[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:48:00 UTC 2012


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

 * keywords:  has-patch dev-feedback => has-patch
 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 Right; my thought was that plugins shouldn't rely on the globals at all,
 since they receive that information as parameters:

 {{{
 function transition_hook( $post_id, $post ) {
         $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');
 }}}

 The fact that the $post global happens to be the same in the
 'draft_to_publish' hook is a coincidence. Notice that
 wp_transition_post_status() doesn't explicitly set the post global either:

 {{{
 function wp_transition_post_status($new_status, $old_status, $post) {
         do_action('transition_post_status', $new_status, $old_status,
 $post);
         do_action("{$old_status}_to_{$new_status}", $post);
         do_action("{$new_status}_{$post->post_type}", $post->ID, $post);
 }
 }}}

 Given that 1) the patch might cause other unwanted side-effects and 2) we
 want to discourage use of globals in general, I'm closing this.

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


More information about the wp-trac mailing list