Make WordPress Core

Changeset 62070


Ignore:
Timestamp:
03/19/2026 09:16:06 PM (2 months ago)
Author:
luisherranz
Message:

Interactivity API: fix data-wp-bind skipping valid directives after encountering an invalid one

Change return to continue in data_wp_bind_processor so that when an element has multiple data-wp-bind directives and one is invalid (empty suffix or unique ID), the invalid entry is skipped instead of causing the entire function to exit, allowing valid directives on the same element to still be processed.

Props DAreRodz, ozgursar, alexodiy.
Fixes #64518.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php

    r61885 r62070  
    10271027            foreach ( $entries as $entry ) {
    10281028                if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) {
    1029                         return;
     1029                        continue;
    10301030                }
    10311031
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php

    r61020 r62070  
    136136
    137137    /**
     138     * Tests that `data-wp-bind` ignores directives with no suffix but still
     139     * processes valid bind directives on the same element.
     140     *
     141     * @ticket 64518
     142     *
     143     * @covers ::process_directives
     144     */
     145    public function test_wp_bind_ignores_empty_suffix_but_processes_valid_binds() {
     146        $html    = '<div data-wp-bind="myPlugin::state.id" data-wp-bind--id="myPlugin::state.id">Text</div>';
     147        list($p) = $this->process_directives( $html );
     148        $this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
     149    }
     150
     151    /**
    138152     * Tests that `data-wp-bind` does nothing when referencing non-existent
    139153     * references.
     
    417431        $this->assertNull( $p->get_attribute( 'id---unique-id' ) );
    418432    }
     433
     434    /**
     435     * Tests that `data-wp-bind` ignores directives with unique IDs but still
     436     * processes valid bind directives on the same element.
     437     *
     438     * @ticket 64518
     439     *
     440     * @covers ::process_directives
     441     */
     442    public function test_wp_bind_ignores_unique_id_but_processes_valid_binds() {
     443        $html    = '<div data-wp-bind--id---unique-id="myPlugin::state.id" data-wp-bind--id="myPlugin::state.id">Text</div>';
     444        list($p) = $this->process_directives( $html );
     445        $this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
     446    }
    419447}
Note: See TracChangeset for help on using the changeset viewer.