Skip to:
Content

BuddyPress.org

Changeset 3395


Ignore:
Timestamp:
11/11/2010 07:15:01 AM (16 years ago)
Author:
johnjamesjacoby
Message:

Fixes #1236 (branch) props swinton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-xprofile/bp-xprofile-classes.php

    r3390 r3395  
    694694                if ( $profiledata = $wpdb->get_row($sql) ) {
    695695
    696                         $this->id = $profiledata->id;
    697                         $this->user_id = $profiledata->user_id;
    698                         $this->field_id = $profiledata->field_id;
    699                         $this->value = stripslashes($profiledata->value);
     696                        $this->id           = $profiledata->id;
     697                        $this->user_id      = $profiledata->user_id;
     698                        $this->field_id     = $profiledata->field_id;
     699                        $this->value        = stripslashes($profiledata->value);
    700700                        $this->last_updated = $profiledata->last_updated;
    701701                }
    702702        }
    703703
     704        /**
     705         * exists ()
     706         *
     707         * Check if there is data already for the user.
     708         *
     709         * @global object $wpdb
     710         * @global array $bp
     711         * @return bool
     712         */
    704713        function exists() {
    705714                global $wpdb, $bp;
    706715
    707                 // check to see if there is data already for the user.
    708                 $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id );
    709 
    710                 if ( !$wpdb->get_row($sql) )
    711                         return false;
    712 
    713                 return true;
    714         }
    715 
     716
     717                $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 ) );
     718
     719                return apply_filters( 'xprofile_data_exists', (bool)$retval, $this );
     720        }
     721
     722        /**
     723         * is_valid_field()
     724         *
     725         * Check if this data is for a valid field.
     726         *
     727         * @global object $wpdb
     728         * @global array $bp
     729         * @return bool
     730         */
    716731        function is_valid_field() {
    717732                global $wpdb, $bp;
    718733
    719                 // check to see if this data is actually for a valid field.
    720                 $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
    721 
    722                 if ( !$wpdb->get_row($sql) )
    723                         return false;
    724 
    725                 return true;
     734                $retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ) );
     735
     736                return apply_filters( 'xprofile_data_is_valid_field', (bool)$retval, $this );
    726737        }
    727738
     
    729740                global $wpdb, $bp;
    730741
    731                 $this->user_id = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id );
    732                 $this->field_id = apply_filters( 'xprofile_data_field_id_before_save', $this->field_id, $this->id );
    733                 $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id );
     742                $this->user_id      = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id );
     743                $this->field_id     = apply_filters( 'xprofile_data_field_id_before_save', $this->field_id, $this->id );
     744                $this->value        = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id );
    734745                $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id );
    735746
     
    737748
    738749                if ( $this->is_valid_field() ) {
    739                         if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) ) {
     750                        if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) )
    740751                                $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_data} SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id ) );
    741                         } else if ( $this->exists() && empty( $this->value ) ) {
    742                                 // Data removed, delete the entry.
     752
     753                        // Data removed, delete the entry.
     754                        elseif ( $this->exists() && empty( $this->value ) )                             
    743755                                $result = $this->delete();
    744                         } else {
     756
     757                        else
    745758                                $result = $wpdb->query( $wpdb->prepare("INSERT INTO {$bp->profile->table_name_data} (user_id, field_id, value, last_updated) VALUES (%d, %d, %s, %s)", $this->user_id, $this->field_id, $this->value, $this->last_updated ) );
    746                         }
    747759
    748760                        if ( !$result )
Note: See TracChangeset for help on using the changeset viewer.