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-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 ) );
Note: See TracChangeset for help on using the changeset viewer.