Forums

[resolved] current_user_can broken using multisite (7 posts)

  1. af.
    Member
    Posted 1 year ago #

    I've been using this code:
    if (is_user_logged_in() && !current_user_can('subscriber')) { [...] }
    ... fine for a while now to show something only to users logged in above the level of subscribers (authors, admins, etc).

    Recently I upgraded my install of WordPress to use the Multisite feature and ever since this bit of code has not worked.

    Has anyone else had problems with current_user_can and Multisite?

  2. Andrea_r
    team pirate
    Posted 1 year ago #

    current_user_can('subscriber')

    Becasue on subsites, if they are not expressly listed as a user on that site, then this would return false.

  3. af.
    Member
    Posted 1 year ago #

    I haven't started using any other subsites yet though so surely all the users from before the switch should be listed as users of the (main) site that this code is on?

    Also, I am negating the current_user_can('subscriber') so even if it was returning false then that shouldn't matter...

  4. Ron Rennick
    MultiSite Guru
    Posted 1 year ago #

    current_user_can('read') is the equivalent of a subscriber. See http://codex.wordpress.org/Roles_and_Capabilities#Administrator for a complete list.

  5. af.
    Member
    Posted 1 year ago #

    Thanks, changing the argument from the subscriber role to a different capability seems to have worked :)

  6. Andrea_r
    team pirate
    Posted 1 year ago #

    Doh, yeah that was a bad argument to begin with. :)

  7. anmari
    Member
    Posted 9 months ago #

    Actually current_user_can says it will work on role check too

    See
    http://codex.wordpress.org/Function_Reference/current_user_can

Topic Closed

This topic has been closed to new replies.

About this Topic