Skip to content

Docs: Fix incorrect echo of wp_interactivity_state() in getServerState() example#75857

Merged
luisherranz merged 1 commit intoWordPress:trunkfrom
Mustafabharmal:fix/docs-wp-interactivity-state-example
Feb 24, 2026
Merged

Docs: Fix incorrect echo of wp_interactivity_state() in getServerState() example#75857
luisherranz merged 1 commit intoWordPress:trunkfrom
Mustafabharmal:fix/docs-wp-interactivity-state-example

Conversation

@Mustafabharmal
Copy link
Contributor

What?

Closes #75827
Fixes incorrect PHP code example in the getServerState() section of the "Understanding global state, local context and derived state" documentation.

Why?

wp_interactivity_state() sets global state server-side (serialized as a <script> tag) and does not return HTML attributes. The example was incorrectly calling echo wp_interactivity_state() inside an HTML tag's attribute position — mimicking wp_interactivity_data_wp_context(), which does output HTML attributes.

How?

  • Call wp_interactivity_state() without echo, outside the <div> tag
  • Add data-wp-interactive="myPlugin" to the <div> element

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: eatse21 <eatse@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @Mustafabharmal!

@luisherranz luisherranz added the [Type] Developer Documentation Documentation for developers label Feb 24, 2026
@luisherranz luisherranz enabled auto-merge (squash) February 24, 2026 10:14
@luisherranz luisherranz merged commit 6c26975 into WordPress:trunk Feb 24, 2026
43 of 46 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.7 milestone Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: wrong use of wp_interactivity_state?

2 participants