From 86afc2523a54a81f49815e33fb2f5df42ca2ad41 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 22 Sep 2023 14:52:12 +0300 Subject: [PATCH 1/4] - init commit --- includes/core/class-builtin.php | 15 +++++++++++++++ includes/core/class-fields.php | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 44956c60..bbe8249d 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -665,6 +665,21 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { ), ), ), + 'oembed' => array( + 'name' => __( 'oEmbed', 'ultimate-member' ), + 'col1' => array( '_title', '_metakey', '_help', '_default', '_visibility' ), + 'col2' => array( '_label', '_placeholder', '_public', '_roles', '_validate', '_custom_validate' ), + 'col3' => array( '_required', '_editable', '_icon' ), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __( 'You must provide a title', 'ultimate-member' ), + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ), + ), /*'group' => array( 'name' => 'Field Group', diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 8554b9cd..cb30c3a3 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -1711,6 +1711,12 @@ if ( ! class_exists( 'um\core\Fields' ) ) { break; + case 'oembed': + + $array['input'] = 'url'; + + break; + case 'date': $array['input'] = 'text'; @@ -2649,6 +2655,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } break; /* URL */ + case 'oembed': case 'url': $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>'; From d4b7a9c5656f4cea9ffa59ffe291931dd67831a3 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 25 Sep 2023 15:36:51 +0300 Subject: [PATCH 2/4] - 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; From 2cf7387b69421936cee61e970e34960d69374041 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 26 Sep 2023 09:05:22 +0300 Subject: [PATCH 3/4] - for member directory --- includes/core/class-form.php | 1 + includes/core/um-filters-fields.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/includes/core/class-form.php b/includes/core/class-form.php index 6a3b74d4..beb43872 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -775,6 +775,7 @@ if ( ! class_exists( 'um\core\Form' ) ) { $form[ $k ] = sanitize_textarea_field( $form[ $k ] ); } break; + case 'oembed': case 'url': $f = UM()->builtin()->get_a_field( $k ); diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index e6446382..78211b89 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -22,6 +22,30 @@ function um_edit_label_all_fields( $label, $data ) { add_filter( 'um_edit_label_all_fields', 'um_edit_label_all_fields', 10, 2 ); +/** + * Outputs a oEmbed field + * + * @param string $value + * @param array $data + * + * @return string + */ +function um_profile_field_filter_hook__oembed( $value, $data ) { + if ( empty( $value ) ) { + return ''; + } + $responce = wp_oembed_get( $value ); + if ( empty( $responce ) ) { + $value = '' . esc_html( $value ) . ''; + } else { + $value = $responce; + } + + return $value; +} +add_filter( 'um_profile_field_filter_hook__oembed', 'um_profile_field_filter_hook__oembed', 99, 2 ); + + /** * Outputs a SoundCloud track * From dc0ea197701196ef8ff80974d4c387003714279b Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 26 Sep 2023 09:19:25 +0300 Subject: [PATCH 4/4] - fix code comment --- includes/core/class-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 4009c041..074e17ff 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -4445,7 +4445,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } break; - /* HTML */ + /* oEmbed */ case 'oembed': $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>';