diff --git a/assets/js/um-profile.js b/assets/js/um-profile.js index 8f0f3381..5a95598d 100644 --- a/assets/js/um-profile.js +++ b/assets/js/um-profile.js @@ -88,41 +88,22 @@ jQuery(document).ready(function() { return false; }); - /*function um_update_bio_countdown() { - // - jQuery(this) - if ( typeof jQuery('textarea[id="um-meta-bio"]').val() !== 'undefined' ){ - var um_bio_limit = jQuery('textarea[id="um-meta-bio"]').attr( "data-character-limit" ); - var remaining = um_bio_limit - jQuery('textarea[id="um-meta-bio"]').val().length; - jQuery('span.um-meta-bio-character span.um-bio-limit').text( remaining ); - if ( remaining < 5 ) { - jQuery('span.um-meta-bio-character').css('color','red'); - } else { - jQuery('span.um-meta-bio-character').css('color',''); - } - } - }*/ - - //um_update_bio_countdown(); - //jQuery( 'textarea[id="um-meta-bio"]' ).on('change', um_update_bio_countdown ).keyup( um_update_bio_countdown ).trigger('change'); - // Bio characters limit jQuery( document.body ).on( 'change keyup', '#um-meta-bio', function() { if ( typeof jQuery(this).val() !== 'undefined' ) { - var um_bio_limit = jQuery(this).data( 'character-limit' ); - var bio_html = jQuery(this).attr('data-html'); - if ( parseInt( bio_html ) === 1 ){ - var remaining = um_bio_limit - jQuery(this).val().replace(/(<([^>]+)>)/ig,'').length; - } else { - var remaining = um_bio_limit - jQuery(this).val().length; + let um_bio_limit = jQuery(this).data( 'character-limit' ); + let bio_html = jQuery(this).data( 'html' ); + + let remaining = um_bio_limit - jQuery(this).val().length; + if ( parseInt( bio_html ) === 1 ) { + remaining = um_bio_limit - jQuery(this).val().replace(/(<([^>]+)>)/ig,'').length; } + remaining = remaining < 0 ? 0 : remaining; + jQuery( 'span.um-meta-bio-character span.um-bio-limit' ).text( remaining ); - if ( remaining < 5 ) { - jQuery('span.um-meta-bio-character').css('color','red'); - } else { - jQuery('span.um-meta-bio-character').css('color',''); - } + let color = remaining < 5 ? 'red' : ''; + jQuery('span.um-meta-bio-character').css( 'color', color ); } }); jQuery( '#um-meta-bio' ).trigger('change'); @@ -158,5 +139,4 @@ jQuery(document).ready(function() { jQuery( '.um-profile-nav a' ).on( 'touchend', function(e) { jQuery( e.currentTarget).trigger( "click" ); }); - }); diff --git a/assets/js/um-profile.min.js b/assets/js/um-profile.min.js index f965ed66..557d45b8 100644 --- a/assets/js/um-profile.min.js +++ b/assets/js/um-profile.min.js @@ -1 +1 @@ -jQuery(document).ready(function(){jQuery(".um-profile.um-viewing .um-profile-body .um-row").each(function(){var e=jQuery(this);0==e.find(".um-field").length&&(e.prev(".um-row-heading").remove(),e.remove())}),jQuery(".um-profile.um-viewing .um-profile-body").length&&0==jQuery(".um-profile.um-viewing .um-profile-body").find(".um-field").length&&(jQuery(".um-profile.um-viewing .um-profile-body").find(".um-row-heading,.um-row").remove(),jQuery(".um-profile-note").show()),jQuery(document.body).on("click",".um-profile-save",function(e){return e.preventDefault(),jQuery(this).parents(".um").find("form").trigger("submit"),!1}),jQuery(document.body).on("click",".um-profile-edit-a",function(e){jQuery(this).addClass("active")}),jQuery(document.body).on("click",".um-cover a.um-cover-add, .um-photo a",function(e){e.preventDefault()}),jQuery(document.body).on("click",".um-photo-modal",function(e){e.preventDefault();e=jQuery(this).attr("data-src");return um_new_modal("um_view_photo","fit",!0,e),!1}),jQuery(document.body).on("click",".um-reset-profile-photo",function(e){return jQuery(".um-profile-photo-img img").attr("src",jQuery(this).attr("data-default_src")),user_id=jQuery(this).attr("data-user_id"),metakey="profile_photo",UM.dropdown.hideAll(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_delete_profile_photo",metakey:metakey,user_id:user_id,nonce:um_scripts.nonce}}),jQuery(this).parents("li").hide(),!1}),jQuery(document.body).on("click",".um-reset-cover-photo",function(e){var r=jQuery(this);return jQuery(".um-cover-overlay").hide(),jQuery(".um-cover-e").html(''),um_responsive(),user_id=jQuery(this).attr("data-user_id"),metakey="cover_photo",jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_delete_cover_photo",metakey:metakey,user_id:user_id,nonce:um_scripts.nonce},success:function(e){r.hide()}}),UM.dropdown.hideAll(),!1}),jQuery(document.body).on("change keyup","#um-meta-bio",function(){var e;void 0!==jQuery(this).val()&&(e=jQuery(this).data("character-limit")-jQuery(this).val().length,jQuery("span.um-meta-bio-character span.um-bio-limit").text(e),e<5?jQuery("span.um-meta-bio-character").css("color","red"):jQuery("span.um-meta-bio-character").css("color",""))}),jQuery("#um-meta-bio").trigger("change"),jQuery(".um-profile form").each(function(){let r=jQuery(this).data("description_key");jQuery(this).find('textarea[name="'+r+'"]').length&&jQuery(document.body).on("change input",'textarea[name="'+r+'"]',function(e){jQuery(this).parents("form").find('textarea[name="'+r+'"]').each(function(){jQuery(this).val(e.currentTarget.value),jQuery("#um-meta-bio")[0]!==e.currentTarget&&jQuery("#um-meta-bio")[0]===jQuery(this)[0]&&jQuery(this).trigger("change")})})}),jQuery(".um-profile-edit a.um_delete-item").on("click",function(e){if(e.preventDefault(),!confirm(wp.i18n.__("Are you sure that you want to delete this user?","ultimate-member")))return!1}),jQuery(".um-profile-nav a").on("touchend",function(e){jQuery(e.currentTarget).trigger("click")})}); \ No newline at end of file +jQuery(document).ready(function(){jQuery(".um-profile.um-viewing .um-profile-body .um-row").each(function(){var e=jQuery(this);0==e.find(".um-field").length&&(e.prev(".um-row-heading").remove(),e.remove())}),jQuery(".um-profile.um-viewing .um-profile-body").length&&0==jQuery(".um-profile.um-viewing .um-profile-body").find(".um-field").length&&(jQuery(".um-profile.um-viewing .um-profile-body").find(".um-row-heading,.um-row").remove(),jQuery(".um-profile-note").show()),jQuery(document.body).on("click",".um-profile-save",function(e){return e.preventDefault(),jQuery(this).parents(".um").find("form").trigger("submit"),!1}),jQuery(document.body).on("click",".um-profile-edit-a",function(e){jQuery(this).addClass("active")}),jQuery(document.body).on("click",".um-cover a.um-cover-add, .um-photo a",function(e){e.preventDefault()}),jQuery(document.body).on("click",".um-photo-modal",function(e){e.preventDefault();e=jQuery(this).attr("data-src");return um_new_modal("um_view_photo","fit",!0,e),!1}),jQuery(document.body).on("click",".um-reset-profile-photo",function(e){return jQuery(".um-profile-photo-img img").attr("src",jQuery(this).attr("data-default_src")),user_id=jQuery(this).attr("data-user_id"),metakey="profile_photo",UM.dropdown.hideAll(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_delete_profile_photo",metakey:metakey,user_id:user_id,nonce:um_scripts.nonce}}),jQuery(this).parents("li").hide(),!1}),jQuery(document.body).on("click",".um-reset-cover-photo",function(e){var t=jQuery(this);return jQuery(".um-cover-overlay").hide(),jQuery(".um-cover-e").html(''),um_responsive(),user_id=jQuery(this).attr("data-user_id"),metakey="cover_photo",jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_delete_cover_photo",metakey:metakey,user_id:user_id,nonce:um_scripts.nonce},success:function(e){t.hide()}}),UM.dropdown.hideAll(),!1}),jQuery(document.body).on("change keyup","#um-meta-bio",function(){if(void 0!==jQuery(this).val()){var t=jQuery(this).data("character-limit"),r=jQuery(this).data("html");let e=t-jQuery(this).val().length;e=(e=1===parseInt(r)?t-jQuery(this).val().replace(/(<([^>]+)>)/gi,"").length:e)<0?0:e,jQuery("span.um-meta-bio-character span.um-bio-limit").text(e);r=e<5?"red":"";jQuery("span.um-meta-bio-character").css("color",r)}}),jQuery("#um-meta-bio").trigger("change"),jQuery(".um-profile form").each(function(){let t=jQuery(this).data("description_key");jQuery(this).find('textarea[name="'+t+'"]').length&&jQuery(document.body).on("change input",'textarea[name="'+t+'"]',function(e){jQuery(this).parents("form").find('textarea[name="'+t+'"]').each(function(){jQuery(this).val(e.currentTarget.value),jQuery("#um-meta-bio")[0]!==e.currentTarget&&jQuery("#um-meta-bio")[0]===jQuery(this)[0]&&jQuery(this).trigger("change")})})}),jQuery(".um-profile-edit a.um_delete-item").on("click",function(e){if(e.preventDefault(),!confirm(wp.i18n.__("Are you sure that you want to delete this user?","ultimate-member")))return!1}),jQuery(".um-profile-nav a").on("touchend",function(e){jQuery(e.currentTarget).trigger("click")})}); \ No newline at end of file diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 1b016584..6668d2ba 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -908,11 +908,11 @@ if ( ! class_exists( 'um\core\Account' ) ) { $classes .= ' um-in-admin'; } - if ( UM()->fields()->editing == true ) { + if ( true === UM()->fields()->editing ) { $classes .= ' um-editing'; } - if ( UM()->fields()->viewing == true ) { + if ( true === UM()->fields()->viewing ) { $classes .= ' um-viewing'; } diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 71f3384e..c4f61134 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -625,11 +625,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $output = null; $output .= '
'; - if ( isset( $data['icon'] ) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || $this->viewing == true ) ) { + if ( isset( $data['icon'] ) && $data['icon'] != '' && isset( $this->field_icons ) && $this->field_icons != 'off' && ( $this->field_icons == 'label' || true === $this->viewing ) ) { $output .= '
'; } - if ( $this->viewing == true ) { + if ( true === $this->viewing ) { /** * UM hook * @@ -705,7 +705,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $output .= '' . __( $label, 'ultimate-member' ) . ''; - if ( ! empty( $data['help'] ) && $this->viewing == false && ! strstr( $key, 'confirm_user_pass' ) ) { + if ( ! empty( $data['help'] ) && false === $this->viewing && ! strstr( $key, 'confirm_user_pass' ) ) { if ( ! UM()->mobile()->isMobile() ) { if ( false === $this->disable_tooltips ) { $output .= ''; @@ -836,7 +836,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { return stripslashes_deep( UM()->form()->post_form[ $key ] ); - } elseif ( um_user( $key ) && $this->editing == true ) { + } elseif ( um_user( $key ) && true === $this->editing ) { //show empty value for password fields if ( strstr( $key, 'user_pass' ) || $type == 'password' ) { @@ -889,7 +889,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { */ $value = apply_filters( "um_edit_{$type}_field_value", $value, $key ); - } elseif ( ( um_user( $key ) || isset( $data['show_anyway'] ) ) && $this->viewing == true ) { + } elseif ( ( um_user( $key ) || isset( $data['show_anyway'] ) ) && true === $this->viewing ) { return um_filtered_value( $key, $data ); @@ -993,7 +993,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } // Default Value for Registration Form and Profile Form editing - if ( ! isset( $value ) && ( $this->set_mode == 'register' || $this->editing == true ) ) { + if ( ! isset( $value ) && ( $this->set_mode == 'register' || true === $this->editing ) ) { /** * UM hook @@ -1173,7 +1173,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { */ $data = apply_filters( 'um_is_selected_filter_data', $data, $key, $field_value ); - if ( ! $this->editing || 'custom' == $this->set_mode ) { + if ( false === $this->editing || 'custom' === $this->set_mode ) { // show default on register screen if there is default if ( isset( $data['default'] ) ) { @@ -1258,7 +1258,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } } else { - if ( $this->editing && 'custom' !== $this->set_mode ) { + if ( true === $this->editing && 'custom' !== $this->set_mode ) { if ( um_user( $key ) ) { $um_user_value = um_user( $key ); @@ -1611,7 +1611,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $array['default'] = null; } - if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && ! $this->viewing ) { + if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && false === $this->viewing ) { $array['conditional'] = ''; foreach ( $array['conditions'] as $cond_id => $cond ) { @@ -2178,7 +2178,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } } - if ( ! empty( $this->editing ) && 'profile' === $this->set_mode ) { + if ( true === $this->editing && 'profile' === $this->set_mode ) { if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) { if ( empty( $data['editable'] ) ) { $disabled = ' disabled="disabled" '; @@ -2716,10 +2716,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $field_name = $key; $field_value = $this->field_value( $key, $default, $data ); + $bio_key = UM()->profile()->get_show_bio_key( $this->global_args ); + $output .= '
'; - if ( isset( $data['html'] ) && 0 !== $data['html'] && 'description' !== $key ) { - + if ( ! empty( $data['html'] ) && $bio_key !== $key ) { $textarea_settings = array( 'media_buttons' => false, 'wpautop' => false, @@ -2761,24 +2762,29 @@ if ( ! class_exists( 'um\core\Fields' ) ) { // echo the editor to the buffer wp_editor( $field_value, $key, $textarea_settings ); - // add the contents of the buffer to the output variable + // Add the contents of the buffer to the output variable. $output .= ob_get_clean(); $output .= '
' . esc_html( $placeholder ) . ''; } else { + // User 'description' field uses ` - - - + if ( $show_bio ) { + $description_key = UM()->profile()->get_show_bio_key( $args ); - fields()->is_error( $description_key ) ) { - echo UM()->fields()->field_error( UM()->fields()->show_error( $description_key ), true ); - } ?> + if ( true === UM()->fields()->viewing && um_user( $description_key ) ) { + ?> +
+ + if ( $bio_html ) { + echo wp_kses_post( nl2br( make_clickable( wpautop( $description ) ) ) ); + } else { + echo nl2br( esc_html( $description ) ); + } + ?> +
+ fields()->editing ) { + if ( ! empty( $args['custom_fields'][ $description_key ] ) ) { + if ( ! empty( $args['custom_fields'][ $description_key ]['html'] ) && $bio_html ) { + $description_value = UM()->fields()->field_value( $description_key ); + } else { + $description_value = wp_strip_all_tags( UM()->fields()->field_value( $description_key ) ); + } + } else { + if ( $bio_html ) { + $description_value = UM()->fields()->field_value( $description_key ); + } else { + $description_value = wp_strip_all_tags( UM()->fields()->field_value( $description_key ) ); + } + } - + if ( ! empty( $args['custom_fields'][ $description_key ]['max_chars'] ) ) { + $limit = $args['custom_fields'][ $description_key ]['max_chars']; + } else { + $limit = UM()->options()->get( 'profile_bio_maxchars' ); + } + ?> + +
+ + + + + fields()->is_error( $description_key ) ) { + echo UM()->fields()->field_error( UM()->fields()->show_error( $description_key ), true ); + } + ?> +
+
@@ -1306,8 +1326,8 @@ function um_profile_header( $args ) { * } * ?> */ - do_action( 'um_after_header_meta', um_user( 'ID' ), $args ); ?> - + do_action( 'um_after_header_meta', um_user( 'ID' ), $args ); + ?>
@@ -1354,7 +1374,7 @@ function um_pre_profile_shortcode( $args ) { return; } - if ( UM()->fields()->editing ) { + if ( true === UM()->fields()->editing ) { if ( um_get_requested_user() ) { if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) { um_redirect_home( um_get_requested_user(), um_is_myprofile() ); @@ -1362,7 +1382,7 @@ function um_pre_profile_shortcode( $args ) { um_fetch_user( um_get_requested_user() ); } } else { - UM()->fields()->viewing = 1; + UM()->fields()->viewing = true; if ( um_get_requested_user() ) { if ( ! um_is_myprofile() && ! um_can_view_profile( um_get_requested_user() ) ) { @@ -1400,7 +1420,7 @@ function um_add_edit_icon( $args ) { // do not proceed if user cannot edit - if ( UM()->fields()->editing == true ) { ?> + if ( true === UM()->fields()->editing ) { ?>
@@ -1501,7 +1521,7 @@ add_action( 'um_pre_header_editprofile', 'um_add_edit_icon' ); * @param $args */ function um_add_profile_fields( $args ) { - if ( UM()->fields()->editing == true ) { + if ( true === UM()->fields()->editing ) { echo UM()->fields()->display( 'profile', $args ); @@ -1569,7 +1589,7 @@ function um_add_submit_button_to_profile( $args ) { } // only when editing - if ( UM()->fields()->editing == false ) { + if ( false === UM()->fields()->editing ) { return; } diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index 32ce1b96..b4b7e41d 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -248,16 +248,18 @@ function um_profile_field_filter_hook__textarea( $value, $data ) { if ( ! $value ) { return ''; } - if ( isset( $data['html'] ) && $data['html'] == 1 ) { + if ( ! empty( $data['html'] ) ) { return $value; } + $description_key = UM()->profile()->get_show_bio_key( UM()->fields()->global_args ); + $value = wp_kses( $value, 'strip' ); $value = html_entity_decode( $value ); - $value = preg_replace('$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' $1 ', $value." "); - $value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '$1 ', $value." "); + $value = preg_replace( '$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' $1 ', $value . ' ' ); + $value = preg_replace( '$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '$1 ', $value . ' ' ); - if ( ! ( isset( $data['metakey'] ) && 'description' === $data['metakey'] ) ) { + if ( ! ( isset( $data['metakey'] ) && $description_key === $data['metakey'] ) ) { $value = wpautop( $value ); } diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index 5aac9dd3..7f82e9ff 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -1662,7 +1662,7 @@ function um_is_user_himself() { function um_can_edit_field( $data ) { $can_edit = true; - if ( ! empty( UM()->fields()->editing ) && isset( UM()->fields()->set_mode ) && UM()->fields()->set_mode == 'profile' ) { + if ( true === UM()->fields()->editing && isset( UM()->fields()->set_mode ) && UM()->fields()->set_mode == 'profile' ) { if ( ! is_user_logged_in() ) { $can_edit = false; } else {