From 8a6f04140744d61a17d4dc92ff87662c3054e964 Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Fri, 12 Mar 2021 03:46:45 +0200 Subject: [PATCH] - added profile tab privacy 'Owner + Specific roles'; --- includes/admin/assets/js/um-admin-forms.js | 30 +++++++++++++++++--- includes/admin/core/class-admin-settings.php | 2 +- includes/core/class-profile.php | 22 +++++++++++++- readme.txt | 3 ++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/includes/admin/assets/js/um-admin-forms.js b/includes/admin/assets/js/um-admin-forms.js index 478ef13d..1299c920 100644 --- a/includes/admin/assets/js/um-admin-forms.js +++ b/includes/admin/assets/js/um-admin-forms.js @@ -774,10 +774,20 @@ jQuery(document).ready( function() { if ( input_type === 'checkbox' ) { own_condition = ( value == '1' ) ? cond_field.is(':checked') : ! cond_field.is(':checked'); } else { - own_condition = ( cond_field.val() == value ); + if ( Array.isArray( value ) ) { + own_condition = ( value.indexOf( cond_field.val() ) !== -1 ); + } else { + own_condition = ( cond_field.val() == value ); + } } } else if ( tagName === 'select' ) { - own_condition = ( cond_field.val() == value ); + + if ( Array.isArray( value ) ) { + own_condition = ( value.indexOf( cond_field.val() ) !== -1 ); + } else { + own_condition = ( cond_field.val() == value ); + } + } if ( own_condition && parent_condition ) { @@ -794,10 +804,22 @@ jQuery(document).ready( function() { if ( input_type == 'checkbox' ) { own_condition = ( value == '1' ) ? condition_field.is(':checked') : ! condition_field.is(':checked'); } else { - own_condition = ( condition_field.val() == value ); + + if ( Array.isArray( value ) ) { + own_condition = ( value.indexOf( condition_field.val() ) !== -1 ); + } else { + own_condition = ( condition_field.val() == value ); + } + } } else if ( tagName == 'select' ) { - own_condition = ( condition_field.val() == value ); + + if ( Array.isArray( value ) ) { + own_condition = ( value.indexOf( condition_field.val() ) !== -1 ); + } else { + own_condition = ( condition_field.val() == value ); + } + } return ( own_condition && parent_condition ); diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index e1d8865e..439c224d 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -336,7 +336,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { 'tooltip' => __( 'Select the the user roles allowed to view this tab.', 'ultimate-member' ), 'options' => UM()->roles()->get_roles(), 'placeholder' => __( 'Choose user roles...', 'ultimate-member' ), - 'conditional' => array( 'profile_tab_' . $id . '_privacy', '=', 4 ), + 'conditional' => array( 'profile_tab_' . $id . '_privacy', '=', [ '4', '5' ] ), 'size' => 'small' ) ); diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php index 1cffe05c..ccde480c 100644 --- a/includes/core/class-profile.php +++ b/includes/core/class-profile.php @@ -101,7 +101,8 @@ if ( ! class_exists( 'um\core\Profile' ) ) { 1 => __( 'Guests only', 'ultimate-member' ), 2 => __( 'Members only', 'ultimate-member' ), 3 => __( 'Only the owner', 'ultimate-member' ), - 4 => __( 'Specific roles', 'ultimate-member' ), + 4 => __( 'Only specific roles', 'ultimate-member' ), + 5 => __( 'Owner and specific roles', 'ultimate-member' ), ); return $privacy; @@ -227,6 +228,25 @@ if ( ! class_exists( 'um\core\Profile' ) ) { } } break; + case 5: + if ( is_user_logged_in() ) { + // check profile owner if not - check privacy roles settings + $can_view = get_current_user_id() === $target_id; + + if ( ! $can_view ) { + if ( isset( $tab_data['default_privacy'] ) ) { + $roles = isset( $tab_data['default_privacy_roles'] ) ? $tab_data['default_privacy_roles'] : array(); + } else { + $roles = (array) UM()->options()->get( 'profile_tab_' . $tab . '_roles' ); + } + + $current_user_roles = um_user( 'roles' ); + if ( ! empty( $current_user_roles ) && count( array_intersect( $current_user_roles, $roles ) ) > 0 ) { + $can_view = true; + } + } + } + break; default: $can_view = true; diff --git a/readme.txt b/readme.txt index afafafc8..4d9e2389 100644 --- a/readme.txt +++ b/readme.txt @@ -157,6 +157,9 @@ The plugin works with popular caching plugins by automatically excluding Ultimat = 2.1.17: xx, 2021 = +* Enhancements: + - Added: 'Owner and specific roles' privacy type for the Profile tabs + * Bugfixes: - Fixed: PHP notice when the admin filtering field has the not array default value (e.g. bool)