bbp_make_current_user_keymaster()

Hooked to the ‘bbp_activate’ action, this helper function automatically makes the current user a Key Master in the forums if they just activated Forums, regardless of the bbp_allow_global_access() setting.

Description

Return

(If) user can't activate plugins or is already a keymaster

Source

File: bp-forums/core/update.php

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
function bbp_make_current_user_keymaster() {
 
    // Bail if the current user can't activate plugins since previous pageload
    if ( ! current_user_can( 'activate_plugins' ) ) {
        return;
    }
 
    // Get the current user ID
    $user_id = get_current_user_id();
    $blog_id = get_current_blog_id();
 
    // Bail if user is not actually a member of this site
    if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) {
        return;
    }
 
    // Bail if the current user already has a forum role to prevent
    // unexpected role and capability escalation.
    if ( bbp_get_user_role( $user_id ) ) {
        return;
    }
 
    // Make the current user a keymaster
    bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
 
    // Reload the current user so caps apply immediately
    wp_get_current_user();
}

Changelog

Changelog
Version Description
bbPress (r4910) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.