bp_nouveau_ajax_mark_activity_favorite()
Mark an activity as a favourite via a POST request.
Description
Return
(string) JSON reply
Source
File: bp-templates/bp-nouveau/includes/activity/ajax.php
function bp_nouveau_ajax_mark_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_add_user_favorite( $_POST['id'] ) ) { $response = array( 'content' => __( 'Unlike', '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 if ( ! bp_is_user() ) { $fav_count = (int) bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ); if ( 1 === $fav_count ) { $response['directory_tab'] = '<li id="activity-favorites" data-bp-scope="favorites" data-bp-object="activity"> <a href="' . bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/"> ' . esc_html__( 'Liked', 'buddyboss' ) . ' </a> </li>'; } else { $response['fav_count'] = $fav_count; } } wp_send_json_success( $response ); } else { wp_send_json_error(); } }
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.