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 ); |
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() ) { |
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 */ |
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 ) { |
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(); |
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 |
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 ?> |
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. |
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 ); |
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( |
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. |
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 * |
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 |
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 * |
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 */ |
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 |
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. |
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 |
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 |