Generic Pluggable Approach for WordPress < 4.6 (See @birgire\'s Answer for > 4.6)
可插拔功能是WordPress过去令人沮丧的遗物之一,并且伴随着一系列复杂的功能。直接修改核心文件(正如@Jarmerson在评论中提到的那样,这是完全不可取的)不起作用,这让我怀疑您安装的另一个插件可能正在覆盖可插拔文件。
这个wp-includes/pluggable.php 文件加载在活动插件和mu插件之后,但在活动主题之前;这意味着“可插入函数”只能由插件中的声明替代。
您在另一个答案中发现的修改适用于更旧版本的WordPress。在替换任何可插入功能的过程中,您应该从the original function as it exists in your installation\'s version (在您的例子中,是v4.5.3)。这样,解决方案如下所示(注释省略;未添加任何行,仅删除):
function wp_new_user_notification( $user_id, $deprecated = null, $notify = \'\' ) {
if ( $deprecated !== null )
_deprecated_argument( __FUNCTION__, \'4.3.1\' );
if ( \'admin\' === $notify || ( empty( $deprecated ) && empty( $notify ) ) )
return;
global $wpdb, $wp_hasher;
$user = get_userdata( $user_id );
$blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);
$key = wp_generate_password( 20, false );
do_action( \'retrieve_password_key\', $user->user_login, $key );
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . \'/class-phpass.php\';
$wp_hasher = new PasswordHash( 8, true );
}
$hashed = time() . \':\' . $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( \'user_activation_key\' => $hashed ), array( \'user_login\' => $user->user_login ) );
$message = sprintf(__(\'Username: %s\'), $user->user_login) . "\\r\\n\\r\\n";
$message .= __(\'To set your password, visit the following address:\') . "\\r\\n\\r\\n";
$message .= \'<\' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), \'login\') . ">\\r\\n\\r\\n";
$message .= wp_login_url() . "\\r\\n";
wp_mail($user->user_email, sprintf(__(\'[%s] Your username and password info\'), $blogname), $message);
}
我省略了传统的
if( !function_exists() ) 检查是否通常封装了可插拔覆盖,因为在这种情况下,可能会出现重复声明错误-这将表明另一个插件已覆盖
wp_new_user_notification() 功能,因此您这样做的尝试被完全忽略。
我建议将此函数放置在mu-plugin 因为它减少了另一个插件击败你的机会。在任何情况下,都不要修改核心文件wp-includes/pluggable.php 与上述内容。