Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
switch($djd_options['djd-editor-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 );
        break;
    case 'rich':
        $teeny = false;
        $show_quicktags = true;
        break;
    case 'html':
        $teeny = true;
        $show_quicktags = true;
        add_filter ( 'user_can_richedit' , create_function ( '' , 'return false;' ) , 50 );
        break;
}

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

share|improve this question
add comment

1 Answer

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:

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/kses.php#L48

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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