Can not get future_to_publish to work

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);

0

Leave a Comment