Open nahakiole opened 9 years ago
Validation of this issue from @dreeves in the Beeminder forum:
editing an existing blog post would send a +1 to Beeminder if that blog post wasn’t already counted. Which is not typically what you want if you want to beemind your blog starting now. Our workaround was to just delete the extra datapoints. And future edits, if I’m remembering this right, didn’t send a new +1 so all was good after we’d hit the point of having edited all past blog posts at least once.
This can be easily addressed with a more selective choice of WP action hooks when updating posts.
The issue is our use of the publish_post
hook. This hook is constructed dynamically within wp_transition_post_status()
whenever a post is saved, by combining the post-status and post-type through string interpolation whenever a post is updated: do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
(From the function's documentation: "When a post is saved, the post status is "transitioned" from one status to another, though this does not always mean the status has actually changed before and after the save". Misleading language. The transition_post_status
hook is the better way to go here.)
Thus, code hooked to publish_post
runs whenever a post is published for the first time, or a post's status is publish
after it has been updated. We then rely on Beeminder-specific option data to determine whether or not we've already reported this post to Beeminder. That data is unreliable for posts published prior to the installation of beeminder-ping
.
To inform a better choice of hooks to act on, I've drafted the user stories below to document expected behavior. Even though this is dirt simple, I'd appreciate a sanity check before moving forward with the fix. (ATTN @dreeves, @Sodaware)
Bloggerbee user definition: Someone with beeminder-ping
installed who edits and publishes blog posts.
Stories:
As a Bloggerbee…
When I publish a post for the first time, I want to add a +1 Beeminder data point, to have my new post count towards my posts-published goal.
When I edit a previously-published post (whether or not it has been previously logged to Beeminder), I do not want to add or update any Beeminder data, so that my posts-published goal data remains valid.
Translation to technical requirements/rules:
publish
to publish
, then and only then add a data point to Beeminder. Do this by hooking into the transition_post_status
hook, instead of the publish_post
hook._beeminder_ping_sent
post meta data in the Handle_onPublishPost
method. (We'll continue to set that post meta data; it may still be useful in the future.)
If you edit posts which have been published before installing the plugin another data-point will be pushed to the beeminder goal.
I think the problem lies here: https://github.com/beeminder/beeminder-ping/blob/master/beeminder-ping.php#L107