1
0

customize.php 4.4 KB

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