mrapino

Custom Profile for User Roles

Aug 18th, 2014
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. Okay ... So, I went through some of the Buddypress code, and found this:
  2.  
  3. function bp_profile_group_tabs() {
  4. global $bp, $group_name;
  5. if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) {
  6. $groups = BP_XProfile_Group::get( array( 'fetch_fields' => true ) );
  7. wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );
  8. }
  9. if ( empty( $group_name ) )
  10. $group_name = bp_profile_group_name(false);
  11. $tabs = array();
  12. for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) {
  13. if ( $group_name == $groups[$i]->name )
  14. $selected = ' class="current"';
  15. else
  16. $selected = '';
  17. if ( !empty( $groups[$i]->fields ) ) {
  18. $link = trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $groups[$i]->id );
  19. $tabs[] = sprintf( '<li %1$s><a href="%2$s">%3$s</a></li>', $selected, $link, esc_html( $groups[$i]->name ) );
  20. }
  21. }
  22. $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
  23. foreach ( (array) $tabs as $tab )
  24. echo $tab;
  25. do_action( 'xprofile_profile_group_tabs' );
  26. }
  27.  
  28.  
  29. Which builds out your profile edit tabs, when you create profile groups in the backend.
  30.  
  31. After I found this, I went to my bp_custom file, and wrote:
  32.  
  33. add_action( 'xprofile_template_loop_start', 'mar_define_profile_by_role' );
  34. function mar_define_profile_by_role() {
  35. global $current_user;
  36. $user_roles = $current_user->roles;
  37. $user_role = array_shift($user_roles);
  38. if( $user_role == "writer" ) {
  39. //* EXECUTE WRITER SPECIFIC CODE
  40. } elseif( $user_role == "publisher" ) {
  41. //* EXECUTE PUBLISHER SPECIFIC CODE
  42. }
  43. }
  44. `
  45.  
  46. Can anyone help fill in the blanks?  Basically, from the first code block, I need to figure out how to filter out the specific profile group from the array, with the correct section of my second code block.  
  47.  
  48. EXAMPLE:
  49.  
  50. I have 2 profile group tabs ... a WRITER tab, and a PUBLISHER tab.  Each tab has user role specific profile fields.
  51.  
  52. if( $user_role == "writer" ) {
  53. //* EXECUTE WRITER SPECIFIC CODE
  54. //* SOME KIND OF FILTER THAT REMOVES THE PUBLISHER PROFILE GROUP
  55. } elseif( $user_role == "publisher" ) {
  56. //* EXECUTE PUBLISHER SPECIFIC CODE
  57. //* SOME KIND OF FILTER THAT REMOVES THE WRITER PROFILE GROUP
  58. }
  59.  
  60. Within the first block of code, the piece of code that sticks out the most for me is:
  61.  
  62. $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
  63. foreach ( (array) $tabs as $tab )
  64. echo $tab;
  65.  
  66. I think this is the code that actually loops through all the profile groups and spits them onto the page.  If there is an "apply_filters", I should be able to tap into this, right?
  67.  
  68. What do you think.  Any suggestions?
  69.  
  70. I'll keep working on this.  
  71.  
  72. Cheers!
Advertisement
Add Comment
Please, Sign In to add comment