How to hide the Text Color icon from Visual Editor of WordPress Post Editor from Users other than Admins?

wordpress.stackexchange https://wordpress.stackexchange.com/questions/343909

  •  16-04-2021
  •  | 
  •  

Domanda

Want to hide the Text Color icon from Visual Editor of WordPress Post Editor from Users other than Admins. How to do it?

È stato utile?

Soluzione

This should work if you add it to your functions.php file. It targets the buttons on the second row in your text editor. To target the first row, use the mce_buttons hook instead of mce_buttons_2.

/**
 * Removes text color button from tiny mce editor
 */
add_filter( 'mce_buttons_2', 'remove_tiny_mce_buttons');
function remove_tiny_mce_buttons( $buttons ) {
    if ( is_admin() && !current_user_can('administrator')){
    $remove_buttons = array(
        'forecolor', // text color
    );
    foreach ( $buttons as $button_key => $button_value ) {
        if ( in_array( $button_value, $remove_buttons ) ) {
            unset( $buttons[ $button_key ] );
        }
    }

    }
    return $buttons;
}

If you would like to remove more buttons on the second row (mce_buttons_2), add their IDs to the $remove_buttons array. Below are a few second row IDs:

  • formatselect
  • underline
  • alignjustify
  • forecolor
  • pastetext
  • removeformat
  • charmap
  • outdent
  • indent
  • undo
  • redo
  • wp_help
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top