Ticket #29197: 28979.2.class-wp-customize-section.diff
File 28979.2.class-wp-customize-section.diff, 8.9 KB (added by , 10 years ago) |
---|
-
class-wp-customize-section.php
1 1 <?php 2 2 /** 3 * Customize SectionClass.3 * Customize Container Class. 4 4 * 5 * A UI container for controls, managed by the WP_Customize_Manager.5 * A UI container for Customizer components, managed by the WP_Customize_Manager. 6 6 * 7 7 * @package WordPress 8 8 * @subpackage Customize 9 * @since 3.4.09 * @since 4.0.0 10 10 */ 11 class WP_Customize_Section{11 abstract class WP_Customize_Container { 12 12 13 13 /** 14 14 * WP_Customize_Manager instance. 15 15 * 16 * @since 3.4.016 * @since 4.0.0 17 17 * @access public 18 18 * @var WP_Customize_Manager 19 19 */ … … 22 22 /** 23 23 * Unique identifier. 24 24 * 25 * @since 3.4.025 * @since 4.0.0 26 26 * @access public 27 27 * @var string 28 28 */ … … 29 29 public $id; 30 30 31 31 /** 32 * Priority of the section which informs load order of sections.32 * Priority of the container, which determines display order. 33 33 * 34 * @since 3.4.034 * @since 4.0.0 35 35 * @access public 36 36 * @var integer 37 37 */ 38 public $priority = 1 0;38 public $priority = 160; 39 39 40 40 /** 41 * Panel in which to show the section, making it a sub-section.41 * Capability required for the container. 42 42 * 43 43 * @since 4.0.0 44 44 * @access public 45 45 * @var string 46 46 */ 47 public $panel = '';48 49 /**50 * Capability required for the section.51 *52 * @since 3.4.053 * @access public54 * @var string55 */56 47 public $capability = 'edit_theme_options'; 57 48 58 49 /** 59 * Theme feature support for the section.50 * Theme feature support requied for the container. 60 51 * 61 * @since 3.4.052 * @since 4.0.0 62 53 * @access public 63 54 * @var string|array 64 55 */ … … 65 56 public $theme_supports = ''; 66 57 67 58 /** 68 * Title of the section to show inUI.59 * Title to show in the UI. 69 60 * 70 * @since 3.4.061 * @since 4.0.0 71 62 * @access public 72 63 * @var string 73 64 */ … … 76 67 /** 77 68 * Description to show in the UI. 78 69 * 79 * @since 3.4.070 * @since 4.0.0 80 71 * @access public 81 72 * @var string 82 73 */ … … 83 74 public $description = ''; 84 75 85 76 /** 86 * Customizer controls for this section.87 *88 * @since 3.4.089 * @access public90 * @var array91 */92 public $controls;93 94 /**95 77 * Constructor. 96 78 * 97 79 * Any supplied $args override class property defaults. 98 80 * 99 * @since 3.4.081 * @since 4.0.0 100 82 * 101 83 * @param WP_Customize_Manager $manager Customizer bootstrap instance. 102 * @param string $id An specific ID of the section.103 * @param array $args Sectionarguments.84 * @param string $id An specific ID for the container. 85 * @param array $args Container arguments. 104 86 */ 105 87 public function __construct( $manager, $id, $args = array() ) { 106 88 $keys = array_keys( get_object_vars( $this ) ); … … 112 94 $this->manager = $manager; 113 95 $this->id = $id; 114 96 115 $this->controls = array(); // Users cannot customize the $controls array.116 117 97 return $this; 118 98 } 119 99 120 100 /** 121 101 * Checks required user capabilities and whether the theme has the 122 * feature support required by the section.102 * feature support required by the container. 123 103 * 124 * @since 3.4.0104 * @since 4.0.0 125 105 * 126 * @return bool False if theme doesn't support the sectionor user doesn't have the capability.106 * @return bool False if theme doesn't support the container or user doesn't have the capability. 127 107 */ 128 108 public final function check_capabilities() { 129 109 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) … … 136 116 } 137 117 138 118 /** 139 * Check capabilities and render the section.119 * Check capabilities and render the container. 140 120 * 141 * @since 3.4.0121 * @since 4.0.0 142 122 */ 143 123 public final function maybe_render() { 144 124 if ( ! $this->check_capabilities() ) … … 145 125 return; 146 126 147 127 /** 148 * Fires before rendering a Customizer section .128 * Fires before rendering a Customizer section (or panel). 149 129 * 150 130 * @since 3.4.0 151 131 * … … 152 132 * @param WP_Customize_Section $this WP_Customize_Section instance. 153 133 */ 154 134 do_action( 'customize_render_section', $this ); 135 155 136 /** 156 * Fires before rendering a specific Customizer section .137 * Fires before rendering a specific Customizer section (or panel). 157 138 * 158 139 * The dynamic portion of the hook name, $this->id, refers to the ID 159 * of the specific Customizer sectionto be rendered.140 * of the specific Customizer container to be rendered. 160 141 * 161 142 * @since 3.4.0 162 143 */ … … 166 147 } 167 148 168 149 /** 169 * Render the section, and the controls that have been added to it.150 * Render the container, and the objects that have been added to it. 170 151 * 171 * @since 3.4.0152 * @since 4.0.0 172 153 */ 173 protected function render() { 174 $classes = 'control-section accordion-section'; 175 if ( $this->panel ) { 176 $classes .= ' control-subsection'; 177 } 178 ?> 179 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> 180 <h3 class="accordion-section-title" tabindex="0"> 181 <?php echo esc_html( $this->title ); ?> 182 <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span> 183 </h3> 184 <ul class="accordion-section-content"> 185 <?php if ( ! empty( $this->description ) ) : ?> 186 <li><p class="description customize-section-description"><?php echo $this->description; ?></p></li> 187 <?php endif; ?> 188 <?php 189 foreach ( $this->controls as $control ) 190 $control->maybe_render(); 191 ?> 192 </ul> 193 </li> 194 <?php 195 } 154 abstract protected function render(); 196 155 } 197 156 157 198 158 /** 199 159 * Customize Panel Class. 200 160 * … … 204 164 * @subpackage Customize 205 165 * @since 4.0.0 206 166 */ 207 class WP_Customize_Panel extends WP_Customize_ Section{167 class WP_Customize_Panel extends WP_Customize_Container { 208 168 209 169 /** 210 170 * Customizer sections for this panel. … … 243 203 */ 244 204 protected function render() { 245 205 ?> 246 <li id="accordion- section-<?php echo esc_attr( $this->id ); ?>" class="control-section control-panel accordion-section">206 <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="control-section control-panel accordion-section"> 247 207 <h3 class="accordion-section-title" tabindex="0"> 248 208 <?php echo esc_html( $this->title ); ?> 249 209 <span class="screen-reader-text"><?php _e( 'Press return or enter to open panel' ); ?></span> … … 253 213 <li class="accordion-section control-section<?php if ( empty( $this->description ) ) echo ' cannot-expand'; ?>"> 254 214 <div class="accordion-section-title" tabindex="0"> 255 215 <span class="preview-notice"><?php 256 /* translators: %s is the site/panel title in the Customize pane*/216 /* translators: %s is the site/panel title in the Customizer */ 257 217 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' ); 258 218 ?></span> 259 219 </div> … … 273 233 <?php 274 234 } 275 235 } 236 237 238 /** 239 * Customize Section Class. 240 * 241 * A UI container for controls, managed by the WP_Customize_Manager. 242 * 243 * @package WordPress 244 * @subpackage Customize 245 * @since 3.4.0 246 */ 247 class WP_Customize_Section extends WP_Customize_Container { 248 249 /** 250 * Panel in which to show the section, making it a sub-section. 251 * 252 * @since 4.0.0 253 * @access public 254 * @var string 255 */ 256 public $panel = ''; 257 258 /** 259 * Customizer controls for this section. 260 * 261 * @since 3.4.0 262 * @access public 263 * @var array 264 */ 265 public $controls; 266 267 /** 268 * Constructor. 269 * 270 * Any supplied $args override class property defaults. 271 * 272 * @since 3.4.0 273 * 274 * @param WP_Customize_Manager $manager Customizer bootstrap instance. 275 * @param string $id An specific ID of the section. 276 * @param array $args Section arguments. 277 */ 278 public function __construct( $manager, $id, $args = array() ) { 279 parent::__construct( $manager, $id, $args ); 280 281 $this->controls = array(); // Users cannot customize the $controls array. 282 283 return $this; 284 } 285 286 /** 287 * Render the section, and the controls that have been added to it. 288 * 289 * @since 3.4.0 290 */ 291 protected function render() { 292 $classes = 'control-section accordion-section'; 293 if ( $this->panel ) { 294 $classes .= ' control-subsection'; 295 } 296 ?> 297 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> 298 <h3 class="accordion-section-title" tabindex="0"> 299 <?php echo esc_html( $this->title ); ?> 300 <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span> 301 </h3> 302 <ul class="accordion-section-content"> 303 <?php if ( ! empty( $this->description ) ) : ?> 304 <li><p class="description customize-section-description"><?php echo $this->description; ?></p></li> 305 <?php endif; ?> 306 <?php 307 foreach ( $this->controls as $control ) 308 $control->maybe_render(); 309 ?> 310 </ul> 311 </li> 312 <?php 313 } 314 }