Skip to:
Content

bbPress.org

Changeset 4985


Ignore:
Timestamp:
06/11/2013 04:42:26 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Remove capability pre-check from admin links functions. Remove duplicate trash-removal logic that's done inside the respective trash-link generating functions. Fixes inconsistent nested capability checks within admin link functions. See #2348.

Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/replies/template-tags.php

    r4973 r4985  
    16851685 * @since bbPress (r2667)
    16861686 *
    1687  * @param mixed $args See {@link bbp_get_reply_admin_links()}
     1687 * @param array $args See {@link bbp_get_reply_admin_links()}
    16881688 * @uses bbp_get_reply_admin_links() To get the reply admin links
    16891689 */
    1690 function bbp_reply_admin_links( $args = '' ) {
     1690function bbp_reply_admin_links( $args = array() ) {
    16911691    echo bbp_get_reply_admin_links( $args );
    16921692}
     
    16961696     * @since bbPress (r2667)
    16971697     *
    1698      * @param mixed $args This function supports these arguments:
     1698     * @param array $args This function supports these arguments:
    16991699     *  - id: Optional. Reply id
    17001700     *  - before: HTML before the links. Defaults to
     
    17181718     * @return string Reply admin links
    17191719     */
    1720     function bbp_get_reply_admin_links( $args = '' ) {
     1720    function bbp_get_reply_admin_links( $args = array() ) {
    17211721
    17221722        // Parse arguments against default values
     
    17321732
    17331733        // If post is a topic, return the topic admin links instead
    1734         if ( bbp_is_topic( $r['id'] ) )
     1734        if ( bbp_is_topic( $r['id'] ) ) {
    17351735            return bbp_get_topic_admin_links( $args );
     1736        }
    17361737
    17371738        // If post is not a reply, return
    1738         if ( !bbp_is_reply( $r['id'] ) )
     1739        if ( !bbp_is_reply( $r['id'] ) ) {
    17391740            return;
    1740 
    1741         // Make sure user can edit this reply
    1742         if ( !current_user_can( 'edit_reply', $r['id'] ) )
     1741        }
     1742
     1743        // If topic is trashed, do not show admin links
     1744        if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) {
    17431745            return;
    1744 
    1745         // If topic is trashed, do not show admin links
    1746         if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) )
    1747             return;
     1746        }
    17481747
    17491748        // If no links were passed, default to the standard
     
    17591758        }
    17601759
    1761         // Check caps for trashing the topic
    1762         if ( !current_user_can( 'delete_reply', $r['id'] ) && !empty( $r['links']['trash'] ) )
    1763             unset( $r['links']['trash'] );
    1764 
    17651760        // See if links need to be unset
    17661761        $reply_status = bbp_get_reply_status( $r['id'] );
     
    17681763
    17691764            // Spam link shouldn't be visible on trashed topics
    1770             if ( bbp_get_trash_status_id() == $reply_status ) {
     1765            if ( bbp_get_trash_status_id() === $reply_status ) {
    17711766                unset( $r['links']['spam'] );
    17721767
    17731768            // Trash link shouldn't be visible on spam topics
    1774             } elseif ( isset( $r['links']['trash'] ) && ( bbp_get_spam_status_id() == $reply_status ) ) {
     1769            } elseif ( bbp_get_spam_status_id() === $reply_status ) {
    17751770                unset( $r['links']['trash'] );
    17761771            }
     
    17811776        $retval = $r['before'] . $links . $r['after'];
    17821777
    1783         return apply_filters( 'bbp_get_reply_admin_links', $retval, $r );
     1778        return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args );
    17841779    }
    17851780
  • trunk/includes/topics/template-tags.php

    r4970 r4985  
    22172217 * Output admin links for topic
    22182218 *
    2219  * @param mixed $args See {@link bbp_get_topic_admin_links()}
     2219 * @param array $args See {@link bbp_get_topic_admin_links()}
    22202220 * @uses bbp_get_topic_admin_links() To get the topic admin links
    22212221 */
    2222 function bbp_topic_admin_links( $args = '' ) {
     2222function bbp_topic_admin_links( $args = array() ) {
    22232223    echo bbp_get_topic_admin_links( $args );
    22242224}
     
    22282228     * Move topic functionality is handled by the edit topic page.
    22292229     *
    2230      * @param mixed $args This function supports these arguments:
     2230     * @param array $args This function supports these arguments:
    22312231     *  - id: Optional. Topic id
    22322232     *  - before: Before the links
     
    22472247     * @return string Topic admin links
    22482248     */
    2249     function bbp_get_topic_admin_links( $args = '' ) {
     2249    function bbp_get_topic_admin_links( $args = array() ) {
    22502250
    22512251        // Parse arguments against default values
     
    22572257            'links'  => array()
    22582258        ), 'get_topic_admin_links' );
    2259 
    2260         if ( !current_user_can( 'edit_topic', $r['id'] ) )
    2261             return;
    22622259
    22632260        if ( empty( $r['links'] ) ) {
     
    22732270        }
    22742271
    2275         // Check caps for trashing the topic
    2276         if ( !current_user_can( 'delete_topic', $r['id'] ) && !empty( $r['links']['trash'] ) )
    2277             unset( $r['links']['trash'] );
    2278 
    22792272        // See if links need to be unset
    22802273        $topic_status = bbp_get_topic_status( $r['id'] );
     
    22852278
    22862279            // Spam link shouldn't be visible on trashed topics
    2287             if ( $topic_status == bbp_get_trash_status_id() )
     2280            if ( bbp_get_trash_status_id() === $topic_status ) {
    22882281                unset( $r['links']['spam'] );
    22892282
    22902283            // Trash link shouldn't be visible on spam topics
    2291             elseif ( $topic_status == bbp_get_spam_status_id() )
     2284            } elseif ( bbp_get_spam_status_id() === $topic_status ) {
    22922285                unset( $r['links']['trash'] );
     2286            }
    22932287        }
    22942288
    22952289        // Process the admin links
    2296         $links = implode( $r['sep'], array_filter( $r['links'] ) );
    2297 
    2298         return apply_filters( 'bbp_get_topic_admin_links', $r['before'] . $links . $r['after'], $r );
     2290        $links  = implode( $r['sep'], array_filter( $r['links'] ) );
     2291        $retval = $r['before'] . $links . $r['after'];
     2292
     2293        return apply_filters( 'bbp_get_topic_admin_links', $retval, $r, $args );
    22992294    }
    23002295
Note: See TracChangeset for help on using the changeset viewer.