WordPress 3.4
[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
10 class WP_Customize_Section {
11         public $manager;
12         public $id;
13         public $priority       = 10;
14         public $capability     = 'edit_theme_options';
15         public $theme_supports = '';
16         public $title          = '';
17         public $description    = '';
18         public $controls;
19
20         /**
21          * Constructor.
22          *
23          * @since 3.4.0
24          *
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         /**
77          * Render the section.
78          *
79          * @since 3.4.0
80          */
81         protected function render() {
82                 ?>
83                 <li id="customize-section-<?php echo esc_attr( $this->id ); ?>" class="control-section customize-section">
84                         <h3 class="customize-section-title" title="<?php echo esc_attr( $this->description ); ?>"><?php echo esc_html( $this->title ); ?></h3>
85                         <ul class="customize-section-content">
86                                 <?php
87                                 foreach ( $this->controls as $control )
88                                         $control->maybe_render();
89                                 ?>
90                         </ul>
91                 </li>
92                 <?php
93         }
94 }