[wp-hackers] Using post_updated_messages filter and better code

Michael E. Hancock justmichaelh at gmail.com
Tue May 25 17:53:45 UTC 2010

Now that the $messages in /wp-admin/edit-form-advanced.php can be filtered 
by post_updated_messages it is possilble to tell the user that a particular 
post type object has been updated rather than just "Post updated".

In this example, is there a better way of manipulating the $messages array 
so the word Post (or post), gets changed to the word Book (or book)?

add_filter('post_updated_messages', 'apply_post_type_to_messages');

function apply_post_type_to_messages($messages) {
global $post_type_object;

if ( 'post' == $post_type_object->capability_type )  {
$old_label = array( 'Post', 'post' );
} else {
$old_label = array( 'Page', 'page' );

//for post_type book this should result in:   array('Book','book')
$new_label = array( $post_type_object->labels->singular_name, 
strtolower($post_type_object->labels->singular_name) );

$messages[$post_type_object->capability_type] = 

return $messages;


Thanks for your suggestions.


More information about the wp-hackers mailing list