Provides an interface to navigate colors and submits the 6-character hex code e.g. #ffffff. This field uses the {@link https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/ WordPress core color picker introduced in WordPress 3.5}.
Inheritance: extends Fieldmanager_Field
 public function test_sanitization()
 {
     $test_data = 'invalid';
     $fm = new Fieldmanager_Colorpicker(array('name' => 'test_colorpicker'));
     $fm->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, $test_data);
     $this->assertEquals('', get_post_meta($this->post->ID, 'test_colorpicker', true));
 }
 /**
  * @dataProvider default_color_iterations
  * @param  array $args Fieldmanager_Colorpicker args
  * @param  string $regex Test regex
  */
 public function test_default_color($args, $regex)
 {
     $args['name'] = rand_str();
     $fm = new Fieldmanager_Colorpicker($args);
     ob_start();
     $fm->add_meta_box('Test Colorpicker', 'post')->render_meta_box($this->post, array());
     $html = ob_get_clean();
     $this->assertRegExp($regex, $html);
 }
 public function setUp()
 {
     parent::setUp();
     // Spoof is_admin() for fm_add_script().
     $this->screen = get_current_screen();
     set_current_screen('dashboard-user');
     // Re-init scripts. @see Tests_Dependencies_Scripts.
     $this->old_wp_scripts = isset($GLOBALS['wp_scripts']) ? $GLOBALS['wp_scripts'] : null;
     remove_action('wp_default_scripts', 'wp_default_scripts');
     $GLOBALS['wp_scripts'] = new WP_Scripts();
     $GLOBALS['wp_scripts']->default_version = get_bloginfo('version');
     // Some fields will only register a script once, so hack around that.
     Fieldmanager_Media::$has_registered_media = false;
     Fieldmanager_Colorpicker::$has_registered_statics = false;
     // Instantiate field classes that register scripts.
     new Fieldmanager_Autocomplete('Test', array('datasource' => new Fieldmanager_Datasource_Post()));
     new Fieldmanager_Datepicker('Test');
     new Fieldmanager_DraggablePost('Test');
     new Fieldmanager_Grid('Test');
     new Fieldmanager_Group('Test', array('tabbed' => 'horizontal'));
     new Fieldmanager_Media('Test');
     new Fieldmanager_Select('Test');
     new Fieldmanager_RichTextArea('Test');
     new Fieldmanager_Colorpicker('Test');
     do_action('wp_enqueue_scripts');
     do_action('admin_enqueue_scripts');
 }
 /**
  * Build the colorpicker object and enqueue assets.
  *
  * @param string $label
  * @param array $options
  */
 public function __construct($label = '', $options = array())
 {
     if (!self::$has_registered_statics) {
         add_action('admin_enqueue_scripts', function () {
             wp_enqueue_style('wp-color-picker');
         });
         fm_add_script('fm_colorpicker', 'js/fieldmanager-colorpicker.js', array('jquery', 'wp-color-picker'), '1.0', true);
         self::$has_registered_statics = true;
     }
     $this->sanitize = array($this, 'sanitize_hex_color');
     parent::__construct($label, $options);
 }
 /**
  * Build the colorpicker object and enqueue assets.
  *
  * @param string $label
  * @param array $options
  */
 public function __construct($label = '', $options = array())
 {
     if (!self::$has_registered_statics) {
         add_action('admin_enqueue_scripts', function () {
             wp_enqueue_style('wp-color-picker');
         });
         fm_add_script('fm_colorpicker', 'js/fieldmanager-colorpicker.js', array('jquery', 'wp-color-picker'), '1.0', true);
         self::$has_registered_statics = true;
     }
     $this->sanitize = array($this, 'sanitize_hex_color');
     parent::__construct($label, $options);
     // If we have a default_value and default_color was not explicitly set
     // to be empty, set default_color to default_value.
     if (!isset($this->default_color) && !empty($this->default_value)) {
         $this->default_color = $this->default_value;
     }
 }