您可以尝试此骨架插件:
/**
* Plugin Name: Allow duplicate emails on registration
* Plugin URI: http://wordpress.stackexchange.com/a/125129/26350
*/
add_action( \'plugins_loaded\', array( \'Allow_Duplicate_Emails_Registration\', \'get_instance\' ) );
class Allow_Duplicate_Emails_Registration
{
private $rand = \'\';
static private $instance = NULL;
static public function get_instance()
{
if ( NULL === self::$instance )
self::$instance = new self;
return self::$instance;
}
public function __construct()
{
// Generate some random string:
$this->rand = \'_remove_\' . rand( 0, 99999);
add_filter( \'user_registration_email\', array( $this, \'user_registration_email\' ) );
add_action( \'user_register\', array( $this, \'user_register\' ) );
}
public function user_registration_email( $user_email )
{
// inject random string into the email
$user_email = str_replace( \'@\', $this->rand . \'@\', $user_email );
return $user_email;
}
public function user_register( $user_id )
{
// retrieve the newly registered user object
$user = get_user_by( \'id\', $user_id );
// remove the random string
$user_email = str_replace( $this->rand . \'@\', \'@\', $user->user_email );
// update the email of the newly registered user
$args = array(
\'ID\' => $user_id,
\'user_email\' => $user_email,
);
$result = wp_update_user( $args );
}
}
此插件将在注册时向电子邮件中添加一些随机字符串。它在唯一电子邮件检查之前完成,然后在
wp_new_user_notification()
在中激活
register_new_user()
. 因此,您应该将电子邮件通知发送到未修改的电子邮件地址。
然后,您可以根据需要进一步修改此选项。
上一个答案:
我只是想知道如何绕过电子邮件的独特限制:
注册过程中,对唯一电子邮件的检查在哪里
a) 在…内
wp_insert_user()
我们有这张支票:
if ( !$update && ! defined( \'WP_IMPORTING\' ) && email_exists($user_email) )
return new WP_Error( \'existing_user_email\', __( \'Sorry, that email address is already used!\' ) );
函数内没有显式筛选器
email_exists()
我们可以用来解决这个问题。这个
\'WP_IMPORTING\'
常量可能是解决这个问题的方法(但我不确定它是否有一些安全问题)
b) 内部register_new_user()
功能我们有以下几行:
} elseif ( email_exists( $user_email ) ) {
$errors->add( \'email_exists\', __( \'<strong>ERROR</strong>: This email is already registered, please choose another one.\' ) );
}
解决方法(警告:未完全测试):绕过
a) 和
b), 我们可以尝试:
function custom_registration_errors( $errors )
{
define( \'WP_IMPORTING\', TRUE );
unset( $errors->errors[\'email_exists\'] );
return $errors;
}
add_filter( \'registration_errors\', \'custom_registration_errors\' );
也许再把它关掉:
function custom_user_register( $errors )
{
define( \'WP_IMPORTING\', FALSE );
}
add_action( \'user_register\', \'custom_user_register\' );
因此,这似乎让我可以用相同的电子邮件注册用户,但这只是一些针对电子邮件检查的黑客行为,所以要小心。我还没有检查使用
WP_IMPORTING
绕过独特的电子邮件限制。因此,你应该进一步挖掘这一问题。
密码丢失过程可能需要一些修改?
您需要在导入期间删除此项。
所以希望这能让你开始,但你也应该重新考虑你的设置,也许有更好的方法来实现你的主要目标;-)