Skip to:
Content

bbPress.org

Changeset 6889


Ignore:
Timestamp:
01/25/2019 10:17:11 PM (3 years ago)
Author:
johnjamesjacoby
Message:

Rewrites: use property_exists() on $wp_rewrite global touches.

This makes sure that bbPress defaults are preferred, and avoids fatal errors if class properties are unset.

Also relocate bbp_use_pretty_urls() to better group it together with other bbp_rewrite() wrappers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/abstraction.php

    r6842 r6889  
    165165    return bbp_get_global_object( 'wp_rewrite', 'WP_Rewrite', (object) array(
    166166        'root'            => '',
    167         'pagination_base' => '',
     167        'pagination_base' => 'page',
    168168    ) );
    169169}
     
    178178function bbp_get_root_url() {
    179179
    180     // Filter & return
    181     return apply_filters( 'bbp_get_root_url', bbp_rewrite()->root );
     180    // Default
     181    $retval  = '';
     182    $rewrite = bbp_rewrite();
     183
     184    // Use $wp_rewrite->root if available
     185    if ( property_exists( $rewrite, 'root' ) ) {
     186        $retval = $rewrite->root;
     187    }
     188
     189    // Filter & return
     190    return apply_filters( 'bbp_get_root_url', $retval );
    182191}
    183192
     
    191200function bbp_get_paged_slug() {
    192201
    193     // Filter & return
    194     return apply_filters( 'bbp_get_paged_slug', bbp_rewrite()->pagination_base );
     202    // Default
     203    $retval  = 'page';
     204    $rewrite = bbp_rewrite();
     205
     206    // Use $wp_rewrite->pagination_base if available
     207    if ( property_exists( $rewrite, 'pagination_base' ) ) {
     208        $retval = $rewrite->pagination_base;
     209    }
     210
     211    // Filter & return
     212    return apply_filters( 'bbp_get_paged_slug', $retval );
     213}
     214
     215/**
     216 * Is the environment using pretty URLs?
     217 *
     218 * @since 2.5.8 bbPress (r5814)
     219 *
     220 * @global object $wp_rewrite The WP_Rewrite object
     221 *
     222 * @return bool
     223 */
     224function bbp_use_pretty_urls() {
     225
     226    // Default
     227    $retval  = false;
     228    $rewrite = bbp_rewrite();
     229
     230    // Use $wp_rewrite->using_permalinks() if available
     231    if ( method_exists( $rewrite, 'using_permalinks' ) ) {
     232        $retval = $rewrite->using_permalinks();
     233    }
     234
     235    // Filter & return
     236    return apply_filters( 'bbp_pretty_urls', $retval );
    195237}
    196238
     
    270312
    271313/**
    272  * Is the environment using pretty URLs?
    273  *
    274  * @since 2.5.8 bbPress (r5814)
    275  *
    276  * @global object $wp_rewrite The WP_Rewrite object
    277  *
    278  * @return bool
    279  */
    280 function bbp_use_pretty_urls() {
    281 
    282     // Default
    283     $retval  = false;
    284     $rewrite = bbp_rewrite();
    285 
    286     // Use $wp_rewrite->using_permalinks() if available
    287     if ( method_exists( $rewrite, 'using_permalinks' ) ) {
    288         $retval = $rewrite->using_permalinks();
    289     }
    290 
    291     // Filter & return
    292     return apply_filters( 'bbp_pretty_urls', $retval );
    293 }
    294 
    295 /**
    296314 * Parse the WordPress core version number
    297315 *
Note: See TracChangeset for help on using the changeset viewer.