According with the codex, get_current_screen()
has to be used later than admin_init
hook. After a few tests, it seems that the safiest way is to use current_screen
action hook instead of get_current_screen()
:
add_action('current_screen', 'current_screen_callback');
function current_screen_callback($screen) {
if( is_object($screen) && $screen->post_type == 'mycpt' ) {
add_filter( 'gettext', 'theme_change_comments_label', 99, 3 );
}
}
function theme_change_comments_label( $translated_text, $untranslated_text, $domain ) {
if( stripos( $untranslated_text, 'comment' ) !== FALSE ) {
$translated_text = str_ireplace( 'Comment', 'Review', $untranslated_text ) ;
}
return $translated_text;
}
You can reuse the filter if you want, for example in the frontend for “mycpt” archives:
add_action('init', function() {
if( is_post_type_archive( 'mycpt' ) ) {
add_filter( 'gettext', 'theme_change_comments_label', 99, 3 );
}
});