wp/wp-includes/class-wp-customize-widgets.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   236 	/**
   236 	/**
   237 	 * Retrieves an unslashed post value or return a default.
   237 	 * Retrieves an unslashed post value or return a default.
   238 	 *
   238 	 *
   239 	 * @since 3.9.0
   239 	 * @since 3.9.0
   240 	 *
   240 	 *
   241 	 * @param string $name    Post value.
   241 	 * @param string $name          Post value.
   242 	 * @param mixed  $default Default post value.
   242 	 * @param mixed  $default_value Default post value.
   243 	 * @return mixed Unslashed post value or default value.
   243 	 * @return mixed Unslashed post value or default value.
   244 	 */
   244 	 */
   245 	protected function get_post_value( $name, $default = null ) {
   245 	protected function get_post_value( $name, $default_value = null ) {
   246 		if ( ! isset( $_POST[ $name ] ) ) {
   246 		if ( ! isset( $_POST[ $name ] ) ) {
   247 			return $default;
   247 			return $default_value;
   248 		}
   248 		}
   249 
   249 
   250 		return wp_unslash( $_POST[ $name ] );
   250 		return wp_unslash( $_POST[ $name ] );
   251 	}
   251 	}
   252 
   252 
   418 				'title'                    => __( 'Widgets' ),
   418 				'title'                    => __( 'Widgets' ),
   419 				'description'              => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ),
   419 				'description'              => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ),
   420 				'priority'                 => 110,
   420 				'priority'                 => 110,
   421 				'active_callback'          => array( $this, 'is_panel_active' ),
   421 				'active_callback'          => array( $this, 'is_panel_active' ),
   422 				'auto_expand_sole_section' => true,
   422 				'auto_expand_sole_section' => true,
       
   423 				'theme_supports'           => 'widgets',
   423 			)
   424 			)
   424 		);
   425 		);
   425 
   426 
   426 		foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) {
   427 		foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) {
   427 			if ( empty( $sidebar_widget_ids ) ) {
   428 			if ( empty( $sidebar_widget_ids ) ) {
   744 		 * Gather all strings in PHP that may be needed by JS on the client.
   745 		 * Gather all strings in PHP that may be needed by JS on the client.
   745 		 * Once JS i18n is implemented (in #20491), this can be removed.
   746 		 * Once JS i18n is implemented (in #20491), this can be removed.
   746 		 */
   747 		 */
   747 		$some_non_rendered_areas_messages    = array();
   748 		$some_non_rendered_areas_messages    = array();
   748 		$some_non_rendered_areas_messages[1] = html_entity_decode(
   749 		$some_non_rendered_areas_messages[1] = html_entity_decode(
   749 			__( 'Your theme has 1 other widget area, but this particular page doesn’t display it.' ),
   750 			__( 'Your theme has 1 other widget area, but this particular page does not display it.' ),
   750 			ENT_QUOTES,
   751 			ENT_QUOTES,
   751 			get_bloginfo( 'charset' )
   752 			get_bloginfo( 'charset' )
   752 		);
   753 		);
   753 		$registered_sidebar_count            = count( $wp_registered_sidebars );
   754 		$registered_sidebar_count            = count( $wp_registered_sidebars );
   754 		for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) {
   755 		for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) {
   755 			$some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode(
   756 			$some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode(
   756 				sprintf(
   757 				sprintf(
   757 					/* translators: %s: The number of other widget areas registered but not rendered. */
   758 					/* translators: %s: The number of other widget areas registered but not rendered. */
   758 					_n(
   759 					_n(
   759 						'Your theme has %s other widget area, but this particular page doesn&#8217;t display it.',
   760 						'Your theme has %s other widget area, but this particular page does not display it.',
   760 						'Your theme has %s other widget areas, but this particular page doesn&#8217;t display them.',
   761 						'Your theme has %s other widget areas, but this particular page does not display them.',
   761 						$non_rendered_count
   762 						$non_rendered_count
   762 					),
   763 					),
   763 					number_format_i18n( $non_rendered_count )
   764 					number_format_i18n( $non_rendered_count )
   764 				),
   765 				),
   765 				ENT_QUOTES,
   766 				ENT_QUOTES,
   768 		}
   769 		}
   769 
   770 
   770 		if ( 1 === $registered_sidebar_count ) {
   771 		if ( 1 === $registered_sidebar_count ) {
   771 			$no_areas_shown_message = html_entity_decode(
   772 			$no_areas_shown_message = html_entity_decode(
   772 				sprintf(
   773 				sprintf(
   773 					__( 'Your theme has 1 widget area, but this particular page doesn&#8217;t display it.' )
   774 					__( 'Your theme has 1 widget area, but this particular page does not display it.' )
   774 				),
   775 				),
   775 				ENT_QUOTES,
   776 				ENT_QUOTES,
   776 				get_bloginfo( 'charset' )
   777 				get_bloginfo( 'charset' )
   777 			);
   778 			);
   778 		} else {
   779 		} else {
   779 			$no_areas_shown_message = html_entity_decode(
   780 			$no_areas_shown_message = html_entity_decode(
   780 				sprintf(
   781 				sprintf(
   781 					/* translators: %s: The total number of widget areas registered. */
   782 					/* translators: %s: The total number of widget areas registered. */
   782 					_n(
   783 					_n(
   783 						'Your theme has %s widget area, but this particular page doesn&#8217;t display it.',
   784 						'Your theme has %s widget area, but this particular page does not display it.',
   784 						'Your theme has %s widget areas, but this particular page doesn&#8217;t display them.',
   785 						'Your theme has %s widget areas, but this particular page does not display them.',
   785 						$registered_sidebar_count
   786 						$registered_sidebar_count
   786 					),
   787 					),
   787 					number_format_i18n( $registered_sidebar_count )
   788 					number_format_i18n( $registered_sidebar_count )
   788 				),
   789 				),
   789 				ENT_QUOTES,
   790 				ENT_QUOTES,
   835 		 * 'customize-widgets'. This will let us skip most of the above and not
   836 		 * 'customize-widgets'. This will let us skip most of the above and not
   836 		 * enqueue 'customize-widgets' which saves bytes.
   837 		 * enqueue 'customize-widgets' which saves bytes.
   837 		 */
   838 		 */
   838 
   839 
   839 		if ( wp_use_widgets_block_editor() ) {
   840 		if ( wp_use_widgets_block_editor() ) {
   840 			$block_editor_context = new WP_Block_Editor_Context();
   841 			$block_editor_context = new WP_Block_Editor_Context(
       
   842 				array(
       
   843 					'name' => 'core/customize-widgets',
       
   844 				)
       
   845 			);
   841 
   846 
   842 			$editor_settings = get_block_editor_settings(
   847 			$editor_settings = get_block_editor_settings(
   843 				get_legacy_widget_block_editor_settings(),
   848 				get_legacy_widget_block_editor_settings(),
   844 				$block_editor_context
   849 				$block_editor_context
   845 			);
   850 			);
  1419 		if ( isset( $value['raw_instance'] ) && $id_base && wp_use_widgets_block_editor() ) {
  1424 		if ( isset( $value['raw_instance'] ) && $id_base && wp_use_widgets_block_editor() ) {
  1420 			$widget_object = $wp_widget_factory->get_widget_object( $id_base );
  1425 			$widget_object = $wp_widget_factory->get_widget_object( $id_base );
  1421 			if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
  1426 			if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
  1422 				if ( 'block' === $id_base && ! current_user_can( 'unfiltered_html' ) ) {
  1427 				if ( 'block' === $id_base && ! current_user_can( 'unfiltered_html' ) ) {
  1423 					/*
  1428 					/*
  1424 					 * The content of the 'block' widget is not filtered on the
  1429 					 * The content of the 'block' widget is not filtered on the fly while editing.
  1425 					 * fly while editing. Filter the content here to prevent
  1430 					 * Filter the content here to prevent vulnerabilities.
  1426 					 * vulnerabilities.
       
  1427 					 */
  1431 					 */
  1428 					$value['raw_instance']['content'] = wp_kses_post( $value['raw_instance']['content'] );
  1432 					$value['raw_instance']['content'] = wp_kses_post( $value['raw_instance']['content'] );
  1429 				}
  1433 				}
  1430 
  1434 
  1431 				return $value['raw_instance'];
  1435 				return $value['raw_instance'];
  2051 	/**
  2055 	/**
  2052 	 * Retrieves the option that was captured from being saved.
  2056 	 * Retrieves the option that was captured from being saved.
  2053 	 *
  2057 	 *
  2054 	 * @since 4.2.0
  2058 	 * @since 4.2.0
  2055 	 *
  2059 	 *
  2056 	 * @param string $option_name Option name.
  2060 	 * @param string $option_name   Option name.
  2057 	 * @param mixed  $default     Optional. Default value to return if the option does not exist. Default false.
  2061 	 * @param mixed  $default_value Optional. Default value to return if the option does not exist. Default false.
  2058 	 * @return mixed Value set for the option.
  2062 	 * @return mixed Value set for the option.
  2059 	 */
  2063 	 */
  2060 	protected function get_captured_option( $option_name, $default = false ) {
  2064 	protected function get_captured_option( $option_name, $default_value = false ) {
  2061 		if ( array_key_exists( $option_name, $this->_captured_options ) ) {
  2065 		if ( array_key_exists( $option_name, $this->_captured_options ) ) {
  2062 			$value = $this->_captured_options[ $option_name ];
  2066 			$value = $this->_captured_options[ $option_name ];
  2063 		} else {
  2067 		} else {
  2064 			$value = $default;
  2068 			$value = $default_value;
  2065 		}
  2069 		}
  2066 		return $value;
  2070 		return $value;
  2067 	}
  2071 	}
  2068 
  2072 
  2069 	/**
  2073 	/**