Making WordPress.org


Ignore:
Timestamp:
04/30/2021 08:06:27 AM (5 years ago)
Author:
dd32
Message:

Support: Use an implementation of WP_User::has_role() instead of WP_User::has_cap().

WordPress doesn't have a WP_User::has_role() because you should always check for a cap instead, well, super admins have all caps, including bbp_blocked!

This caused a super admin being set to bbp_participant to end up with a broken password, as $user->has_cap( 'bbp_blocked' ) && ! $password_broken === true.

Follow up to [10918].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r10918 r10939  
    13161316        $note_text       = false;
    13171317
     1318        // WP_User::has_role() does not exist, and WP_User::has_cap( 'bbp_blocked' ) will be truthful for super admins.
     1319        $user_has_blocked_role = ! empty( $user->roles ) && in_array( $blocked_role, $user->roles, true );
     1320
    13181321        if (
    1319             ( $blocked_role === $new_role || $user->has_cap( $blocked_role ) ) &&
     1322            ( $blocked_role === $new_role || $user_has_blocked_role ) &&
    13201323            ! $password_broken
    13211324        ) {
     
    13451348        } else if (
    13461349            $password_broken &&
    1347             ! $user->has_cap( $blocked_role )
     1350            ! $user_has_blocked_role
    13481351        ) {
    13491352            // User was blocked (broken password) but no longer is.
Note: See TracChangeset for help on using the changeset viewer.