[wp-hackers] Using post_updated_messages filter and better code

Andrew Nacin wp at andrewnacin.com
Tue May 25 18:04:21 UTC 2010


It looks like you are overcomplicating this a little. Proper usage of the
filter would be the following:

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) ) ) ),

}


More information about the wp-hackers mailing list