bp_groupblog_upgrade_user

Bp_groupblog_upgrade_user( $user_id, $group_id, $blog_id ).

Description

bp_groupblog_upgrade_user( $user_id, $group_id, (bool) $blog_id = false ); 

Subscribes user in question to blog in question This code was initially inspired by Burt Adsit re-interpreted by Boone

Parameters (3)

0. $user_id
The user id.
1. $group_id
The group id.
2. $blog_id — Optional. (bool) => false
The blog id.

Usage

  1. if ( !function_exists( 'bp_groupblog_upgrade_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog.php'; 
  3.  
  4. // The user id. 
  5. $user_id = null; 
  6.  
  7. // The group id. 
  8. $group_id = null; 
  9.  
  10. // The blog id. 
  11. $blog_id = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_groupblog_upgrade_user($user_id, $group_id, $blog_id); 
  15.  

Defined (1)

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

/bp-groupblog.php  
  1. function bp_groupblog_upgrade_user( $user_id, $group_id, $blog_id = false ) { 
  2. global $bp; 
  3.  
  4. if ( !$blog_id ) 
  5. $blog_id = groups_get_groupmeta ( $group_id, 'groupblog_blog_id' ); 
  6.  
  7. // If the group has no blog linked, get the heck out of here! 
  8. if ( !$blog_id ) 
  9. return; 
  10.  
  11. // Set up some variables 
  12. $groupblog_silent_add = groups_get_groupmeta ( $group_id, 'groupblog_silent_add' ); 
  13. $groupblog_default_member_role = groups_get_groupmeta ( $group_id, 'groupblog_default_member_role' ); 
  14. $groupblog_default_mod_role = groups_get_groupmeta ( $group_id, 'groupblog_default_mod_role' ); 
  15. $groupblog_default_admin_role = groups_get_groupmeta ( $group_id, 'groupblog_default_admin_role' ); 
  16. $groupblog_creator_role = 'admin'; 
  17.  
  18. // get user's blog role 
  19. $user_role = bp_groupblog_get_user_role( $user_id, false, $blog_id ); 
  20.  
  21. // Get the current user's group status. For efficiency, we try first to look at the 
  22. // current group object 
  23. if ( isset( $bp->groups->current_group->id ) && $group_id == $bp->groups->current_group->id ) { 
  24. // It's tricky to walk through the admin/mod lists over and over, so let's format 
  25. if ( empty( $bp->groups->current_group->adminlist ) ) { 
  26. $bp->groups->current_group->adminlist = array(); 
  27. if ( isset( $bp->groups->current_group->admins ) ) { 
  28. foreach( (array)$bp->groups->current_group->admins as $admin ) { 
  29. if ( isset( $admin->user_id ) ) { 
  30. $bp->groups->current_group->adminlist[] = $admin->user_id; 
  31.  
  32. if ( empty( $bp->groups->current_group->modlist ) ) { 
  33. $bp->groups->current_group->modlist = array(); 
  34. if ( isset( $bp->groups->current_group->mods ) ) { 
  35. foreach( (array)$bp->groups->current_group->mods as $mod ) { 
  36. if ( isset( $mod->user_id ) ) { 
  37. $bp->groups->current_group->modlist[] = $mod->user_id; 
  38.  
  39. if ( in_array( $user_id, $bp->groups->current_group->adminlist ) ) { 
  40. $user_group_status = 'admin'; 
  41. } elseif ( in_array( $user_id, $bp->groups->current_group->modlist ) ) { 
  42. $user_group_status = 'mod'; 
  43. } else { 
  44. // I'm assuming that if a user is passed to this function, they're a member 
  45. // Doing an actual lookup is costly. Try to look for an efficient method 
  46. $user_group_status = 'member'; 
  47. } else { 
  48. if ( groups_is_user_admin ( $user_id, $group_id ) ) { 
  49. $user_group_status = 'admin'; 
  50. } else if ( groups_is_user_mod ( $user_id, $group_id ) ) { 
  51. $user_group_status = 'mod'; 
  52. } else if ( groups_is_user_member ( $user_id, $group_id ) ) { 
  53. $user_group_status = 'member'; 
  54. } else { 
  55. return false; 
  56.  
  57. // change user status based on promotion / demotion 
  58. switch( bp_action_variable( 1 ) ) { 
  59. case 'promote' : 
  60. $user_group_status = bp_action_variable( 2 ); 
  61. break; 
  62.  
  63. case 'demote' : 
  64. case 'unban' : 
  65. $user_group_status = 'member'; 
  66. break; 
  67.  
  68. // we don't remove users from blogs at the moment 
  69. // we give them the minimum role of 'subscriber' 
  70. case 'ban' : 
  71. case 'remove' : 
  72. $user_group_status = 'subscriber'; 
  73. break; 
  74.  
  75. // set the role 
  76. switch ( $user_group_status ) { 
  77. case 'admin' : 
  78. $default_role = $groupblog_default_admin_role; 
  79. break; 
  80.  
  81. case 'mod' : 
  82. $default_role = $groupblog_default_mod_role; 
  83. break; 
  84.  
  85. case 'subscriber' : 
  86. $default_role = 'subscriber'; 
  87. break; 
  88.  
  89. case 'member' : 
  90. default : 
  91. $default_role = $groupblog_default_member_role; 
  92. break; 
  93.  
  94. if ( $user_role == $default_role && $groupblog_silent_add == true ) { 
  95. return false; 
  96.  
  97. if ( !$groupblog_silent_add ) { 
  98. $default_role = 'subscriber'; 
  99.  
  100. add_user_to_blog( $blog_id, $user_id, $default_role ); 
  101.  
  102. do_action( 'bp_groupblog_upgrade_user', $user_id, $user_role, $default_role );