Skip to:
Content

BuddyPress.org

Changeset 9471


Ignore:
Timestamp:
02/10/2015 02:49:16 AM (5 years ago)
Author:
johnjamesjacoby
Message:

Replace all remaining $bp global touches with buddypress().

All existing tests continue to pass as normal. I will further manually scrutinize each replacement to ensure correctness.

Fixes #5138. Any stragglers or updates will reference this ticket.

Location:
trunk
Files:
46 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-actions.php

    r9384 r9471  
    3636 * @since BuddyPress (1.2)
    3737 *
    38  * @global object $bp BuddyPress global settings
    3938 * @uses bp_is_activity_component()
    4039 * @uses bp_is_current_action()
     
    201200 * @since BuddyPress (1.6)
    202201 *
    203  * @global object $bp BuddyPress global settings
    204202 * @param int $activity_id Activity id to be deleted. Defaults to 0.
    205203 * @return bool False on failure.
    206204 */
    207205function bp_activity_action_spam_activity( $activity_id = 0 ) {
    208     global $bp;
     206    $bp = buddypress();
    209207
    210208    // Not viewing activity, or action is not spam, or Akismet isn't present
     
    507505 * @since BuddyPress (1.0)
    508506 *
    509  * @global object $bp BuddyPress global settings
    510507 * @uses bp_is_activity_component()
    511508 * @uses bp_is_current_action()
     
    516513 */
    517514function bp_activity_action_sitewide_feed() {
    518     global $bp;
     515    $bp = buddypress();
    519516
    520517    if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
     
    715712 *
    716713 * @since BuddyPress (1.6)
    717  *
    718  * @global object $bp BuddyPress global settings
    719714 */
    720715function bp_activity_setup_akismet() {
    721     global $bp;
     716    $bp = buddypress();
    722717
    723718    // Bail if Akismet is not active
  • trunk/src/bp-activity/bp-activity-admin.php

    r9351 r9471  
    821821 * @since BuddyPress (1.6.0)
    822822 *
    823  * @global object $bp BuddyPress global settings.
    824  *
    825823 * @param object $item Activity item.
    826824 */
    827825function bp_activity_admin_edit_metabox_type( $item ) {
    828     global $bp;
     826    $bp = buddypress();
    829827
    830828    $actions  = array();
  • trunk/src/bp-activity/bp-activity-akismet.php

    r9351 r9471  
    655655 * @since BuddyPress (1.6)
    656656 *
    657  * @global object $bp BuddyPress global settings.
    658657 * @global wpdb $wpdb WordPress database object.
    659658 */
    660659function bp_activity_akismet_delete_old_metadata() {
    661     global $bp, $wpdb;
     660    global $wpdb;
     661
     662    $bp = buddypress();
    662663
    663664    /**
  • trunk/src/bp-activity/bp-activity-cache.php

    r9367 r9471  
    2121 */
    2222function bp_activity_update_meta_cache( $activity_ids = false ) {
    23     global $bp;
     23    $bp = buddypress();
    2424
    2525    $cache_args = array(
  • trunk/src/bp-activity/bp-activity-functions.php

    r9456 r9471  
    912912 *
    913913 * @global object $wpdb WordPress database access object.
    914  * @global object $bp BuddyPress global settings.
    915914 *
    916915 * @param int $activity_id ID of the activity item whose metadata is being deleted.
     
    10791078 *
    10801079 * @global object $wpdb WordPress database access object.
    1081  * @global object $bp BuddyPress global settings.
    10821080 *
    10831081 * @param int $user_id ID of the user whose activity is being spammed.
     
    11481146 *
    11491147 * @global object $wpdb WordPress database access object.
    1150  * @global object $bp BuddyPress global settings.
    11511148 *
    11521149 * @param int $user_id ID of the user whose activity is being hammed.
     
    20542051 * @since BuddyPress (1.2.0)
    20552052 *
    2056  * @global object $bp BuddyPress global settings.
    20572053 * @uses wp_parse_args()
    20582054 * @uses bp_activity_add()
  • trunk/src/bp-activity/bp-activity-screens.php

    r9351 r9471  
    231231 * @since BuddyPress (1.2.0)
    232232 *
    233  * @global object $bp BuddyPress global settings
    234233 * @uses bp_is_activity_component()
    235234 * @uses bp_activity_get_specific()
     
    253252 */
    254253function bp_activity_screen_single_activity_permalink() {
    255     global $bp;
     254    $bp = buddypress();
    256255
    257256    // No displayed user or not viewing activity component
  • trunk/src/bp-activity/bp-activity-template.php

    r9411 r9471  
    165165     */
    166166    function __construct( $args ) {
    167         global $bp;
     167        $bp = buddypress();
    168168
    169169        // Backward compatibility with old method of passing arguments
     
    427427 *
    428428 * @global object $activities_template {@link BP_Activity_Template}
    429  * @global object $bp BuddyPress global settings.
    430429 * @uses groups_is_user_member()
    431430 * @uses bp_current_action()
     
    13491348     * @see bp_core_fetch_avatar() For a description of the arguments.
    13501349     * @global object $activities_template {@link BP_Activity_Template}
    1351      * @global object $bp BuddyPress global settings
    13521350     * @uses bp_is_single_activity()
    13531351     * @uses wp_parse_args()
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r9369 r9471  
    1616 * @since BuddyPress (1.0.0)
    1717 *
    18  * @global object $bp The BuddyPress global settings object.
    19  *
    2018 * @return bool|null Returns false if activity component is not active.
    2119 */
    2220function bp_blogs_register_activity_actions() {
    23     global $bp;
     21    $bp = buddypress();
    2422
    2523    // Bail if activity is not active
     
    322320 *
    323321 * @see bp_activity_add() for description of parameters.
    324  * @global object $bp The BuddyPress global settings object.
    325322 *
    326323 * @param array $args {
     
    333330 */
    334331function bp_blogs_record_activity( $args = '' ) {
    335     global $bp;
    336332
    337333    // Bail if activity is not active
     
    339335        return false;
    340336    }
     337
     338    $bp = buddypress();
    341339
    342340    $defaults = array(
  • trunk/src/bp-blogs/bp-blogs-classes.php

    r9354 r9471  
    4040     */
    4141    public function populate() {
    42         global $wpdb, $bp;
     42        global $wpdb;
     43
     44        $bp = buddypress();
    4345
    4446        $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
     
    5456     */
    5557    public function save() {
    56         global $wpdb, $bp;
     58        global $wpdb;
    5759
    5860        $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
     
    7880            return false;
    7981
     82        $bp = buddypress();
     83
    8084        if ( $this->id ) {
    8185            // Update
     
    113117     */
    114118    public function exists() {
    115         global $bp, $wpdb;
     119        global $wpdb;
     120
     121        $bp = buddypress();
    116122
    117123        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
     
    141147     */
    142148    public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false ) {
    143         global $bp, $wpdb;
     149        global $wpdb;
     150
     151        $bp = buddypress();
    144152
    145153        if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
     
    232240     */
    233241    public static function delete_blog_for_all( $blog_id ) {
    234         global $wpdb, $bp;
     242        global $wpdb;
    235243
    236244        bp_blogs_delete_blogmeta( $blog_id );
     245       
     246        $bp = buddypress();
     247
    237248        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
    238249    }
     
    247258     */
    248259    public static function delete_blog_for_user( $blog_id, $user_id = null ) {
    249         global $wpdb, $bp;
     260        global $wpdb;
    250261
    251262        if ( !$user_id )
    252263            $user_id = bp_loggedin_user_id();
     264
     265        $bp = buddypress();
    253266
    254267        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
     
    264277     */
    265278    public static function delete_blogs_for_user( $user_id = null ) {
    266         global $wpdb, $bp;
     279        global $wpdb;
    267280
    268281        if ( !$user_id )
    269282            $user_id = bp_loggedin_user_id();
     283
     284        $bp = buddypress();
    270285
    271286        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
     
    290305     */
    291306    public static function get_blogs_for_user( $user_id = 0, $show_hidden = false ) {
    292         global $bp, $wpdb;
     307        global $wpdb;
     308
     309        $bp = buddypress();
    293310
    294311        if ( !$user_id )
     
    325342     */
    326343    public static function get_blog_ids_for_user( $user_id = 0 ) {
    327         global $bp, $wpdb;
     344        global $wpdb;
     345
     346        $bp = buddypress();
    328347
    329348        if ( !$user_id )
     
    341360     */
    342361    public static function is_recorded( $blog_id ) {
    343         global $bp, $wpdb;
     362        global $wpdb;
     363
     364        $bp = buddypress();
    344365
    345366        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
     
    358379     */
    359380    public static function total_blog_count_for_user( $user_id = null ) {
    360         global $bp, $wpdb;
     381        global $wpdb;
     382
     383        $bp = buddypress();
    361384
    362385        if ( !$user_id )
     
    387410     */
    388411    public static function search_blogs( $filter, $limit = null, $page = null ) {
    389         global $wpdb, $bp;
     412        global $wpdb;
    390413
    391414        $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
     
    400423            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    401424        }
     425
     426        $bp = buddypress();
    402427
    403428        $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
     
    422447     */
    423448    public static function get_all( $limit = null, $page = null ) {
    424         global $bp, $wpdb;
     449        global $wpdb;
     450
     451        $bp = buddypress();
    425452
    426453        $hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
    427         $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
     454        $pag_sql    = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
    428455
    429456        $paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
     
    449476     */
    450477    public static function get_by_letter( $letter, $limit = null, $page = null ) {
    451         global $bp, $wpdb;
     478        global $wpdb;
     479
     480        $bp = buddypress();
    452481
    453482        $letter_like = '%' . bp_esc_like( $letter ) . '%';
     
    483512     */
    484513    public static function get_blog_extras( &$paged_blogs, &$blog_ids, $type = false ) {
    485         global $bp, $wpdb;
     514        global $wpdb;
     515
     516        $bp = buddypress();
    486517
    487518        if ( empty( $blog_ids ) )
     
    562593     */
    563594    public static function get_user_blog( $user_id, $blog_id ) {
    564         global $bp, $wpdb;
     595        global $wpdb;
     596
     597        $bp = buddypress();
    565598
    566599        $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r9351 r9471  
    1515 * @since BuddyPress (1.5.0)
    1616 *
    17  * @global BuddyPress $bp The one true BuddyPress instance.
    18  *
    1917 * @return bool True if set, false if empty.
    2018 */
    2119function bp_blogs_has_directory() {
    22     global $bp;
     20    $bp = buddypress();
    2321
    2422    return (bool) !empty( $bp->pages->blogs->id );
     
    827825 */
    828826function bp_blogs_remove_blog( $blog_id ) {
    829     global $bp;
    830827
    831828    $blog_id = (int) $blog_id;
     
    844841
    845842    // Delete activity stream item
    846     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
     843    bp_blogs_delete_activity( array(
     844        'item_id'   => $blog_id,
     845        'component' => buddypress()->blogs->id,
     846        'type'      => 'new_blog'
     847    ) );
    847848
    848849    /**
     
    865866 */
    866867function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
    867     global $bp;
    868868
    869869    $blog_id = (int) $blog_id;
     
    885885    bp_blogs_delete_activity( array(
    886886        'item_id'   => $blog_id,
    887         'component' => $bp->blogs->id,
     887        'component' => buddypress()->blogs->id,
    888888        'type'      => 'new_blog'
    889889    ) );
     
    910910 */
    911911function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
    912     global $wpdb, $bp;
     912    global $wpdb;
    913913
    914914    if ( empty( $wpdb->blogid ) )
     
    935935
    936936    // Delete activity stream item
    937     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->id, 'type' => 'new_blog_post' ) );
     937    bp_blogs_delete_activity( array(
     938        'item_id'           => $blog_id,
     939        'secondary_item_id' => $post_id,
     940        'component'         => buddypress()->blogs->id,
     941        'type'              => 'new_blog_post'
     942    ) );
    938943
    939944    /**
     
    10641069 * @since BuddyPress (1.6.0)
    10651070 *
    1066  * @global object $bp BuddyPress global settings.
    1067  *
    10681071 * @param string $new_status New comment status.
    10691072 * @param string $old_status Previous comment status.
     
    10711074 */
    10721075function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
    1073     global $bp;
    10741076
    10751077    // Check the Activity component is active
     
    11001102    // Get the activity
    11011103    if ( bp_disable_blogforum_comments() ) {
    1102         $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
     1104        $activity_id = bp_activity_get_activity_id( array(
     1105            'component'         => buddypress()->blogs->id,
     1106            'item_id'           => get_current_blog_id(),
     1107            'secondary_item_id' => $comment->comment_ID,
     1108            'type'              => 'new_blog_comment'
     1109        ) );
    11031110    } else {
    11041111        $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
     
    11891196 */
    11901197function bp_blogs_remove_data_for_blog( $blog_id ) {
    1191     global $bp;
    11921198
    11931199    /**
     
    12051211
    12061212    // Delete activity stream item
    1207     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => false ) );
     1213    bp_blogs_delete_activity( array(
     1214        'item_id'   => $blog_id,
     1215        'component' => buddypress()->blogs->id,
     1216        'type'      => false
     1217    ) );
    12081218
    12091219    /**
     
    12841294 *
    12851295 * @global object $wpdb WordPress database access object.
    1286  * @global object $bp BuddyPress global settings.
    12871296 *
    12881297 * @param int $blog_id ID of the blog whose metadata is being deleted.
     
    12981307 */
    12991308function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
    1300     global $wpdb, $bp;
     1309    global $wpdb;
    13011310
    13021311    // Legacy - if no meta_key is passed, delete all for the blog_id
     
    13261335 *
    13271336 * @global object $wpdb WordPress database access object.
    1328  * @global object $bp BuddyPress global settings.
    13291337 *
    13301338 * @param int $blog_id ID of the blog whose metadata is being requested.
     
    13491357 *
    13501358 * @global object $wpdb WordPress database access object.
    1351  * @global object $bp BuddyPress global settings.
    13521359 *
    13531360 * @param int $blog_id ID of the blog whose metadata is being updated.
  • trunk/src/bp-blogs/bp-blogs-template.php

    r9468 r9471  
    11151115 */
    11161116function bp_blog_signup_enabled() {
    1117     global $bp;
    1118 
    1119     $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
     1117    $bp = buddypress();
     1118
     1119    $active_signup = isset( $bp->site_options['registration'] )
     1120        ? $bp->site_options['registration']
     1121        : 'all';
    11201122
    11211123    /**
  • trunk/src/bp-core/admin/bp-core-slugs.php

    r9351 r9471  
    4949 */
    5050function bp_core_admin_slugs_options() {
    51     global $bp;
     51    $bp = buddypress();
    5252
    5353    // Get the existing WP pages
  • trunk/src/bp-core/admin/bp-core-tools.php

    r9308 r9471  
    156156 */
    157157function bp_admin_repair_friend_count() {
    158     global $wpdb, $bp;
     158    global $wpdb;
    159159
    160160    if ( ! bp_is_active( 'friends' ) ) {
     
    169169        return array( 1, sprintf( $statement, $result ) );
    170170    }
     171
     172    $bp = buddypress();
    171173
    172174    // Walk through all users on the site
     
    212214 */
    213215function bp_admin_repair_group_count() {
    214     global $wpdb, $bp;
     216    global $wpdb;
    215217
    216218    if ( ! bp_is_active( 'groups' ) ) {
     
    225227        return array( 1, sprintf( $statement, $result ) );
    226228    }
     229
     230    $bp = buddypress();
    227231
    228232    // Walk through all users on the site
  • trunk/src/bp-core/bp-core-buddybar.php

    r9351 r9471  
    1414/**
    1515 * Add an item to the main BuddyPress navigation array.
    16  *
    17  * @global BuddyPress $bp The one true BuddyPress instance.
    1816 *
    1917 * @param array $args {
     
    3937 */
    4038function bp_core_new_nav_item( $args = '' ) {
    41     global $bp;
     39    $bp = buddypress();
    4240
    4341    $defaults = array(
     
    120118 * Modify the default subnav item that loads when a top level nav item is clicked.
    121119 *
    122  * @global BuddyPress $bp The one true BuddyPress instance.
    123  *
    124120 * @param array $args {
    125121 *     @type string $parent_slug The slug of the nav item whose default is
     
    131127 */
    132128function bp_core_new_nav_default( $args = '' ) {
    133     global $bp;
     129    $bp = buddypress();
    134130
    135131    $defaults = array(
     
    196192 * after all plugins have had a chance to register their navigation items.
    197193 *
    198  * @global BuddyPress $bp The one true BuddyPress instance
    199  *
    200194 * @return bool|null Returns false on failure.
    201195 */
    202196function bp_core_sort_nav_items() {
    203     global $bp;
     197    $bp = buddypress();
    204198
    205199    if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
     
    229223/**
    230224 * Add a subnav item to the BuddyPress navigation.
    231  *
    232  * @global BuddyPress $bp The one true BuddyPress instance.
    233225 *
    234226 * @param array $args {
     
    261253 */
    262254function bp_core_new_subnav_item( $args = '' ) {
    263     global $bp;
     255    $bp = buddypress();
    264256
    265257    $r = wp_parse_args( $args, array(
     
    442434 * Sort all subnavigation arrays.
    443435 *
    444  * @global BuddyPress $bp The one true BuddyPress instance
    445  *
    446436 * @return bool|null Returns false on failure.
    447437 */
    448438function bp_core_sort_subnav_items() {
    449     global $bp;
     439    $bp = buddypress();
    450440
    451441    if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
     
    487477 */
    488478function bp_nav_item_has_subnav( $nav_item = '' ) {
    489     global $bp;
     479    $bp = buddypress();
    490480
    491481    if ( !$nav_item )
     
    504494 */
    505495function bp_core_remove_nav_item( $parent_id ) {
    506     global $bp;
     496    $bp = buddypress();
    507497
    508498    // Unset subnav items for this nav item
     
    533523 */
    534524function bp_core_remove_subnav_item( $parent_id, $slug ) {
    535     global $bp;
    536 
    537     $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false;
     525    $bp = buddypress();
     526
     527    $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] )
     528        ? $bp->bp_options_nav[$parent_id][$slug]['screen_function']
     529        : false;
    538530
    539531    if ( ! empty( $screen_function ) ) {
     
    553545 * Clear all subnav items from a specific nav item.
    554546 *
    555  * @global BuddyPress $bp The one true BuddyPress instance.
    556  *
    557547 * @param string $parent_slug The slug of the parent navigation item.
    558548 */
    559549function bp_core_reset_subnav_items( $parent_slug ) {
    560     global $bp;
     550    $bp = buddypress();
    561551
    562552    unset( $bp->bp_options_nav[$parent_slug] );
  • trunk/src/bp-core/bp-core-catchuri.php

    r9467 r9471  
    3434 */
    3535function bp_core_set_uri_globals() {
    36     global $bp, $current_blog, $wp_rewrite;
     36    global $current_blog, $wp_rewrite;
    3737
    3838    // Don't catch URIs on non-root blogs unless multiblog mode is on
    3939    if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
    4040        return false;
     41
     42    $bp = buddypress();
    4143
    4244    // Define local variables
     
    419421 */
    420422function bp_core_catch_no_access() {
    421     global $bp, $wp_query;
     423    global $wp_query;
     424
     425    $bp = buddypress();
    422426
    423427    // If coming from bp_core_redirect() and $bp_no_status_set is true,
     
    550554 */
    551555function bp_redirect_canonical() {
    552     global $bp;
    553556
    554557    if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {
     
    574577        if ( $canonical_url !== $req_url_clean ) {
    575578
     579            $bp = buddypress();
     580
    576581            // Template messages have been deleted from the cookie by this point, so
    577582            // they must be readded before redirecting
     
    619624 */
    620625function bp_get_canonical_url( $args = array() ) {
    621     global $bp;
    622626
    623627    // For non-BP content, return the requested url, and let WP do the work
     
    625629        return bp_get_requested_url();
    626630    }
     631
     632    $bp = buddypress();
    627633
    628634    $defaults = array(
     
    701707 */
    702708function bp_get_requested_url() {
    703     global $bp;
     709    $bp = buddypress();
    704710
    705711    if ( empty( $bp->canonical_stack['requested_url'] ) ) {
  • trunk/src/bp-core/bp-core-classes.php

    r9404 r9471  
    222222     */
    223223    public function prepare_user_ids_query() {
    224         global $wpdb, $bp;
     224        global $wpdb;
     225
     226        $bp = buddypress();
    225227
    226228        // Default query variables used here
     
    953955     */
    954956    public static function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
    955         global $wpdb, $bp;
     957        global $wpdb;
    956958
    957959        _deprecated_function( __METHOD__, '1.7', 'BP_User_Query' );
     960
     961        $bp = buddypress();
    958962
    959963        $sql = array();
     
    11291133     * Fetch the details for all users whose usernames start with the given letter.
    11301134     *
    1131      * @global BuddyPress $bp The one true BuddyPress instance.
    11321135     * @global wpdb $wpdb WordPress database object.
    11331136     *
     
    11431146     */
    11441147    public static function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
    1145         global $bp, $wpdb;
     1148        global $wpdb;
    11461149
    11471150        $pag_sql = '';
     
    11601163            }
    11611164        }
     1165
     1166        $bp = buddypress();
    11621167
    11631168        $letter_like = bp_esc_like( $letter ) . '%';
     
    12441249     * Find users who match on the value of an xprofile data.
    12451250     *
    1246      * @global BuddyPress $bp The one true BuddyPress instance.
    12471251     * @global wpdb $wpdb WordPress database object.
    12481252     *
     
    12551259     */
    12561260    public static function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
    1257         global $bp, $wpdb;
     1261        global $wpdb;
     1262
     1263        $bp = buddypress();
    12581264
    12591265        $user_ids = array();
     
    12881294     * Accepts multiple user IDs to fetch data for.
    12891295     *
    1290      * @global BuddyPress $bp The one true BuddyPress instance.
    12911296     * @global wpdb $wpdb WordPress database object.
    12921297     *
     
    12971302     */
    12981303    public static function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
    1299         global $bp, $wpdb;
     1304        global $wpdb;
     1305
     1306        $bp = buddypress();
    13001307
    13011308        if ( empty( $user_ids ) )
     
    16991706     * Update or insert notification details into the database.
    17001707     *
    1701      * @global BuddyPress $bp The one true BuddyPress instance
    17021708     * @global wpdb $wpdb WordPress database object
    17031709     * @return bool Success or failure
    17041710     */
    17051711    public function save() {
    1706         global $bp, $wpdb;
     1712        global $wpdb;
     1713
     1714        $bp = buddypress();
    17071715
    17081716        // Update
     
    17281736     * Fetches the notification data from the database.
    17291737     *
    1730      * @global BuddyPress $bp The one true BuddyPress instance
    17311738     * @global wpdb $wpdb WordPress database object
    17321739     */
    17331740    public function populate() {
    1734         global $bp, $wpdb;
     1741        global $wpdb;
     1742
     1743        $bp = buddypress();
    17351744
    17361745        if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
     
    17481757
    17491758    public static function check_access( $user_id, $notification_id ) {
    1750         global $wpdb, $bp;
     1759        global $wpdb;
     1760
     1761        $bp = buddypress();
    17511762
    17521763        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
     
    17561767     * Fetches all the notifications in the database for a specific user.
    17571768     *
    1758      * @global BuddyPress $bp The one true BuddyPress instance
    17591769     * @global wpdb $wpdb WordPress database object
    17601770     * @param integer $user_id User ID
     
    17641774     */
    17651775    public static function get_all_for_user( $user_id, $status = 'is_new' ) {
    1766         global $bp, $wpdb;
    1767 
    1768         $is_new = ( 'is_new' == $status ) ? ' AND is_new = 1 ' : '';
     1776        global $wpdb;
     1777
     1778        $bp = buddypress();
     1779
     1780        $is_new = ( 'is_new' === $status )
     1781            ? ' AND is_new = 1 '
     1782            : '';
    17691783
    17701784        return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d {$is_new}", $user_id ) );
     
    17741788     * Delete all the notifications for a user based on the component name and action.
    17751789     *
    1776      * @global BuddyPress $bp The one true BuddyPress instance
    17771790     * @global wpdb $wpdb WordPress database object
    17781791     * @param integer $user_id
     
    17821795     */
    17831796    public static function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
    1784         global $bp, $wpdb;
     1797        global $wpdb;
     1798
     1799        $bp = buddypress();
    17851800
    17861801        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
     
    17901805     * Delete all the notifications that have a specific item id, component name and action.
    17911806     *
    1792      * @global BuddyPress $bp The one true BuddyPress instance
    17931807     * @global wpdb $wpdb WordPress database object
    17941808     * @param integer $user_id The ID of the user who the notifications are for.
     
    18001814     */
    18011815    public static function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
    1802         global $bp, $wpdb;
    1803 
    1804         $secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : '';
     1816        global $wpdb;
     1817
     1818        $bp = buddypress();
     1819
     1820        $secondary_item_sql = !empty( $secondary_item_id )
     1821            ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id )
     1822            : '';
    18051823
    18061824        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
     
    18101828     * Deletes all the notifications sent by a specific user, by component and action.
    18111829     *
    1812      * @global BuddyPress $bp The one true BuddyPress instance
    18131830     * @global wpdb $wpdb WordPress database object
    18141831     * @param integer $user_id The ID of the user whose sent notifications we wish to delete.
     
    18181835     */
    18191836    public static function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
    1820         global $bp, $wpdb;
     1837        global $wpdb;
     1838
     1839        $bp = buddypress();
    18211840
    18221841        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
     
    18261845     * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action.
    18271846     *
    1828      * @global BuddyPress $bp The one true BuddyPress instance
    18291847     * @global wpdb $wpdb WordPress database object
    18301848     * @param string $item_id The item id that they notifications are to be for.
     
    18351853     */
    18361854    public static function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
    1837         global $bp, $wpdb;
     1855        global $wpdb;
    18381856
    18391857        if ( $component_action )
     
    18461864        else
    18471865            $secondary_item_sql = '';
     1866
     1867        $bp = buddypress();
    18481868
    18491869        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
  • trunk/src/bp-core/bp-core-filters.php

    r9399 r9471  
    504504 *
    505505 * @see wp_title()
    506  * @global object $bp BuddyPress global settings.
    507506 *
    508507 * @param string $title Original page title.
     
    512511 */
    513512function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) {
    514     global $bp;
    515513
    516514    // If this is not a BP page, just return the title produced by WP
     
    529527    }
    530528
     529    $bp    = buddypress();
    531530    $title = '';
    532531
  • trunk/src/bp-core/bp-core-options.php

    r9351 r9471  
    297297 */
    298298function bp_core_activate_site_options( $keys = array() ) {
    299     global $bp;
    300299
    301300    if ( !empty( $keys ) && is_array( $keys ) ) {
     301        $bp = buddypress();
     302
    302303        $errors = false;
    303304
  • trunk/src/bp-core/bp-core-template.php

    r9428 r9471  
    443443     */
    444444    function bp_get_search_default_text( $component = '' ) {
    445         global $bp;
     445
     446        $bp = buddypress();
    446447
    447448        if ( empty( $component ) ) {
  • trunk/src/bp-core/deprecated/2.1.php

    r9470 r9471  
    9191 * @since BuddyPress (1.0.0)
    9292 * @deprecated BuddyPress (2.1.0)
    93  *
    94  * @global object $bp The BuddyPress global settings object.
    9593 *
    9694 * @return bool|null Returns false on failure. Otherwise echoes the menu item.
  • trunk/src/bp-forums/bp-forums-filters.php

    r9467 r9471  
    105105 */
    106106function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
    107     global $bp;
    108 
    109107    /**
    110108     * Filters the link for a forum topic tags directory.
     
    142140 * Append forum topic to page title.
    143141 *
    144  * @global object $bp Global BuddyPress settings object.
    145  *
    146142 * @see bp_modify_page_title()
    147143 *
     
    153149 */
    154150function bp_forums_add_forum_topic_to_page_title( $title, $original_title, $sep, $seplocation  ) {
    155     global $bp;
    156151
    157152    if ( bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) )
  • trunk/src/bp-forums/bp-forums-functions.php

    r9383 r9471  
    316316 */
    317317function bp_forums_new_topic( $args = '' ) {
    318     global $bp;
     318    $bp = buddypress();
    319319
    320320    /** This action is documented in bp-forums/bp-forums-screens */
     
    907907 */
    908908function bp_forums_get_post_extras( $posts ) {
    909     global $bp, $wpdb;
     909    global $wpdb;
    910910
    911911    if ( empty( $posts ) )
    912912        return $posts;
     913
     914    $bp = buddypress();
    913915
    914916    // Get the user ids
  • trunk/src/bp-forums/bp-forums-template.php

    r9467 r9471  
    2828     */
    2929    function bp_get_forums_slug() {
    30         global $bp;
    31 
    3230        /**
    3331         * Filters the forums component slug.
     
    3735         * @param string $slug Forums component slug.
    3836         */
    39         return apply_filters( 'bp_get_forums_slug', $bp->forums->slug );
     37        return apply_filters( 'bp_get_forums_slug', buddypress()->forums->slug );
    4038    }
    4139
     
    5856     */
    5957    function bp_get_forums_root_slug() {
    60         global $bp;
    61 
    6258        /**
    6359         * Filters the forums component root slug.
     
    6763         * @param string $root_slug Forums component root slug.
    6864         */
    69         return apply_filters( 'bp_get_forums_root_slug', $bp->forums->root_slug );
     65        return apply_filters( 'bp_get_forums_root_slug', buddypress()->forums->root_slug );
    7066    }
    7167
     
    231227     */
    232228    function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
    233         global $bp;
     229        $bp = buddypress();
    234230
    235231        $this->pag_page     = $page;
     
    333329         * @param string $no_stickies Requested sticky format.
    334330         */
    335         $this->topic_count       = apply_filters_ref_array( 'bp_forums_template_topic_count',                                array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
     331        $this->topic_count = apply_filters_ref_array( 'bp_forums_template_topic_count', array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
    336332
    337333        /**
     
    499495 */
    500496function bp_has_forum_topics( $args = '' ) {
    501     global $forum_template, $bp;
     497    global $forum_template;
     498
     499    $bp = buddypress();
    502500
    503501    /***
     
    16661664     */
    16671665    function bp_get_my_forum_topics_link() {
    1668         global $bp;
    1669 
    16701666        /**
    16711667         * Filters the permalink to the 'personal' topics tab.
     
    16901686     */
    16911687    function bp_get_unreplied_forum_topics_link() {
    1692         global $bp;
    1693 
    16941688        /**
    16951689         * Filters the permalink to the 'unreplied' topics tab.
     
    17141708     */
    17151709    function bp_get_popular_forum_topics_link() {
    1716         global $bp;
    1717 
    17181710        /**
    17191711         * Filters the permalink to the 'popular' topics tab.
     
    17381730     */
    17391731    function bp_get_newest_forum_topics_link() {
    1740         global $bp;
    1741 
    17421732        /**
    17431733         * Filters the link to the forums directory.
     
    17641754     */
    17651755    function bp_get_forum_topic_type() {
    1766         global $bp;
    17671756
    17681757        if ( !bp_is_directory() || !bp_current_action() )
     
    18791868     */
    18801869    function bp_get_forum_pagination_count() {
    1881         global $bp, $forum_template;
     1870        global $forum_template;
    18821871
    18831872        $start_num  = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
     
    19091898 */
    19101899function bp_is_edit_topic() {
    1911     global $bp;
    19121900
    19131901    if ( bp_is_action_variable( 'post' ) && bp_is_action_variable( 'edit' ) )
     
    20612049     */
    20622050    function __construct( $topic_id, $per_page, $max, $order ) {
    2063         global $bp, $current_user, $forum_template;
    2064 
    2065                 if ( !isset( $forum_template ) ) {
    2066                         $forum_template = new stdClass;
    2067                 }
     2051        global $forum_template;
     2052
     2053        if ( !isset( $forum_template ) ) {
     2054            $forum_template = new stdClass;
     2055        }
    20682056
    20692057        $this->pag_page        = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
     
    21932181     */
    21942182    function the_post() {
    2195         global $post;
    21962183
    21972184        $this->in_the_loop = true;
     
    25162503     */
    25172504    function bp_get_the_topic_post_is_mine() {
    2518         global $bp, $topic_template;
     2505        global $topic_template;
    25192506
    25202507        return bp_loggedin_user_id() == $topic_template->post->poster_id;
     
    26292616 */
    26302617function bp_the_topic_pagination_count() {
    2631     global $bp, $topic_template;
     2618    global $topic_template;
    26322619
    26332620    $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
     
    27582745     */
    27592746    function bp_get_forum_name( $forum_id = 0 ) {
    2760         global $bp;
    27612747
    27622748        if ( empty( $forum_id ) ) {
  • trunk/src/bp-friends/bp-friends-classes.php

    r9351 r9471  
    113113     */
    114114    public function populate() {
    115         global $wpdb, $bp;
     115        global $wpdb;
     116
     117        $bp = buddypress();
    116118
    117119        if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ) ) {
     
    138140     */
    139141    public function save() {
    140         global $wpdb, $bp;
     142        global $wpdb;
     143
     144        $bp = buddypress();
    141145
    142146        $this->initiator_user_id = apply_filters( 'friends_friendship_initiator_user_id_before_save', $this->initiator_user_id, $this->id );
     
    178182
    179183    public function delete() {
    180         global $wpdb, $bp;
     184        global $wpdb;
     185
     186        $bp = buddypress();
     187
    181188        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) );
    182189    }
     
    195202     */
    196203    public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
    197         global $wpdb, $bp;
     204        global $wpdb;
    198205
    199206        if ( !empty( $friend_requests_only ) ) {
     
    205212        }
    206213
     214        $bp = buddypress();
    207215        $friends = $wpdb->get_results( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} {$friend_sql} {$oc_sql} ORDER BY date_created DESC" );
    208216        $fids = array();
     
    228236     */
    229237    public static function get_friendship_id( $user_id, $friend_id ) {
    230         global $wpdb, $bp;
     238        global $wpdb;
     239
     240        $bp = buddypress();
    231241
    232242        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) );
     
    244254
    245255        if ( false === $friend_requests ) {
    246             global $wpdb, $bp;
     256            global $wpdb;
     257
     258            $bp = buddypress();
    247259
    248260            $friend_requests = $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
     
    263275     */
    264276    public static function total_friend_count( $user_id = 0 ) {
    265         global $wpdb, $bp;
     277        global $wpdb;
    266278
    267279        if ( empty( $user_id ) )
    268280            $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     281
     282        $bp = buddypress();
    269283
    270284        /* This is stored in 'total_friend_count' usermeta.
     
    298312     */
    299313    public static function search_friends( $filter, $user_id, $limit = null, $page = null ) {
    300         global $wpdb, $bp;
     314        global $wpdb;
    301315
    302316        // TODO: Optimize this function.
     
    321335        if ( empty( $fids ) )
    322336            return false;
     337
     338        $bp = buddypress();
    323339
    324340        // filter the user_ids based on the search criteria.
     
    356372     */
    357373    public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
    358         global $wpdb, $bp;
     374        global $wpdb;
    359375
    360376        if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) {
    361377            return false;
    362378        }
     379
     380        $bp = buddypress();
    363381
    364382        $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) );
     
    419437     */
    420438    public static function accept($friendship_id) {
    421         global $wpdb, $bp;
     439        global $wpdb;
     440
     441        $bp = buddypress();
     442
    422443        return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
    423444    }
     
    430451     */
    431452    public static function withdraw($friendship_id) {
    432         global $wpdb, $bp;
     453        global $wpdb;
     454
     455        $bp = buddypress();
     456
    433457        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
    434458    }
     
    441465     */
    442466    public static function reject($friendship_id) {
    443         global $wpdb, $bp;
     467        global $wpdb;
     468
     469        $bp = buddypress();
     470
    444471        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
    445472    }
     
    458485     */
    459486    public static function search_users( $filter, $user_id, $limit = null, $page = null ) {
    460         global $wpdb, $bp;
     487        global $wpdb;
    461488
    462489        // Only search for matching strings at the beginning of the
     
    470497        if ( !empty( $limit ) && !empty( $page ) )
    471498            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) );
     499
     500        $bp = buddypress();
    472501
    473502        // filter the user_ids based on the search criteria.
     
    495524     */
    496525    public static function search_users_count( $filter ) {
    497         global $wpdb, $bp;
     526        global $wpdb;
    498527
    499528        // Only search for matching strings at the beginning of the
     
    503532        $usermeta_table = $wpdb->prefix . 'usermeta';
    504533        $users_table    = $wpdb->base_prefix . 'users';
     534
     535        $bp = buddypress();
    505536
    506537        // filter the user_ids based on the search criteria.
     
    528559     */
    529560    public static function sort_by_name( $user_ids ) {
    530         global $wpdb, $bp;
     561        global $wpdb;
    531562
    532563        if ( !bp_is_active( 'xprofile' ) )
    533564            return false;
     565
     566        $bp = buddypress();
    534567
    535568        $user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
     
    548581     */
    549582    public static function get_random_friends( $user_id, $total_friends = 5 ) {
    550         global $wpdb, $bp;
    551 
     583        global $wpdb;
     584
     585        $bp      = buddypress();
    552586        $fids    = array();
    553587        $sql     = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends );
     
    612646     */
    613647    public static function get_user_ids_for_friendship( $friendship_id ) {
    614         global $wpdb, $bp;
     648        global $wpdb;
     649
     650        $bp = buddypress();
     651
    615652        return $wpdb->get_row( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE id = %d", $friendship_id ) );
    616653    }
     
    622659     */
    623660    public static function delete_all_for_user( $user_id ) {
    624         global $wpdb, $bp;
     661        global $wpdb;
     662
     663        $bp = buddypress();
    625664
    626665        // Get friends of $user_id
  • trunk/src/bp-friends/bp-friends-filters.php

    r8958 r9471  
    1616 * @since BuddyPress (1.7.0)
    1717 *
    18  * @global BuddyPress $bp Global BuddyPress settings.
    1918 * @global WPDB $wpdb WordPress database access object.
    2019 *
     
    2423 */
    2524function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
    26     global $bp, $wpdb;
     25    global $wpdb;
    2726
    2827    // stop if user isn't logged in
     
    3029        return;
    3130    }
     31
     32    $bp = buddypress();
    3233
    3334    // Fetch whether or not the user is a friend of the current user
  • trunk/src/bp-groups/bp-groups-actions.php

    r9466 r9471  
    9696 */
    9797function groups_action_create_group() {
    98     global $bp;
    9998
    10099    // If we're not at domain.org/groups/create/ then return false
     
    109108        bp_core_redirect( bp_get_groups_directory_permalink() );
    110109    }
     110
     111    $bp = buddypress();
    111112
    112113    // Make sure creation steps are in the right order
     
    361362 */
    362363function groups_action_join_group() {
    363     global $bp;
    364364
    365365    if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( 'join' ) )
     
    369369    if ( !check_admin_referer( 'groups_join_group' ) )
    370370        return false;
     371
     372    $bp = buddypress();
    371373
    372374    // Skip if banned or already a member
     
    457459 */
    458460function groups_action_sort_creation_steps() {
    459     global $bp;
    460461
    461462    if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) )
    462463        return false;
     464
     465    $bp = buddypress();
    463466
    464467    if ( !is_array( $bp->groups->group_creation_steps ) )
  • trunk/src/bp-groups/bp-groups-cache.php

    r9351 r9471  
    2929 */
    3030function bp_groups_update_meta_cache( $group_ids = false ) {
    31     global $bp;
     31    $bp = buddypress();
    3232
    3333    $cache_args = array(
  • trunk/src/bp-groups/bp-groups-classes.php

    r9365 r9471  
    260260     */
    261261    public function save() {
    262         global $wpdb, $bp;
     262        global $wpdb;
     263
     264        $bp = buddypress();
    263265
    264266        $this->creator_id   = apply_filters( 'groups_group_creator_id_before_save',   $this->creator_id,   $this->id );
     
    356358     */
    357359    public function delete() {
    358         global $wpdb, $bp;
     360        global $wpdb;
    359361
    360362        // Delete groupmeta for the group
     
    374376
    375377        wp_cache_delete( $this->id, 'bp_groups' );
     378
     379        $bp = buddypress();
    376380
    377381        // Finally remove the group entry from the DB
     
    393397     */
    394398    public static function group_exists( $slug, $table_name = false ) {
    395         global $wpdb, $bp;
     399        global $wpdb;
    396400
    397401        if ( empty( $table_name ) )
    398             $table_name = $bp->groups->table_name;
     402            $table_name = buddypress()->groups->table_name;
    399403
    400404        if ( empty( $slug ) )
     
    425429     */
    426430    public static function get_invites( $user_id, $group_id ) {
    427         global $wpdb, $bp;
     431        global $wpdb;
     432
     433        $bp = buddypress();
     434
    428435        return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id ) );
    429436    }
     
    447454     */
    448455    public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
    449         global $wpdb, $bp;
     456        global $wpdb;
    450457
    451458        if ( empty( $user_id ) )
     
    464471        if ( empty( $gids['groups'] ) )
    465472            return false;
     473
     474        $bp = buddypress();
    466475
    467476        $gids = esc_sql( implode( ',', wp_parse_id_list( $gids['groups'] ) ) );
     
    491500     */
    492501    public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {
    493         global $wpdb, $bp;
     502        global $wpdb;
    494503
    495504        $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
     
    509518            $hidden_sql = "AND status != 'hidden'";
    510519
     520        $bp = buddypress();
     521
    511522        $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) {$hidden_sql} {$order_sql} {$pag_sql}", $search_terms_like, $search_terms_like ) );
    512523        $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) {$hidden_sql}", $search_terms_like, $search_terms_like ) );
     
    522533     */
    523534    public static function check_slug( $slug ) {
    524         global $wpdb, $bp;
     535        global $wpdb;
     536
     537        $bp = buddypress();
    525538
    526539        return $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM {$bp->groups->table_name} WHERE slug = %s", $slug ) );
     
    534547     */
    535548    public static function get_slug( $group_id ) {
    536         global $wpdb, $bp;
     549        global $wpdb;
     550
     551        $bp = buddypress();
    537552
    538553        return $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM {$bp->groups->table_name} WHERE id = %d", $group_id ) );
     
    546561     */
    547562    public static function has_members( $group_id ) {
    548         global $wpdb, $bp;
     563        global $wpdb;
     564
     565        $bp = buddypress();
    549566
    550567        $members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
     
    564581     */
    565582    public static function has_membership_requests( $group_id ) {
    566         global $wpdb, $bp;
     583        global $wpdb;
     584
     585        $bp = buddypress();
    567586
    568587        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0", $group_id ) );
     
    584603     */
    585604    public static function get_membership_requests( $group_id, $limit = null, $page = null ) {
    586         global $wpdb, $bp;
     605        global $wpdb;
    587606
    588607        if ( !empty( $limit ) && !empty( $page ) ) {
    589608            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    590609        }
     610
     611        $bp = buddypress();
    591612
    592613        $paged_requests = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0{$pag_sql}", $group_id ) );
     
    648669     */
    649670    public static function get( $args = array() ) {
    650         global $wpdb, $bp;
     671        global $wpdb;
    651672
    652673        // Backward compatibility with old method of passing arguments
     
    687708
    688709        $r = wp_parse_args( $args, $defaults );
     710
     711        $bp = buddypress();
    689712
    690713        $sql       = array();
     
    10131036     */
    10141037    public static function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
    1015         global $wpdb, $bp, $bbdb;
     1038        global $wpdb, $bbdb;
    10161039
    10171040        if ( empty( $bbdb ) )
     
    10341057            $exclude_sql = " AND g.id NOT IN ({$exclude})";
    10351058        }
     1059
     1060        $bp = buddypress();
    10361061
    10371062        if ( !empty( $user_id ) ) {
     
    10771102     */
    10781103    public static function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
    1079         global $wpdb, $bp, $bbdb;
     1104        global $wpdb, $bbdb;
    10801105
    10811106        if ( empty( $bbdb ) )
     
    10981123            $exclude_sql = " AND g.id NOT IN ({$exclude})";
    10991124        }
     1125
     1126        $bp = buddypress();
    11001127
    11011128        if ( !empty( $user_id ) ) {
     
    11381165     */
    11391166    public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
    1140         global $wpdb, $bp;
     1167        global $wpdb;
    11411168
    11421169        $pag_sql = $hidden_sql = $exclude_sql = '';
     
    11521179            }
    11531180        }
     1181
     1182        $bp = buddypress();
    11541183
    11551184        if ( !empty( $exclude ) ) {
     
    12061235     */
    12071236    public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
    1208         global $wpdb, $bp;
     1237        global $wpdb;
    12091238
    12101239        $pag_sql = $hidden_sql = $search_sql = $exclude_sql = '';
     
    12261255            $exclude_sql = " AND g.id NOT IN ({$exclude})";
    12271256        }
     1257
     1258        $bp = buddypress();
    12281259
    12291260        if ( !empty( $user_id ) ) {
     
    12641295     */
    12651296    public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {
    1266         global $bp, $wpdb;
     1297        global $wpdb;
    12671298
    12681299        if ( empty( $group_ids ) )
    12691300            return $paged_groups;
     1301
     1302        $bp = buddypress();
    12701303
    12711304        // Sanitize group IDs
     
    13381371     */
    13391372    public static function delete_all_invites( $group_id ) {
    1340         global $wpdb, $bp;
     1373        global $wpdb;
     1374
     1375        $bp = buddypress();
    13411376
    13421377        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d AND invite_sent = 1", $group_id ) );
     
    13521387     */
    13531388    public static function get_total_group_count() {
    1354         global $wpdb, $bp;
     1389        global $wpdb;
    13551390
    13561391        $hidden_sql = '';
     
    13581393            $hidden_sql = "WHERE status != 'hidden'";
    13591394
     1395        $bp = buddypress();
     1396
    13601397        return $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" );
    13611398    }
     
    13691406     */
    13701407    public static function get_global_forum_topic_count( $type ) {
    1371         global $bbdb, $wpdb, $bp;
     1408        global $bbdb, $wpdb;
     1409
     1410        $bp = buddypress();
    13721411
    13731412        if ( 'unreplied' == $type )
     
    13911430     */
    13921431    public static function get_total_member_count( $group_id ) {
    1393         global $wpdb, $bp;
     1432        global $wpdb;
     1433
     1434        $bp = buddypress();
    13941435
    13951436        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
     
    14061447     */
    14071448    public static function get_global_topic_count( $status = 'public', $search_terms = false ) {
    1408         global $bbdb, $wpdb, $bp;
     1449        global $bbdb, $wpdb;
    14091450
    14101451        switch ( $status ) {
     
    14271468        }
    14281469
     1470        $bp = buddypress();
     1471
    14291472        $sql = array();
    14301473
     
    14521495     */
    14531496    public static function get_group_type_ids() {
    1454         global $wpdb, $bp;
    1455 
     1497        global $wpdb;
     1498
     1499        $bp  = buddypress();
    14561500        $ids = array();
    14571501
     
    19812025     */
    19822026    public function populate() {
    1983         global $wpdb, $bp;
     2027        global $wpdb;
     2028
     2029        $bp = buddypress();
    19842030
    19852031        if ( $this->user_id && $this->group_id && !$this->id )
     
    20152061     */
    20162062    public function save() {
    2017         global $wpdb, $bp;
     2063        global $wpdb;
     2064
     2065        $bp = buddypress();
    20182066
    20192067        $this->user_id       = apply_filters( 'groups_member_user_id_before_save',       $this->user_id,       $this->id );
     
    21452193     */
    21462194    public function remove() {
    2147         global $wpdb, $bp;
    2148 
     2195        global $wpdb;
     2196
     2197        $bp  = buddypress();
    21492198        $sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
    21502199
     
    21952244     */
    21962245    public static function delete( $user_id, $group_id ) {
    2197         global $wpdb, $bp;
    2198 
     2246        global $wpdb;
     2247
     2248        $bp = buddypress();
    21992249        $remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
    22002250
     
    22222272     */
    22232273    public static function get_group_ids( $user_id, $limit = false, $page = false ) {
    2224         global $wpdb, $bp;
     2274        global $wpdb;
    22252275
    22262276        $pag_sql = '';
    22272277        if ( !empty( $limit ) && !empty( $page ) )
    22282278            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     2279
     2280        $bp = buddypress();
    22292281
    22302282        // If the user is logged in and viewing their own groups, we can show hidden and private groups
     
    22582310     */
    22592311    public static function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) {
    2260         global $wpdb, $bp;
     2312        global $wpdb;
    22612313
    22622314        $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
     
    22742326        if ( $user_id != bp_loggedin_user_id() )
    22752327            $hidden_sql = " AND g.status != 'hidden'";
     2328
     2329        $bp = buddypress();
    22762330
    22772331        $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}" );
     
    22972351     */
    22982352    public static function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) {
    2299         global $wpdb, $bp;
     2353        global $wpdb;
    23002354
    23012355        $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
     
    23132367        if ( $user_id != bp_loggedin_user_id() )
    23142368            $hidden_sql = " AND g.status != 'hidden'";
     2369
     2370        $bp = buddypress();
    23152371
    23162372        $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
     
    23362392     */
    23372393    public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
    2338         global $wpdb, $bp;
     2394        global $wpdb;
    23392395
    23402396        $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
     
    23532409            $hidden_sql = " AND g.status != 'hidden'";
    23542410
     2411        $bp = buddypress();
     2412
    23552413        $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
    23562414        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" );
     
    23662424     */
    23672425    public static function total_group_count( $user_id = 0 ) {
    2368         global $bp, $wpdb;
     2426        global $wpdb;
    23692427
    23702428        if ( empty( $user_id ) )
    23712429            $user_id = bp_displayed_user_id();
     2430
     2431        $bp = buddypress();
    23722432
    23732433        if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
     
    23942454     */
    23952455    public static function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) {
    2396         global $wpdb, $bp;
     2456        global $wpdb;
    23972457
    23982458        $pag_sql = ( !empty( $limit ) && !empty( $page ) ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
     
    24042464            $exclude_sql = '';
    24052465        }
     2466
     2467        $bp = buddypress();
    24062468
    24072469        $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d {$exclude_sql} ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
     
    24442506     */
    24452507    public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
    2446         global $wpdb, $bp;
     2508        global $wpdb;
    24472509
    24482510        if ( empty( $user_id ) )
    24492511            return false;
    24502512
     2513        $bp  = buddypress();
    24512514        $sql = "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0";
    24522515
     
    24652528     */
    24662529    public static function delete_invite( $user_id, $group_id ) {
    2467         global $wpdb, $bp;
     2530        global $wpdb;
    24682531
    24692532        if ( empty( $user_id ) )
    24702533            return false;
     2534
     2535        $bp = buddypress();
    24712536
    24722537        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) );
     
    24812546     */
    24822547    public static function delete_request( $user_id, $group_id ) {
    2483         global $wpdb, $bp;
     2548        global $wpdb;
    24842549
    24852550        if ( empty( $user_id ) )
    24862551            return false;
     2552
     2553        $bp = buddypress();
    24872554
    24882555        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
     
    24982565     */
    24992566    public static function check_is_admin( $user_id, $group_id ) {
    2500         global $wpdb, $bp;
     2567        global $wpdb;
    25012568
    25022569        if ( empty( $user_id ) )
    25032570            return false;
     2571
     2572        $bp = buddypress();
    25042573
    25052574        return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) );
     
    25152584     */
    25162585    public static function check_is_mod( $user_id, $group_id ) {
    2517         global $wpdb, $bp;
     2586        global $wpdb;
    25182587
    25192588        if ( empty( $user_id ) )
    25202589            return false;
     2590
     2591        $bp = buddypress();
    25212592
    25222593        return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) );
     
    25322603     */
    25332604    public static function check_is_member( $user_id, $group_id ) {
    2534         global $wpdb, $bp;
     2605        global $wpdb;
    25352606
    25362607        if ( empty( $user_id ) )
    25372608            return false;
     2609
     2610        $bp = buddypress();
    25382611
    25392612        return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) );
     
    25492622     */
    25502623    public static function check_is_banned( $user_id, $group_id ) {
    2551         global $wpdb, $bp;
     2624        global $wpdb;
    25522625
    25532626        if ( empty( $user_id ) )
    25542627            return false;
     2628
     2629        $bp = buddypress();
    25552630
    25562631        return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     
    25682643     */
    25692644    public static function check_is_creator( $user_id, $group_id ) {
    2570         global $bp, $wpdb;
     2645        global $wpdb;
    25712646
    25722647        if ( empty( $user_id ) )
    25732648            return false;
     2649
     2650        $bp = buddypress();
    25742651
    25752652        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     
    25842661     */
    25852662    public static function check_for_membership_request( $user_id, $group_id ) {
    2586         global $wpdb, $bp;
     2663        global $wpdb;
    25872664
    25882665        if ( empty( $user_id ) )
    25892666            return false;
     2667
     2668        $bp = buddypress();
    25902669
    25912670        return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) );
     
    26002679     */
    26012680    public static function get_random_groups( $user_id = 0, $total_groups = 5 ) {
    2602         global $wpdb, $bp;
     2681        global $wpdb;
     2682
     2683        $bp = buddypress();
    26032684
    26042685        // If the user is logged in and viewing their random groups, we can show hidden and private groups
     
    26172698     */
    26182699    public static function get_group_member_ids( $group_id ) {
    2619         global $bp, $wpdb;
     2700        global $wpdb;
     2701
     2702        $bp = buddypress();
    26202703
    26212704        return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
     
    26292712     */
    26302713    public static function get_group_administrator_ids( $group_id ) {
    2631         global $bp, $wpdb;
     2714        global $wpdb;
    26322715
    26332716        $group_admins = wp_cache_get( $group_id, 'bp_group_admins' );
    26342717
    26352718        if ( false === $group_admins ) {
     2719            $bp = buddypress();
    26362720            $group_admins = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) );
    26372721
     
    26492733     */
    26502734    public static function get_group_moderator_ids( $group_id ) {
    2651         global $bp, $wpdb;
     2735        global $wpdb;
     2736
     2737        $bp = buddypress();
    26522738
    26532739        return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) );
     
    26612747     */
    26622748    public static function get_all_membership_request_user_ids( $group_id ) {
    2663         global $bp, $wpdb;
     2749        global $wpdb;
     2750
     2751        $bp = buddypress();
    26642752
    26652753        return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0", $group_id ) );
     
    26722760     */
    26732761    public static function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false ) {
    2674         global $bp, $wpdb;
     2762        global $wpdb;
    26752763
    26762764        _deprecated_function( __METHOD__, '1.8', 'BP_Group_Member_Query' );
     
    26932781            $exclude_sql = " AND m.user_id NOT IN ({$exclude})";
    26942782        }
     2783
     2784        $bp = buddypress();
    26952785
    26962786        if ( bp_is_active( 'xprofile' ) ) {
     
    27372827     */
    27382828    public static function delete_all( $group_id ) {
    2739         global $wpdb, $bp;
     2829        global $wpdb;
     2830
     2831        $bp = buddypress();
    27402832
    27412833        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
     
    27502842     */
    27512843    public static function delete_all_for_user( $user_id ) {
    2752         global $bp, $wpdb;
     2844        global $wpdb;
     2845
     2846        $bp = buddypress();
    27532847
    27542848        // Get all the group ids for the current user's groups and update counts
  • trunk/src/bp-groups/bp-groups-filters.php

    r9462 r9471  
    142142 */
    143143function groups_add_forum_tables_sql( $sql = '' ) {
    144     global $bp;
     144    $bp = buddypress();
    145145
    146146    $sql .= 'JOIN ' . $bp->groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id ';
     
    156156 */
    157157function groups_add_forum_where_sql( $sql = '' ) {
    158     global $bp;
    159158
    160159    // Define locale variable
     
    190189    // Assemble Voltron
    191190    $parts_string = implode( ' AND ', $parts );
     191
     192    $bp = buddypress();
    192193
    193194    // Set it to the global filter
     
    207208 */
    208209function groups_filter_bbpress_caps( $value, $cap, $args ) {
    209     global $bp;
    210210
    211211    if ( bp_current_user_can( 'bp_moderate' ) )
    212212        return true;
    213213
    214     if ( 'add_tag_to' == $cap )
    215         if ( $bp->groups->current_group->user_has_access ) return true;
     214    if ( 'add_tag_to' === $cap ) {
     215        $bp = buddypress();
     216
     217        if ( $bp->groups->current_group->user_has_access ) {
     218            return true;
     219        }
     220    }
    216221
    217222    if ( 'manage_forums' == $cap && is_user_logged_in() )
  • trunk/src/bp-groups/bp-groups-functions.php

    r9351 r9471  
    2121 * @since BuddyPress (1.5.0)
    2222 *
    23  * @global BuddyPress $bp The one true BuddyPress instance
    2423 * @return bool True if set, False if empty
    2524 */
    2625function bp_groups_has_directory() {
    27     global $bp;
     26    $bp = buddypress();
    2827
    2928    return (bool) !empty( $bp->pages->groups->id );
     
    301300 */
    302301function groups_is_valid_status( $status ) {
    303     global $bp;
     302    $bp = buddypress();
    304303
    305304    return in_array( $status, (array) $bp->groups->valid_status );
     
    313312 */
    314313function groups_check_slug( $slug ) {
    315     global $bp;
     314    $bp = buddypress();
    316315
    317316    if ( 'wp' == substr( $slug, 0, 2 ) )
     
    365364 */
    366365function groups_leave_group( $group_id, $user_id = 0 ) {
    367     global $bp;
    368366
    369367    if ( empty( $user_id ) )
     
    399397 */
    400398function groups_join_group( $group_id, $user_id = 0 ) {
    401     global $bp;
    402399
    403400    if ( empty( $user_id ) )
     
    427424    if ( !$new_member->save() )
    428425        return false;
     426
     427    $bp = buddypress();
    429428
    430429    if ( !isset( $bp->groups->current_group ) || !$bp->groups->current_group || $group_id != $bp->groups->current_group->id )
     
    705704 */
    706705function groups_get_current_group() {
    707     global $bp;
    708 
    709     $current_group = isset( $bp->groups->current_group ) ? $bp->groups->current_group : false;
     706    $bp = buddypress();
     707
     708    $current_group = isset( $bp->groups->current_group )
     709        ? $bp->groups->current_group
     710        : false;
    710711
    711712    return apply_filters( 'groups_get_current_group', $current_group );
     
    722723 */
    723724function groups_avatar_upload_dir( $group_id = 0 ) {
    724     global $bp;
    725 
    726     if ( !$group_id )
    727         $group_id = $bp->groups->current_group->id;
     725
     726    if ( empty( $group_id ) ) {
     727        $group_id = bp_get_current_group_id();
     728    }
    728729
    729730    $path    = bp_core_avatar_upload_path() . '/group-avatars/' . $group_id;
     
    810811 */
    811812function groups_post_update( $args = '' ) {
    812     global $bp;
     813    $bp = buddypress();
    813814
    814815    $defaults = array(
  • trunk/src/bp-groups/bp-groups-screens.php

    r9351 r9471  
    510510 */
    511511function groups_screen_group_request_membership() {
    512     global $bp;
    513512
    514513    if ( !is_user_logged_in() )
     
    912911 */
    913912function groups_screen_group_admin_delete_group() {
    914     global $bp;
    915913
    916914    if ( 'delete-group' != bp_get_group_current_admin_tab() )
     
    919917    if ( ! bp_is_item_admin() && !bp_current_user_can( 'bp_moderate' ) )
    920918        return false;
     919
     920    $bp = buddypress();
    921921
    922922    if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) {
  • trunk/src/bp-groups/bp-groups-template.php

    r9466 r9471  
    15001500 */
    15011501function bp_group_search_form() {
    1502     global $bp;
    15031502
    15041503    $action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/';
     
    15971596 */
    15981597function bp_groups_auto_join() {
    1599     global $bp;
    1600 
    1601     return apply_filters( 'bp_groups_auto_join', (bool)$bp->groups->auto_join );
     1598    return apply_filters( 'bp_groups_auto_join', (bool) buddypress()->groups->auto_join );
    16021599}
    16031600
     
    18611858 */
    18621859function bp_group_get_invite_status( $group_id = false ) {
    1863     global $bp, $groups_template;
     1860    global $groups_template;
    18641861
    18651862    if ( !$group_id ) {
     1863        $bp = buddypress();
     1864
    18661865        if ( isset( $bp->groups->current_group->id ) ) {
    18671866            // Default to the current group first
     
    25582557     */
    25592558    function bp_get_group_accept_invite_link( $group = false ) {
    2560         global $groups_template, $bp;
     2559        global $groups_template;
    25612560
    25622561        if ( empty( $group ) )
    25632562            $group =& $groups_template->group;
     2563
     2564        $bp = buddypress();
    25642565
    25652566        return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ) );
     
    25802581     */
    25812582    function bp_get_group_reject_invite_link( $group = false ) {
    2582         global $groups_template, $bp;
     2583        global $groups_template;
    25832584
    25842585        if ( empty( $group ) )
    25852586            $group =& $groups_template->group;
     2587
     2588        $bp = buddypress();
    25862589
    25872590        return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ) );
     
    36233626
    36243627function bp_group_creation_tabs() {
    3625     global $bp;
     3628    $bp = buddypress();
    36263629
    36273630    if ( !is_array( $bp->groups->group_creation_steps ) )
     
    36483651
    36493652function bp_group_creation_stage_title() {
    3650     global $bp;
     3653    $bp = buddypress();
    36513654
    36523655    echo apply_filters( 'bp_group_creation_stage_title', '<span>&mdash; ' . $bp->groups->group_creation_steps[bp_get_groups_current_create_step()]['name'] . '</span>' );
     
    36573660}
    36583661    function bp_get_group_creation_form_action() {
    3659         global $bp;
     3662        $bp = buddypress();
    36603663
    36613664        if ( !bp_action_variable( 1 ) ) {
     
    36683671
    36693672function bp_is_group_creation_step( $step_slug ) {
    3670     global $bp;
    36713673
    36723674    /* Make sure we are in the groups component */
    36733675    if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) )
    36743676        return false;
     3677
     3678    $bp = buddypress();
    36753679
    36763680    /* If this the first step, we can just accept and return true */
     
    36933697
    36943698function bp_is_group_creation_step_complete( $step_slugs ) {
    3695     global $bp;
     3699    $bp = buddypress();
    36963700
    36973701    if ( !isset( $bp->groups->completed_create_steps ) )
     
    37153719
    37163720function bp_are_previous_group_creation_steps_complete( $step_slug ) {
    3717     global $bp;
     3721    $bp = buddypress();
    37183722
    37193723    /* If this is the first group creation step, return true */
     
    37403744}
    37413745    function bp_get_new_group_id() {
    3742         global $bp;
     3746        $bp = buddypress();
    37433747
    37443748        if ( isset( $bp->groups->new_group_id ) )
     
    37543758}
    37553759    function bp_get_new_group_name() {
    3756         global $bp;
     3760        $bp = buddypress();
    37573761
    37583762        if ( isset( $bp->groups->current_group->name ) )
     
    37683772}
    37693773    function bp_get_new_group_description() {
    3770         global $bp;
     3774        $bp = buddypress();
    37713775
    37723776        if ( isset( $bp->groups->current_group->description ) )
     
    37823786}
    37833787    function bp_get_new_group_enable_forum() {
    3784         global $bp;
     3788        $bp = buddypress();
     3789
    37853790        return (int) apply_filters( 'bp_get_new_group_enable_forum', $bp->groups->current_group->enable_forum );
    37863791    }
     
    37903795}
    37913796    function bp_get_new_group_status() {
    3792         global $bp;
     3797        $bp = buddypress();
     3798
    37933799        return apply_filters( 'bp_get_new_group_status', $bp->groups->current_group->status );
    37943800    }
     
    37983804}
    37993805    function bp_get_new_group_avatar( $args = '' ) {
    3800         global $bp;
     3806        $bp = buddypress();
    38013807
    38023808        $defaults = array(
     
    38203826}
    38213827    function bp_get_group_creation_previous_link() {
    3822         global $bp;
     3828        $bp = buddypress();
    38233829
    38243830        foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
     
    38493855     */
    38503856    function bp_get_groups_current_create_step() {
    3851         global $bp;
     3857        $bp = buddypress();
    38523858
    38533859        if ( !empty( $bp->groups->current_create_step ) ) {
     
    38613867
    38623868function bp_is_last_group_creation_step() {
    3863     global $bp;
     3869    $bp = buddypress();
    38643870
    38653871    $keys      = array_keys( $bp->groups->group_creation_steps );
     
    38733879
    38743880function bp_is_first_group_creation_step() {
    3875     global $bp;
     3881    $bp = buddypress();
    38763882
    38773883    $keys       = array_keys( $bp->groups->group_creation_steps );
     
    38883894}
    38893895    function bp_get_new_group_invite_friend_list( $args = '' ) {
    3890         global $bp;
     3896        $bp = buddypress();
    38913897
    38923898        if ( !bp_is_active( 'friends' ) )
     
    39453951 */
    39463952function bp_groups_header_tabs() {
    3947     global $bp;?>
     3953    $bp = buddypress(); ?>
    39483954
    39493955    <li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/recently-active' ) ?>"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
     
    40954101}
    40964102    function bp_get_group_avatar_delete_link() {
    4097         global $bp;
     4103        $bp = buddypress();
    40984104
    40994105        return apply_filters( 'bp_get_group_avatar_delete_link', wp_nonce_url( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/group-avatar/delete', 'bp_group_avatar_delete' ) );
  • trunk/src/bp-members/bp-members-adminbar.php

    r9351 r9471  
    2121 */
    2222function bp_members_admin_bar_my_account_menu() {
    23     global $bp, $wp_admin_bar;
     23    global $wp_admin_bar;
    2424
    2525    // Bail if this is an ajax request
     
    2929    // Logged in user
    3030    if ( is_user_logged_in() ) {
     31
     32        $bp = buddypress();
    3133
    3234        // Stored in the global so we can add menus easily later on
     
    7375 */
    7476function bp_members_admin_bar_user_admin_menu() {
    75     global $bp, $wp_admin_bar;
     77    global $wp_admin_bar;
    7678
    7779    // Only show if viewing a user
     
    8284    if ( !current_user_can( 'edit_users' ) || bp_is_my_profile() )
    8385        return false;
     86
     87    $bp = buddypress();
    8488
    8589    // Unique ID for the 'My Account' menu
  • trunk/src/bp-members/bp-members-functions.php

    r9428 r9471  
    2121 */
    2222function bp_members_has_directory() {
    23     global $bp;
     23    $bp = buddypress();
    2424
    2525    return (bool) !empty( $bp->pages->members->id );
  • trunk/src/bp-members/bp-members-screens.php

    r9467 r9471  
    6565 */
    6666function bp_core_screen_signup() {
    67     global $bp;
     67    $bp = buddypress();
    6868
    6969    if ( ! bp_is_current_component( 'register' ) || bp_current_action() )
  • trunk/src/bp-members/bp-members-template.php

    r9455 r9471  
    12981298 */
    12991299function bp_get_loggedin_user_nav() {
    1300     global $bp;
     1300    $bp = buddypress();
    13011301
    13021302    // Loop through each navigation item
     
    13401340 */
    13411341function bp_get_displayed_user_nav() {
    1342     global $bp;
     1342    $bp = buddypress();
    13431343
    13441344    foreach ( (array) $bp->bp_nav as $user_nav_item ) {
     
    14841484     */
    14851485    function bp_get_displayed_user_email() {
    1486         global $bp;
     1486        $bp = buddypress();
    14871487
    14881488        // If displayed user exists, return email address
     
    16461646 */
    16471647function bp_displayed_user_domain() {
    1648     global $bp;
     1648    $bp = buddypress();
    16491649
    16501650    /**
     
    16641664 */
    16651665function bp_loggedin_user_domain() {
    1666     global $bp;
     1666    $bp = buddypress();
    16671667
    16681668    /**
     
    16881688     */
    16891689    function bp_get_displayed_user_fullname() {
    1690         global $bp;
     1690        $bp = buddypress();
    16911691
    16921692        /**
     
    17181718     */
    17191719    function bp_get_loggedin_user_fullname() {
    1720         global $bp;
     1720        $bp = buddypress();
    17211721
    17221722        /**
     
    17421742     */
    17431743    function bp_get_displayed_user_username() {
    1744         global $bp;
     1744        $bp = buddypress();
    17451745
    17461746        if ( bp_displayed_user_id() ) {
     
    17721772     */
    17731773    function bp_get_loggedin_user_username() {
    1774         global $bp;
     1774        $bp = buddypress();
    17751775
    17761776        if ( bp_loggedin_user_id() ) {
     
    20962096     */
    20972097    function bp_get_signup_avatar_dir_value() {
    2098         global $bp;
     2098        $bp = buddypress();
    20992099
    21002100        // Check if signup_avatar_dir is passed
     
    21322132     */
    21332133    function bp_get_current_signup_step() {
    2134         global $bp;
    2135 
    2136         return $bp->signup->step;
     2134        return buddypress()->signup->step;
    21372135    }
    21382136
     
    23032301     */
    23042302    function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
    2305         global $bp;
    23062303
    23072304        // Must be displayed user
    23082305        if ( !bp_displayed_user_id() )
    23092306            return;
     2307
     2308        $bp = buddypress();
    23102309
    23112310        // Append $action to $url if there is no $type
  • trunk/src/bp-messages/bp-messages-classes.php

    r9351 r9471  
    135135     */
    136136    public function populate( $thread_id = 0, $order = 'ASC', $args = array() ) {
    137         global $wpdb, $bp;
     137        global $wpdb;
    138138
    139139        if( 'ASC' != $order && 'DESC' != $order ) {
     
    149149        $this->thread_id      = $thread_id;
    150150
     151        $bp = buddypress();
     152
    151153        if ( !$this->messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent " . $order, $this->thread_id ) ) ) {
    152154            return false;
     
    210212     */
    211213    public function get_recipients() {
    212         global $wpdb, $bp;
     214        global $wpdb;
     215
     216        $bp = buddypress();
    213217
    214218        $recipients = array();
     
    244248     */
    245249    public static function delete( $thread_id ) {
    246         global $wpdb, $bp;
     250        global $wpdb;
    247251
    248252        /**
     
    254258         */
    255259        do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
     260
     261        $bp = buddypress();
    256262
    257263        // Mark messages as deleted
     
    335341     */
    336342    public static function get_current_threads_for_user( $args = array() ) {
    337         global $wpdb, $bp;
     343        global $wpdb;
    338344
    339345        // Backward compatibility with old method of passing arguments
     
    405411        }
    406412
     413        $bp = buddypress();
     414
    407415        // set up SQL array
    408416        $sql = array();
     
    491499     */
    492500    public static function mark_as_read( $thread_id ) {
    493         global $wpdb, $bp;
    494 
     501        global $wpdb;
     502
     503        $bp  = buddypress();
    495504        $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
    496505        $wpdb->query($sql);
     
    507516     */
    508517    public static function mark_as_unread( $thread_id ) {
    509         global $wpdb, $bp;
    510 
     518        global $wpdb;
     519
     520        $bp  = buddypress();
    511521        $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
    512522        $wpdb->query($sql);
     
    528538     */
    529539    public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
    530         global $wpdb, $bp;
     540        global $wpdb;
    531541
    532542        $exclude_sender = '';
     
    539549            $type_sql = " AND unread_count = 0 ";
    540550
     551        $bp = buddypress();
     552
    541553        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender} {$type_sql}", $user_id ) );
    542554    }
     
    551563     */
    552564    public static function user_is_sender( $thread_id ) {
    553         global $wpdb, $bp;
     565        global $wpdb;
     566
     567        $bp = buddypress();
    554568
    555569        $sender_ids = $wpdb->get_col( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     
    571585     */
    572586    public static function get_last_sender( $thread_id ) {
    573         global $wpdb, $bp;
     587        global $wpdb;
     588
     589        $bp = buddypress();
    574590
    575591        if ( ! $sender_id = $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d GROUP BY sender_id ORDER BY date_sent LIMIT 1", $thread_id ) ) ) {
     
    589605     */
    590606    public static function get_inbox_count( $user_id = 0 ) {
    591         global $wpdb, $bp;
     607        global $wpdb;
    592608
    593609        if ( empty( $user_id ) ) {
     
    598614
    599615        if ( false === $unread_count ) {
     616            $bp = buddypress();
     617
    600618            $unread_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $user_id ) );
    601619
     
    624642     */
    625643    public static function check_access( $thread_id, $user_id = 0 ) {
    626         global $wpdb, $bp;
     644        global $wpdb;
    627645
    628646        if ( empty( $user_id ) )
    629647            $user_id = bp_loggedin_user_id();
     648
     649        $bp = buddypress();
    630650
    631651        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ) );
     
    694714     */
    695715    public static function update_tables() {
    696         global $wpdb, $bp;
     716        global $wpdb;
    697717
    698718        $bp_prefix = bp_core_get_table_prefix();
     
    704724            return true;
    705725        }
     726
     727        $bp = buddypress();
    706728
    707729        foreach( (array) $threads as $thread ) {
     
    798820     */
    799821    public function populate( $id ) {
    800         global $wpdb, $bp;
     822        global $wpdb;
     823
     824        $bp = buddypress();
    801825
    802826        if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) {
     
    817841     */
    818842    public function send() {
    819         global $wpdb, $bp;
     843        global $wpdb;
     844
     845        $bp = buddypress();
    820846
    821847        $this->sender_id = apply_filters( 'messages_message_sender_id_before_save', $this->sender_id, $this->id );
     
    891917     */
    892918    public function get_recipients() {
    893         global $bp, $wpdb;
     919        global $wpdb;
     920
     921        $bp = buddypress();
     922
    894923        return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
    895924    }
     
    925954     */
    926955    public static function get_last_sent_for_user( $thread_id ) {
    927         global $wpdb, $bp;
     956        global $wpdb;
     957
     958        $bp = buddypress();
     959
    928960        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
    929961    }
     
    938970     */
    939971    public static function is_user_sender( $user_id, $message_id ) {
    940         global $wpdb, $bp;
     972        global $wpdb;
     973
     974        $bp = buddypress();
     975
    941976        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) );
    942977    }
     
    949984     */
    950985    public static function get_message_sender( $message_id ) {
    951         global $wpdb, $bp;
     986        global $wpdb;
     987
     988        $bp = buddypress();
     989
    952990        return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) );
    953991    }
     
    10181056     */
    10191057    public function populate() {
    1020         global $wpdb, $bp;
     1058        global $wpdb;
     1059
     1060        $bp = buddypress();
    10211061
    10221062        $notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) );
     
    10381078     */
    10391079    public function save() {
    1040         global $wpdb, $bp;
     1080        global $wpdb;
     1081
     1082        $bp = buddypress();
    10411083
    10421084        $this->subject = apply_filters( 'messages_notice_subject_before_save', $this->subject, $this->id );
     
    11171159     */
    11181160    public function delete() {
    1119         global $wpdb, $bp;
     1161        global $wpdb;
    11201162
    11211163        /**
     
    11281170        do_action( 'messages_notice_before_delete', $this );
    11291171
     1172        $bp  = buddypress();
    11301173        $sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id );
    11311174
     
    11541197     */
    11551198    public static function get_notices( $args = array() ) {
    1156         global $wpdb, $bp;
     1199        global $wpdb;
    11571200
    11581201        $r = wp_parse_args( $args, array(
     
    11661209        }
    11671210
     1211        $bp = buddypress();
     1212
    11681213        $notices = $wpdb->get_results( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC {$limit_sql}" );
    11691214
     
    11791224     */
    11801225    public static function get_total_notice_count() {
    1181         global $wpdb, $bp;
    1182 
    1183         $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices );
     1226        global $wpdb;
     1227
     1228        $bp = buddypress();
     1229
     1230        $notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->messages->table_name_notices}" );
    11841231
    11851232        return $notice_count;
     
    11971244
    11981245        if ( false === $notice ) {
    1199             global $wpdb, $bp;
     1246            global $wpdb;
     1247
     1248            $bp = buddypress();
    12001249
    12011250            $notice_id = $wpdb->get_var( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1" );
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r9351 r9471  
    262262 */
    263263function xprofile_admin_manage_field( $group_id, $field_id = null ) {
    264     global $bp, $wpdb, $message, $groups;
     264    global $wpdb, $message, $groups;
     265
     266    $bp = buddypress();
    265267
    266268    $field           = new BP_XProfile_Field( $field_id );
  • trunk/src/bp-xprofile/bp-xprofile-classes.php

    r9351 r9471  
    2525
    2626    public function populate( $id ) {
    27         global $wpdb, $bp;
     27        global $wpdb;
    2828
    2929        $group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' );
    3030
    3131        if ( false === $group ) {
     32            $bp = buddypress();
    3233            $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) );
    3334        }
     
    4546
    4647    public function save() {
    47         global $wpdb, $bp;
     48        global $wpdb;
    4849
    4950        $this->name        = apply_filters( 'xprofile_group_name_before_save',        $this->name,        $this->id );
     
    6061         */
    6162        do_action_ref_array( 'xprofile_group_before_save', array( &$this ) );
     63
     64        $bp = buddypress();
    6265
    6366        if ( $this->id )
     
    8689
    8790    public function delete() {
    88         global $wpdb, $bp;
     91        global $wpdb;
    8992
    9093        if ( empty( $this->can_delete ) )
     
    99102         */
    100103        do_action_ref_array( 'xprofile_group_before_delete', array( &$this ) );
     104
     105        $bp = buddypress();
    101106
    102107        // Delete field group
     
    163168     */
    164169    public static function get( $args = array() ) {
    165         global $wpdb, $bp;
     170        global $wpdb;
    166171
    167172        $defaults = array(
     
    197202        }
    198203
     204        $bp = buddypress();
     205
    199206        if ( ! empty( $hide_empty_groups ) ) {
    200207            $group_ids = $wpdb->get_col( "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" );
     
    416423
    417424    public static function update_position( $field_group_id, $position ) {
    418         global $wpdb, $bp;
     425        global $wpdb;
    419426
    420427        if ( !is_numeric( $position ) ) {
     
    424431        // purge profile field group cache
    425432        wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
     433
     434        $bp = buddypress();
    426435
    427436        return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
     
    481490     */
    482491    public static function fetch_default_visibility_levels() {
    483         global $wpdb, $bp;
     492        global $wpdb;
    484493
    485494        $default_visibility_levels = wp_cache_get( 'xprofile_default_visibility_levels', 'bp' );
    486495
    487496        if ( false === $default_visibility_levels ) {
     497            $bp = buddypress();
     498
    488499            $levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" );
    489500
     
    658669
    659670    public function populate( $id, $user_id, $get_data ) {
    660         global $wpdb, $userdata, $bp;
     671        global $wpdb, $userdata;
    661672
    662673        if ( empty( $user_id ) ) {
     
    664675        }
    665676
     677        $bp  = buddypress();
    666678        $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id );
    667679
     
    699711
    700712    public function delete( $delete_data = false ) {
    701         global $wpdb, $bp;
     713        global $wpdb;
    702714
    703715        // Prevent deletion if no ID is present
     
    707719            return false;
    708720
     721        $bp = buddypress();
     722
    709723        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
    710724            return false;
     
    718732
    719733    public function save() {
    720         global $wpdb, $bp;
     734        global $wpdb;
     735
     736        $bp = buddypress();
    721737
    722738        $this->group_id    = apply_filters( 'xprofile_field_group_id_before_save',    $this->group_id,    $this->id );
     
    857873
    858874    public function get_children( $for_editing = false ) {
    859         global $wpdb, $bp;
     875        global $wpdb;
    860876
    861877        // This is done here so we don't have problems with sql injection
     
    875891        }
    876892
     893        $bp  = buddypress();
    877894        $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );
    878895
     
    891908
    892909    public function delete_children() {
    893         global $wpdb, $bp;
    894 
     910        global $wpdb;
     911
     912        $bp  = buddypress();
    895913        $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE parent_id = %d", $this->id );
    896914
     
    901919
    902920    public static function get_type( $field_id ) {
    903         global $wpdb, $bp;
     921        global $wpdb;
    904922
    905923        if ( !empty( $field_id ) ) {
     924            $bp  = buddypress();
    906925            $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
    907926
     
    917936
    918937    public static function delete_for_group( $group_id ) {
    919         global $wpdb, $bp;
     938        global $wpdb;
    920939
    921940        if ( !empty( $group_id ) ) {
     941            $bp  = buddypress();
    922942            $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
    923943
     
    933953
    934954    public static function get_id_from_name( $field_name ) {
    935         global $wpdb, $bp;
     955        global $wpdb;
     956
     957        $bp = buddypress();
    936958
    937959        if ( empty( $bp->profile->table_name_fields ) || !isset( $field_name ) )
     
    942964
    943965    public static function update_position( $field_id, $position, $field_group_id ) {
    944         global $wpdb, $bp;
     966        global $wpdb;
    945967
    946968        if ( !is_numeric( $position ) || !is_numeric( $field_group_id ) )
    947969            return false;
     970
     971        $bp = buddypress();
    948972
    949973        // Update $field_id with new $position and $field_group_id
     
    12211245
    12221246    public function populate( $field_id, $user_id )  {
    1223         global $wpdb, $bp;
     1247        global $wpdb;
    12241248
    12251249        $cache_key   = "{$user_id}:{$field_id}";
     
    12271251
    12281252        if ( false === $profiledata ) {
     1253            $bp = buddypress();
     1254
    12291255            $sql         = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
    12301256            $profiledata = $wpdb->get_row( $sql );
     
    12571283     */
    12581284    public function exists() {
    1259         global $wpdb, $bp;
     1285        global $wpdb;
    12601286
    12611287        // Check cache first
     
    12661292            $retval = true;
    12671293        } else {
     1294            $bp = buddypress();
    12681295            $retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id ) );
    12691296        }
     
    12841311     *
    12851312     * @global object $wpdb
    1286      * @global array $bp
    12871313     * @return bool
    12881314     */
    12891315    public function is_valid_field() {
    1290         global $wpdb, $bp;
     1316        global $wpdb;
     1317
     1318        $bp = buddypress();
    12911319
    12921320        $retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ) );
     
    13041332
    13051333    public function save() {
    1306         global $wpdb, $bp;
     1334        global $wpdb;
     1335
     1336        $bp = buddypress();
    13071337
    13081338        $this->user_id      = apply_filters( 'xprofile_data_user_id_before_save',      $this->user_id,         $this->id );
     
    15091539     */
    15101540    public static function get_fielddataid_byid( $field_id, $user_id ) {
    1511         global $wpdb, $bp;
     1541        global $wpdb;
    15121542
    15131543        if ( empty( $field_id ) || empty( $user_id ) ) {
    15141544            $fielddata_id = 0;
    15151545        } else {
     1546            $bp = buddypress();
    15161547
    15171548            // Check cache first
     
    15391570     */
    15401571    public static function get_value_byid( $field_id, $user_ids = null ) {
    1541         global $wpdb, $bp;
     1572        global $wpdb;
    15421573
    15431574        if ( empty( $user_ids ) ) {
     
    15621593        // Prime caches
    15631594        if ( ! empty( $uncached_ids ) ) {
     1595            $bp = buddypress();
    15641596            $uncached_ids_sql = implode( ',', $uncached_ids );
    15651597            $queried_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$uncached_ids_sql})", $field_id ) );
     
    16101642
    16111643    public static function get_value_byfieldname( $fields, $user_id = null ) {
    1612         global $bp, $wpdb;
     1644        global $wpdb;
    16131645
    16141646        if ( empty( $fields ) )
    16151647            return false;
     1648
     1649        $bp = buddypress();
    16161650
    16171651        if ( empty( $user_id ) )
     
    16591693
    16601694    public static function delete_for_field( $field_id ) {
    1661         global $wpdb, $bp;
     1695        global $wpdb;
     1696
     1697        $bp = buddypress();
    16621698
    16631699        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) )
     
    16681704
    16691705    public static function get_last_updated( $user_id ) {
    1670         global $wpdb, $bp;
     1706        global $wpdb;
     1707
     1708        $bp = buddypress();
    16711709
    16721710        $last_updated = $wpdb->get_var( $wpdb->prepare( "SELECT last_updated FROM {$bp->profile->table_name_data} WHERE user_id = %d ORDER BY last_updated LIMIT 1", $user_id ) );
     
    16761714
    16771715    public static function delete_data_for_user( $user_id ) {
    1678         global $wpdb, $bp;
     1716        global $wpdb;
     1717
     1718        $bp = buddypress();
    16791719
    16801720        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );
     
    16821722
    16831723    public static function get_random( $user_id, $exclude_fullname ) {
    1684         global $wpdb, $bp;
     1724        global $wpdb;
    16851725
    16861726        $exclude_sql = ! empty( $exclude_fullname ) ? ' AND pf.id != 1' : '';
     1727
     1728        $bp = buddypress();
    16871729
    16881730        return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM {$bp->profile->table_name_data} pd INNER JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) );
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r9351 r9471  
    218218 */
    219219function xprofile_insert_field( $args = '' ) {
    220     global $bp;
    221220
    222221    $r = wp_parse_args( $args, array(
     
    240239
    241240    // Check this is a valid field type
    242     if ( ! in_array( $r['type'], (array) $bp->profile->field_types ) ) {
     241    if ( ! in_array( $r['type'], (array) buddypress()->profile->field_types ) ) {
    243242        return false;
    244243    }
     
    10221021 */
    10231022function bp_xprofile_get_visibility_levels() {
    1024     global $bp;
    10251023
    10261024    /**
     
    10311029     * @param array $visibility_levels Array of visibility levels.
    10321030     */
    1033     return apply_filters( 'bp_xprofile_get_visibility_levels', $bp->profile->visibility_levels );
     1031    return apply_filters( 'bp_xprofile_get_visibility_levels', buddypress()->profile->visibility_levels );
    10341032}
    10351033
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r9351 r9471  
    370370}
    371371    function bp_get_the_profile_group_edit_form_action() {
    372         global $bp, $group;
     372        global $group;
     373
     374        $bp = buddypress();
    373375
    374376        /**
     
    845847 */
    846848function bp_profile_group_tabs() {
    847     global $bp, $group_name;
    848 
     849    global $group_name;
     850
     851    $bp     = buddypress();
    849852    $groups = bp_profile_get_field_groups();
    850853
     
    967970}
    968971    function bp_get_avatar_delete_link() {
    969         global $bp;
     972        $bp = buddypress();
    970973
    971974        /**
     
    980983
    981984function bp_edit_profile_button() {
    982     global $bp;
     985    $bp = buddypress();
    983986
    984987    bp_button( array (
  • trunk/tests/phpunit/includes/testcase.php

    r9282 r9471  
    328328     * user during tests. BP caches the current user differently, so we
    329329     * have to do a bit more work to change it
    330      *
    331      * @global BuddyPres $bp
    332330     */
    333331    public static function set_current_user( $user_id ) {
    334         global $bp;
     332        $bp = buddypress();
     333
    335334        $bp->loggedin_user->id = $user_id;
    336335        $bp->loggedin_user->fullname       = bp_core_get_user_displayname( $user_id );
  • trunk/tests/phpunit/testcases/activity/template.php

    r9417 r9471  
    2222     */
    2323    public function test_user_can_delete() {
    24         global $bp;
     24        $bp = buddypress();
    2525
    2626        $a = $this->factory->activity->create( array(
     
    134134            'action' => 'activity_update',
    135135        ) );
    136 
    137         global $wpdb, $bp;
    138136
    139137        $ids = wp_list_pluck( $activities_template->activities, 'id' );
  • trunk/tests/phpunit/testcases/core/cache.php

    r8958 r9471  
    1414
    1515        // Confirm that all activitymeta is deleted
    16         global $wpdb, $bp;
     16        global $wpdb;
     17
     18        $bp = buddypress();
     19
    1720        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $a1 ) );
    1821
  • trunk/tests/phpunit/testcases/groups/functions.php

    r9139 r9471  
    442442
    443443        // Get rid of any auto-created values
    444         global $wpdb, $bp;
     444        global $wpdb;
     445
     446        $bp = buddypress();
    445447        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_groupmeta} WHERE group_id = %d", $g ) );
    446448        wp_cache_delete( $g, 'group_meta' );
  • trunk/tests/phpunit/testcases/members/functions.php

    r9398 r9471  
    172172     */
    173173    public function test_bp_core_get_user_displayname_xprofile_does_not_exist() {
     174        $bp = buddypress();
    174175        $xprofile_is_active = bp_is_active( 'xprofile' );
    175         buddypress()->active_components['xprofile'] = '1';
     176        $bp->active_components['xprofile'] = '1';
    176177
    177178        $u = $this->factory->user->create( array(
     
    181182        // Delete directly because BP won't let you delete a required
    182183        // field through the API
    183         global $wpdb, $bp;
     184        global $wpdb;
    184185        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u ) );
    185186        wp_cache_delete( 'bp_user_fullname_' . $u, 'bp' );
     
    191192
    192193        if ( ! $xprofile_is_active ) {
    193             unset( buddypress()->active_components['xprofile'] );
     194            unset( $bp->active_components['xprofile'] );
    194195        }
    195196    }
     
    233234        // Delete directly because BP won't let you delete a required
    234235        // field through the API
    235         global $wpdb, $bp;
     236        global $wpdb;
     237        $bp = buddypress();
    236238        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u2 ) );
    237239        wp_cache_delete( 'bp_user_fullname_' . $u2, 'bp' );
     
    378380
    379381        // Create an existing entry in last_activity to test no dupes
    380         global $wpdb, $bp;
     382        global $wpdb;
     383        $bp = buddypress();
    381384        $wpdb->query( $wpdb->prepare(
    382385            "INSERT INTO {$bp->members->table_name_last_activity}
Note: See TracChangeset for help on using the changeset viewer.