3 * Customize Panel Class.
5 * A UI container for sections, managed by the WP_Customize_Manager.
8 * @subpackage Customize
11 class WP_Customize_Panel {
14 * WP_Customize_Manager instance.
18 * @var WP_Customize_Manager
32 * Priority of the panel, defining the display order of panels and sections.
38 public $priority = 160;
41 * Capability required for the panel.
47 public $capability = 'edit_theme_options';
50 * Theme feature support for the panel.
56 public $theme_supports = '';
59 * Title of the panel to show in UI.
68 * Description to show in the UI.
74 public $description = '';
77 * Customizer sections for this panel.
88 * Any supplied $args override class property defaults.
92 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
93 * @param string $id An specific ID for the panel.
94 * @param array $args Panel arguments.
96 public function __construct( $manager, $id, $args = array() ) {
97 $keys = array_keys( get_object_vars( $this ) );
98 foreach ( $keys as $key ) {
99 if ( isset( $args[ $key ] ) ) {
100 $this->$key = $args[ $key ];
104 $this->manager = $manager;
107 $this->sections = array(); // Users cannot customize the $sections array.
113 * Checks required user capabilities and whether the theme has the
114 * feature support required by the panel.
118 * @return bool False if theme doesn't support the panel or the user doesn't have the capability.
120 public final function check_capabilities() {
121 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
125 if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
133 * Check capabilities and render the panel.
137 public final function maybe_render() {
138 if ( ! $this->check_capabilities() ) {
143 * Fires before rendering a Customizer panel.
147 * @param WP_Customize_Panel $this WP_Customize_Panel instance.
149 do_action( 'customize_render_panel', $this );
152 * Fires before rendering a specific Customizer panel.
154 * The dynamic portion of the hook name, $this->id, refers to the ID
155 * of the specific Customizer panel to be rendered.
159 do_action( "customize_render_panel_{$this->id}" );
165 * Render the panel, and the sections that have been added to it.
170 protected function render() {
172 <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="control-section control-panel accordion-section">
173 <h3 class="accordion-section-title" tabindex="0">
174 <?php echo esc_html( $this->title ); ?>
175 <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span>
177 <ul class="accordion-sub-container control-panel-content">
178 <li class="accordion-section control-section<?php if ( empty( $this->description ) ) echo ' cannot-expand'; ?>">
179 <div class="accordion-section-title" tabindex="0">
180 <span class="preview-notice"><?php
181 /* translators: %s is the site/panel title in the Customizer */
182 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
185 <?php if ( ! empty( $this->description ) ) : ?>
186 <div class="accordion-section-content description">
187 <?php echo $this->description; ?>
192 foreach ( $this->sections as $section ) {
193 $section->maybe_render();