2

I'm trying to figure out why future_to_publish will not work. Here is a list of what I have checked to work:

  1. draft_to_publish
  2. future_post
  3. publish_post
  4. transition_post_status (works draft to future, but not future to publish)

I can't seem to figure out the problem. I'll include the test code I'm using below:

function on_post_scheduled( $ID, $post ) {
    $fp = fopen( get_template_directory() . "/files/foo.php", 'r+' );   
    if ( flock( $fp, LOCK_EX ) ) {
        ftruncate( $fp, 0 );      
        fwrite( $fp, "future post published" . mt_rand( 0, 255 ) );
        fflush( $fp );           
        flock( $fp, LOCK_UN );
    }
}
add_action( 'future_to_publish', 'on_post_scheduled', 10, 2 );
add_action( 'new_to_publish', 'on_post_scheduled', 10, 2);
add_action( 'draft_to_publish', 'on_post_scheduled', 10, 2);
6
  • there is the publish_future_post action hook, which gets triggered when posts are transitioned from »future« to »publish«, see my answer for a little bit more information Nov 2, 2015 at 12:50
  • publish_future_post does not work either.
    – Drzgamer
    Nov 2, 2015 at 18:33
  • 1
    You need to get more descriptive, does not work, really does not help anybody. You might have to do some in depth debugging and come back with it. Nov 2, 2015 at 20:00
  • So after some testing, the cron job for publish_future_post is being set and executing. For some reason the function is not activating. I even tried doing wp_schedule_single_event. In that case it still created the cron job, but it never executed the action i created (which was tied to the function I'm trying to execute). I even activated debug mode and added a print to that at each step. No errors and it only printed when the post is scheduled.
    – Drzgamer
    Nov 2, 2015 at 22:31
  • 2
    I had the same problem and it was not working because I had the "add_action( 'publish_future_post'..." call wrapped inside of "if ( is_admin() ) {" Dec 2, 2016 at 6:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.