• Resolved letsserveit

    (@letsserveit)


    Just updated to the latest version of wordpress, and not too happy with the results.

    I use the search function on the users superadmin tab a few times a week, to search for email domains such as 163.com who has signed up, as these users are generally spam, i look for domains that has come up a few times, and then search for the domain name in search users – the previously version used to bring up the results of any users using a email address matching the search string, and then I would just select all and mark as spam.

    This no longer works!

    does anyone have any ideas?

Viewing 7 replies - 16 through 22 (of 22 total)
  • For those still wanting to search in the email field, like before, you can add these lines of code to your theme “functions.php” file:

    if(is_admin()) {
      add_action( 'pre_user_query', 'user_search_by_email' );
      function user_search_by_email($wp_user_query) {
        if(false === strpos($wp_user_query->query_where, '@')) {
          $wp_user_query->query_where = substr(trim($wp_user_query->query_where), 0, -1 )." OR user_email LIKE '%".mysql_real_escape_string($_GET["s"])."%')";
        }
        return $wp_user_query;
      }
    }

    It’s so small, that i don’t think i needed a plugin just for this.

    I had to come up with this, because people were used to search users for parts of the the email (ex: “abc” to match “[email protected]”).

    Hope this helps.
    Cheers!

    you can add these lines of code to your theme “functions.php” file:

    It woudl be better for something like this to go in the mu-plugins folder. This is exactly the kind of code you would place there and you don’t need a plugin header nor does it need to be activated.

    It is not as appropriate to place it in theme files, as it’s not theme dependent.

    I understand that Andrea. Since i’m using a regular WordPress 3.x installation (not the MU), is there an “equivalent folder” where i can store this lines of code?
    TIA.

    Same folder. It’s not even mu anymore in the code, and as the codex page I linked to explains, this folder has been in WordPress single since 2.8.

    mu-plugins is a backronym. Doesn’t mean it’s for multisite only.

    For those still wanting to search in the email field, like before, you can add these lines of code to your theme “functions.php” file:

    if(is_admin()) {
    add_action( ‘pre_user_query’, ‘user_search_by_email’ );
    function user_search_by_email($wp_user_query) {
    if(false === strpos($wp_user_query->query_where, ‘@’)) {
    $wp_user_query->query_where = substr(trim($wp_user_query->query_where), 0, -1 ).” OR user_email LIKE ‘%”.mysql_real_escape_string($_GET[“s”]).”%’)”;
    }
    return $wp_user_query;
    }
    }

    Definitely a great alternative. Many of those who participate in this discussions play smart but only the rare ones give really a smart solution to solve a issue. Congratulations and many thanks!

    Please correct the above code with this instead:

    if(is_admin()) {
      add_action( 'pre_user_query', 'user_search_by_email' );
      function user_search_by_email($wp_user_query) {
        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_email LIKE '%".mysql_real_escape_string($_GET["s"])."%'",
                  $wp_user_query->query_where);
        }
        return $wp_user_query;
      }
    }

    Sorry folks, but the previous code prevented from searching users by role. This approach is better and corrects that.

    @gon?alo Thanks for the code.

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Using User Search’ is closed to new replies.