WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-theme-customize.php
Go to the documentation of this file.
1 <?php
2 
15 
16  const CHECKBOX = 'checkbox';
17  const COLOR = 'WP_Customize_Color_Control';
18  const DROP_DOWN_PAGES = 'dropdown-pages';
19  const IMAGE = 'WP_Customize_Image_Control';
20  const RADIO = 'radio';
21  const SELECT = 'select';
22  const TEXT = 'text';
23  const UPLOAD = 'WP_Customize_Upload_Control';
24 
31  public static function controls()
32  {
33  $controls = array(
34  self::COLOR => self::COLOR,
35  self::CHECKBOX => self::CHECKBOX,
36  self::DROP_DOWN_PAGES => self::DROP_DOWN_PAGES,
37  self::IMAGE => self::IMAGE,
38  self::RADIO => self::RADIO,
39  self::SELECT => self::SELECT,
40  self::TEXT => self::TEXT,
41  self::UPLOAD => self::UPLOAD
42  );
43 
44  return apply_filters( 'wpdk_theme_customize_controls_type', $controls );
45  }
46 
53  public static function instanceable()
54  {
55  $controls = array(
56  self::COLOR => self::COLOR,
57  self::IMAGE => self::IMAGE,
58  self::UPLOAD => self::UPLOAD
59  );
60 
61  return apply_filters( 'wpdk_theme_customize_controls_instanceable', $controls );
62  }
63 
64 }
65 
66 
79 
87  public function __construct()
88  {
89  // Setup the Theme Customizer settings and controls...
90  add_action( 'customize_register', array( $this, 'customize_register' ) );
91 
92  // Output custom CSS to live site
93  add_action( 'wp_head', array( $this, 'wp_head' ) );
94 
95  // Enqueue live preview javascript in Theme Customizer admin screen
96  add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
97  }
98 
107  public function customize_preview_init()
108  {
109  }
110 
123  public function customize_register( $wp_customize )
124  {
125  $sections = $this->sections();
126 
127  if ( empty( $sections ) ) {
128  return;
129  }
130 
131  /* List of instanceable controls */
133 
134  /* Sections */
135  foreach ( $sections as $section_id => $section_args ) {
136 
137  $wp_customize->add_section( $section_id, $section_args );
138 
139  if ( isset( $section_args['_setting'] ) ) {
140 
141  /* Settings */
142  foreach ( $section_args['_setting'] as $setting_id => $setting_args ) {
143  $wp_customize->add_setting( $setting_id, $setting_args );
144 
145  if ( isset( $setting_args['_control'] ) ) {
146 
147  /* Controls */
148  $control_args = $setting_args['_control'];
149  $control_args['section'] = $section_id;
150 
151  if ( in_array( $control_args['type'], $instanceable ) ) {
152  // Get instanceable class name
153  $class_name = $control_args['type'];
154  // Unset unused
155  unset( $control_args['type'] );
156  // Set a new arg
157  $control_args['settings'] = $setting_id;
158  // Create the control
159  $control = new $class_name( $wp_customize, $setting_id, $control_args );
160  $wp_customize->add_control( $control, $control_args );
161  }
162  else {
163  $wp_customize->add_control( $setting_id, $control_args );
164  }
165 
166  }
167  }
168  }
169  }
170 
171  }
172 
189  public function sections()
190  {
191  // You have to override this method
192  return array();
193  }
194 
201  public function wp_head()
202  {
203  // Your output in the head
204  }
205 
206 }