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

Editing ACF fields then Publish ignores changes #1

Closed
jamiechong opened this issue Oct 26, 2016 · 6 comments
Closed

Editing ACF fields then Publish ignores changes #1

jamiechong opened this issue Oct 26, 2016 · 6 comments
Assignees

Comments

@jamiechong
Copy link
Owner

  1. Revisionize
  2. Edit ACF Fields
  3. Click Publish

Result: The revision is published, but the ACF fields aren't.
Reason: transition_post_status hook fires too early. The revision $post content has been saved, but its meta fields have not (they're saved shortly after). So the meta fields of the revision aren't updated when we copy_post over top of the original.
Fix: Need to hook into an action later on. Possibly publish_post.

Work Around

  1. Revisionize
  2. Edit ACF Fields
  3. Click Save Draft
  4. Click Publish
@jamiechong jamiechong self-assigned this Oct 26, 2016
@brucesdad13
Copy link

Excellent!

@thegaffney
Copy link
Contributor

thegaffney commented May 23, 2017

I fixed this (if you have ACF) by changing the hook to acf/save_post and I had to change the on_publish_post function to
function on_publish_post($post_id) { $post = get_post($post_id); $new_status = get_post_status($post_id); if($post && $new_status == 'publish') { $id = get_revision_of($post); if ($id) { $original = get_post($id); if ($original) { publish($post, $original); } } } }

@jamiechong
Copy link
Owner Author

@thegaffney Will this change continue to work without ACF? If so, care to create a PR? Thanks for looking into a workable solution!

@thegaffney
Copy link
Contributor

thegaffney commented May 23, 2017

I'd imagine no, but I think you could just do a simple check like this to see if ACF is installed

if (has_action( 'acf/save_post' ) ) {
     add_action('acf/save_post', __NAMESPACE__.'\\ACF_on_publish_post', 130, 1);
} else {
     add_action('transition_post_status', __NAMESPACE__.'\\on_publish_post', 10, 3);
}

That change still works with ACF, but I won't be able to test it on a site without it, but it seems like it would be the correct way to do it.

Then of course have two on_publish_post functions, one for ACF users

@jamiechong
Copy link
Owner Author

Thanks for the help @thegaffney. I had to modify your changes a bit to make it work with scheduled posts. Will get this up onto WP.org.

@thegaffney
Copy link
Contributor

thegaffney commented May 31, 2017 via email

jamiechong pushed a commit that referenced this issue Mar 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants