禁止域名扩展名buddypress

时间:2013-01-25 15:57:34

标签: php

有人可以帮助我,我正在使用Buddypress / wordpress,我想禁止一些域名扩展名,例如.pl,.ru,.asia。我尝试了以下功能,适用于电子邮件域,但不适用于扩展。

function my_bp_ban_domains( $result ) {
    $banned = array('.ru', '.pl');
    $error = 'God catch you brah !!!, Spammers are not welcome here, try your luck elsewhere.';
    $email = $result['user_email']; 
    $domain = array_pop(explode('@', $email));
    if ( in_array($domain, $banned)) {
        $result['errors']->add('user_email', __($error, 'my_bp_ban_domains' ) );
    };
    return $result;
}

add_filter( 'bp_core_validate_user_signup', 'my_bp_ban_domains' );

1 个答案:

答案 0 :(得分:2)

下面应该可以正常工作。我只是进一步使用.拆分域并获取数组中的最后一项:

function my_bp_ban_domains( $result ) {
    $banned = array('ru', 'pl');
    $error = 'Your email domain has been the source of spam. Please use another email address.';
    $email = $result['user_email']; 
    $domain = array_pop(explode('@', $email));
    $ext = array_pop(explode(',',$domain));
    if ( in_array($ext, $banned)) {
        $result['errors']->add('user_email', __($error, 'my_bp_ban_domains' ) );
    };
    return $result;
}

注意$banned = array('ru', 'pl');稍微改变(删除了前导点)