From 9cb4d5fa8fb561266e3ffee041628efe5ac8b639 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 27 Jul 2023 14:39:08 +0300 Subject: [PATCH 1/5] - fix count of words and letters for the bio field --- assets/js/um-profile.js | 7 +++- includes/core/um-actions-form.php | 54 ++++++++++++++++++++-------- includes/core/um-actions-profile.php | 1 + 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/assets/js/um-profile.js b/assets/js/um-profile.js index 5929df97..8f0f3381 100644 --- a/assets/js/um-profile.js +++ b/assets/js/um-profile.js @@ -110,7 +110,12 @@ jQuery(document).ready(function() { 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 remaining = um_bio_limit - jQuery(this).val().length; + 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; + } jQuery( 'span.um-meta-bio-character span.um-bio-limit' ).text( remaining ); if ( remaining < 5 ) { diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 0d847b2e..3222faa1 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -573,9 +573,14 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { } if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) { - // count words without html tags - $without_tags = wp_strip_all_tags( $submitted_data[ $key ] ); - if ( str_word_count( $without_tags, 0, 'éèàôù' ) > $array['max_words'] ) { + if ( array_key_exists( 'html', $array ) && 1 === (int) $array['html'] ) { + $text_value = wp_strip_all_tags( $submitted_data[ $key ] ); + } else { + // count words without html tags + $text_value = $submitted_data[ $key ]; + } + + if ( str_word_count( $text_value, 0, '0123456789éèàôù' ) > $array['max_words'] ) { // translators: %s: max words. UM()->form()->add_error( $key, sprintf( __( 'You are only allowed to enter a maximum of %s words', 'ultimate-member' ), $array['max_words'] ) ); } @@ -668,6 +673,23 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { } } + if ( isset( $submitted_data['description'] ) ) { + $max_chars = UM()->options()->get( 'profile_bio_maxchars' ); + $profile_show_bio = UM()->options()->get( 'profile_show_bio' ); + 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( $array['validate'] ) ) { continue; } @@ -933,17 +955,21 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { } - if ( isset( $submitted_data['description'] ) ) { - $max_chars = UM()->options()->get( 'profile_bio_maxchars' ); - $profile_show_bio = UM()->options()->get( 'profile_show_bio' ); - - if ( $profile_show_bio ) { - if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $submitted_data['description'] ) ) > $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 ( isset( $submitted_data['description'] ) ) { +// echo '
';
+//			print_r($submitted_data);
+//			echo '
'; +// exit(); +// $max_chars = UM()->options()->get( 'profile_bio_maxchars' ); +// $profile_show_bio = UM()->options()->get( 'profile_show_bio' ); +// +// if ( $profile_show_bio ) { +// if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $submitted_data['description'] ) ) > $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 ) ); +// } +// } +// } } // end if ( isset in args array ) } add_action( 'um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10, 2 ); diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 625994b4..b2a99eae 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -1241,6 +1241,7 @@ function um_profile_header( $args ) {
From bb4139e514659365488c66604a787e79a8caeb42 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 28 Jul 2023 10:49:36 +0300 Subject: [PATCH 2/5] - fix bio conflict --- includes/core/class-fields.php | 17 ++++++++++++++++- includes/core/um-actions-profile.php | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 6c3670f4..71f3384e 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2767,7 +2767,22 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } else { $textarea_field_value = ''; if ( ! empty( $field_value ) ) { - $textarea_field_value = ! empty( $data['html'] ) ? $field_value : wp_strip_all_tags( $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; + } else { + $bio_html = 0; + } + } + + if ( 1 === (int) $bio_html && array_key_exists( 'html', $data ) && 1 === (int) $data['html'] ) { + $textarea_field_value = $field_value; + } else { + $textarea_field_value = wp_strip_all_tags( $field_value ); + } } $output .= ''; } diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index b2a99eae..1c548ec0 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -1237,14 +1237,28 @@ function um_profile_header( $args ) { } ?>
- fields()->editing == true && $args['show_bio'] ) { ?> + 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 ) ); + } + } + ?>
+ name=""> options()->get( 'profile_bio_maxchars' ); ?> From 82d574b93b14133a07bf102015bf994a4c0c3ecc Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 28 Jul 2023 15:25:55 +0300 Subject: [PATCH 3/5] - fix limit chars for bio --- includes/core/um-actions-profile.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 1c548ec0..93b33ed2 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -1251,16 +1251,22 @@ function um_profile_header( $args ) { $description_value = wp_strip_all_tags( UM()->fields()->field_value( $description_key ) ); } } + 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' ); + } ?>
- options()->get( 'profile_bio_maxchars' ); ?> + + + fields()->is_error( $description_key ) ) { echo UM()->fields()->field_error( UM()->fields()->show_error( $description_key ), true ); From 7f7556719b8a895643917a0b19d280f3a2fa6fde Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 31 Jul 2023 09:11:05 +0300 Subject: [PATCH 4/5] - fix description length error --- includes/core/um-actions-form.php | 41 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 3222faa1..57b62730 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -673,16 +673,33 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { } } - if ( isset( $submitted_data['description'] ) ) { + $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' ); - if ( ! UM()->options()->get( 'profile_show_html_bio' ) ) { - $description_value = $submitted_data['description']; + $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']; + } + + if ( array_key_exists( 'html', $array ) && 1 === (int) $array['html'] && 1 === (int) UM()->options()->get( 'profile_show_html_bio' ) ) { + $description_value = wp_strip_all_tags( $submitted_data[ $description_key ] ); + } else { + $description_value = $submitted_data[ $description_key ]; + } } else { - $description_value = wp_strip_all_tags( $submitted_data['description'] ); + 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 ) ); @@ -954,22 +971,6 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { break; } - -// if ( isset( $submitted_data['description'] ) ) { -// echo '
';
-//			print_r($submitted_data);
-//			echo '
'; -// exit(); -// $max_chars = UM()->options()->get( 'profile_bio_maxchars' ); -// $profile_show_bio = UM()->options()->get( 'profile_show_bio' ); -// -// if ( $profile_show_bio ) { -// if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $submitted_data['description'] ) ) > $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 ) ); -// } -// } -// } } // end if ( isset in args array ) } add_action( 'um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10, 2 ); From 60a71ec983f0205ce9d4baccd7322fad65a10c37 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 31 Jul 2023 10:02:48 +0300 Subject: [PATCH 5/5] - small wpcs fix --- includes/core/um-actions-form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 57b62730..32873e64 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -673,7 +673,7 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { } } - $description_key = UM()->profile()->get_show_bio_key( $array ); + $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' );