WordPress.org

Ready to get started?Download WordPress

Forums

[closed] WP_User_Query and Multisite (25 posts)

  1. raskull
    Member
    Posted 2 years ago #

    I am trying to get all users. All users were created in Network Admin. Some have been granted super admin privileges. The others are, according to the quote below, automatically subscribers. There are no role options offered in Network Admin.

    Using WP_User_Query I can only seem to get the super admins.

    And this yields no one:
    new WP_User_Query( array( 'role' => 'subscriber' ) )

    What gives? How do I get all users created in Network Admin?

    User Access: By design, all users who are added to your network will have subscriber access to all sites on your network. To allocate a different default role for users on individual sites, you must use a plugin, such as Multisite User Management.
    http://codex.wordpress.org/Create_A_Network

  2. They're psudeo subscribers. For most sites, they have the same access as a logged-out user, and they don't show up on the user lists.

    Where are you trying to get all users?

    The network admin -> Users lists has 'em all.

  3. raskull
    Member
    Posted 2 years ago #

    I want to display all users on the front end, as a company's employee directory. How can I do that using the users created in network admin? How to call all users even if they are pseudo users with pseudo roles?

  4. Not easily. They don't exist as a part of any blog, so they aren't listed in an easily accessible way.

    Can you add them all to the main site as subscribers for REAL and use that?

  5. raskull
    Member
    Posted 2 years ago #

    I COULD, but that would be a semantically sad use of the multisite framework. The users (employees) are all part of the multisite (company), with different permissions per individual site (department).

    These users and their attributes exist in the database. As such, shouldn't I be able to query for them?

  6. Yes, but it's a DB query since the WP functinos are per-site.

    Wouldn't everyone be a member of the main (company) site though? I mean I'm assuming you have this:

    domain.com - Main site. my cool company

    domain.com/hr - HR's site

    domain.com/mail - the mailroom guys

    etc etc.

  7. raskull
    Member
    Posted 2 years ago #

    Hmph... I suppose so... but it still doesn't seem quite right...

    WP_User_Query( array( 'blog_id' => 1 ) )

    I guess I don't see why creating (pseudo) users in network admin is even offered as an option then...

    Huh, wait... I, super admin, can create them in network admin, whereupon they will get an email to login to their profile, which they can fill in. Then I can check it and correct it before assigning them as a subscriber to the main site, whereupon they will be listed in the directory...

    I wonder if there's a way that I, super admin, can get an email when a (pseudo) user or (real) user changes their profile?

  8. You can use a plugin to auto-add all new users to the main site.

    http://wordpress.org/extend/plugins/multisite-user-management/

  9. raskull
    Member
    Posted 2 years ago #

    Hmmmmm. Since we are now blog-specific... why not use the "author" functionality: wp_list_authors() and author.php for the author (employee) detail page?

    It seems "author" = "user" if including the argument hide_empty=0 (show users even if they haven't posted anything)

    Wouldn't this be more efficient?

  10. I have a sneeking memory that author == user with at least a post. I could be wrong. It's been a while.

    There's a pay-for plugin called Members Directory which touts that it can do it, but it's behind a paywall.

  11. raskull
    Member
    Posted 2 years ago #

    Unless my back is up against the wall, I try to forgo plugins, free or paid. (Apparently, I like reinventing the wheel.)

    But author does = user if you set hide_empty (has no posts) to false. At least it did in my limited test.

  12. Aaaaaah! That would do it. :D

    I'm pro plugin but anti-paywall. I fork a lot of plugins for what I need. :)

  13. raskull
    Member
    Posted 2 years ago #

    Wish I knew how to fork!

    Meanwhile it's time to throw roleless users vs postless authors into the ring to see who comes up fighting...

  14. Fork: Take someone else's plugin. Make edits. Change the plugin name and version number so their updates don't whack yours. Have a beer!

  15. raskull
    Member
    Posted 2 years ago #

    I understood step 4 anyway... Will start there.

  16. modifiedcontent
    Member
    Posted 2 years ago #

    I'm trying to figure out the same thing and it is utterly ridiculous that this should require complicated custom coding or plugins.

    Automattic apparently developed multisite for the WordPress.com use case; a network of blogs that are completely independent of eachother. That use case would make sense for maybe a big hosting company.

    Normal people in the real world will almost never use multisite that way. Most will try to use WP multisite as a network for an organization or company, only to find out the hard way that letting "users" interact on the platform is virtually impossible.

    Yes, being forced to add all users to the main blog is "a semantically sad use of the multisite framework". In my case the main blog is used for organization news and announcement, so it's the last place I want to have overrun by members/"users".

    So we're supposed to use half-baked plugins and hacks to fix the mess again.

    Can anyone give a basic example of a custom query to list all users in the 'users' database table?

  17. modifiedcontent
    Member
    Posted 2 years ago #

    This basically works:

    <?
    $wp_user_search = $wpdb->get_results("SELECT ID, display_name, user_registered FROM $wpdb->users ORDER BY user_registered DESC LIMIT 7");
    foreach ( $wp_user_search as $userid ) {
    	$user_id       = (int) $userid->ID;
    	$user_login    = stripslashes($userid->user_login);
    	$display_name  = stripslashes($userid->display_name);
    	$return  = '';
    	$return .= "\t" . '<li>'. $display_name .'</li>' . "\n";
    	print($return);
    }
     ?>

    Now I have to figure out how to split the return/echo stuff from the PHP...

    What are the arguments against doing it this way? Are there better ways? Maybe using WP_User_Query somehow?

  18. modifiedcontent
    Member
    Posted 2 years ago #

    This also works:

    <?php
    
     $querystr = "
        SELECT $wpdb->users.*
        FROM $wpdb->users
        ORDER BY $wpdb->users.user_registered DESC LIMIT 10
     ";
    
     $listmembers = $wpdb->get_results($querystr, OBJECT);
    
     ?>
     <?php if ($listmembers): ?>
     <?php global $member; ?>
     <?php foreach ($listmembers as $member): ?>
     <?php setup_postdata($member); ?>
    <p><? echo $member->display_name ?></p>
     <?php endforeach; ?>
     <?php else: ?>
        <h2>You got nuthin...</h2>
     <?php endif; ?>

    Again, are there arguments against this approach? Is there a better way?

    To get from here to the blog specific data raskull needed is another story of course. These multisite functions and methods could be useful.

  19. Yes, WordPress Multisite was designed to with WordPress.com in mind as the sample.

    It's not a huge thing to code, it's just no one's done it and come back to say 'This is what I did and how it works.' It's only custom because there wasn't a need case. (I can think of maybe 5 times this has come up in 3 years, compared to over 300 times I've been asked why you can't get rid of the /blog/ slug in SubDirectory installs. I'd really rather they fix the slug first ;) )

    As a stopgap, if you don't want to write the calls yourself, you could use http://wordpress.org/extend/plugins/multisite-user-management/ and add them all to a 'fake' blog.

    Or go check out BuddyPress. I'm sure it's overkill for many people, but you can see how they make a list of all members. http://buddypress.org/community/members as an example. You could download their code and check it out.

  20. modifiedcontent
    Member
    Posted 2 years ago #

    Thanks for your response.

    ... over 300 times I've been asked why you can't get rid of the /blog/ slug in SubDirectory installs ...

    That's another one I wasted one or two days on solving.

    Or go check out BuddyPress

    I have tried Buddypress for about two years since it first came out and it just got worse and worse. I have just junked that pile of garbage and am now trying to simplify/streamline my projects on standard WP multisite with as few plugins as possible.

    The Multisite User Management plugin is mentioned for every multisite user management problem and is simply not a solution. It only lets you manually add users to blogs on the network, which is useless if you try to use multisite for a company or membership organization.

    Yes, WordPress Multisite was designed to with WordPress.com in mind as the sample.

    Why?! Who would use it like that?

  21. About 80% of Multisite users, at the last check (based on people who reply to such surveys), use Multisite for multiple, separate, sites. The other 10% either really want totally separate sites with separate user bases or, like you, a totally integrated site where everything's shared.

    Instead of trying to be all things for all people, WordPress said 'This is what we are.'

    It only lets you manually add users to blogs on the network, which is useless if you try to use multisite for a company or membership organization.

    No, it lets you automatically assign users a role on a specific site on the domain. So let's say you make a site called members. You set the plugin to make all new users 'subscribers' on the members blog. Then on the front page of the members site, you hard code the php for the members list (or use another plugin: http://wordpress.org/extend/plugins/members-list/ )

    It's not great I grant you, but it gets the job done if you don't want the SQL query :)

    And when I mentioned BuddyPress, please note I was specifically saying "You could download their code and check it out." What I meant by that was not 'use BuddyPress it will cure cancer!' but 'Look at their code, for the members page, and steal it.'

  22. modifiedcontent
    Member
    Posted 2 years ago #

    About 80% of Multisite users, at the last check (based on people who reply to such surveys), use Multisite for multiple, separate, sites

    Who are these people? I really can't imagine many cases where that would make much sense, except maybe a big hosting company or a blog farm advertising scam.

    Those 80% are probably lots of kids in basements starting their own blog farms that never go anywhere.

    WordPress is developed by and for PHP tinkerers, piling on features on top of "what it is" without much thought to what it could be, how it could be used in the real world.

    Creating a members blog feels like a illogical workaround that will only cause problems down the line. It still wouldn't help make a network-wide view of latest posts etc. easier to accomplish.

    Apologies for hijacking/derailing this thread. Was the original question answered? In general, is there a way to make WP_user_query work in multisite, maybe in combination with the blog_id switch stuff?

  23. In general, is there a way to make WP_user_query work in multisite, maybe in combination with the blog_id switch stuff?

    Not without the DB query, as you noted, or adding all the users to a 'member' blog and calling it from there (which after I poked around, seems to be how BuddyPress does it).

  24. SeanD
    Member
    Posted 2 years ago #

    I was having the same problem, then I decided to try using wp_user_query with a blog id of 0. This seems to return all users whether or not they are assigned to a blog. Let me know if you see any downsides.

  25. kirkward
    Member
    Posted 1 year ago #

    About 80% of Multisite users, at the last check (based on people who reply to such surveys), use Multisite for multiple, separate, sites

    Who are these people? I really can't imagine many cases where that would make much sense, except maybe a big hosting company or a blog farm advertising scam.

    Many of them are "Internet Marketers" trying to fool their world (Google) into thinking they have a lot of sites and jumping to the top of the search results for each product page/site.

Topic Closed

This topic has been closed to new replies.

About this Topic