bp_nouveau_ajax_unmark_activity_favorite()

Un-favourite an activity via a POST request.

Description

Return

(string) JSON reply

Source

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

function bp_nouveau_ajax_unmark_activity_favorite() {
	if ( ! bp_is_post_request() ) {
		wp_send_json_error();
	}

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

	if ( bp_activity_remove_user_favorite( $_POST['id'] ) ) {
		$response = array(
			'content'    => __( 'Like', 'buddyboss' ),
			'like_count' => bp_activity_get_favorite_users_string( $_POST['id'] ),
			'tooltip'    => bp_activity_get_favorite_users_tooltip_string( $_POST['id'] )
		); // here like_count is for activity total like count

		$fav_count = (int) bp_get_total_favorite_count_for_user( bp_loggedin_user_id() );

		if ( 0 === $fav_count && ! bp_is_single_activity() ) {
			$response['no_favorite'] = '<li><div class="bp-feedback bp-messages info">
				' . __( 'Sorry, there was no activity found.', 'buddyboss' ) . '
			</div></li>';
		} else {
			$response['fav_count'] = $fav_count;
		}

		wp_send_json_success( $response );
	} else {
		wp_send_json_error();
	}
}

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.