-
Notifications
You must be signed in to change notification settings - Fork 447
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
Set post status for Post Object Create mutations late, to allow for side-effects before final status is set #395
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonbahl a few things
'edit_date' => ! empty( $post_args['post_date'] ) ? $post_args['post_date'] : false, | ||
]; | ||
|
||
$update_args = array_merge( $update_args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are missing the second array you are trying to merge in here, eh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, I did have a merge, but changed it.
]; | ||
|
||
$update_args = array_merge( $update_args ); | ||
wp_update_post( $update_args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this get moved out of this if statement so it fires even if the filter is set to false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The intent is that a plugin, like DFM GraphQL Extensions, that needs to process sideloaded images, can filter this to false, meaning the created post will remain a draft. Then the process that sideloads the images can come back and set the post as Publish
or whatever the intended status was.
Otherwise, if the status was set to publish and the deferred (cron / queued tasks, etc) side effects were not complete, then you'd have a published post with incomplete data.
- Fixes some code review feedback, and provides additional context to some filters and actions to make it easier for plugins to handle mutation side effects.
@CodeProKid pushed an update, cleaning up the unused |
- Fixes some code review feedback, and provides additional context to some filters and actions to make it easier for plugins to handle mutation side effects.
@CodeProKid updated to fix the broken tests too. |
What does this implement/fix? Explain your changes.
During PostObjectMutations, any post_status input will be cached, and the post will be created with the default status (draft, but filterable to accompany plugins like Edit Flow, etc).
Then the side-effects will be triggered via
PostObjectMutation::update_additional_post_object_data()
.Then, if
$should_set_intended_status
is true (filterable), the post_status that was input with the mutation (if different than the default) will be set as the status of the post.This allows for side effects that may take a long time (sideloading images, etc) to happen in a deferred process (like a WPCron or a WP Queue Task - https://github.com/dfmedia/wp-queue-tasks) and those side effects can come back later and set the status when they complete.
Does this close any currently open issues?
closes #394
closes #393
Where has this been tested?
Operating System:
Mac OSX 10.12.6
WordPress Version:
4.9.4