Ticket #4636: 4636.patch
File 4636.patch, 4.1 KB (added by , 12 years ago) |
---|
-
bp-xprofile/bp-xprofile-functions.php
199 199 * @param $value The value for the field you want to set for the user. 200 200 * @global BuddyPress $bp The one true BuddyPress instance 201 201 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name. 202 * @return true on success, falseon failure.202 * @return true on success, WP_Error on failure. 203 203 */ 204 204 function xprofile_set_field_data( $field, $user_id, $value, $is_required = false ) { 205 205 … … 209 209 $field_id = xprofile_get_field_id_from_name( $field ); 210 210 211 211 if ( empty( $field_id ) ) 212 return false;212 return new WP_Error( 'empty_field_id', __( 'Could not find profile field ID given field name', 'buddypress' ) ); 213 213 214 214 if ( $is_required && ( empty( $value ) || !is_array( $value ) && !strlen( trim( $value ) ) ) ) 215 return false;215 return new WP_Error( 'empty_required_field', __( 'Required field must have a value', 'buddypress' ) ); 216 216 217 217 $field = new BP_XProfile_Field( $field_id ); 218 218 … … 243 243 $value = array_merge( array(), $value ); 244 244 } else { 245 245 if ( !in_array( $value, $possible_values ) ) { 246 return false;246 return new WP_Error( 'value_not_in_possible_values', __( 'Field value entered is not in possible values', 'buddypress' ) ); 247 247 } 248 248 } 249 249 } 250 250 251 $field = new BP_XProfile_ProfileData();252 $field->field_id = $field_id;253 $field->user_id = $user_id;254 $field->value 251 $field = new BP_XProfile_ProfileData( $field_id, $user_id ); 252 if ( $field->exists() && $value == $field->value ) 253 return new WP_Error( 'same_value', __( 'Field value entered is the same as the current value', 'buddypress' ) ); 254 $field->value = maybe_serialize( $value ); 255 255 256 256 return $field->save(); 257 257 } -
bp-xprofile/bp-xprofile-classes.php
1030 1030 return apply_filters_ref_array( 'xprofile_data_is_valid_field', array( (bool)$retval, $this ) ); 1031 1031 } 1032 1032 1033 /** 1034 * save() 1035 * 1036 * Save the profile field data to the database. 1037 * 1038 * @global object $wpdb 1039 * @global object $bp 1040 * @return true on success, WP_Error on failure 1041 */ 1033 1042 function save() { 1034 1043 global $wpdb, $bp; 1035 1044 … … 1054 1063 } 1055 1064 1056 1065 if ( false === $result ) 1057 return false;1066 return new WP_Error( 'db_error', __( 'Could not update or insert profile data into the database', 'buddypress' ), $wpdb->last_error ); 1058 1067 1059 1068 do_action_ref_array( 'xprofile_data_after_save', array( $this ) ); 1060 1069 1070 if ( bp_is_active( 'activity' ) ) { 1071 $field = new BP_XProfile_Field( $this->id, $this->user_id, false ); 1072 bp_activity_add( array( 'action' => sprintf( __( '%s edited %s on their profile', 'buddypress' ), bp_core_get_userlink( $this->user_id ), $field->name ), 1073 'component' => 'xprofile', 'primary_link' => bp_loggedin_user_domain() . BP_XPROFILE_SLUG, 'type' => 'profile_updated', 'item_id' => $this->id ) ); 1074 } 1075 1061 1076 return true; 1062 1077 } 1063 1078 1064 return false;1079 return new WP_Error( 'invalid_field', __( 'The field ID is invalid', 'buddypress' ) ); 1065 1080 } 1066 1081 1067 1082 function delete() { -
bp-xprofile/bp-xprofile-screens.php
111 111 $value = $_POST['field_' . $field_id]; 112 112 } 113 113 114 if ( !xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[$field_id] ) ) { 114 $saved = xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[$field_id] ); 115 if ( is_wp_error( $saved ) && $saved->get_error_code() != 'same_value' ) { 115 116 $errors = true; 116 } else {117 } else if ( is_bool( $saved ) && $saved ) { 117 118 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 118 119 } 119 120