Oops…

I'm just a plugin, not much I can do when called directly.

Might be a good idea to have a look at Dashboard › Settings › TinyMCE Color Grid.

update(); } /** * Update procedures * @since 1.6 */ protected function update() { $version = get_option(self::INSTALLED_VERSION, 0); if ($version == self::VERSION) { return; } while ($version != self::VERSION) { switch ($version) { case 0: $sets = get_option(self::SETS, array()); foreach ($sets as &$set) { $set[0] = str_replace('#', '', $set[0]); } update_option(self::SETS, $sets); $version = 16; break; default: $version = self::VERSION; } } update_option(self::INSTALLED_VERSION, self::VERSION); } /** * Loads translation file * @since 1.4.4 */ public function translation() { load_plugin_textdomain('kt-tinymce-color-grid', false, dirname(plugin_basename(__FILE__)) . '/language'); } /** * Enqueues JavaScript and CSS files * @since 1.3 * @param string $hook Current page load hook */ public function scripts($hook) { if ($hook == 'settings_page_' . self::KEY) { if (!defined('SCRIPT_DEBUG')) { include(ABSPATH . WPINC . '/version.php'); $dev = strpos($wp_version, '-src') !== false; $suffix = $dev ? '' : '.min'; } else { $suffix = SCRIPT_DEBUG ? '' : '.min'; } wp_enqueue_script(self::KEY, plugins_url("settings$suffix.js", __FILE__), array('jquery-ui-position', 'jquery-ui-sortable'), self::VERSION); wp_enqueue_style(self::KEY, plugins_url('settings.css', __FILE__), array('farbtastic'), self::VERSION); $picker = preg_replace(array('/\s*\n\s*/', '/"/'), array('', "'"), $this->picker); wp_localize_script(self::KEY, 'kt_TinyMCE_color_picker', $picker); } } /** * Adds dynamic CSS file for TinyMCE * @since 1.3 */ public function style() { $n = 0; if (get_option(self::CUSTOM, false)) { $n = ceil(count(get_option(self::SETS, array())) / 13); } echo ''; } /** * Adds entry for settings page to WordPress' admin menu * @since 1.3 */ public function menu() { $name = esc_html__('TinyMCE Color Grid', 'kt-tinymce-color-grid'); $hook = add_options_page($name, $name, 'manage_options', self::KEY, array($this, 'editor')); add_action("load-$hook", array($this, 'init')); } /** * Adds a link to the plugin listing page leading to the settings page * @since 1.4 * @param array $links Array holding HTML * @param string $file Current name of plugin file * @return array Modified array */ public function link($links, $file) { if (plugin_basename($file) == plugin_basename(__FILE__)) { $links[] = ' ' . esc_html__('Custom Colors', 'kt-tinymce-color-grid') . ''; } return $links; } /** * Saving routines and adds help to settings page * @since 1.4.4 */ public function init() { if (wp_verify_nonce(self::request('kt_settings_nonce'), self::NONCE)) { update_option(self::CUSTOM, self::request('kt_custom', '0')); $colors = self::request('kt_colors', array()); $names = self::request('kt_names', array()); $sets = array(); foreach ($names as $i => $name) { $color = $this->sanitize($colors[$i]); if ($color) { $sets[] = array($color, sanitize_text_field(stripslashes($name))); } } $match = null; $action = self::request('kt_action'); if ($action == 'add') { $sets[] = array('000000', ''); } else if (preg_match('/remove-(\d+)/', $action, $match)) { array_splice($sets, $match[1], 1); } update_option(self::SETS, $sets); wp_redirect($action == 'save' ? add_query_arg('updated', '1') : remove_query_arg('updated')); exit; } $screen = get_current_screen(); $screen->add_help_tab(array( 'id' => 'aria', 'title' => __('Accessibility', 'kt-tinymce-color-grid'), 'content' => '

' . __('You can access every input field of the editor via your keyboard.', 'kt-tinymce-color-grid') . '

' . __('The editor consists of a toolbar and a list of entries. The toolbar has a button Add for adding a new entry to the list. An entry has a color picker, two text fields — one holding a hexadecimal representation of the color, and one for the name of the entry — and lastly a button to remove the entry.', 'kt-tinymce-color-grid') . '

' . __('If an entry itself is focused use and to change the focus, and you can change its position among its siblings by pressing the page keys Page Up and Page Down. If you want to delete that entry press DEL', 'kt-tinymce-color-grid') . '

' . __('If a color picker has focus, use and to change the lightness, and to change the saturation, and + and - to change the hue. ENTER opens a visual color picker.', 'kt-tinymce-color-grid') . '

' )); $this->picker = '
'; } /** * Highlights an accesskey inside a translated string * @since 1.4.4 * @param string $translation Translated string * @param string $key Accesskey * @return string */ protected function accesskey($translation, $key) { return preg_replace('/(' . preg_quote($key, '/') . ')/i', '$1', esc_html($translation), 1); } /** * Renders settings page * @since 1.3 * @global string $wp_version */ public function editor() { global $wp_version; $version = 0; preg_match('/^(\d+\.\d+)/', $wp_version, $version); $head = floatval($version[1]) >= 4.3 ? 'h1' : 'h2'; $use_custom = self::request('custom', get_option(self::CUSTOM, false)); $custom_key = _x('C', 'accesskey for custom colors', 'kt-tinymce-color-grid'); $add_key = _x('A', 'accesskey for adding color', 'kt-tinymce-color-grid'); $save_key = _x('S', 'accesskey for saving', 'kt-tinymce-color-grid'); $picker = ''; $sets = get_option(self::SETS, array()); foreach ($sets as $i => $set) { list($color, $name) = array_map('esc_attr', $set); $picker .= sprintf($this->picker, "#$color", $name, $i); } vprintf('
<%s>%s › %s

%s

%s
%s

', array( $head, esc_html__('Settings'), esc_html__('TinyMCE Color Grid', 'kt-tinymce-color-grid'), $head, esc_html__('This editor works best with JavaScript enabled.', 'kt-tinymce-color-grid'), self::KEY, wp_nonce_field(self::NONCE, 'kt_settings_nonce', false, false), $use_custom ? ' checked="checked"' : '', esc_attr($custom_key), $this->accesskey(__("I'd like to define some custom colors", 'kt-tinymce-color-grid'), $custom_key), $use_custom ? 'false' : 'true', esc_attr__('Color Editor Toolbar', 'kt-tinymce-color-grid'), esc_attr($add_key), $this->accesskey(__('Add'), $add_key), esc_attr__('No colors yet', 'kt-tinymce-color-grid'), $picker, esc_attr($save_key), $this->accesskey(__('Save'), $save_key), esc_attr__('Visual Color Picker', 'kt-tinymce-color-grid') )); } /** * Checks a string for a valid hexadecimal color and normalizes it to RRGGBB * @since 1.4 * @param string $string String to be checked * @return string|boolean Returns a color of RRGGBB or false on failure */ protected function sanitize($string) { $string = strtoupper($string); $match = null; if (preg_match('/([0-9A-F]{6}|[0-9A-F]{3})/', $string, $match)) { if (strlen($match[1]) == 3) { return preg_replace('/[0-9A-F]/', '\1\1', $match[1]); } return $match[1]; } return false; } /** * Renders the new color grid * @since 1.3 * @param array $init Wordpress' TinyMCE inits * @return array */ public function grid($init) { $rows = 13; $columns = 19; $extra = 0; if (get_option(self::CUSTOM, false)) { $custom_colors = get_option(self::SETS, array()); $custom_colors = array_chunk($custom_colors, $rows); $extra = count($custom_colors); if ($extra) { $last_column = $extra - 1; $custom_colors[$last_column] = array_pad($custom_colors[$last_column], $rows, array('FFFFFF', '')); } } $map = array(); for ($row = 0; $row < $rows; $row++) { for ($column = 0; $column < $extra; $column++) { list($color, $name) = $custom_colors[$column][$row]; $map[] = '"' . $color . '","' . esc_js($name) . '"'; } for ($column = 0; $column < $columns; $column++) { if ($row == $rows - 1 && $column == $columns - 1) { break; } $map[] = '"' . $this->colors[$column][$row] . '",""'; } } $init['textcolor_map'] = '[' . implode(',', $map) . ']'; $init['textcolor_cols'] = $columns + $extra; $init['textcolor_rows'] = $rows; return $init; } /** * Fetches a HTTP request value * @since 1.3 * @param string $key Name of the value to fetch * @param mixed|null $default Default value if $key does not exist * @return mixed The value for $key or $default */ static function request($key, $default = null) { return key_exists($key, $_REQUEST) ? $_REQUEST[$key] : $default; } } } new kt_TinyMCE_Color_Grid();