mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-17 21:53:43 +09:00
- member directory;
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,310 +26,7 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
add_filter( 'user_search_columns', array( &$this, 'user_search_columns' ), 99 );
|
||||
add_action( 'template_redirect', array( &$this, 'access_members' ), 555 );
|
||||
|
||||
$this->core_search_fields = array(
|
||||
'user_login',
|
||||
'user_url',
|
||||
'display_name',
|
||||
'user_email',
|
||||
'user_nicename',
|
||||
);
|
||||
|
||||
add_filter( 'um_search_select_fields', array( &$this, 'um_search_select_fields' ), 10, 1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show filter
|
||||
*
|
||||
* @todo make UM:Groups members list via general directory
|
||||
*
|
||||
* @deprecated since 2.1.0 - Use only in UM Groups extension
|
||||
* @param $filter
|
||||
*/
|
||||
function show_filter( $filter ) {
|
||||
/**
|
||||
* @var $type
|
||||
* @var $attrs
|
||||
*/
|
||||
extract( $this->prepare_filter( $filter ) );
|
||||
|
||||
switch ( $type ) {
|
||||
|
||||
case 'select':
|
||||
/*if( isset($attrs) && is_array( $attrs['options'] ) ){
|
||||
asort( $attrs['options'] );
|
||||
}*/
|
||||
if ( isset( $attrs['label'] ) ) {
|
||||
$label = $attrs['label'];
|
||||
} else {
|
||||
$label = isset( $attrs['title'] ) ? $attrs['title'] : '';
|
||||
} ?>
|
||||
|
||||
<select name="<?php echo esc_attr( $filter ); ?>" id="<?php echo esc_attr( $filter ); ?>" class="um-s1"
|
||||
style="width: 100%" data-placeholder="<?php esc_attr_e( stripslashes( $label ), 'ultimate-member' ); ?>" <?php if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) { ?> data-um-parent="<?php echo esc_attr( $attrs['parent_dropdown_relationship'] ); ?>" data-mebers-directory="yes" data-um-ajax-source="<?php echo esc_attr( $attrs['custom_dropdown_options_source'] ) ?>"<?php } ?>>
|
||||
|
||||
<option></option>
|
||||
|
||||
<?php foreach ( $attrs['options'] as $k => $v ) {
|
||||
|
||||
$v = stripslashes( $v );
|
||||
|
||||
$opt = $v;
|
||||
|
||||
if ( strstr( $filter, 'role_' ) ) {
|
||||
$opt = $k;
|
||||
}
|
||||
|
||||
if ( isset( $attrs['custom'] ) ) {
|
||||
$opt = $k;
|
||||
} ?>
|
||||
|
||||
<option value="<?php echo esc_attr( $opt ); ?>" <?php um_select_if_in_query_params( $filter, $opt ); ?> <?php selected( isset( $_GET[ $filter ] ) && $_GET[ $filter ] == $v ) ?>><?php esc_html_e( $v, 'ultimate-member'); ?></option>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
|
||||
<?php
|
||||
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
?>
|
||||
|
||||
<input type="text" autocomplete="off" name="<?php echo esc_attr( $filter ); ?>" id="<?php echo esc_attr( $filter ); ?>"
|
||||
placeholder="<?php echo isset( $attrs['label'] ) ? esc_attr__( $attrs['label'], 'ultimate-member' ) : ''; ?>"
|
||||
value="<?php echo esc_attr( um_queried_search_value( $filter, false ) ); ?>" />
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User_search_columns
|
||||
*
|
||||
* @param $search_columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function user_search_columns( $search_columns ) {
|
||||
if ( is_admin() ) {
|
||||
$search_columns[] = 'display_name';
|
||||
}
|
||||
return $search_columns;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Members page allowed?
|
||||
*/
|
||||
function access_members() {
|
||||
if ( UM()->options()->get( 'members_page' ) == 0 && um_is_core_page( 'members' ) ) {
|
||||
um_redirect_home();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tag conversion for member directory
|
||||
*
|
||||
* @param $string
|
||||
* @param $array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function convert_tags( $string, $array ) {
|
||||
|
||||
$search = array(
|
||||
'{total_users}',
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
$array['total_users'],
|
||||
);
|
||||
|
||||
$string = str_replace( $search, $replace, $string );
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare filter data
|
||||
*
|
||||
* @param $filter
|
||||
* @return array
|
||||
*/
|
||||
function prepare_filter( $filter ) {
|
||||
$fields = UM()->builtin()->all_user_fields;
|
||||
|
||||
if ( isset( $fields[ $filter ] ) ) {
|
||||
$attrs = $fields[ $filter ];
|
||||
} else {
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_custom_search_field_{$filter}
|
||||
* @description Custom search settings by $filter
|
||||
* @input_vars
|
||||
* [{"var":"$settings","type":"array","desc":"Search Settings"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_custom_search_field_{$filter}', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_custom_search_field_{$filter}', 'my_custom_search_field', 10, 1 );
|
||||
* function my_change_email_template_file( $settings ) {
|
||||
* // your code here
|
||||
* return $settings;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$attrs = apply_filters( "um_custom_search_field_{$filter}", array() );
|
||||
}
|
||||
|
||||
// additional filter for search field attributes
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_search_field_{$filter}
|
||||
* @description Extend search settings by $filter
|
||||
* @input_vars
|
||||
* [{"var":"$settings","type":"array","desc":"Search Settings"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_search_field_{$filter}', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_search_field_{$filter}', 'my_search_field', 10, 1 );
|
||||
* function my_change_email_template_file( $settings ) {
|
||||
* // your code here
|
||||
* return $settings;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$attrs = apply_filters( "um_search_field_{$filter}", $attrs );
|
||||
|
||||
$type = UM()->builtin()->is_dropdown_field( $filter, $attrs ) ? 'select' : 'text';
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_search_field_type
|
||||
* @description Change search field type
|
||||
* @input_vars
|
||||
* [{"var":"$type","type":"string","desc":"Search field type"},
|
||||
* {"var":"$settings","type":"array","desc":"Search Settings"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_search_field_type', 'function_name', 10, 2 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_search_field_type', 'my_search_field_type', 10, 2 );
|
||||
* function my_search_field_type( $type, $settings ) {
|
||||
* // your code here
|
||||
* return $type;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$type = apply_filters( 'um_search_field_type', $type, $attrs );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_search_fields
|
||||
* @description Filter all search fields
|
||||
* @input_vars
|
||||
* [{"var":"$settings","type":"array","desc":"Search Fields"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_search_fields', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_search_fields', 'my_search_fields', 10, 1 );
|
||||
* function my_search_fields( $settings ) {
|
||||
* // your code here
|
||||
* return $settings;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$attrs = apply_filters( 'um_search_fields', $attrs );
|
||||
|
||||
if ( $type == 'select' ) {
|
||||
if ( isset( $attrs ) && is_array( $attrs['options'] ) ) {
|
||||
asort( $attrs['options'] );
|
||||
}
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_search_select_fields
|
||||
* @description Filter all search fields for select field type
|
||||
* @input_vars
|
||||
* [{"var":"$settings","type":"array","desc":"Search Fields"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_search_select_fields', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_search_select_fields', 'my_search_select_fields', 10, 1 );
|
||||
* function my_search_select_fields( $settings ) {
|
||||
* // your code here
|
||||
* return $settings;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$attrs = apply_filters( 'um_search_select_fields', $attrs );
|
||||
}
|
||||
|
||||
return compact( 'type', 'attrs' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display assigned roles in search filter 'role' field
|
||||
* @param array $attrs
|
||||
* @return array
|
||||
* @uses add_filter 'um_search_select_fields'
|
||||
* @since 1.3.83
|
||||
*/
|
||||
function um_search_select_fields( $attrs ) {
|
||||
|
||||
if ( ! empty( $attrs['metakey'] ) && strstr( $attrs['metakey'], 'role_' ) ) {
|
||||
|
||||
$shortcode_roles = get_post_meta( UM()->shortcodes()->form_id, '_um_roles', true );
|
||||
$um_roles = UM()->roles()->get_roles( false );
|
||||
|
||||
if ( ! empty( $shortcode_roles ) && is_array( $shortcode_roles ) ) {
|
||||
|
||||
$attrs['options'] = array();
|
||||
|
||||
foreach ( $um_roles as $key => $value ) {
|
||||
if ( in_array( $key, $shortcode_roles ) ) {
|
||||
$attrs['options'][ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +1,6 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
|
||||
/**
|
||||
* WP API user search
|
||||
*
|
||||
* @param $query_args
|
||||
* @param $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
//function um_search_usernames_emails( $query_args, $args ) {
|
||||
// extract( $args );
|
||||
//
|
||||
// $query = UM()->permalinks()->get_query_array();
|
||||
// $arr_columns = array();
|
||||
//
|
||||
// foreach ( UM()->members()->core_search_fields as $key ) {
|
||||
// if ( ! empty( $query[ $key ] ) ) {
|
||||
// $arr_columns[] = $key;
|
||||
// $query_args['search'] = '*' . $query[ $key ] .'*';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if ( ! empty( $arr_columns ) )
|
||||
// $query_args['search_columns'] = $arr_columns;
|
||||
//
|
||||
// return $query_args;
|
||||
//}
|
||||
//add_filter( 'um_prepare_user_query_args', 'um_search_usernames_emails', 51, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* Remove users we do not need to show in directory
|
||||
*
|
||||
@@ -99,173 +70,4 @@ function um_remove_special_users_from_list( $query_args, $args ) {
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
//add_filter( 'um_prepare_user_query_args', 'um_remove_special_users_from_list', 99, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* Adds main parameters
|
||||
*
|
||||
* @param $query_args
|
||||
* @param $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function um_prepare_user_query_args( $query_args, $args ) {
|
||||
extract( $args );
|
||||
|
||||
$query_args['fields'] = 'ID';
|
||||
|
||||
$query_args['number'] = 0;
|
||||
|
||||
$query_args['meta_query']['relation'] = 'AND';
|
||||
|
||||
// must have a profile photo
|
||||
if ( $has_profile_photo == 1 ) {
|
||||
if ( UM()->options()->get( 'use_gravatars' ) ) {
|
||||
$query_args['meta_query'][] = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'synced_profile_photo', // addons
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
),
|
||||
array(
|
||||
'key' => 'profile_photo', // from upload form
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
),
|
||||
array(
|
||||
'key' => 'synced_gravatar_hashed_id', // gravatar
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
)
|
||||
|
||||
);
|
||||
} else {
|
||||
$query_args['meta_query'][] = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'synced_profile_photo', // addons
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
),
|
||||
array(
|
||||
'key' => 'profile_photo', // from upload form
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// must have a cover photo
|
||||
if ( $has_cover_photo == 1 ) {
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => 'cover_photo',
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// show specific usernames
|
||||
if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) {
|
||||
foreach ( $show_these_users as $username ) {
|
||||
$users_array[] = username_exists( $username );
|
||||
}
|
||||
$query_args['include'] = $users_array;
|
||||
}
|
||||
|
||||
// add roles to appear in directory
|
||||
if ( ! empty( $roles ) ) {
|
||||
//since WP4.4 use 'role__in' argument
|
||||
$query_args['role__in'] = $roles;
|
||||
}
|
||||
|
||||
// sort members by
|
||||
$query_args['order'] = 'ASC';
|
||||
|
||||
if ( isset( $sortby ) ) {
|
||||
|
||||
if ( $sortby == 'other' && $sortby_custom ) {
|
||||
|
||||
$query_args['meta_key'] = $sortby_custom;
|
||||
$query_args['orderby'] = 'meta_value, display_name';
|
||||
|
||||
} elseif ( 'display_name' == $sortby ) {
|
||||
|
||||
$display_name = UM()->options()->get( 'display_name' );
|
||||
if ( $display_name == 'username' ) {
|
||||
$query_args['orderby'] = 'user_login';
|
||||
$order = 'ASC';
|
||||
} else {
|
||||
$query_args['meta_query'][] = array(
|
||||
'relation' => 'OR',
|
||||
'full_name' => array(
|
||||
'key' => 'full_name',
|
||||
'compare' => 'EXISTS'
|
||||
),
|
||||
array(
|
||||
'key' => 'full_name',
|
||||
'compare' => 'NOT EXISTS'
|
||||
)
|
||||
);
|
||||
|
||||
$query_args['orderby'] = 'full_name, display_name';
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
} elseif ( in_array( $sortby, array( 'last_name', 'first_name' ) ) ) {
|
||||
|
||||
$query_args['meta_key'] = $sortby;
|
||||
$query_args['orderby'] = 'meta_value';
|
||||
|
||||
} else {
|
||||
|
||||
if ( strstr( $sortby, '_desc' ) ) {
|
||||
$sortby = str_replace( '_desc', '', $sortby );
|
||||
$order = 'DESC';
|
||||
}
|
||||
|
||||
if ( strstr( $sortby, '_asc' ) ) {
|
||||
$sortby = str_replace('_asc','',$sortby);
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
$query_args['orderby'] = $sortby;
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $order ) ) {
|
||||
$query_args['order'] = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_modify_sortby_parameter
|
||||
* @description Change query sort by attributes for search at Members Directory
|
||||
* @input_vars
|
||||
* [{"var":"$query_args","type":"array","desc":"Query Arguments"},
|
||||
* {"var":"$sortby","type":"string","desc":"Sort by"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_modify_sortby_parameter', 'function_name', 10, 2 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_modify_sortby_parameter', 'my_modify_sortby_parameter', 10, 2 );
|
||||
* function my_modify_sortby_parameter( $query_args, $sortby ) {
|
||||
* // your code here
|
||||
* return $query_args;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$query_args = apply_filters( 'um_modify_sortby_parameter', $query_args, $sortby );
|
||||
|
||||
}
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
//add_filter( 'um_prepare_user_query_args', 'um_prepare_user_query_args', 10, 2 );
|
||||
//add_filter( 'um_prepare_user_query_args', 'um_remove_special_users_from_list', 99, 2 );
|
||||
Reference in New Issue
Block a user