Hook into install email

时间:2015-06-12 作者:mousesports

我创建了一个插件,利用wp_install 方法(此部分是插件正常工作所必需的,需要调用此函数)。

http://wpseek.com/function/wp_install/

其中wp_new_blog_notification 方法在安装后立即发出标准WordPress电子邮件(插件不需要此部分)。

http://wpseek.com/function/wp_new_blog_notification/

有没有人知道有没有办法加入到这个方法中,阻止邮件被炒鱿鱼?

EDIT:

我还应该提到,在插件中,我创建了一个过滤器:

add_filter( \'wp_mail\', array( $this, \'_fix_mail\' ) );
其中_fix_mail 方法只查找wp_new_blog_notification 并将其替换为自定义的。然而,这完全是因为我似乎无法阻止它开火。更好的解决方案是不发送安装电子邮件。

1 个回复
SO网友:sakibmoon

如果您看到了代码,那么就没有钩子可以做到这一点。但是您可以创建自己的函数并删除不需要的部分,就像这样

function custom_wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = \'\', $user_password = \'\', $language = \'\' ) {
    if ( !empty( $deprecated ) )
        _deprecated_argument( __FUNCTION__, \'2.6\' );

    wp_check_mysql_version();
    wp_cache_flush();
    make_db_current_silent();
    populate_options();
    populate_roles();

    update_option(\'blogname\', $blog_title);
    update_option(\'admin_email\', $user_email);
    update_option(\'blog_public\', $public);

    if ( $language ) {
        update_option( \'WPLANG\', $language );
    }

    $guessurl = wp_guess_url();

    update_option(\'siteurl\', $guessurl);

    // If not a public blog, don\'t ping.
    if ( ! $public )
        update_option(\'default_pingback_flag\', 0);

    /*
     * Create default user. If the user already exists, the user tables are
     * being shared among blogs. Just set the role in that case.
     */
    $user_id = username_exists($user_name);
    $user_password = trim($user_password);
    $email_password = false;
    if ( !$user_id && empty($user_password) ) {
        $user_password = wp_generate_password( 12, false );
        $message = __(\'<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.\');
        $user_id = wp_create_user($user_name, $user_password, $user_email);
        update_user_option($user_id, \'default_password_nag\', true, true);
        $email_password = true;
    } elseif ( ! $user_id ) {
        // Password has been provided
        $message = \'<em>\'.__(\'Your chosen password.\').\'</em>\';
        $user_id = wp_create_user($user_name, $user_password, $user_email);
    } else {
        $message = __(\'User already exists. Password inherited.\');
    }

    $user = new WP_User($user_id);
    $user->set_role(\'administrator\');

    wp_install_defaults($user_id);

    wp_install_maybe_enable_pretty_permalinks();

    flush_rewrite_rules();

    wp_cache_flush();

    /**
     * Fires after a site is fully installed.
     *
     * @since 3.9.0
     *
     * @param WP_User $user The site owner.
     */
    do_action( \'wp_install\', $user );

    return array(\'url\' => $guessurl, \'user_id\' => $user_id, \'password\' => $user_password, \'password_message\' => $message);
}

结束

相关推荐

排除Plugins.php HTTP安装路径与单个插件的HTTPS的故障

我正在尝试对插件中显示的安装路径进行故障排除。php作为我在自己的网站上安装的插件,我最初并没有编写该插件。当我的站点的其余部分是HTTPS时,此插件引用和安装的所有资源都会显示为混合内容HTTP。我一直在玩弄下面的代码段,但它似乎没有起到什么作用,也没有解决问题。有人能指出我遗漏了什么吗? /** * registers scripts and stylesheets */ public function register_assets() {&