一直在寻找解决方案,但似乎无法找到解决方案。我的网站在单独的页面上有2个注册表格(表格A和表格B),效果很好。当用户注册到表单B时,将填充名为subscriber_type
的隐藏字段。否则表格A和表格B相同。提交表单后,只有在填充此subscriber_type
字段时才应自动激活并登录用户。
到目前为止,填写表格B的用户已被激活(并且未获得激活电子邮件)并已登录。但填写表格A的用户即使应该也未收到他们的激活电子邮件。看起来没有用户收到任何激活电子邮件,无论他们填写什么表格。
有没有办法让激活电子邮件有条件发送?
到目前为止我尝试过:
// Auto-activate users from Form B (This works)
function auto_activate_user( $user_id ) {
//Check if subscriber_type is in form POST (and is from Form B)
$subscriber_type = $_POST['subscriber_type'];
if ($subscriber_type){
global $wpdb;
//Hook if you want to do something before the activation
do_action('bp_disable_activation_before_activation');
$activation_key = get_user_meta($user_id, 'activation_key', true);
$activate = apply_filters('bp_core_activate_account', bp_core_activate_signup($activation_key));
BP_Signup::validate($activation_key);
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) );
//Add note on Activity Stream
if ( function_exists( 'bp_activity_add' ) ) {
$userlink = bp_core_get_userlink( $user_id );
bp_activity_add( array(
'user_id' => $user_id,
'action' => apply_filters( 'bp_core_activity_registered_member', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
'component' => 'profile',
'type' => 'new_member'
) );
}
//Send email to admin
wp_new_user_notification( $user_id );
// Remove the activation key meta
delete_user_meta( $user_id, 'activation_key' );
// Delete the total member cache
wp_cache_delete( 'bp_total_member_count', 'bp' );
//Hook if you want to do something before the login
do_action('bp_disable_activation_before_login');
//Automatically log the user in .
$user_info = get_userdata($user_id);
wp_set_auth_cookie($user_id);
do_action('wp_signon', $user_info->user_login);
//Hook if you want to do something after the login
do_action('bp_disable_activation_after_login');
}
}
// Fix validation on Form B (This doesn't work - doesn't disable emails)
function fix_signup_form_validation_text() {
//Check if subscriber_type is in form POST (and is from Form B)
$subscriber_type = $_POST['subscriber_type'];
if ($subscriber_type){
return false;
}
}
// Disable activation email only for Form B (This doesn't work - disables emails for all users)
function disable_activation_email() {
//Check if subscriber_type is in form POST (and is from Form B)
$subscriber_type = $_POST['subscriber_type'];
if ($subscriber_type){
return false;
}
}
add_action( 'bp_core_signup_user', 'auto_activate_user');
add_filter( 'bp_registration_needs_activation', 'fix_signup_form_validation_text');
add_filter( 'bp_core_signup_send_activation_key', 'disable_activation_email');
更新:经过多次挖掘后,我确认了以下内容:
bp_registration_needs_activation
不是正确的过滤器,因为在用户注册过程中未调用它。bp_core_signup_send_activation_key
过滤器会禁用所有激活电子邮件,无论其调用的函数是否为第二个参数。