How to change the “Item updated” message for a custom taxonomy

This is the first in a series of posts on some more technical (read ‘developer’) issues that I have come across. I’m documenting them here primarily so I can remember them, but hopefully some other developer will find hem useful someday. I’ll focus on challenges for which I have trouble finding solutions on the Internet, not solutions that are readily available in many tutorials.

Today I was working on a “Teams” custom taxonomy for the next MSTW Team Rosters release. This is a custom taxonomy ( think category or tag ) that links a group of “Players” ( a custom post type ) together as a team. I added a metadata field to the taxonomy in order to link the Team Rosters plugin “Teams” together with the Schedules & Scoreboards plugin’s “Teams”. The data for each “Team” – items like home venue, logos, colors – will live in the Schedules & Scoreboards data tables, but be accessible to the Team Rosters plugin. Those readers who use the MSTW plugins will learn more about this cool new feature later.

As I completed this code, I noticed that when updating a Team, the update message looked like this:

Item Update Message

Hummm, what’s with this “Item” stuff? That should read “Team”. It seemed like that fix should be a simple WP filter (and it was). I do essentially the same thing for custom post types (see below).

Game Update Message

But this was a bit different, it was a taxonomy. After Goggling my brains out with little success (ergo, this post), I decided to dig into the WordPress core code, and found the filter I needed in /wp-admin/edit-tags.php. The filter is “term_updated_messages“, but (of course) it doesn’t work quite the same as the “post_updated_messages” used for CPTs. It’s a bit simpler, and there is no “bulk_term_updated_messages” like there is for CPTs ( “bulk_post_updated_messages” ). I assume because there is no trash can for terms ( items in a taxonomy ) like there is for posts.

So the code is pretty simple once you find it. First add the filter.

add_filter('term_updated_messages', 'mstw_tr_updated_term_messages');

Then write the callback.

 function mstw_tr_updated_term_messages( $messages ) {

     //mstw_tr_team is the custom taxonomy	
     $messages['mstw_tr_team'] = array(
		0 => '',
		1 => __( 'Team added.', 'mstw-team-rosters' ),
		2 => __( 'Team deleted.', 'mstw-team-rosters' ),
		3 => __( 'Team updated.', 'mstw-team-rosters' ),
		4 => __( 'Team not added.', 'mstw-team-rosters' ),
		5 => __( 'Team not updated.', 'mstw-team-rosters' ),
		6 => __( 'Teams deleted.', 'mstw-team-rosters' ),
		);
									
     return $messages;
		
 } //End: mstw_tr_updated_term_messages( )

And there you have it.

Team Update Message

I hope that helps somebody someday. I’m sure I’ll end up looking for it eventually. If you have an questions, send me an e-mail.