Skip to:
Content

BuddyPress.org

Changeset 9677


Ignore:
Timestamp:
04/01/2015 11:56:35 PM (5 years ago)
Author:
johnjamesjacoby
Message:

XProfile: Improvements to BP_XProfile_Group

  • Use self::get() in populate() to inherit caching goodness
  • Improve failure detection in save() method, also checking for empty $wpdb->query()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r9676 r9677  
    8080     */
    8181    public function populate( $id ) {
    82         global $wpdb;
    83 
    84         $group = wp_cache_get( $id, 'bp_xprofile_groups' );
    85 
    86         if ( false === $group ) {
    87             $bp    = buddypress();
    88             $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) );
    89             wp_cache_set( $id, $group, 'bp_xprofile_groups' );
    90         }
    91 
     82
     83        // Get this group
     84        $group = self::get( array(
     85            'profile_group_id' => $id
     86        ) );
     87
     88        // Bail if group not found
    9289        if ( empty( $group ) ) {
    9390            return false;
    9491        }
    9592
     93        // Get the first array element
     94        $group = reset( $group );
     95
     96        // Set object properties
    9697        $this->id          = $group->id;
    9798        $this->name        = $group->name;
     
    129130        $bp = buddypress();
    130131
     132        // Update or insert
    131133        if ( ! empty( $this->id ) ) {
    132134            $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
     
    135137        }
    136138
     139        // Attempt to insert or update
     140        $query = $wpdb->query( $sql );
     141
    137142        // Bail if query fails
    138         if ( is_wp_error( $wpdb->query( $sql ) ) ) {
     143        if ( empty( $query ) || is_wp_error( $query ) ) {
    139144            return false;
    140145        }
Note: See TracChangeset for help on using the changeset viewer.