Set WordPress TinyMCE Editor To Readonly

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

Related posts

Leave a Reply

1 comment

  1. 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.