[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Customize Panel classes 4 * 5 * @package WordPress 6 * @subpackage Customize 7 * @since 4.0.0 8 */ 9 10 /** 11 * Customize Panel class. 12 * 13 * A UI container for sections, managed by the WP_Customize_Manager. 14 * 15 * @since 4.0.0 16 * 17 * @see WP_Customize_Manager 18 */ 19 class WP_Customize_Panel { 20 21 /** 22 * Incremented with each new class instantiation, then stored in $instance_number. 23 * 24 * Used when sorting two instances whose priorities are equal. 25 * 26 * @since 4.1.0 27 * @var int 28 */ 29 protected static $instance_count = 0; 30 31 /** 32 * Order in which this instance was created in relation to other instances. 33 * 34 * @since 4.1.0 35 * @var int 36 */ 37 public $instance_number; 38 39 /** 40 * WP_Customize_Manager instance. 41 * 42 * @since 4.0.0 43 * @var WP_Customize_Manager 44 */ 45 public $manager; 46 47 /** 48 * Unique identifier. 49 * 50 * @since 4.0.0 51 * @var string 52 */ 53 public $id; 54 55 /** 56 * Priority of the panel, defining the display order of panels and sections. 57 * 58 * @since 4.0.0 59 * @var int 60 */ 61 public $priority = 160; 62 63 /** 64 * Capability required for the panel. 65 * 66 * @since 4.0.0 67 * @var string 68 */ 69 public $capability = 'edit_theme_options'; 70 71 /** 72 * Theme features required to support the panel. 73 * 74 * @since 4.0.0 75 * @var string|string[] 76 */ 77 public $theme_supports = ''; 78 79 /** 80 * Title of the panel to show in UI. 81 * 82 * @since 4.0.0 83 * @var string 84 */ 85 public $title = ''; 86 87 /** 88 * Description to show in the UI. 89 * 90 * @since 4.0.0 91 * @var string 92 */ 93 public $description = ''; 94 95 /** 96 * Auto-expand a section in a panel when the panel is expanded when the panel only has the one section. 97 * 98 * @since 4.7.4 99 * @var bool 100 */ 101 public $auto_expand_sole_section = false; 102 103 /** 104 * Customizer sections for this panel. 105 * 106 * @since 4.0.0 107 * @var array 108 */ 109 public $sections; 110 111 /** 112 * Type of this panel. 113 * 114 * @since 4.1.0 115 * @var string 116 */ 117 public $type = 'default'; 118 119 /** 120 * Active callback. 121 * 122 * @since 4.1.0 123 * 124 * @see WP_Customize_Section::active() 125 * 126 * @var callable Callback is called with one argument, the instance of 127 * WP_Customize_Section, and returns bool to indicate whether 128 * the section is active (such as it relates to the URL currently 129 * being previewed). 130 */ 131 public $active_callback = ''; 132 133 /** 134 * Constructor. 135 * 136 * Any supplied $args override class property defaults. 137 * 138 * @since 4.0.0 139 * 140 * @param WP_Customize_Manager $manager Customizer bootstrap instance. 141 * @param string $id A specific ID for the panel. 142 * @param array $args { 143 * Optional. Array of properties for the new Panel object. Default empty array. 144 * 145 * @type int $priority Priority of the panel, defining the display order 146 * of panels and sections. Default 160. 147 * @type string $capability Capability required for the panel. 148 * Default `edit_theme_options`. 149 * @type string|string[] $theme_supports Theme features required to support the panel. 150 * @type string $title Title of the panel to show in UI. 151 * @type string $description Description to show in the UI. 152 * @type string $type Type of the panel. 153 * @type callable $active_callback Active callback. 154 * } 155 */ 156 public function __construct( $manager, $id, $args = array() ) { 157 $keys = array_keys( get_object_vars( $this ) ); 158 foreach ( $keys as $key ) { 159 if ( isset( $args[ $key ] ) ) { 160 $this->$key = $args[ $key ]; 161 } 162 } 163 164 $this->manager = $manager; 165 $this->id = $id; 166 if ( empty( $this->active_callback ) ) { 167 $this->active_callback = array( $this, 'active_callback' ); 168 } 169 self::$instance_count += 1; 170 $this->instance_number = self::$instance_count; 171 172 $this->sections = array(); // Users cannot customize the $sections array. 173 } 174 175 /** 176 * Check whether panel is active to current Customizer preview. 177 * 178 * @since 4.1.0 179 * 180 * @return bool Whether the panel is active to the current preview. 181 */ 182 final public function active() { 183 $panel = $this; 184 $active = call_user_func( $this->active_callback, $this ); 185 186 /** 187 * Filters response of WP_Customize_Panel::active(). 188 * 189 * @since 4.1.0 190 * 191 * @param bool $active Whether the Customizer panel is active. 192 * @param WP_Customize_Panel $panel WP_Customize_Panel instance. 193 */ 194 $active = apply_filters( 'customize_panel_active', $active, $panel ); 195 196 return $active; 197 } 198 199 /** 200 * Default callback used when invoking WP_Customize_Panel::active(). 201 * 202 * Subclasses can override this with their specific logic, or they may 203 * provide an 'active_callback' argument to the constructor. 204 * 205 * @since 4.1.0 206 * 207 * @return bool Always true. 208 */ 209 public function active_callback() { 210 return true; 211 } 212 213 /** 214 * Gather the parameters passed to client JavaScript via JSON. 215 * 216 * @since 4.1.0 217 * 218 * @return array The array to be exported to the client as JSON. 219 */ 220 public function json() { 221 $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'type' ) ); 222 $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); 223 $array['content'] = $this->get_content(); 224 $array['active'] = $this->active(); 225 $array['instanceNumber'] = $this->instance_number; 226 $array['autoExpandSoleSection'] = $this->auto_expand_sole_section; 227 return $array; 228 } 229 230 /** 231 * Checks required user capabilities and whether the theme has the 232 * feature support required by the panel. 233 * 234 * @since 4.0.0 235 * @since 5.9.0 Method was marked non-final. 236 * 237 * @return bool False if theme doesn't support the panel or the user doesn't have the capability. 238 */ 239 public function check_capabilities() { 240 if ( $this->capability && ! current_user_can( $this->capability ) ) { 241 return false; 242 } 243 244 if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) { 245 return false; 246 } 247 248 return true; 249 } 250 251 /** 252 * Get the panel's content template for insertion into the Customizer pane. 253 * 254 * @since 4.1.0 255 * 256 * @return string Content for the panel. 257 */ 258 final public function get_content() { 259 ob_start(); 260 $this->maybe_render(); 261 return trim( ob_get_clean() ); 262 } 263 264 /** 265 * Check capabilities and render the panel. 266 * 267 * @since 4.0.0 268 */ 269 final public function maybe_render() { 270 if ( ! $this->check_capabilities() ) { 271 return; 272 } 273 274 /** 275 * Fires before rendering a Customizer panel. 276 * 277 * @since 4.0.0 278 * 279 * @param WP_Customize_Panel $panel WP_Customize_Panel instance. 280 */ 281 do_action( 'customize_render_panel', $this ); 282 283 /** 284 * Fires before rendering a specific Customizer panel. 285 * 286 * The dynamic portion of the hook name, `$this->id`, refers to 287 * the ID of the specific Customizer panel to be rendered. 288 * 289 * @since 4.0.0 290 */ 291 do_action( "customize_render_panel_{$this->id}" ); 292 293 $this->render(); 294 } 295 296 /** 297 * Render the panel container, and then its contents (via `this->render_content()`) in a subclass. 298 * 299 * Panel containers are now rendered in JS by default, see WP_Customize_Panel::print_template(). 300 * 301 * @since 4.0.0 302 */ 303 protected function render() {} 304 305 /** 306 * Render the panel UI in a subclass. 307 * 308 * Panel contents are now rendered in JS by default, see WP_Customize_Panel::print_template(). 309 * 310 * @since 4.1.0 311 */ 312 protected function render_content() {} 313 314 /** 315 * Render the panel's JS templates. 316 * 317 * This function is only run for panel types that have been registered with 318 * WP_Customize_Manager::register_panel_type(). 319 * 320 * @since 4.3.0 321 * 322 * @see WP_Customize_Manager::register_panel_type() 323 */ 324 public function print_template() { 325 ?> 326 <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>-content"> 327 <?php $this->content_template(); ?> 328 </script> 329 <script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>"> 330 <?php $this->render_template(); ?> 331 </script> 332 <?php 333 } 334 335 /** 336 * An Underscore (JS) template for rendering this panel's container. 337 * 338 * Class variables for this panel class are available in the `data` JS object; 339 * export custom variables by overriding WP_Customize_Panel::json(). 340 * 341 * @see WP_Customize_Panel::print_template() 342 * 343 * @since 4.3.0 344 */ 345 protected function render_template() { 346 ?> 347 <li id="accordion-panel-{{ data.id }}" class="accordion-section control-section control-panel control-panel-{{ data.type }}"> 348 <h3 class="accordion-section-title" tabindex="0"> 349 {{ data.title }} 350 <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span> 351 </h3> 352 <ul class="accordion-sub-container control-panel-content"></ul> 353 </li> 354 <?php 355 } 356 357 /** 358 * An Underscore (JS) template for this panel's content (but not its container). 359 * 360 * Class variables for this panel class are available in the `data` JS object; 361 * export custom variables by overriding WP_Customize_Panel::json(). 362 * 363 * @see WP_Customize_Panel::print_template() 364 * 365 * @since 4.3.0 366 */ 367 protected function content_template() { 368 ?> 369 <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> 370 <button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></button> 371 <div class="accordion-section-title"> 372 <span class="preview-notice"> 373 <?php 374 /* translators: %s: The site/panel title in the Customizer. */ 375 printf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); 376 ?> 377 </span> 378 <# if ( data.description ) { #> 379 <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button> 380 <# } #> 381 </div> 382 <# if ( data.description ) { #> 383 <div class="description customize-panel-description"> 384 {{{ data.description }}} 385 </div> 386 <# } #> 387 388 <div class="customize-control-notifications-container"></div> 389 </li> 390 <?php 391 } 392 } 393 394 /** WP_Customize_Nav_Menus_Panel class */ 395 require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |