diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 8a507fe0..a296437a 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -1058,21 +1058,24 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { ), 'youtube' => array( - 'title' => __('YouTube','ultimate-member'), - 'metakey' => 'youtube', - 'type' => 'url', - 'label' => __('YouTube','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, + 'title' => __( 'YouTube', 'ultimate-member' ), + 'metakey' => 'youtube', + 'type' => 'url', + 'label' => __( 'YouTube', 'ultimate-member' ), + 'required' => 0, + 'public' => 1, + 'editable' => 1, 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-youtube', - 'validate' => 'youtube_url', - 'url_text' => 'YouTube', - 'advanced' => 'social', - 'color' => '#e52d27', - 'match' => 'https://youtube.com/', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-youtube', + 'validate' => 'youtube_url', + 'url_text' => __( 'YouTube', 'ultimate-member' ), + 'advanced' => 'social', + 'color' => '#e52d27', + 'match' => array( + 'https://youtube.com/', + 'https://youtu.be/', + ), ), 'soundcloud' => array( diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 88a6cb35..bb2e172c 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -86,9 +86,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } foreach ( $social as $k => $arr ) { - if ( um_profile( $k ) ) { ?> + if ( um_profile( $k ) ) { + $match = is_array( $arr['match'] ) ? $arr['match'][0] : $arr['match']; ?> - diff --git a/includes/core/class-form.php b/includes/core/class-form.php index d6494d9b..ab12b1ca 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -657,19 +657,47 @@ if ( ! class_exists( 'um\core\Form' ) ) { $v = sanitize_text_field( $form[ $k ] ); // Make a proper social link - if ( ! empty( $v ) && ! strstr( $v, $f['match'] ) ) { - $domain = trim( strtr( $f['match'], array( - 'https://' => '', - 'http://' => '', - ) ), ' /' ); + if ( ! empty( $v ) ) { + $replace_match = is_array( $f['match'] ) ? $f['match'][0] : $f['match']; - if ( ! strstr( $v, $domain ) ) { - $v = $f['match'] . $v; - } else { - $v = 'https://' . trim( strtr( $v, array( - 'https://' => '', - 'http://' => '', - ) ), ' /' ); + $need_replace = false; + if ( is_array( $f['match'] ) ) { + $need_replace = true; + foreach ( $f['match'] as $arr_match ) { + if ( strstr( $v, $arr_match ) ) { + $need_replace = false; + } + } + } + + if ( ! is_array( $f['match'] ) || $need_replace ) { + if ( ! strstr( $v, $replace_match ) ) { + $domain = trim( + strtr( + $replace_match, + array( + 'https://' => '', + 'http://' => '', + ) + ), + ' /' + ); + + if ( ! strstr( $v, $domain ) ) { + $v = $replace_match . $v; + } else { + $v = 'https://' . trim( + strtr( + $v, + array( + 'https://' => '', + 'http://' => '', + ) + ), + ' /' + ); + } + } } } diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 61531d60..15b1ae94 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -702,7 +702,7 @@ function um_submit_form_errors_hook_( $args ) { break; case 'youtube_url': - if ( ! UM()->validation()->is_url( $args[ $key ], 'youtube.com' ) ) { + if ( ! UM()->validation()->is_url( $args[ $key ], 'youtube.com' ) && ! UM()->validation()->is_url( $args[ $key ], 'youtu.be' ) ) { UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) ); } break;