Make WordPress Core


Ignore:
Timestamp:
09/26/2023 04:47:24 PM (2 years ago)
Author:
Bernhard Reiter
Message:

Templates: Move old theme attr injection function to deprecated.php.

Move the now-deprecated function _inject_theme_attribute_in_block_template_content from wp-includes/block-template-utils.php to wp-includes/deprecated.php.

Follow-up [56719].
Props spacedmonkey, davidbaumwald, mukesh27.
See #59452.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r56719 r56722  
    469469
    470470    return $all_blocks;
    471 }
    472 
    473 /**
    474  * Parses wp_template content and injects the active theme's
    475  * stylesheet as a theme attribute into each wp_template_part
    476  *
    477  * @since 5.9.0
    478  * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead.
    479  * @access private
    480  *
    481  * @param string $template_content serialized wp_template content.
    482  * @return string Updated 'wp_template' content.
    483  */
    484 function _inject_theme_attribute_in_block_template_content( $template_content ) {
    485     _deprecated_function(
    486         __FUNCTION__,
    487         '6.4.0',
    488         'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )'
    489     );
    490 
    491     $has_updated_content = false;
    492     $new_content         = '';
    493     $template_blocks     = parse_blocks( $template_content );
    494 
    495     $blocks = _flatten_blocks( $template_blocks );
    496     foreach ( $blocks as &$block ) {
    497         if (
    498             'core/template-part' === $block['blockName'] &&
    499             ! isset( $block['attrs']['theme'] )
    500         ) {
    501             $block['attrs']['theme'] = get_stylesheet();
    502             $has_updated_content     = true;
    503         }
    504     }
    505 
    506     if ( $has_updated_content ) {
    507         foreach ( $template_blocks as &$block ) {
    508             $new_content .= serialize_block( $block );
    509         }
    510 
    511         return $new_content;
    512     }
    513 
    514     return $template_content;
    515471}
    516472
Note: See TracChangeset for help on using the changeset viewer.