Changeset 3395 for branches/1.2/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 11/11/2010 07:15:01 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/bp-xprofile/bp-xprofile-classes.php
r3390 r3395 694 694 if ( $profiledata = $wpdb->get_row($sql) ) { 695 695 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); 700 700 $this->last_updated = $profiledata->last_updated; 701 701 } 702 702 } 703 703 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 */ 704 713 function exists() { 705 714 global $wpdb, $bp; 706 715 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 */ 716 731 function is_valid_field() { 717 732 global $wpdb, $bp; 718 733 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 ); 726 737 } 727 738 … … 729 740 global $wpdb, $bp; 730 741 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 ); 734 745 $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id ); 735 746 … … 737 748 738 749 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 ) ) ) 740 751 $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 ) ) 743 755 $result = $this->delete(); 744 } else { 756 757 else 745 758 $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 }747 759 748 760 if ( !$result )
Note: See TracChangeset
for help on using the changeset viewer.