Make WordPress Core


Ignore:
Timestamp:
03/13/2024 10:46:53 AM (3 months ago)
Author:
swissspidy
Message:

Interactivity API: Increase hook priority for processing directives.

Use a priority of 100 to ensure that other filters can add additional directives before the processing starts.
This way, directives will be processed even if the $parsed_block variable is edited by a filter.

Props cbravobernal, swissspidy, flixos90, joemcgill, gziolo.
Fixes #60743.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php

    r57822 r57826  
    309309        $this->data_wp_test_processor_count = 0;
    310310        do_blocks( $post_content );
     311        unregister_block_type( 'test/custom-directive-block' );
    311312        $this->assertEquals( 2, $this->data_wp_test_processor_count );
     313        $directive_processors->setValue( null, $old_directive_processors );
     314    }
     315
     316    /**
     317     * Tests that directives are server side processing even if the $parsed_block variable is edited by a filter.
     318     *
     319     * @ticket 60743
     320     *
     321     * @covers ::wp_interactivity_process_directives_of_interactive_blocks
     322     */
     323    public function test_process_directives_when_block_is_filtered() {
     324        register_block_type(
     325            'test/custom-directive-block',
     326            array(
     327                'render_callback' => function () {
     328                    return '<input data-wp-interactive="nameSpace" ' . wp_interactivity_data_wp_context( array( 'text' => 'test' ) ) . ' data-wp-bind--value="context.text" />';
     329                },
     330                'supports'        => array(
     331                    'interactivity' => true,
     332                ),
     333            )
     334        );
     335        function test_render_block_data( $parsed_block ) {
     336            $parsed_block['testKey'] = true;
     337            return $parsed_block;
     338        }
     339        add_filter( 'render_block_data', 'test_render_block_data' );
     340        $post_content      = '<!-- wp:test/custom-directive-block /-->';
     341        $processed_content = do_blocks( $post_content );
     342        $processor         = new WP_HTML_Tag_Processor( $processed_content );
     343        $processor->next_tag( array( 'data-wp-interactive' => 'nameSpace' ) );
     344        remove_filter( 'render_block_data', 'test_render_block_data' );
    312345        unregister_block_type( 'test/custom-directive-block' );
    313         $directive_processors->setValue( null, $old_directive_processors );
     346        $this->assertEquals( 'test', $processor->get_attribute( 'value' ) );
    314347    }
    315348
Note: See TracChangeset for help on using the changeset viewer.