Ejemplo n.º 1
0
/**
 * The main action used for handling theme-side GET requests
 *
 * @since 2.3.0 bbPress (r4550)
 *
 * @uses do_action()
 */
function bbp_get_request()
{
    // Bail if not a POST action
    if (!bbp_is_get_request()) {
        return;
    }
    // Bail if no action
    if (empty($_GET['action'])) {
        return;
    }
    // Sanitize the GET action
    $action = sanitize_key($_GET['action']);
    // This dynamic action is probably the one you want to use. It narrows down
    // the scope of the 'action' without needing to check it in your function.
    do_action('bbp_get_request_' . $action);
    // Use this static action if you don't mind checking the 'action' yourself.
    do_action('bbp_get_request', $action);
}
Ejemplo n.º 2
0
/**
 * Handle the processing and feedback of the admin tools page
 *
 * @since 2.0.0 bbPress (r2613)
 *
 * @uses bbp_admin_repair_list() To get the recount list
 * @uses check_admin_referer() To verify the nonce and the referer
 * @uses wp_cache_flush() To flush the cache
 * @uses do_action() Calls 'admin_notices' to display the notices
 */
function bbp_admin_repair_handler()
{
    if (!bbp_is_get_request()) {
        return;
    }
    // Get the current action or bail
    if (!empty($_GET['action'])) {
        $action = sanitize_key($_GET['action']);
    } elseif (!empty($_GET['action2'])) {
        $action = sanitize_key($_GET['action2']);
    } else {
        return;
    }
    // Bail if not running an action
    if ('run' !== $action) {
        return;
    }
    check_admin_referer('bbpress-do-counts');
    // Stores messages
    $messages = array();
    // Kill all the caches, because we don't know what's where anymore
    wp_cache_flush();
    // Get the list
    $list = bbp_get_admin_repair_tools();
    // Run through checked repair tools
    if (!empty($_GET['checked'])) {
        foreach ($_GET['checked'] as $item_id) {
            if (isset($list[$item_id]) && is_callable($list[$item_id]['callback'])) {
                $messages[] = call_user_func($list[$item_id]['callback']);
            }
        }
    }
    // Feedback
    if (count($messages)) {
        foreach ($messages as $message) {
            bbp_admin_tools_feedback($message[1]);
        }
    }
    // @todo Redirect away from here
}
Ejemplo n.º 3
0
        /**
         * Toggle reply notices
         *
         * Display the success/error notices from
         * {@link BBP_Admin::toggle_reply()}
         *
         * @since 2.0.0 bbPress (r2740)
         *
         * @uses bbp_get_reply() To get the reply
         * @uses bbp_get_reply_title() To get the reply title of the reply
         * @uses esc_html() To sanitize the reply title
         * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with
         *                        message, reply id, notice and is it a failure
         */
        public function toggle_reply_notice()
        {
            if ($this->bail()) {
                return;
            }
            // Only proceed if GET is a reply toggle action
            if (bbp_is_get_request() && !empty($_GET['bbp_reply_toggle_notice']) && in_array($_GET['bbp_reply_toggle_notice'], array('spammed', 'unspammed', 'approved', 'unapproved')) && !empty($_GET['reply_id'])) {
                $notice = $_GET['bbp_reply_toggle_notice'];
                // Which notice?
                $reply_id = (int) $_GET['reply_id'];
                // What's the reply id?
                $is_failure = !empty($_GET['failed']) ? true : false;
                // Was that a failure?
                // Empty? No reply?
                if (empty($notice) || empty($reply_id)) {
                    return;
                }
                // Get reply and bail if empty
                $reply = bbp_get_reply($reply_id);
                if (empty($reply)) {
                    return;
                }
                $reply_title = bbp_get_reply_title($reply->ID);
                switch ($notice) {
                    case 'spammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem marking the reply "%1$s" as spam.', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully marked as spam.', 'bbpress'), $reply_title);
                        break;
                    case 'unspammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem unmarking the reply "%1$s" as spam.', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully unmarked as spam.', 'bbpress'), $reply_title);
                        break;
                    case 'approved':
                        $message = $is_failure === true ? sprintf(__('There was a problem approving the reply "%1$s".', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully approved.', 'bbpress'), $reply_title);
                        break;
                    case 'unapproved':
                        $message = $is_failure === true ? sprintf(__('There was a problem unapproving the reply "%1$s".', 'bbpress'), $reply_title) : sprintf(__('Reply "%1$s" successfully unapproved.', 'bbpress'), $reply_title);
                        break;
                }
                // Do additional reply toggle notice filters (admin side)
                $message = apply_filters('bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure);
                ?>

			<div id="message" class="<?php 
                echo $is_failure === true ? 'error' : 'updated';
                ?>
 fade">
				<p style="line-height: 150%"><?php 
                echo esc_html($message);
                ?>
</p>
			</div>

			<?php 
            }
        }
    /**
     * Prints an admin notice when a reply has been (un)reported
     *
     * @since 1.0.0
     *
     * @return null
     */
    public function toggle_reply_notice_admin()
    {
        // Bail if we're not editing replies
        if (bbp_get_reply_post_type() != get_current_screen()->post_type) {
            return;
        }
        // Only proceed if GET is a reply toggle action
        if (bbp_is_get_request() && !empty($_GET['bbp_reply_toggle_notice']) && in_array($_GET['bbp_reply_toggle_notice'], array('unreported')) && !empty($_GET['reply_id'])) {
            $notice = $_GET['bbp_reply_toggle_notice'];
            // Which notice?
            $reply_id = (int) $_GET['reply_id'];
            // What's the reply id?
            $is_failure = !empty($_GET['failed']) ? true : false;
            // Was that a failure?
            // Bails if no reply_id or notice
            if (empty($notice) || empty($reply_id)) {
                return;
            }
            // Bail if reply is missing
            $reply = bbp_get_reply($reply_id);
            if (empty($reply)) {
                return;
            }
            $reply_title = bbp_get_reply_title($reply->ID);
            switch ($notice) {
                case 'unreported':
                    $message = $is_failure === true ? sprintf(__('There was a problem unreporting the reply "%1$s".', 'bbpress-report-content'), $reply_title) : sprintf(__('Reply "%1$s" successfully unreported.', 'bbpress-report-content'), $reply_title);
                    break;
            }
            ?>

			<div id="message" class="<?php 
            echo $is_failure === true ? 'error' : 'updated';
            ?>
 fade">
				<p style="line-height: 150%"><?php 
            echo esc_html($message);
            ?>
</p>
			</div>

			<?php 
        }
    }
Ejemplo n.º 5
0
        /**
         * Toggle topic notices
         *
         * Display the success/error notices from
         * {@link BBP_Admin::toggle_topic()}
         *
         * @since 2.0.0 bbPress (r2727)
         *
         * @uses bbp_get_topic() To get the topic
         * @uses bbp_get_topic_title() To get the topic title of the topic
         * @uses esc_html() To sanitize the topic title
         * @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with
         *                        message, topic id, notice and is it a failure
         */
        public function toggle_topic_notice()
        {
            if ($this->bail()) {
                return;
            }
            // Only proceed if GET is a topic toggle action
            if (bbp_is_get_request() && !empty($_GET['bbp_topic_toggle_notice']) && in_array($_GET['bbp_topic_toggle_notice'], array('opened', 'closed', 'super_sticky', 'stuck', 'unstuck', 'spammed', 'unspammed', 'approved', 'unapproved')) && !empty($_GET['topic_id'])) {
                $notice = $_GET['bbp_topic_toggle_notice'];
                // Which notice?
                $topic_id = (int) $_GET['topic_id'];
                // What's the topic id?
                $is_failure = !empty($_GET['failed']) ? true : false;
                // Was that a failure?
                // Bais if no topic_id or notice
                if (empty($notice) || empty($topic_id)) {
                    return;
                }
                // Bail if topic is missing
                $topic = bbp_get_topic($topic_id);
                if (empty($topic)) {
                    return;
                }
                $topic_title = bbp_get_topic_title($topic->ID);
                switch ($notice) {
                    case 'opened':
                        $message = $is_failure === true ? sprintf(__('There was a problem opening the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully opened.', 'bbpress'), $topic_title);
                        break;
                    case 'closed':
                        $message = $is_failure === true ? sprintf(__('There was a problem closing the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully closed.', 'bbpress'), $topic_title);
                        break;
                    case 'super_sticky':
                        $message = $is_failure === true ? sprintf(__('There was a problem sticking the topic "%1$s" to front.', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully stuck to front.', 'bbpress'), $topic_title);
                        break;
                    case 'stuck':
                        $message = $is_failure === true ? sprintf(__('There was a problem sticking the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully stuck.', 'bbpress'), $topic_title);
                        break;
                    case 'unstuck':
                        $message = $is_failure === true ? sprintf(__('There was a problem unsticking the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully unstuck.', 'bbpress'), $topic_title);
                        break;
                    case 'spammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem marking the topic "%1$s" as spam.', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully marked as spam.', 'bbpress'), $topic_title);
                        break;
                    case 'unspammed':
                        $message = $is_failure === true ? sprintf(__('There was a problem unmarking the topic "%1$s" as spam.', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully unmarked as spam.', 'bbpress'), $topic_title);
                        break;
                    case 'approved':
                        $message = $is_failure === true ? sprintf(__('There was a problem approving the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully approved.', 'bbpress'), $topic_title);
                        break;
                    case 'unapproved':
                        $message = $is_failure === true ? sprintf(__('There was a problem unapproving the topic "%1$s".', 'bbpress'), $topic_title) : sprintf(__('Topic "%1$s" successfully unapproved.', 'bbpress'), $topic_title);
                        break;
                }
                // Do additional topic toggle notice filters (admin side)
                $message = apply_filters('bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure);
                ?>

			<div id="message" class="<?php 
                echo $is_failure === true ? 'error' : 'updated';
                ?>
 fade">
				<p style="line-height: 150%"><?php 
                echo esc_html($message);
                ?>
</p>
			</div>

			<?php 
            }
        }
Ejemplo n.º 6
0
        /**
         * Toggle forum notices
         *
         * Display the success/error notices from
         * {@link BBP_Admin::toggle_forum()}
         *
         * @since 2.6.0 bbPress (r5254)
         *
         * @uses bbp_get_forum() To get the forum
         * @uses bbp_get_forum_title() To get the forum title of the forum
         * @uses esc_html() To sanitize the forum title
         * @uses apply_filters() Calls 'bbp_toggle_forum_notice_admin' with
         *                        message, forum id, notice and is it a failure
         */
        public function toggle_forum_notice()
        {
            if ($this->bail()) {
                return;
            }
            // Only proceed if GET is a forum toggle action
            if (bbp_is_get_request() && !empty($_GET['bbp_forum_toggle_notice']) && in_array($_GET['bbp_forum_toggle_notice'], array('opened', 'closed')) && !empty($_GET['forum_id'])) {
                $notice = $_GET['bbp_forum_toggle_notice'];
                // Which notice?
                $forum_id = (int) $_GET['forum_id'];
                // What's the forum id?
                $is_failure = !empty($_GET['failed']) ? true : false;
                // Was that a failure?
                // Bail if no forum_id or notice
                if (empty($notice) || empty($forum_id)) {
                    return;
                }
                // Bail if forum is missing
                $forum = bbp_get_forum($forum_id);
                if (empty($forum)) {
                    return;
                }
                $forum_title = bbp_get_forum_title($forum->ID);
                switch ($notice) {
                    case 'opened':
                        $message = $is_failure === true ? sprintf(__('There was a problem opening the forum "%1$s".', 'bbpress'), $forum_title) : sprintf(__('Forum "%1$s" successfully opened.', 'bbpress'), $forum_title);
                        break;
                    case 'closed':
                        $message = $is_failure === true ? sprintf(__('There was a problem closing the forum "%1$s".', 'bbpress'), $forum_title) : sprintf(__('Forum "%1$s" successfully closed.', 'bbpress'), $forum_title);
                        break;
                }
                // Do additional forum toggle notice filters (admin side)
                $message = apply_filters('bbp_toggle_forum_notice_admin', $message, $forum->ID, $notice, $is_failure);
                ?>

			<div id="message" class="<?php 
                echo $is_failure === true ? 'error' : 'updated';
                ?>
 fade">
				<p style="line-height: 150%"><?php 
                echo esc_html($message);
                ?>
</p>
			</div>

			<?php 
            }
        }