From 0acc9ad280161d5c5b80125074c9a2fc66e8792a Mon Sep 17 00:00:00 2001 From: denisbaranov Date: Fri, 24 Apr 2020 14:54:04 +0300 Subject: [PATCH] Fixed: Option "Make this profile form role-specific" Users in WordPress can have several roles. So, we should look for the priority role. Otherwise form may be duplicated. --- includes/core/class-shortcodes.php | 37 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 6042cc83..596f0e99 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -666,21 +666,28 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { um_set_requested_user( um_profile_id() ); } - if ( ! empty( $args['use_custom_settings'] ) ) { // Custom Form settings - $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); - - //backward compatibility between single/multi role form's setting - if ( ! empty( $args['role'] ) ) { - 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 ''; - } + 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'] ) ) { + ob_get_clean(); + return ''; } } }