无法使用muplugin覆盖可插拔函数

时间:2013-02-06 作者:Jake Lisby

我正在尝试修改当用户被邀请加入我的多站点网络时发送给他们的电子邮件。了解我只能使用可插拔功能,如何使用必须使用的插件覆盖默认电子邮件?现在它不允许我覆盖并显示默认文本。

这是我当前的代码:

if ( !function_exists(\'wp_new_user_notification\') ) {
    function wp_new_user_notification( $user_id, $plaintext_pass = \'\' ) {
        $user = new WP_User($user_id);

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);
        $siteUrl = get_site_url().\'/login\';
        $email_subject = "Welcome to Dewsly ".$user_login;

        $message  = sprintf(__(\'New user registration on your blog %s:\'), get_option(\'blogname\')) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'E-mail: %s\'), $user_email) . "\\r\\n";

        @wp_mail(get_option(\'admin_email\'), $email_subject, $message);

        if ( empty($plaintext_pass) )
            return;

        ob_start();

        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            </head>
            <body style="background:#e5f6fb">

            </body>
        </html>

        <?php

        $message = ob_get_contents();
        ob_end_clean();

        wp_mail($user_email, $email_subject, $message);

    }
}

1 个回复
最合适的回答,由SO网友:Milo 整理而成

该功能不适用于MS注册wpmu_signup_user_notification 中的函数wp-includes/ms-functions.php 处理这个问题。下面是该函数的docblock:

/**
 * Notify user of signup success.
 *
 * This is the notification function used when no new site has
 * been requested.
 *
 * Filter \'wpmu_signup_user_notification\' to bypass this function or
 * replace it with your own notification behavior.
 *
 * Filter \'wpmu_signup_user_notification_email\' and
 * \'wpmu_signup_user_notification_subject\' to change the content
 * and subject line of the email sent to newly registered users.
 *

结束