Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Okay ... So, I went through some of the Buddypress code, and found this:
- function bp_profile_group_tabs() {
- global $bp, $group_name;
- if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) {
- $groups = BP_XProfile_Group::get( array( 'fetch_fields' => true ) );
- wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );
- }
- if ( empty( $group_name ) )
- $group_name = bp_profile_group_name(false);
- $tabs = array();
- for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) {
- if ( $group_name == $groups[$i]->name )
- $selected = ' class="current"';
- else
- $selected = '';
- if ( !empty( $groups[$i]->fields ) ) {
- $link = trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $groups[$i]->id );
- $tabs[] = sprintf( '<li %1$s><a href="%2$s">%3$s</a></li>', $selected, $link, esc_html( $groups[$i]->name ) );
- }
- }
- $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
- foreach ( (array) $tabs as $tab )
- echo $tab;
- do_action( 'xprofile_profile_group_tabs' );
- }
- Which builds out your profile edit tabs, when you create profile groups in the backend.
- After I found this, I went to my bp_custom file, and wrote:
- add_action( 'xprofile_template_loop_start', 'mar_define_profile_by_role' );
- function mar_define_profile_by_role() {
- global $current_user;
- $user_roles = $current_user->roles;
- $user_role = array_shift($user_roles);
- if( $user_role == "writer" ) {
- //* EXECUTE WRITER SPECIFIC CODE
- } elseif( $user_role == "publisher" ) {
- //* EXECUTE PUBLISHER SPECIFIC CODE
- }
- }
- `
- 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.
- EXAMPLE:
- I have 2 profile group tabs ... a WRITER tab, and a PUBLISHER tab. Each tab has user role specific profile fields.
- if( $user_role == "writer" ) {
- //* EXECUTE WRITER SPECIFIC CODE
- //* SOME KIND OF FILTER THAT REMOVES THE PUBLISHER PROFILE GROUP
- } elseif( $user_role == "publisher" ) {
- //* EXECUTE PUBLISHER SPECIFIC CODE
- //* SOME KIND OF FILTER THAT REMOVES THE WRITER PROFILE GROUP
- }
- Within the first block of code, the piece of code that sticks out the most for me is:
- $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
- foreach ( (array) $tabs as $tab )
- echo $tab;
- 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?
- What do you think. Any suggestions?
- I'll keep working on this.
- Cheers!
Advertisement
Add Comment
Please, Sign In to add comment