This is more of an excercise than something for a client.

Anyway, I'm trying to disable the quicktags when you're on the dashboard and you click on Comments > Edit Comment. On that screen, there's a TinyMCE with quicktags and the textarea has an id of "content".

I know in the WordPress core, this can be changed on line 67 of wp-admin/edit-form-comment.php by changing this:

wp_editor( $comment->comment_content, 'content', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );

To this (quicktags set to false):

wp_editor( $comment->comment_content, 'content', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => false ) );

But I obviously don't want to edit core and want to do this via filter/hook. This is what I tried.

function disable_tinymce_quicktags_comments ( $args ) {
  ob_start();
  $comment = get_comment_to_edit( $comment_id );
  wp_editor( $comment->comment_content, 'content', array( 'quicktags' => false ) );
  $args = ob_get_contents(); 
  ob_end_clean();
  return $args;
}

add_filter( 'admin_init', 'disable_tinymce_quicktags_comments' );

A var_dump of $args is revealing nothing after the return, and this is what the text editor looks like on the Edit Comment screen with this function happening:

enter image description here

Am I just trying to achieve the impossible or am I just using the wrong hook? I'm still learning about hooks and PHP. Any suggestions? Thanks. :-)

up vote 2 down vote accepted

After checking out the code, the best way to do this would be to use the wp_editor_settings filter in /wp-includes/class-wp-editor.php. When you call wp_editor() it internally makes a call to _WP_Editors::editor($content, $editor_id, $settings);. This function first passes the $settings array through parse_settings() which uses that filter.

add_filter( 'wp_editor_settings', 'remove_editor_quicktags', 10, 2 );
function remove_editor_quicktags( $settings, $id ){
    // $id will be 'content' in your example
    // use it in an if or make it gone for everything...

    // use $pagenow to determine if you are on the edit comments page.
    global $pagenow; 
    if ( $pagenow === 'comment.php' ){
        $settings['quicktags'] = false;
    }
    return $settings;
}

Note - I just realized this filter is new as of WordPress 4.0, so you will need it or newer to take advantage. This also affects all instances of TinyMCE on the admin.

  • Hmm it looks like the wp_editor_settings hook works but it affects all instances of the TinyMCE on the admin, not just the Edit Comment admin page. So it removes the "text" tab on the post/page editors. Is there any way to target specific admin pages to run this? Looks like there isn't a conditional that would help as is_admin just generally checks if you're on the dash, correct? – RachieVee Nov 14 '14 at 14:27
  • I also credited this answer to another person's question with just one line changed, hope you don't mind. Added it as a comment and it's somewhat relevant to my question: wordpress.stackexchange.com/questions/168099/… – RachieVee Nov 14 '14 at 15:34
  • Ah I missed the comment for the $id - unfortunately this doesn't work in this case because the editor on Edit Comment and the editor on a post/page (text mode) both use the same id which is "content". So I can't target a specific editor using this method. – RachieVee Nov 14 '14 at 16:24
  • 1
    If it is on the admin side you can use the global $pagenow to control it too. – doublesharp Nov 14 '14 at 19:43
  • Updated the answer to show this. – doublesharp Nov 14 '14 at 19:47

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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