From d4b7a9c5656f4cea9ffa59ffe291931dd67831a3 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 25 Sep 2023 15:36:51 +0300 Subject: [PATCH] - frontend field oembed --- includes/core/class-fields.php | 15 +++++ includes/core/um-filters-fields.php | 87 +++++++++++++++++++---------- 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index cb30c3a3..4009c041 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -4444,6 +4444,21 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } } + break; + /* HTML */ + case 'oembed': + $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>'; + + if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) { + $output .= $this->field_label( $data['label'], $key, $data ); + } + $response = wp_oembed_get( $_field_value ); + if ( empty( $response ) ) { + $response = $_field_value; + } + $output .= '
'; + $output .= '
' . $response . '
'; + $output .= '
'; break; /* HTML */ case 'block': diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index 1727b234..e6446382 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -436,49 +436,76 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) { } if ( isset( $data['type'] ) && 'text' === $data['type'] && isset( $data['validate'] ) && 'skype' === $data['validate'] ) { - $alt = ! empty( $data['url_text'] ) ? $data['url_text'] : $value; - $url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : ''; + $alt = ! empty( $data['url_text'] ) ? $data['url_text'] : $value; + $url_rel = ( isset( $data['url_rel'] ) && 'nofollow' === $data['url_rel'] ) ? 'rel="nofollow"' : ''; $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; if ( false === strstr( $value, 'join.skype.com' ) ) { $value = 'skype:' . $value . '?chat'; } - $value = '' . esc_html( $alt ) . ''; + $value = '' . esc_html( $alt ) . ''; } else { - if ( ( isset( $data['validate'] ) && $data['validate'] !== '' && $data['type'] !== 'spotify' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) { - $alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value; - $url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : ''; + // check $value is oEmbed + if ( 'oembed' === $data['type'] ) { + return $value; + } + + if ( ( isset( $data['validate'] ) && '' !== $data['validate'] && 'spotify' !== $data['type'] && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && 'url' === $data['type'] && 'oembed' !== $data['type'] ) ) { + $alt = ( isset( $data['url_text'] ) && ! empty( $data['url_text'] ) ) ? $data['url_text'] : $value; + $url_rel = ( isset( $data['url_rel'] ) && 'nofollow' === $data['url_rel'] ) ? 'rel="nofollow"' : ''; if ( ! strstr( $value, 'http' ) - && !strstr( $value, '://' ) - && !strstr( $value, 'www.' ) - && !strstr( $value, '.com' ) - && !strstr( $value, '.net' ) - && !strstr( $value, '.org' ) - && !strstr( $value, '.me' ) + && ! strstr( $value, '://' ) + && ! strstr( $value, 'www.' ) + && ! strstr( $value, '.com' ) + && ! strstr( $value, '.net' ) + && ! strstr( $value, '.org' ) + && ! strstr( $value, '.me' ) ) { - if ( $data['validate'] == 'soundcloud_url' ) $value = 'https://soundcloud.com/' . $value; - if ( $data['validate'] == 'youtube_url' ) $value = 'https://youtube.com/user/' . $value; - if ( $data['validate'] == 'telegram_url' ) $value = 'https://t.me/' . $value; - if ( $data['validate'] == 'facebook_url' ) $value = 'https://facebook.com/' . $value; - if ( $data['validate'] == 'twitter_url' ) $value = 'https://twitter.com/' . $value; - if ( $data['validate'] == 'linkedin_url' ) $value = 'https://linkedin.com/' . $value; - if ( $data['validate'] == 'instagram_url' ) $value = 'https://instagram.com/' . $value; - if ( $data['validate'] == 'tiktok_url' ) $value = 'https://tiktok.com/' . $value; - if ( $data['validate'] == 'twitch_url' ) $value = 'https://twitch.tv/' . $value; - if ( $data['validate'] == 'reddit_url' ) $value = 'https://www.reddit.com/user/' . $value; - if ( $data['validate'] == 'spotify_url' ) $value = 'https://open.spotify.com/' . $value; + if ( 'soundcloud_url' === $data['validate'] ) { + $value = 'https://soundcloud.com/' . $value; + } + if ( 'youtube_url' === $data['validate'] ) { + $value = 'https://youtube.com/user/' . $value; + } + if ( 'telegram_url' === $data['validate'] ) { + $value = 'https://t.me/' . $value; + } + if ( 'facebook_url' === $data['validate'] ) { + $value = 'https://facebook.com/' . $value; + } + if ( 'twitter_url' === $data['validate'] ) { + $value = 'https://twitter.com/' . $value; + } + if ( 'linkedin_url' === $data['validate'] ) { + $value = 'https://linkedin.com/' . $value; + } + if ( 'instagram_url' === $data['validate'] ) { + $value = 'https://instagram.com/' . $value; + } + if ( 'tiktok_url' === $data['validate'] ) { + $value = 'https://tiktok.com/' . $value; + } + if ( 'twitch_url' === $data['validate'] ) { + $value = 'https://twitch.tv/' . $value; + } + if ( 'reddit_url' === $data['validate'] ) { + $value = 'https://www.reddit.com/user/' . $value; + } + if ( 'spotify_url' === $data['validate'] ) { + $value = 'https://open.spotify.com/' . $value; + } } if ( strpos( $value, 'http://' ) !== 0 ) { $value = 'http://' . $value; } - $value = str_replace('https://https://','https://',$value); - $value = str_replace('http://https://','https://',$value); + $value = str_replace( 'https://https://', 'https://', $value ); + $value = str_replace( 'http://https://', 'https://', $value ); $onclick_alert = ''; - if ( UM()->options()->get( 'allow_url_redirect_confirm' ) && $value !== wp_validate_redirect( $value ) ) { + if ( UM()->options()->get( 'allow_url_redirect_confirm' ) && wp_validate_redirect( $value ) !== $value ) { $onclick_alert = sprintf( ' onclick="' . esc_attr( 'return confirm( "%s" );' ) . '"', // translators: %s: link. @@ -487,20 +514,20 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) { } $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; - $value = '' . esc_html( $alt ) . ''; + $value = '' . esc_html( $alt ) . ''; } } if ( ! is_array( $value ) ) { if ( is_email( $value ) ) { - $value = ''.$value.''; + $value = '' . $value . ''; } } else { $value = implode( ', ', $value ); } - $value = str_replace('https://https://','https://',$value); - $value = str_replace('http://https://','https://',$value); + $value = str_replace( 'https://https://', 'https://', $value ); + $value = str_replace( 'http://https://', 'https://', $value ); //$value = UM()->shortcodes()->emotize( $value ); return $value;