WordPress Snippets at WPcustoms

restrict post editor to visual or text based on userrole

This snippet hides either the visual or text editor to non-admins. Options for tab: ‘tinymce’, ‘html’. Quickly disable the specific view for all authors and contributors.


/**
 * Snippet Name: restrict post editor to visual or text based on userrole
 * Snippet URL: http://www.wpcustoms.net/snippets/restrict-post-editor-to-visual-or-text/
 */
 function wpc_set_html_content_editor( $tab ) {
  if( ! current_user_can( 'administrator' ) ) {
    $tab = 'html';
  }
  return $tab;
}
add_filter( 'wp_default_editor', 'wpc_set_html_content_editor' );