Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#23700 closed defect (bug) (invalid)

publish_future_post action not working

Reported by: jkoon's profile jkoon Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: General Keywords: close
Focuses: Cc:

Description

The API Action Reference for publish_future_post says "Runs when a future post or page is published. Action function arguments: post ID."

However this action does not fire when a post goes from scheduled to published.

I first noticed this on a 3.4.2 install however I have confirmed this in 3.5.1 as well.

Change History (6)

#1 @SergeyBiryukov
13 years ago

  • Keywords reporter-feedback added

Could you provide the steps to reproduce the issue on a clean install?

#2 @jkoon
13 years ago

1) Add the following to the functions.php file:

add_action ('publish_future_post', 'test_action');

function test_action () {
	global $post;	
	$id = $post->ID;
	update_post_meta($post->ID, 'hook_fired', 'true');
}

2) Schedule a post to be published in the future.

3) Review the custom fields data once post has published.

Expected Results: A custom field named hook_fired added to the post with the value of true

Actual Results: No custom fields added to the post

#3 @jkoon
13 years ago

  • Keywords reporter-feedback removed

#4 @helen
13 years ago

  • Keywords reporter-feedback added

What happens if you use the $post_id function arg noted in the reference instead of doing global $post? So:

function test_action ( $post_id ) {
	update_post_meta( $post_id, 'hook_fired', 'true' );
}

#5 @nacin
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Yeah, the global $post isn't set up on cron, nor should it be.

The publish_future_post passes a post ID, as stated in the reference (and in the initial description of the ticket).

#6 @jkoon
13 years ago

  • Keywords close added; reporter-feedback removed
Note: See TracTickets for help on using tickets.