• Resolved lexhair

    (@lexhair)


    Andrew…I wrote my own little plugin to tweet a post with the YOURLS shortlink. My plugin fires on the “draft”to”publish” action hook in wp_transition_post_status().

    I was digging through your code to determine when it creates a shortlink on a post going from Draft to Publish status because my tweets did not have the YOURLS shortlink included.

    Correct me if I’m wrong but it seems like for posts not going from future to publish, your plugin creates the YOURLS shortlink for draft posts going to published posts on the “save_post” hook. As I understand how WordPress posts, the “save_post” hook is fired after the “transition_post_status” hook. Since my plugin hooks into “draft_to_publish” hook, (which seemed logical to me), the YOURLS shortlink isn’t ready yet.

    My workaround was to change my plugin to the “wp_insert_post” hook which fires after “save_post”. However, when I do this and to prevent firing tweets when I update my post, I eliminated the ability for the function to fire when future posts transition to publish. So I added another hook for another function to fire on the “future_to_publish” hook which modifies the arguments I send to the original function. Your plugin uses the transition_post_status hook which fires before “future_to_publish” so the YOURLS shortlink should be ready when my function fires.

    My workaround is fine but required quite a bit of research looking at thee core’s sequence of firing do_action() events. If you would include a do_action() hook after your plugin creates a new shortlink and pass the $post object, I could have hooked into your plugin and not worried about the core works to that level of detail.

    Thanks for a great plugin.
    John
    NYC USA

    https://www.ads-software.com/plugins/yourls-link-creator/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Andrew Norcross

    (@norcross)

    the reason it uses the save_post hook is because other plugins can modify the URL structure / post slug / etc, which would then make the URL being used earlier incorrect.

    would adding a hook to fire after the save routine is done solve your issue?

    Thread Starter lexhair

    (@lexhair)

    I’m sure there was a good reason ??

    If “after the save routine” means after you’ve updated the post metadata with the YOURLS link, then yes it would solve the issue as long as you pass the $post object as an argument in the hook.

    Plugin Author Andrew Norcross

    (@norcross)

    I can do that.

    Thread Starter lexhair

    (@lexhair)

    Much obliged.

    Plugin Author Andrew Norcross

    (@norcross)

    gonna push this out this afternoon. one thing: the save_post action doesn’t have the entire $post object, rather, just the $post_id. so I’m going to pass that along with the generated short URL, which should give you whatever you need.

    Plugin Author Andrew Norcross

    (@norcross)

    just pushed to the repo. let me know if this handles the issue for you.

    Thread Starter lexhair

    (@lexhair)

    I’m not seeing it at wp.org yet but thanks for passing the entire object. Saves a query.

    Plugin Author Andrew Norcross

    (@norcross)

    my mistake. I forgot to change the version number on the file. just fixed.

    as for the update, remember I am not passing the entire $post object, rather, the $post_id (and the short URL generated), since the $post_id is what is made available in the save_post function.

    Thread Starter lexhair

    (@lexhair)

    I’ll give it a test this week but it should do the trick. Thanks!

    Thread Starter lexhair

    (@lexhair)

    Works as advertised!! Thanks again.

    Plugin Author Andrew Norcross

    (@norcross)

    fantastic! glad it’s working out for you.

    Thread Starter lexhair

    (@lexhair)

    Would you confirm if your new hook fires when a future post is published either manually or automatically?

    Plugin Author Andrew Norcross

    (@norcross)

    No, it doesn’t. Well, it didn’t, until now. I just pushed v 2.1.0 to the repo which adds the same hook (with the same parameters) to the post transition as well.

    Thread Starter lexhair

    (@lexhair)

    Didn’t think so but couldn’t be sure because I rarely use the ‘save_post’ hook’ so I had to look that one up..

    Not to be a twister but I believe the ‘save_post’ hook does pass the $post object as well as the post ID.

    Plugin Author Andrew Norcross

    (@norcross)

    it can, but but the object isn’t up to date with whatever changes have been made (it’s the object at the time of saving, not after) so I’m not going to add that full object.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘YOURLS hooks’ is closed to new replies.