Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/14/2015 12:31:42 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Abstraction: Use bbp_db(), bbp_rewrite() & friends, introduced in r5823 & r5826.

This commit improves the stability of bbPress in the WordPress environment by reducing global variable exposure. It also comes with minimal opcode improvements in some circumstances where $GLOBALS is preferred over defining via global statements.

Some additional surrounding cleanup directly related to functions & methods being altered is also being performed here.

Fixes #2786.

File:
1 edited

Legend:

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

    r5811 r5827  
    128128 * @uses bbp_get_super_stickies() To get the super stickies
    129129 * @uses bbp_get_stickies() To get the forum stickies
    130  * @uses wpdb::get_results() To execute our query and get the results
    131  * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
     130 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs
    132131 * @uses get_permalink() To get the permalink
    133132 * @uses add_query_arg() To add custom args to the url
     
    140139 */
    141140function bbp_has_topics( $args = array() ) {
    142     global $wp_rewrite;
    143141
    144142    /** Defaults **************************************************************/
     
    354352
    355353        // If pretty permalinks are enabled, make our pagination pretty
    356         if ( $wp_rewrite->using_permalinks() ) {
     354        if ( bbp_use_pretty_urls() ) {
    357355
    358356            // User's topics
     
    398396
    399397            // Use pagination base
    400             $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
     398            $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' );
    401399
    402400        // Unpretty pagination
     
    420418
    421419        // Remove first page from pagination
    422         $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links );
     420        $bbp->topic_query->pagination_links = str_replace( bbp_get_paged_slug() . "/1/'", "'", $bbp->topic_query->pagination_links );
    423421    }
    424422
     
    851849     *  - after: After the links
    852850     * @uses bbp_get_topic_id() To get the topic id
    853      * @uses WP_Rewrite::using_permalinks() To check if the blog is using
    854      *                                       permalinks
     851     * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs
    855852     * @uses user_trailingslashit() To add a trailing slash
    856853     * @uses trailingslashit() To add a trailing slash
     
    866863     */
    867864    function bbp_get_topic_pagination( $args = array() ) {
    868         global $wp_rewrite;
    869865
    870866        // Bail if threading replies
     
    881877
    882878        // If pretty permalinks are enabled, make our pagination pretty
    883         if ( $wp_rewrite->using_permalinks() ) {
    884             $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
     879        if ( bbp_use_pretty_urls() ) {
     880            $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' );
    885881        } else {
    886882            $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
     
    910906
    911907            // Remove first page from pagination
    912             if ( $wp_rewrite->using_permalinks() ) {
    913                 $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links );
     908            if ( bbp_use_pretty_urls() ) {
     909                $pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links );
    914910            } else {
    915911                $pagination_links = str_replace( '&paged=1', '', $pagination_links );
     
    26402636     */
    26412637    function bbp_get_topic_edit_url( $topic_id = 0 ) {
    2642         global $wp_rewrite;
    26432638
    26442639        $topic = bbp_get_topic( $topic_id );
     
    26512646
    26522647        // Pretty permalinks
    2653         if ( $wp_rewrite->using_permalinks() ) {
     2648        if ( bbp_use_pretty_urls() ) {
    26542649            $url = trailingslashit( $topic_link ) . bbp_get_edit_rewrite_id();
    2655             $url = trailingslashit( $url );
     2650            $url = user_trailingslashit( $url );
    26562651
    26572652        // Unpretty permalinks
    26582653        } else {
    2659             $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, bbp_get_edit_rewrite_id() => '1' ), $topic_link );
     2654            $url = add_query_arg( array(
     2655                bbp_get_topic_post_type() => $topic->post_name,
     2656                bbp_get_edit_rewrite_id() => '1'
     2657            ), $topic_link );
    26602658        }
    26612659
     
    37673765     */
    37683766    function bbp_get_topic_tag_edit_link( $tag = '' ) {
    3769         global $wp_rewrite;
    37703767
    37713768        // Get the term
     
    37813778
    37823779            // Pretty
    3783             if ( $wp_rewrite->using_permalinks() ) {
     3780            if ( bbp_use_pretty_urls() ) {
    37843781                $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_rewrite_id() );
    37853782
Note: See TracChangeset for help on using the changeset viewer.