If you want to register a new post status in WordPress, you can do so with the function register_post_status()
. But WordPress as some predefined statuses that cannot be renamed without interfering with the core functionalities i.e. the Publish state. But you can rename the label without risking to breaking the way WordPress runs.
The quick and easy fix for this is to hook into the views_{$this->screen->id}
filter and apply a string replace function on the label you wish to modify.
In my case, I was working on a WP plugin and I needed to change the Published label to Approved so here’s the snippet that takes care of this.
If you want the filter to affect only your custom post type replace cpt with your custom post type in views_edit-cpt
.
If you feel you need to get the screen id of the page you wish your filter applies to, you can print out the current screen object by accessing the get_current_screen()
method or the property directly by using get_current_screen()->id
I wrote an handy debugging function to help me print out variables and objects so you could also use this function to get the object conveniently
debug_print(get_current_screen(),'','',0);
This snippets goes in functions.php
or your plugin’s function file.
// Replace defaults label with your custom ones
add_filter('views_edit-cpt', 'bn_custom_post_status_labels' );
function bn_custom_post_status_labels( $views ) {
// unset( $views['mine'] ); // If you need to unset a particular view
$views['publish'] = str_replace( 'Published', 'Approved', $views['publish'] );
return $views;
}
Leave a Reply