Make WordPress Core


Ignore:
Timestamp:
09/26/2023 04:59:11 PM (12 months ago)
Author:
Bernhard Reiter
Message:

Templates: Introduce _remove_theme_attribute_from_template_part_block.

Introduce a _remove_theme_attribute_from_template_part_block() function that can be used as a callback argument for traverse_and_serialize_block(s) on a parsed block tree in order to remove the theme attribute from all Template Part blocks found therein, and deprecate _remove_theme_attribute_in_block_template_content().

Counterpart to _inject_theme_attribute_in_template_part_block from #59338 (which superseded _inject_theme_attribute_in_block_template_content, deprecated in #59452).

Props mukesh27.
Fixes #59460.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-template-utils.php

    r56719 r56724  
    362362    /**
    363363     * @ticket 54448
     364     * @ticket 59460
    364365     *
    365366     * @dataProvider data_remove_theme_attribute_in_block_template_content
     367     *
     368     * @expectedDeprecated _remove_theme_attribute_in_block_template_content
    366369     */
    367370    public function test_remove_theme_attribute_in_block_template_content( $template_content, $expected ) {
    368371        $this->assertSame( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );
     372    }
     373
     374    /**
     375     * @ticket 59460
     376     *
     377     * @covers ::_remove_theme_attribute_from_template_part_block
     378     * @covers ::traverse_and_serialize_blocks
     379     *
     380     * @dataProvider data_remove_theme_attribute_in_block_template_content
     381     *
     382     * @param string $template_content The template markup.
     383     * @param string $expected         The expected markup after removing the theme attribute from Template Part blocks.
     384     */
     385    public function test_remove_theme_attribute_from_template_part_block( $template_content, $expected ) {
     386        $template_content_parsed_blocks = parse_blocks( $template_content );
     387
     388        $this->assertSame(
     389            $expected,
     390            traverse_and_serialize_blocks(
     391                $template_content_parsed_blocks,
     392                '_remove_theme_attribute_from_template_part_block'
     393            )
     394        );
    369395    }
    370396
Note: See TracChangeset for help on using the changeset viewer.