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/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-form.php b/includes/core/um-actions-form.php index 0d847b2e..32873e64 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,40 @@ 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']; + } + + 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 { + 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; } @@ -932,18 +971,6 @@ function um_submit_form_errors_hook_( $submitted_data, $form_data ) { break; } - - 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 ) ); - } - } - } } // 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..93b33ed2 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -1237,15 +1237,36 @@ 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 ) ); + } + } + 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' ); + } + ?>