BBP_Replies_Admin::toggle_reply()

Toggle reply

Description

Handles the admin-side spamming/unspamming of replies

Source

File: bp-forums/admin/replies.php

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
public function toggle_reply() {
 
    if ( $this->bail() ) return;
 
    // Only proceed if GET is a reply toggle action
    if ( bbp_is_get_request() && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) {
        $action    = $_GET['action'];            // What action is taking place?
        $reply_id  = (int) $_GET['reply_id'];    // What's the reply id?
        $success   = false;                      // Flag
        $post_data = array( 'ID' => $reply_id ); // Prelim array
 
        // Get reply and die if empty
        $reply = bbp_get_reply( $reply_id );
        if ( empty( $reply ) ) // Which reply?
            wp_die( __( 'The reply was not found!', 'buddyboss' ) );
 
        if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here?
            wp_die( __( 'You do not have the permission to do that!', 'buddyboss' ) );
 
        switch ( $action ) {
            case 'bbp_toggle_reply_spam' :
                check_admin_referer( 'spam-reply_' . $reply_id );
 
                $is_spam = bbp_is_reply_spam( $reply_id );
                $message = $is_spam ? 'unspammed' : 'spammed';
                $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
 
                break;
        }
 
        $success = wp_update_post( $post_data );
        $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID );
 
        if ( false === $success || is_wp_error( $success ) )
            $message['failed'] = '1';
 
        // Do additional reply toggle actions (admin side)
        do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message );
 
        // Redirect back to the reply
        $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) );
        wp_safe_redirect( $redirect );
 
        // For good measure
        exit();
    }
}

Changelog

Changelog
Version Description
bbPress (r2740) 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.