/**
  * Callback function for handling post status changes.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function handler()
 {
     /* Checks if the close toggle link was clicked. */
     if (isset($_GET['mb_toggle_status']) && isset($_GET['forum_id'])) {
         $forum_id = absint(mb_get_forum_id($_GET['forum_id']));
         /* Assume the changed failed. */
         $notice = 'failure';
         if ('open' === $_GET['mb_toggle_status'] && !mb_is_forum_open($forum_id)) {
             /* Verify the nonce. */
             check_admin_referer("open_forum_{$forum_id}");
             /* Update the post status. */
             $updated = mb_open_forum($forum_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_forum_closed($forum_id)) {
             /* Verify the nonce. */
             check_admin_referer("close_forum_{$forum_id}");
             /* Update the post status. */
             $updated = mb_close_forum($forum_id);
             /* If the status was updated, add notice slug. */
             if ($updated && !is_wp_error($updated)) {
                 $notice = mb_get_close_post_status();
             }
         } elseif ('archive' === $_GET['mb_toggle_status'] && !mb_is_forum_archived($forum_id)) {
             /* Verify the nonce. */
             check_admin_referer("archive_forum_{$forum_id}");
             /* Update the post status. */
             $updated = mb_archive_forum($forum_id);
             /* If the status was updated, add notice slug. */
             if ($updated && !is_wp_error($updated)) {
                 $notice = mb_get_archive_post_status();
             }
         }
         /* Redirect to correct admin page. */
         $redirect = add_query_arg(array('forum_id' => $forum_id, 'mb_forum_notice' => $notice), remove_query_arg(array('action', 'mb_toggle_status', 'forum_id', '_wpnonce')));
         wp_safe_redirect($redirect);
         /* Always exit for good measure. */
         exit;
     }
 }
示例#2
0
function mb_handler_forum_toggle_open()
{
    $actions = array('mb_toggle_open', 'mb_toggle_close');
    if (!isset($_GET['action']) || !in_array($_GET['action'], $actions) || !isset($_GET['forum_id'])) {
        return;
    }
    $forum_id = mb_get_forum_id($_GET['forum_id']);
    if ('mb_toggle_open' === $_GET['action']) {
        /* Verify nonce. */
        if (!isset($_GET['mb_nonce']) || !wp_verify_nonce($_GET['mb_nonce'], "open_forum_{$forum_id}")) {
            return;
        }
        if (mb_is_forum_open($forum_id) || !current_user_can('open_forum', $forum_id)) {
            return;
        }
        $updated = mb_open_forum($forum_id);
    } elseif ('mb_toggle_close' === $_GET['action']) {
        /* Verify nonce. */
        if (!isset($_GET['mb_nonce']) || !wp_verify_nonce($_GET['mb_nonce'], "close_forum_{$forum_id}")) {
            return;
        }
        if (mb_is_forum_closed($forum_id) || !current_user_can('close_forum', $forum_id)) {
            return;
        }
        $updated = mb_close_forum($forum_id);
    }
    $redirect = remove_query_arg(array('action', 'forum_id', 'mb_nonce'));
    wp_safe_redirect(esc_url($redirect));
}