1321941
1321941

Reputation: 2170

Buddypress: add custom component to members section

For each member page you have a selection of components (e.g. profile, settings, activity...)

What I am trying to do is add a new component called jobs to each page. I understand how to add the link to the navigation bar. It is just creating the page that is confusing me.

Do I add a new directory, if so how do I let buddypress know.

Having a url structure like:

example.com/member/username/jobs 

is important.

Thanks!

Upvotes: 0

Views: 2451

Answers (1)

McLovin
McLovin

Reputation: 1601

The global variable $bp is where you want to insert the new Jobs component. By dumping the global variable $bp, you can see all of the elements contained in it, including all of the components. To easily dump $bp, add the following to the top of member-header.php:

global $bp;
foreach ( (array)$bp as $key => $value ) {
    echo '<pre>';
    echo '<strong>' . $key . ': </strong><br />';
    print_r( $value );
    echo '</pre>';
}

The array within $bp that you want to add the component 'Jobs' to is bp_nav.

In functions.php add the following:

add_action( 'bp_setup_nav', 'add_subnav_items', 100 ); //Priority must be higher than 10
function add_subnav_items() {
    global $bp;

    //Jobs tab
    $tab_array['name'] = 'Jobs';    
    $tab_array['link'] =  $bp->displayed_user->domain.'jobs';   
    $tab_array['slug'] = 'jobs';    
    $tab_array['parent_url'] = $bp->displayed_user->domain; 
    $tab_array['parent_slug'] = bp_core_get_userlink(bp_loggedin_user_id());    
    $tab_array['css_id'] = 'jobs';  
    $tab_array['position'] = 100;   
    $tab_array['user_has_access'] = '1';    
    $tab_array['screen_function'] = 'bp_jobs_screen_general';   

    $bp->bp_nav['jobs'] = $tab_array;  //Add new array element to the 'bp_nav' array
}

The 'screen_function' is a function that handles the screen that is to be shown when 'Jobs' tab is selected so you must add the function 'bp_jobs_screen_general' in functions.php:

function bp_jobs_screen_general() {
    bp_core_load_template( apply_filters( 'bp_jobs_screen_general','members/single/jobs' ) );
}

This function looks for a template file named jobs.php in members/single/ so you must create it. For an example on how the screen_function's work, refer to a function for displaying Groups screens within wp-content/plugins/buddypress/bp-groups/bp-groups-screens.php.

Upvotes: 3

Related Questions