- Timestamp:
- 12/11/2021 12:00:16 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment-avatar.php
r12588 r13175 200 200 * 201 201 * @param array $args Array of arguments for the cropping. 202 * @return array The cropped avatars (full and thumb).202 * @return array The cropped avatars (full, thumb and the timestamp). 203 203 */ 204 204 public function crop( $args = array() ) { … … 256 256 /** 257 257 * Check that the new avatar doesn't have the same name as the 258 * old one before deleting258 * old one before moving the previous one into history. 259 259 */ 260 260 if ( ! empty( $existing_avatar ) && $existing_avatar !== $this->url . $relative_path ) { 261 bp_core_delete_existing_avatar( array( 'object' => $args['object'], 'item_id' => $args['item_id'], 'avatar_path' => $avatar_folder_dir ) ); 261 // Add a new revision for the existing avatar. 262 $avatars = bp_attachments_list_directory_files( $avatar_folder_dir ); 263 264 if ( $avatars ) { 265 foreach ( $avatars as $avatar_file ) { 266 if ( ! isset( $avatar_file->name, $avatar_file->id, $avatar_file->path ) ) { 267 continue; 268 } 269 270 $is_full = preg_match( "/-bpfull/", $avatar_file->name ); 271 $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name ); 272 273 if ( $is_full || $is_thumb ) { 274 $revision = $this->add_revision( 275 'avatar', 276 array( 277 'file_abspath' => $avatar_file->path, 278 'file_id' => $avatar_file->id, 279 ) 280 ); 281 282 if ( is_wp_error( $revision ) ) { 283 error_log( $revision->get_error_message() ); 284 } 285 } 286 } 287 } 262 288 } 263 289 … … 273 299 // Get the file extension. 274 300 $data = @getimagesize( $absolute_path ); 275 $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';301 $ext = $data['mime'] === 'image/png' ? 'png' : 'jpg'; 276 302 277 303 $args['original_file'] = $absolute_path; 278 304 $args['src_abs'] = false; 279 $avatar_types = array( 'full' => '', 'thumb' => '' ); 305 306 $avatar_types = array( 307 'full' => '', 308 'thumb' => '', 309 ); 310 $timestamp = bp_core_current_time( true, 'timestamp' ); 280 311 281 312 foreach ( $avatar_types as $key_type => $type ) { … … 288 319 } 289 320 290 $filename = wp_unique_filename( $avatar_folder_dir, uniqid(). "-bp{$key_type}.{$ext}" );321 $filename = wp_unique_filename( $avatar_folder_dir, $timestamp . "-bp{$key_type}.{$ext}" ); 291 322 $args['dst_file'] = $avatar_folder_dir . '/' . $filename; 292 323 … … 297 328 @unlink( $absolute_path ); 298 329 299 // Return the full and thumb cropped avatars. 300 return $avatar_types; 330 // Return the full, thumb cropped avatars and the timestamp. 331 return array_merge( 332 $avatar_types, 333 array( 334 'timestamp' => $timestamp, 335 ) 336 ); 301 337 } 302 338 … … 383 419 3 => __( 'There was a problem deleting your profile photo. Please try again.', 'buddypress' ), 384 420 4 => __( 'Your profile photo was deleted successfully!', 'buddypress' ), 421 5 => __( 'Your profile photo was recycled successfully!', 'buddypress' ), 422 6 => __( 'The profile photo was permanently deleted successfully!', 'buddypress' ), 385 423 ); 386 424 } elseif ( ! empty( $group_id ) ) { … … 401 439 3 => __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 402 440 4 => __( 'The group profile photo was deleted successfully!', 'buddypress' ), 441 5 => __( 'The group profile photo was recycled successfully!', 'buddypress' ), 442 6 => __( 'The group profile photo was permanently deleted successfully!', 'buddypress' ), 403 443 ); 404 444 } else {
Note: See TracChangeset
for help on using the changeset viewer.