mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- fixed gender member directory filter with Male/Female field values;
This commit is contained in:
@@ -496,6 +496,33 @@ if ( ! class_exists( 'um\core\Member_Directory_Meta' ) ) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'gender':
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array( $value );
|
||||
}
|
||||
|
||||
// $join_alias is pre-escaped.
|
||||
$this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata {$join_alias} ON {$join_alias}.user_id = u.ID";
|
||||
|
||||
$values_array = array();
|
||||
foreach ( $value as $single_val ) {
|
||||
$single_val = trim( stripslashes( $single_val ) );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $join_alias and $compare variables are pre-escaped.
|
||||
$values_array[] = $wpdb->prepare( "{$join_alias}.um_value LIKE %s", '%"' . $wpdb->esc_like( $single_val ) . '"%' );
|
||||
$values_array[] = $wpdb->prepare( "{$join_alias}.um_value = %s", $single_val );
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $join_alias is pre-escaped.
|
||||
}
|
||||
|
||||
$values = implode( ' OR ', $values_array );
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $join_alias and $values variables are pre-escaped or $wpdb->prepare.
|
||||
$this->where_clauses[] = $wpdb->prepare( "( {$join_alias}.um_key = %s AND ( {$values} ) )", $field );
|
||||
|
||||
if ( ! $is_default ) {
|
||||
$this->custom_filters_in_query[ $field ] = $value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1819,7 +1819,6 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
|
||||
switch ( $field ) {
|
||||
default:
|
||||
|
||||
$filter_type = $this->filter_types[ $field ];
|
||||
|
||||
/**
|
||||
@@ -1975,7 +1974,6 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
if ( ! empty( $field_query ) && $field_query !== true ) {
|
||||
$this->query_args['meta_query'] = array_merge( $this->query_args['meta_query'], array( $field_query ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case 'role':
|
||||
$value = array_map( 'strtolower', $value );
|
||||
@@ -1991,7 +1989,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
$this->query_args['role__in'] = array_merge( $default_role, $um_role );
|
||||
} else {
|
||||
$this->query_args['role__in'] = $value;
|
||||
};
|
||||
}
|
||||
|
||||
$this->custom_filters_in_query[ $field ] = $this->query_args['role__in'];
|
||||
|
||||
@@ -2016,7 +2014,6 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
|
||||
break;
|
||||
case 'user_registered':
|
||||
|
||||
$offset = 0;
|
||||
if ( isset( $_POST['gmt_offset'] ) && is_numeric( $_POST['gmt_offset'] ) ) {
|
||||
$offset = (int) $_POST['gmt_offset'];
|
||||
@@ -2065,6 +2062,36 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
|
||||
$this->query_args['meta_query'] = array_merge( $this->query_args['meta_query'], array( $meta_query ) );
|
||||
break;
|
||||
case 'gender':
|
||||
if ( is_array( $value ) ) {
|
||||
$field_query = array( 'relation' => 'OR' );
|
||||
|
||||
foreach ( $value as $single_val ) {
|
||||
$single_val = trim( stripslashes( $single_val ) );
|
||||
|
||||
$arr_meta_query = array(
|
||||
array(
|
||||
'key' => $field,
|
||||
'value' => $single_val,
|
||||
'compare' => '=',
|
||||
),
|
||||
array(
|
||||
'key' => $field,
|
||||
'value' => '"' . $single_val . '"',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
);
|
||||
|
||||
$field_query = array_merge( $field_query, $arr_meta_query );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $field_query ) ) {
|
||||
$this->query_args['meta_query'] = array_merge( $this->query_args['meta_query'], array( $field_query ) );
|
||||
|
||||
$this->custom_filters_in_query[ $field ] = $value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Author URI: https://ultimatemember.com/
|
||||
Plugin URI: https://ultimatemember.com/
|
||||
Contributors: ultimatemember, champsupertramp, nsinelnikov
|
||||
Donate link:
|
||||
Tags: community, member, membership, user-profile, user-registration
|
||||
Requires PHP: 5.6
|
||||
Requires at least: 5.5
|
||||
|
||||
Reference in New Issue
Block a user