Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/14/2015 12:31:42 AM (11 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/core/capabilities.php

    r5770 r5827  
    244244
    245245/**
    246  * Get the $wp_roles global without needing to declare it everywhere
     246 * Get the `$wp_roles` global without needing to declare it everywhere
    247247 *
    248248 * @since bbPress (r4293)
    249249 *
    250  * @global WP_Roles $wp_roles
    251250 * @return WP_Roles
    252251 */
    253252function bbp_get_wp_roles() {
    254     global $wp_roles;
    255 
    256     // Load roles if not set
    257     if ( ! isset( $wp_roles ) ) {
    258         $wp_roles = new WP_Roles();
    259     }
    260 
    261     return $wp_roles;
     253
     254    // Try to get `$wp_roles`
     255    $retval = bbp_get_global_object( 'wp_roles', 'WP_Roles' );
     256
     257    // Set roles if not loaded
     258    if ( is_null( $retval ) ) {
     259        $retval = $GLOBALS['wp_roles'] = new WP_Roles();
     260    }
     261
     262    return $retval;
    262263}
    263264
     
    273274
    274275    // Get WordPress's roles (returns $wp_roles global)
    275     $wp_roles  = bbp_get_wp_roles();
     276    $wp_roles = bbp_get_wp_roles();
    276277
    277278    // Apply the WordPress 'editable_roles' filter to let plugins ride along.
     
    302303
    303304    foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
    304         $wp_roles->roles[$role_id]        = $details;
    305         $wp_roles->role_objects[$role_id] = new WP_Role( $role_id, $details['capabilities'] );
    306         $wp_roles->role_names[$role_id]   = $details['name'];
     305        $wp_roles->roles[ $role_id ]        = $details;
     306        $wp_roles->role_objects[ $role_id ] = new WP_Role( $role_id, $details['capabilities'] );
     307        $wp_roles->role_names[ $role_id ]   = $details['name'];
    307308    }
    308309
     
    316317 *
    317318 * @see _bbp_reinit_dynamic_roles()
    318  *
    319  * @global WPDB $wpdb Used to get the database prefix
    320319 */
    321320function bbp_filter_user_roles_option() {
    322     global $wpdb;
    323 
    324     $role_key = $wpdb->prefix . 'user_roles';
     321    $role_key = bbp_db()->prefix . 'user_roles';
    325322
    326323    add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' );
     
    419416function bbp_get_dynamic_role_name( $role_id = '' ) {
    420417    $roles = bbp_get_dynamic_roles();
    421     $role  = isset( $roles[$role_id] ) ? $roles[$role_id]['name'] : '';
     418    $role  = isset( $roles[ $role_id ] ) ? $roles[ $role_id ]['name'] : '';
    422419
    423420    return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
     
    445442            // If keys match, unset
    446443            if ( $wp_role === $bbp_role ) {
    447                 unset( $all_roles[$wp_role] );
     444                unset( $all_roles[ $wp_role ] );
    448445            }
    449446        }
Note: See TracChangeset for help on using the changeset viewer.