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 bbPress, regardless of the bbp_allow_global_access() setting.
Description Description
Return Return
(If) user can't activate plugins or is already a keymaster
Source Source
File: includes/core/update.php
function bbp_make_current_user_keymaster() { // Catch all, to prevent premature user initialization if ( ! did_action( 'set_current_user' ) ) { return; } // Bail if not logged in or already a member of this site if ( ! is_user_logged_in() ) { return; } // Bail if the current user can't activate plugins since previous pageload if ( ! current_user_can( 'activate_plugins' ) ) { return; } // Cannot use bbp_get_current_user_id() during activation process $user_id = get_current_user_id(); // Get the current blog ID, to know if they should be promoted here $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 |
---|---|
2.4.0 | Introduced. |