mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- exclude fields for default usermeta table
This commit is contained in:
@@ -1187,6 +1187,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
|
||||
delete_post_meta( $post_id, '_um_tagline_fields' );
|
||||
delete_post_meta( $post_id, '_um_reveal_fields' );
|
||||
delete_post_meta( $post_id, '_um_search_fields' );
|
||||
delete_post_meta( $post_id, '_um_search_exclude_fields' );
|
||||
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' );
|
||||
|
||||
@@ -10,8 +10,9 @@ $_um_roles_search_value = empty( $_um_roles_search_value ) ? array() : $_um_role
|
||||
$_um_roles_filter_value = get_post_meta( $post_id, '_um_roles_can_filter', true );
|
||||
$_um_roles_filter_value = empty( $_um_roles_filter_value ) ? array() : $_um_roles_filter_value;
|
||||
|
||||
$_um_search_fields = get_post_meta( $post_id, '_um_search_fields', true );
|
||||
$_um_search_filters = get_post_meta( $post_id, '_um_search_filters', true ); ?>
|
||||
$_um_search_exclude_fields = get_post_meta( $post_id, '_um_search_exclude_fields', true );
|
||||
$_um_search_fields = get_post_meta( $post_id, '_um_search_fields', true );
|
||||
$_um_search_filters = get_post_meta( $post_id, '_um_search_filters', true ); ?>
|
||||
|
||||
|
||||
<div class="um-admin-metabox">
|
||||
@@ -38,6 +39,17 @@ $_um_search_filters = get_post_meta( $post_id, '_um_search_filters', true ); ?>
|
||||
'columns' => 3,
|
||||
'conditional' => array( '_um_search', '=', 1 ),
|
||||
),
|
||||
array(
|
||||
'id' => '_um_search_exclude_fields',
|
||||
'type' => 'multi_selects',
|
||||
'label' => __( 'Choose fields to exclude from search', 'ultimate-member' ),
|
||||
'value' => $_um_search_exclude_fields,
|
||||
'conditional' => array( '_um_filters', '=', 1 ),
|
||||
'options' => UM()->member_directory()->filter_fields,
|
||||
'add_text' => __( 'Add New Custom Field to Exclude', 'ultimate-member' ),
|
||||
'show_default_number' => 0,
|
||||
'sorting' => true,
|
||||
),
|
||||
array(
|
||||
'id' => '_um_filters',
|
||||
'type' => 'checkbox',
|
||||
|
||||
@@ -1642,10 +1642,34 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
*/
|
||||
public function general_search() {
|
||||
//general search
|
||||
// phpcs:disable WordPress.Security.NonceVerification
|
||||
if ( ! empty( $_POST['search'] ) ) {
|
||||
// complex using with change_meta_sql function
|
||||
$search = $this->prepare_search( $_POST['search'] );
|
||||
if ( ! empty( $search ) ) {
|
||||
$directory_id = $this->get_directory_by_hash( sanitize_key( $_POST['directory_id'] ) );
|
||||
$exclude_fields = get_post_meta( $directory_id, '_um_search_exclude_fields', true );
|
||||
if ( ! empty( $exclude_fields ) ) {
|
||||
global $wpdb;
|
||||
$exclude_users = array();
|
||||
$search_meta = '%' . $wpdb->esc_like( $search ) . '%';
|
||||
foreach ( $exclude_fields as $field ) {
|
||||
$field_users = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
"SELECT user_id
|
||||
FROM {$wpdb->usermeta}
|
||||
WHERE meta_key = %s
|
||||
AND meta_value LIKE %s",
|
||||
$field,
|
||||
$search_meta
|
||||
)
|
||||
);
|
||||
|
||||
$exclude_users = array_merge( $exclude_users, $field_users );
|
||||
}
|
||||
$exclude_users = array_unique( $exclude_users );
|
||||
}
|
||||
|
||||
$meta_query = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
@@ -1665,10 +1689,14 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
$meta_query = apply_filters( 'um_member_directory_general_search_meta_query', $meta_query, $search );
|
||||
|
||||
$this->query_args['meta_query'][] = $meta_query;
|
||||
if ( ! empty( $exclude_users ) ) {
|
||||
$this->query_args['exclude'] = $exclude_users;
|
||||
}
|
||||
|
||||
$this->is_search = true;
|
||||
}
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user