diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 3a8ec28c..9920e7fb 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -3683,6 +3683,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $roles = UM()->roles()->get_roles( false, $exclude_roles ); if ( ! empty( $options ) ) { + + $roles = array_map( function( $item ) { + return html_entity_decode( $item, ENT_QUOTES ); + }, $roles ); + //fix when customers change options for role (radio/dropdown) fields $intersected_options = array(); foreach ( $options as $option ) { diff --git a/includes/core/class-form.php b/includes/core/class-form.php index cddc9440..4e1c39ba 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -592,12 +592,35 @@ if ( ! class_exists( 'um\core\Form' ) ) { return false; } + // role field + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles', array() ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + $roles = UM()->roles()->get_roles( false, $exclude_roles ); + $roles = array_map( function( $item ) { + return html_entity_decode( $item, ENT_QUOTES ); + }, $roles ); + foreach ( $fields as $field_key => $field_settings ) { if ( strstr( $field_key , 'role_' ) ) { if ( is_array( $field_settings['options'] ) ) { - $option_pairs = apply_filters( 'um_select_options_pair', null, $field_settings ); - return ! empty( $option_pairs ) ? array_keys( $field_settings['options'] ) : array_values( $field_settings['options'] ); + //$option_pairs = apply_filters( 'um_select_options_pair', null, $field_settings ); + + $intersected_options = array(); + foreach ( $field_settings['options'] as $option ) { + if ( false !== $search_key = array_search( $option, $roles ) ) { + $intersected_options[ $search_key ] = $option; + } else { + $intersected_options[] = $option; + } + } + + //return ! empty( $option_pairs ) ? array_keys( $field_settings['options'] ) : array_values( $field_settings['options'] ); + return array_keys( $intersected_options ); } } diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index cf47728c..cf373e4b 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -697,7 +697,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { // 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 ( empty( $current_user_roles ) ) { + ob_get_clean(); + return ''; + } elseif ( is_array( $args['role'] ) ) { if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) { ob_get_clean(); return '';