- fixed #1005;
- fixed #1006;
- fixed #1010;
This commit is contained in:
Nikita Sinelnikov
2022-06-09 17:17:15 +03:00
parent ffadc8e99d
commit 72d58f709d
4 changed files with 122 additions and 4 deletions
+81 -1
View File
@@ -51,6 +51,9 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
var $filter_supported_fields = array();
var $sorting_supported_fields = array();
var $filter_types = array();
@@ -302,9 +305,32 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
'display_name' => __( 'Display name', 'ultimate-member' ),
'last_first_name' => __( 'Last & First name', 'ultimate-member' ),
'last_login' => __( 'Last login', 'ultimate-member' ),
) );
$this->sorting_supported_fields = apply_filters( 'um_members_directory_custom_field_types_supported_sorting', array( 'number' ) );
if ( ! empty( UM()->builtin()->saved_fields ) ) {
foreach ( UM()->builtin()->saved_fields as $key => $data ) {
if ( $key == '_um_last_login' ) {
continue;
}
if ( isset( $data['type'] ) && in_array( $data['type'], $this->sorting_supported_fields ) ) {
if ( isset( $data['title'] ) && array_search( sprintf( __( '%s DESC', 'ultimate-member' ), $data['title'] ), $this->sort_fields ) !== false ) {
$data['title'] = $data['title'] . ' (' . $key . ')';
}
$title = isset( $data['title'] ) ? $data['title'] : ( isset( $data['label'] ) ? $data['label'] : '' );
if ( empty( $title ) ) {
continue;
}
$this->sort_fields[ $key . '_desc' ] = sprintf( __( '%s DESC', 'ultimate-member' ), $title );
$this->sort_fields[ $key . '_asc' ] = sprintf( __( '%s ASC', 'ultimate-member' ), $title );
}
}
}
asort( $this->sort_fields );
$this->default_sorting = apply_filters( 'um_members_directory_default_sort', array_merge( $this->sort_fields, array(
@@ -1262,6 +1288,25 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
}
}
$numeric_sorting_keys = array();
if ( ! empty( UM()->builtin()->saved_fields ) ) {
foreach ( UM()->builtin()->saved_fields as $key => $data ) {
if ( $key == '_um_last_login' ) {
continue;
}
if ( isset( $data['type'] ) && 'number' === $data['type'] ) {
if ( array_key_exists( $key . '_desc', $this->sort_fields ) ) {
$numeric_sorting_keys[] = $key . '_desc';
}
if ( array_key_exists( $key . '_asc', $this->sort_fields ) ) {
$numeric_sorting_keys[] = $key . '_asc';
}
}
}
}
if ( 'username' == $sortby ) {
$this->query_args['orderby'] = 'user_login';
@@ -1332,6 +1377,41 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$this->query_args['orderby'] = array( 'last_name_c' => 'ASC', 'first_name_c' => 'ASC' );
unset( $this->query_args['order'] );
} elseif ( count( $numeric_sorting_keys ) && in_array( $sortby, $numeric_sorting_keys ) ) {
$order = 'DESC';
if ( strstr( $sortby, '_desc' ) ) {
$sortby = str_replace( '_desc', '', $sortby );
$order = 'DESC';
}
if ( strstr( $sortby, '_asc' ) ) {
$sortby = str_replace( '_asc', '', $sortby );
$order = 'ASC';
}
$this->query_args['meta_query'] = array_merge(
$this->query_args['meta_query'],
array(
array(
'relation' => 'OR',
array(
'key' => $sortby,
'compare' => 'EXISTS',
'type' => 'NUMERIC',
),
$sortby . '_ns' => array(
'key' => $sortby,
'compare' => 'NOT EXISTS',
'type' => 'NUMERIC',
),
),
)
);
$this->query_args['orderby'] = array( $sortby . '_ns' => $order, 'user_registered' => 'DESC' );
unset( $this->query_args['order'] );
} elseif ( ( ! empty( $directory_data['sortby_custom'] ) && $sortby == $directory_data['sortby_custom'] ) || in_array( $sortby, $custom_sort ) ) {
$custom_sort_type = apply_filters( 'um_member_directory_custom_sorting_type', 'CHAR', $sortby, $directory_data );