Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

API push should be called on action hook 'publish_post', not 'save_post' #13

Open
eobanb opened this issue Jun 12, 2015 · 0 comments
Open

Comments

@eobanb
Copy link

eobanb commented Jun 12, 2015

Issue: post data can be incorrect in certain circumstances
Cause: save_post action is used for npr_push()
Suggested fix: use publish_post instead

In debugging a problem with audio not being attached to our pushed posts, we discovered an incompatibility between WP-DS-NPR-API and a Wordpress Mu plugin we use, Sitewide Tags. The $post object used in post_to_nprml_story() corresponded to a copy of the original post created by the Sitewide Tags plugin.

This led me to notice that the add_action() function in the plugin file push_story.php that calls npr_push() is attached to Wordpress action hook save_post. This caused a problem, because under some conditions it's possible for save_post to return post data from an unintended post, such as a post revision (or, in this case, the reference copy of the post made by Sitewide Tags).

While save_post does usually work, the better action to use in this case is publish_post, which is a very similar—but not identical—action; publish_post always returns the actual post's data, and only when its transition status goes to 'publish'.

(side note: the decision to use save_post when this plugin was written likely arose because publish_post was previously mistakenly marked as deprecated in the Wordpress API reference)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant