Title: YOURLS hooks
Last modified: August 30, 2016

---

# YOURLS hooks

 *  Resolved [lexhair](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/)
 * 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://wordpress.org/plugins/yourls-link-creator/](https://wordpress.org/plugins/yourls-link-creator/)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/yourls-hooks/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/yourls-hooks/page/2/?output_format=md)

 *  Plugin Author [Andrew Norcross](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393750)
 * 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](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393758)
 * 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](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393763)
 * I can do that.
 *  Thread Starter [lexhair](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393781)
 * Much obliged.
 *  Plugin Author [Andrew Norcross](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393823)
 * 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](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393828)
 * just pushed to the repo. let me know if this handles the issue for you.
 *  Thread Starter [lexhair](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393949)
 * I’m not seeing it at wp.org yet but thanks for passing the entire object. Saves
   a query.
 *  Plugin Author [Andrew Norcross](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393951)
 * 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](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393987)
 * I’ll give it a test this week but it should do the trick. Thanks!
 *  Thread Starter [lexhair](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393991)
 * Works as advertised!! Thanks again.
 *  Plugin Author [Andrew Norcross](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6393992)
 * fantastic! glad it’s working out for you.
 *  Thread Starter [lexhair](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6394014)
 * Would you confirm if your new hook fires when a future post is published either
   manually or automatically?
 *  Plugin Author [Andrew Norcross](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6394015)
 * 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](https://wordpress.org/support/users/lexhair/)
 * (@lexhair)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6394017)
 * 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](https://wordpress.org/support/users/norcross/)
 * (@norcross)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/#post-6394018)
 * 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)

1 [2](https://wordpress.org/support/topic/yourls-hooks/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/yourls-hooks/page/2/?output_format=md)

The topic ‘YOURLS hooks’ is closed to new replies.

 * ![](https://ps.w.org/yourls-link-creator/assets/icon-256x256.png?rev=1081567)
 * [YOURLS Link Creator](https://wordpress.org/plugins/yourls-link-creator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yourls-link-creator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yourls-link-creator/)
 * [Active Topics](https://wordpress.org/support/plugin/yourls-link-creator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yourls-link-creator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yourls-link-creator/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [lexhair](https://wordpress.org/support/users/lexhair/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/yourls-hooks/page/2/#post-6394020)
 * Status: resolved