/** * Callback function for handling post status changes. * * @since 1.0.0 * @access public * @return void */ public function handler() { /* Checks if the open/close toggle link was clicked. */ if (isset($_GET['mb_toggle_status']) && isset($_GET['topic_id'])) { $topic_id = absint(mb_get_topic_id($_GET['topic_id'])); /* Assume the changed failed. */ $notice = 'failure'; if ('spam' === $_GET['mb_toggle_status']) { /* Verify the nonce. */ check_admin_referer("spam_topic_{$topic_id}"); /* Check if the topic is open. */ $is_spam = mb_is_topic_spam($topic_id); /* Update the post status. */ $updated = $is_spam ? mb_unspam_topic($topic_id) : mb_spam_topic($topic_id); /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = $is_spam ? 'restore' : mb_get_spam_post_status(); } } elseif ('open' === $_GET['mb_toggle_status'] && !mb_is_topic_open($topic_id)) { /* Verify the nonce. */ check_admin_referer("open_topic_{$topic_id}"); /* Update the post status. */ $updated = mb_open_topic($topic_id); /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = mb_get_open_post_status(); } } elseif ('close' === $_GET['mb_toggle_status'] && !mb_is_topic_closed($topic_id)) { /* Verify the nonce. */ check_admin_referer("close_topic_{$topic_id}"); /* Update the post status. */ $updated = mb_close_topic($topic_id); /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = mb_get_close_post_status(); } } /* Redirect to correct admin page. */ $redirect = add_query_arg(array('topic_id' => $topic_id, 'mb_topic_notice' => $notice), remove_query_arg(array('action', 'mb_toggle_status', 'topic_id', '_wpnonce'))); wp_safe_redirect($redirect); /* Always exit for good measure. */ exit; } elseif (isset($_GET['action']) && 'mb_toggle_spam' === $_GET['action'] && isset($_GET['topic_id'])) { $topic_id = absint(mb_get_topic_id($_GET['topic_id'])); /* Verify the nonce. */ check_admin_referer("spam_topic_{$topic_id}"); /* Assume the changed failed. */ $notice = 'failure'; /* Check if the topic is open. */ $is_spam = mb_is_topic_spam($topic_id); /* Update the post status. */ $updated = $is_spam ? mb_unspam_topic($topic_id) : mb_spam_topic($topic_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('topic_id' => $topic_id, 'mb_topic_notice' => $notice), remove_query_arg(array('action', 'topic_id', '_wpnonce'))); wp_safe_redirect($redirect); /* Always exit for good measure. */ exit; } elseif (isset($_GET['action']) && 'mb_toggle_sticky' === $_GET['action'] && isset($_GET['topic_id'])) { $topic_id = absint(mb_get_topic_id($_GET['topic_id'])); /* Verify the nonce. */ check_admin_referer("sticky_topic_{$topic_id}"); /* Assume the changed failed. */ $notice = 'failure'; /* Check if the topic is sticky. */ $is_sticky = mb_is_topic_sticky($topic_id); /* Update the topic type. */ if ($is_sticky) { $updated = mb_remove_sticky_topic($topic_id); mb_set_topic_type($topic_id, 'normal'); } else { $updated = mb_add_sticky_topic($topic_id); mb_set_topic_type($topic_id, 'sticky'); } /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = $is_sticky ? 'unsticky' : 'sticky'; } /* Redirect to correct admin page. */ $redirect = add_query_arg(array('topic_id' => $topic_id, 'mb_topic_notice' => $notice), remove_query_arg(array('action', 'topic_id', '_wpnonce'))); wp_safe_redirect($redirect); /* Always exit for good measure. */ exit; } elseif (isset($_GET['action']) && 'mb_toggle_super' === $_GET['action'] && isset($_GET['topic_id'])) { $topic_id = absint(mb_get_topic_id($_GET['topic_id'])); /* Verify the nonce. */ check_admin_referer("super_topic_{$topic_id}"); /* Assume the changed failed. */ $notice = 'failure'; /* Check if the topic is sticky. */ $is_super = mb_is_topic_super($topic_id); /* Update the topic type. */ if ($is_super) { $updated = mb_remove_super_topic($topic_id); mb_set_topic_type($topic_id, 'normal'); } else { $updated = mb_add_super_topic($topic_id); mb_set_topic_type($topic_id, 'super'); } /* If the status was updated, add notice slug. */ if ($updated && !is_wp_error($updated)) { $notice = $is_sticky ? 'unsuper' : 'super'; } /* Redirect to correct admin page. */ $redirect = add_query_arg(array('topic_id' => $topic_id, 'mb_topic_notice' => $notice), remove_query_arg(array('action', 'topic_id', '_wpnonce'))); wp_safe_redirect($redirect); /* Always exit for good measure. */ exit; } }
function mb_handler_topic_toggle_spam() { if (!isset($_GET['action']) || 'mb_toggle_spam' !== $_GET['action'] || !isset($_GET['topic_id'])) { return; } $topic_id = mb_get_topic_id($_GET['topic_id']); /* Verify nonce. */ if (!isset($_GET['mb_nonce']) || !wp_verify_nonce($_GET['mb_nonce'], "spam_topic_{$topic_id}")) { return; } if (!current_user_can('spam_topic', $topic_id)) { return; } $updated = mb_is_topic_spam($topic_id) ? mb_unspam_topic($topic_id) : mb_spam_topic($topic_id); $redirect = remove_query_arg(array('action', 'topic_id', 'mb_nonce')); wp_safe_redirect(esc_url($redirect)); }