Skip to content

Conversation

@iamdharmesh
Copy link
Member

@iamdharmesh iamdharmesh commented Mar 3, 2025

Description of the Change

This PR introduces a new helper function, distributor_register_data, which enables developers to register stored data references, such as IDs stored in post meta, shortcodes, or block attributes and define custom pre-distribution and post-distribution callbacks to process these references.

Function Definition

distributor_register_data
This function registers a piece of data by providing details about its location and the callbacks needed to process it during distribution.

Parameters

  • $data_name (string): The unique identifier for the data.
  • $args (array): An array of parameters that describe:
    • location (string): Where the data is stored. Accepted values are 'post_meta' or 'post_content'.
    • attributes (array): Additional details depending on the location:
      • For post meta:
        • meta_key (string): The post meta key. (Required)
      • For shortcodes:
        • shortcode (string): The shortcode tag. (Required)
        • shortcode_attribute (string|array): The attribute(s) containing the data. (Required)
      • For blocks:
        • block_name (string): The block name. (Required)
        • block_attribute (string|array): The attribute(s) containing the data. (Required)
    • pre_distribute_cb (callable): A callback function that prepares the data on the source site before distribution. It should return extra data required for processing on the target site.
    • post_distribute_cb (callable): A callback function that processes the extra data on the target site and returns the updated ID to replace the source reference.

I have added detailed information on how this function works along with examples. You can view them here.

Note

  • For the Classic editor, the post content is distributed in its rendered form. Therefore, shortcode data does not work as expected because the output of the shortcode is distributed instead of the shortcode tag. Let's discuss how we can handle this. I need feedback on this from someone who has a better understanding of this.
  • This PR is Phase 1 of stored ID handling, which aims to add support for popular plugins like ACF and Gravity Forms in upcoming phases. However, to fully support these plugins, additional implementation will be required beyond this newly added helper function.

How to test the Change

You can find examples of data registration using the distributor_register_data function in the documentation and the e2e-test-plugin file. But please feel free to experiment on your own for something different.

  1. Check out this PR branch on both the source and target WordPress sites.
  2. Register data using distributor_register_data for specific stored IDs in functions.php or in a custom plugin.
  3. Test with Post Meta:
    • Register a stored ID reference for post meta using distributor_register_data.
    • Distribute the post and verify that the references update correctly on the target site.
    • Test with different scenarios, such as multiple metadata entries under the same meta key.
  4. Test with Shortcodes:
    • Register a stored ID reference for a shortcode using distributor_register_data.
    • Distribute the post and verify that the ID is replaced with the correct target site equivalent.
    • Test with different scenarios, such as passing multiple attributes under shortcode_attribute, to ensure everything works as expected.
  5. Test with Block Attributes:
    • Register a stored ID reference for a block using distributor_register_data.
    • Distribute the post and verify that the correct ID is assigned on the target site.
    • Test with different scenarios, such as passing multiple attributes under block_attribute, to ensure everything works as expected.

Changelog Entry

Added - The distributor_register_data function to handle stored ID references in post meta, shortcodes, and block attributes during distribution.

Credits

Props @dkotter, @iamdharmesh

Checklist:

@iamdharmesh iamdharmesh self-assigned this Mar 3, 2025
@github-actions github-actions bot added this to the 2.2.0 milestone Mar 3, 2025
@iamdharmesh iamdharmesh changed the title [WIP] Stored ID handling [WIP] Stored ID handling - Phase 1 Mar 7, 2025
@iamdharmesh
Copy link
Member Author

E2E tests with WP trunk are failing due to an issue in insertBlock command with WP 6.8. It will be resolved with this PR

@iamdharmesh iamdharmesh changed the title [WIP] Stored ID handling - Phase 1 Stored ID handling - Phase 1 Mar 10, 2025
@iamdharmesh iamdharmesh marked this pull request as ready for review March 10, 2025 06:36
@iamdharmesh iamdharmesh requested review from a team and jeffpaul as code owners March 10, 2025 06:36
@jeffpaul jeffpaul mentioned this pull request Mar 11, 2025
10 tasks
dkotter
dkotter previously approved these changes Mar 17, 2025
Copy link
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

I didn't do a super thorough test of everything here but overall code looks good to me and the tests I have done also look good. Since this is just phase 1 of a larger effort, I'd love to see this get merged in so we can work on the next piece

@github-project-automation github-project-automation bot moved this from Code Review to QA Testing in Open Source Practice Mar 17, 2025
dkotter
dkotter previously approved these changes Mar 18, 2025
@dkotter
Copy link
Collaborator

dkotter commented Mar 20, 2025

@peterwilsoncc Dharmesh mentioned you may want to review / have already reviewed this PR and may have some feedback to provide. If you get a chance to add that feedback, that would be great so we can get this merged and start progress on phase 2 of this feature

Copy link
Collaborator

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

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

Added a few notes, as discussed they're mainly nitpicks.

peterwilsoncc
peterwilsoncc previously approved these changes Mar 26, 2025
Copy link
Collaborator

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

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

Thanks for the follow up, this looks good for merge.

@github-actions github-actions bot added the needs:refresh This requires a refreshed PR to resolve. label Apr 4, 2025
@github-actions github-actions bot removed the needs:refresh This requires a refreshed PR to resolve. label Apr 14, 2025
Copy link
Contributor

@Sidsector9 Sidsector9 left a comment

Choose a reason for hiding this comment

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

Re-approving only to enable merging.

@iamdharmesh iamdharmesh merged commit 25f6bb3 into develop Apr 14, 2025
18 checks passed
@iamdharmesh iamdharmesh deleted the enhancement/stored-id-handling branch April 14, 2025 08:47
@github-project-automation github-project-automation bot moved this from QA Testing to Done in Open Source Practice Apr 14, 2025
@iamdharmesh iamdharmesh mentioned this pull request May 8, 2025
4 tasks
@dkotter dkotter mentioned this pull request May 16, 2025
1 task
@dkotter dkotter mentioned this pull request Aug 26, 2025
8 tasks
@jeffpaul jeffpaul linked an issue Aug 29, 2025 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

E2E Tests: migrate TestLodge tests to Cypress

5 participants