register_control_type( 'Epsilon_Control_Color_Scheme' ); } /** * Add custom parameters to pass to the JS via JSON. * * @since 1.2.0 * @access public */ public function json() { $json = parent::json(); $json['id'] = $this->id; $json['link'] = $this->get_link(); $json['value'] = $this->value(); $json['choices'] = $this->get_choices(); if ( 'default' === $json['value'] || null === $json['value'] ) { $temp = reset( $json['choices'] ); $json['value'] = $temp['id']; } $json['selectedColors'] = $this->get_selected_colors( $json ); return $json; } /** * Arrange a new array of options using the values from database * * @since 1.0.0 */ public function get_selected_colors( $json ) { $arr = $json['choices'][ $json['value'] ]; foreach ( $arr['colors'] as $input => $value ) { if ( ! get_theme_mod( $input, false ) ) { continue; } $arr['colors'][ $input ] = get_theme_mod( $input ); } return $arr; } /** * Arrange array so we can handle it easier * * @since 1.0.0 */ public function get_choices() { $arr = array(); foreach ( $this->choices as $index => $choice ) { $arr[ $choice['id'] ] = $choice; $arr[ $choice['id'] ]['encodedColors'] = json_encode( $choice['colors'] ); } return $arr; } /** * Display the control content * * @since 1.0.0 */ public function content_template() { //@formatter:off ?>