• I’m trying to perform an action on future_to_publish. The code works fine on publish_post action. I’m using a class and the add_action is in the constructor.

    add_action( 'future_to_publish', array( $this, 'doit' ) );
    
    function doit( $post ) {
      // $post_id = $post->ID;
      // do stuff here
    }

    do the post status transitions pass a post object or a post id? is $post above the object or is it the post id? I’ve scheduled a post that I had previously published for a future date, say 5 minutes ahead. When it publishes, it doesn’t seem as if the doit() method is triggered.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Beer

    (@beer)

    I’ve tested the code with draft to publish, and new to publish. Those worked perfectly. For whatever reason, future to publish is not working. The post does transition from scheduled to published, but the action hook isn’t triggered.

    Thread Starter Beer

    (@beer)

    I hooked into ‘transition_post_status’ to monitor the changes. I’ve seen it go from new, inherit, auto-draft, draft, future, publish. While scheduled posts do show up published, the the transition from future to publish never happens. Any ideas?

    Why not just use the built in post scheduler and wp-cron built into current WordPress? Just edit the post date and time prior to publish, could not be easier.

    Thread Starter Beer

    (@beer)

    @swanson, I am scheduling posts through WordPress built-in and I am letting wp-cron change the status to publish.

    I’m trying to hook into that post status transition, to send me an email with information from the post when it publishes. It works on other transition_post_status events, but not on future_to_publish, on this server. I’ve tested the same code on 2 different servers now, and those worked. I’m trying to troubleshoot what might be responsible so I can work-around it or fix it.

    If it matters, php 5.3.3 is running on the server it isn’t working on so far.

    Same issue for me
    add_action(‘future_to_publish’,’function’)
    is not working

    I ran into this same problem, and after a lot of digging, realized that my add_action(‘future_to_publish’,’handler_function’) call was gated behind an is_admin() check. So when the cron process executed the transition from “future” to “publish”, the add_action() call was never being executed, so it never registered the function to handle the transition in my plugin. Long story short — make sure the add_action call isn’t gated behind any conditions that might keep the cron process (which obviously isn’t logged in as an admin) from letting the handler be registered. My implementation works correctly after doing so.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Post status transitions’ is closed to new replies.