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

Already published post gets counted as data-point #1

Open
nahakiole opened this issue Sep 17, 2015 · 3 comments
Open

Already published post gets counted as data-point #1

nahakiole opened this issue Sep 17, 2015 · 3 comments

Comments

@nahakiole
Copy link

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

@MatthewEppelsheimer
Copy link

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.

@MatthewEppelsheimer
Copy link

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.

@MatthewEppelsheimer
Copy link

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…

  1. 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.

  2. 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:

  • When a post's post-status changes from anything other than 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.
  • That will enable us to stop checking _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.)

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

2 participants