Exemple #1
0
/**
 * Redirect to search results page if needed
 *
 * @since 2.4.0 bbPress (r4928)
 *
 * @return If a redirect is not needed
 */
function bbp_search_results_redirect()
{
    // Bail if not a search request action
    if (empty($_GET['action']) || 'bbp-search-request' !== $_GET['action']) {
        return;
    }
    // Bail if not using pretty permalinks
    if (!bbp_use_pretty_urls()) {
        return;
    }
    // Get the redirect URL
    $redirect_to = bbp_get_search_results_url();
    if (empty($redirect_to)) {
        return;
    }
    // Redirect and bail
    bbp_redirect($redirect_to);
}
Exemple #2
0
 /**
  * Toggle reply
  *
  * Handles the admin-side spamming/unspamming of replies
  *
  * @since 2.0.0 bbPress (r2740)
  *
  * @uses bbp_get_reply() To get the reply
  * @uses current_user_can() To check if the user is capable of editing
  *                           the reply
  * @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_reply_spam() To check if the reply is marked as spam
  * @uses bbp_unspam_reply() To unmark the reply as spam
  * @uses bbp_spam_reply() To mark the reply as spam
  * @uses do_action() Calls 'bbp_toggle_reply_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_reply()
 {
     if ($this->bail()) {
         return;
     }
     // Only proceed if GET is a reply toggle action
     if (bbp_is_get_request() && !empty($_GET['action']) && in_array($_GET['action'], array('bbp_toggle_reply_spam', 'bbp_toggle_reply_approve')) && !empty($_GET['reply_id'])) {
         $action = $_GET['action'];
         // What action is taking place?
         $reply_id = (int) $_GET['reply_id'];
         // What's the reply id?
         $success = false;
         // Flag
         $post_data = array('ID' => $reply_id);
         // Prelim array
         // Get reply and die if empty
         $reply = bbp_get_reply($reply_id);
         if (empty($reply)) {
             wp_die(__('The reply was not found!', 'bbpress'));
         }
         // What is the user doing here?
         if (!current_user_can('moderate', $reply->ID)) {
             wp_die(__('You do not have the permission to do that!', 'bbpress'));
         }
         switch ($action) {
             case 'bbp_toggle_reply_approve':
                 check_admin_referer('approve-reply_' . $reply_id);
                 $is_approve = bbp_is_reply_pending($reply_id);
                 $message = $is_approve ? 'approved' : 'unapproved';
                 $success = $is_approve ? bbp_approve_reply($reply_id) : bbp_unapprove_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 = $is_spam ? 'unspammed' : 'spammed';
                 $success = $is_spam ? bbp_unspam_reply($reply_id) : bbp_spam_reply($reply_id);
                 break;
         }
         $message = array('bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID);
         if (false === $success || is_wp_error($success)) {
             $message['failed'] = '1';
         }
         // Do additional reply toggle actions (admin side)
         do_action('bbp_toggle_reply_admin', $success, $post_data, $action, $message);
         // Redirect back to the reply
         $redirect = add_query_arg($message, remove_query_arg(array('action', 'reply_id')));
         bbp_redirect($redirect);
     }
 }
Exemple #3
0
/**
 * Mark notifications as read when reading a topic
 *
 * @since 2.5.0 bbPress (r5155)
 *
 * @return If not trying to mark a notification as read
 */
function bbp_buddypress_mark_notifications($action = '')
{
    // Bail if no topic ID is passed
    if (empty($_GET['topic_id'])) {
        return;
    }
    // Bail if action is not for this function
    if ('bbp_mark_read' !== $action) {
        return;
    }
    // Get required data
    $user_id = bp_loggedin_user_id();
    $topic_id = intval($_GET['topic_id']);
    // Check nonce
    if (!bbp_verify_nonce_request('bbp_mark_topic_' . $topic_id)) {
        bbp_add_error('bbp_notification_topic_id', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        // Check current user's ability to edit the user
    } elseif (!current_user_can('edit_user', $user_id)) {
        bbp_add_error('bbp_notification_permissions', __('<strong>ERROR</strong>: You do not have permission to mark notifications for that user.', 'bbpress'));
    }
    // Bail if we have errors
    if (!bbp_has_errors()) {
        // Attempt to clear notifications for the current user from this topic
        $success = bp_notifications_mark_notifications_by_item_id($user_id, $topic_id, bbp_get_component_name(), 'bbp_new_reply');
        // Do additional subscriptions actions
        do_action('bbp_notifications_handler', $success, $user_id, $topic_id, $action);
    }
    // Redirect to the topic
    $redirect = bbp_get_reply_url($topic_id);
    // Redirect
    bbp_redirect($redirect);
}
/**
 * Redirect a user back to their profile if they are already logged in.
 *
 * This should be used before {@link get_header()} is called in template files
 * where the user should never have access to the contents of that file.
 *
 * @since 2.0.0 bbPress (r2815)
 *
 * @param string $url The URL to redirect to
 * @uses is_user_logged_in() Check if user is logged in
 * @uses bbp_redirect() To safely redirect
 * @uses bbp_get_user_profile_url() To get the profile url of the user
 * @uses bbp_get_current_user_id() To get the current user id
 */
function bbp_logged_in_redirect($url = '')
{
    // Bail if user is not logged in
    if (!is_user_logged_in()) {
        return;
    }
    // Setup the profile page to redirect to
    $redirect_to = !empty($url) ? $url : bbp_get_user_profile_url(bbp_get_current_user_id());
    // Do a safe redirect
    bbp_redirect($redirect_to);
}
Exemple #5
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);
     }
 }
/**
 * Redirect if unathorized user is attempting to edit a topic tag
 *
 * @since 2.1.0 bbPress (r3605)
 *
 * @uses bbp_is_topic_tag_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_tag_id()
 * @uses bbp_redirect()
 * @uses bbp_get_topic_tag_link()
 */
function bbp_check_topic_tag_edit()
{
    // Bail if not editing a topic tag
    if (!bbp_is_topic_tag_edit()) {
        return;
    }
    // Bail if current user cannot edit topic tags
    if (!current_user_can('edit_topic_tags', bbp_get_topic_tag_id())) {
        bbp_redirect(bbp_get_topic_tag_link());
    }
}
/**
 * Redirect if unathorized user is attempting to edit a forum
 *
 * @since 2.1.0 bbPress (r3607)
 *
 * @uses bbp_is_forum_edit()
 * @uses current_user_can()
 * @uses bbp_get_forum_id()
 * @uses bbp_redirect()
 * @uses bbp_get_forum_permalink()
 */
function bbp_check_forum_edit()
{
    // Bail if not editing a topic
    if (!bbp_is_forum_edit()) {
        return;
    }
    // User cannot edit topic, so redirect back to reply
    if (!current_user_can('edit_forum', bbp_get_forum_id())) {
        bbp_redirect(bbp_get_forum_permalink());
    }
}
/**
 * Redirect if unathorized user is attempting to edit another user
 *
 * This is hooked to 'bbp_template_redirect' and controls the conditions under
 * which a user can edit another user (or themselves.) If these conditions are
 * met, we assume a user cannot perform this task, and look for ways they can
 * earn the ability to access this template.
 *
 * @since 2.1.0 bbPress (r3605)
 *
 * @uses bbp_is_single_user_edit()
 * @uses current_user_can()
 * @uses bbp_get_displayed_user_id()
 * @uses bbp_redirect()
 * @uses bbp_get_user_profile_url()
 */
function bbp_check_user_edit()
{
    // Bail if not editing a user
    if (!bbp_is_single_user_edit()) {
        return;
    }
    // Default to false
    $redirect = true;
    $user_id = bbp_get_displayed_user_id();
    // Allow user to edit their own profile
    if (bbp_is_user_home_edit()) {
        $redirect = false;
        // Allow if current user can edit the displayed user
    } elseif (current_user_can('edit_user', $user_id)) {
        $redirect = false;
        // Allow if user can manage network users, or edit-any is enabled
    } elseif (current_user_can('manage_network_users') || apply_filters('enable_edit_any_user_configuration', false)) {
        $redirect = false;
    }
    // Allow conclusion to be overridden
    $redirect = (bool) apply_filters('bbp_check_user_edit', $redirect, $user_id);
    // Bail if not redirecting
    if (false === $redirect) {
        return;
    }
    // Filter redirect URL
    $profile_url = bbp_get_user_profile_url($user_id);
    $redirect_to = apply_filters('bbp_check_user_edit_redirect_to', $profile_url, $user_id);
    // Redirect
    bbp_redirect($redirect_to);
}
/**
 * Redirect if unathorized user is attempting to edit a reply
 *
 * @since 2.1.0 bbPress (r3605)
 *
 * @uses bbp_is_reply_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_id()
 * @uses bbp_redirect()
 * @uses bbp_get_topic_permalink()
 */
function bbp_check_reply_edit()
{
    // Bail if not editing a topic
    if (!bbp_is_reply_edit()) {
        return;
    }
    // User cannot edit topic, so redirect back to reply
    if (!current_user_can('edit_reply', bbp_get_reply_id())) {
        bbp_redirect(bbp_get_reply_url());
    }
}
Exemple #10
0
 /**
  * Toggle forum
  *
  * Handles the admin-side opening/closing of forums
  *
  * @since 2.6.0 bbPress (r5254)
  *
  * @uses bbp_get_forum() To get the forum
  * @uses current_user_can() To check if the user is capable of editing
  *                           the forum
  * @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_forum_open() To check if the forum is open
  * @uses bbp_close_forum() To close the forum
  * @uses bbp_open_forum() To open the forum
  * @uses do_action() Calls 'bbp_toggle_forum_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_forum()
 {
     if ($this->bail()) {
         return;
     }
     // Only proceed if GET is a forum toggle action
     if (bbp_is_get_request() && !empty($_GET['action']) && in_array($_GET['action'], array('bbp_toggle_forum_close')) && !empty($_GET['forum_id'])) {
         $action = $_GET['action'];
         // What action is taking place?
         $forum_id = (int) $_GET['forum_id'];
         // What's the forum id?
         $success = false;
         // Flag
         $post_data = array('ID' => $forum_id);
         // Prelim array
         $forum = bbp_get_forum($forum_id);
         // Bail if forum is missing
         if (empty($forum)) {
             wp_die(__('The forum was not found!', 'bbpress'));
         }
         // What is the user doing here?
         if (!current_user_can('keep_gate', $forum->ID)) {
             wp_die(__('You do not have the permission to do that!', 'bbpress'));
         }
         switch ($action) {
             case 'bbp_toggle_forum_close':
                 check_admin_referer('close-forum_' . $forum_id);
                 $is_open = bbp_is_forum_open($forum_id);
                 $message = true === $is_open ? 'closed' : 'opened';
                 $success = true === $is_open ? bbp_close_forum($forum_id) : bbp_open_forum($forum_id);
                 break;
         }
         $message = array('bbp_forum_toggle_notice' => $message, 'forum_id' => $forum->ID);
         if (false === $success || is_wp_error($success)) {
             $message['failed'] = '1';
         }
         // Do additional forum toggle actions (admin side)
         do_action('bbp_toggle_forum_admin', $success, $post_data, $action, $message);
         // Redirect back to the forum
         $redirect = add_query_arg($message, remove_query_arg(array('action', 'forum_id')));
         bbp_redirect($redirect);
     }
 }
/**
 * Redirect user to bbPress's What's New page on activation
 *
 * @since 2.2.0 bbPress (r4389)
 *
 * @internal Used internally to redirect bbPress to the about page on activation
 *
 * @uses get_transient() To see if transient to redirect exists
 * @uses delete_transient() To delete the transient if it exists
 * @uses is_network_admin() To bail if being network activated
 * @uses bbp_redirect() To redirect
 * @uses add_query_arg() To help build the URL to redirect to
 * @uses admin_url() To get the admin URL to index.php
 *
 * @return If no transient, or in network admin, or is bulk activation
 */
function bbp_do_activation_redirect()
{
    // Bail if no activation redirect
    if (!get_transient('_bbp_activation_redirect')) {
        return;
    }
    // Delete the redirect transient
    delete_transient('_bbp_activation_redirect');
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Bail if the current user cannot see the about page
    if (!current_user_can('bbp_about_page')) {
        return;
    }
    // Redirect to bbPress about page
    bbp_redirect(add_query_arg(array('page' => 'bbp-about'), admin_url('index.php')));
}