bp_nouveau_ajax_spam_activity()

AJAX spam an activity item or comment.

Description

Return

(string) JSON reply.

Source

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

681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
function bp_nouveau_ajax_spam_activity() {
    $bp = buddypress();
 
    $response = array(
        'feedback' => sprintf(
            '<div class="bp-feedback bp-messages error">%s</div>',
            esc_html__( 'There was a problem marking this activity as spam. Please try again.', 'buddyboss' )
        ),
    );
 
    // Bail if not a POST action.
    if ( ! bp_is_post_request() ) {
        wp_send_json_error( $response );
    }
 
    if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) ) {
        wp_send_json_error( $response );
    }
 
    if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) ) {
        wp_send_json_error( $response );
    }
 
    // Is the current user allowed to spam items?
    if ( ! bp_activity_user_can_mark_spam() ) {
        wp_send_json_error( $response );
    }
 
    $activity = new BP_Activity_Activity( (int) $_POST['id'] );
 
    if ( empty( $activity->component ) ) {
        wp_send_json_error( $response );
    }
 
    // Nonce check!
    if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'bp_activity_akismet_spam_' . $activity->id ) ) {
        wp_send_json_error( $response );
    }
 
    /** This action is documented in bp-activity/bp-activity-actions.php */
    do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
 
    // Mark as spam.
    bp_activity_mark_as_spam( $activity );
    $activity->save();
 
    /** This action is documented in bp-activity/bp-activity-actions.php */
    do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
 
    // Prepare the successfull reply
    $response = array( 'spammed' => $activity->id );
 
    // If on a single activity redirect to user's home.
    if ( ! empty( $_POST['is_single'] ) ) {
        $response['redirect'] = bp_core_get_user_domain( $activity->user_id );
        bp_core_add_message( __( 'This activity has been marked as spam and is no longer visible.', 'buddyboss' ) );
    }
 
    // Send the json reply
    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.