Cambio del valor predeterminado del mensaje “Complemento activado”

11

Cada vez que un administrador en WordPress active un complemento, al volver a cargar la página del complemento, aparecerá un aviso cuando se active correctamente el informe "Complemento activado".

¿Hayalgunaformadecambiarestetextoqueapareceenelavisodeadministraciónodebousarmipropiomensajepersonalizado?Además,sidebousarunmensajepersonalizado,¿suprimiráestoelmensajepredeterminado"Complemento activado"?

Preguntas relacionadas:

Duplicar:

Gracias a Pieter por el hallazgo:

Recursos adicionales:

  

Nota

     

Recuerde que aunque el filtro 'gettext' solo se aplica durante las llamadas a la función translate() , prácticamente todas las demás funciones i18n utilizan i18n.php . Incluyen todas las funciones enumeradas aquí en esta publicación en " Sintaxis de Gettext ".

    
pregunta gate_engineer 29.03.2014 - 05:29

1 respuesta

14

Puedes probar esto:

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 );

para modificar el mensaje a su gusto:

Podemosrefinarlomás:

Sisoloquieresactivarelfiltroenlapágina/wp-admins/plugins.php,puedesusarlosiguiente:

add_action('load-plugins.php',function(){add_filter('gettext','b2e_gettext',99,3);});

con:

/***Translatethe"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;
}

donde eliminamos la devolución de llamada del filtro gettext tan pronto tengamos una coincidencia.

Si queremos verificar la cantidad de llamadas de Gettext realizadas antes de que coincidamos con la cadena correcta, podemos usar esto:

/**
 * 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;
}

y recibo 301 llamadas en mi instalación:

Puedoreducirloasolo10calls:

agregando el filtro gettext dentro del enlace in_admin_header , dentro del enlace load-plugins.php :

add_action( 'load-plugins.php',
    function(){
        add_action( 'in_admin_header',
            function(){
                add_filter( 'gettext', 'b2e_gettext_debug', 99, 3 );
            }
        );
    }
);

Tenga en cuenta que esto no contará las llamadas gettext antes de la redirección interna utilizada cuando se activan los complementos.

Para activar nuestro filtro después de la redirección interna, podemos verificar los parámetros GET utilizados cuando se activan los complementos:

/**
 * 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;
}

y usar así:

b2e_is_activated() && add_filter( 'gettext', 'b2e_gettext', 99, 3 );

en el ejemplo de código anterior.

    
respondido por el birgire 29.03.2014 - 09:07

Lea otras preguntas en las etiquetas