From 4e90ec55020d439968998569d88ab597ebc57bc0 Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Sat, 11 Dec 2021 02:55:42 +0200 Subject: [PATCH] - Skype field code review; --- .../admin/core/packages/2.2.6/functions.php | 82 +++++++++++++++++++ includes/admin/core/packages/2.2.6/hooks.php | 5 ++ includes/admin/core/packages/2.2.6/init.php | 30 +++++++ includes/core/class-builtin.php | 6 +- includes/core/class-member-directory.php | 3 +- includes/core/um-actions-profile.php | 4 +- includes/core/um-filters-fields.php | 78 +++++++----------- includes/core/um-filters-profile.php | 2 +- readme.txt | 8 +- ultimate-member.php | 2 +- 10 files changed, 162 insertions(+), 58 deletions(-) create mode 100644 includes/admin/core/packages/2.2.6/functions.php create mode 100644 includes/admin/core/packages/2.2.6/hooks.php create mode 100644 includes/admin/core/packages/2.2.6/init.php diff --git a/includes/admin/core/packages/2.2.6/functions.php b/includes/admin/core/packages/2.2.6/functions.php new file mode 100644 index 00000000..e7fe34b9 --- /dev/null +++ b/includes/admin/core/packages/2.2.6/functions.php @@ -0,0 +1,82 @@ +admin()->check_ajax_nonce(); + + um_maybe_unset_time_limit(); + + $forms_query = new WP_Query; + $forms = $forms_query->query( array( + 'post_type' => 'um_form', + 'posts_per_page' => -1, + 'fields' => 'ids' + ) ); + + $fields_for_upgrade = array(); + + foreach ( $forms as $form_id ) { + $forms_fields = get_post_meta( $form_id, '_um_custom_fields', true ); + + $changed = false; + foreach ( $forms_fields as $key => &$field ) { + if ( isset( $field['validate'] ) && 'skype' === $field['validate'] ) { + if ( isset( $field['type'] ) && 'url' === $field['type'] ) { + $field['type'] = 'text'; + $changed = true; + + $fields_for_upgrade[] = $field['metakey']; + } + } + } + + if ( $changed ) { + update_post_meta( $form_id, '_um_custom_fields', $forms_fields ); + } + } + + $changed = false; + $custom_fields = get_option( 'um_fields', array() ); + foreach ( $custom_fields as &$custom_field ) { + if ( isset( $custom_field['validate'] ) && 'skype' === $custom_field['validate'] ) { + if ( isset( $custom_field['type'] ) && 'url' === $custom_field['type'] ) { + $custom_field['type'] = 'text'; + $changed = true; + + $fields_for_upgrade[] = $custom_field['metakey']; + } + } + } + if ( $changed ) { + update_option( 'um_fields', $custom_fields ); + } + + $fields_for_upgrade = array_unique( $fields_for_upgrade ); + + // avoid 'https://', 'http://' at the start of the Skype field is there is nickname but not https://join.skype.com/ + // change only links with nickname skip https://join.skype.com/ + if ( ! empty( $fields_for_upgrade ) ) { + global $wpdb; + $usermetas = $wpdb->get_results( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN( '" . implode( "','", $fields_for_upgrade ) . "' )", ARRAY_A ); + if ( ! empty( $usermetas ) ) { + foreach ( $usermetas as $usermeta ) { + if ( false !== strstr( $usermeta['meta_value'], 'https://' ) || false !== strstr( $usermeta['meta_value'], 'http://' ) ) { + if ( false === strstr( $usermeta['meta_value'], 'join.skype.com/' ) ) { + $usermeta['meta_value'] = str_replace( array( 'https://', 'http://' ), '', $usermeta['meta_value'] ); + update_user_meta( $usermeta['user_id'], $usermeta['meta_key'], $usermeta['meta_value'] ); + + delete_option( "um_cache_userdata_{$usermeta['user_id']}" ); + } + } + } + } + } + + update_option( 'um_last_version_upgrade', '2.2.6' ); + + if ( ! empty( $fields_for_upgrade ) ) { + wp_send_json_success( array( 'message' => __( 'SkypeID fields have been updated successfully', 'ultimate-member' ) ) ); + } else { + wp_send_json_success( array( 'message' => __( 'Database has been updated successfully', 'ultimate-member' ) ) ); + } +} diff --git a/includes/admin/core/packages/2.2.6/hooks.php b/includes/admin/core/packages/2.2.6/hooks.php new file mode 100644 index 00000000..ad5e7f11 --- /dev/null +++ b/includes/admin/core/packages/2.2.6/hooks.php @@ -0,0 +1,5 @@ + 'skype_id226', +); diff --git a/includes/admin/core/packages/2.2.6/init.php b/includes/admin/core/packages/2.2.6/init.php new file mode 100644 index 00000000..2445132d --- /dev/null +++ b/includes/admin/core/packages/2.2.6/init.php @@ -0,0 +1,30 @@ + + + + diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 96f08889..1f9ab5e0 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -972,7 +972,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { 'skype' => array( 'title' => __('Skype ID','ultimate-member'), 'metakey' => 'skype', - 'type' => 'url', + 'type' => 'text', 'label' => __('Skype ID','ultimate-member'), 'required' => 0, 'public' => 1, @@ -981,7 +981,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { 'url_rel' => 'nofollow', 'icon' => 'um-faicon-skype', 'validate' => 'skype', - 'url_text' => 'Skype', + 'url_text' => __( 'Join chat', 'ultimate-member' ), ), 'viber' => array( @@ -1008,7 +1008,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) { 'editable' => 1, 'url_target' => '_blank', 'url_rel' => 'nofollow', - 'icon' => 'um-icon-ios-telephone-outline', + 'icon' => 'um-icon-social-whatsapp', 'validate' => 'phone_number', ), diff --git a/includes/core/class-member-directory.php b/includes/core/class-member-directory.php index 918c24ee..7f21d69e 100644 --- a/includes/core/class-member-directory.php +++ b/includes/core/class-member-directory.php @@ -876,7 +876,8 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) { function slider_range_placeholder( $filter, $attrs ) { switch ( $filter ) { default: { - $label = ucwords( str_replace( array( 'um_', '_' ), array( '', ' ' ), $attrs['label'] ) ); + $label = ! empty( $attrs['label'] ) ? $attrs['label'] : $filter; + $label = ucwords( str_replace( array( 'um_', '_' ), array( '', ' ' ), $label ) ); $placeholders = apply_filters( 'um_member_directory_filter_slider_range_placeholder', false, $filter ); if ( ! $placeholders ) { diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 9e3a62c2..12d06e13 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -767,7 +767,9 @@ function um_profile_dynamic_meta_desc() { - + + + diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index a3cce8f7..2589a3b3 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -385,52 +385,44 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) { return ''; } - if ( ( isset( $data['validate'] ) && $data['validate'] !== '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) { - $alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value; + 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"' : ''; - if ( ! strstr( $value, 'http' ) - && !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'] == 'skype' ) $value = 'skype:'.$value.'?chat'; - if ( $data['validate'] == 'googleplus_url' ) $value = 'https://plus.google.com/' . $value; - if ( $data['validate'] == 'instagram_url' ) $value = 'https://instagram.com/' . $value; - if ( $data['validate'] == 'vk_url' ) $value = 'https://vk.com/' . $value; + $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; + + if ( false === strstr( $value, 'join.skype.com' ) ) { + $value = 'skype:' . $value . '?chat'; } - - if ( ! ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) ) { + $value = '' . esc_html( $alt ) . ''; + } else { + if ( ( isset( $data['validate'] ) && $data['validate'] !== '' && 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"' : ''; + if ( ! strstr( $value, 'http' ) + && !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'] == 'googleplus_url' ) $value = 'https://plus.google.com/' . $value; + if ( $data['validate'] == 'instagram_url' ) $value = 'https://instagram.com/' . $value; + if ( $data['validate'] == 'vk_url' ) $value = 'https://vk.com/' . $value; + } if ( strpos( $value, 'http://' ) !== 0 ) { $value = 'http://' . $value; } $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; $value = ''.$alt.''; - - } - - } - - if ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) { - - $value = str_replace('https://','',$value ); - $value = str_replace('http://','',$value ); - - $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; - if ( strpos( $value, '.cid.' ) !== 0 ) { - $value = '' . $value . ''; - } else { - $value = '' . esc_html__( 'Skype' ) . ''; } } @@ -895,15 +887,3 @@ function um_edit_url_field_value( $value, $key ) { return $value; } add_filter( 'um_edit_url_field_value', 'um_edit_url_field_value', 10, 2 ); - - -add_filter( 'um_submit_post_form', 'my_submit_post_form', 10, 1 ); -function my_submit_post_form( $data ) { - $skype_key = 'skype-'. $data['form_id']; - if ( array_key_exists( $skype_key , $data ) ) { - $skype = str_replace('live:', '', $data[ $skype_key ] ); - $data[ $skype_key ] = $skype; - } - - return $data; -} \ No newline at end of file diff --git a/includes/core/um-filters-profile.php b/includes/core/um-filters-profile.php index 4b7b6eb2..f6b6d869 100644 --- a/includes/core/um-filters-profile.php +++ b/includes/core/um-filters-profile.php @@ -79,7 +79,7 @@ add_filter( 'the_title', 'um_dynamic_user_profile_title', 100000, 2 ); * @return string|false The canonical URL, or false if current URL is canonical. */ function um_get_canonical_url( $canonical_url, $post ) { - if ( UM()->config()->permalinks['user'] == $post->ID || (UM()->external_integrations()->is_wpml_active() && UM()->config()->permalinks['user'] == wpml_object_id_filter( $post->ID, 'page', true, icl_get_default_language() )) ) { + if ( UM()->config()->permalinks['user'] == $post->ID || ( UM()->external_integrations()->is_wpml_active() && UM()->config()->permalinks['user'] == wpml_object_id_filter( $post->ID, 'page', true, icl_get_default_language() ) ) ) { /** * UM hook diff --git a/readme.txt b/readme.txt index 6045e744..5cf6ffc1 100644 --- a/readme.txt +++ b/readme.txt @@ -155,11 +155,15 @@ The plugin works with popular caching plugins by automatically excluding Ultimat * To learn more about version 2.1 please see this [docs](https://docs.ultimatemember.com/article/1512-upgrade-2-1-0) * UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin -= 2.2.6: October xx, 2021 = += 2.2.6: December xx, 2021 = * Bugfixes: - - Fixed: "Clear All" button for the filters with "&" symbol in the label + - Fixed: "Clear All" button for the filters with "&" symbol in the label. + - Fixed: Uninstall process when delete UM data. Avoid the issue when 3rd-party pages that had been selected as UM page are removed on UM uninstall. + - Fixed: Header meta for the Twitter Card. If the user has twitter field filled then will be filled by this value. + - Fixed: Member directory a slider filter's label displaying. It uses the filed label for now. + - Fixed: Some typos in the fields' labels. = 2.2.5: September 22, 2021 = diff --git a/ultimate-member.php b/ultimate-member.php index be2018a7..52b4c41a 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ Plugin Name: Ultimate Member Plugin URI: http://ultimatemember.com/ Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress -Version: 2.2.6-alpha +Version: 2.2.6 Author: Ultimate Member Author URI: http://ultimatemember.com/ Text Domain: ultimate-member