#62136 closed feature request (fixed)
Interactivity API: Allow reading element attributes inside derived state props
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 6.7 |
Component: | Interactivity API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Developers can define derived state props with wp_interactivity_state
since WordPress 6.6 (see Updates to the Interactivity API in 6.6). However, they lack a function to obtain the current element's attributes, which is possible in JavaScript with the getElement()
function exposed from @wordpress/interactivity
.
A PHP function equivalent to getElement()
should be implemented to allow developers to write derived state props that depend on element attributes.
Change History (4)
This ticket was mentioned in PR #7460 on WordPress/wordpress-develop by @darerodz.
8 months ago
#1
- Keywords has-patch has-unit-tests added
#2
@
8 months ago
- Owner set to czapla
- Resolution set to fixed
- Status changed from new to closed
In 59131:
8 months ago
#3
Committed with https://core.trac.wordpress.org/changeset/59131
Note: See
TracTickets for help on using
tickets.
This PR adds a PHP function named
wp_interactivity_get_element
, analogous to thegetElement()
function exposed in the@wordpress/interactivity
JavaScript module (see docs).The function is intended to be used in derived state props inside
wp_interactivity_state
, same aswp_interactivity_get_context
.For now, the returned value is an array that contains only the
attributes
property, which lists the originally defined attributes present in the element. That means attributes added or modified by directive processing don't appear.Trac ticket: https://core.trac.wordpress.org/ticket/62136