diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 1f9ab5e0..5910a3f6 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -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'); /** diff --git a/includes/core/class-validation.php b/includes/core/class-validation.php index a070a331..861c8997 100644 --- a/includes/core/class-validation.php +++ b/includes/core/class-validation.php @@ -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 * diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index cea1871a..293a7e70 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -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' ) );