Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/10/2015 02:49:16 AM (10 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.