• I used to be able to extract the maximum user level in 3.2.1 and earlier with:

    $user = wp_authenticate($username, $password);
    if (!is_wp_error($user)) $user->update_user_level_from_caps();

    Then I scanned the $user object for “user_level” entries to calculate the actual maximum user level. The changes in 3.3.1 to WP_User break my code. My code has been working fine since WPMU 2.7.

    All I really care about is: “Does this user account have permissions to do anything beyond ‘Subscriber’ in a multisite setup?” How do I go about doing this now?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bigsite

    (@bigsite)

    I fixed my code by doing:

    http://pastebin.com/L2Bv7sen

    Accessing the database directly is SO much cleaner than trying to parse an object that could change between versions. I realize user levels are “deprecated”, but the devs directly admit that user levels vs. capabilities are “a mess”:

    http://core.trac.wordpress.org/ticket/16841

    User levels are still quite useful for answering the question, “Does the user have ANY permissions?” That is a true/false answer so any non-zero value is fine by me. But the above function could be useful for someone stuck in the past with an old code base.

    I am not sure how update_user_level_from_caps() broke in 3.3, but I would be interested in tracking down why.

    You can do this instead:

    $keys = get_user_meta( $user_id );

    And then loop through them to look for *_user_level keys. It’s a better approach to a direct query.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘update_user_level_from_caps() broken in 3.3.1?’ is closed to new replies.