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

bbp_make_current_user_keymaster(); 

Usage

  1. if ( !function_exists( 'bbp_make_current_user_keymaster' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/update.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_make_current_user_keymaster(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/core/update.php  
  1. function bbp_make_current_user_keymaster() { 
  2.  
  3. // Bail if the current user can't activate plugins since previous pageload 
  4. if ( ! current_user_can( 'activate_plugins' ) ) { 
  5. return; 
  6.  
  7. // Get the current user ID 
  8. $user_id = get_current_user_id(); 
  9. $blog_id = get_current_blog_id(); 
  10.  
  11. // Bail if user is not actually a member of this site 
  12. if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) { 
  13. return; 
  14.  
  15. // Bail if the current user already has a forum role to prevent 
  16. // unexpected role and capability escalation. 
  17. if ( bbp_get_user_role( $user_id ) ) { 
  18. return; 
  19.  
  20. // Make the current user a keymaster 
  21.  
  22. // Reload the current user so caps apply immediately 
  23. wp_get_current_user();