]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-customize-manager.php
WordPress 4.3
[autoinstalls/wordpress.git] / wp-includes / class-wp-customize-manager.php
index 8d78bddaef092b44a470b08a840dac710d3b39ab..9cac338591189dc687fab0b940466d838c4f36bd 100644 (file)
@@ -38,7 +38,7 @@ final class WP_Customize_Manager {
        /**
         * Whether this is a Customizer pageload.
         *
-        * @var boolean
+        * @var bool
         */
        protected $previewing = false;
 
@@ -49,6 +49,13 @@ final class WP_Customize_Manager {
         */
        public $widgets;
 
+       /**
+        * Methods and properties deailing with managing nav menus in the Customizer.
+        *
+        * @var WP_Customize_Nav_Menus
+        */
+       public $nav_menus;
+
        protected $settings   = array();
        protected $containers = array();
        protected $panels     = array();
@@ -60,7 +67,25 @@ final class WP_Customize_Manager {
        protected $customized;
 
        /**
-        * Controls that may be rendered from JS templates.
+        * Panel types that may be rendered from JS templates.
+        *
+        * @since 4.3.0
+        * @access protected
+        * @var array
+        */
+       protected $registered_panel_types = array();
+
+       /**
+        * Section types that may be rendered from JS templates.
+        *
+        * @since 4.3.0
+        * @access protected
+        * @var array
+        */
+       protected $registered_section_types = array();
+
+       /**
+        * Control types that may be rendered from JS templates.
         *
         * @since 4.1.0
         * @access protected
@@ -86,8 +111,10 @@ final class WP_Customize_Manager {
                require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
                require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
                require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
+               require_once( ABSPATH . WPINC . '/class-wp-customize-nav-menus.php' );
 
                $this->widgets = new WP_Customize_Widgets( $this );
+               $this->nav_menus = new WP_Customize_Nav_Menus( $this );
 
                add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
 
@@ -612,19 +639,29 @@ final class WP_Customize_Manager {
                }
 
                foreach ( $this->settings as $id => $setting ) {
-                       $settings['values'][ $id ] = $setting->js_value();
+                       if ( $setting->check_capabilities() ) {
+                               $settings['values'][ $id ] = $setting->js_value();
+                       }
                }
-               foreach ( $this->panels as $id => $panel ) {
-                       $settings['activePanels'][ $id ] = $panel->active();
-                       foreach ( $panel->sections as $id => $section ) {
-                               $settings['activeSections'][ $id ] = $section->active();
+               foreach ( $this->panels as $panel_id => $panel ) {
+                       if ( $panel->check_capabilities() ) {
+                               $settings['activePanels'][ $panel_id ] = $panel->active();
+                               foreach ( $panel->sections as $section_id => $section ) {
+                                       if ( $section->check_capabilities() ) {
+                                               $settings['activeSections'][ $section_id ] = $section->active();
+                                       }
+                               }
                        }
                }
                foreach ( $this->sections as $id => $section ) {
-                       $settings['activeSections'][ $id ] = $section->active();
+                       if ( $section->check_capabilities() ) {
+                               $settings['activeSections'][ $id ] = $section->active();
+                       }
                }
                foreach ( $this->controls as $id => $control ) {
-                       $settings['activeControls'][ $id ] = $control->active();
+                       if ( $control->check_capabilities() ) {
+                               $settings['activeControls'][ $id ] = $control->active();
+                       }
                }
 
                ?>
@@ -647,6 +684,8 @@ final class WP_Customize_Manager {
         * Removes the signature in case we experience a case where the Customizer was not properly executed.
         *
         * @since 3.4.0
+        *
+        * @return mixed
         */
        public function remove_preview_signature( $return = null ) {
                remove_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 );
@@ -841,7 +880,7 @@ final class WP_Customize_Manager {
         *
         * @since 4.2.0
         *
-        * @param string $setting_ids The setting IDs to add.
+        * @param array $setting_ids The setting IDs to add.
         * @return WP_Customize_Setting The settings added.
         */
        public function add_dynamic_settings( $setting_ids ) {
@@ -879,7 +918,7 @@ final class WP_Customize_Manager {
                         *
                         * @param string $setting_class WP_Customize_Setting or a subclass.
                         * @param string $setting_id    ID for dynamic setting, usually coming from `$_POST['customized']`.
-                        * @param string $setting_args  WP_Customize_Setting or a subclass.
+                        * @param array  $setting_args  WP_Customize_Setting or a subclass.
                         */
                        $setting_class = apply_filters( 'customize_dynamic_setting_class', $setting_class, $setting_id, $setting_args );
 
@@ -897,7 +936,7 @@ final class WP_Customize_Manager {
         * @since 3.4.0
         *
         * @param string $id Customize Setting ID.
-        * @return WP_Customize_Setting
+        * @return WP_Customize_Setting|void The setting, if set.
         */
        public function get_setting( $id ) {
                if ( isset( $this->settings[ $id ] ) ) {
@@ -942,7 +981,7 @@ final class WP_Customize_Manager {
         * @access public
         *
         * @param string $id Panel ID to get.
-        * @return WP_Customize_Panel Requested panel instance.
+        * @return WP_Customize_Panel|void Requested panel instance, if set.
         */
        public function get_panel( $id ) {
                if ( isset( $this->panels[ $id ] ) ) {
@@ -962,6 +1001,35 @@ final class WP_Customize_Manager {
                unset( $this->panels[ $id ] );
        }
 
+       /**
+        * Register a customize panel type.
+        *
+        * Registered types are eligible to be rendered via JS and created dynamically.
+        *
+        * @since 4.3.0
+        * @access public
+        *
+        * @see WP_Customize_Panel
+        *
+        * @param string $panel Name of a custom panel which is a subclass of WP_Customize_Panel.
+        */
+       public function register_panel_type( $panel ) {
+               $this->registered_panel_types[] = $panel;
+       }
+
+       /**
+        * Render JS templates for all registered panel types.
+        *
+        * @since 4.3.0
+        * @access public
+        */
+       public function render_panel_templates() {
+               foreach ( $this->registered_panel_types as $panel_type ) {
+                       $panel = new $panel_type( $this, 'temp', array() );
+                       $panel->print_template();
+               }
+       }
+
        /**
         * Add a customize section.
         *
@@ -985,7 +1053,7 @@ final class WP_Customize_Manager {
         * @since 3.4.0
         *
         * @param string $id Section ID.
-        * @return WP_Customize_Section
+        * @return WP_Customize_Section|void The section, if set.
         */
        public function get_section( $id ) {
                if ( isset( $this->sections[ $id ] ) )
@@ -1003,6 +1071,35 @@ final class WP_Customize_Manager {
                unset( $this->sections[ $id ] );
        }
 
+       /**
+        * Register a customize section type.
+        *
+        * Registered types are eligible to be rendered via JS and created dynamically.
+        *
+        * @since 4.3.0
+        * @access public
+        *
+        * @see WP_Customize_Section
+        *
+        * @param string $section Name of a custom section which is a subclass of WP_Customize_Section.
+        */
+       public function register_section_type( $section ) {
+               $this->registered_section_types[] = $section;
+       }
+
+       /**
+        * Render JS templates for all registered section types.
+        *
+        * @since 4.3.0
+        * @access public
+        */
+       public function render_section_templates() {
+               foreach ( $this->registered_section_types as $section_type ) {
+                       $section = new $section_type( $this, 'temp', array() );
+                       $section->print_template();
+               }
+       }
+
        /**
         * Add a customize control.
         *
@@ -1027,7 +1124,7 @@ final class WP_Customize_Manager {
         * @since 3.4.0
         *
         * @param string $id ID of the control.
-        * @return WP_Customize_Control $control The control object.
+        * @return WP_Customize_Control|void The control object, if set.
         */
        public function get_control( $id ) {
                if ( isset( $this->controls[ $id ] ) )
@@ -1119,7 +1216,7 @@ final class WP_Customize_Manager {
                $sections = array();
 
                foreach ( $this->sections as $section ) {
-                       if ( ! $section->check_capabilities() || ! $section->controls ) {
+                       if ( ! $section->check_capabilities() ) {
                                continue;
                        }
 
@@ -1142,7 +1239,7 @@ final class WP_Customize_Manager {
                $panels = array();
 
                foreach ( $this->panels as $panel ) {
-                       if ( ! $panel->check_capabilities() || ! $panel->sections ) {
+                       if ( ! $panel->check_capabilities() ) {
                                continue;
                        }
 
@@ -1174,12 +1271,17 @@ final class WP_Customize_Manager {
         */
        public function register_controls() {
 
-               /* Control Types (custom control classes) */
+               /* Panel, Section, and Control Types */
+               $this->register_panel_type( 'WP_Customize_Panel' );
+               $this->register_section_type( 'WP_Customize_Section' );
+               $this->register_section_type( 'WP_Customize_Sidebar_Section' );
                $this->register_control_type( 'WP_Customize_Color_Control' );
                $this->register_control_type( 'WP_Customize_Media_Control' );
                $this->register_control_type( 'WP_Customize_Upload_Control' );
                $this->register_control_type( 'WP_Customize_Image_Control' );
                $this->register_control_type( 'WP_Customize_Background_Image_Control' );
+               $this->register_control_type( 'WP_Customize_Cropped_Image_Control' );
+               $this->register_control_type( 'WP_Customize_Site_Icon_Control' );
                $this->register_control_type( 'WP_Customize_Theme_Control' );
 
                /* Themes */
@@ -1226,10 +1328,10 @@ final class WP_Customize_Manager {
                        ) ) );
                }
 
-               /* Site Title & Tagline */
+               /* Site Identity */
 
                $this->add_section( 'title_tagline', array(
-                       'title'    => __( 'Site Title & Tagline' ),
+                       'title'    => __( 'Site Identity' ),
                        'priority' => 20,
                ) );
 
@@ -1255,6 +1357,21 @@ final class WP_Customize_Manager {
                        'section'    => 'title_tagline',
                ) );
 
+               $this->add_setting( 'site_icon', array(
+                       'type'       => 'option',
+                       'capability' => 'manage_options',
+                       'transport'  => 'postMessage', // Previewed with JS in the Customizer controls window.
+               ) );
+
+               $this->add_control( new WP_Customize_Site_Icon_Control( $this, 'site_icon', array(
+                       'label'       => __( 'Site Icon' ),
+                       'description' => __( 'The Site Icon is used as a browser and app icon for your site. Icons must be square, and at least 512px wide and tall.' ),
+                       'section'     => 'title_tagline',
+                       'priority'    => 60,
+                       'height'      => 512,
+                       'width'       => 512,
+               ) ) );
+
                /* Colors */
 
                $this->add_section( 'colors', array(
@@ -1277,6 +1394,7 @@ final class WP_Customize_Manager {
                        'label'    => __( 'Display Header Text' ),
                        'section'  => 'title_tagline',
                        'type'     => 'checkbox',
+                       'priority' => 40,
                ) );
 
                $this->add_control( new WP_Customize_Color_Control( $this, 'header_textcolor', array(
@@ -1395,48 +1513,6 @@ final class WP_Customize_Manager {
                        }
                }
 
-               /* Nav Menus */
-
-               $locations      = get_registered_nav_menus();
-               $menus          = wp_get_nav_menus();
-               $num_locations  = count( array_keys( $locations ) );
-
-               if ( 1 == $num_locations ) {
-                       $description = __( 'Your theme supports one menu. Select which menu you would like to use.' );
-               } else {
-                       $description = sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) );
-               }
-
-               $this->add_section( 'nav', array(
-                       'title'          => __( 'Navigation' ),
-                       'theme_supports' => 'menus',
-                       'priority'       => 100,
-                       'description'    => $description . "\n\n" . __( 'You can edit your menu content on the Menus screen in the Appearance section.' ),
-               ) );
-
-               if ( $menus ) {
-                       $choices = array( '' => __( '— Select —' ) );
-                       foreach ( $menus as $menu ) {
-                               $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
-                       }
-
-                       foreach ( $locations as $location => $description ) {
-                               $menu_setting_id = "nav_menu_locations[{$location}]";
-
-                               $this->add_setting( $menu_setting_id, array(
-                                       'sanitize_callback' => 'absint',
-                                       'theme_supports'    => 'menus',
-                               ) );
-
-                               $this->add_control( $menu_setting_id, array(
-                                       'label'   => $description,
-                                       'section' => 'nav',
-                                       'type'    => 'select',
-                                       'choices' => $choices,
-                               ) );
-                       }
-               }
-
                /* Static Front Page */
                // #WP19627
 
@@ -1513,7 +1589,7 @@ final class WP_Customize_Manager {
         * @since 3.4.0
         *
         * @param string $color
-        * @return string
+        * @return mixed
         */
        public function _sanitize_header_textcolor( $color ) {
                if ( 'blank' === $color )
@@ -1530,13 +1606,13 @@ final class WP_Customize_Manager {
 /**
  * Sanitizes a hex color.
  *
- * Returns either '', a 3 or 6 digit hex color (with #), or null.
+ * Returns either '', a 3 or 6 digit hex color (with #), or nothing.
  * For sanitizing values without a #, see sanitize_hex_color_no_hash().
  *
  * @since 3.4.0
  *
  * @param string $color
- * @return string|null
+ * @return string|void
  */
 function sanitize_hex_color( $color ) {
        if ( '' === $color )
@@ -1545,8 +1621,6 @@ function sanitize_hex_color( $color ) {
        // 3 or 6 hex digits, or the empty string.
        if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
                return $color;
-
-       return null;
 }
 
 /**