function mb_handler_reply_toggle_spam() { if (!isset($_GET['action']) || 'mb_toggle_spam' !== $_GET['action'] || !isset($_GET['reply_id'])) { return; } $reply_id = mb_get_reply_id($_GET['reply_id']); /* Verify nonce. */ if (!isset($_GET['mb_nonce']) || !wp_verify_nonce($_GET['mb_nonce'], "spam_reply_{$reply_id}")) { return; } if (!current_user_can('spam_reply', $reply_id)) { return; } $updated = mb_is_reply_spam($reply_id) ? mb_unspam_reply($reply_id) : mb_spam_reply($reply_id); $redirect = remove_query_arg(array('action', 'reply_id', 'mb_nonce')); wp_safe_redirect(esc_url($redirect)); }
/** * Callback function for handling post status changes. * * @since 1.0.0 * @access public * @return void */ public function handler() { /* Checks if the spam toggle link was clicked. */ if (isset($_GET['action']) && 'mb_toggle_spam' === $_GET['action'] && isset($_GET['reply_id'])) { $reply_id = absint($_GET['reply_id']); /* Verify the nonce. */ check_admin_referer("spam_reply_{$reply_id}"); /* Assume the changed failed. */ $notice = 'failure'; /* Check if the reply is open. */ $is_spam = mb_is_reply_spam($reply_id); /* Update the post status. */ $updated = $is_spam ? mb_unspam_reply($reply_id) : mb_spam_reply($reply_id); /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = $is_spam ? 'restore' : mb_get_spam_post_status(); } /* Redirect to correct admin page. */ $redirect = add_query_arg(array('reply_id' => $reply_id, 'mb_reply_notice' => $notice), remove_query_arg(array('action', 'reply_id', '_wpnonce'))); wp_safe_redirect($redirect); /* Always exit for good measure. */ exit; } }