Tagged: buddypress, custom profile group, login, visibility
Hey guys,
I’m a bit stuck and I hope someone here might have an idea 🙂
Here’s what I wanted to do: Put a new profile group in a separate bp profile menu tab and make it visible to both, logged in as well as logged out users. Now, it works perfectly fine, except for the fact that logged out users for some reason get to see my personal profile group under my custom tab instead of the new profile group – which is displayed correctly for me as well as other logged in users.
Here’s my code:
‘/**
BP Profile Tab Visibility
*/function bpfr_hide_top_nav() {
if( !is_user_logged_in() ) {
// bp topnav items to hide
bp_core_remove_nav_item( ‘activity’ );
bp_core_remove_nav_item( ‘friends’ );
bp_core_remove_nav_item( ‘groups’ );
bp_core_remove_nav_item( ‘forums’ );
bp_core_remove_nav_item( ‘media’ );
bp_core_remove_nav_item( ‘docs’ );
bp_core_remove_nav_item( ‘location’ );//bp subnav (my activities, my groups, etc)
bp_core_remove_subnav_item( ‘activity’, ‘activity’ );
bp_core_remove_subnav_item( ‘activity’, ‘friends’ );
bp_core_remove_subnav_item( ‘activity’, ‘favorites’ );
bp_core_remove_subnav_item( ‘activity’, ‘groups’ );
bp_core_remove_subnav_item( ‘activity’, ‘mentions’ );
bp_core_remove_subnav_item( ‘activity’, ‘media’ );
bp_core_remove_subnav_item( ‘activity’, ‘docs’ );
bp_core_remove_subnav_item( ‘activity’, ‘comments’ );}
}
add_action( ‘bp_ready’, ‘bpfr_hide_top_nav’, 10 );/**
BP Tab Order Profile and Tab Rename
*/function bpex_primary_nav_tabs_position() {
buddypress()->members->nav->edit_nav( array( ‘position’ => 2, ), ‘activity’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 1, ), ‘profile’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 3, ), ‘messages’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 4, ), ‘notifications’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 5, ), ‘friends’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 6, ), ‘groups’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 7, ), ‘forums’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 8, ), ‘criticalreview’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 9, ), ‘docs’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 10, ), ‘media’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 11, ), ‘location’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 12, ), ‘orders’ );
buddypress()->members->nav->edit_nav( array( ‘position’ => 13, ), ‘settings’ );
}
add_action( ‘bp_setup_nav’, ‘bpex_primary_nav_tabs_position’, 999 );/**
Put Critical Review Profile Group in BP Tab
*/function buddydev_modifyy_user_profile_tab() {
bp_core_new_nav_item( array(
‘name’ => ‘Critical Review’,
‘slug’ => ‘criticalreview’,
‘screen_function’ => ‘buddydev_screen_profile_data’,
‘default_subnav_slug’ => ‘criticalreview-sub’,
‘show_for_displayed_user’ => true,
));}
add_action( ‘bp_setup_nav’, ‘buddydev_modifyy_user_profile_tab’, 8 );function buddydev_screen_profile_data() {
//filter loop
add_filter( ‘bp_after_has_profile_parse_args’, ‘buddydev_filter_args_for_profile_group’ );
//load loop
add_action( ‘bp_template_content’, ‘buddydev_show_profile_group_data’);bp_core_load_template( ‘members/single/plugins’);
}function buddydev_filter_args_for_profile_group( $args ) {
///CHANGE IT
$args[‘profile_group_id’] = ‘6’; //Your Profile Group ID Herereturn $args;
}
//Load the loop
function buddydev_show_profile_group_data() {
$profileslug = bp_get_profile_slug();
bp_get_template_part( ‘members/single/profile/profile-loop’ );
}’A few comments:
The code essentially comes from this threat: https://buddydev.com/support/forums/topic/xprofile-field-group/. I am not really a coder myself, but usually I understand what the functions are doing, but in this case I’m not understanding what’s causing the issue.
Please note: To avoid duplication of the Critical Review profile group under the actual profile tab, I’ve hidden the profile group via CSS.
Finally, I’m running the latest WP and BP installs and you can have a look at the described behavior here: https://fslci.org/members/philip-strothmann/criticalreview/ As you can see, it shows the personal profile instead of the critical review profile – which is correctly displayed for logged-in users.
Interestingly, as you can see in this instance, the profile fields are actually adjusted to my CSS for the Critical Review profiles group – but the actual content doesn’t show correctly.Now, if you could help me out, I would highly appreciate it!
Thank you so much in advance! 🙂
Hi Phillip,
My apologies for missing the topic. Please allow me to get back to you a little late today or early tomorrow.Thank you
BrajeshHey Brajesh,
no problem. Have you had a chance to look at the issue? 🙂
Kind regards,
PhilipHi Phillip,
I just tested the code.I used this section from the above code
//step 1: Add a new Tab function buddydev_setup_new_xprofile_tab() { $slug = bp_get_profile_slug(); bp_core_new_subnav_item( array( 'name' => 'About',//label 'slug' => 'about',//slug 'parent_slug' => $slug, 'position' => 12, 'parent_url' => trailingslashit( bp_loggedin_user_domain() . $slug ) , 'screen_function' => 'buddydev_screen_profile_data' )); } add_action( 'bp_setup_nav', 'buddydev_setup_new_xprofile_tab' ); //Step 2: Load the plugins template file function buddydev_screen_profile_data() { //filter loop add_filter( 'bp_after_has_profile_parse_args', 'buddydev_filter_args_for_profile_group' ); //load loop add_action( 'bp_template_content', 'buddydev_show_profile_group_data'); bp_core_load_template( 'members/single/plugins'); } function buddydev_modifyy_user_profile_tab() { bp_core_new_nav_item( array( 'name' => 'Critical Review', 'slug' => 'criticalreview', 'screen_function' => 'buddydev_screen_profile_data', 'default_subnav_slug' => 'criticalreview-sub', 'show_for_displayed_user' => true, )); } add_action( 'bp_setup_nav', 'buddydev_modifyy_user_profile_tab', 8 ); function buddydev_filter_args_for_profile_group( $args ) { ///CHANGE IT $args['profile_group_id'] = 2; //Your Profile Group ID Here return $args; } //Load the loop function buddydev_show_profile_group_data() { bp_get_template_part( 'members/single/profile/profile-loop' ); }
It is working fine for on BuddyPress 2.8 for the logged ion user’s profile as well as other user’s profile.
I am sorry but I am not sure of the problem.
You must be logged in to reply to this topic.