You can try this:
is_admin() && add_filter( 'gettext',
function( $translated_text, $untranslated_text, $domain )
{
$old = array(
"Plugin <strong>activated</strong>.",
"Selected plugins <strong>activated</strong>."
);
$new = "Captain: The Core is stable and the Plugin is <strong>activated</strong> at full Warp speed";
if ( in_array( $untranslated_text, $old, true ) )
$translated_text = $new;
return $translated_text;
}
, 99, 3 );
to modify the message to your likings:
We can refine it further:
If you only want to activate the filter on the /wp-admins/plugins.php
page, you can use the following instead:
add_action( 'load-plugins.php',
function(){
add_filter( 'gettext', 'b2e_gettext', 99, 3 );
}
);
with:
/**
* Translate the "Plugin activated." string
*/
function b2e_gettext( $translated_text, $untranslated_text, $domain )
{
$old = array(
"Plugin <strong>activated</strong>.",
"Selected plugins <strong>activated</strong>."
);
$new = "Captain: The Core is stable and the Plugin is <strong>activated</strong> at full Warp speed";
if ( in_array( $untranslated_text, $old, true ) )
{
$translated_text = $new;
remove_filter( current_filter(), __FUNCTION__, 99 );
}
return $translated_text;
}
where we remove the gettext filter callback as soon we have a match.
If we want to check the number of gettext calls made, before we match the correct string, we can use this:
/**
* Debug gettext filter callback with counter
*/
function b2e_gettext_debug( $translated_text, $untranslated_text, $domain )
{
static $counter = 0;
$counter++;
$old = "Plugin <strong>activated</strong>.";
$new = "Captain: The Core is stable and the Plugin is <strong>activated</strong> at full Warp speed";
if ( $untranslated_text === $old )
{
$translated_text = $new;
printf( 'counter: %d - ', $counter );
remove_filter( current_filter(), __FUNCTION__ , 99 );
}
return $translated_text;
}
and I get 301
calls on my install:
I can reduce it to only 10
calls:
by adding the gettext filter within the in_admin_header
hook, within the load-plugins.php
hook:
add_action( 'load-plugins.php',
function(){
add_action( 'in_admin_header',
function(){
add_filter( 'gettext', 'b2e_gettext_debug', 99, 3 );
}
);
}
);
Notice that this will not count the gettext calls before the internal redirect used when the plugins are activated.
To activate our filter after the internal redirect we can check the GET parameters used when plugins are activated:
/**
* Check if the GET parameters "activate" and "activate-multi" are set
*/
function b2e_is_activated()
{
$return = FALSE;
$activate = filter_input( INPUT_GET, 'activate', FILTER_SANITIZE_STRING );
$activate_multi = filter_input( INPUT_GET, 'activate-multi', FILTER_SANITIZE_STRING );
if( ! empty( $activate ) || ! empty( $activate_multi ) )
$return = TRUE;
return $return;
}
and use like this:
b2e_is_activated() && add_filter( 'gettext', 'b2e_gettext', 99, 3 );
in the previous code example.