mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-19 06:33:50 +09:00
- reviewed #1269;
- 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:
@@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user