everest-forms
/
addons
/
StyleCustomizer
/
includes
/
customize
/
class-evf-customize-image-checkbox-control.php
class-evf-customize-background-image-control.php
1 year ago
class-evf-customize-color-control.php
1 year ago
class-evf-customize-color-palette-control.php
1 year ago
class-evf-customize-dimension-control.php
1 year ago
class-evf-customize-image-checkbox-control.php
1 year ago
class-evf-customize-image-radio-control.php
1 year ago
class-evf-customize-select2-control.php
1 year ago
class-evf-customize-slider-control.php
1 year ago
class-evf-customize-templates-section.php
1 year ago
class-evf-customize-toggle-control.php
1 year ago
class-evf-customize-image-checkbox-control.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customize API: EVF_Customize_Image_Checkbox_Control class |
| 4 | * |
| 5 | * @package EverestForms_Style_Customizer\Customize |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Customize Image Checkbox Control class. |
| 13 | * |
| 14 | * @see WP_Customize_Control |
| 15 | */ |
| 16 | class EVF_Customize_Image_Checkbox_Control extends WP_Customize_Control { |
| 17 | |
| 18 | /** |
| 19 | * Type. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | public $type = 'evf-image_checkbox'; |
| 24 | |
| 25 | /** |
| 26 | * Refresh the parameters passed to the JavaScript via JSON. |
| 27 | * |
| 28 | * @uses WP_Customize_Control::to_json() |
| 29 | */ |
| 30 | public function to_json() { |
| 31 | parent::to_json(); |
| 32 | $this->json['default'] = $this->setting->default; |
| 33 | $this->json['id'] = $this->id; |
| 34 | $this->json['link'] = $this->get_link(); |
| 35 | $this->json['choices'] = $this->choices; |
| 36 | |
| 37 | $this->json['inputAttrs'] = ''; |
| 38 | foreach ( $this->input_attrs as $attr => $value ) { |
| 39 | $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
| 40 | } |
| 41 | |
| 42 | $value = $this->value(); |
| 43 | $this->json['value'] = array(); |
| 44 | if ( is_array( $value ) ) { |
| 45 | foreach ( $this->value() as $key => $value ) { |
| 46 | if ( is_numeric( $key ) ) { |
| 47 | $this->json['value'][ $value ] = true; |
| 48 | } else { |
| 49 | $this->json['value'][ $key ] = $value; |
| 50 | } |
| 51 | } |
| 52 | } elseif ( ! empty( $value ) ) { |
| 53 | $this->json['value'] = array( $value => true ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Don't render the control content from PHP, as it's rendered via JS on load. |
| 59 | */ |
| 60 | public function render_content() {} |
| 61 | |
| 62 | /** |
| 63 | * Render a JS template for control display. |
| 64 | * |
| 65 | * @see WP_Customize_Control::print_template() |
| 66 | */ |
| 67 | public function content_template() { |
| 68 | ?> |
| 69 | <label> |
| 70 | <# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #> |
| 71 | <# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# |
| 72 | } #> |
| 73 | |
| 74 | </label> |
| 75 | <ul class="image-checkbox-wrapper"> |
| 76 | <# Object.keys( data.choices ).forEach( function( key ) { #> |
| 77 | |
| 78 | <li> |
| 79 | <input id="image-checkbox-{{{data.id}}}-{{{key}}}" type="checkbox" name="image-checkbox-{{{data.id}}}" value = "{{{key}}}" {{{ ( data.value[key]!=undefined && data.value[key] == true ) ? 'checked="checked"' : '' }}}/> |
| 80 | <label class="image-checkbox-item" title="{{{data.choices[key].name}}}" for="image-checkbox-{{{data.id}}}-{{{key}}}"> |
| 81 | <img src="{{{data.choices[key].image}}}" alt="{{{data.choices[key].name}}}" /> |
| 82 | </label> |
| 83 | </li> |
| 84 | <# } ); #> |
| 85 | </ul> |
| 86 | <input class="image-checkbox-hidden-value" type="hidden" {{{ data.link }}} > |
| 87 | <?php |
| 88 | } |
| 89 | } |
| 90 |