Custom Profile Group doesn’t show when logged out
-
Hey guys,
first of all, awesome forum! I’ve already solved so many of my issues simply by reading the many helpful answers – hence never had the need to post anything myself, but now I’m a bit stuck.
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 Here return $args; } //Load the loop function buddydev_show_profile_group_data() { $profileslug = bp_get_profile_slug(); // if ( bp_is_my_profile() ) : // echo "Edit under Profile"; // endif; bp_get_template_part( 'members/single/profile/profile-loop' ); } function hide_profile_group( $grpid ) { if ( is_user_logged_in() && !bp_is_profile_edit() ) { $myfield = xprofile_get_field_data( 'Critical Review' ); $grpid['exclude_groups'] = '6'; } return $grpid; } add_filter( 'bp_after_has_profile_parse_args', 'hide_profile_group' );
A few comments:
Most of the essential code is based on this threat. I am not really a coder myself, but usually I understand what the functions are doing.
For now I commented `// if ( bp_is_my_profile() ) :
// echo “Edit under Profile”;
// endif;` out, because if I leave it in, for some reason then also logged-in users only see the personal profile group instead of the Critical Review one?!Also, I’m not entirely sure about the use of the last function and its use / relevance, because it doesn’t seem to affect anything. This might however have to do with the fact that in order 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. 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 any of you could help me out, I would highly appreciate it!
Thank you so much in advance! 🙂
- You must be logged in to reply to this topic.