Include/Exclude unnecessarily alters global $current_user-roles

Support MB Include Exclude Include/Exclude unnecessarily alters global $current_user-roles

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2882
    FEDFED
    Participant

    The check_user_role function accesses the global $current_user with the goal of setting the first array item as a new var, $user_role. In using array_shift(), the first item in $current_user->roles is removed. This causes problems if one attempts to continue working with $current_user->roles.

    Suggested solution: Set the $user_role var using a method that does not alter the original array. One method might be to use reset() as shown below.

    Proposed solution:

    File: class-mb-include-exclude.php
    Line: 267

    original:
    $user_role = array_shift( $current_user->roles );

    proposed:
    $user_role = reset( $current_user->roles );

    #2892
    Anh TranAnh Tran
    Keymaster

    You're right about that! I've just pushed a new update with the suggested fix. Thanks a lot for helping me 🙂

    #2893
    FEDFED
    Participant

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Include/Exclude unnecessarily alters global $current_user-roles’ is closed to new replies.