- member directory;

This commit is contained in:
nikitasinelnikov
2019-09-02 16:35:10 +03:00
parent 1b76b1e1bd
commit a7f046fe6f
13 changed files with 936 additions and 1285 deletions
-303
View File
@@ -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;
}