diff --git a/README.md b/README.md index 9b550640..a4b9fa38 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Support requests in issues on this repository will be closed on sight. GNU Version 2 or Any Later Version ## Releases -[Official Release Version: 2.1.7](https://github.com/ultimatemember/ultimatemember/releases/tag/2.1.7). +[Official Release Version: 2.1.8](https://github.com/ultimatemember/ultimatemember/releases/tag/2.1.8). ## Changelog [ From v1.0.0 to latest version ](https://wordpress.org/plugins/ultimate-member/changelog/). diff --git a/assets/img/extensions/user-notes.png b/assets/img/extensions/user-notes.png new file mode 100644 index 00000000..f409ecc2 Binary files /dev/null and b/assets/img/extensions/user-notes.png differ diff --git a/includes/admin/core/class-admin-builder.php b/includes/admin/core/class-admin-builder.php index 1a8ca885..9e6bfbe5 100644 --- a/includes/admin/core/class-admin-builder.php +++ b/includes/admin/core/class-admin-builder.php @@ -1066,6 +1066,14 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) { case 'um_admin_review_registration': //$user_id = $arg1; + + if ( ! current_user_can( 'administrator' ) ) { + if ( ! um_can_view_profile( $arg1 ) ) { + $output = ''; + break; + } + } + um_fetch_user( $arg1 ); UM()->user()->preview = true; diff --git a/includes/admin/core/class-admin-users.php b/includes/admin/core/class-admin-users.php index 45b3bcfe..8be31391 100644 --- a/includes/admin/core/class-admin-users.php +++ b/includes/admin/core/class-admin-users.php @@ -26,6 +26,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) { add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 ); + add_filter( 'user_has_cap', array( &$this, 'map_caps_by_role' ), 10, 4 ); + + add_filter( 'users_list_table_query_args', array( &$this, 'hide_by_caps' ), 1, 1 ); + add_filter( 'pre_user_query', array( &$this, 'sort_by_newest' ) ); add_filter( 'pre_user_query', array( &$this, 'filter_users_by_status' ) ); @@ -38,6 +42,41 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) { } + /** + * Restrict the edit/delete users via wp-admin screen by the UM role capabilities + * + * @param $allcaps + * @param $cap + * @param $args + * @param $user + * + * @return mixed + */ + function map_caps_by_role( $allcaps, $cap, $args, $user ) { + if ( isset( $cap[0] ) && $cap[0] == 'edit_users' ) { + if ( ! user_can( $args[1], 'administrator' ) && $args[0] == 'edit_user' ) { + if ( ! UM()->roles()->um_current_user_can( 'edit', $args[2] ) ) { + $allcaps[ $cap[0] ] = false; + } + } + } elseif ( isset( $cap[0] ) && $cap[0] == 'delete_users' ) { + if ( ! user_can( $args[1], 'administrator' ) && $args[0] == 'delete_user' ) { + if ( ! UM()->roles()->um_current_user_can( 'delete', $args[2] ) ) { + $allcaps[ $cap[0] ] = false; + } + } + } elseif ( isset( $cap[0] ) && $cap[0] == 'list_users' ) { + if ( ! user_can( $args[1], 'administrator' ) && $args[0] == 'list_users' ) { + if ( ! um_user( 'can_view_all' ) ) { + $allcaps[ $cap[0] ] = false; + } + } + } + + return $allcaps; + } + + /** * Does an action to user asap * @@ -200,13 +239,21 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) { function user_row_actions( $actions, $user_object ) { $user_id = $user_object->ID; - - $actions['frontend_profile'] = "" . __( 'View profile', 'ultimate-member' ) . ""; + $actions['frontend_profile'] = '' . __( 'View profile', 'ultimate-member' ) . ''; $submitted = get_user_meta( $user_id, 'submitted', true ); - if ( ! empty( $submitted ) ) + if ( ! empty( $submitted ) ) { $actions['view_info'] = '' . __( 'Info', 'ultimate-member' ) . ''; + } + + if ( ! current_user_can( 'administrator' ) ) { + if ( ! um_can_view_profile( $user_id ) ) { + unset( $actions['frontend_profile'] ); + unset( $actions['view_info'] ); + unset( $actions['view'] ); + } + } /** * UM hook @@ -235,6 +282,24 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) { } + /** + * Change default sorting at WP Users list table + * + * @param array $args + * @return array + */ + function hide_by_caps( $args ) { + if ( ! current_user_can( 'administrator' ) ) { + $can_view_roles = um_user( 'can_view_roles' ); + if ( um_user( 'can_view_all' ) && ! empty( $can_view_roles ) ) { + $args['role__in'] = $can_view_roles; + } + } + + return $args; + } + + /** * Change default sorting at WP Users list table * @@ -363,6 +428,19 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) { $views[ $key ] = $view; } + // hide filters with not accessible roles + if ( ! current_user_can( 'administrator' ) ) { + $wp_roles = wp_roles(); + $can_view_roles = um_user( 'can_view_roles' ); + if ( ! empty( $can_view_roles ) ) { + foreach ( $wp_roles->get_names() as $this_role => $name ) { + if ( ! in_array( $this_role, $can_view_roles ) ) { + unset( $views[ $this_role ] ); + } + } + } + } + return $views; } diff --git a/includes/admin/templates/extensions.php b/includes/admin/templates/extensions.php index 4da751fa..51496429 100644 --- a/includes/admin/templates/extensions.php +++ b/includes/admin/templates/extensions.php @@ -134,6 +134,18 @@ $premium['user-locations'] = array( 'desc' => 'Using the Google Maps API, display users on a map on the member directory page and allow users to add their location via their profile', ); +$premium['user-notes'] = array( + 'url' => 'https://ultimatemember.com/extensions/user-notes/', + 'name' => 'User Notes', + 'desc' => 'Allow users to create public and private notes from their profile', +); + +$premium['profile-tabs'] = array( + 'url' => 'https://ultimatemember.com/extensions/profile-tabs/', + 'name' => 'Profile Tabs', + 'desc' => 'Add custom tabs to profiles', +); + $free['jobboardwp'] = array( 'url' => 'https://wordpress.org/plugins/um-jobboardwp', 'name' => 'JobBoardWP', diff --git a/includes/admin/templates/role/general.php b/includes/admin/templates/role/general.php index 58d895eb..97ca8559 100644 --- a/includes/admin/templates/role/general.php +++ b/includes/admin/templates/role/general.php @@ -5,22 +5,22 @@ admin_forms( array( - 'class' => 'um-role-general um-half-column', - 'prefix_id' => 'role', - 'fields' => array( + 'class' => 'um-role-general um-half-column', + 'prefix_id' => 'role', + 'fields' => array( array( - 'id' => '_um_can_edit_profile', - 'type' => 'checkbox', - 'label' => __( 'Can edit their profile?', 'ultimate-member' ), - 'tooltip' => __( 'Can this role edit his own profile?', 'ultimate-member' ), - 'value' => ! empty( $role['_um_can_edit_profile'] ) ? $role['_um_can_edit_profile'] : 0, + 'id' => '_um_can_edit_profile', + 'type' => 'checkbox', + 'label' => __( 'Can edit their profile?', 'ultimate-member' ), + 'tooltip' => __( 'Can this role edit his own profile?', 'ultimate-member' ), + 'value' => ! empty( $role['_um_can_edit_profile'] ) ? $role['_um_can_edit_profile'] : 0, ), array( - 'id' => '_um_can_delete_profile', - 'type' => 'checkbox', - 'label' => __( 'Can delete their account?', 'ultimate-member' ), - 'tooltip' => __( 'Allow this role to delete their account and end their membership on your site', 'ultimate-member' ), - 'value' => ! empty( $role['_um_can_delete_profile'] ) ? $role['_um_can_delete_profile'] : 0, + 'id' => '_um_can_delete_profile', + 'type' => 'checkbox', + 'label' => __( 'Can delete their account?', 'ultimate-member' ), + 'tooltip' => __( 'Allow this role to delete their account and end their membership on your site', 'ultimate-member' ), + 'value' => ! empty( $role['_um_can_delete_profile'] ) ? $role['_um_can_delete_profile'] : 0, ) ) ) )->render_form(); ?> diff --git a/includes/admin/templates/role/profile.php b/includes/admin/templates/role/profile.php index c36da283..4aaf6da7 100644 --- a/includes/admin/templates/role/profile.php +++ b/includes/admin/templates/role/profile.php @@ -5,41 +5,41 @@ admin_forms( array( - 'class' => 'um-role-profile um-half-column', - 'prefix_id' => 'role', - 'fields' => array( + 'class' => 'um-role-profile um-half-column', + 'prefix_id' => 'role', + 'fields' => array( array( - 'id' => '_um_can_view_all', - 'type' => 'checkbox', - 'label' => __( 'Can view other member profiles?', 'ultimate-member' ), - 'tooltip' => __( 'Can this role view all member profiles?', 'ultimate-member' ), - 'value' => ! empty( $role['_um_can_view_all'] ) ? $role['_um_can_view_all'] : 0, + 'id' => '_um_can_view_all', + 'type' => 'checkbox', + 'label' => __( 'Can view other member profiles?', 'ultimate-member' ), + 'tooltip' => __( 'Can this role view all member profiles?', 'ultimate-member' ), + 'value' => ! empty( $role['_um_can_view_all'] ) ? $role['_um_can_view_all'] : 0, ), array( - 'id' => '_um_can_view_roles', - 'type' => 'select', - 'label' => __( 'Can view these user roles only', 'ultimate-member' ), - 'tooltip' => __( 'Which roles that role can view, choose none to allow role to view all member roles', 'ultimate-member' ), - 'options' => UM()->roles()->get_roles(), - 'multi' => true, - 'value' => ! empty( $role['_um_can_view_roles'] ) ? $role['_um_can_view_roles'] : array(), - 'conditional' => array( '_um_can_view_all', '=', '1' ) + 'id' => '_um_can_view_roles', + 'type' => 'select', + 'label' => __( 'Can view these user roles only', 'ultimate-member' ), + 'tooltip' => __( 'Which roles that role can view, choose none to allow role to view all member roles', 'ultimate-member' ), + 'options' => UM()->roles()->get_roles(), + 'multi' => true, + 'value' => ! empty( $role['_um_can_view_roles'] ) ? $role['_um_can_view_roles'] : array(), + 'conditional' => array( '_um_can_view_all', '=', '1' ) ), array( - 'id' => '_um_can_make_private_profile', - 'type' => 'checkbox', - 'name' => '_um_can_make_private_profile', - 'label' => __( 'Can make their profile private?', 'ultimate-member' ), - 'tooltip' => __( 'Can this role make their profile private?', 'ultimate-member' ), - 'value' => ! empty( $role['_um_can_make_private_profile'] ) ? $role['_um_can_make_private_profile'] : 0, + 'id' => '_um_can_make_private_profile', + 'type' => 'checkbox', + 'name' => '_um_can_make_private_profile', + 'label' => __( 'Can make their profile private?', 'ultimate-member' ), + 'tooltip' => __( 'Can this role make their profile private?', 'ultimate-member' ), + 'value' => ! empty( $role['_um_can_make_private_profile'] ) ? $role['_um_can_make_private_profile'] : 0, ), array( - 'id' => '_um_can_access_private_profile', - 'type' => 'checkbox', - 'name' => '_um_can_access_private_profile', - 'label' => __( 'Can view/access private profiles?', 'ultimate-member' ), - 'tooltip' => __( 'Can this role view private profiles?', 'ultimate-member' ), - 'value' => ! empty( $role['_um_can_access_private_profile'] ) ? $role['_um_can_access_private_profile'] : 0, + 'id' => '_um_can_access_private_profile', + 'type' => 'checkbox', + 'name' => '_um_can_access_private_profile', + 'label' => __( 'Can view/access private profiles?', 'ultimate-member' ), + 'tooltip' => __( 'Can this role view private profiles?', 'ultimate-member' ), + 'value' => ! empty( $role['_um_can_access_private_profile'] ) ? $role['_um_can_access_private_profile'] : 0, ) ) ) )->render_form(); ?> diff --git a/readme.txt b/readme.txt index 6b0ca97b..20d75268 100644 --- a/readme.txt +++ b/readme.txt @@ -156,12 +156,13 @@ The plugin works with popular caching plugins by automatically excluding Ultimat * To learn more about version 2.1 please see this [docs](https://docs.ultimatemember.com/article/1512-upgrade-2-1-0) * UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin -= 2.1.8: September 3, 2020 = += 2.1.8: September 1, 2020 = * Enhancements: - Added dependency functions for extensions: [Ultimate Member - User Notes](https://ultimatemember.com/extensions/user-notes/) & [Ultimate Member - Profile Tabs](https://ultimatemember.com/extensions/profile-tabs/) - Added unique IDs to the form fields at the Profile's view mode + - Added restrictions for WP > Users list table based on UM Roles capabilities * Bugfixes: