Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Prevents a large number of cron jobs from being registered, unless they are truly needed.
This PR includes 3 steps:
Some Considerations
For 2, by removing the two default offloads - the track_publish_post() and _publish_post_hook() logic will now happen synchronously when a post is published, the effects of which quite minimal here. One additional note is that
track_publish_post()
would have technically only have been run when the async cron job was truly added based on theshould_offload()
default logic, meaning it was also excluded from being run on new posts created during cron, cli, and xmlrpc. This could be replicated if desired by checking for more than justWP_IMPORTING
in this function.For 3, if one of these hooks was for some reason only conditionally registered underneath cli/cron checks specifically - then we'd possibly be missing out that the cron needed to be registered. This is quite unlikely though, and I have searched for all use cases I can find and the few out there do not fall into this trap. But if desired, we could move step 3 into a future PR for after we have more usage information.
Changelog Description
Plugin Updated: Async Publish Actions
This change removes the creation of async post publish cron jobs if they are not being utilized. If the relevant hooks are in use, the cron jobs will continue to be created normally.
Checklist
Please make sure the items below have been covered before requesting a review:
Documentation: https://docs.wpvip.com/how-tos/code-quality-and-best-practices/write-asynchronous-publishing-actions/. Will be updated when applicable.
Steps to Test
wp cron-control events list
and notice how nowpcom_vip_async_transition_post_status
job was added.For phpunit,
phpunit --group async-publish-actions
to skip to the relevant parts.