Buddypress ajax problem after adding new groups sub nav [closed]

This problem has been bugging me for couple of days. After adding a new subnav, I got the following error when trying to use the drop down groups filter:
404 Not Found – mysite.com/wp-admin/admin-ajax.php”

Basically I wanted to add a new subnav items under a member’s main nav “groups”. Currently there are two subnav items there: “memberships” and “invitations”. I would like to add my own subnav item called “My Customized Groups”. When this subnav is clicked, it will show groups of certain feature.

Okay the first step is to create a new subnav items. I did it by adding the following code to my functions.php

//add new subnav items
bp_core_new_subnav_item( array(
'name' => __( 'My Customized Groups', 'buddypress' ),
'slug' => 'my-custom-groups',
'parent_url' => $groups_link,
'parent_slug' => $bp->groups->slug,
'screen_function' => 'groups_screen_my_custom_groups',
'position' => 20
));

To make sure my subnav works, my screen_function “groups_screen_my_custom_groups” is a exactly copy of the default “groups_screen_my_groups”. Now the subnav is added, and groups loop show up correctly. But when I select the drop down filter ( “last active”, “most members”, “newly created”, etc), the following error shows up:
404 Not Found – mysite.com/wp-admin/admin-ajax.php”

if I set this new subnav as the default by adding the following code in functions.php

$args = array(
'parent_slug' => $bp->groups->slug,
'screen_function' => 'groups_screen_my_custom_groups',
'subnav_slug' => 'my-custom-groups'
);

bp_core_new_nav_default($args);

Then the ajax works correctly for my-custom-groups, but it doesn’t work for other subnav items anymore. It seems ajax only works for the default subnav? This is strange.

It must be something minor, but I still can’t figure out what’s been wrong after searching everywhere for two days.

Thanks in advance for the help.

WordPress version: 3.4.2
buddypress version: 1.6.1

1 Answer
1

Is i commented previously im having the same error. I dont know what it causing it but i found a workaround for it.

Im using a modified version (by me) of the plugin buddypress-groups-tags which allows me to create categories for groups. That plugin uses bp_core_new_subnav_item to be able to use slugs like : http://local.dev/groups/category/teachers/

My problem was that inside that url in the activity loop, the more link was getting a 404 responde header error on admin-ajax.php. If i check the response content all the activity data was there. So im not sure what is causing the problem.

To solve it i added a function that will return a status header of 200 when the ajax call is triggered. In my case i needed for “get_older_updates” action but i suppose you can use it for any other action defined at /bp-themes/bp-default/_inc/ajax.php:27

add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_activity_template_loader2' );
add_action( 'wp_ajax_nopriv_activity_get_older_updates', 'bp_dtheme_activity_template_loader2' );

function bp_dtheme_activity_template_loader2(){
    if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'activity_get_older_updates')
    {
        status_header( 200 );
    }
}   

Hope it helps!

Leave a Comment