Skip to:
Content

bbPress.org

Changeset 4759


Ignore:
Timestamp:
02/07/2013 01:59:43 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Backport roles improvements to 2.2 branch.

  • bbp_add_forums_roles() now returns the modified roles global.
  • Hardening around saving a user's role when editing their profile.
  • Call bbp_add_forums_roles() in a few places to make sure roles are added before using add_role() or set_role().
Location:
branches/2.2/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/includes/core/capabilities.php

    r4453 r4759  
    336336        $wp_roles->role_names[$role_id]   = $details['name'];
    337337    }
     338
     339    return $wp_roles;
    338340}
    339341
  • branches/2.2/includes/users/capabilities.php

    r4449 r4759  
    8282            // Add the new role
    8383            if ( !empty( $new_role ) ) {
     84
     85                // Make sure bbPress roles are added
     86                bbp_add_forums_roles();
     87
    8488                $user->add_role( $new_role );
    8589            }
     
    137141 */
    138142function bbp_get_user_blog_role( $user_id = 0 ) {
    139     global $wp_roles;
    140 
    141     // This really shold not be necessary anymore, and will likely be removed
    142     // at a later date. If roles aren't loaded yet, something else is wrong.
    143     if ( ! isset( $wp_roles ) )
    144         $wp_roles = new WP_Roles();
     143
     144    // Add bbPress roles (returns $wp_roles global)
     145    $wp_roles  = bbp_add_forums_roles();
    145146
    146147    // Validate user id
     
    164165
    165166/**
    166  * Helper function hooked to 'bbp_edit_user_profile_update' action to save or
     167 * Helper function hooked to 'bbp_profile_update' action to save or
    167168 * update user roles and capabilities.
    168169 *
     
    187188    $forums_role = bbp_get_user_role( $user_id );
    188189
     190    // Bail if no role change
     191    if ( $new_role == $forums_role )
     192        return;
     193
     194    // Bail if trying to set their own role
     195    if ( bbp_is_user_home_edit() )
     196        return;
     197
     198    // Bail if current user cannot promote the passing user
     199    if ( ! current_user_can( 'promote_user', $user_id ) )
     200        return;
     201
    189202    // Set the new forums role
    190     if ( $new_role != $forums_role ) {
    191         bbp_set_user_role( $user_id, $new_role );
    192     }
     203    bbp_set_user_role( $user_id, $new_role );
    193204}
    194205
     
    267278    // Add the user to the site
    268279    if ( true == $add_to_site ) {
     280
     281        // Make sure bbPress roles are added
     282        bbp_add_forums_roles();
     283
    269284        $bbp->current_user->add_role( $new_role );
    270285
    271286    // Don't add the user, but still give them the correct caps dynamically
    272     } else {       
     287    } else {
    273288        $bbp->current_user->caps[$new_role] = true;
    274289        $bbp->current_user->get_role_caps();
     
    370385    // Bail if no user ID
    371386    if ( empty( $user_id ) )
    372         return;
     387        return false;
    373388
    374389    // Bail if user ID is super admin
    375390    if ( is_super_admin( $user_id ) )
    376         return;
     391        return false;
    377392
    378393    // Arm the torpedos
     
    422437        restore_current_blog();
    423438    }
     439
     440    // Success
     441    return true;
    424442}
    425443
     
    455473    // Bail if no user ID
    456474    if ( empty( $user_id ) )
    457         return;
     475        return false;
    458476
    459477    // Bail if user ID is super admin
    460478    if ( is_super_admin( $user_id ) )
    461         return;
     479        return false;
    462480
    463481    // Arm the torpedos
     
    507525        restore_current_blog();
    508526    }
     527
     528    // Success
     529    return true;
    509530}
    510531
Note: See TracChangeset for help on using the changeset viewer.