Yarin
Yarin

Reputation: 183599

Disable WYSISYG editor in Wordpress

I'm trying to write a plugin to disable the WordPress WSYIWYG editor for all users.

I wrote some code to remove the tinymce directory, but this breaks the editor- you can't write anything or use the HTML tab.

$dirName = ABSPATH . '/wp-includes/js/tinymce';
if (is_dir($dirName)) {
    rename("$dirName", $dirName."_DISABLED");
}

I'm trying to emulate what happens when you select the "Disable the visual editor when writing" checkbox in the user settings tab, but for all users all the time.

Upvotes: 0

Views: 409

Answers (2)

Yarin
Yarin

Reputation: 183599

Jean pointed the way, but wanted to share the full working code:

In my plugin:

// Only do this if we're in admin section:
if(is_admin()) {
    // Add the action on the init hook, when user stuff is already initialized:
    add_action('init', 'disable_rich_editing');
}
function disable_rich_editing(){
    $current_user = wp_get_current_user();
    $isRichEditing = $current_user->get('rich_editing');
    if ($isRichEditing) {
        update_user_meta( $current_user->ID, 'rich_editing', 'false' );
    }
}

What it does:

Normally the only way to disable WYSIWYG is to select the "Disable the visual editor when writing" on each user's settings page. This will force that option to be checked for all users all the time, even if they try to uncheck it.

Upvotes: 0

Jean
Jean

Reputation: 772

If you want to go with a very frontal solution, you could emulate that by updating a few rows directly in the database, like that :

UPDATE wp_usermeta SET meta_value = 'false' WHERE meta_key = 'rich_editing';

Or else, if you want to use Wordpress functions, you could use update_user_meta. Here is the doc: http://codex.wordpress.org/Function_Reference/update_user_meta

Upvotes: 1

Related Questions