Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#64518 new defect (bug)

Interactivity API: `data-wp-bind` stops processing valid directives when encountering an invalid one

Reported by: luisherranz's profile luisherranz Owned by:
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Interactivity API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

When the Interactivity API is processing the data-wp-bind directive on the server using the data_wp_bind_processor method, a `return` statement inside a `foreach` loop causes the function to exit entirely when encountering a data-wp-bind directive with an empty suffix or a unique ID. This prevents any subsequent valid bind directives on the same element from being processed.

Steps to Reproduce:

  1. Create an element with both an invalid data-wp-bind directive (no suffix) and a valid one:
<div
  data-wp-interactive="myPlugin"
  data-wp-context='{"id":"some-id"}'
  data-wp-bind="context.id"
  data-wp-bind--id="context.id"
>
  Text
</div>
  1. Process the directives using wp_interactivity_process_directives().

Expected Behavior:

The invalid data-wp-bind (no suffix) should be skipped, and the valid data-wp-bind--id should be processed, resulting in:

<div
  data-wp-interactive="myPlugin"
  data-wp-context='{"id":"some-id"}'
  data-wp-bind="context.id"
  data-wp-bind--id="context.id"
  id="some-id"
>
  Text
</div>

Actual Behavior:

The return statement exits the function when it encounters the invalid directive, so the valid data-wp-bind--id is never processed. The id attribute is not added.

Change History (1)

This ticket was mentioned in PR #10746 on WordPress/wordpress-develop by @luisherranz.


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

## What

This PR fixes a bug in the data_wp_bind_processor method where a return statement inside a foreach loop was causing the function to exit entirely when encountering a bind directive with an empty suffix or a unique ID.

## Why

When an element has multiple data-wp-bind directives, such as:

<div data-wp-bind="myPlugin::state.id" data-wp-bind--id="myPlugin::state.id">Text</div>

The first directive (data-wp-bind with no suffix) is invalid and should be skipped. However, the return statement was causing the entire function to exit, preventing the valid data-wp-bind--id directive from being processed.

## How

Changed return to continue so that invalid entries are skipped while valid entries continue to be processed.

---

Trac ticket: https://core.trac.wordpress.org/ticket/64518

Note: See TracTickets for help on using tickets.