npr / nprapi-wordpress

Access the NPR API from within WordPress. This repository is no longer being maintained. See the README for more information.
GNU General Public License v2.0
13 stars 30 forks source link

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

Open eobanb opened 9 years ago

eobanb commented 9 years ago

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)