John Davidson

php - create custom profile url nav item buddypress

0 comments
Message:


i have created and nav item for orders page in buddypress and i want to create another one but append url to the last nav item.


The first nav tab item:


function profile_tab_orders() {
global $bp;
bp_core_new_nav_item( array(
'name' => 'All orders',
'slug' => 'orders',
'screen_function' => 'orders_screen',
'position' => 40,
'parent_url' => bp_loggedin_user_domain() . '/orders/',
'parent_slug' => $bp->profile->slug,
'default_subnav_slug' => 'orders'
) );
}
add_action( 'bp_setup_nav', 'profile_tab_orders' );


function orders_screen() {
add_action( 'bp_template_content', 'orders_content' );
bp_core_load_template( 'buddypress/members/single/plugins' );
}

function orders_content() {
echo do_shortcode('[orders]');
}

Everything works fine and it can be access via this url:


http://example.com/members/demo/orders


Now, I want to create another nav item or shortcode to display orders completed, order pending... like this.


http://example.com/members/demo/orders/completed


http://example.com/members/demo/orders/pending


I tried this but not working..


function profile_tab_orders_completed() {
global $bp;
bp_core_new_nav_item( array(
'name' => 'completed',
'slug' => 'completed',
'screen_function' => 'completed_screen',
'position' => 40,
'parent_url' => $bp->loggedin_user->domain . $bp->orders->slug . '/completed',
'parent_slug' => $bp->orders->slug,
'default_subnav_slug' => 'completed'
) );
}
add_action( 'bp_setup_nav', 'profile_tab_completed' );


function completed_screen() {
add_action( 'bp_template_content', 'completed_content' );
bp_core_load_template( 'buddypress/members/single/plugins' );
}

function completed_content() {
echo do_shortcode('[orders-completed]');
}

Can someone suggest me a solution or help me in how to access pending, completed via this url


/orders/completed


/orders/pending


Thanks in advance!



My Answer:
> 'Orders',
> 'slug' => 'orders',
> 'position' => 30,
> 'screen_function' => 'profile_orders_screen',
> 'default_subnav_slug' => 'orders'
> ) );
> }
> add_action( 'bp_setup_nav', 'profile_tab_orders' );

To create a custom profile URL nav item that appends to the last nav item, you can modify the above code as follows:

php
function profile_tab_custom() {
global $bp;

$last_nav_item = end($bp->bp_nav);
$last_position = $last_nav_item['position'];

bp_core_new_nav_item( array(
'name' => 'Custom',
'slug' => 'custom',
'position' => $last_position + 1,
'screen_function' => 'profile_custom_screen',
'parent_url' => $bp->loggedin_user->domain . $last_nav_item['slug'] . '/',
'parent_slug' => $last_nav_item['slug']
) );
}
add_action( 'bp_setup_nav', 'profile_tab_custom' );


In this code snippet, we first get the last nav item and its position. Then, we create a new nav item with a position one greater than the last nav item. We also set the `parent_url` to append to the URL of the last nav item. Make sure to replace `'profile_custom_screen'` with the appropriate screen function for your custom nav item.

Rate this post

3 of 5 based on 8292 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us