Skip to content

Stored ID handling - Phase 2#1309

Merged
dkotter merged 37 commits into
developfrom
enhancement/stored-id-handling-phase-2
Aug 5, 2025
Merged

Stored ID handling - Phase 2#1309
dkotter merged 37 commits into
developfrom
enhancement/stored-id-handling-phase-2

Conversation

@iamdharmesh

@iamdharmesh iamdharmesh commented Mar 28, 2025

Copy link
Copy Markdown
Member

Description of the Change

This PR is the Phase 2 of the "Stored ID handling" work we began in #1302.

It introduces a new type key in the $args parameter of distributor_register_data. This allows users to utilize the default pre/post callback functions we've implemented for common entities like posts, terms, and media. For these types of entities, users no longer need to write custom pre/post callbacks, they can simply provide the data type, location, and attribute, and the default callback functions will handle the rest.

Example:
An image ID stored in post meta under the key example_image_id would be handled like this:

distributor_register_data( 'example_post_meta_data', array(
	'location'   => 'post_meta',
	'attributes' => array(
		'meta_key' => 'example_image_id',
	),
	'type'       => 'media'
) );

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. Register a stored ID reference for post, media and term type.
  4. Distribute the post and verify that the references update correctly on the target site.
  5. Test with different scenarios, and ensure everything works as expected.

Changelog Entry

Added - New type parameter in distributor_register_data to enable utilization of the default pre/post callbacks for posts, terms, and media.

Credits

Props @dkotter @iamdharmesh

Checklist:

@iamdharmesh iamdharmesh self-assigned this Mar 28, 2025
Base automatically changed from enhancement/stored-id-handling to develop April 14, 2025 08:47
@github-actions github-actions Bot added this to the 2.2.0 milestone Apr 14, 2025
@iamdharmesh iamdharmesh changed the title [WIP] Stored ID handling - Phase 2 Stored ID handling - Phase 2 May 8, 2025
Comment thread docs/stored-id-handling.md Outdated
Comment thread docs/stored-id-handling.md Outdated
Comment thread includes/global-functions.php
Comment thread includes/global-functions.php Outdated
Comment thread includes/global-functions.php Outdated
Comment thread includes/global-functions.php Outdated
Comment thread includes/classes/RegisteredDataHandler.php

@dkotter dkotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Haven't had time to actually test this but from a code perspective, this looks really good to me. Left a handful of minor comments

@dkotter dkotter requested a review from peterwilsoncc May 20, 2025 13:35
@iamdharmesh iamdharmesh marked this pull request as ready for review June 17, 2025 12:45
@iamdharmesh iamdharmesh requested a review from a team as a code owner June 17, 2025 12:45
@iamdharmesh iamdharmesh requested review from peterwilsoncc and removed request for a team June 17, 2025 12:45
@github-actions github-actions Bot added the needs:code-review This requires code review. label Jun 17, 2025
@iamdharmesh

Copy link
Copy Markdown
Member Author

Finally, E2E tests are now passing in all env and we are ready to go with this.

Comment thread includes/global-functions.php Outdated
Comment thread tests/cypress/e2e/stored-id-handling-classic-editor.test.js Outdated
Comment thread tests/cypress/e2e/stored-id-handling.test.js
dkotter
dkotter previously approved these changes Jun 27, 2025
@github-project-automation github-project-automation Bot moved this from Code Review to QA Testing in Open Source Practice Jun 27, 2025
@jeffpaul

jeffpaul commented Jul 7, 2025

Copy link
Copy Markdown
Member

@iamdharmesh @peterwilsoncc would be great to sort out any updates needed from Peter's latest review so we can get this merged and ready for a v2.2 release

peterwilsoncc
peterwilsoncc previously approved these changes Jul 9, 2025

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks great, thank you.

My one thought is to make sure the post and term IDs differ between the two sites by adding the following to the end of initialize.sh

# Create some posts to bump the post IDs so they differ between the two sites.
wp-env run tests-cli wp post generate --count=10 --post_type=post --post_author=1
wp-env run tests-cli wp post generate --count=20 --post_type=post --post_author=1 --url=localhost/second

# Now delete the posts created by the test suite
wp-env run tests-cli wp post delete $(wp-env run tests-cli wp post list --post_type=post --format=ids) --force
wp-env run tests-cli wp post delete $(wp-env run tests-cli wp post list --post_type=post --format=ids --url=localhost/second) --url=localhost/second --force

# Create some terms to bump the term IDs so they differ between the two sites.
wp-env run tests-cli wp term generate category --count=10
wp-env run tests-cli wp term generate category --count=20 --url=localhost/second

# Now delete the terms created by the test suite
wp-env run tests-cli wp term delete category $(wp-env run tests-cli wp term list category --format=ids)
wp-env run tests-cli wp term delete category $(wp-env run tests-cli wp term list category --format=ids --url=localhost/second) --url=localhost/second

It's not a blocker so I'll approve now and you can decide.

@iamdharmesh

Copy link
Copy Markdown
Member Author

My one thought is to make sure the post and term IDs differ between the two sites by adding the following to the end of initialize.sh

Thanks for suggestion @peterwilsoncc. This is added and PR is ready for merge.

@dkotter dkotter merged commit b998756 into develop Aug 5, 2025
18 checks passed
@dkotter dkotter deleted the enhancement/stored-id-handling-phase-2 branch August 5, 2025 19:43
@github-project-automation github-project-automation Bot moved this from QA Testing to Done in Open Source Practice Aug 5, 2025
@dkotter dkotter mentioned this pull request Aug 26, 2025
8 tasks
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.

4 participants