From 23abfa9dd86dc9bf274122920d3bd0475177adec Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Thu, 18 Jun 2015 10:39:28 -0700 Subject: [PATCH 1/2] Added User Filtering --- UserTags.php | 76 +++++++++++++++++++++++++++++++++++++- assets/js/user_taxonomy.js | 14 +++++++ 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/UserTags.php b/UserTags.php index 53dd674..ed2e26e 100755 --- a/UserTags.php +++ b/UserTags.php @@ -64,6 +64,10 @@ public function __construct() { add_action( 'edit_user_profile_update', array( $this, 'ut_save_profile' ) ); add_filter( 'sanitize_user', array( $this, 'restrict_username' ) ); add_action( 'wp_head', array( $this, 'admin_ajax' ) ); + + // User Query Filter + add_filter( 'pre_user_query', array( $this, 'ut_users_filter_query' ) ); + add_action( 'restrict_manage_users', array( $this, 'ut_users_filter' ) ); } function ut_enqueue_scripts( $hook ) { @@ -377,8 +381,7 @@ public function set_user_column_values( $display, $column, $term_id ) { $args = array( 'taxonomy' => $tax->name, 'term' => $term->slug ); } - return $count; -// return "$count"; + return "".$count.""; } /** @@ -560,6 +563,75 @@ function admin_ajax() { 32 ? substr( $taxonomy_slug, 0, 32 ) : $taxonomy_slug; + $taxonomy = get_taxonomy($taxonomy_slug); + if ( $taxonomy && isset( $_GET[$taxonomy_slug] ) && ! empty( $_GET[$taxonomy_slug] ) ) { + $term_slug = $_GET[$taxonomy_slug]; + continue; + } + } + } + } + + if ( ! empty( $term_slug ) ) { + $query->query_from .= " INNER JOIN {$wpdb->term_relationships} ON {$wpdb->users}.`ID` = {$wpdb->term_relationships}.`object_id` INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_relationships}.`term_taxonomy_id` = {$wpdb->term_taxonomy}.`term_taxonomy_id` INNER JOIN {$wpdb->terms} ON {$wpdb->terms}.`term_id` = {$wpdb->term_taxonomy}.`term_id`"; + $query->query_where .= " AND {$wpdb->terms}.`slug` = '{$term_slug}'"; + } + + return $query; + + } + + /** + * User Filter + */ + function ut_users_filter() { + $ut_taxonomies = get_site_option( 'ut_taxonomies' ); + if ( empty( $ut_taxonomies ) || ! is_array( $ut_taxonomies ) ) { + return; + } + + foreach ( $ut_taxonomies as $ut_taxonomy ) { + extract( $ut_taxonomy ); + $taxonomy_slug = ! empty( $slug ) ? $slug : ut_taxonomy_name( $name ); + $taxonomy_slug = strlen( $taxonomy_slug ) > 32 ? substr( $taxonomy_slug, 0, 32 ) : $taxonomy_slug; + $taxonomy = get_taxonomy($taxonomy_slug); + if ( $taxonomy ) { ?> + + + Date: Thu, 18 Jun 2015 10:50:50 -0700 Subject: [PATCH 2/2] Added Reset Button --- UserTags.php | 7 ++++++- assets/css/style.css | 9 +++++++++ assets/js/user_taxonomy.js | 10 +++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/UserTags.php b/UserTags.php index ed2e26e..0192393 100755 --- a/UserTags.php +++ b/UserTags.php @@ -615,7 +615,7 @@ function ut_users_filter() { $taxonomy = get_taxonomy($taxonomy_slug); if ( $taxonomy ) { ?> - + Reset Filters +