Skip to:
Content

bbPress.org

Changeset 4910


Ignore:
Timestamp:
05/15/2013 05:39:17 PM (13 years ago)
Author:
johnjamesjacoby
Message:

When activating bbPress, conditionally make the current user a Key Master, but only if they can already activate plugins, they are already a member of the current site, and they're not already a Key Master. Fixes activation issues some users experienced with old global access settings being turned off, preventing them from seeing bbPress configuration screens. (trunk)

Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/actions.php

    r4390 r4910  
    6464
    6565// Activation
    66 add_action( 'bbp_activation', 'bbp_delete_rewrite_rules'    );
     66add_action( 'bbp_activation', 'bbp_delete_rewrite_rules'        );
     67add_action( 'bbp_activation', 'bbp_make_current_user_keymaster' );
    6768
    6869// Deactivation
  • trunk/includes/core/update.php

    r4849 r4910  
    302302    set_transient( '_bbp_activation_redirect', true, 30 );
    303303}
     304
     305/**
     306 * Hooked to the 'bbp_activate' action, this helper function automatically makes
     307 * the current user a Key Master in the forums if they just activated bbPress,
     308 * regardless of the bbp_allow_global_access() setting.
     309 *
     310 * @since bbPress (r4910)
     311 *
     312 * @internal Used to internally make the current user a keymaster on activation
     313 *
     314 * @uses current_user_can() to bail if user cannot activate plugins
     315 * @uses get_current_user_id() to get the current user ID
     316 * @uses get_current_blog_id() to get the current blog ID
     317 * @uses is_user_member_of_blog() to bail if the current user does not have a role
     318 * @uses bbp_is_user_keymaster() to bail if the user is already a keymaster
     319 * @uses bbp_set_user_role() to make the current user a keymaster
     320 *
     321 * @return If user can't activate plugins or is already a keymaster
     322 */
     323function bbp_make_current_user_keymaster() {
     324
     325        // Bail if the current user can't activate plugins since previous pageload
     326        if ( ! current_user_can( 'activate_plugins' ) )
     327                return;
     328
     329        // Get the current user ID
     330        $user_id = get_current_user_id();
     331        $blog_id = get_current_blog_id();
     332
     333        // Bail if user is not actually a member of this site
     334        if ( ! is_user_member_of_blog( $user_id, $blog_id ) )
     335                return;
     336
     337        // Bail if the current user is already a keymaster
     338        if ( bbp_is_user_keymaster( $user_id ) )
     339                return;
     340
     341        // Make the current user a keymaster
     342        bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     343}
Note: See TracChangeset for help on using the changeset viewer.