- unified `UM()->fields()->editing` and `UM()->fields()->viewing` to bool variables use true|false in conditions to make `===` or `!==` comparing;
This commit is contained in:
Mykyta Synelnikov
2023-08-15 03:49:13 +03:00
parent 766653a360
commit bfef1f9dc7
11 changed files with 222 additions and 161 deletions
+10 -30
View File
@@ -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" );
});
});
+1 -1
View File
@@ -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('<a href="javascript:void(0);" class="um-cover-add" style="height: 370px;"><span class="um-cover-add-i"><i class="um-icon-plus um-tip-n" original-title="Upload a cover photo"></i></span></a>'),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")})});
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('<a href="javascript:void(0);" class="um-cover-add" style="height: 370px;"><span class="um-cover-add-i"><i class="um-icon-plus um-tip-n" original-title="Upload a cover photo"></i></span></a>'),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")})});
+2 -2
View File
@@ -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';
}
+46 -23
View File
@@ -625,11 +625,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$output = null;
$output .= '<div class="um-field-label">';
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 .= '<div class="um-field-label-icon"><i class="' . esc_attr( $data['icon'] ) . '" aria-label="' . esc_attr( $label ) . '"></i></div>';
}
if ( $this->viewing == true ) {
if ( true === $this->viewing ) {
/**
* UM hook
*
@@ -705,7 +705,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$output .= '<label' . $for_attr . '>' . __( $label, 'ultimate-member' ) . '</label>';
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 .= '<span class="um-tip um-tip-' . ( is_rtl() ? 'e' : 'w' ) . '" title="' . esc_attr__( $data['help'], 'ultimate-member' ) . '"><i class="um-icon-help-circled"></i></span>';
@@ -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 .= '<div class="um-field-area">';
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 .= '<br /><span class="description">' . esc_html( $placeholder ) . '</span>';
} else {
// User 'description' field uses `<textarea>` block everytime.
$textarea_field_value = '';
if ( ! empty( $field_value ) ) {
$profile_custom_settings = get_post_meta( $this->global_args['form_id'], '_um_profile_use_custom_settings', true );
if ( 1 === $profile_custom_settings ) {
$bio_html = get_post_meta( $this->global_args['form_id'], '_um_profile_show_bio', true );
} else {
if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
$bio_html = 1;
$bio_html = false;
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
if ( 'profile' === $this->global_args['mode'] ) {
if ( ! empty( $this->global_args['use_custom_settings'] ) ) {
if ( ! empty( $this->global_args['show_bio'] ) ) {
$bio_html = ! empty( $global_setting );
}
} else {
$bio_html = 0;
$global_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( ! empty( $global_show_bio ) ) {
$bio_html = ! empty( $global_setting );
}
}
}
if ( 1 === (int) $bio_html && array_key_exists( 'html', $data ) && 1 === (int) $data['html'] ) {
if ( true === $bio_html && ! empty( $data['html'] ) ) {
$textarea_field_value = $field_value;
} else {
$textarea_field_value = wp_strip_all_tags( $field_value );
@@ -4270,8 +4276,25 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
if ( ! empty( $res ) ) {
$res = stripslashes( $res );
}
if ( 'description' === $data['metakey'] ) {
if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
$bio_key = UM()->profile()->get_show_bio_key( $this->global_args );
if ( $bio_key === $data['metakey'] ) {
$bio_html = false;
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
if ( 'profile' === $this->global_args['mode'] ) {
if ( ! empty( $this->global_args['use_custom_settings'] ) ) {
if ( ! empty( $this->global_args['show_bio'] ) ) {
$bio_html = ! empty( $global_setting );
}
} else {
$global_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( ! empty( $global_show_bio ) ) {
$bio_html = ! empty( $global_setting );
}
}
}
if ( true === $bio_html && ! empty( $data['html'] ) ) {
$res = make_clickable( wpautop( wp_kses_post( $res ) ) );
} else {
$res = esc_html( $res );
+2 -2
View File
@@ -75,11 +75,11 @@ if ( ! class_exists( 'um\core\Password' ) ) {
$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';
}
+17 -6
View File
@@ -404,14 +404,13 @@ if ( ! class_exists( 'um\core\Profile' ) ) {
return $this->active_subnav;
}
/**
* Show meta in profile
*
* @param array $array Meta Array
* @return string
*/
function show_meta( $array ) {
public function show_meta( $array, $args ) {
$output = '';
$fields_without_metakey = UM()->builtin()->get_fields_without_metakey();
@@ -427,16 +426,28 @@ if ( ! class_exists( 'um\core\Profile' ) ) {
$data['in_profile_meta'] = true;
$value = um_filtered_value( $key, $data );
if ( 'description' === $key ) {
if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
$res = make_clickable( wpautop( wp_kses_post( $value ) ) );
$description_key = UM()->profile()->get_show_bio_key( $args );
if ( $description_key === $key ) {
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
$bio_html = ! empty( $global_setting );
if ( ! empty( $args['custom_fields'][ $description_key ] ) ) {
if ( empty( $args['custom_fields'][ $description_key ]['html'] ) ) {
$bio_html = false;
}
}
if ( $bio_html ) {
$res = wp_kses_post( make_clickable( wpautop( $value ) ) );
} else {
$res = esc_html( $value );
}
$value = nl2br( $res );
}
if ( ! $value && ( ! array_key_exists( 'type', $data ) || ! in_array( $data['type'], $fields_without_metakey ) ) ) {
if ( ! $value && ( ! array_key_exists( 'type', $data ) || ! in_array( $data['type'], $fields_without_metakey, true ) ) ) {
continue;
}
+2 -2
View File
@@ -355,11 +355,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$classes .= ' um-err';
}
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';
}
+54 -29
View File
@@ -573,10 +573,10 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
}
if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) {
if ( array_key_exists( 'html', $array ) && 1 === (int) $array['html'] ) {
if ( ! empty( $array['html'] ) ) {
// Count words without html tags when HTML is enabled.
$text_value = wp_strip_all_tags( $submitted_data[ $key ] );
} else {
// count words without html tags
$text_value = $submitted_data[ $key ];
}
@@ -599,7 +599,14 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
}
if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) {
if ( $submitted_data[ $key ] && mb_strlen( $submitted_data[ $key ] ) > $array['max_chars'] ) {
if ( ! empty( $array['html'] ) ) {
// Count words without html tags when HTML is enabled.
$text_value = wp_strip_all_tags( $submitted_data[ $key ] );
} else {
$text_value = $submitted_data[ $key ];
}
if ( ! empty( $text_value ) && mb_strlen( $text_value ) > $array['max_chars'] ) {
if ( empty( $array['label'] ) ) {
// translators: %s: max chars.
UM()->form()->add_error( $key, sprintf( __( 'This field must contain less than %s characters', 'ultimate-member' ), $array['max_chars'] ) );
@@ -610,9 +617,9 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
}
}
if ( isset( $array['type'] ) && $array['type'] == 'textarea' && UM()->profile()->get_show_bio_key( $submitted_data ) !== $key ) {
if ( ! isset( $array['html'] ) || $array['html'] == 0 ) {
if ( wp_strip_all_tags( $submitted_data[ $key ] ) != trim( $submitted_data[ $key ] ) ) {
if ( isset( $array['type'] ) && 'textarea' === $array['type'] && UM()->profile()->get_show_bio_key( $submitted_data ) !== $key ) {
if ( empty( $array['html'] ) ) {
if ( wp_strip_all_tags( $submitted_data[ $key ] ) !== trim( $submitted_data[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'You can not use HTML tags here', 'ultimate-member' ) );
}
}
@@ -673,37 +680,55 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
}
}
$description_key = UM()->profile()->get_show_bio_key( $array );
if ( isset( $submitted_data['description'] ) && $description_key === $array['metakey'] ) {
$max_chars = UM()->options()->get( 'profile_bio_maxchars' );
$profile_show_bio = UM()->options()->get( 'profile_show_bio' );
$description_key = UM()->profile()->get_show_bio_key( $array );
if ( array_key_exists( $description_key, $submitted_data['submitted'] ) ) {
if ( array_key_exists( 'max_chars', $array ) && ! empty( $array['max_chars'] ) ) {
$max_chars = $array['max_chars'];
$description_key = UM()->profile()->get_show_bio_key( $form_data );
if ( isset( $form_data['mode'] ) && 'profile' === $form_data['mode'] && $description_key === $key ) {
$show_bio = false;
$bio_html = false;
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
if ( ! empty( $form_data['use_custom_settings'] ) ) {
if ( ! empty( $form_data['show_bio'] ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
} else {
$global_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( ! empty( $global_show_bio ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
}
if ( array_key_exists( 'html', $array ) && 1 === (int) $array['html'] && 1 === (int) UM()->options()->get( 'profile_show_html_bio' ) ) {
if ( $show_bio ) {
$max_chars = UM()->options()->get( 'profile_bio_maxchars' );
}
$field_exists = false;
if ( ! empty( $form_data['custom_fields'] ) ) {
$custom_fields = maybe_unserialize( $form_data['custom_fields'] );
if ( array_key_exists( $description_key, $custom_fields ) ) {
$field_exists = true;
if ( ! empty( $array['max_chars'] ) ) {
$max_chars = $array['max_chars'];
}
if ( ! empty( $array['html'] ) && $bio_html ) {
$description_value = wp_strip_all_tags( $submitted_data[ $description_key ] );
} else {
$description_value = $submitted_data[ $description_key ];
}
}
}
if ( ! $field_exists && $show_bio ) {
if ( $bio_html ) {
$description_value = wp_strip_all_tags( $submitted_data[ $description_key ] );
} else {
$description_value = $submitted_data[ $description_key ];
}
} else {
if ( ! UM()->options()->get( 'profile_show_html_bio' ) ) {
$description_value = $submitted_data['description'];
} else {
$description_value = wp_strip_all_tags( $submitted_data['description'] );
}
}
if ( $profile_show_bio ) {
if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $description_value ) ) > $max_chars && $max_chars ) {
// translators: %s: max chars.
UM()->form()->add_error( 'description', sprintf( __( 'Your user description must contain less than %s characters', 'ultimate-member' ), $max_chars ) );
}
if ( ! empty( $description_value ) && ! empty( $max_chars ) && mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $description_value ) ) > $max_chars ) {
// translators: %s: max chars.
UM()->form()->add_error( $description_key, sprintf( __( 'Your user description must contain less than %s characters', 'ultimate-member' ), $max_chars ) );
}
}
+81 -61
View File
@@ -590,7 +590,7 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 );
* @param $args
*/
function um_editing_user_id_input( $args ) {
if ( UM()->fields()->editing == 1 && UM()->fields()->set_mode == 'profile' && UM()->user()->target_id ) { ?>
if ( true === UM()->fields()->editing && 'profile' === UM()->fields()->set_mode && UM()->user()->target_id ) { ?>
<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( UM()->user()->target_id ); ?>" />
<input type="hidden" name="profile_nonce" id="profile_nonce" value="<?php echo esc_attr( UM()->form()->nonce ); ?>" />
@@ -838,7 +838,7 @@ function um_profile_header_cover_area( $args ) {
* ?>
*/
do_action( 'um_cover_area_content', um_profile_id() );
if ( UM()->fields()->editing ) {
if ( true === UM()->fields()->editing ) {
$hide_remove = um_user( 'cover_photo' ) ? false : ' style="display:none;"';
@@ -1075,7 +1075,7 @@ function um_profile_header( $args ) {
UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
} elseif ( UM()->fields()->editing == true ) {
} elseif ( true === UM()->fields()->editing ) {
$items = array(
'<a href="javascript:void(0);" class="um-manual-trigger" data-parent=".um-profile-photo" data-child=".um-btn-auto-width">' . __( 'Change photo', 'ultimate-member' ) . '</a>',
@@ -1217,70 +1217,90 @@ function um_profile_header( $args ) {
<?php if ( ! empty( $args['metafields'] ) ) { ?>
<div class="um-meta">
<?php echo UM()->profile()->show_meta( $args['metafields'] ); ?>
<?php echo UM()->profile()->show_meta( $args['metafields'], $args ); ?>
</div>
<?php }
<?php
}
$description_key = UM()->profile()->get_show_bio_key( $args );
if ( UM()->fields()->viewing == true && um_user( $description_key ) && $args['show_bio'] ) { ?>
<div class="um-meta-text">
<?php $description = get_user_meta( um_user( 'ID' ), $description_key, true );
if ( UM()->options()->get( 'profile_show_html_bio' ) ) {
echo make_clickable( wpautop( wp_kses_post( $description ) ) );
} else {
echo esc_html( $description );
} ?>
</div>
<?php } elseif ( UM()->fields()->editing == true && $args['show_bio'] ) {
if ( ! empty( $args['custom_fields']['description'] ) ) {
if ( array_key_exists( 'html', $args['custom_fields']['description'] ) && 1 === (int) $args['custom_fields']['description']['html'] && 1 === (int) UM()->options()->get( 'profile_show_html_bio' ) ) {
$description_value = UM()->fields()->field_value( $description_key );
} else {
$description_value = wp_strip_all_tags( UM()->fields()->field_value( $description_key ) );
}
} else {
if ( 1 === (int) UM()->options()->get( 'profile_show_html_bio' ) ) {
$description_value = UM()->fields()->field_value( $description_key );
} else {
$description_value = wp_strip_all_tags( UM()->fields()->field_value( $description_key ) );
}
$show_bio = false;
$bio_html = false;
$global_setting = UM()->options()->get( 'profile_show_html_bio' );
if ( ! empty( $args['use_custom_settings'] ) ) {
if ( ! empty( $args['show_bio'] ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
if ( array_key_exists( 'max_chars', $args['custom_fields']['description'] ) ) {
$limit = $args['custom_fields']['description']['max_chars'];
} else {
$limit = UM()->options()->get( 'profile_bio_maxchars' );
} else {
$global_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( ! empty( $global_show_bio ) ) {
$show_bio = true;
$bio_html = ! empty( $global_setting );
}
?>
}
<div class="um-meta-text">
<textarea id="um-meta-bio"
data-html="<?php echo esc_attr( UM()->options()->get( 'profile_show_html_bio' ) ); ?>"
data-character-limit="<?php echo esc_attr( $limit ); ?>"
placeholder="<?php esc_attr_e( 'Tell us a bit about yourself...', 'ultimate-member' ); ?>"
name="<?php echo esc_attr( $description_key ); ?>"><?php echo $description_value; ?></textarea>
<span class="um-meta-bio-character um-right">
<span class="um-bio-limit"><?php echo esc_html( $limit ); ?></span>
</span>
if ( $show_bio ) {
$description_key = UM()->profile()->get_show_bio_key( $args );
<?php if ( UM()->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 ) ) {
?>
<div class="um-meta-text">
<?php
$description = get_user_meta( um_user( 'ID' ), $description_key, true );
</div>
if ( $bio_html ) {
echo wp_kses_post( nl2br( make_clickable( wpautop( $description ) ) ) );
} else {
echo nl2br( esc_html( $description ) );
}
?>
</div>
<?php
} elseif ( true === UM()->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 ) );
}
}
<?php } ?>
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' );
}
?>
<div class="um-meta-text">
<textarea id="um-meta-bio" data-html="<?php echo esc_attr( $bio_html ); ?>"
data-character-limit="<?php echo esc_attr( $limit ); ?>"
placeholder="<?php esc_attr_e( 'Tell us a bit about yourself...', 'ultimate-member' ); ?>"
name="<?php echo esc_attr( $description_key ); ?>"><?php echo esc_textarea( $description_value ); ?></textarea>
<span class="um-meta-bio-character um-right">
<span class="um-bio-limit"><?php echo esc_html( $limit ); ?></span>
</span>
<?php
if ( UM()->fields()->is_error( $description_key ) ) {
echo UM()->fields()->field_error( UM()->fields()->show_error( $description_key ), true );
}
?>
</div>
<?php
}
}
?>
<div class="um-profile-status <?php echo esc_attr( um_user( 'account_status' ) ); ?>">
<span>
<?php
// translators: %s: profile status.
printf( __( 'This user account status is %s', 'ultimate-member' ), um_user( 'account_status_name' ) );
echo esc_html( sprintf( __( 'This user account status is %s', 'ultimate-member' ), um_user( 'account_status_name' ) ) );
?>
</span>
</div>
@@ -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 );
?>
</div>
<div class="um-clear"></div>
@@ -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 ) { ?>
<div class="um-profile-edit um-profile-headericon">
<a href="javascript:void(0);" class="um-profile-edit-a um-profile-save"><i class="um-faicon-check"></i></a>
@@ -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;
}
+6 -4
View File
@@ -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', ' <a href="$1" target="_blank">$1</a> ', $value." ");
$value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '<a target="_blank" href="http://$1">$1</a> ', $value." ");
$value = preg_replace( '$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' <a href="$1" target="_blank">$1</a> ', $value . ' ' );
$value = preg_replace( '$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '<a target="_blank" href="http://$1">$1</a> ', $value . ' ' );
if ( ! ( isset( $data['metakey'] ) && 'description' === $data['metakey'] ) ) {
if ( ! ( isset( $data['metakey'] ) && $description_key === $data['metakey'] ) ) {
$value = wpautop( $value );
}
+1 -1
View File
@@ -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 {