Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_core_new_nav_item ‘s screen_function is not working properly

  • Hello everyone,
    I created a tab using bp_core_new_nav_item. However, it does not call the screen function when I click on it, instead it sends me to the homepage of the site.
    I know that BP hooks the screen function to the ‘wp’ hook. So, to diagnose the problem I printed out the global $wp_filter variable to see if the screen function is present. Surprisingly, once I print out the variable I see the screen function is present and the tab calls the screen function and everything works. But it stops working again if I comment out the line that prints the the $wp_filter variable. I am dumbfounded by this. What am I a doing wrong?
    I would appreciate any input.
    `
    add_action( ‘wp’, ‘rt_gallery_setup_nav’, 2 ); //setup the tab
    /**
    * rt_gallery_setup_nav()
    *
    * Sets up the user profile navigation items for the component. This adds the top level nav
    * item and all the sub level nav items to the navigation array. This is then
    * rendered in the template.
    */
    function rt_gallery_setup_nav() {
    global $bp,$wp_actions,$wp_filter; //using $wp_actions and $wp_filter for diag

    bp_core_new_nav_item( array(
    ‘name’ => __( ‘Gallery’, ‘rt-gallery’ ),
    ‘slug’ => $bp->rt_gallery->slug,
    ‘position’ => 80,
    ‘screen_function’ => ‘rt_gallery_screen_pictures’,
    ‘default_subnav_slug’ => ‘screen-one’
    ) );

    echo ‘

    test

    ‘;
    print_r($wp_filter); //the tab will not work if I comment out this line
    echo ‘

    test

    ‘;
    }

    function rt_gallery_screen_pictures()
    {

    echo ‘jello world’;
    }`
    `

Viewing 6 replies - 1 through 6 (of 6 total)

  • nicholmikey
    Participant

    @nicholmikey

    I am having the same problem


    Boone Gorges
    Keymaster

    @boonebgorges

    The problem is probably that you’re hooking to ‘wp’, which is too late in the loading process to add new items to the nav bar. Try hooking to ‘bp_setup_nav’ instead.


    nicholmikey
    Participant

    @nicholmikey

    Hello, thanks for the response.

    I tried bp_setup_nav and with that the menu item does not even appear. my code is

    `

    add_action(‘wp’, ‘CubePoints_List_Menu’);
    function CubePoints_List_Menu(){

    global $bp;
    $cubepoint_link = ($bp->displayed_user->id ? $bp->displayed_user->domain : $bp->loggedin_user->domain) . $bp->cubepoint->slug . ‘/’;
    global $wp_filter;

    bp_core_new_subnav_item( array(
    ‘name’ =>’test’,
    ‘slug’ => ‘top_points’,
    ‘parent_slug’ => $bp->cubepoint->slug,
    ‘parent_url’ => $cubepoint_link,
    ‘screen_function’ => ‘top_points_screen’,
    ‘position’ => 70,
    ) );
    }

    function top_points_screen() {
    global $bp;

    add_action( ‘bp_template_title’, ‘top_points_events_title’ );
    add_action( ‘bp_template_content’, ‘top_points_events_content’ );
    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
    //bp_core_load_template( apply_filters( ‘bp_em_template_screen_one’, ’em/screen-one’ ) );
    }
    /***
    * The second argument of each of the above add_action() calls is a function that will
    * display the corresponding information. The functions are presented below:
    */
    function top_points_events_title() {
    echo ‘Top Points’;
    }

    function top_points_events_content() {
    global $bp;

    ?>

    hello world

    <?php
    }
    `

    With this the menu item shows up, if I hover over it points to the correct place, but when I click it just takes me to the home page. I have tried several variations of this code with no luck.


    nicholmikey
    Participant

    @nicholmikey

    Anyone have any ideas on how to load a template from a sub menu item?

    @nicholmikey – Did you figure this out? I am having the same issue.


    Boone Gorges
    Keymaster

    @boonebgorges

    The problem with this code is that it hooks to ‘wp’ instead of ‘bp_setup_nav’. Use
    `add_action( ‘bp_setup_nav’, ‘CubePoints_List_Menu’ );`

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘bp_core_new_nav_item ‘s screen_function is not working properly’ is closed to new replies.
Skip to toolbar