]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-wp-customize-section.php
Wordpress 3.5.2
[autoinstalls/wordpress.git] / wp-includes / class-wp-customize-section.php
1 <?php
2 /**
3  * Customize Section Class.
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 3.4.0
8  */
9 class WP_Customize_Section {
10         public $manager;
11         public $id;
12         public $priority       = 10;
13         public $capability     = 'edit_theme_options';
14         public $theme_supports = '';
15         public $title          = '';
16         public $description    = '';
17         public $controls;
18
19         /**
20          * Constructor.
21          *
22          * @since 3.4.0
23          *
24          * @param WP_Customize_Manager $manager
25          * @param string $id An specific ID of the section.
26          * @param array $args Section arguments.
27          */
28         function __construct( $manager, $id, $args = array() ) {
29                 $keys = array_keys( get_class_vars( __CLASS__ ) );
30                 foreach ( $keys as $key ) {
31                         if ( isset( $args[ $key ] ) )
32                                 $this->$key = $args[ $key ];
33                 }
34
35                 $this->manager = $manager;
36                 $this->id = $id;
37
38                 $this->controls = array(); // Users cannot customize the $controls array.
39
40                 return $this;
41         }
42
43         /**
44          * Check if the theme supports the section and check user capabilities.
45          *
46          * @since 3.4.0
47          *
48          * @return bool False if theme doesn't support the section or user doesn't have the capability.
49          */
50         public final function check_capabilities() {
51                 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
52                         return false;
53
54                 if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
55                         return false;
56
57                 return true;
58         }
59
60         /**
61          * Check capabilities and render the section.
62          *
63          * @since 3.4.0
64          */
65         public final function maybe_render() {
66                 if ( ! $this->check_capabilities() )
67                         return;
68
69                 do_action( 'customize_render_section', $this );
70                 do_action( 'customize_render_section_' . $this->id );
71
72                 $this->render();
73         }
74
75         /**
76          * Render the section.
77          *
78          * @since 3.4.0
79          */
80         protected function render() {
81                 ?>
82                 <li id="customize-section-<?php echo esc_attr( $this->id ); ?>" class="control-section customize-section">
83                         <h3 class="customize-section-title" tabindex="0" title="<?php echo esc_attr( $this->description ); ?>"><?php echo esc_html( $this->title ); ?></h3>
84                         <ul class="customize-section-content">
85                                 <?php
86                                 foreach ( $this->controls as $control )
87                                         $control->maybe_render();
88                                 ?>
89                         </ul>
90                 </li>
91                 <?php
92         }
93 }