diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index de4f52bf..5d53d5b6 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -1071,6 +1071,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { delete_post_meta( $post_id, '_um_roles_can_search' ); delete_post_meta( $post_id, '_um_roles_can_filter' ); delete_post_meta( $post_id, '_um_show_these_users' ); + delete_post_meta( $post_id, '_um_exclude_these_users' ); delete_post_meta( $post_id, '_um_search_filters' ); delete_post_meta( $post_id, '_um_search_filters_gmt' ); @@ -1082,6 +1083,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY ); } + if ( $k == '_um_exclude_these_users' && trim( $_POST['um_metadata'][ $k ] ) ) { + $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY ); + } + if ( strstr( $k, '_um_' ) ) { if ( $k === '_um_is_default' ) { diff --git a/includes/admin/templates/directory/general.php b/includes/admin/templates/directory/general.php index ab07126f..60a40d7d 100644 --- a/includes/admin/templates/directory/general.php +++ b/includes/admin/templates/directory/general.php @@ -10,6 +10,11 @@ if ( $show_these_users ) { $show_these_users = implode( "\n", str_replace( "\r", "", $show_these_users ) ); } +$exclude_these_users = get_post_meta( get_the_ID(), '_um_exclude_these_users', true ); +if ( $exclude_these_users ) { + $exclude_these_users = implode( "\n", str_replace( "\r", "", $exclude_these_users ) ); +} + $_um_view_types_value = get_post_meta( $post_id, '_um_view_types', true ); $_um_view_types_value = empty( $_um_view_types_value ) ? array( 'grid', 'list' ) : $_um_view_types_value; @@ -77,6 +82,12 @@ foreach ( $view_types_options as $key => $value ) { 'label' => __( 'Only show specific users (Enter one username per line)', 'ultimate-member' ), 'value' => $show_these_users, ), + array( + 'id' => '_um_exclude_these_users', + 'type' => 'textarea', + 'label' => __( 'Exclude specific users (Enter one username per line)', 'ultimate-member' ), + 'value' => $exclude_these_users, + ), ); /** diff --git a/includes/class-config.php b/includes/class-config.php index c53193d4..28382baa 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -147,6 +147,7 @@ if ( ! class_exists( 'um\Config' ) ) { '_um_has_profile_photo' => 0, '_um_has_cover_photo' => 0, '_um_show_these_users' => '', + '_um_exclude_these_users' => '', '_um_sortby' => 'user_registered_desc', '_um_sortby_custom' => '', diff --git a/includes/core/class-member-directory.php b/includes/core/class-member-directory.php index b6c50a2a..b6f521a2 100644 --- a/includes/core/class-member-directory.php +++ b/includes/core/class-member-directory.php @@ -1093,6 +1093,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) { $this->show_only_with_avatar( $directory_data ); $this->show_only_with_cover( $directory_data ); $this->show_only_these_users( $directory_data ); + $this->exclude_these_users( $directory_data ); do_action( 'um_member_directory_general_options_handle_extend', $directory_data ); } @@ -1177,6 +1178,34 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) { } + /** + * Handle "Exclude specific users (Enter one username per line)" option + * + * @param array $directory_data + */ + function exclude_these_users( $directory_data ) { + if ( ! empty( $directory_data['exclude_these_users'] ) ) { + $exclude_these_users = maybe_unserialize( $directory_data['exclude_these_users'] ); + + if ( is_array( $exclude_these_users ) && ! empty( $exclude_these_users ) ) { + + $users_array = array(); + + foreach ( $exclude_these_users as $username ) { + if ( false !== ( $exists_id = username_exists( $username ) ) ) { + $users_array[] = $exists_id; + } + } + + if ( ! empty( $users_array ) ) { + $this->query_args['exclude'] = $users_array; + } + + } + } + } + + /** * Handle "Pagination Options" metabox settings *