wp/wp-includes/class-wp-customize-manager.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   159 
   159 
   160 	/**
   160 	/**
   161 	 * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
   161 	 * Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
   162 	 *
   162 	 *
   163 	 * @since 4.4.0
   163 	 * @since 4.4.0
   164 	 * @var array
   164 	 * @var string[]
   165 	 */
   165 	 */
   166 	protected $autofocus = array();
   166 	protected $autofocus = array();
   167 
   167 
   168 	/**
   168 	/**
   169 	 * Messenger channel.
   169 	 * Messenger channel.
   344 		 * @since 4.4.0
   344 		 * @since 4.4.0
   345 		 *
   345 		 *
   346 		 * @see WP_Customize_Manager::__construct()
   346 		 * @see WP_Customize_Manager::__construct()
   347 		 *
   347 		 *
   348 		 * @param string[]             $components Array of core components to load.
   348 		 * @param string[]             $components Array of core components to load.
   349 		 * @param WP_Customize_Manager $this       WP_Customize_Manager instance.
   349 		 * @param WP_Customize_Manager $manager    WP_Customize_Manager instance.
   350 		 */
   350 		 */
   351 		$components = apply_filters( 'customize_loaded_components', $this->components, $this );
   351 		$components = apply_filters( 'customize_loaded_components', $this->components, $this );
   352 
   352 
   353 		require_once ABSPATH . WPINC . '/customize/class-wp-customize-selective-refresh.php';
   353 		require_once ABSPATH . WPINC . '/customize/class-wp-customize-selective-refresh.php';
   354 		$this->selective_refresh = new WP_Customize_Selective_Refresh( $this );
   354 		$this->selective_refresh = new WP_Customize_Selective_Refresh( $this );
   405 			add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' );
   405 			add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' );
   406 		}
   406 		}
   407 	}
   407 	}
   408 
   408 
   409 	/**
   409 	/**
   410 	 * Return true if it's an Ajax request.
   410 	 * Returns true if it's an Ajax request.
   411 	 *
   411 	 *
   412 	 * @since 3.4.0
   412 	 * @since 3.4.0
   413 	 * @since 4.2.0 Added `$action` param.
   413 	 * @since 4.2.0 Added `$action` param.
   414 	 *
   414 	 *
   415 	 * @param string|null $action Whether the supplied Ajax action is being run.
   415 	 * @param string|null $action Whether the supplied Ajax action is being run.
   474 
   474 
   475 		wp_die( $message );
   475 		wp_die( $message );
   476 	}
   476 	}
   477 
   477 
   478 	/**
   478 	/**
   479 	 * Return the Ajax wp_die() handler if it's a customized request.
   479 	 * Returns the Ajax wp_die() handler if it's a customized request.
   480 	 *
   480 	 *
   481 	 * @since 3.4.0
   481 	 * @since 3.4.0
   482 	 * @deprecated 4.7.0
   482 	 * @deprecated 4.7.0
   483 	 *
   483 	 *
   484 	 * @return callable Die handler.
   484 	 * @return callable Die handler.
   492 
   492 
   493 		return '_default_wp_die_handler';
   493 		return '_default_wp_die_handler';
   494 	}
   494 	}
   495 
   495 
   496 	/**
   496 	/**
   497 	 * Start preview and customize theme.
   497 	 * Starts preview and customize theme.
   498 	 *
   498 	 *
   499 	 * Check if customize query variable exist. Init filters to filter the current theme.
   499 	 * Check if customize query variable exist. Init filters to filter the active theme.
   500 	 *
   500 	 *
   501 	 * @since 3.4.0
   501 	 * @since 3.4.0
   502 	 *
   502 	 *
   503 	 * @global string $pagenow
   503 	 * @global string $pagenow The filename of the current screen.
   504 	 */
   504 	 */
   505 	public function setup_theme() {
   505 	public function setup_theme() {
   506 		global $pagenow;
   506 		global $pagenow;
   507 
   507 
   508 		// Check permissions for customize.php access since this method is called before customize.php can run any code.
   508 		// Check permissions for customize.php access since this method is called before customize.php can run any code.
   595 
   595 
   596 		$this->start_previewing_theme();
   596 		$this->start_previewing_theme();
   597 	}
   597 	}
   598 
   598 
   599 	/**
   599 	/**
   600 	 * Establish the loaded changeset.
   600 	 * Establishes the loaded changeset.
   601 	 *
   601 	 *
   602 	 * This method runs right at after_setup_theme and applies the 'customize_changeset_branching' filter to determine
   602 	 * This method runs right at after_setup_theme and applies the 'customize_changeset_branching' filter to determine
   603 	 * whether concurrent changesets are allowed. Then if the Customizer is not initialized with a `changeset_uuid` param,
   603 	 * whether concurrent changesets are allowed. Then if the Customizer is not initialized with a `changeset_uuid` param,
   604 	 * this method will determine which UUID should be used. If changeset branching is disabled, then the most saved
   604 	 * this method will determine which UUID should be used. If changeset branching is disabled, then the most saved
   605 	 * changeset will be loaded by default. Otherwise, if there are no existing saved changesets or if changeset branching is
   605 	 * changeset will be loaded by default. Otherwise, if there are no existing saved changesets or if changeset branching is
   606 	 * enabled, then a new UUID will be generated.
   606 	 * enabled, then a new UUID will be generated.
   607 	 *
   607 	 *
   608 	 * @since 4.9.0
   608 	 * @since 4.9.0
   609 	 *
   609 	 *
   610 	 * @global string $pagenow
   610 	 * @global string $pagenow The filename of the current screen.
   611 	 */
   611 	 */
   612 	public function establish_loaded_changeset() {
   612 	public function establish_loaded_changeset() {
   613 		global $pagenow;
   613 		global $pagenow;
   614 
   614 
   615 		if ( empty( $this->_changeset_uuid ) ) {
   615 		if ( empty( $this->_changeset_uuid ) ) {
   689 		/**
   689 		/**
   690 		 * Fires once the Customizer theme preview has started.
   690 		 * Fires once the Customizer theme preview has started.
   691 		 *
   691 		 *
   692 		 * @since 3.4.0
   692 		 * @since 3.4.0
   693 		 *
   693 		 *
   694 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
   694 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
   695 		 */
   695 		 */
   696 		do_action( 'start_previewing_theme', $this );
   696 		do_action( 'start_previewing_theme', $this );
   697 	}
   697 	}
   698 
   698 
   699 	/**
   699 	/**
   700 	 * Stop previewing the selected theme.
   700 	 * Stops previewing the selected theme.
   701 	 *
   701 	 *
   702 	 * Removes filters to change the current theme.
   702 	 * Removes filters to change the active theme.
   703 	 *
   703 	 *
   704 	 * @since 3.4.0
   704 	 * @since 3.4.0
   705 	 */
   705 	 */
   706 	public function stop_previewing_theme() {
   706 	public function stop_previewing_theme() {
   707 		if ( ! $this->is_preview() ) {
   707 		if ( ! $this->is_preview() ) {
   727 		/**
   727 		/**
   728 		 * Fires once the Customizer theme preview has stopped.
   728 		 * Fires once the Customizer theme preview has stopped.
   729 		 *
   729 		 *
   730 		 * @since 3.4.0
   730 		 * @since 3.4.0
   731 		 *
   731 		 *
   732 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
   732 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
   733 		 */
   733 		 */
   734 		do_action( 'stop_previewing_theme', $this );
   734 		do_action( 'stop_previewing_theme', $this );
   735 	}
   735 	}
   736 
   736 
   737 	/**
   737 	/**
   800 
   800 
   801 		return $this->branching;
   801 		return $this->branching;
   802 	}
   802 	}
   803 
   803 
   804 	/**
   804 	/**
   805 	 * Get the changeset UUID.
   805 	 * Gets the changeset UUID.
   806 	 *
   806 	 *
   807 	 * @since 4.7.0
   807 	 * @since 4.7.0
   808 	 *
   808 	 *
   809 	 * @see WP_Customize_Manager::establish_loaded_changeset()
   809 	 * @see WP_Customize_Manager::establish_loaded_changeset()
   810 	 *
   810 	 *
   816 		}
   816 		}
   817 		return $this->_changeset_uuid;
   817 		return $this->_changeset_uuid;
   818 	}
   818 	}
   819 
   819 
   820 	/**
   820 	/**
   821 	 * Get the theme being customized.
   821 	 * Gets the theme being customized.
   822 	 *
   822 	 *
   823 	 * @since 3.4.0
   823 	 * @since 3.4.0
   824 	 *
   824 	 *
   825 	 * @return WP_Theme
   825 	 * @return WP_Theme
   826 	 */
   826 	 */
   830 		}
   830 		}
   831 		return $this->theme;
   831 		return $this->theme;
   832 	}
   832 	}
   833 
   833 
   834 	/**
   834 	/**
   835 	 * Get the registered settings.
   835 	 * Gets the registered settings.
   836 	 *
   836 	 *
   837 	 * @since 3.4.0
   837 	 * @since 3.4.0
   838 	 *
   838 	 *
   839 	 * @return array
   839 	 * @return array
   840 	 */
   840 	 */
   841 	public function settings() {
   841 	public function settings() {
   842 		return $this->settings;
   842 		return $this->settings;
   843 	}
   843 	}
   844 
   844 
   845 	/**
   845 	/**
   846 	 * Get the registered controls.
   846 	 * Gets the registered controls.
   847 	 *
   847 	 *
   848 	 * @since 3.4.0
   848 	 * @since 3.4.0
   849 	 *
   849 	 *
   850 	 * @return array
   850 	 * @return array
   851 	 */
   851 	 */
   852 	public function controls() {
   852 	public function controls() {
   853 		return $this->controls;
   853 		return $this->controls;
   854 	}
   854 	}
   855 
   855 
   856 	/**
   856 	/**
   857 	 * Get the registered containers.
   857 	 * Gets the registered containers.
   858 	 *
   858 	 *
   859 	 * @since 4.0.0
   859 	 * @since 4.0.0
   860 	 *
   860 	 *
   861 	 * @return array
   861 	 * @return array
   862 	 */
   862 	 */
   863 	public function containers() {
   863 	public function containers() {
   864 		return $this->containers;
   864 		return $this->containers;
   865 	}
   865 	}
   866 
   866 
   867 	/**
   867 	/**
   868 	 * Get the registered sections.
   868 	 * Gets the registered sections.
   869 	 *
   869 	 *
   870 	 * @since 3.4.0
   870 	 * @since 3.4.0
   871 	 *
   871 	 *
   872 	 * @return array
   872 	 * @return array
   873 	 */
   873 	 */
   874 	public function sections() {
   874 	public function sections() {
   875 		return $this->sections;
   875 		return $this->sections;
   876 	}
   876 	}
   877 
   877 
   878 	/**
   878 	/**
   879 	 * Get the registered panels.
   879 	 * Gets the registered panels.
   880 	 *
   880 	 *
   881 	 * @since 4.0.0
   881 	 * @since 4.0.0
   882 	 *
   882 	 *
   883 	 * @return array Panels.
   883 	 * @return array Panels.
   884 	 */
   884 	 */
   896 	public function is_theme_active() {
   896 	public function is_theme_active() {
   897 		return $this->get_stylesheet() === $this->original_stylesheet;
   897 		return $this->get_stylesheet() === $this->original_stylesheet;
   898 	}
   898 	}
   899 
   899 
   900 	/**
   900 	/**
   901 	 * Register styles/scripts and initialize the preview of each setting
   901 	 * Registers styles/scripts and initialize the preview of each setting
   902 	 *
   902 	 *
   903 	 * @since 3.4.0
   903 	 * @since 3.4.0
   904 	 */
   904 	 */
   905 	public function wp_loaded() {
   905 	public function wp_loaded() {
   906 
   906 
   926 		/**
   926 		/**
   927 		 * Fires once WordPress has loaded, allowing scripts and styles to be initialized.
   927 		 * Fires once WordPress has loaded, allowing scripts and styles to be initialized.
   928 		 *
   928 		 *
   929 		 * @since 3.4.0
   929 		 * @since 3.4.0
   930 		 *
   930 		 *
   931 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
   931 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
   932 		 */
   932 		 */
   933 		do_action( 'customize_register', $this );
   933 		do_action( 'customize_register', $this );
   934 
   934 
   935 		if ( $this->settings_previewed() ) {
   935 		if ( $this->settings_previewed() ) {
   936 			foreach ( $this->settings as $setting ) {
   936 			foreach ( $this->settings as $setting ) {
   964 
   964 
   965 		return $status;
   965 		return $status;
   966 	}
   966 	}
   967 
   967 
   968 	/**
   968 	/**
   969 	 * Find the changeset post ID for a given changeset UUID.
   969 	 * Finds the changeset post ID for a given changeset UUID.
   970 	 *
   970 	 *
   971 	 * @since 4.7.0
   971 	 * @since 4.7.0
   972 	 *
   972 	 *
   973 	 * @param string $uuid Changeset UUID.
   973 	 * @param string $uuid Changeset UUID.
   974 	 * @return int|null Returns post ID on success and null on failure.
   974 	 * @return int|null Returns post ID on success and null on failure.
  1002 
  1002 
  1003 		return null;
  1003 		return null;
  1004 	}
  1004 	}
  1005 
  1005 
  1006 	/**
  1006 	/**
  1007 	 * Get changeset posts.
  1007 	 * Gets changeset posts.
  1008 	 *
  1008 	 *
  1009 	 * @since 4.9.0
  1009 	 * @since 4.9.0
  1010 	 *
  1010 	 *
  1011 	 * @param array $args {
  1011 	 * @param array $args {
  1012 	 *     Args to pass into `get_posts()` to query changesets.
  1012 	 *     Args to pass into `get_posts()` to query changesets.
  1049 
  1049 
  1050 		return get_posts( $args );
  1050 		return get_posts( $args );
  1051 	}
  1051 	}
  1052 
  1052 
  1053 	/**
  1053 	/**
  1054 	 * Dismiss all of the current user's auto-drafts (other than the present one).
  1054 	 * Dismisses all of the current user's auto-drafts (other than the present one).
  1055 	 *
  1055 	 *
  1056 	 * @since 4.9.0
  1056 	 * @since 4.9.0
  1057 	 * @return int The number of auto-drafts that were dismissed.
  1057 	 * @return int The number of auto-drafts that were dismissed.
  1058 	 */
  1058 	 */
  1059 	protected function dismiss_user_auto_draft_changesets() {
  1059 	protected function dismiss_user_auto_draft_changesets() {
  1075 		}
  1075 		}
  1076 		return $dismissed;
  1076 		return $dismissed;
  1077 	}
  1077 	}
  1078 
  1078 
  1079 	/**
  1079 	/**
  1080 	 * Get the changeset post ID for the loaded changeset.
  1080 	 * Gets the changeset post ID for the loaded changeset.
  1081 	 *
  1081 	 *
  1082 	 * @since 4.7.0
  1082 	 * @since 4.7.0
  1083 	 *
  1083 	 *
  1084 	 * @return int|null Post ID on success or null if there is no post yet saved.
  1084 	 * @return int|null Post ID on success or null if there is no post yet saved.
  1085 	 */
  1085 	 */
  1096 		}
  1096 		}
  1097 		return $this->_changeset_post_id;
  1097 		return $this->_changeset_post_id;
  1098 	}
  1098 	}
  1099 
  1099 
  1100 	/**
  1100 	/**
  1101 	 * Get the data stored in a changeset post.
  1101 	 * Gets the data stored in a changeset post.
  1102 	 *
  1102 	 *
  1103 	 * @since 4.7.0
  1103 	 * @since 4.7.0
  1104 	 *
  1104 	 *
  1105 	 * @param int $post_id Changeset post ID.
  1105 	 * @param int $post_id Changeset post ID.
  1106 	 * @return array|WP_Error Changeset data or WP_Error on error.
  1106 	 * @return array|WP_Error Changeset data or WP_Error on error.
  1130 		}
  1130 		}
  1131 		return $changeset_data;
  1131 		return $changeset_data;
  1132 	}
  1132 	}
  1133 
  1133 
  1134 	/**
  1134 	/**
  1135 	 * Get changeset data.
  1135 	 * Gets changeset data.
  1136 	 *
  1136 	 *
  1137 	 * @since 4.7.0
  1137 	 * @since 4.7.0
  1138 	 * @since 4.9.0 This will return the changeset's data with a user's autosave revision merged on top, if one exists and $autosaved is true.
  1138 	 * @since 4.9.0 This will return the changeset's data with a user's autosave revision merged on top, if one exists and $autosaved is true.
  1139 	 *
  1139 	 *
  1140 	 * @return array Changeset data.
  1140 	 * @return array Changeset data.
  1177 	 * @var array
  1177 	 * @var array
  1178 	 */
  1178 	 */
  1179 	protected $pending_starter_content_settings_ids = array();
  1179 	protected $pending_starter_content_settings_ids = array();
  1180 
  1180 
  1181 	/**
  1181 	/**
  1182 	 * Import theme starter content into the customized state.
  1182 	 * Imports theme starter content into the customized state.
  1183 	 *
  1183 	 *
  1184 	 * @since 4.7.0
  1184 	 * @since 4.7.0
  1185 	 *
  1185 	 *
  1186 	 * @param array $starter_content Starter content. Defaults to `get_theme_starter_content()`.
  1186 	 * @param array $starter_content Starter content. Defaults to `get_theme_starter_content()`.
  1187 	 */
  1187 	 */
  1188 	function import_theme_starter_content( $starter_content = array() ) {
  1188 	public function import_theme_starter_content( $starter_content = array() ) {
  1189 		if ( empty( $starter_content ) ) {
  1189 		if ( empty( $starter_content ) ) {
  1190 			$starter_content = get_theme_starter_content();
  1190 			$starter_content = get_theme_starter_content();
  1191 		}
  1191 		}
  1192 
  1192 
  1193 		$changeset_data = array();
  1193 		$changeset_data = array();
  1630 			}
  1630 			}
  1631 		}
  1631 		}
  1632 	}
  1632 	}
  1633 
  1633 
  1634 	/**
  1634 	/**
  1635 	 * Prepare starter content attachments.
  1635 	 * Prepares starter content attachments.
  1636 	 *
  1636 	 *
  1637 	 * Ensure that the attachments are valid and that they have slugs and file name/path.
  1637 	 * Ensure that the attachments are valid and that they have slugs and file name/path.
  1638 	 *
  1638 	 *
  1639 	 * @since 4.7.0
  1639 	 * @since 4.7.0
  1640 	 *
  1640 	 *
  1692 		}
  1692 		}
  1693 		return $prepared_attachments;
  1693 		return $prepared_attachments;
  1694 	}
  1694 	}
  1695 
  1695 
  1696 	/**
  1696 	/**
  1697 	 * Save starter content changeset.
  1697 	 * Saves starter content changeset.
  1698 	 *
  1698 	 *
  1699 	 * @since 4.7.0
  1699 	 * @since 4.7.0
  1700 	 */
  1700 	 */
  1701 	public function _save_starter_content_changeset() {
  1701 	public function _save_starter_content_changeset() {
  1702 
  1702 
  1714 
  1714 
  1715 		$this->pending_starter_content_settings_ids = array();
  1715 		$this->pending_starter_content_settings_ids = array();
  1716 	}
  1716 	}
  1717 
  1717 
  1718 	/**
  1718 	/**
  1719 	 * Get dirty pre-sanitized setting values in the current customized state.
  1719 	 * Gets dirty pre-sanitized setting values in the current customized state.
  1720 	 *
  1720 	 *
  1721 	 * The returned array consists of a merge of three sources:
  1721 	 * The returned array consists of a merge of three sources:
  1722 	 * 1. If the theme is not currently active, then the base array is any stashed
  1722 	 * 1. If the theme is not currently active, then the base array is any stashed
  1723 	 *    theme mods that were modified previously but never published.
  1723 	 *    theme mods that were modified previously but never published.
  1724 	 * 2. The values from the current changeset, if it exists.
  1724 	 * 2. The values from the current changeset, if it exists.
  1767 				if ( ! array_key_exists( 'value', $setting_params ) ) {
  1767 				if ( ! array_key_exists( 'value', $setting_params ) ) {
  1768 					continue;
  1768 					continue;
  1769 				}
  1769 				}
  1770 				if ( isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] ) {
  1770 				if ( isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] ) {
  1771 
  1771 
  1772 					// Ensure that theme mods values are only used if they were saved under the current theme.
  1772 					// Ensure that theme mods values are only used if they were saved under the active theme.
  1773 					$namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/';
  1773 					$namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/';
  1774 					if ( preg_match( $namespace_pattern, $setting_id, $matches ) && $this->get_stylesheet() === $matches['stylesheet'] ) {
  1774 					if ( preg_match( $namespace_pattern, $setting_id, $matches ) && $this->get_stylesheet() === $matches['stylesheet'] ) {
  1775 						$values[ $matches['setting_id'] ] = $setting_params['value'];
  1775 						$values[ $matches['setting_id'] ] = $setting_params['value'];
  1776 					}
  1776 					}
  1777 				} else {
  1777 				} else {
  1804 	 * The name "post_value" is a carry-over from when the customized state was exclusively
  1804 	 * The name "post_value" is a carry-over from when the customized state was exclusively
  1805 	 * sourced from `$_POST['customized']`. Nevertheless, the value returned will come
  1805 	 * sourced from `$_POST['customized']`. Nevertheless, the value returned will come
  1806 	 * from the current changeset post and from the incoming post data.
  1806 	 * from the current changeset post and from the incoming post data.
  1807 	 *
  1807 	 *
  1808 	 * @since 3.4.0
  1808 	 * @since 3.4.0
  1809 	 * @since 4.1.1 Introduced the `$default` parameter.
  1809 	 * @since 4.1.1 Introduced the `$default_value` parameter.
  1810 	 * @since 4.6.0 `$default` is now returned early when the setting post value is invalid.
  1810 	 * @since 4.6.0 `$default_value` is now returned early when the setting post value is invalid.
  1811 	 *
  1811 	 *
  1812 	 * @see WP_REST_Server::dispatch()
  1812 	 * @see WP_REST_Server::dispatch()
  1813 	 * @see WP_REST_Request::sanitize_params()
  1813 	 * @see WP_REST_Request::sanitize_params()
  1814 	 * @see WP_REST_Request::has_valid_params()
  1814 	 * @see WP_REST_Request::has_valid_params()
  1815 	 *
  1815 	 *
  1816 	 * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object.
  1816 	 * @param WP_Customize_Setting $setting       A WP_Customize_Setting derived object.
  1817 	 * @param mixed                $default Value returned $setting has no post value (added in 4.2.0)
  1817 	 * @param mixed                $default_value Value returned if `$setting` has no post value (added in 4.2.0)
  1818 	 *                                      or the post value is invalid (added in 4.6.0).
  1818 	 *                                            or the post value is invalid (added in 4.6.0).
  1819 	 * @return string|mixed Sanitized value or the $default provided.
  1819 	 * @return string|mixed Sanitized value or the `$default_value` provided.
  1820 	 */
  1820 	 */
  1821 	public function post_value( $setting, $default = null ) {
  1821 	public function post_value( $setting, $default_value = null ) {
  1822 		$post_values = $this->unsanitized_post_values();
  1822 		$post_values = $this->unsanitized_post_values();
  1823 		if ( ! array_key_exists( $setting->id, $post_values ) ) {
  1823 		if ( ! array_key_exists( $setting->id, $post_values ) ) {
  1824 			return $default;
  1824 			return $default_value;
  1825 		}
  1825 		}
       
  1826 
  1826 		$value = $post_values[ $setting->id ];
  1827 		$value = $post_values[ $setting->id ];
  1827 		$valid = $setting->validate( $value );
  1828 		$valid = $setting->validate( $value );
  1828 		if ( is_wp_error( $valid ) ) {
  1829 		if ( is_wp_error( $valid ) ) {
  1829 			return $default;
  1830 			return $default_value;
  1830 		}
  1831 		}
       
  1832 
  1831 		$value = $setting->sanitize( $value );
  1833 		$value = $setting->sanitize( $value );
  1832 		if ( is_null( $value ) || is_wp_error( $value ) ) {
  1834 		if ( is_null( $value ) || is_wp_error( $value ) ) {
  1833 			return $default;
  1835 			return $default_value;
  1834 		}
  1836 		}
       
  1837 
  1835 		return $value;
  1838 		return $value;
  1836 	}
  1839 	}
  1837 
  1840 
  1838 	/**
  1841 	/**
  1839 	 * Override a setting's value in the current customized state.
  1842 	 * Overrides a setting's value in the current customized state.
  1840 	 *
  1843 	 *
  1841 	 * The name "post_value" is a carry-over from when the customized state was
  1844 	 * The name "post_value" is a carry-over from when the customized state was
  1842 	 * exclusively sourced from `$_POST['customized']`.
  1845 	 * exclusively sourced from `$_POST['customized']`.
  1843 	 *
  1846 	 *
  1844 	 * @since 4.2.0
  1847 	 * @since 4.2.0
  1849 	public function set_post_value( $setting_id, $value ) {
  1852 	public function set_post_value( $setting_id, $value ) {
  1850 		$this->unsanitized_post_values(); // Populate _post_values from $_POST['customized'].
  1853 		$this->unsanitized_post_values(); // Populate _post_values from $_POST['customized'].
  1851 		$this->_post_values[ $setting_id ] = $value;
  1854 		$this->_post_values[ $setting_id ] = $value;
  1852 
  1855 
  1853 		/**
  1856 		/**
  1854 		 * Announce when a specific setting's unsanitized post value has been set.
  1857 		 * Announces when a specific setting's unsanitized post value has been set.
  1855 		 *
  1858 		 *
  1856 		 * Fires when the WP_Customize_Manager::set_post_value() method is called.
  1859 		 * Fires when the WP_Customize_Manager::set_post_value() method is called.
  1857 		 *
  1860 		 *
  1858 		 * The dynamic portion of the hook name, `$setting_id`, refers to the setting ID.
  1861 		 * The dynamic portion of the hook name, `$setting_id`, refers to the setting ID.
  1859 		 *
  1862 		 *
  1860 		 * @since 4.4.0
  1863 		 * @since 4.4.0
  1861 		 *
  1864 		 *
  1862 		 * @param mixed                $value Unsanitized setting post value.
  1865 		 * @param mixed                $value   Unsanitized setting post value.
  1863 		 * @param WP_Customize_Manager $this  WP_Customize_Manager instance.
  1866 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
  1864 		 */
  1867 		 */
  1865 		do_action( "customize_post_value_set_{$setting_id}", $value, $this );
  1868 		do_action( "customize_post_value_set_{$setting_id}", $value, $this );
  1866 
  1869 
  1867 		/**
  1870 		/**
  1868 		 * Announce when any setting's unsanitized post value has been set.
  1871 		 * Announces when any setting's unsanitized post value has been set.
  1869 		 *
  1872 		 *
  1870 		 * Fires when the WP_Customize_Manager::set_post_value() method is called.
  1873 		 * Fires when the WP_Customize_Manager::set_post_value() method is called.
  1871 		 *
  1874 		 *
  1872 		 * This is useful for `WP_Customize_Setting` instances to watch
  1875 		 * This is useful for `WP_Customize_Setting` instances to watch
  1873 		 * in order to update a cached previewed value.
  1876 		 * in order to update a cached previewed value.
  1874 		 *
  1877 		 *
  1875 		 * @since 4.4.0
  1878 		 * @since 4.4.0
  1876 		 *
  1879 		 *
  1877 		 * @param string               $setting_id Setting ID.
  1880 		 * @param string               $setting_id Setting ID.
  1878 		 * @param mixed                $value      Unsanitized setting post value.
  1881 		 * @param mixed                $value      Unsanitized setting post value.
  1879 		 * @param WP_Customize_Manager $this       WP_Customize_Manager instance.
  1882 		 * @param WP_Customize_Manager $manager    WP_Customize_Manager instance.
  1880 		 */
  1883 		 */
  1881 		do_action( 'customize_post_value_set', $setting_id, $value, $this );
  1884 		do_action( 'customize_post_value_set', $setting_id, $value, $this );
  1882 	}
  1885 	}
  1883 
  1886 
  1884 	/**
  1887 	/**
  1885 	 * Print JavaScript settings.
  1888 	 * Prints JavaScript settings.
  1886 	 *
  1889 	 *
  1887 	 * @since 3.4.0
  1890 	 * @since 3.4.0
  1888 	 */
  1891 	 */
  1889 	public function customize_preview_init() {
  1892 	public function customize_preview_init() {
  1890 
  1893 
  1935 		 * Fires once the Customizer preview has initialized and JavaScript
  1938 		 * Fires once the Customizer preview has initialized and JavaScript
  1936 		 * settings have been printed.
  1939 		 * settings have been printed.
  1937 		 *
  1940 		 *
  1938 		 * @since 3.4.0
  1941 		 * @since 3.4.0
  1939 		 *
  1942 		 *
  1940 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
  1943 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
  1941 		 */
  1944 		 */
  1942 		do_action( 'customize_preview_init', $this );
  1945 		do_action( 'customize_preview_init', $this );
  1943 	}
  1946 	}
  1944 
  1947 
  1945 	/**
  1948 	/**
  1955 		$headers['Content-Security-Policy'] = "frame-ancestors 'self'";
  1958 		$headers['Content-Security-Policy'] = "frame-ancestors 'self'";
  1956 		return $headers;
  1959 		return $headers;
  1957 	}
  1960 	}
  1958 
  1961 
  1959 	/**
  1962 	/**
  1960 	 * Add customize state query params to a given URL if preview is allowed.
  1963 	 * Adds customize state query params to a given URL if preview is allowed.
  1961 	 *
  1964 	 *
  1962 	 * @since 4.7.0
  1965 	 * @since 4.7.0
  1963 	 *
  1966 	 *
  1964 	 * @see wp_redirect()
  1967 	 * @see wp_redirect()
  1965 	 * @see WP_Customize_Manager::get_allowed_url()
  1968 	 * @see WP_Customize_Manager::get_allowed_url()
  1999 
  2002 
  2000 		return $url;
  2003 		return $url;
  2001 	}
  2004 	}
  2002 
  2005 
  2003 	/**
  2006 	/**
  2004 	 * Prevent sending a 404 status when returning the response for the customize
  2007 	 * Prevents sending a 404 status when returning the response for the customize
  2005 	 * preview, since it causes the jQuery Ajax to fail. Send 200 instead.
  2008 	 * preview, since it causes the jQuery Ajax to fail. Send 200 instead.
  2006 	 *
  2009 	 *
  2007 	 * @since 4.0.0
  2010 	 * @since 4.0.0
  2008 	 * @deprecated 4.7.0
  2011 	 * @deprecated 4.7.0
  2009 	 */
  2012 	 */
  2010 	public function customize_preview_override_404_status() {
  2013 	public function customize_preview_override_404_status() {
  2011 		_deprecated_function( __METHOD__, '4.7.0' );
  2014 		_deprecated_function( __METHOD__, '4.7.0' );
  2012 	}
  2015 	}
  2013 
  2016 
  2014 	/**
  2017 	/**
  2015 	 * Print base element for preview frame.
  2018 	 * Prints base element for preview frame.
  2016 	 *
  2019 	 *
  2017 	 * @since 3.4.0
  2020 	 * @since 3.4.0
  2018 	 * @deprecated 4.7.0
  2021 	 * @deprecated 4.7.0
  2019 	 */
  2022 	 */
  2020 	public function customize_preview_base() {
  2023 	public function customize_preview_base() {
  2021 		_deprecated_function( __METHOD__, '4.7.0' );
  2024 		_deprecated_function( __METHOD__, '4.7.0' );
  2022 	}
  2025 	}
  2023 
  2026 
  2024 	/**
  2027 	/**
  2025 	 * Print a workaround to handle HTML5 tags in IE < 9.
  2028 	 * Prints a workaround to handle HTML5 tags in IE < 9.
  2026 	 *
  2029 	 *
  2027 	 * @since 3.4.0
  2030 	 * @since 3.4.0
  2028 	 * @deprecated 4.7.0 Customizer no longer supports IE8, so all supported browsers recognize HTML5.
  2031 	 * @deprecated 4.7.0 Customizer no longer supports IE8, so all supported browsers recognize HTML5.
  2029 	 */
  2032 	 */
  2030 	public function customize_preview_html5() {
  2033 	public function customize_preview_html5() {
  2031 		_deprecated_function( __FUNCTION__, '4.7.0' );
  2034 		_deprecated_function( __FUNCTION__, '4.7.0' );
  2032 	}
  2035 	}
  2033 
  2036 
  2034 	/**
  2037 	/**
  2035 	 * Print CSS for loading indicators for the Customizer preview.
  2038 	 * Prints CSS for loading indicators for the Customizer preview.
  2036 	 *
  2039 	 *
  2037 	 * @since 4.2.0
  2040 	 * @since 4.2.0
  2038 	 */
  2041 	 */
  2039 	public function customize_preview_loading_style() {
  2042 	public function customize_preview_loading_style() {
  2040 		?>
  2043 		?>
  2059 		</style>
  2062 		</style>
  2060 		<?php
  2063 		<?php
  2061 	}
  2064 	}
  2062 
  2065 
  2063 	/**
  2066 	/**
  2064 	 * Remove customize_messenger_channel query parameter from the preview window when it is not in an iframe.
  2067 	 * Removes customize_messenger_channel query parameter from the preview window when it is not in an iframe.
  2065 	 *
  2068 	 *
  2066 	 * This ensures that the admin bar will be shown. It also ensures that link navigation will
  2069 	 * This ensures that the admin bar will be shown. It also ensures that link navigation will
  2067 	 * work as expected since the parent frame is not being sent the URL to navigate to.
  2070 	 * work as expected since the parent frame is not being sent the URL to navigate to.
  2068 	 *
  2071 	 *
  2069 	 * @since 4.7.0
  2072 	 * @since 4.7.0
  2096 		</script>
  2099 		</script>
  2097 		<?php
  2100 		<?php
  2098 	}
  2101 	}
  2099 
  2102 
  2100 	/**
  2103 	/**
  2101 	 * Print JavaScript settings for preview frame.
  2104 	 * Prints JavaScript settings for preview frame.
  2102 	 *
  2105 	 *
  2103 	 * @since 3.4.0
  2106 	 * @since 3.4.0
  2104 	 */
  2107 	 */
  2105 	public function customize_preview_settings() {
  2108 	public function customize_preview_settings() {
  2106 		$post_values                 = $this->unsanitized_post_values( array( 'exclude_changeset' => true ) );
  2109 		$post_values                 = $this->unsanitized_post_values( array( 'exclude_changeset' => true ) );
  2230 	 * Removes the signature in case we experience a case where the Customizer was not properly executed.
  2233 	 * Removes the signature in case we experience a case where the Customizer was not properly executed.
  2231 	 *
  2234 	 *
  2232 	 * @since 3.4.0
  2235 	 * @since 3.4.0
  2233 	 * @deprecated 4.7.0
  2236 	 * @deprecated 4.7.0
  2234 	 *
  2237 	 *
  2235 	 * @param mixed $return Value passed through for {@see 'wp_die_handler'} filter.
  2238 	 * @param callable|null $callback Optional. Value passed through for {@see 'wp_die_handler'} filter.
  2236 	 * @return mixed Value passed through for {@see 'wp_die_handler'} filter.
  2239 	 *                                Default null.
  2237 	 */
  2240 	 * @return callable|null Value passed through for {@see 'wp_die_handler'} filter.
  2238 	public function remove_preview_signature( $return = null ) {
  2241 	 */
       
  2242 	public function remove_preview_signature( $callback = null ) {
  2239 		_deprecated_function( __METHOD__, '4.7.0' );
  2243 		_deprecated_function( __METHOD__, '4.7.0' );
  2240 
  2244 
  2241 		return $return;
  2245 		return $callback;
  2242 	}
  2246 	}
  2243 
  2247 
  2244 	/**
  2248 	/**
  2245 	 * Is it a theme preview?
  2249 	 * Determines whether it is a theme preview or not.
  2246 	 *
  2250 	 *
  2247 	 * @since 3.4.0
  2251 	 * @since 3.4.0
  2248 	 *
  2252 	 *
  2249 	 * @return bool True if it's a preview, false if not.
  2253 	 * @return bool True if it's a preview, false if not.
  2250 	 */
  2254 	 */
  2251 	public function is_preview() {
  2255 	public function is_preview() {
  2252 		return (bool) $this->previewing;
  2256 		return (bool) $this->previewing;
  2253 	}
  2257 	}
  2254 
  2258 
  2255 	/**
  2259 	/**
  2256 	 * Retrieve the template name of the previewed theme.
  2260 	 * Retrieves the template name of the previewed theme.
  2257 	 *
  2261 	 *
  2258 	 * @since 3.4.0
  2262 	 * @since 3.4.0
  2259 	 *
  2263 	 *
  2260 	 * @return string Template name.
  2264 	 * @return string Template name.
  2261 	 */
  2265 	 */
  2262 	public function get_template() {
  2266 	public function get_template() {
  2263 		return $this->theme()->get_template();
  2267 		return $this->theme()->get_template();
  2264 	}
  2268 	}
  2265 
  2269 
  2266 	/**
  2270 	/**
  2267 	 * Retrieve the stylesheet name of the previewed theme.
  2271 	 * Retrieves the stylesheet name of the previewed theme.
  2268 	 *
  2272 	 *
  2269 	 * @since 3.4.0
  2273 	 * @since 3.4.0
  2270 	 *
  2274 	 *
  2271 	 * @return string Stylesheet name.
  2275 	 * @return string Stylesheet name.
  2272 	 */
  2276 	 */
  2273 	public function get_stylesheet() {
  2277 	public function get_stylesheet() {
  2274 		return $this->theme()->get_stylesheet();
  2278 		return $this->theme()->get_stylesheet();
  2275 	}
  2279 	}
  2276 
  2280 
  2277 	/**
  2281 	/**
  2278 	 * Retrieve the template root of the previewed theme.
  2282 	 * Retrieves the template root of the previewed theme.
  2279 	 *
  2283 	 *
  2280 	 * @since 3.4.0
  2284 	 * @since 3.4.0
  2281 	 *
  2285 	 *
  2282 	 * @return string Theme root.
  2286 	 * @return string Theme root.
  2283 	 */
  2287 	 */
  2284 	public function get_template_root() {
  2288 	public function get_template_root() {
  2285 		return get_raw_theme_root( $this->get_template(), true );
  2289 		return get_raw_theme_root( $this->get_template(), true );
  2286 	}
  2290 	}
  2287 
  2291 
  2288 	/**
  2292 	/**
  2289 	 * Retrieve the stylesheet root of the previewed theme.
  2293 	 * Retrieves the stylesheet root of the previewed theme.
  2290 	 *
  2294 	 *
  2291 	 * @since 3.4.0
  2295 	 * @since 3.4.0
  2292 	 *
  2296 	 *
  2293 	 * @return string Theme root.
  2297 	 * @return string Theme root.
  2294 	 */
  2298 	 */
  2295 	public function get_stylesheet_root() {
  2299 	public function get_stylesheet_root() {
  2296 		return get_raw_theme_root( $this->get_stylesheet(), true );
  2300 		return get_raw_theme_root( $this->get_stylesheet(), true );
  2297 	}
  2301 	}
  2298 
  2302 
  2299 	/**
  2303 	/**
  2300 	 * Filters the current theme and return the name of the previewed theme.
  2304 	 * Filters the active theme and return the name of the previewed theme.
  2301 	 *
  2305 	 *
  2302 	 * @since 3.4.0
  2306 	 * @since 3.4.0
  2303 	 *
  2307 	 *
  2304 	 * @param mixed $current_theme {@internal Parameter is not used}
  2308 	 * @param mixed $current_theme {@internal Parameter is not used}
  2305 	 * @return string Theme name.
  2309 	 * @return string Theme name.
  2406 			return true;
  2410 			return true;
  2407 		}
  2411 		}
  2408 	}
  2412 	}
  2409 
  2413 
  2410 	/**
  2414 	/**
  2411 	 * Handle customize_save WP Ajax request to save/update a changeset.
  2415 	 * Handles customize_save WP Ajax request to save/update a changeset.
  2412 	 *
  2416 	 *
  2413 	 * @since 3.4.0
  2417 	 * @since 3.4.0
  2414 	 * @since 4.7.0 The semantics of this method have changed to update a changeset, optionally to also change the status and other attributes.
  2418 	 * @since 4.7.0 The semantics of this method have changed to update a changeset, optionally to also change the status and other attributes.
  2415 	 */
  2419 	 */
  2416 	public function save() {
  2420 	public function save() {
  2590 		 *
  2594 		 *
  2591 		 * @since 4.2.0
  2595 		 * @since 4.2.0
  2592 		 *
  2596 		 *
  2593 		 * @param array                $response Additional information passed back to the 'saved'
  2597 		 * @param array                $response Additional information passed back to the 'saved'
  2594 		 *                                       event on `wp.customize`.
  2598 		 *                                       event on `wp.customize`.
  2595 		 * @param WP_Customize_Manager $this     WP_Customize_Manager instance.
  2599 		 * @param WP_Customize_Manager $manager  WP_Customize_Manager instance.
  2596 		 */
  2600 		 */
  2597 		$response = apply_filters( 'customize_save_response', $response, $this );
  2601 		$response = apply_filters( 'customize_save_response', $response, $this );
  2598 
  2602 
  2599 		if ( is_wp_error( $r ) ) {
  2603 		if ( is_wp_error( $r ) ) {
  2600 			wp_send_json_error( $response );
  2604 			wp_send_json_error( $response );
  2602 			wp_send_json_success( $response );
  2606 			wp_send_json_success( $response );
  2603 		}
  2607 		}
  2604 	}
  2608 	}
  2605 
  2609 
  2606 	/**
  2610 	/**
  2607 	 * Save the post for the loaded changeset.
  2611 	 * Saves the post for the loaded changeset.
  2608 	 *
  2612 	 *
  2609 	 * @since 4.7.0
  2613 	 * @since 4.7.0
  2610 	 *
  2614 	 *
  2611 	 * @param array $args {
  2615 	 * @param array $args {
  2612 	 *     Args for changeset post.
  2616 	 *     Args for changeset post.
  2620 	 *     @type bool   $autosave        Whether this is a request to create an autosave revision.
  2624 	 *     @type bool   $autosave        Whether this is a request to create an autosave revision.
  2621 	 * }
  2625 	 * }
  2622 	 *
  2626 	 *
  2623 	 * @return array|WP_Error Returns array on success and WP_Error with array data on error.
  2627 	 * @return array|WP_Error Returns array on success and WP_Error with array data on error.
  2624 	 */
  2628 	 */
  2625 	function save_changeset_post( $args = array() ) {
  2629 	public function save_changeset_post( $args = array() ) {
  2626 
  2630 
  2627 		$args = array_merge(
  2631 		$args = array_merge(
  2628 			array(
  2632 			array(
  2629 				'status'          => null,
  2633 				'status'          => null,
  2630 				'title'           => null,
  2634 				'title'           => null,
  2758 		 * at this point to catch any settings registered after `customize_register`.
  2762 		 * at this point to catch any settings registered after `customize_register`.
  2759 		 * The dynamic portion of the hook name, `$this->ID` refers to the setting ID.
  2763 		 * The dynamic portion of the hook name, `$this->ID` refers to the setting ID.
  2760 		 *
  2764 		 *
  2761 		 * @since 4.6.0
  2765 		 * @since 4.6.0
  2762 		 *
  2766 		 *
  2763 		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
  2767 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
  2764 		 */
  2768 		 */
  2765 		do_action( 'customize_save_validation_before', $this );
  2769 		do_action( 'customize_save_validation_before', $this );
  2766 
  2770 
  2767 		// Validate settings.
  2771 		// Validate settings.
  2768 		$validated_values      = array_merge(
  2772 		$validated_values      = array_merge(
  2990 
  2994 
  2991 		return $response;
  2995 		return $response;
  2992 	}
  2996 	}
  2993 
  2997 
  2994 	/**
  2998 	/**
  2995 	 * Preserve the initial JSON post_content passed to save into the post.
  2999 	 * Preserves the initial JSON post_content passed to save into the post.
  2996 	 *
  3000 	 *
  2997 	 * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
  3001 	 * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
  2998 	 * from corrupting JSON data.
  3002 	 * from corrupting JSON data.
  2999 	 *
  3003 	 *
  3000 	 * Note that WP_Customize_Manager::validate_setting_values() have already
  3004 	 * Note that WP_Customize_Manager::validate_setting_values() have already
  3035 		}
  3039 		}
  3036 		return $data;
  3040 		return $data;
  3037 	}
  3041 	}
  3038 
  3042 
  3039 	/**
  3043 	/**
  3040 	 * Trash or delete a changeset post.
  3044 	 * Trashes or deletes a changeset post.
  3041 	 *
  3045 	 *
  3042 	 * The following re-formulates the logic from `wp_trash_post()` as done in
  3046 	 * The following re-formulates the logic from `wp_trash_post()` as done in
  3043 	 * `wp_publish_post()`. The reason for bypassing `wp_trash_post()` is that it
  3047 	 * `wp_publish_post()`. The reason for bypassing `wp_trash_post()` is that it
  3044 	 * will mutate the the `post_content` and the `post_name` when they should be
  3048 	 * will mutate the the `post_content` and the `post_name` when they should be
  3045 	 * untouched.
  3049 	 * untouched.
  3114 
  3118 
  3115 		return $post;
  3119 		return $post;
  3116 	}
  3120 	}
  3117 
  3121 
  3118 	/**
  3122 	/**
  3119 	 * Handle request to trash a changeset.
  3123 	 * Handles request to trash a changeset.
  3120 	 *
  3124 	 *
  3121 	 * @since 4.9.0
  3125 	 * @since 4.9.0
  3122 	 */
  3126 	 */
  3123 	public function handle_changeset_trash_request() {
  3127 	public function handle_changeset_trash_request() {
  3124 		if ( ! is_user_logged_in() ) {
  3128 		if ( ! is_user_logged_in() ) {
  3199 			)
  3203 			)
  3200 		);
  3204 		);
  3201 	}
  3205 	}
  3202 
  3206 
  3203 	/**
  3207 	/**
  3204 	 * Re-map 'edit_post' meta cap for a customize_changeset post to be the same as 'customize' maps.
  3208 	 * Re-maps 'edit_post' meta cap for a customize_changeset post to be the same as 'customize' maps.
  3205 	 *
  3209 	 *
  3206 	 * There is essentially a "meta meta" cap in play here, where 'edit_post' meta cap maps to
  3210 	 * There is essentially a "meta meta" cap in play here, where 'edit_post' meta cap maps to
  3207 	 * the 'customize' meta cap which then maps to 'edit_theme_options'. This is currently
  3211 	 * the 'customize' meta cap which then maps to 'edit_theme_options'. This is currently
  3208 	 * required in core for `wp_create_post_autosave()` because it will call
  3212 	 * required in core for `wp_create_post_autosave()` because it will call
  3209 	 * `_wp_translate_postdata()` which in turn will check if a user can 'edit_post', but the
  3213 	 * `_wp_translate_postdata()` which in turn will check if a user can 'edit_post', but the
  3264 	 */
  3268 	 */
  3265 	public function refresh_changeset_lock( $changeset_post_id ) {
  3269 	public function refresh_changeset_lock( $changeset_post_id ) {
  3266 		if ( ! $changeset_post_id ) {
  3270 		if ( ! $changeset_post_id ) {
  3267 			return;
  3271 			return;
  3268 		}
  3272 		}
       
  3273 
  3269 		$lock = get_post_meta( $changeset_post_id, '_edit_lock', true );
  3274 		$lock = get_post_meta( $changeset_post_id, '_edit_lock', true );
  3270 		$lock = explode( ':', $lock );
  3275 		$lock = explode( ':', $lock );
  3271 
  3276 
  3272 		if ( $lock && ! empty( $lock[1] ) ) {
  3277 		if ( $lock && ! empty( $lock[1] ) ) {
  3273 			$user_id         = (int) $lock[1];
  3278 			$user_id         = (int) $lock[1];
  3281 
  3286 
  3282 	/**
  3287 	/**
  3283 	 * Filters heartbeat settings for the Customizer.
  3288 	 * Filters heartbeat settings for the Customizer.
  3284 	 *
  3289 	 *
  3285 	 * @since 4.9.0
  3290 	 * @since 4.9.0
       
  3291 	 *
       
  3292 	 * @global string $pagenow The filename of the current screen.
       
  3293 	 *
  3286 	 * @param array $settings Current settings to filter.
  3294 	 * @param array $settings Current settings to filter.
  3287 	 * @return array Heartbeat settings.
  3295 	 * @return array Heartbeat settings.
  3288 	 */
  3296 	 */
  3289 	public function add_customize_screen_to_heartbeat_settings( $settings ) {
  3297 	public function add_customize_screen_to_heartbeat_settings( $settings ) {
  3290 		global $pagenow;
  3298 		global $pagenow;
       
  3299 
  3291 		if ( 'customize.php' === $pagenow ) {
  3300 		if ( 'customize.php' === $pagenow ) {
  3292 			$settings['screenId'] = 'customize';
  3301 			$settings['screenId'] = 'customize';
  3293 		}
  3302 		}
       
  3303 
  3294 		return $settings;
  3304 		return $settings;
  3295 	}
  3305 	}
  3296 
  3306 
  3297 	/**
  3307 	/**
  3298 	 * Get lock user data.
  3308 	 * Gets lock user data.
  3299 	 *
  3309 	 *
  3300 	 * @since 4.9.0
  3310 	 * @since 4.9.0
  3301 	 *
  3311 	 *
  3302 	 * @param int $user_id User ID.
  3312 	 * @param int $user_id User ID.
  3303 	 * @return array|null User data formatted for client.
  3313 	 * @return array|null User data formatted for client.
  3304 	 */
  3314 	 */
  3305 	protected function get_lock_user_data( $user_id ) {
  3315 	protected function get_lock_user_data( $user_id ) {
  3306 		if ( ! $user_id ) {
  3316 		if ( ! $user_id ) {
  3307 			return null;
  3317 			return null;
  3308 		}
  3318 		}
       
  3319 
  3309 		$lock_user = get_userdata( $user_id );
  3320 		$lock_user = get_userdata( $user_id );
       
  3321 
  3310 		if ( ! $lock_user ) {
  3322 		if ( ! $lock_user ) {
  3311 			return null;
  3323 			return null;
  3312 		}
  3324 		}
       
  3325 
  3313 		return array(
  3326 		return array(
  3314 			'id'     => $lock_user->ID,
  3327 			'id'     => $lock_user->ID,
  3315 			'name'   => $lock_user->display_name,
  3328 			'name'   => $lock_user->display_name,
  3316 			'avatar' => get_avatar_url( $lock_user->ID, array( 'size' => 128 ) ),
  3329 			'avatar' => get_avatar_url( $lock_user->ID, array( 'size' => 128 ) ),
  3317 		);
  3330 		);
  3318 	}
  3331 	}
  3319 
  3332 
  3320 	/**
  3333 	/**
  3321 	 * Check locked changeset with heartbeat API.
  3334 	 * Checks locked changeset with heartbeat API.
  3322 	 *
  3335 	 *
  3323 	 * @since 4.9.0
  3336 	 * @since 4.9.0
  3324 	 *
  3337 	 *
  3325 	 * @param array  $response  The Heartbeat response.
  3338 	 * @param array  $response  The Heartbeat response.
  3326 	 * @param array  $data      The $_POST data sent.
  3339 	 * @param array  $data      The $_POST data sent.
  3397 
  3410 
  3398 		wp_send_json_success( 'changeset_taken_over' );
  3411 		wp_send_json_success( 'changeset_taken_over' );
  3399 	}
  3412 	}
  3400 
  3413 
  3401 	/**
  3414 	/**
  3402 	 * Whether a changeset revision should be made.
  3415 	 * Determines whether a changeset revision should be made.
  3403 	 *
  3416 	 *
  3404 	 * @since 4.7.0
  3417 	 * @since 4.7.0
  3405 	 * @var bool
  3418 	 * @var bool
  3406 	 */
  3419 	 */
  3407 	protected $store_changeset_revision;
  3420 	protected $store_changeset_revision;
  3425 		}
  3438 		}
  3426 		return $post_has_changed;
  3439 		return $post_has_changed;
  3427 	}
  3440 	}
  3428 
  3441 
  3429 	/**
  3442 	/**
  3430 	 * Publish changeset values.
  3443 	 * Publishes the values of a changeset.
  3431 	 *
  3444 	 *
  3432 	 * This will the values contained in a changeset, even changesets that do not
  3445 	 * This will publish the values contained in a changeset, even changesets that do not
  3433 	 * correspond to current manager instance. This is called by
  3446 	 * correspond to current manager instance. This is called by
  3434 	 * `_wp_customize_publish_changeset()` when a customize_changeset post is
  3447 	 * `_wp_customize_publish_changeset()` when a customize_changeset post is
  3435 	 * transitioned to the `publish` status. As such, this method should not be
  3448 	 * transitioned to the `publish` status. As such, this method should not be
  3436 	 * called directly and instead `wp_publish_post()` should be used.
  3449 	 * called directly and instead `wp_publish_post()` should be used.
  3437 	 *
  3450 	 *
  3615 
  3628 
  3616 		return true;
  3629 		return true;
  3617 	}
  3630 	}
  3618 
  3631 
  3619 	/**
  3632 	/**
  3620 	 * Update stashed theme mod settings.
  3633 	 * Updates stashed theme mod settings.
  3621 	 *
  3634 	 *
  3622 	 * @since 4.7.0
  3635 	 * @since 4.7.0
  3623 	 *
  3636 	 *
  3624 	 * @param array $inactive_theme_mod_settings Mapping of stylesheet to arrays of theme mod settings.
  3637 	 * @param array $inactive_theme_mod_settings Mapping of stylesheet to arrays of theme mod settings.
  3625 	 * @return array|false Returns array of updated stashed theme mods or false if the update failed or there were no changes.
  3638 	 * @return array|false Returns array of updated stashed theme mods or false if the update failed or there were no changes.
  3652 		}
  3665 		}
  3653 		return $stashed_theme_mod_settings;
  3666 		return $stashed_theme_mod_settings;
  3654 	}
  3667 	}
  3655 
  3668 
  3656 	/**
  3669 	/**
  3657 	 * Refresh nonces for the current preview.
  3670 	 * Refreshes nonces for the current preview.
  3658 	 *
  3671 	 *
  3659 	 * @since 4.2.0
  3672 	 * @since 4.2.0
  3660 	 */
  3673 	 */
  3661 	public function refresh_nonces() {
  3674 	public function refresh_nonces() {
  3662 		if ( ! $this->is_preview() ) {
  3675 		if ( ! $this->is_preview() ) {
  3665 
  3678 
  3666 		wp_send_json_success( $this->get_nonces() );
  3679 		wp_send_json_success( $this->get_nonces() );
  3667 	}
  3680 	}
  3668 
  3681 
  3669 	/**
  3682 	/**
  3670 	 * Delete a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock.
  3683 	 * Deletes a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock.
  3671 	 *
  3684 	 *
  3672 	 * @since 4.9.0
  3685 	 * @since 4.9.0
  3673 	 */
  3686 	 */
  3674 	public function handle_dismiss_autosave_or_lock_request() {
  3687 	public function handle_dismiss_autosave_or_lock_request() {
  3675 		// Calls to dismiss_user_auto_draft_changesets() and wp_get_post_autosave() require non-zero get_current_user_id().
  3688 		// Calls to dismiss_user_auto_draft_changesets() and wp_get_post_autosave() require non-zero get_current_user_id().
  3733 
  3746 
  3734 		wp_send_json_error( 'unknown_error', 500 );
  3747 		wp_send_json_error( 'unknown_error', 500 );
  3735 	}
  3748 	}
  3736 
  3749 
  3737 	/**
  3750 	/**
  3738 	 * Add a customize setting.
  3751 	 * Adds a customize setting.
  3739 	 *
  3752 	 *
  3740 	 * @since 3.4.0
  3753 	 * @since 3.4.0
  3741 	 * @since 4.5.0 Return added WP_Customize_Setting instance.
  3754 	 * @since 4.5.0 Return added WP_Customize_Setting instance.
  3742 	 *
  3755 	 *
  3743 	 * @see WP_Customize_Setting::__construct()
  3756 	 * @see WP_Customize_Setting::__construct()
  3767 		$this->settings[ $setting->id ] = $setting;
  3780 		$this->settings[ $setting->id ] = $setting;
  3768 		return $setting;
  3781 		return $setting;
  3769 	}
  3782 	}
  3770 
  3783 
  3771 	/**
  3784 	/**
  3772 	 * Register any dynamically-created settings, such as those from $_POST['customized']
  3785 	 * Registers any dynamically-created settings, such as those from $_POST['customized']
  3773 	 * that have no corresponding setting created.
  3786 	 * that have no corresponding setting created.
  3774 	 *
  3787 	 *
  3775 	 * This is a mechanism to "wake up" settings that have been dynamically created
  3788 	 * This is a mechanism to "wake up" settings that have been dynamically created
  3776 	 * on the front end and have been sent to WordPress in `$_POST['customized']`. When WP
  3789 	 * on the front end and have been sent to WordPress in `$_POST['customized']`. When WP
  3777 	 * loads, the dynamically-created settings then will get created and previewed
  3790 	 * loads, the dynamically-created settings then will get created and previewed
  3828 		}
  3841 		}
  3829 		return $new_settings;
  3842 		return $new_settings;
  3830 	}
  3843 	}
  3831 
  3844 
  3832 	/**
  3845 	/**
  3833 	 * Retrieve a customize setting.
  3846 	 * Retrieves a customize setting.
  3834 	 *
  3847 	 *
  3835 	 * @since 3.4.0
  3848 	 * @since 3.4.0
  3836 	 *
  3849 	 *
  3837 	 * @param string $id Customize Setting ID.
  3850 	 * @param string $id Customize Setting ID.
  3838 	 * @return WP_Customize_Setting|void The setting, if set.
  3851 	 * @return WP_Customize_Setting|void The setting, if set.
  3842 			return $this->settings[ $id ];
  3855 			return $this->settings[ $id ];
  3843 		}
  3856 		}
  3844 	}
  3857 	}
  3845 
  3858 
  3846 	/**
  3859 	/**
  3847 	 * Remove a customize setting.
  3860 	 * Removes a customize setting.
  3848 	 *
  3861 	 *
  3849 	 * Note that removing the setting doesn't destroy the WP_Customize_Setting instance or remove its filters.
  3862 	 * Note that removing the setting doesn't destroy the WP_Customize_Setting instance or remove its filters.
  3850 	 *
  3863 	 *
  3851 	 * @since 3.4.0
  3864 	 * @since 3.4.0
  3852 	 *
  3865 	 *
  3855 	public function remove_setting( $id ) {
  3868 	public function remove_setting( $id ) {
  3856 		unset( $this->settings[ $id ] );
  3869 		unset( $this->settings[ $id ] );
  3857 	}
  3870 	}
  3858 
  3871 
  3859 	/**
  3872 	/**
  3860 	 * Add a customize panel.
  3873 	 * Adds a customize panel.
  3861 	 *
  3874 	 *
  3862 	 * @since 4.0.0
  3875 	 * @since 4.0.0
  3863 	 * @since 4.5.0 Return added WP_Customize_Panel instance.
  3876 	 * @since 4.5.0 Return added WP_Customize_Panel instance.
  3864 	 *
  3877 	 *
  3865 	 * @see WP_Customize_Panel::__construct()
  3878 	 * @see WP_Customize_Panel::__construct()
  3880 		$this->panels[ $panel->id ] = $panel;
  3893 		$this->panels[ $panel->id ] = $panel;
  3881 		return $panel;
  3894 		return $panel;
  3882 	}
  3895 	}
  3883 
  3896 
  3884 	/**
  3897 	/**
  3885 	 * Retrieve a customize panel.
  3898 	 * Retrieves a customize panel.
  3886 	 *
  3899 	 *
  3887 	 * @since 4.0.0
  3900 	 * @since 4.0.0
  3888 	 *
  3901 	 *
  3889 	 * @param string $id Panel ID to get.
  3902 	 * @param string $id Panel ID to get.
  3890 	 * @return WP_Customize_Panel|void Requested panel instance, if set.
  3903 	 * @return WP_Customize_Panel|void Requested panel instance, if set.
  3894 			return $this->panels[ $id ];
  3907 			return $this->panels[ $id ];
  3895 		}
  3908 		}
  3896 	}
  3909 	}
  3897 
  3910 
  3898 	/**
  3911 	/**
  3899 	 * Remove a customize panel.
  3912 	 * Removes a customize panel.
  3900 	 *
  3913 	 *
  3901 	 * Note that removing the panel doesn't destroy the WP_Customize_Panel instance or remove its filters.
  3914 	 * Note that removing the panel doesn't destroy the WP_Customize_Panel instance or remove its filters.
  3902 	 *
  3915 	 *
  3903 	 * @since 4.0.0
  3916 	 * @since 4.0.0
  3904 	 *
  3917 	 *
  3924 		}
  3937 		}
  3925 		unset( $this->panels[ $id ] );
  3938 		unset( $this->panels[ $id ] );
  3926 	}
  3939 	}
  3927 
  3940 
  3928 	/**
  3941 	/**
  3929 	 * Register a customize panel type.
  3942 	 * Registers a customize panel type.
  3930 	 *
  3943 	 *
  3931 	 * Registered types are eligible to be rendered via JS and created dynamically.
  3944 	 * Registered types are eligible to be rendered via JS and created dynamically.
  3932 	 *
  3945 	 *
  3933 	 * @since 4.3.0
  3946 	 * @since 4.3.0
  3934 	 *
  3947 	 *
  3939 	public function register_panel_type( $panel ) {
  3952 	public function register_panel_type( $panel ) {
  3940 		$this->registered_panel_types[] = $panel;
  3953 		$this->registered_panel_types[] = $panel;
  3941 	}
  3954 	}
  3942 
  3955 
  3943 	/**
  3956 	/**
  3944 	 * Render JS templates for all registered panel types.
  3957 	 * Renders JS templates for all registered panel types.
  3945 	 *
  3958 	 *
  3946 	 * @since 4.3.0
  3959 	 * @since 4.3.0
  3947 	 */
  3960 	 */
  3948 	public function render_panel_templates() {
  3961 	public function render_panel_templates() {
  3949 		foreach ( $this->registered_panel_types as $panel_type ) {
  3962 		foreach ( $this->registered_panel_types as $panel_type ) {
  3951 			$panel->print_template();
  3964 			$panel->print_template();
  3952 		}
  3965 		}
  3953 	}
  3966 	}
  3954 
  3967 
  3955 	/**
  3968 	/**
  3956 	 * Add a customize section.
  3969 	 * Adds a customize section.
  3957 	 *
  3970 	 *
  3958 	 * @since 3.4.0
  3971 	 * @since 3.4.0
  3959 	 * @since 4.5.0 Return added WP_Customize_Section instance.
  3972 	 * @since 4.5.0 Return added WP_Customize_Section instance.
  3960 	 *
  3973 	 *
  3961 	 * @see WP_Customize_Section::__construct()
  3974 	 * @see WP_Customize_Section::__construct()
  3976 		$this->sections[ $section->id ] = $section;
  3989 		$this->sections[ $section->id ] = $section;
  3977 		return $section;
  3990 		return $section;
  3978 	}
  3991 	}
  3979 
  3992 
  3980 	/**
  3993 	/**
  3981 	 * Retrieve a customize section.
  3994 	 * Retrieves a customize section.
  3982 	 *
  3995 	 *
  3983 	 * @since 3.4.0
  3996 	 * @since 3.4.0
  3984 	 *
  3997 	 *
  3985 	 * @param string $id Section ID.
  3998 	 * @param string $id Section ID.
  3986 	 * @return WP_Customize_Section|void The section, if set.
  3999 	 * @return WP_Customize_Section|void The section, if set.
  3990 			return $this->sections[ $id ];
  4003 			return $this->sections[ $id ];
  3991 		}
  4004 		}
  3992 	}
  4005 	}
  3993 
  4006 
  3994 	/**
  4007 	/**
  3995 	 * Remove a customize section.
  4008 	 * Removes a customize section.
  3996 	 *
  4009 	 *
  3997 	 * Note that removing the section doesn't destroy the WP_Customize_Section instance or remove its filters.
  4010 	 * Note that removing the section doesn't destroy the WP_Customize_Section instance or remove its filters.
  3998 	 *
  4011 	 *
  3999 	 * @since 3.4.0
  4012 	 * @since 3.4.0
  4000 	 *
  4013 	 *
  4003 	public function remove_section( $id ) {
  4016 	public function remove_section( $id ) {
  4004 		unset( $this->sections[ $id ] );
  4017 		unset( $this->sections[ $id ] );
  4005 	}
  4018 	}
  4006 
  4019 
  4007 	/**
  4020 	/**
  4008 	 * Register a customize section type.
  4021 	 * Registers a customize section type.
  4009 	 *
  4022 	 *
  4010 	 * Registered types are eligible to be rendered via JS and created dynamically.
  4023 	 * Registered types are eligible to be rendered via JS and created dynamically.
  4011 	 *
  4024 	 *
  4012 	 * @since 4.3.0
  4025 	 * @since 4.3.0
  4013 	 *
  4026 	 *
  4018 	public function register_section_type( $section ) {
  4031 	public function register_section_type( $section ) {
  4019 		$this->registered_section_types[] = $section;
  4032 		$this->registered_section_types[] = $section;
  4020 	}
  4033 	}
  4021 
  4034 
  4022 	/**
  4035 	/**
  4023 	 * Render JS templates for all registered section types.
  4036 	 * Renders JS templates for all registered section types.
  4024 	 *
  4037 	 *
  4025 	 * @since 4.3.0
  4038 	 * @since 4.3.0
  4026 	 */
  4039 	 */
  4027 	public function render_section_templates() {
  4040 	public function render_section_templates() {
  4028 		foreach ( $this->registered_section_types as $section_type ) {
  4041 		foreach ( $this->registered_section_types as $section_type ) {
  4030 			$section->print_template();
  4043 			$section->print_template();
  4031 		}
  4044 		}
  4032 	}
  4045 	}
  4033 
  4046 
  4034 	/**
  4047 	/**
  4035 	 * Add a customize control.
  4048 	 * Adds a customize control.
  4036 	 *
  4049 	 *
  4037 	 * @since 3.4.0
  4050 	 * @since 3.4.0
  4038 	 * @since 4.5.0 Return added WP_Customize_Control instance.
  4051 	 * @since 4.5.0 Return added WP_Customize_Control instance.
  4039 	 *
  4052 	 *
  4040 	 * @see WP_Customize_Control::__construct()
  4053 	 * @see WP_Customize_Control::__construct()
  4055 		$this->controls[ $control->id ] = $control;
  4068 		$this->controls[ $control->id ] = $control;
  4056 		return $control;
  4069 		return $control;
  4057 	}
  4070 	}
  4058 
  4071 
  4059 	/**
  4072 	/**
  4060 	 * Retrieve a customize control.
  4073 	 * Retrieves a customize control.
  4061 	 *
  4074 	 *
  4062 	 * @since 3.4.0
  4075 	 * @since 3.4.0
  4063 	 *
  4076 	 *
  4064 	 * @param string $id ID of the control.
  4077 	 * @param string $id ID of the control.
  4065 	 * @return WP_Customize_Control|void The control object, if set.
  4078 	 * @return WP_Customize_Control|void The control object, if set.
  4069 			return $this->controls[ $id ];
  4082 			return $this->controls[ $id ];
  4070 		}
  4083 		}
  4071 	}
  4084 	}
  4072 
  4085 
  4073 	/**
  4086 	/**
  4074 	 * Remove a customize control.
  4087 	 * Removes a customize control.
  4075 	 *
  4088 	 *
  4076 	 * Note that removing the control doesn't destroy the WP_Customize_Control instance or remove its filters.
  4089 	 * Note that removing the control doesn't destroy the WP_Customize_Control instance or remove its filters.
  4077 	 *
  4090 	 *
  4078 	 * @since 3.4.0
  4091 	 * @since 3.4.0
  4079 	 *
  4092 	 *
  4082 	public function remove_control( $id ) {
  4095 	public function remove_control( $id ) {
  4083 		unset( $this->controls[ $id ] );
  4096 		unset( $this->controls[ $id ] );
  4084 	}
  4097 	}
  4085 
  4098 
  4086 	/**
  4099 	/**
  4087 	 * Register a customize control type.
  4100 	 * Registers a customize control type.
  4088 	 *
  4101 	 *
  4089 	 * Registered types are eligible to be rendered via JS and created dynamically.
  4102 	 * Registered types are eligible to be rendered via JS and created dynamically.
  4090 	 *
  4103 	 *
  4091 	 * @since 4.1.0
  4104 	 * @since 4.1.0
  4092 	 *
  4105 	 *
  4096 	public function register_control_type( $control ) {
  4109 	public function register_control_type( $control ) {
  4097 		$this->registered_control_types[] = $control;
  4110 		$this->registered_control_types[] = $control;
  4098 	}
  4111 	}
  4099 
  4112 
  4100 	/**
  4113 	/**
  4101 	 * Render JS templates for all registered control types.
  4114 	 * Renders JS templates for all registered control types.
  4102 	 *
  4115 	 *
  4103 	 * @since 4.1.0
  4116 	 * @since 4.1.0
  4104 	 */
  4117 	 */
  4105 	public function render_control_templates() {
  4118 	public function render_control_templates() {
  4106 		if ( $this->branching() ) {
  4119 		if ( $this->branching() ) {
  4386 			return $a->priority - $b->priority;
  4399 			return $a->priority - $b->priority;
  4387 		}
  4400 		}
  4388 	}
  4401 	}
  4389 
  4402 
  4390 	/**
  4403 	/**
  4391 	 * Prepare panels, sections, and controls.
  4404 	 * Prepares panels, sections, and controls.
  4392 	 *
  4405 	 *
  4393 	 * For each, check if required related components exist,
  4406 	 * For each, check if required related components exist,
  4394 	 * whether the user has the necessary capabilities,
  4407 	 * whether the user has the necessary capabilities,
  4395 	 * and sort by priority.
  4408 	 * and sort by priority.
  4396 	 *
  4409 	 *
  4498 			true
  4511 			true
  4499 		);
  4512 		);
  4500 	}
  4513 	}
  4501 
  4514 
  4502 	/**
  4515 	/**
  4503 	 * Enqueue scripts for customize controls.
  4516 	 * Enqueues scripts for customize controls.
  4504 	 *
  4517 	 *
  4505 	 * @since 3.4.0
  4518 	 * @since 3.4.0
  4506 	 */
  4519 	 */
  4507 	public function enqueue_control_scripts() {
  4520 	public function enqueue_control_scripts() {
  4508 		foreach ( $this->controls as $control ) {
  4521 		foreach ( $this->controls as $control ) {
  4520 			);
  4533 			);
  4521 		}
  4534 		}
  4522 	}
  4535 	}
  4523 
  4536 
  4524 	/**
  4537 	/**
  4525 	 * Determine whether the user agent is iOS.
  4538 	 * Determines whether the user agent is iOS.
  4526 	 *
  4539 	 *
  4527 	 * @since 4.4.0
  4540 	 * @since 4.4.0
  4528 	 *
  4541 	 *
  4529 	 * @return bool Whether the user agent is iOS.
  4542 	 * @return bool Whether the user agent is iOS.
  4530 	 */
  4543 	 */
  4531 	public function is_ios() {
  4544 	public function is_ios() {
  4532 		return wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
  4545 		return wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
  4533 	}
  4546 	}
  4534 
  4547 
  4535 	/**
  4548 	/**
  4536 	 * Get the template string for the Customizer pane document title.
  4549 	 * Gets the template string for the Customizer pane document title.
  4537 	 *
  4550 	 *
  4538 	 * @since 4.4.0
  4551 	 * @since 4.4.0
  4539 	 *
  4552 	 *
  4540 	 * @return string The template string for the document title.
  4553 	 * @return string The template string for the document title.
  4541 	 */
  4554 	 */
  4550 		$document_title_tmpl = html_entity_decode( $document_title_tmpl, ENT_QUOTES, 'UTF-8' ); // Because exported to JS and assigned to document.title.
  4563 		$document_title_tmpl = html_entity_decode( $document_title_tmpl, ENT_QUOTES, 'UTF-8' ); // Because exported to JS and assigned to document.title.
  4551 		return $document_title_tmpl;
  4564 		return $document_title_tmpl;
  4552 	}
  4565 	}
  4553 
  4566 
  4554 	/**
  4567 	/**
  4555 	 * Set the initial URL to be previewed.
  4568 	 * Sets the initial URL to be previewed.
  4556 	 *
  4569 	 *
  4557 	 * URL is validated.
  4570 	 * URL is validated.
  4558 	 *
  4571 	 *
  4559 	 * @since 4.4.0
  4572 	 * @since 4.4.0
  4560 	 *
  4573 	 *
  4564 		$preview_url       = esc_url_raw( $preview_url );
  4577 		$preview_url       = esc_url_raw( $preview_url );
  4565 		$this->preview_url = wp_validate_redirect( $preview_url, home_url( '/' ) );
  4578 		$this->preview_url = wp_validate_redirect( $preview_url, home_url( '/' ) );
  4566 	}
  4579 	}
  4567 
  4580 
  4568 	/**
  4581 	/**
  4569 	 * Get the initial URL to be previewed.
  4582 	 * Gets the initial URL to be previewed.
  4570 	 *
  4583 	 *
  4571 	 * @since 4.4.0
  4584 	 * @since 4.4.0
  4572 	 *
  4585 	 *
  4573 	 * @return string URL being previewed.
  4586 	 * @return string URL being previewed.
  4574 	 */
  4587 	 */
  4594 		$cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) );
  4607 		$cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) );
  4595 		return $cross_domain;
  4608 		return $cross_domain;
  4596 	}
  4609 	}
  4597 
  4610 
  4598 	/**
  4611 	/**
  4599 	 * Get URLs allowed to be previewed.
  4612 	 * Gets URLs allowed to be previewed.
  4600 	 *
  4613 	 *
  4601 	 * If the front end and the admin are served from the same domain, load the
  4614 	 * If the front end and the admin are served from the same domain, load the
  4602 	 * preview over ssl if the Customizer is being loaded over ssl. This avoids
  4615 	 * preview over ssl if the Customizer is being loaded over ssl. This avoids
  4603 	 * insecure content warnings. This is not attempted if the admin and front end
  4616 	 * insecure content warnings. This is not attempted if the admin and front end
  4604 	 * are on different domains to avoid the case where the front end doesn't have
  4617 	 * are on different domains to avoid the case where the front end doesn't have
  4627 
  4640 
  4628 		return $allowed_urls;
  4641 		return $allowed_urls;
  4629 	}
  4642 	}
  4630 
  4643 
  4631 	/**
  4644 	/**
  4632 	 * Get messenger channel.
  4645 	 * Gets messenger channel.
  4633 	 *
  4646 	 *
  4634 	 * @since 4.7.0
  4647 	 * @since 4.7.0
  4635 	 *
  4648 	 *
  4636 	 * @return string Messenger channel.
  4649 	 * @return string Messenger channel.
  4637 	 */
  4650 	 */
  4638 	public function get_messenger_channel() {
  4651 	public function get_messenger_channel() {
  4639 		return $this->messenger_channel;
  4652 		return $this->messenger_channel;
  4640 	}
  4653 	}
  4641 
  4654 
  4642 	/**
  4655 	/**
  4643 	 * Set URL to link the user to when closing the Customizer.
  4656 	 * Sets URL to link the user to when closing the Customizer.
  4644 	 *
  4657 	 *
  4645 	 * URL is validated.
  4658 	 * URL is validated.
  4646 	 *
  4659 	 *
  4647 	 * @since 4.4.0
  4660 	 * @since 4.4.0
  4648 	 *
  4661 	 *
  4654 		$return_url       = wp_validate_redirect( $return_url );
  4667 		$return_url       = wp_validate_redirect( $return_url );
  4655 		$this->return_url = $return_url;
  4668 		$this->return_url = $return_url;
  4656 	}
  4669 	}
  4657 
  4670 
  4658 	/**
  4671 	/**
  4659 	 * Get URL to link the user to when closing the Customizer.
  4672 	 * Gets URL to link the user to when closing the Customizer.
  4660 	 *
  4673 	 *
  4661 	 * @since 4.4.0
  4674 	 * @since 4.4.0
  4662 	 *
  4675 	 *
  4663 	 * @global array $_registered_pages
  4676 	 * @global array $_registered_pages
  4664 	 *
  4677 	 *
  4686 		if ( 'themes.php' === $return_url_basename && $return_url_query ) {
  4699 		if ( 'themes.php' === $return_url_basename && $return_url_query ) {
  4687 			parse_str( $return_url_query, $query_vars );
  4700 			parse_str( $return_url_query, $query_vars );
  4688 
  4701 
  4689 			/*
  4702 			/*
  4690 			 * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(),
  4703 			 * If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(),
  4691 			 * verify that belongs to the active theme, otherwise fall back to the Themes screen.
  4704 			 * verify that it belongs to the active theme, otherwise fall back to the Themes screen.
  4692 			 */
  4705 			 */
  4693 			if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) {
  4706 			if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) {
  4694 				$return_url = admin_url( 'themes.php' );
  4707 				$return_url = admin_url( 'themes.php' );
  4695 			}
  4708 			}
  4696 		}
  4709 		}
  4697 
  4710 
  4698 		return $return_url;
  4711 		return $return_url;
  4699 	}
  4712 	}
  4700 
  4713 
  4701 	/**
  4714 	/**
  4702 	 * Set the autofocused constructs.
  4715 	 * Sets the autofocused constructs.
  4703 	 *
  4716 	 *
  4704 	 * @since 4.4.0
  4717 	 * @since 4.4.0
  4705 	 *
  4718 	 *
  4706 	 * @param array $autofocus {
  4719 	 * @param array $autofocus {
  4707 	 *     Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
  4720 	 *     Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
  4714 	public function set_autofocus( $autofocus ) {
  4727 	public function set_autofocus( $autofocus ) {
  4715 		$this->autofocus = array_filter( wp_array_slice_assoc( $autofocus, array( 'panel', 'section', 'control' ) ), 'is_string' );
  4728 		$this->autofocus = array_filter( wp_array_slice_assoc( $autofocus, array( 'panel', 'section', 'control' ) ), 'is_string' );
  4716 	}
  4729 	}
  4717 
  4730 
  4718 	/**
  4731 	/**
  4719 	 * Get the autofocused constructs.
  4732 	 * Gets the autofocused constructs.
  4720 	 *
  4733 	 *
  4721 	 * @since 4.4.0
  4734 	 * @since 4.4.0
  4722 	 *
  4735 	 *
  4723 	 * @return array {
  4736 	 * @return string[] {
  4724 	 *     Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
  4737 	 *     Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
  4725 	 *
  4738 	 *
  4726 	 *     @type string $control ID for control to be autofocused.
  4739 	 *     @type string $control ID for control to be autofocused.
  4727 	 *     @type string $section ID for section to be autofocused.
  4740 	 *     @type string $section ID for section to be autofocused.
  4728 	 *     @type string $panel   ID for panel to be autofocused.
  4741 	 *     @type string $panel   ID for panel to be autofocused.
  4731 	public function get_autofocus() {
  4744 	public function get_autofocus() {
  4732 		return $this->autofocus;
  4745 		return $this->autofocus;
  4733 	}
  4746 	}
  4734 
  4747 
  4735 	/**
  4748 	/**
  4736 	 * Get nonces for the Customizer.
  4749 	 * Gets nonces for the Customizer.
  4737 	 *
  4750 	 *
  4738 	 * @since 4.5.0
  4751 	 * @since 4.5.0
  4739 	 *
  4752 	 *
  4740 	 * @return array Nonces.
  4753 	 * @return array Nonces.
  4741 	 */
  4754 	 */
  4752 		/**
  4765 		/**
  4753 		 * Filters nonces for Customizer.
  4766 		 * Filters nonces for Customizer.
  4754 		 *
  4767 		 *
  4755 		 * @since 4.2.0
  4768 		 * @since 4.2.0
  4756 		 *
  4769 		 *
  4757 		 * @param string[]             $nonces Array of refreshed nonces for save and
  4770 		 * @param string[]             $nonces  Array of refreshed nonces for save and
  4758 		 *                                     preview actions.
  4771 		 *                                      preview actions.
  4759 		 * @param WP_Customize_Manager $this   WP_Customize_Manager instance.
  4772 		 * @param WP_Customize_Manager $manager WP_Customize_Manager instance.
  4760 		 */
  4773 		 */
  4761 		$nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this );
  4774 		$nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this );
  4762 
  4775 
  4763 		return $nonces;
  4776 		return $nonces;
  4764 	}
  4777 	}
  4765 
  4778 
  4766 	/**
  4779 	/**
  4767 	 * Print JavaScript settings for parent window.
  4780 	 * Prints JavaScript settings for parent window.
  4768 	 *
  4781 	 *
  4769 	 * @since 4.4.0
  4782 	 * @since 4.4.0
  4770 	 */
  4783 	 */
  4771 	public function customize_pane_settings() {
  4784 	public function customize_pane_settings() {
  4772 
  4785 
  5012 
  5025 
  5013 		return $devices;
  5026 		return $devices;
  5014 	}
  5027 	}
  5015 
  5028 
  5016 	/**
  5029 	/**
  5017 	 * Register some default controls.
  5030 	 * Registers some default controls.
  5018 	 *
  5031 	 *
  5019 	 * @since 3.4.0
  5032 	 * @since 3.4.0
  5020 	 */
  5033 	 */
  5021 	public function register_controls() {
  5034 	public function register_controls() {
  5022 
  5035 
  5730 			)
  5743 			)
  5731 		);
  5744 		);
  5732 	}
  5745 	}
  5733 
  5746 
  5734 	/**
  5747 	/**
  5735 	 * Return whether there are published pages.
  5748 	 * Returns whether there are published pages.
  5736 	 *
  5749 	 *
  5737 	 * Used as active callback for static front page section and controls.
  5750 	 * Used as active callback for static front page section and controls.
  5738 	 *
  5751 	 *
  5739 	 * @since 4.7.0
  5752 	 * @since 4.7.0
  5740 	 *
  5753 	 *
  5748 				if ( 'page' === get_post_type( $post_id ) ) {
  5761 				if ( 'page' === get_post_type( $post_id ) ) {
  5749 					return true;
  5762 					return true;
  5750 				}
  5763 				}
  5751 			}
  5764 			}
  5752 		}
  5765 		}
  5753 		return 0 !== count( get_pages() );
  5766 		return 0 !== count( get_pages( array( 'number' => 1 ) ) );
  5754 	}
  5767 	}
  5755 
  5768 
  5756 	/**
  5769 	/**
  5757 	 * Add settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets
  5770 	 * Adds settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets
  5758 	 *
  5771 	 *
  5759 	 * @since 4.2.0
  5772 	 * @since 4.2.0
  5760 	 *
  5773 	 *
  5761 	 * @see add_dynamic_settings()
  5774 	 * @see add_dynamic_settings()
  5762 	 */
  5775 	 */
  5764 		$setting_ids = array_keys( $this->unsanitized_post_values() );
  5777 		$setting_ids = array_keys( $this->unsanitized_post_values() );
  5765 		$this->add_dynamic_settings( $setting_ids );
  5778 		$this->add_dynamic_settings( $setting_ids );
  5766 	}
  5779 	}
  5767 
  5780 
  5768 	/**
  5781 	/**
  5769 	 * Load themes into the theme browsing/installation UI.
  5782 	 * Loads themes into the theme browsing/installation UI.
  5770 	 *
  5783 	 *
  5771 	 * @since 4.9.0
  5784 	 * @since 4.9.0
  5772 	 */
  5785 	 */
  5773 	public function handle_load_themes_request() {
  5786 	public function handle_load_themes_request() {
  5774 		check_ajax_referer( 'switch_themes', 'nonce' );
  5787 		check_ajax_referer( 'switch_themes', 'nonce' );
  5806 		require_once ABSPATH . 'wp-admin/includes/theme.php';
  5819 		require_once ABSPATH . 'wp-admin/includes/theme.php';
  5807 
  5820 
  5808 		if ( 'installed' === $theme_action ) {
  5821 		if ( 'installed' === $theme_action ) {
  5809 
  5822 
  5810 			// Load all installed themes from wp_prepare_themes_for_js().
  5823 			// Load all installed themes from wp_prepare_themes_for_js().
  5811 			$themes = array( 'themes' => wp_prepare_themes_for_js() );
  5824 			$themes = array( 'themes' => array() );
  5812 			foreach ( $themes['themes'] as &$theme ) {
  5825 			foreach ( wp_prepare_themes_for_js() as $theme ) {
  5813 				$theme['type']   = 'installed';
  5826 				$theme['type']      = 'installed';
  5814 				$theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] );
  5827 				$theme['active']    = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] );
       
  5828 				$themes['themes'][] = $theme;
  5815 			}
  5829 			}
  5816 		} elseif ( 'wporg' === $theme_action ) {
  5830 		} elseif ( 'wporg' === $theme_action ) {
  5817 
  5831 
  5818 			// Load WordPress.org themes from the .org API and normalize data to match installed theme objects.
  5832 			// Load WordPress.org themes from the .org API and normalize data to match installed theme objects.
  5819 			if ( ! current_user_can( 'install_themes' ) ) {
  5833 			if ( ! current_user_can( 'install_themes' ) ) {
  5921 		 *
  5935 		 *
  5922 		 * @see wp_prepare_themes_for_js()
  5936 		 * @see wp_prepare_themes_for_js()
  5923 		 * @see themes_api()
  5937 		 * @see themes_api()
  5924 		 * @see WP_Customize_Manager::__construct()
  5938 		 * @see WP_Customize_Manager::__construct()
  5925 		 *
  5939 		 *
  5926 		 * @param array                $themes  Nested array of theme data.
  5940 		 * @param array|stdClass       $themes  Nested array or object of theme data.
  5927 		 * @param array                $args    List of arguments, such as page, search term, and tags to query for.
  5941 		 * @param array                $args    List of arguments, such as page, search term, and tags to query for.
  5928 		 * @param WP_Customize_Manager $manager Instance of Customize manager.
  5942 		 * @param WP_Customize_Manager $manager Instance of Customize manager.
  5929 		 */
  5943 		 */
  5930 		$themes = apply_filters( 'customize_load_themes', $themes, $args, $this );
  5944 		$themes = apply_filters( 'customize_load_themes', $themes, $args, $this );
  5931 
  5945 
  5998 		}
  6012 		}
  5999 		return $value;
  6013 		return $value;
  6000 	}
  6014 	}
  6001 
  6015 
  6002 	/**
  6016 	/**
  6003 	 * Export header video settings to facilitate selective refresh.
  6017 	 * Exports header video settings to facilitate selective refresh.
  6004 	 *
  6018 	 *
  6005 	 * @since 4.7.0
  6019 	 * @since 4.7.0
  6006 	 *
  6020 	 *
  6007 	 * @param array                          $response          Response.
  6021 	 * @param array                          $response          Response.
  6008 	 * @param WP_Customize_Selective_Refresh $selective_refresh Selective refresh component.
  6022 	 * @param WP_Customize_Selective_Refresh $selective_refresh Selective refresh component.