bb_apply_wp_role_map_to_orphans

The BuddyPress bb apply wp role map to orphans function.

Description

bb_apply_wp_role_map_to_orphans(); 

Usage

  1. if ( !function_exists( 'bb_apply_wp_role_map_to_orphans' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-users.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_apply_wp_role_map_to_orphans(); 
  7.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-users.php  
  1. function bb_apply_wp_role_map_to_orphans() { 
  2. if ( !$wordpress_table_prefix = bb_get_option('wp_table_prefix') ) { 
  3. return; 
  4.  
  5. if ( $wordpress_mu_primary_blog_id = bb_get_option( 'wordpress_mu_primary_blog_id' ) ) { 
  6. $wordpress_table_prefix .= $wordpress_mu_primary_blog_id . '_'; 
  7.  
  8. $role_query = <<<EOQ 
  9. SELECT 
  10. ID 
  11. FROM 
  12. `%1\$s` 
  13. LEFT JOIN `%2\$s` AS bbrole 
  14. ON ID = bbrole.user_id 
  15. AND bbrole.meta_key = '%3\$scapabilities' 
  16. LEFT JOIN `%2\$s` AS wprole 
  17. ON ID = wprole.user_id 
  18. AND wprole.meta_key = '%4\$scapabilities' 
  19. WHERE 
  20. bbrole.meta_key IS NULL OR 
  21. bbrole.meta_value IS NULL OR 
  22. wprole.meta_key IS NULL OR 
  23. wprole.meta_value IS NULL 
  24. ORDER BY 
  25. ID 
  26. EOQ; 
  27.  
  28. global $bbdb; 
  29.  
  30. $role_query = $bbdb->prepare( $role_query, $bbdb->users, $bbdb->usermeta, $bbdb->prefix, $wordpress_table_prefix ); 
  31.  
  32. if ( $user_ids = $bbdb->get_col( $role_query ) ) { 
  33. foreach ( $user_ids as $user_id ) { 
  34. bb_apply_wp_role_map_to_user( $user_id, false );