Exemplo n.º 1
0
/**
 * Sticks a topic to a forum or front
 *
 * @since bbPress (r2754)
 *
 * @param int $topic_id Optional. Topic id
 * @param int $super Should we make the topic a super sticky?
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_unstick_topic() To unstick the topic
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_stickies() To get the stickies
 * @uses do_action() 'bbp_stick_topic' with topic id and bool super
 * @uses update_option() To update the super stickies option
 * @uses update_post_meta() To update the forum stickies meta
 * @uses do_action() Calls 'bbp_sticked_topic' with the topic id, bool super
 *                    and success
 * @return bool True on success, false on failure
 */
function bbp_stick_topic($topic_id = 0, $super = false)
{
    $topic_id = bbp_get_topic_id($topic_id);
    // We may have a super sticky to which we want to convert into a normal sticky and vice versa
    // So, unstick the topic first to avoid any possible error
    bbp_unstick_topic($topic_id);
    $forum_id = empty($super) ? bbp_get_topic_forum_id($topic_id) : 0;
    $stickies = bbp_get_stickies($forum_id);
    do_action('bbp_stick_topic', $topic_id, $super);
    if (!is_array($stickies)) {
        $stickies = array($topic_id);
    } else {
        $stickies[] = $topic_id;
    }
    $stickies = array_unique(array_filter($stickies));
    $success = !empty($super) ? update_option('_bbp_super_sticky_topics', $stickies) : update_post_meta($forum_id, '_bbp_sticky_topics', $stickies);
    do_action('bbp_sticked_topic', $topic_id, $super, $success);
    return $success;
}
Exemplo n.º 2
0
/**
 * Sticks a topic to a forum or front
 *
 * @since bbPress (r2754)
 *
 * @param int $topic_id Optional. Topic id
 * @param int $super Should we make the topic a super sticky?
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_unstick_topic() To unstick the topic
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_stickies() To get the stickies
 * @uses do_action() 'bbp_stick_topic' with topic id and bool super
 * @uses update_option() To update the super stickies option
 * @uses update_post_meta() To update the forum stickies meta
 * @uses do_action() Calls 'bbp_sticked_topic' with the topic id, bool super
 *                    and success
 * @return bool True on success, false on failure
 */
function bbp_stick_topic($topic_id = 0, $super = false)
{
    $topic_id = bbp_get_topic_id($topic_id);
    // Bail if a topic is not a topic (prevents revisions as stickies)
    if (!bbp_is_topic($topic_id)) {
        return false;
    }
    // We may have a super sticky to which we want to convert into a normal
    // sticky and vice versa; unstick the topic first to avoid any possible error.
    bbp_unstick_topic($topic_id);
    $forum_id = empty($super) ? bbp_get_topic_forum_id($topic_id) : 0;
    $stickies = bbp_get_stickies($forum_id);
    do_action('bbp_stick_topic', $topic_id, $super);
    if (!is_array($stickies)) {
        $stickies = array($topic_id);
    } else {
        $stickies[] = $topic_id;
    }
    // Pull out duplicates and empties
    $stickies = array_unique(array_filter($stickies));
    // Unset incorrectly stuck revisions
    foreach ((array) $stickies as $key => $id) {
        if (!bbp_is_topic($id)) {
            unset($stickies[$key]);
        }
    }
    // Reset keys
    $stickies = array_values($stickies);
    $success = !empty($super) ? update_option('_bbp_super_sticky_topics', $stickies) : update_post_meta($forum_id, '_bbp_sticky_topics', $stickies);
    do_action('bbp_sticked_topic', $topic_id, $super, $success);
    return (bool) $success;
}
Exemplo n.º 3
0
 /**
  * Toggle topic
  *
  * Handles the admin-side opening/closing, sticking/unsticking and
  * spamming/unspamming of topics
  *
  * @since 2.0.0 bbPress (r2727)
  *
  * @uses bbp_get_topic() To get the topic
  * @uses current_user_can() To check if the user is capable of editing
  *                           the topic
  * @uses wp_die() To die if the user isn't capable or the post wasn't
  *                 found
  * @uses check_admin_referer() To verify the nonce and check referer
  * @uses bbp_is_topic_open() To check if the topic is open
  * @uses bbp_close_topic() To close the topic
  * @uses bbp_open_topic() To open the topic
  * @uses bbp_is_topic_sticky() To check if the topic is a sticky or
  *                              super sticky
  * @uses bbp_unstick_topic() To unstick the topic
  * @uses bbp_stick_topic() To stick the topic
  * @uses bbp_is_topic_spam() To check if the topic is marked as spam
  * @uses bbp_unspam_topic() To unmark the topic as spam
  * @uses bbp_spam_topic() To mark the topic as spam
  * @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post
  *                    data, action and message
  * @uses add_query_arg() To add custom args to the url
  * @uses bbp_redirect() Redirect the page to custom url
  */
 public function toggle_topic()
 {
     if ($this->bail()) {
         return;
     }
     // Only proceed if GET is a topic toggle action
     if (bbp_is_get_request() && !empty($_GET['action']) && in_array($_GET['action'], array('bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_approve')) && !empty($_GET['topic_id'])) {
         $action = $_GET['action'];
         // What action is taking place?
         $topic_id = (int) $_GET['topic_id'];
         // What's the topic id?
         $success = false;
         // Flag
         $post_data = array('ID' => $topic_id);
         // Prelim array
         $topic = bbp_get_topic($topic_id);
         // Verify the topic id
         // Bail if topic is missing
         if (empty($topic)) {
             wp_die(__('The topic was not found!', 'bbpress'));
         }
         // What is the user doing here?
         if (!current_user_can('moderate', $topic->ID)) {
             wp_die(__('You do not have the permission to do that!', 'bbpress'));
         }
         switch ($action) {
             case 'bbp_toggle_topic_approve':
                 check_admin_referer('approve-topic_' . $topic_id);
                 $is_approve = bbp_is_topic_pending($topic_id);
                 $message = true === $is_approve ? 'approved' : 'unapproved';
                 $success = true === $is_approve ? bbp_approve_topic($topic_id) : bbp_unapprove_topic($topic_id);
                 break;
             case 'bbp_toggle_topic_close':
                 check_admin_referer('close-topic_' . $topic_id);
                 $is_open = bbp_is_topic_open($topic_id);
                 $message = true === $is_open ? 'closed' : 'opened';
                 $success = true === $is_open ? bbp_close_topic($topic_id) : bbp_open_topic($topic_id);
                 break;
             case 'bbp_toggle_topic_stick':
                 check_admin_referer('stick-topic_' . $topic_id);
                 $is_sticky = bbp_is_topic_sticky($topic_id);
                 $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false;
                 $message = true === $is_sticky ? 'unstuck' : 'stuck';
                 $message = true === $is_super ? 'super_sticky' : $message;
                 $success = true === $is_sticky ? bbp_unstick_topic($topic_id) : bbp_stick_topic($topic_id, $is_super);
                 break;
             case 'bbp_toggle_topic_spam':
                 check_admin_referer('spam-topic_' . $topic_id);
                 $is_spam = bbp_is_topic_spam($topic_id);
                 $message = true === $is_spam ? 'unspammed' : 'spammed';
                 $success = true === $is_spam ? bbp_unspam_topic($topic_id) : bbp_spam_topic($topic_id);
                 break;
         }
         $message = array('bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID);
         if (false === $success || is_wp_error($success)) {
             $message['failed'] = '1';
         }
         // Do additional topic toggle actions (admin side)
         do_action('bbp_toggle_topic_admin', $success, $post_data, $action, $message);
         // Redirect back to the topic
         $redirect = add_query_arg($message, remove_query_arg(array('action', 'topic_id')));
         bbp_redirect($redirect);
     }
 }