Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/10/2015 02:49:16 AM (12 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-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 ) );
Note: See TracChangeset for help on using the changeset viewer.