- add the field "Exclude specific users"

This commit is contained in:
ashubawork
2020-03-31 14:42:24 +03:00
parent 25287c77f4
commit 02d8e2019b
4 changed files with 46 additions and 0 deletions
@@ -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' ) {
@@ -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,
),
);
/**
+1
View File
@@ -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' => '',
+29
View File
@@ -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
*