BBP_Replies_Admin::toggle_reply()
Toggle reply
Description Description
Handles the admin-side spamming/unspamming of replies
Source Source
File: includes/admin/replies.php
public function toggle_reply() {
// Bail if not a topic toggle action
if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['reply_id'] ) ) {
return;
}
// Bail if not an allowed action
$action = sanitize_key( $_GET['action'] );
if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
return;
}
// Get reply and die if empty
$reply_id = bbp_get_reply_id( $_GET['reply_id'] );
if ( ! bbp_get_reply( $reply_id ) ) {
wp_die( esc_html__( 'The reply was not found.', 'bbpress' ) );
}
// What is the user doing here?
if ( ! current_user_can( 'moderate', $reply_id ) ) {
wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
}
// Defaults
$post_data = array( 'ID' => $reply_id );
$message = '';
$success = false;
switch ( $action ) {
case 'bbp_toggle_reply_approve' :
check_admin_referer( 'approve-reply_' . $reply_id );
$is_approve = bbp_is_reply_public( $reply_id );
$message = ( true === $is_approve )
? 'unpproved'
: 'approved';
$success = ( true === $is_approve )
? bbp_unapprove_reply( $reply_id )
: bbp_approve_reply( $reply_id );
break;
case 'bbp_toggle_reply_spam' :
check_admin_referer( 'spam-reply_' . $reply_id );
$is_spam = bbp_is_reply_spam( $reply_id );
$message = ( true === $is_spam )
? 'unspammed'
: 'spammed';
$success = ( true === $is_spam )
? bbp_unspam_reply( $reply_id )
: bbp_spam_reply( $reply_id );
break;
}
// Setup the message
$retval = array(
'bbp_reply_toggle_notice' => $message,
'reply_id' => $reply_id
);
// Prepare for failure
if ( ( false === $success ) || is_wp_error( $success ) ) {
$retval['failed'] = '1';
}
// Filter all message args
$retval = apply_filters( 'bbp_toggle_reply_action_admin', $retval, $reply_id, $action );
// Do additional reply toggle actions (admin side)
do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $retval );
// Redirect back to the reply
$redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'reply_id' ) ) );
bbp_redirect( $redirect );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |