Skip to content

Instantly share code, notes, and snippets.

@7studio
Last active December 19, 2016 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 7studio/ae1693f312a405e1f706e4fa2a04fd9a to your computer and use it in GitHub Desktop.
Save 7studio/ae1693f312a405e1f706e4fa2a04fd9a to your computer and use it in GitHub Desktop.
WP + TinyMCE + Color Picker Plugin + Text Color Plugin = ❤️
<?php
if ( ! function_exists( 'thistle_remove_tiny_mce_colorpicker' ) ) {
/**
* Pulls out the colorpicker plugin from TinyMCE.
* Without this plugin the end user cannot select a custom color.
*
* @link https://www.tinymce.com/docs/plugins/colorpicker/
*
* @param array $plugins An array of default TinyMCE plugins.
* @return array
*/
function thistle_remove_tiny_mce_colorpicker( $plugins ) {
return array_diff( $plugins, array( 'colorpicker' ) );
}
}
add_filter( 'tiny_mce_plugins', 'thistle_remove_tiny_mce_colorpicker' );
if ( ! function_exists( 'thistle_tiny_mce_textcolor_map' ) ) {
/**
* Specifies a map of the text colors that will appear in the grid of
* the textcolor plugin.
* If the map is empty, the textcolor plugin is pulled out.
*
* @link https://www.tinymce.com/docs/plugins/textcolor/#textcolor_map
*
* @param $mceInit array An array with TinyMCE config.
* @return array
*/
function thistle_tiny_mce_textcolor_map( $mceInit ) {
$textcolor_map = apply_filters( 'thistle_tiny_mce_textcolor_map', array() );
if ( ! empty( $textcolor_map ) ) {
$mceInit['textcolor_map'] = wp_json_encode( $textcolor_map );
} else {
$mceInit['plugins'] = explode( ',' , $mceInit['plugins'] );
$mceInit['plugins'] = array_diff( $mceInit['plugins'], array( 'textcolor' ) );
$mceInit['plugins'] = implode( ',' , $mceInit['plugins'] );
}
return $mceInit;
}
}
add_filter( 'tiny_mce_before_init', 'thistle_tiny_mce_textcolor_map' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment