WordPress.org

Ready to get started?Download WordPress

Forums

update_user_level_from_caps() broken in 3.3.1? (3 posts)

  1. bigsite
    Member
    Posted 2 years ago #

    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?

  2. bigsite
    Member
    Posted 2 years ago #

    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.

  3. Andrew Nacin
    Lead Developer
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.