Skip to:
Content

bbPress.org

Changeset 5683


Ignore:
Timestamp:
04/15/2015 03:00:15 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Forums: Audit template.php:

  • General code formatting improvements
  • Pass $args into more filters
  • Escape more gettext output
  • Un-nest a few complex-looking lines
File:
1 edited

Legend:

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

    r5676 r5683  
    218218
    219219        // Easy empty checking
    220         if ( !empty( $forum_id ) && is_numeric( $forum_id ) ) {
     220        if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) {
    221221            $bbp_forum_id = $forum_id;
    222222
    223223        // Currently inside a forum loop
    224         } elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
     224        } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
    225225            $bbp_forum_id = $bbp->forum_query->post->ID;
    226226
    227227        // Currently inside a search loop
    228         } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
     228        } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
    229229            $bbp_forum_id = $bbp->search_query->post->ID;
    230230
    231231        // Currently viewing a forum
    232         } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && !empty( $bbp->current_forum_id ) ) {
     232        } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) {
    233233            $bbp_forum_id = $bbp->current_forum_id;
    234234
     
    328328
    329329        // Use the redirect address
    330         if ( !empty( $redirect_to ) ) {
     330        if ( ! empty( $redirect_to ) ) {
    331331            $forum_permalink = esc_url_raw( $redirect_to );
    332332
     
    401401            // Set root text to page title
    402402            $page = bbp_get_page_by_path( bbp_get_root_slug() );
    403             if ( !empty( $page ) ) {
     403            if ( ! empty( $page ) ) {
    404404                $title = get_the_title( $page->ID );
    405405
     
    532532        if ( empty( $last_active ) ) {
    533533            $reply_id = bbp_get_forum_last_reply_id( $forum_id );
    534             if ( !empty( $reply_id ) ) {
     534            if ( ! empty( $reply_id ) ) {
    535535                $last_active = get_post_field( 'post_date', $reply_id );
    536536            } else {
    537537                $topic_id = bbp_get_forum_last_topic_id( $forum_id );
    538                 if ( !empty( $topic_id ) ) {
     538                if ( ! empty( $topic_id ) ) {
    539539                    $last_active = bbp_get_topic_last_active_time( $topic_id );
    540540                }
     
    542542        }
    543543
    544         $active_time = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
     544        $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
    545545
    546546        return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
     
    607607        $time_since = bbp_get_forum_last_active_time( $forum_id );
    608608
    609         if ( !empty( $time_since ) && !empty( $link_url ) ) {
     609        if ( ! empty( $time_since ) && ! empty( $link_url ) ) {
    610610            $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
    611611        } else {
     
    662662    $forum     = bbp_get_forum( $forum_id );
    663663
    664     if ( !empty( $forum ) ) {
     664    if ( ! empty( $forum ) ) {
    665665        while ( 0 !== (int) $forum->post_parent ) {
    666666            $ancestors[] = $forum->post_parent;
     
    731731
    732732    // No forum passed
    733     $sub_forums = !empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();
    734 
    735     return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r );
     733    $sub_forums = ! empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();
     734
     735    return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r, $args );
    736736}
    737737
     
    779779    // Loop through forums and create a list
    780780    $sub_forums = bbp_forum_get_subforums( $r['forum_id'] );
    781     if ( !empty( $sub_forums ) ) {
     781    if ( ! empty( $sub_forums ) ) {
    782782
    783783        // Total count (for separator)
     
    793793
    794794            // Show topic count
    795             if ( !empty( $r['show_topic_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
     795            if ( ! empty( $r['show_topic_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
    796796                $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
    797797            }
    798798
    799799            // Show reply count
    800             if ( !empty( $r['show_reply_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
     800            if ( ! empty( $r['show_reply_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
    801801                $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
    802802            }
    803803
    804804            // Counts to show
    805             if ( !empty( $count ) ) {
     805            if ( ! empty( $count ) ) {
    806806                $counts = $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after'];
    807807            }
     
    812812
    813813        // Output the list
    814         echo apply_filters( 'bbp_list_forums', $r['before'] . $output . $r['after'], $r );
     814        echo apply_filters( 'bbp_list_forums', $r['before'] . $output . $r['after'], $r, $args );
    815815    }
    816816}
     
    851851            'before'      => '',
    852852            'after'       => '',
    853             'subscribe'   => __( 'Subscribe',   'bbpress' ),
    854             'unsubscribe' => __( 'Unsubscribe', 'bbpress' )
     853            'subscribe'   => esc_html__( 'Subscribe',   'bbpress' ),
     854            'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' )
    855855        ), 'get_forum_subscribe_link' );
    856856
     
    861861        }
    862862
    863         return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r );
     863        return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r, $args );
    864864    }
    865865
     
    923923        $forum_id = bbp_get_forum_id( $forum_id );
    924924        $topic_id = bbp_get_forum_last_topic_id( $forum_id );
    925         $title    = !empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
     925        $title    = ! empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
    926926
    927927        return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
     
    955955    function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
    956956        $forum_id = bbp_get_forum_id( $forum_id );
    957         return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
     957        $topic_id = bbp_get_forum_last_topic_id( $forum_id );
     958        $link     = bbp_get_topic_permalink( $topic_id );
     959
     960        return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id );
    958961    }
    959962
     
    973976function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
    974977    $forum_id  = bbp_get_forum_id( $forum_id );
    975     $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
    976     return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
     978    $topic_id  = bbp_get_forum_last_topic_id( $forum_id );
     979    $author_id = bbp_get_topic_author_id( $topic_id );
     980
     981    return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id, $topic_id );
    977982}
    978983
     
    10071012        $author_id   = bbp_get_forum_last_topic_author_id( $forum_id );
    10081013        $author_link = bbp_get_user_profile_link( $author_id );
     1014
    10091015        return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
    10101016    }
     
    10691075    function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
    10701076        $forum_id = bbp_get_forum_id( $forum_id );
    1071         return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
     1077        $reply_id = bbp_get_forum_last_reply_id( $forum_id );
     1078        $title    = bbp_get_reply_title( $reply_id );
     1079
     1080        return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id );
    10721081    }
    10731082
     
    10981107    function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
    10991108        $forum_id = bbp_get_forum_id( $forum_id );
    1100         return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
     1109        $reply_id = bbp_get_forum_last_reply_id( $forum_id );
     1110        $link     = bbp_get_reply_permalink( $reply_id );
     1111
     1112        return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id );
    11011113    }
    11021114
     
    11321144        // If forum has replies, get the last reply and use its url
    11331145        $reply_id = bbp_get_forum_last_reply_id( $forum_id );
    1134         if ( !empty( $reply_id ) ) {
     1146        if ( ! empty( $reply_id ) ) {
    11351147            $reply_url = bbp_get_reply_url( $reply_id );
    11361148
     
    11461158
    11471159        // Filter and return
    1148         return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
     1160        return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id );
    11491161    }
    11501162
     
    11771189    function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
    11781190        $forum_id  = bbp_get_forum_id( $forum_id );
    1179         $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
    1180         return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
     1191        $reply_id  = bbp_get_forum_last_reply_id( $forum_id );
     1192        $author_id = bbp_get_reply_author_id( $reply_id );
     1193
     1194        return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id );
    11811195    }
    11821196
     
    12121226        $author_id   = bbp_get_forum_last_reply_author_id( $forum_id );
    12131227        $author_link = bbp_get_user_profile_link( $author_id );
    1214         return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
     1228
     1229        return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id );
    12151230    }
    12161231
     
    12651280
    12661281        // This forum has hidden topics
    1267         if ( !empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) {
     1282        if ( ! empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) {
    12681283
    12691284            // Extra text
     
    14901505        $forum_id = bbp_get_forum_id( $forum_id );
    14911506        $status   = get_post_meta( $forum_id, '_bbp_status', true );
     1507
    14921508        if ( empty( $status ) ) {
    14931509            $status = 'open';
     
    15151531     * @param int $forum_id Optional. Forum id
    15161532     * @uses bbp_get_forum_id() To get the forum id
    1517      * @uses get_post_visibility() To get the forum's visibility
     1533     * @uses get_post_status() To get the forum's status
    15181534     * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility
    15191535     *                        and forum id
     
    15211537     */
    15221538    function bbp_get_forum_visibility( $forum_id = 0 ) {
    1523         $forum_id = bbp_get_forum_id( $forum_id );
    1524 
    1525         return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id );
     1539        $forum_id   = bbp_get_forum_id( $forum_id );
     1540        $visibility = get_post_status( $forum_id );
     1541
     1542        return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id );
    15261543    }
    15271544
     
    15491566        $forum_id = bbp_get_forum_id( $forum_id );
    15501567        $retval   = get_post_meta( $forum_id, '_bbp_forum_type', true );
     1568
    15511569        if ( empty( $retval ) ) {
    15521570            $retval = 'forum';
     
    15681586    $forum_id = bbp_get_forum_id( $forum_id );
    15691587    $type     = bbp_get_forum_type( $forum_id );
    1570     $retval   = ( !empty( $type ) && 'category' === $type );
     1588    $retval   = ( ! empty( $type ) && 'category' === $type );
    15711589
    15721590    return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
     
    15851603 */
    15861604function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
    1587     return !bbp_is_forum_closed( $forum_id, $check_ancestors );
     1605    return ! bbp_is_forum_closed( $forum_id, $check_ancestors );
    15881606}
    15891607
     
    17791797
    17801798    // Quickly compare visibility of first forum ID
    1781     if ( $status_name === $visibility ){
     1799    if ( $status_name === $visibility ) {
    17821800        $retval = true;
    17831801        $count++;
     
    17881806
    17891807        // Adjust the ancestor check based on the count
    1790         switch( $operator ) {
     1808        switch ( $operator ) {
    17911809
    17921810            // Adjust the ancestor check based on the count
     
    18281846    return (bool) apply_filters( 'bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
    18291847}
     1848
     1849/**
     1850 * Output the author ID of the forum
     1851 *
     1852 * @since bbPress (r3675)
     1853 *
     1854 * @param int $forum_id Optional. Forum id
     1855 * @uses bbp_get_forum_author_id() To get the forum author id
     1856 */
     1857function bbp_forum_author_id( $forum_id = 0 ) {
     1858    echo bbp_get_forum_author_id( $forum_id );
     1859}
     1860    /**
     1861     * Return the author ID of the forum
     1862     *
     1863     * @since bbPress (r3675)
     1864     *
     1865     * @param int $forum_id Optional. Forum id
     1866     * @uses bbp_get_forum_id() To get the forum id
     1867     * @uses get_post_field() To get the forum author id
     1868     * @uses apply_filters() Calls 'bbp_get_forum_author_id' with the author
     1869     *                        id and forum id
     1870     * @return string Author of forum
     1871     */
     1872    function bbp_get_forum_author_id( $forum_id = 0 ) {
     1873        $forum_id  = bbp_get_forum_id( $forum_id );
     1874        $author_id = get_post_field( 'post_author', $forum_id );
     1875
     1876        return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
     1877    }
    18301878
    18311879/**
     
    18541902     */
    18551903    function bbp_get_forum_author_display_name( $forum_id = 0 ) {
    1856         $forum_id = bbp_get_forum_id( $forum_id );
    1857         $author   = get_the_author_meta( 'display_name', bbp_get_forum_author_id( $forum_id ) );
    1858 
    1859         return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id );
    1860     }
    1861 
    1862 /**
    1863  * Output the author ID of the forum
    1864  *
    1865  * @since bbPress (r3675)
    1866  *
    1867  * @param int $forum_id Optional. Forum id
    1868  * @uses bbp_get_forum_author_id() To get the forum author id
    1869  */
    1870 function bbp_forum_author_id( $forum_id = 0 ) {
    1871     echo bbp_get_forum_author_id( $forum_id );
    1872 }
    1873     /**
    1874      * Return the author ID of the forum
    1875      *
    1876      * @since bbPress (r3675)
    1877      *
    1878      * @param int $forum_id Optional. Forum id
    1879      * @uses bbp_get_forum_id() To get the forum id
    1880      * @uses get_post_field() To get the forum author id
    1881      * @uses apply_filters() Calls 'bbp_get_forum_author_id' with the author
    1882      *                        id and forum id
    1883      * @return string Author of forum
    1884      */
    1885     function bbp_get_forum_author_id( $forum_id = 0 ) {
    18861904        $forum_id  = bbp_get_forum_id( $forum_id );
    1887         $author_id = get_post_field( 'post_author', $forum_id );
    1888 
    1889         return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
     1905        $author_id = bbp_get_forum_author_id( $forum_id );
     1906        $author    = get_the_author_meta( 'display_name', $author_id );
     1907
     1908        return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id );
    18901909    }
    18911910
     
    19041923 */
    19051924function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
    1906     if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) ) {
     1925    if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_private_forums' ) ) {
    19071926        $retval = '-';
    19081927    }
     
    19351954
    19361955    // Show the normal author link
    1937     if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) {
     1956    if ( ! empty( $args['post_id'] ) && ! current_user_can( 'read_private_forums' ) ) {
    19381957
    19391958        // What post type are we looking at?
     
    20862105
    20872106        // Has replies
    2088         if ( !empty( $reply_count ) ) {
     2107        if ( ! empty( $reply_count ) ) {
    20892108            $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
    20902109        }
    20912110
    20922111        // Forum has active data
    2093         if ( !empty( $last_active ) ) {
     2112        if ( ! empty( $last_active ) ) {
    20942113            $topic_text      = bbp_get_forum_topics_link( $forum_id );
    20952114            $time_since      = bbp_get_forum_freshness_link( $forum_id );
     
    21022121
    21032122        // Forum has active data
    2104         if ( !empty( $last_active ) ) {
    2105 
    2106             if ( !empty( $reply_count ) ) {
     2123        if ( ! empty( $last_active ) ) {
     2124
     2125            if ( ! empty( $reply_count ) ) {
    21072126
    21082127                if ( bbp_is_forum_category( $forum_id ) ) {
     
    21242143        } else {
    21252144
    2126             if ( !empty( $reply_count ) ) {
     2145            if ( ! empty( $reply_count ) ) {
    21272146
    21282147                if ( bbp_is_forum_category( $forum_id ) ) {
     
    21342153            } else {
    21352154
    2136                 if ( !empty( $topic_count ) ) {
     2155                if ( ! empty( $topic_count ) ) {
    21372156
    21382157                    if ( bbp_is_forum_category( $forum_id ) ) {
     
    21492168
    21502169        // Add feeds
    2151         //$feed_links = ( !empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
     2170        //$feed_links = ( ! empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
    21522171
    21532172        // Add the 'view all' filter back
     
    21582177
    21592178        // Return filtered result
    2160         return apply_filters( 'bbp_get_single_forum_description', $retstr, $r );
     2179        return apply_filters( 'bbp_get_single_forum_description', $retstr, $r, $args );
    21612180    }
    21622181
     
    21862205        // Get _POST data
    21872206        if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
    2188             $forum_title = $_POST['bbp_forum_title'];
     2207            $forum_title = wp_unslash( $_POST['bbp_forum_title'] );
    21892208
    21902209        // Get edit data
     
    21972216        }
    21982217
    2199         return apply_filters( 'bbp_get_form_forum_title', esc_attr( $forum_title ) );
     2218        return apply_filters( 'bbp_get_form_forum_title', $forum_title );
    22002219    }
    22012220
     
    23102329        }
    23112330
    2312         return apply_filters( 'bbp_get_form_forum_type', esc_attr( $forum_type ) );
     2331        return apply_filters( 'bbp_get_form_forum_type', $forum_type );
    23132332    }
    23142333
     
    23482367        }
    23492368
    2350         return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) );
     2369        return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility );
    23512370    }
    23522371
     
    25022521
    25032522        // Return the results
    2504         return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
     2523        return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
    25052524    }
    25062525
     
    25942613
    25952614        // Return the results
    2596         return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r );
     2615        return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args );
    25972616    }
    25982617
     
    26862705
    26872706        // Return the results
    2688         return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
     2707        return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
    26892708    }
    26902709
     
    27582777
    27592778        // Forum is valid
    2760         if ( !empty( $forum_id ) ) {
     2779        if ( ! empty( $forum_id ) ) {
    27612780
    27622781            // Define local variable(s)
     
    28202839
    28212840        // Forum is valid
    2822         if ( !empty( $forum_id ) ) {
     2841        if ( ! empty( $forum_id ) ) {
    28232842
    28242843            // Define local variable(s)
Note: See TracChangeset for help on using the changeset viewer.