| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; |
| 3 |
} // Cannot access directly. |
| 4 |
/** |
| 5 |
* |
| 6 |
* WP Customize custom panel |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
* @version 1.0.0 |
| 10 |
*/ |
| 11 |
if ( ! class_exists( 'WP_Customize_Panel_SP_PC' ) && class_exists( 'WP_Customize_Panel' ) ) { |
| 12 |
class WP_Customize_Panel_SP_PC extends WP_Customize_Panel { |
| 13 |
|
| 14 |
public $type = 'spf'; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* |
| 20 |
* WP Customize custom section |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* @version 1.0.0 |
| 24 |
*/ |
| 25 |
if ( ! class_exists( 'WP_Customize_Section_SP_PC' ) && class_exists( 'WP_Customize_Section' ) ) { |
| 26 |
class WP_Customize_Section_SP_PC extends WP_Customize_Section { |
| 27 |
|
| 28 |
public $type = 'spf'; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* |
| 34 |
* WP Customize custom control |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @version 1.0.0 |
| 38 |
*/ |
| 39 |
if ( ! class_exists( 'WP_Customize_Control_SP_PC' ) && class_exists( 'WP_Customize_Control' ) ) { |
| 40 |
class WP_Customize_Control_SP_PC extends WP_Customize_Control { |
| 41 |
|
| 42 |
|
| 43 |
public $type = 'spf'; |
| 44 |
public $field = ''; |
| 45 |
public $unique = ''; |
| 46 |
|
| 47 |
protected function render() { |
| 48 |
|
| 49 |
$depend = ''; |
| 50 |
$hidden = ''; |
| 51 |
|
| 52 |
if ( ! empty( $this->field['dependency'] ) ) { |
| 53 |
$hidden = ' spf-dependency-control hidden'; |
| 54 |
$depend .= ' data-controller="' . $this->field['dependency'][0] . '"'; |
| 55 |
$depend .= ' data-condition="' . $this->field['dependency'][1] . '"'; |
| 56 |
$depend .= ' data-value="' . $this->field['dependency'][2] . '"'; |
| 57 |
} |
| 58 |
|
| 59 |
$id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id ); |
| 60 |
$class = 'customize-control customize-control-' . $this->type . $hidden; |
| 61 |
|
| 62 |
echo '<li id="' . $id . '" class="' . $class . '"' . $depend . '>'; |
| 63 |
$this->render_content(); |
| 64 |
echo '</li>'; |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public function render_content() { |
| 69 |
|
| 70 |
$complex = array( |
| 71 |
'accordion', |
| 72 |
'background', |
| 73 |
'backup', |
| 74 |
'border', |
| 75 |
'button_set', |
| 76 |
'checkbox', |
| 77 |
'color_group', |
| 78 |
'date', |
| 79 |
'dimensions', |
| 80 |
'fieldset', |
| 81 |
'group', |
| 82 |
'image_select', |
| 83 |
'link_color', |
| 84 |
'media', |
| 85 |
'palette', |
| 86 |
'sortable', |
| 87 |
'sorter', |
| 88 |
'switcher', |
| 89 |
'tabbed', |
| 90 |
'typography', |
| 91 |
); |
| 92 |
|
| 93 |
$field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : ''; |
| 94 |
$custom = ( ! empty( $this->field['customizer'] ) ) ? true : false; |
| 95 |
$is_complex = ( in_array( $this->field['type'], $complex ) ) ? true : false; |
| 96 |
$class = ( $is_complex || $custom ) ? ' spf-customize-complex' : ''; |
| 97 |
$atts = ( $is_complex || $custom ) ? ' data-unique-id="' . $this->unique . '" data-option-id="' . $field_id . '"' : ''; |
| 98 |
|
| 99 |
if ( ! $is_complex && ! $custom ) { |
| 100 |
$this->field['attributes']['data-customize-setting-link'] = $this->settings['default']->id; |
| 101 |
} |
| 102 |
|
| 103 |
$this->field['name'] = $this->settings['default']->id; |
| 104 |
|
| 105 |
$this->field['dependency'] = array(); |
| 106 |
|
| 107 |
echo '<div class="spf-customize-field' . $class . '"' . $atts . '>'; |
| 108 |
|
| 109 |
SP_PC::field( $this->field, $this->value(), $this->unique, 'customize' ); |
| 110 |
|
| 111 |
echo '</div>'; |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
} |
| 116 |
} |
| 117 |
|