| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* WP Customize custom panel |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'WP_Customize_Panel_STREAMCAST_CSF' ) && class_exists( 'WP_Customize_Panel' ) ) { |
| 11 |
class WP_Customize_Panel_STREAMCAST_CSF extends WP_Customize_Panel { |
| 12 |
public $type = 'streamcast'; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* |
| 18 |
* WP Customize custom section |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
* @version 1.0.0 |
| 22 |
* |
| 23 |
*/ |
| 24 |
if ( ! class_exists( 'WP_Customize_Section_STREAMCAST_CSF' ) && class_exists( 'WP_Customize_Section' ) ) { |
| 25 |
class WP_Customize_Section_STREAMCAST_CSF extends WP_Customize_Section { |
| 26 |
public $type = 'streamcast'; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* |
| 32 |
* WP Customize custom control |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @version 1.0.0 |
| 36 |
* |
| 37 |
*/ |
| 38 |
if ( ! class_exists( 'WP_Customize_Control_STREAMCAST_CSF' ) && class_exists( 'WP_Customize_Control' ) ) { |
| 39 |
class WP_Customize_Control_STREAMCAST_CSF extends WP_Customize_Control { |
| 40 |
|
| 41 |
public $type = 'streamcast'; |
| 42 |
public $field = ''; |
| 43 |
public $unique = ''; |
| 44 |
|
| 45 |
public function render() { |
| 46 |
|
| 47 |
$depend = ''; |
| 48 |
$visible = ''; |
| 49 |
|
| 50 |
if ( ! empty( $this->field['dependency'] ) ) { |
| 51 |
|
| 52 |
$dependency = $this->field['dependency']; |
| 53 |
$depend_visible = ''; |
| 54 |
$data_controller = ''; |
| 55 |
$data_condition = ''; |
| 56 |
$data_value = ''; |
| 57 |
$data_global = ''; |
| 58 |
|
| 59 |
if ( is_array( $dependency[0] ) ) { |
| 60 |
$data_controller = implode( '|', array_column( $dependency, 0 ) ); |
| 61 |
$data_condition = implode( '|', array_column( $dependency, 1 ) ); |
| 62 |
$data_value = implode( '|', array_column( $dependency, 2 ) ); |
| 63 |
$data_global = implode( '|', array_column( $dependency, 3 ) ); |
| 64 |
$depend_visible = implode( '|', array_column( $dependency, 4 ) ); |
| 65 |
} else { |
| 66 |
$data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : ''; |
| 67 |
$data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : ''; |
| 68 |
$data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : ''; |
| 69 |
$data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : ''; |
| 70 |
$depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : ''; |
| 71 |
} |
| 72 |
|
| 73 |
$depend .= ' data-controller="'. esc_attr( $data_controller ) .'"'; |
| 74 |
$depend .= ' data-condition="'. esc_attr( $data_condition ) .'"'; |
| 75 |
$depend .= ' data-value="'. esc_attr( $data_value ) .'"'; |
| 76 |
$depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : ''; |
| 77 |
|
| 78 |
$visible = ' streamcast-csf-dependency-control'; |
| 79 |
$visible .= ( ! empty( $depend_visible ) ) ? ' streamcast-csf-depend-visible' : ' streamcast-csf-depend-hidden'; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
$id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id ); |
| 84 |
$class = 'customize-control customize-control-'. $this->type . $visible; |
| 85 |
|
| 86 |
echo '<li id="'. esc_attr( $id ) .'" class="'. esc_attr( $class ) .'"'. $depend .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 87 |
$this->render_field_content(); |
| 88 |
echo '</li>'; |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
public function render_field_content() { |
| 93 |
|
| 94 |
$complex = apply_filters( 'streamcast_csf_customize_complex_fields', array( |
| 95 |
'accordion', |
| 96 |
'background', |
| 97 |
'border', |
| 98 |
'button_set', |
| 99 |
'checkbox', |
| 100 |
'color_group', |
| 101 |
'date', |
| 102 |
'dimensions', |
| 103 |
'fieldset', |
| 104 |
'group', |
| 105 |
'image_select', |
| 106 |
'link', |
| 107 |
'link_color', |
| 108 |
'media', |
| 109 |
'palette', |
| 110 |
'repeater', |
| 111 |
'sortable', |
| 112 |
'sorter', |
| 113 |
'spacing', |
| 114 |
'switcher', |
| 115 |
'tabbed', |
| 116 |
'typography' |
| 117 |
) ); |
| 118 |
|
| 119 |
$field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : ''; |
| 120 |
$custom = ( ! empty( $this->field['customizer'] ) ) ? true : false; |
| 121 |
$is_complex = ( in_array( $this->field['type'], $complex ) ) ? true : false; |
| 122 |
$class = ( $is_complex || $custom ) ? ' streamcast-csf-customize-complex' : ''; |
| 123 |
$atts = ( $is_complex || $custom ) ? ' data-unique-id="'. esc_attr( $this->unique ) .'" data-option-id="'. esc_attr( $field_id ) .'"' : ''; |
| 124 |
|
| 125 |
if ( ! $is_complex && ! $custom ) { |
| 126 |
$this->field['attributes']['data-customize-setting-link'] = $this->settings['default']->id; |
| 127 |
} |
| 128 |
|
| 129 |
$this->field['name'] = $this->settings['default']->id; |
| 130 |
|
| 131 |
$this->field['dependency'] = array(); |
| 132 |
|
| 133 |
echo '<div class="streamcast-csf-customize-field'. esc_attr( $class ) .'"'. $atts .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 134 |
|
| 135 |
STREAMCAST_STREAMCAST_CSF::field( $this->field, $this->value(), $this->unique, 'customize' ); |
| 136 |
|
| 137 |
echo '</div>'; |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
} |
| 143 |
|