Make WordPress Core


Ignore:
Timestamp:
05/29/2024 11:55:27 AM (4 months ago)
Author:
gziolo
Message:

Interactivity API: Move directive processing to WP_Block class

Integrates the directives processing into the WP_Block class. It removes the overhead of running additional hooks when rendering blocks and simplifies the way we detect whether the directive processing should run on an interactive region of the produced final HTML for the blocks.

Introduces interactivity_process_directives filter to offer a way to opt out from directives processing. It's needed in Gutenberg: https://github.com/WordPress/gutenberg/pull/62095.

Props gziolo, cbravobernal.
Fixes #61185.

File:
1 edited

Legend:

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

    r57987 r58234  
    526526        $this->assertNull( $input_value );
    527527    }
     528
     529    /**
     530     * Tests interactivity_process_directives filter.
     531     *
     532     * @ticket 61185
     533     *
     534     * @covers wp_interactivity_process_directives
     535     */
     536    public function test_not_processing_directives_filter() {
     537        wp_interactivity_state(
     538            'dont-process',
     539            array(
     540                'text' => 'text',
     541            )
     542        );
     543        register_block_type(
     544            'test/custom-directive-block',
     545            array(
     546                'render_callback' => function () {
     547                    return '<div data-wp-interactive="dont-process"><input data-wp-bind--value="state.text" /></div>';
     548                },
     549                'supports'        => array(
     550                    'interactivity' => true,
     551                ),
     552            )
     553        );
     554        $post_content = '<!-- wp:test/custom-directive-block /-->';
     555        add_filter( 'interactivity_process_directives', '__return_false' );
     556        $processed_content = do_blocks( $post_content );
     557        $processor         = new WP_HTML_Tag_Processor( $processed_content );
     558        $processor->next_tag( array( 'tag_name' => 'input' ) );
     559        $input_value = $processor->get_attribute( 'value' );
     560        remove_filter( 'interactivity_process_directives', '__return_false' );
     561        unregister_block_type( 'test/custom-directive-block' );
     562        $this->assertNull( $input_value );
     563    }
    528564}
Note: See TracChangeset for help on using the changeset viewer.