bp_nouveau_ajax_get_activity_objects()

Get items to attach the activity to.

Description

This is used within the activity post form autocomplete field.

Return

(string) JSON reply

Source

File: bp-templates/bp-nouveau/includes/activity/ajax.php

function bp_nouveau_ajax_get_activity_objects() {
	$response = array();

	if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'bp_nouveau_activity' ) ) {
		wp_send_json_error( $response );
	}

	if ( 'group' === $_POST['type'] ) {
		$groups = groups_get_groups(
			array(
				'user_id'      => bp_loggedin_user_id(),
				'search_terms' => $_POST['search'],
				'show_hidden'  => true,
				'per_page'     => 2,
			)
		);

		wp_send_json_success( array_map( 'bp_nouveau_prepare_group_for_js', $groups['groups'] ) );
	} else {

		/**
		 * Filters the response for custom activity objects.
		 *
		 * @since BuddyPress 3.0.0
		 *
		 * @param array $response Array of custom response objects to send to AJAX return.
		 * @param array $value    Activity object type from $_POST global.
		 */
		$response = apply_filters( 'bp_nouveau_get_activity_custom_objects', $response, $_POST['type'] );
	}

	if ( empty( $response ) ) {
		wp_send_json_error( array( 'error' => __( 'No activities were found.', 'buddyboss' ) ) );
	} else {
		wp_send_json_success( $response );
	}
}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.