I creat a post form on front-end for wordpress members by use DJD Site Post plugin. Plugin url: http://wordpress.org/extend/plugins/djd-site-post/

And now i want to auto strip all hyperlink & images in post when user copy & paste content from other website (with many links).

I use the simple editor in plugin (tinymce editor).

How to auto strip all hyperlinks & images in post befor record to database (or when user click the submit button) by php functions or tinymce functions (exclude admin user)?

Here is some code in the plugin i think need to edit: (I'm using case simple)

// Set editor (content field) style
    case 'simple':
        $teeny = true;
        $show_quicktags = false;
        add_filter( 'teeny_mce_buttons', create_function ( '' , "return array('bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'unlink', 'fullscreen');" ) , 50 );
    case 'rich':
        $teeny = false;
        $show_quicktags = true;
    case 'html':
        $teeny = true;
        $show_quicktags = true;
        add_filter ( 'user_can_richedit' , create_function ( '' , 'return false;' ) , 50 );

Thanks all for help. (Sorry if my english is not good.)


Here is one idea to strip link- and image tags from the post content (before you save it) by using the edit_post_content filter and the wp_kses function:

add_filter( 'edit_post_content', 'my_edit_post_content', 10, 1 );
function my_edit_post_content( $content ) { 
    if (!current_user_can('manage_options')) { // only strip for non-admins
        global $allowedposttags;
        $mytags = $allowedposttags;
        unset($mytags['a']);               // don't allow links
        unset($mytags['img']);             // don't allow images
        $content = wp_kses($content, $mytags);
    return $content;

where $allowedposttags is defined here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.