I am trying to disable the tinyMCEeditor in wordpress so it is readonly if the post has already been published. I already have the logic for determining if the post is published (by using $post object's post_status variable)but I have not found a solution for setting the readonly parameter in tinyMCE to true.

Cross-Post from StackOverflow


You can hook into tiny_mce_before_init to modify the TinyMCE arguments to set the readonly attribute.

For example (using PHP 5.3):

add_filter( 'tiny_mce_before_init', function( $args ) {

    // do you existing check for published here
    if ( 1 == 1 )
         $args['readonly'] = 1;

    return $args;
} );

This will make the TinyMCE readonly, however it won't make the HTML editor readonly (that's not TinyMCE) and it also won't stop people using the Media Upload to insert images. However, that might not be an issue - because I would recommend you implement some server-side checking to prevent edits, as it's always possible for someone to send whatever content they want from the browser by manipulating the DOM etc.

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.