Support » Plugin: Improved user search in backend » multisite network admin improved user search

  • I started working on an extension of this plugin to WP Multisite, but have not gotten too far. I reset the options page as a subpage instead, and attempted to implement a naive search improvement based on this:

    However, I did not see results. Would be interested in properly porting the single-site improvement to the network admin user page, but unsure of how the network search query is constructed.

    Code thus far:

    Plugin Name: Improved User Search in Backend
    Plugin URI:
    Description:  Improves the search for users in the backend significantly: Search for first name, last, email and more of users instead of only nicename.
    Version: 1.2.3
    Author: David Stöckl
    Author URI:
    /* version check */
    global $wp_version;
    if(version_compare($wp_version,"3.0","<")) {
    	exit('Improved User Search in Backend requires WordPress version 3.0 or higher. <a href="">Please update!</a>');
    // all of this is only for admin interface, is_admin does not check for admin user role
    if( is_admin() ) {
    	// add the overwrite actions for the search
    	if (!is_network_admin() ) {
    		add_action('pre_user_query', 'user_search_by_multiple_parameters');
    	/*if ( is_network_admin() ) {
    		add_action('pre_user_query', 'network_user_search_by_multiple_parameters');
    	// add the backend menu page
    	if (!is_network_admin() ) {
    	/*if ( is_network_admin() ) {
      // network search improvement option
    /*  function network_user_search_by_multiple_parameters($wp_user_query) {
    	echo "Hello three";
    	if(false === strpos($wp_user_query->query_where, '@') && !empty($_GET["s"])) {
    		$wp_user_query->query_where = str_replace(
    		"user_nicename LIKE '%".mysql_real_escape_string($_GET["s"])."%'",
    		"user_nicename LIKE '%".mysql_real_escape_string($_GET["s"])."%'
    		OR user_login LIKE '%".mysql_real_escape_string($_GET["s"])."%'
    		OR display_name LIKE '%".mysql_real_escape_string($_GET["s"])."%'
    		OR user_email LIKE '%".mysql_real_escape_string($_GET["s"])."%'", $wp_user_query->query_where);
    	return $wp_user_query;
      } */
      // the actual improvement of the query
        function user_search_by_multiple_parameters($wp_user_query) {
            if(false === strpos($wp_user_query->query_where, '@') && !empty($_GET["s"])) {
                global $wpdb;
    			// get the custom meta fields to search
    			$iusib_custom_meta = get_option('iusib_meta_fields');
    			$iusib_cma = explode(",",$iusib_custom_meta);
    			$iusib_add = "";
    			// the escaped query string
    			$qstr = mysql_real_escape_string($_GET["s"]);
    			// add all custom fields into the query
    			if(!empty($iusib_cma)) {
    				$iusib_add = " OR meta_key='".implode("' OR meta_key='",$wpdb->escape($iusib_cma))."'";
                $usermeta_affected_ids = $wpdb->get_results("SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE (meta_key='first_name' OR meta_key='last_name'".$iusib_add.") AND LOWER(meta_value) LIKE '%".$qstr."%'");
                foreach($usermeta_affected_ids as $maf) {
                $users_affected_ids = $wpdb->get_results("SELECT DISTINCT ID FROM $wpdb->users WHERE LOWER(user_nicename) LIKE '%".$qstr."%' OR LOWER(user_email) LIKE '%".$qstr."%'");
                foreach($users_affected_ids as $maf) {
                    if(!in_array($maf->ID,$uids)) {
                $id_string = implode(",",$uids);
                $wp_user_query->query_where = str_replace("user_nicename LIKE '%".$qstr."%'", "ID IN(".$id_string.")", $wp_user_query->query_where);
            return $wp_user_query;
        // add the options page
        function improved_user_search_in_backend_options() {
        	if (!is_network_admin() ) {
    		add_options_page('User Search','User Search',
        // add the network options page
    /*    function improved_user_search_in_backend_network_options() {
    	if ( is_network_admin() ) {
    		add_submenu_page('settings.php','User Search','User Search',
    	// add the options page
    	function improved_user_search_in_backend_page() { ?>
    		<div class="wrap">
    			<div><?php screen_icon('options-general'); ?></div>
    			<h2>Settings: Improved user search in backend</h2>
    			if(isset($_POST['improved_user_search_in_backend_update']) && $_POST['improved_user_search_in_backend_update']!="") {
    				// remove whitespace
    				$sanitized = implode(",",array_map('trim', explode(",",$_POST['iusib_meta_fields'])));
    				update_option('iusib_meta_fields',stripslashes($sanitized)); ?>
    					<div id="setting-error-settings_updated" class="updated settings-error">
    						<p><strong><?php _e('Settings saved successfully.','improved-user-search-in-backend'); ?></strong></p>
    			<?php } ?>
    			<form name="improved_user_search_in_backend_update" method="post" action="">
    					<table class="form-table">
    						<tr valign="top">
    							<th scope="row">Custom Meta Fields (comma seperated)</th>
    							<td><textarea name="iusib_meta_fields" rows="6" cols="50"><?php echo get_option('iusib_meta_fields'); ?></textarea></td>
    							<td class="description">Add custom user meta fields from your usermeta table for integration in the user search (e.g. "url", "description", "aim", or custom like "birthday")</td>
    					<p><input type="hidden" name="improved_user_search_in_backend_update" value="true" />
    					<input type="submit" name="Save" value="Save Settings" class="button-primary" /></p>
    	<?php }
    function improved_user_search_in_backend_activate() {
    function improved_user_search_in_backend_uninstall() {
    	// delete all options, tables, ...

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Blackbam


    Hello there

    maybe I will have a look at your code soon to make a multisite extension, but currently this Plugin seems not to be compatible with a multisite installation.

    BR David



    Totally interested in this, +1 and following



    Excellent, Ikraav, I haven’t had time to jump back into this–but it would be very handy.

    Blackbam, any possibility of revisiting this for multisite compatibility? Or any insight on network search queries?

    Plugin Author Blackbam


    Hello again I think it is possible to create a search like this for multisite installations, too, but I think the approach is different. You have to go through the WordPress core and probably build a much more complex Plugin which I may do but unfortunatly it is not possible for me in near time.

    Please tell if you have progress regarding this topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘multisite network admin improved user search’ is closed to new replies.