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
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
| 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.