Skip to:
Content

BuddyPress.org

Changeset 5683


Ignore:
Timestamp:
02/09/2012 09:38:45 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Remove a bunch of unneeded globals and clean up some code in Core component. See #3989.

Location:
trunk/bp-core
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-components.php

    r5524 r5683  
    211211 * @since BuddyPress (1.6)
    212212 * @todo Use settings API
    213  * @global WPDB $wpdb
    214213 * @global BuddyPress $bp
    215214 * @return false On failure
    216215 */
    217216function bp_core_admin_components_settings_handler() {
    218     global $wpdb, $bp;
     217    global $bp;
    219218
    220219    if ( isset( $_POST['bp-admin-component-submit'] ) ) {
  • trunk/bp-core/admin/bp-core-schema.php

    r5259 r5683  
    1616
    1717function bp_core_install_notifications() {
    18     global $wpdb;
    19 
    20     $charset_collate = bp_core_set_charset();
    21     $bp_prefix = bp_core_get_table_prefix();
     18
     19    $sql             = array();
     20    $charset_collate = bp_core_set_charset();
     21    $bp_prefix       = bp_core_get_table_prefix();
    2222
    2323    $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
     
    3939               ) {$charset_collate};";
    4040
    41     dbDelta($sql);
     41    dbDelta( $sql );
    4242}
    4343
    4444function bp_core_install_activity_streams() {
    45     global $wpdb;
    46 
    47     $charset_collate = bp_core_set_charset();
    48     $bp_prefix = bp_core_get_table_prefix();
     45
     46    $sql             = array();
     47    $charset_collate = bp_core_set_charset();
     48    $bp_prefix       = bp_core_get_table_prefix();
    4949
    5050    $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
     
    8484               ) {$charset_collate};";
    8585
    86     dbDelta($sql);
     86    dbDelta( $sql );
    8787}
    8888
    8989function bp_core_install_friends() {
    90     global $wpdb;
    91 
    92     $charset_collate = bp_core_set_charset();
    93     $bp_prefix = bp_core_get_table_prefix();
     90
     91    $sql             = array();
     92    $charset_collate = bp_core_set_charset();
     93    $bp_prefix       = bp_core_get_table_prefix();
    9494
    9595    $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
     
    104104               ) {$charset_collate};";
    105105
    106     dbDelta($sql);
     106    dbDelta( $sql );
    107107}
    108108
    109109function bp_core_install_groups() {
    110     global $wpdb;
    111 
    112     $charset_collate = bp_core_set_charset();
    113     $bp_prefix = bp_core_get_table_prefix();
     110
     111    $sql             = array();
     112    $charset_collate = bp_core_set_charset();
     113    $bp_prefix       = bp_core_get_table_prefix();
    114114
    115115    $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
     
    156156               ) {$charset_collate};";
    157157
    158     dbDelta($sql);
     158    dbDelta( $sql );
    159159}
    160160
    161161function bp_core_install_private_messaging() {
    162     global $wpdb;
    163 
    164     $charset_collate = bp_core_set_charset();
    165     $bp_prefix = bp_core_get_table_prefix();
     162
     163    $sql             = array();
     164    $charset_collate = bp_core_set_charset();
     165    $bp_prefix       = bp_core_get_table_prefix();
    166166
    167167    $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
     
    199199               ) {$charset_collate};";
    200200
    201     dbDelta($sql);
     201    dbDelta( $sql );
    202202}
    203203
     
    205205    global $wpdb;
    206206
    207     $charset_collate = bp_core_set_charset();
    208     $bp_prefix = bp_core_get_table_prefix();
     207    $sql             = array();
     208    $charset_collate = bp_core_set_charset();
     209    $bp_prefix       = bp_core_get_table_prefix();
    209210
    210211    bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
     
    275276
    276277function bp_core_install_blog_tracking() {
    277     global $wpdb;
    278 
    279     $charset_collate = bp_core_set_charset();
    280     $bp_prefix = bp_core_get_table_prefix();
     278
     279    $sql             = array();
     280    $charset_collate = bp_core_set_charset();
     281    $bp_prefix       = bp_core_get_table_prefix();
    281282
    282283    $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
     
    297298               ) {$charset_collate};";
    298299
    299     dbDelta($sql);
     300    dbDelta( $sql );
    300301}
    301302
  • trunk/bp-core/admin/bp-core-slugs.php

    r5575 r5683  
    183183 * @since BuddyPress (1.6)
    184184 * @todo Use settings API
    185  * @global WPDB $wpdb
    186  * @global BuddyPress $bp
    187  * @return type
     185 * @return False if referer does not check out
    188186 */
    189187function bp_core_admin_slugs_setup_handler() {
    190     global $wpdb, $bp;
    191188
    192189    if ( isset( $_POST['bp-admin-pages-submit'] ) || isset( $_POST['bp-admin-pages-single'] ) ) {
  • trunk/bp-core/admin/bp-core-update.php

    r5659 r5683  
    8989
    9090    function add_steps() {
    91         global $wp_rewrite;
    9291
    9392        // Setup wizard steps
     
    11711170
    11721171    function setup_pages( $pages ) {
     1172
     1173        $bp_pages = array();
     1174
    11731175        foreach ( $pages as $key => $value ) {
    11741176            if ( 'page' == $value ) {
     
    12141216
    12151217function bp_core_install( $active_components = false ) {
    1216     global $wpdb;
    12171218
    12181219    if ( empty( $active_components ) )
     
    12501251
    12511252function bp_core_update( $disabled ) {
    1252     global $wpdb;
    1253 
    12541253    require( dirname( __FILE__ ) . '/bp-core-schema.php' );
    12551254}
  • trunk/bp-core/bp-core-avatars.php

    r5666 r5683  
    390390    extract( $args, EXTR_SKIP );
    391391
    392     if ( !$item_id ) {
     392    if ( empty( $item_id ) ) {
    393393        if ( 'user' == $object )
    394394            $item_id = bp_displayed_user_id();
     
    403403    }
    404404
    405     if ( !$avatar_dir ) {
     405    if ( empty( $avatar_dir ) ) {
    406406        if ( 'user' == $object )
    407407            $avatar_dir = 'avatars';
     
    548548 *  crop_y - The vertical starting point of the crop
    549549 *
    550  * @global object $bp BuddyPress global settings
    551550 * @param mixed $args
    552551 * @return bool Success/failure
    553552 */
    554553function bp_core_avatar_handle_crop( $args = '' ) {
    555     global $bp;
    556554
    557555    $defaults = array(
  • trunk/bp-core/bp-core-buddybar.php

    r5672 r5683  
    429429// **** Default BuddyPress admin bar logo ********
    430430function bp_adminbar_logo() {
    431     global $bp;
    432 
    433431    echo '<a href="' . bp_get_root_domain() . '" id="admin-bar-logo">' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . '</a>';
    434432}
     
    436434// **** "Log In" and "Sign Up" links (Visible when not logged in) ********
    437435function bp_adminbar_login_menu() {
    438     global $bp;
    439436
    440437    if ( is_user_logged_in() )
     
    525522// **** "Random" Menu (visible when not logged in) ********
    526523function bp_adminbar_random_menu() {
    527     global $bp; ?>
     524?>
    528525
    529526    <li class="align-right" id="bp-adminbar-visitrandom-menu">
     
    653650}
    654651add_action( 'bp_init', 'bp_core_load_buddybar_css' );
     652
    655653?>
  • trunk/bp-core/bp-core-cache.php

    r5663 r5683  
    4949 *
    5050 * @since 1.6
    51  * @uses $wpdb WordPress database object for queries.
    52  * @uses $bp BuddyPress global object.
    53  *
     51 * @global $wpdb WordPress database object for queries.
    5452 * @param array $args See $defaults definition for more details
    5553 * @return mixed Metadata cache for the specified objects, or false on failure.
    5654 */
    5755function bp_update_meta_cache( $args = array() ) {
    58     global $bp, $wpdb;
     56    global $wpdb;
    5957   
    6058    $defaults = array(
  • trunk/bp-core/bp-core-catchuri.php

    r5636 r5683  
    3838 */
    3939function bp_core_set_uri_globals() {
    40     global $bp, $current_blog, $wpdb;
     40    global $bp, $current_blog;
    4141
    4242    // Don't catch URIs on non-root blogs unless multiblog mode is on
  • trunk/bp-core/bp-core-classes.php

    r5595 r5683  
    137137     * Populate the instantiated class with data based on the User ID provided.
    138138     *
    139      * @global object $bp Global BuddyPress settings object
    140139     * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
    141140     * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
     
    146145     */
    147146    function populate() {
    148         global $bp;
    149147
    150148        if ( bp_is_active( 'xprofile' ) )
     
    178176    /**
    179177     * Populates extra fields such as group and friendship counts.
    180      *
    181      * @global object $bp Global BuddyPress settings object
    182178     */
    183179    function populate_extras() {
    184         global $bp;
    185 
    186         if ( bp_is_active( 'friends' ) )
     180
     181        if ( bp_is_active( 'friends' ) ) {
    187182            $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
     183        }
    188184
    189185        if ( bp_is_active( 'groups' ) ) {
     
    206202        $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
    207203
    208         if ( 'active' == $type || 'online' == $type || 'newest' == $type  )
     204        if ( 'active' == $type || 'online' == $type || 'newest' == $type  ) {
    209205            $sql['select_active'] = ", um.meta_value as last_activity";
    210 
    211         if ( 'popular' == $type )
     206        }
     207
     208        if ( 'popular' == $type ) {
    212209            $sql['select_popular'] = ", um.meta_value as total_friend_count";
    213 
    214         if ( 'alphabetical' == $type )
     210        }
     211
     212        if ( 'alphabetical' == $type ) {
    215213            $sql['select_alpha'] = ", pd.value as fullname";
     214        }
    216215
    217216        if ( $meta_key ) {
    218217            $sql['select_meta'] = ", umm.meta_key";
    219218
    220             if ( $meta_value )
     219            if ( $meta_value ) {
    221220                $sql['select_meta'] .= ", umm.meta_value";
     221            }
    222222        }
    223223
     
    225225
    226226        // We search against xprofile fields, so we must join the table
    227         if ( $search_terms && bp_is_active( 'xprofile' ) )
     227        if ( $search_terms && bp_is_active( 'xprofile' ) ) {
    228228            $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id";
     229        }
    229230
    230231        // Alphabetical sorting is done by the xprofile Full Name field
    231         if ( 'alphabetical' == $type )
     232        if ( 'alphabetical' == $type ) {
    232233            $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
    233 
    234         if ( $meta_key )
     234        }
     235
     236        if ( $meta_key ) {
    235237            $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
     238        }
    236239
    237240        $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
    238241
    239         if ( 'active' == $type || 'online' == $type || 'newest' == $type )
     242        if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
    240243            $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
    241 
    242         if ( 'popular' == $type )
     244        }
     245
     246        if ( 'popular' == $type ) {
    243247            $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
    244 
    245         if ( 'online' == $type )
     248        }
     249
     250        if ( 'online' == $type ) {
    246251            $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
    247 
    248         if ( 'alphabetical' == $type )
     252        }
     253
     254        if ( 'alphabetical' == $type ) {
    249255            $sql['where_alpha'] = "AND pd.field_id = 1";
    250 
    251         if ( !empty( $exclude ) )
     256        }
     257
     258        if ( !empty( $exclude ) ) {
    252259            $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})";
     260        }
    253261
    254262        if ( $include ) {
    255             if ( is_array( $include ) )
     263            if ( is_array( $include ) ) {
    256264                $uids = $wpdb->escape( implode( ',', (array)$include ) );
    257             else
     265            } else {
    258266                $uids = $wpdb->escape( $include );
    259 
    260             if ( !empty( $uids ) )
     267            }
     268
     269            if ( !empty( $uids ) ) {
    261270                $sql['where_users'] = "AND u.ID IN ({$uids})";
    262         }
    263 
    264         else if ( $user_id && bp_is_active( 'friends' ) ) {
     271            }
     272        } elseif ( $user_id && bp_is_active( 'friends' ) ) {
    265273            $friend_ids = friends_get_friend_user_ids( $user_id );
    266274            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
    267275
    268             if ( !empty( $friend_ids ) )
     276            if ( !empty( $friend_ids ) ) {
    269277                $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
    270278
    271279            // User has no friends, return false since there will be no users to fetch.
    272             else
     280            } else {
    273281                return false;
    274 
     282            }
    275283        }
    276284
     
    307315        }
    308316
    309         if ( $limit && $page )
     317        if ( $limit && $page ) {
    310318            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     319        }
    311320
    312321        // Get paginated results
     
    317326        unset( $sql['select_main'] );
    318327
    319         if ( !empty( $sql['select_active'] ) )
     328        if ( !empty( $sql['select_active'] ) ) {
    320329            unset( $sql['select_active'] );
    321 
    322         if ( !empty( $sql['select_popular'] ) )
     330        }
     331
     332        if ( !empty( $sql['select_popular'] ) ) {
    323333            unset( $sql['select_popular'] );
    324 
    325         if ( !empty( $sql['select_alpha'] ) )
     334        }
     335
     336        if ( !empty( $sql['select_alpha'] ) ) {
    326337            unset( $sql['select_alpha'] );
    327 
    328         if ( !empty( $sql['pagination'] ) )
     338        }
     339
     340        if ( !empty( $sql['pagination'] ) ) {
    329341            unset( $sql['pagination'] );
     342        }
    330343
    331344        array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
     
    342355            $user_ids = array();
    343356
    344             foreach ( (array)$paged_users as $user )
     357            foreach ( (array)$paged_users as $user ) {
    345358                $user_ids[] = $user->id;
     359            }
    346360
    347361            $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     
    372386
    373387        $pag_sql = '';
    374         if ( $limit && $page )
     388        if ( $limit && $page ) {
    375389            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     390        }
    376391
    377392        // Multibyte compliance
     
    398413
    399414        /***
    400          * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
    401          * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     415         * Lets fetch some other useful data in a separate queries, this will be
     416         * faster than querying the data for every user in a list. We can't add
     417         * these to the main query above since only users who have this
     418         * information will be returned (since the much of the data is in
     419         * usermeta and won't support any type of directional join)
    402420         */
    403421        $user_ids = array();
     
    407425        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    408426
    409         /* Add additional data to the returned results */
    410         if ( $populate_extras )
     427        // Add additional data to the returned results
     428        if ( $populate_extras ) {
    411429            $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
     430        }
    412431
    413432        return array( 'users' => $paged_users, 'total' => $total_users );
     
    417436     * Get details of specific users from the database
    418437     *
    419      * @global object $bp Global BuddyPress settings object
    420438     * @global wpdb $wpdb WordPress database object
    421439     * @param array $user_ids The user IDs of the users who we wish to fetch information on.
     
    427445     */
    428446    function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
    429         global $bp, $wpdb;
     447        global $wpdb;
    430448
    431449        $pag_sql = '';
     
    433451            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    434452
     453        // @todo remove? $user_sql is not used here
    435454        $user_sql   = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
    436455        $status_sql = bp_core_get_status_sql();
     
    443462
    444463        /***
    445          * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
    446          * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     464         * Lets fetch some other useful data in a separate queries, this will be
     465         * faster than querying the data for every user in a list. We can't add
     466         * these to the main query above since only users who have this
     467         * information will be returned (since the much of the data is in
     468         * usermeta and won't support any type of directional join)
    447469         */
    448470
    449         /* Add additional data to the returned results */
    450         if ( $populate_extras )
     471        // Add additional data to the returned results
     472        if ( !empty( $populate_extras ) ) {
    451473            $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
     474        }
    452475
    453476        return array( 'users' => $paged_users, 'total' => $total_users );
     
    10281051
    10291052            // Wrapper ID
    1030             if ( !empty( $wrapper_id ) )
     1053            if ( !empty( $wrapper_id ) ) {
    10311054                $this->wrapper_id    = ' id="' . $wrapper_id . '"';
     1055            }
    10321056
    10331057            // Wrapper class
    1034             if ( !empty( $wrapper_class ) )
     1058            if ( !empty( $wrapper_class ) ) {
    10351059                $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
    1036             else
     1060            } else {
    10371061                $this->wrapper_class = ' class="generic-button"';
     1062            }
    10381063
    10391064            // Set before and after
     
    11741199            foreach ( $handlers as $hid => $handler ) {
    11751200                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
    1176                     if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     1201                    if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) {
    11771202                        return apply_filters( 'embed_handler_html', $return, $url, $attr );
     1203                    }
    11781204                }
    11791205            }
  • trunk/bp-core/bp-core-cssjs.php

    r5524 r5683  
    133133 */
    134134function bp_core_add_ajax_url_js() {
    135     global $bp;
    136135?>
    137136
  • trunk/bp-core/bp-core-filters.php

    r5670 r5683  
    113113 */
    114114function bp_core_login_redirect( $redirect_to ) {
    115     global $bp, $wpdb;
     115    global $wpdb;
    116116
    117117    // Don't mess with the redirect if this is not the root blog
  • trunk/bp-core/bp-core-functions.php

    r5659 r5683  
    183183 */
    184184function bp_core_get_directory_pages() {
    185     global $wpdb, $bp;
     185    global $wpdb;
    186186
    187187    // Set pages as standard class
     
    262262 */
    263263function bp_core_get_root_domain() {
    264     global $wpdb;
    265264
    266265    $domain = get_home_url( bp_get_root_blog_id() );
     
    494493 */
    495494function bp_core_record_activity() {
    496     global $bp;
    497495
    498496    if ( !is_user_logged_in() )
     
    543541 * @package BuddyPress Core
    544542 *
    545  * @global $bp $bp
    546543 * @global object $current_site
    547544 * @return string
    548545 */
    549546function bp_core_get_site_path() {
    550     global $bp, $current_site;
     547    global $current_site;
    551548
    552549    if ( is_multisite() )
     
    624621 *
    625622 * @package BuddyPress Core
    626  * @global object $bp Global BuddyPress settings object
    627623 * @param string $slug The slug to redirect to for searching.
    628624 */
    629625function bp_core_action_search_site( $slug = '' ) {
    630     global $bp;
    631626
    632627    if ( !bp_is_current_component( bp_get_search_slug() ) )
     
    11561151 */
    11571152function bp_do_404( $redirect = 'remove_canonical_direct' ) {
    1158     global $bp, $wp_query;
     1153    global $wp_query;
    11591154
    11601155    do_action( 'bp_do_404', $redirect );
  • trunk/bp-core/bp-core-widgets.php

    r5574 r5683  
    3232
    3333    function widget( $args, $instance ) {
    34         global $bp;
    3534
    3635        extract( $args );
     
    160159
    161160    function widget($args, $instance) {
    162         global $bp;
    163161
    164162        extract( $args );
     
    228226    }
    229227
    230     function widget($args, $instance) {
    231         global $bp;
     228    function widget( $args, $instance ) {
    232229
    233230        extract( $args );
     
    287284
    288285function bp_core_ajax_widget_members() {
    289     global $bp;
    290286
    291287    check_ajax_referer( 'bp_core_widget_members' );
Note: See TracChangeset for help on using the changeset viewer.