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:
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. 🙂
1 Answer
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.