I'm trying to figure out why future_to_publish
will not work. Here is a list of what I have checked to work:
draft_to_publish
future_post
publish_post
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);
publish_future_post
action hook, which gets triggered when posts are transitioned from »future« to »publish«, see my answer for a little bit more informationpublish_future_post
does not work either.publish_future_post
is being set and executing. For some reason the function is not activating. I even tried doingwp_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.