wp/wp-includes/blocks/legacy-widget.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the 'core/legacy-widget' block.
     9  * Renders the 'core/legacy-widget' block.
       
    10  *
       
    11  * @since 5.8.0
       
    12  *
       
    13  * @global int $wp_widget_factory.
    10  *
    14  *
    11  * @param array $attributes The block attributes.
    15  * @param array $attributes The block attributes.
    12  *
    16  *
    13  * @return string Rendered block.
    17  * @return string Rendered block.
    14  */
    18  */
    32 		return '';
    36 		return '';
    33 	}
    37 	}
    34 
    38 
    35 	if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) {
    39 	if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) {
    36 		$serialized_instance = base64_decode( $attributes['instance']['encoded'] );
    40 		$serialized_instance = base64_decode( $attributes['instance']['encoded'] );
    37 		if ( wp_hash( $serialized_instance ) !== $attributes['instance']['hash'] ) {
    41 		if ( ! hash_equals( wp_hash( $serialized_instance ), (string) $attributes['instance']['hash'] ) ) {
    38 			return '';
    42 			return '';
    39 		}
    43 		}
    40 		$instance = unserialize( $serialized_instance );
    44 		$instance = unserialize( $serialized_instance );
    41 	} else {
    45 	} else {
    42 		$instance = array();
    46 		$instance = array();
    52 	return ob_get_clean();
    56 	return ob_get_clean();
    53 }
    57 }
    54 
    58 
    55 /**
    59 /**
    56  * Registers the 'core/legacy-widget' block.
    60  * Registers the 'core/legacy-widget' block.
       
    61  *
       
    62  * @since 5.8.0
    57  */
    63  */
    58 function register_block_core_legacy_widget() {
    64 function register_block_core_legacy_widget() {
    59 	register_block_type_from_metadata(
    65 	register_block_type_from_metadata(
    60 		__DIR__ . '/legacy-widget',
    66 		__DIR__ . '/legacy-widget',
    61 		array(
    67 		array(
    68 
    74 
    69 /**
    75 /**
    70  * Intercepts any request with legacy-widget-preview in the query param and, if
    76  * Intercepts any request with legacy-widget-preview in the query param and, if
    71  * set, renders a page containing a preview of the requested Legacy Widget
    77  * set, renders a page containing a preview of the requested Legacy Widget
    72  * block.
    78  * block.
       
    79  *
       
    80  * @since 5.8.0
    73  */
    81  */
    74 function handle_legacy_widget_preview_iframe() {
    82 function handle_legacy_widget_preview_iframe() {
    75 	if ( empty( $_GET['legacy-widget-preview'] ) ) {
    83 	if ( empty( $_GET['legacy-widget-preview'] ) ) {
    76 		return;
    84 		return;
    77 	}
    85 	}