Merge pull request #953 from ultimatemember/feature/discord_field

Discord field (issue #926)
This commit is contained in:
Nikita Sinelnikov
2021-12-14 08:18:02 +02:00
committed by GitHub
3 changed files with 38 additions and 0 deletions
+14
View File
@@ -1029,6 +1029,19 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
'match' => 'https://t.me/',
),
'discord' => array(
'title' => __('Discord','ultimate-member'),
'metakey' => 'discord',
'type' => 'text',
'label' => __('Discord ID','ultimate-member'),
'required' => 0,
'public' => 1,
'editable' => 1,
'url_target' => '_blank',
'url_rel' => 'nofollow',
'validate' => 'discord',
),
'youtube' => array(
'title' => __('YouTube','ultimate-member'),
'metakey' => 'youtube',
@@ -1455,6 +1468,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
$array['url'] = __('Website URL','ultimate-member');
$array['youtube_url'] = __('YouTube Profile','ultimate-member');
$array['telegram_url'] = __('Telegram URL','ultimate-member');
$array['discord'] = __('Discord ID','ultimate-member');
$array['custom'] = __('Custom Validation','ultimate-member');
/**
+18
View File
@@ -284,6 +284,24 @@ if ( ! class_exists( 'um\core\Validation' ) ) {
}
/**
* Is Discord ID
*
* @param $string
*
* @return bool
*/
public function is_discord_id( $string ) {
if ( ! $string ) {
return true;
}
if ( ! preg_match( '/(^\S+)#(\d+)$/', trim( $string ) ) ) {
return false;
}
return true;
}
/**
* Is url
*
+6
View File
@@ -758,6 +758,12 @@ function um_submit_form_errors_hook_( $args ) {
}
break;
case 'discord':
if ( ! UM()->validation()->is_discord_id( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Please enter a valid Discord ID', 'ultimate-member' ) );
}
break;
case 'url':
if ( ! UM()->validation()->is_url( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Please enter a valid URL', 'ultimate-member' ) );