web-dev-qa-db-fra.com

Dois-je remplacer la fonction plug-in wp_mail () par l'écriture d'un plugin?

Si je veux écraser wp_password_change_notification, dois-je écrire un plugin pour le faire? Cela semble n'avoir aucun effet dans functions.php de mon thème.

La seule chose que je dois faire est de changer le libellé en minuscule.

    if ( !function_exists('wp_password_change_notification') ) :
    /**
     * Notify the blog admin of a user changing password, normally via email.
     *
     * @since 2.7
     *
     * @param object $user User Object
     */
    function wp_password_change_notification(&$user) {
        // send a copy of password change notification to the admin
        // but check to see if it's the admin whose password we're changing, and skip this
        if ( $user->user_email != get_option('admin_email') ) {
            $message = sprintf(__('Password lost and changed for user: %s'), $user->user_login) . "\r\n";
            // The blogname option is escaped with esc_html on the way into the database in sanitize_option
            // we want to reverse this for the plain text arena of emails.
            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
            wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
        }
    }

endif;
2
codecowboy

Oui, vous devez utiliser un plugin. Le fait est que les plug-ins sont entre difficile et impossible à contrôler. Vous pouvez lire via ce fil sur wp-hackers sur les problèmes actuels et sur les raisons pour lesquelles vous ne devriez pas les utiliser .

Important:

Remarque: pluggable.php charge avant le hook 'plugins_loaded'.

Cela signifie que vous avez besoin du "MU-plugins" (Doit utiliser) hook: mu_plugins_loaded et de leur dossier.

Ma recommandation:

Ne le fais pas. Cela ne vaut pas la peine de faire l'effort et les problèmes qui viennent avec cela, juste pour obtenir le texte d'un email en minuscule. Il est beaucoup plus facile d’accrocher directement les filtres et actions wp_mail():

// Compact the input, apply the filters, and extract them back out
extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );

// Plugin authors can override the potentially troublesome default
$phpmailer->From     = apply_filters( 'wp_mail_from'     , $from_email );
$phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name  );

$content_type = apply_filters( 'wp_mail_content_type', $content_type );

// Set the content-type and charset
$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );

do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
1
kaiser