From 6f5777ecbf4e271efb427c9c6227e574b9374d22 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Oct 2017 21:44:48 +0000 Subject: [PATCH] Customize: Register the Publish Settings section in JS to ensure it does not get unregistered via PHP. The `publish_settings` section is a fundamental dependency for Customizer, so it must be guaranteed to be registered. Also unconditionally register core types for panels, sections, and controls in case plugin unhooks all `customize_register` actions. See #39896. Fixes #42337. git-svn-id: https://develop.svn.wordpress.org/trunk@42025 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 9 ++++ .../class-wp-customize-manager.php | 47 +++++++------------ src/wp-includes/script-loader.php | 1 + 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index deafe6c2ca..47e546f9d3 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -7001,6 +7001,15 @@ publishSettingsBtn = $( '#publish-settings' ), footerActions = $( '#customize-footer-actions' ); + // Add publish settings section in JS instead of PHP since the Customizer depends on it to function. + api.bind( 'ready', function() { + api.section.add( new api.OuterSection( 'publish_settings', { + title: api.l10n.publishSettings, + priority: 0, + active: api.settings.theme.active + } ) ); + } ); + // Set up publish settings section and its controls. api.section( 'publish_settings', function( section ) { var updateButtonsState, trashControl, updateSectionActive, isSectionActive, statusControl, dateControl, toggleDateControl, publishWhenTime, pollInterval, updateTimeArrivedPoller, cancelScheduleButtonReminder, timeArrivedPollingInterval = 1000; diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 21760bad4f..ba2a543312 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -891,6 +891,24 @@ final class WP_Customize_Manager { */ public function wp_loaded() { + // Unconditionally register core types for panels, sections, and controls in case plugin unhooks all customize_register actions. + $this->register_panel_type( 'WP_Customize_Panel' ); + $this->register_panel_type( 'WP_Customize_Themes_Panel' ); + $this->register_section_type( 'WP_Customize_Section' ); + $this->register_section_type( 'WP_Customize_Sidebar_Section' ); + $this->register_section_type( 'WP_Customize_Themes_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_Background_Position_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' ); + $this->register_control_type( 'WP_Customize_Code_Editor_Control' ); + $this->register_control_type( 'WP_Customize_Date_Time_Control' ); + /** * Fires once WordPress has loaded, allowing scripts and styles to be initialized. * @@ -4726,35 +4744,6 @@ final class WP_Customize_Manager { */ public function register_controls() { - /* Panel, Section, and Control Types */ - $this->register_panel_type( 'WP_Customize_Panel' ); - $this->register_panel_type( 'WP_Customize_Themes_Panel' ); - $this->register_section_type( 'WP_Customize_Section' ); - $this->register_section_type( 'WP_Customize_Sidebar_Section' ); - $this->register_section_type( 'WP_Customize_Themes_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_Background_Position_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' ); - $this->register_control_type( 'WP_Customize_Code_Editor_Control' ); - $this->register_control_type( 'WP_Customize_Date_Time_Control' ); - - /* Publish Settings */ - - // Note the controls for this section are added via JS. - $this->add_section( 'publish_settings', array( - 'title' => __( 'Publish Settings' ), - 'priority' => 0, - 'capability' => 'customize', - 'type' => 'outer', - 'active_callback' => array( $this, 'is_theme_active' ), - ) ); - /* Themes (controls are loaded via ajax) */ $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 6c2312c397..c43659379d 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -598,6 +598,7 @@ function wp_default_scripts( &$scripts ) { __( 'You won’t be able to install new themes from here yet since your install requires SFTP credentials. For now, please add themes in the admin.' ), esc_url( admin_url( 'theme-install.php' ) ) ), + 'publishSettings' => __( 'Publish Settings' ), ) ); $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );