-4

谁能帮帮我,我正在使用 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' );
4

1 回答 1

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');略有更改(删除了前导点)

于 2013-01-25T16:05:01.183 回答