[wp-trac] [WordPress Trac] #21580: check_and_publish_future_post() should set global $post

WordPress Trac wp-trac at lists.automattic.com
Sat Aug 18 15:22:44 UTC 2012


#21580: check_and_publish_future_post() should set global $post
--------------------------+------------------------------
 Reporter:  MattyRob      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cron          |     Version:  3.4.1
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------

Comment (by MattyRob):

 I'm not 100% sure what additional specifics you want but let me try and
 explain again a little more clearly.

 WordPress has several 'transition' hooks that are called when a post or
 page are 'transitioned' from one publication state to another. I think
 there should be some consistency to the global variables that are
 available.

 I am giving an example here that when the draft_to_publish hook is called
 the global variables of $post and $post_id are available to plugins
 however when hooking to the virtually identical future_to_publish hook
 these variables are not available.

 The code below is a proof of concept that demonstrates this. The attached
 revised patch makes both $post and $post_id available as global variables
 to plugins.

 {{{
 function transition_hook() {
         global $post, $post_id;
         $email = 'your at email.com';
         $message = "Transition Hook was called with $post->ID and
 $post_id";
         @wp_mail($email, 'Transition Hook Plugin', $message);
 }

 add_action('draft_to_publish', 'transition_hook');
 add_action('future_to_publish', 'transition_hook');
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21580#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list