简体   繁体   English

Wordpress / BuddyPress注册中的自定义电子邮件验证

[英]Custom Email Validation in Wordpress/BuddyPress Registration

I'm creating a site using WordPress and BuddyPress. 我正在使用WordPress和BuddyPress创建一个网站。 Registrations should be open to everyone with a .edu email address. 具有.edu电子邮件地址的所有人都可以注册。

If I was using vanilla WordPress, doing this would be pretty straightforward using the registration_errors filter, but that doesn't work when BuddyPress is installed. 如果我使用的是普通WordPress,则使用registration_errors过滤器非常简单,但这在安装BuddyPress时不起作用。 The filter doesn't seem to ever be called. 似乎从未调用过该过滤器。 If I deactivate BuddyPress, it works fine. 如果我停用BuddyPress,则效果很好。

From what I've read, although BuddyPress does have custom validation hooks for extra profile fields beyond the WordPress defaults, you're supposed to use standard WordPress hooks for things like usernames and email addresses. 根据我的阅读,尽管BuddyPress确实为WordPress默认值以外的其他配置文件字段提供了自定义验证钩子,但您应该对用户名和电子邮件地址等使用标准WordPress钩子。

Has anyone run into this issue? 有没有人遇到这个问题? Is there another filter or hook that I should be using? 我应该使用另一个过滤器或挂钩吗?

Take a look at buddypress\\bp-members\\bp-members-screens.php ~L. 看看buddypress \\ bp-members \\ bp-members-screens.php〜L。 49 49

Perhaps this hook ? 也许这个钩子? do_action( 'bp_signup_pre_validate' );

Or take a look at buddypress\\bp-members\\bp-members-functions.php ~L. 或看看buddypress \\ bp-members \\ bp-members-functions.php〜L。 1347 1347

Perhaps this filter? 也许这个过滤器? apply_filters( 'bp_core_validate_user_signup', $result );

The correct hook is bp_signup_validate . 正确的钩子是bp_signup_validate The hooked function isn't passed any parameters, but I can access the global $bp object and modify it to add custom email validation and error messages: 挂钩函数没有传递任何参数,但是我可以访问全局$ bp对象并对其进行修改以添加自定义电子邮件验证和错误消息:

function validate_email_edu(){

    global $bp;

    $email = $bp->signup->email;

    if ($email){

        $tld_index = strrpos($email,'.');
        $tld = substr($email,$tld_index);

        if ($tld != '.edu'){
            $bp->signup->errors['signup_email'] = 'Sorry, you must have a .edu email address to register.';
        }

    }

}

add_action('bp_signup_validate','validate_email_edu');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM