Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/11/2014 02:48:00 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Preliminary template support for un/approving topics. Props netweb. See #2645.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/topics/template.php

    r5477 r5504  
    177177            bbp_get_closed_status_id(),
    178178            bbp_get_spam_status_id(),
    179             bbp_get_trash_status_id()
     179            bbp_get_trash_status_id(),
     180            bbp_get_pending_status_id()
    180181        );
    181182
     
    12321233
    12331234/**
     1235 * Is the topic pending?
     1236 *
     1237 * @since bbPress (r5504)
     1238 *
     1239 * @param int $topic_id Optional. Topic id
     1240 * @uses bbp_get_topic_id() To get the topic id
     1241 * @uses bbp_get_topic_status() To get the topic status
     1242 * @uses apply_filters() Calls 'bbp_is_topic_pending' with the topic id
     1243 * @return bool True if pending, false if not.
     1244 */
     1245function bbp_is_topic_pending( $topic_id = 0 ) {
     1246    $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_pending_status_id();
     1247    return (bool) apply_filters( 'bbp_is_topic_pending', (bool) $topic_status, $topic_id );
     1248}
     1249
     1250/**
     1251 * Is the topic private?
     1252 *
     1253 * @since bbPress (r5504)
     1254 *
     1255 * @param int $topic_id Optional. Topic id
     1256 * @uses bbp_get_topic_id() To get the topic id
     1257 * @uses bbp_get_topic_status() To get the topic status
     1258 * @uses apply_filters() Calls 'bbp_is_topic_private' with the topic id
     1259 * @return bool True if private, false if not.
     1260 */
     1261function bbp_is_topic_private( $topic_id = 0 ) {
     1262    $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_private_status_id();
     1263    return (bool) apply_filters( 'bbp_is_topic_private', (bool) $topic_status, $topic_id );
     1264}
     1265
     1266/**
    12341267 * Is the posted by an anonymous user?
    12351268 *
     
    24472480        if ( empty( $r['links'] ) ) {
    24482481            $r['links'] = apply_filters( 'bbp_topic_admin_links', array(
    2449                 'edit'  => bbp_get_topic_edit_link ( $r ),
    2450                 'close' => bbp_get_topic_close_link( $r ),
    2451                 'stick' => bbp_get_topic_stick_link( $r ),
    2452                 'merge' => bbp_get_topic_merge_link( $r ),
    2453                 'trash' => bbp_get_topic_trash_link( $r ),
    2454                 'spam'  => bbp_get_topic_spam_link ( $r ),
    2455                 'reply' => bbp_get_topic_reply_link( $r )
     2482                'edit'    => bbp_get_topic_edit_link   ( $r ),
     2483                'close'   => bbp_get_topic_close_link  ( $r ),
     2484                'stick'   => bbp_get_topic_stick_link  ( $r ),
     2485                'merge'   => bbp_get_topic_merge_link  ( $r ),
     2486                'trash'   => bbp_get_topic_trash_link  ( $r ),
     2487                'spam'    => bbp_get_topic_spam_link   ( $r ),
     2488                'approve' => bbp_get_topic_approve_link( $r ),
     2489                'reply'   => bbp_get_topic_reply_link  ( $r )
    24562490            ), $r['id'] );
    24572491        }
     
    24592493        // See if links need to be unset
    24602494        $topic_status = bbp_get_topic_status( $r['id'] );
    2461         if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) {
    2462 
    2463             // Close link shouldn't be visible on trashed/spammed topics
     2495        if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ) ) ) {
     2496
     2497            // Close link shouldn't be visible on trashed/spammed/pending topics
    24642498            unset( $r['links']['close'] );
    24652499
     
    27342768
    27352769/**
     2770 * Output the approve link of the topic
     2771 *
     2772 * @since bbPress (r5504)
     2773 *
     2774 * @param mixed $args See {@link bbp_get_topic_approve_link()}
     2775 * @uses bbp_get_topic_approve_link() To get the topic approve link
     2776 */
     2777function bbp_topic_approve_link( $args = '' ) {
     2778    echo bbp_get_topic_approve_link( $args );
     2779}
     2780
     2781    /**
     2782     * Return the approve link of the topic
     2783     *
     2784     * @since bbPress (r5504)
     2785     *
     2786     * @param mixed $args This function supports these args:
     2787     *  - id: Optional. Topic id
     2788     *  - link_before: Before the link
     2789     *  - link_after: After the link
     2790     *  - sep: Separator between links
     2791     *  - approve_text: Approve text
     2792     *  - unapprove_text: Unapprove text
     2793     * @uses bbp_get_topic_id() To get the topic id
     2794     * @uses bbp_get_topic() To get the topic
     2795     * @uses current_user_can() To check if the current user can approve the topic
     2796     * @uses bbp_is_topic_pending() To check if the topic is pending
     2797     * @uses add_query_arg() To add custom args to the url
     2798     * @uses wp_nonce_url() To nonce the url
     2799     * @uses esc_url() To escape the url
     2800     * @uses apply_filters() Calls 'bbp_get_topic_approve_link' with the link
     2801     *                        and args
     2802     * @return string Topic approve link
     2803     */
     2804    function bbp_get_topic_approve_link( $args = '' ) {
     2805
     2806        // Parse arguments against default values
     2807        $r = bbp_parse_args( $args, array(
     2808            'id'             => 0,
     2809            'link_before'    => '',
     2810            'link_after'     => '',
     2811            'sep'            => ' | ',
     2812            'approve_text'   => _x( 'Approve',   'Pending Status', 'bbpress' ),
     2813            'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' )
     2814        ), 'get_topic_approve_link' );
     2815
     2816        $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) );
     2817
     2818        if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) {
     2819            return;
     2820        }
     2821
     2822        $display = bbp_is_topic_pending( $topic->ID ) ? $r['approve_text'] : $r['unapprove_text'];
     2823        $uri     = add_query_arg( array( 'action' => 'bbp_toggle_topic_approve', 'topic_id' => $topic->ID ) );
     2824        $uri     = wp_nonce_url( $uri, 'approve-topic_' . $topic->ID );
     2825        $retval  = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-approve-link">' . $display . '</a>' . $r['link_after'];
     2826
     2827        return apply_filters( 'bbp_get_topic_approve_link', $retval, $r );
     2828    }
     2829
     2830/**
    27362831 * Output the stick link of the topic
    27372832 *
Note: See TracChangeset for help on using the changeset viewer.