1

I'm trying to make a custom Buddypress profile tab and make it so it is the landing page of a users profile. I have defined the tab in functions.php:

// Profile home tab

function profile_tab_overview() {
      global $bp;

      bp_core_new_nav_item( array( 
            'name' => 'Overview', 
            'slug' => 'overview', 
            'screen_function' => 'overview_screen', 
            'position' => 40,
            'parent_url'      => bp_loggedin_user_domain() . '/overview/',
            'parent_slug'     => $bp->profile->slug,
            'default_subnav_slug' => 'overview'
      ) );
}
add_action( 'bp_setup_nav', 'profile_tab_overview' );


function overview_screen() {

    // Add title and content here - last is to call the members plugin.php template.
    add_action( 'bp_template_title', 'overview_title' );
    add_action( 'bp_template_content', 'overview_content' );
    bp_core_load_template( 'buddypress/members/single/plugins' );
}
function overview_title() {
    echo 'Overview';
}

function overview_content() { 
    echo 'Content';
}

Then I set it as the profile landing page in wp-config.php with:

//Change BuddyPress default Members landing tab.

define('BP_DEFAULT_COMPONENT', 'overview' );

If i change BP_DEFAULT_COMPONENT to a standard Buddypress profile page like 'profile' it works, but it doesn't with the custom page I have created. Anyone know why, or what I can do about it?

user585148
  • 117
  • 1
  • 2
  • 12

3 Answers3

1

This should correct the issue using BuddyPress 4.0+ :)

//Set Default Tab to Overview
define('BP_DEFAULT_COMPONENT', 'overview' );
add_filter( 'bp_is_active', function($retval, $component){
    if($component === 'overview') return true;
    return $retval;
}, 10, 2 );
Russ Powers
  • 101
  • 1
  • 1
  • 8
1

@Russ Powers fix worked perfect.. for every other account but yours. when i click your profile in buddypress dasboard i get 404 error when the address is: domain/members/you

if i would be using only:

//Set Default Tab to active
define('BP_DEFAULT_COMPONENT', 'active' );

it works fine. but with my custom tab i get 404 error.. no idea why. everything after /member/you/something works, but for every user that enters his profile /members/mynick there's an error.

and im using this action, so nobody goes straight to wp-admin

add_action( 'load-profile.php', function() {
    if( ! current_user_can( 'manage_options' ) && function_exists( 'bp_core_get_user_domain' ) )
        exit( wp_safe_redirect( bp_core_get_user_domain( get_current_user_id() ) ) );
} );
xpc
  • 11
  • 1
0

What version of BuddyPress are you using? An upgrade to 4.0+ may be needed -- please note this behavior may be expected. From https://buddydev.com/what-is-new-in-buddypress-4-0/

Restoring the behaviour of BP_DEFAULT_COMPONENT

BP_DEFAULT_COMPONENT constant is used to specify the default landing page on a user’s profile when their profile link(http://example.com/members/username/) is opened.

In BuddyPress 3.0, when user front page(home screen) was added, the behaviour changed. If the front page was enabled, this constant did not work. To make it work, you had to disable the user front page. BuddyPress 4.0 restores the suprimacy of BP_DEFAULT_COMPONENT again. Now, It will work as expected.

Alternatively, you're using 4.0+, a downgrade may be needed: https://buddypress.org/support/topic/bp_default_component-no-longer-working/

I’ve using define(‘BP_DEFAULT_COMPONENT’, ‘dashboard’ ); in my functions.php but it’s no longer working since a few updates ago. .... Just rolled back to 3.2.0 and this has now fixed it.

Richard Zack
  • 431
  • 3
  • 12