From 421f22fe3f5f289c73f14a3bf238a289282505af Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Mon, 25 May 2020 17:37:20 +0300 Subject: [PATCH] - PHP fixes; - fixed profile form duplicates, show only the first shortcode for the user with selected role; --- includes/core/class-shortcodes.php | 37 +++++++++++++++-------------- includes/core/um-actions-form.php | 2 +- includes/core/um-filters-fields.php | 6 ++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 596f0e99..2a0e50a6 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -13,6 +13,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { */ class Shortcodes { + var $profile_role = ''; /** * Shortcodes constructor. @@ -668,24 +669,24 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { if ( ! empty( $args['use_custom_settings'] ) ) { // Option "Apply custom settings to this form" if ( ! empty( $args['role'] ) ) { // Option "Make this profile form role-specific" -// $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); -// if ( is_array( $args['role'] ) ) { -// if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) { -// ob_get_clean(); -// return ''; -// } -// } else { -// if ( ! in_array( $args['role'], $current_user_roles ) ) { -// ob_get_clean(); -// return ''; -// } -// } - /* Users in WordPress can have several roles. So, we should look for the priority role. Otherwise form may be duplicated. */ - $priority_user_role = UM()->roles()->get_priority_user_role( um_profile_id() ); - if ( ! is_array( $args['role'] ) ) { - $args['role'] = array( $args['role'] ); - } - if ( ! in_array( $priority_user_role, $args['role'] ) ) { + + // show the first Profile Form with role selected, don't show profile forms below the page with other role-specific setting + if ( empty( $this->profile_role ) ) { + $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); + if ( is_array( $args['role'] ) ) { + if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) { + ob_get_clean(); + return ''; + } + } else { + if ( ! in_array( $args['role'], $current_user_roles ) ) { + ob_get_clean(); + return ''; + } + } + + $this->profile_role = $args['role']; + } else { ob_get_clean(); return ''; } diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index baa868fb..555b636b 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -467,7 +467,7 @@ function um_submit_form_errors_hook_( $args ) { /* WordPress uses the default user role if the role wasn't chosen in the registration form. That is why we should use submitted data to validate fields Roles (Radio) and Roles (Dropdown). */ if ( in_array( $key, array( 'role_radio', 'role_select' ) ) && isset( $array['required'] ) && $array['required'] == 1 && empty( UM()->form()->post_form['submitted']['role'] ) ) { UM()->form()->add_error( 'role', __( 'Please specify account type.', 'ultimate-member' ) ); - UM()->form()->post_form[$key] = ''; + UM()->form()->post_form[ $key ] = ''; } /** diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index f92827d3..414bfdc7 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -722,15 +722,15 @@ function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) { */ $option_pairs = apply_filters( 'um_select_options_pair', null, $data ); - $arr = $data['options']; + $arr = empty( $data['options'] ) ? array() : $data['options'];; if ( $option_pairs ) { - $arr = array_keys( $data['options'] ); + $arr = array_keys( $arr ); } if ( ! empty( $arr ) && ! in_array( $value, array_map( 'trim', $arr ) ) && empty( $data['custom_dropdown_options_source'] ) ) { $value = ''; } else { - if ( $option_pairs ) { + if ( $option_pairs && isset( $data['options'] ) && is_array( $data['options'] ) && isset( $data['options'][ $value ] ) ) { $value = $data['options'][ $value ]; } }