Skip to:
Content

bbPress.org

Changeset 5507


Ignore:
Timestamp:
09/11/2014 02:54:13 PM (10 years ago)
Author:
johnjamesjacoby
Message:

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

File:
1 edited

Legend:

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

    r5467 r5507  
    155155            bbp_get_closed_status_id(),
    156156            bbp_get_spam_status_id(),
    157             bbp_get_trash_status_id()
     157            bbp_get_trash_status_id(),
     158            bbp_get_pending_status_id()
    158159        );
    159160
     
    957958
    958959/**
     960 * Is the reply pending?
     961 *
     962 * @since bbPress (r5507)
     963 *
     964 * @param int $reply_id Optional. Topic id
     965 * @uses bbp_get_reply_id() To get the reply id
     966 * @uses bbp_get_reply_status() To get the reply status
     967 * @uses apply_filters() Calls 'bbp_is_reply_pending' with the reply id
     968 * @return bool True if pending, false if not.
     969 */
     970function bbp_is_reply_pending( $reply_id = 0 ) {
     971    $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_pending_status_id();
     972    return (bool) apply_filters( 'bbp_is_reply_pending', (bool) $reply_status, $reply_id );
     973}
     974
     975/**
     976 * Is the reply private?
     977 *
     978 * @since bbPress (r5507)
     979 *
     980 * @param int $reply_id Optional. Topic id
     981 * @uses bbp_get_reply_id() To get the reply id
     982 * @uses bbp_get_reply_status() To get the reply status
     983 * @uses apply_filters() Calls 'bbp_is_reply_private' with the reply id
     984 * @return bool True if private, false if not.
     985 */
     986function bbp_is_reply_private( $reply_id = 0 ) {
     987    $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_private_status_id();
     988    return (bool) apply_filters( 'bbp_is_reply_private', (bool) $reply_status, $reply_id );
     989}
     990
     991/**
    959992 * Is the reply by an anonymous user?
    960993 *
     
    18581891        if ( empty( $r['links'] ) ) {
    18591892            $r['links'] = apply_filters( 'bbp_reply_admin_links', array(
    1860                 'edit'  => bbp_get_reply_edit_link ( $r ),
    1861                 'move'  => bbp_get_reply_move_link ( $r ),
    1862                 'split' => bbp_get_topic_split_link( $r ),
    1863                 'trash' => bbp_get_reply_trash_link( $r ),
    1864                 'spam'  => bbp_get_reply_spam_link ( $r ),
    1865                 'reply' => bbp_get_reply_to_link   ( $r )
     1893                'edit'    => bbp_get_reply_edit_link   ( $r ),
     1894                'move'    => bbp_get_reply_move_link   ( $r ),
     1895                'split'   => bbp_get_topic_split_link  ( $r ),
     1896                'trash'   => bbp_get_reply_trash_link  ( $r ),
     1897                'spam'    => bbp_get_reply_spam_link   ( $r ),
     1898                'approve' => bbp_get_reply_approve_link( $r ),
     1899                'reply'   => bbp_get_reply_to_link     ( $r )
    18661900            ), $r['id'] );
    18671901        }
     
    18691903        // See if links need to be unset
    18701904        $reply_status = bbp_get_reply_status( $r['id'] );
    1871         if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) {
     1905        if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ) ) ) {
    18721906
    18731907            // Spam link shouldn't be visible on trashed topics
     
    22752309
    22762310        return apply_filters( 'bbp_get_topic_split_link', $retval, $r );
     2311    }
     2312
     2313/**
     2314 * Output the approve link of the reply
     2315 *
     2316 * @since bbPress (r5507)
     2317 *
     2318 * @param mixed $args See {@link bbp_get_reply_approve_link()}
     2319 * @uses bbp_get_reply_approve_link() To get the reply approve link
     2320 */
     2321function bbp_reply_approve_link( $args = '' ) {
     2322    echo bbp_get_reply_approve_link( $args );
     2323}
     2324
     2325    /**
     2326     * Return the approve link of the reply
     2327     *
     2328     * @since bbPress (r5507)
     2329     *
     2330     * @param mixed $args This function supports these args:
     2331     *  - id: Optional. Reply id
     2332     *  - link_before: Before the link
     2333     *  - link_after: After the link
     2334     *  - sep: Separator between links
     2335     *  - approve_text: Approve text
     2336     *  - unapprove_text: Unapprove text
     2337     * @uses bbp_get_reply_id() To get the reply id
     2338     * @uses bbp_get_reply() To get the reply
     2339     * @uses current_user_can() To check if the current user can approve the reply
     2340     * @uses bbp_is_reply_pending() To check if the reply is pending
     2341     * @uses add_query_arg() To add custom args to the url
     2342     * @uses wp_nonce_url() To nonce the url
     2343     * @uses esc_url() To escape the url
     2344     * @uses apply_filters() Calls 'bbp_get_reply_approve_link' with the link
     2345     *                        and args
     2346     * @return string Reply approve link
     2347     */
     2348    function bbp_get_reply_approve_link( $args = '' ) {
     2349
     2350        // Parse arguments against default values
     2351        $r = bbp_parse_args( $args, array(
     2352            'id'             => 0,
     2353            'link_before'    => '',
     2354            'link_after'     => '',
     2355            'sep'            => ' | ',
     2356            'approve_text'   => _x( 'Approve',   'Pending Status', 'bbpress' ),
     2357            'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' )
     2358        ), 'get_reply_approve_link' );
     2359
     2360        $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) );
     2361
     2362        if ( empty( $reply ) || !current_user_can( 'moderate', $reply->ID ) ) {
     2363            return;
     2364        }
     2365
     2366        $display = bbp_is_reply_pending( $reply->ID ) ? $r['approve_text'] : $r['unapprove_text'];
     2367        $uri     = add_query_arg( array( 'action' => 'bbp_toggle_reply_approve', 'reply_id' => $reply->ID ) );
     2368        $uri     = wp_nonce_url( $uri, 'approve-reply_' . $reply->ID );
     2369        $retval  = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-approve-link">' . $display . '</a>' . $r['link_after'];
     2370
     2371        return apply_filters( 'bbp_get_reply_approve_link', $retval, $r );
    22772372    }
    22782373
Note: See TracChangeset for help on using the changeset viewer.