So I am working on a website, and I am adding a new Menu item on my BuddyPress profile page. The Menu has been added correctly through a bp-custom.php
page. But when I click on the Menu, I am not able to redirect it to the page I want to. The code is something like:
function add_gift_card() {
global $bp;
bp_core_new_nav_item( array(
'name' => 'Gift Cards',
'slug' => 'shop',
// 'parent_url' => get_option('siteurl').'/shop',
// 'parent_slug' => $bp->profile->slug,
'screen_function' => 'gift_card_screen',
'position' => 90,
'default_subnav_slug' => 'shop'
) );
}
add_action( 'bp_setup_nav', 'add_gift_card', 100 );
function gift_card_screen() {
add_action( 'bp_template_content', 'gift_card_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function gift_card_screen_content() {
echo 'Gift Cards<br/>';
}
How can I redirect it to a new page on the website irrespective of the root user domain?
I had to remove the template functions, to redirect it properly. And as suggested by shanebp, the bp_core_redirect function came handy. The code now looks like this:
function add_gift_card() {
global $bp;
bp_core_new_nav_item( array(
'name' => 'Gift Cards',
'slug' => 'shop',
'screen_function' => 'gift_card_screen',
'position' => 90,
'default_subnav_slug' => 'shop'
) );
}
add_action( 'bp_setup_nav', 'add_gift_card', 100 );
function gift_card_screen() {
bp_core_redirect( get_option('siteurl').'/shop/' );
}