Skip to:

function that breaks the BP AJAX

  • Rocio Valdivia


    Hi guys! I have a WP 3.7.1 and BP 1.8.1 and I have created the following function in my functions.php to retrieve the number of notifications of the current user. The function has one parametrer $type_notification that can be: ‘new_message’, ‘group_invite’ or ‘friendship_request’.

    The function works quite well, but the point is that with that function in functions.php, the BP ajax doesn’t work. For example: the search box in members or the members list pagination. If I delete this function from functions.php, the members pagination, etc. works fine again.

    Does anyone know why is this happening? or an alternative function that I can use for this porpouse that doens’t break the ajax?

    Thanks in advance! 🙂

    Rocío Valdivia

     * Get notifications for a specific user
    function buddyboss_childtheme_core_get_notifications_for_user( $type_notification ) {
    	global $bp;
    	$user_id = $bp->loggedin_user->id;
    	$notifications         = BP_Core_Notification::get_all_for_user( $user_id );
    	$grouped_notifications = array(); // Notification groups
    	$renderable            = array(); // Renderable notifications
    	// Group notifications by component and component_action and provide totals
    	for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
    		$notification = $notifications[$i];
    		$grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
    	if($type_notification == 'new_message'):
    		$number_notifications = count($grouped_notifications['messages']['new_message']);
    	elseif($type_notification == 'group_invite'):
    		$number_notifications = count($grouped_notifications['groups']['group_invite']);
    	elseif($type_notification == 'friendship_request'):
    		$number_notifications = count($grouped_notifications['friends']['friendship_request']);
    	return $number_notifications;
Viewing 3 replies - 1 through 3 (of 3 total)

  • Rocio Valdivia


    Ok, I have found the problem and I fixed it 🙂

    The conflict was the name of the function:

    buddyboss_childtheme_core_get_notifications_for_user( $type_notification )

    When I was testing the function to find the problem, I realised that even with the empty function the ajax problem was still there. So I tried changing the function’s name and done!

    The new name is:

    buddyboss_childtheme_get_notifications_for_user( $type_notification )

    I will never use again the word “core” in the title of a function in functions.php 😉

    Hope it will be useful for someone. Cheers!




    @_dorsvenabili when adding custom functions to functions.php it might be a good idea to add a prefix to all of your function names. As you can see buddyboss has done it with buddyboss_childtheme_.

    You could have used dorsvenabili_core_get_notifications_for_user or my_core_get_notifications_for_user

    Saves conflicts from happening 🙂

    Rocio Valdivia


    Thanks @henrywright-1, and that was what I did, I was the one that added the prefix:

    buddyboss_childtheme_ to my function, but the point is that if I use the word “core” inside the title of a function, the ajax stop working 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘function that breaks the BP AJAX’ is closed to new replies.
Skip to toolbar