Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment to connect HTML attributes with custom fields #53514

Closed

Conversation

SantosGuillamot
Copy link
Contributor

@SantosGuillamot SantosGuillamot commented Aug 10, 2023

What?

This is an experiment to explore the possibility of connecting HTML attributes with any source like meta/custom fields.

I made a video explaining it a bit deeper:

https://www.loom.com/share/ce428827a81248a297a1b9fa0b091dbc?sid=f9665430-b6c3-41f7-b873-9f852d1e619d

How?

To make it work, I incorporated the changes from this pull request in wordpress/develop because I wanted to use the set_inner_markup function. This will eventually be included in core so it is not relevant for this pull request.

The important part is the logic included in the blocks.php, that is reusing the code that connects block attributes and custom fields.

Testing Instructions

  1. Add a data-wp-dynamic-content attribute to any HTML tag with an object similar to:
{
  "html_attributes": {
    "inner_content": {
      "source": "meta_fields",
      "key": "custom_text"
    },
    "href": {
      "source": "meta_fields",
      "key": "custom_link"
    }
  }
}
  1. Register the custom_text and custom_link custom fields using register_post_meta for example.
  2. Check that the HTML attributes or inner content is replaced in the frontend by the value of the custom fields.

@SantosGuillamot SantosGuillamot added [Feature] Block API API that allows to express the block paradigm. [Type] Experimental Experimental feature or API. [Feature] Custom Fields Anything related to the custom fields project - connecting block attributes and dynamic values labels Aug 10, 2023
@github-actions
Copy link

github-actions bot commented Aug 10, 2023

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/compat/wordpress-6.4/html-api/class-wp-html-tag-processor.php
❔ lib/compat/wordpress-6.4/html-api/class-wp-html-open-elements.php
❔ lib/compat/wordpress-6.4/html-api/class-wp-html-processor-state.php
❔ lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php
❔ lib/experimental/blocks.php
❔ lib/experimental/connection-sources/index.php
❔ lib/load.php

@SantosGuillamot
Copy link
Contributor Author

Closing this PR as it was just meant to be an experiment. It can always be reopened/reused in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Custom Fields Anything related to the custom fields project - connecting block attributes and dynamic values [Type] Experimental Experimental feature or API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant