[wp-hackers] How do filters access variables outside of their function?

Ken Ken at adcSTUDIO.com
Thu Aug 26 20:13:33 UTC 2010


For example a function Nacin put together on a thread back in May (found 
on Google):

add_filter('post_updated_messages', 'nacin_book_updated_messages');

function nacin_book_updated_messages( $messages ) {

$messages['book'] = array(
  1 => sprintf( __('Book updated. <a href="%s">View book</a>',
'myplugin_textdomain'), esc_url( get_permalink($post_ID) ) ),
  2 => $messages['post'][2],
  3 => $messages['post'][3],
  4 => __('Book updated.', 'myplugin_textdomain'),
/* translators: %s: date and time of the revision */
  5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision 
from
%s', 'myplugin_textdomain'), wp_post_revision_title( (int)
$_GET['revision'], false ) ) : false,
  6 => sprintf( __('Book published. <a href="%s">View book</a>',
'myplugin_textdomain'), esc_url( get_permalink($post_ID) ) ),
  7 => __('Book saved.', 'myplugin_textdomain'),
  8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview
book</a>', 'myplugin_textdomain'), esc_url( add_query_arg( 'preview',
'true', get_permalink($post_ID) ) ) ),
  9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a
target="_blank" href="%2$s">Preview book</a>', 'myplugin_textdomain'),
         // translators: Publish box date format, see http://php.net/date
         date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ),
esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview
book</a>', 'myplugin_textdomain'), esc_url( add_query_arg( 'preview',
'true', get_permalink($post_ID) ) ) ),

}

Calls both $post_ID and $post->post_date, both of which thro notices 
with wp_debug turned on.

The thing that has me stumpt is that I didn't think variables outside of 
the function were accessible unless global'd.

Can anyone enlighten me on this? Thanks



More information about the wp-hackers mailing list