| 328 | | // TODO |
| 329 | | if ( empty( $_POST['skip-cropping'] ) ) { |
| 330 | | $crop_ratio = (float) $_POST['crop_ratio']; |
| 331 | | $crop_data = $this->convert_coordinates_from_resized_to_full( $_POST['crop-x'], $_POST['crop-y'], $_POST['crop-w'], $_POST['crop-h'], $crop_ratio ); |
| 332 | | $cropped = wp_crop_image( $attachment_id, $crop_data['crop_x'], $crop_data['crop_y'], $crop_data['crop_width'], $crop_data['crop_height'], $this->min_size, $this->min_size ); |
| 333 | | } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { |
| 334 | | $cropped = _copy_image_file( $attachment_id ); |
| 335 | | } else { |
| 336 | | $cropped = get_attached_file( $attachment_id ); |
| 337 | | } |
| | 326 | /* |
| | 327 | * If the current attachment as been set as site icon don't delete it. |
| | 328 | */ |
| | 329 | if ( $current_site_icon_id != $attachment_id ) { |
| | 330 | // Delete any existing site icon images. |
| | 331 | $this->delete_site_icon(); |
| 343 | | $object = $this->create_attachment_object( $cropped, $attachment_id ); |
| | 334 | // TODO |
| | 335 | if ( empty( $_POST['skip-cropping'] ) ) { |
| | 336 | $crop_ratio = (float) $_POST['crop_ratio']; |
| | 337 | $crop_data = $this->convert_coordinates_from_resized_to_full( |
| | 338 | $_POST['crop-x'], |
| | 339 | $_POST['crop-y'], |
| | 340 | $_POST['crop-w'], |
| | 341 | $_POST['crop-h'], |
| | 342 | $crop_ratio |
| | 343 | ); |
| | 344 | $cropped = wp_crop_image( |
| | 345 | $attachment_id, |
| | 346 | $crop_data['crop_x'], |
| | 347 | $crop_data['crop_y'], |
| | 348 | $crop_data['crop_width'], |
| | 349 | $crop_data['crop_height'], |
| | 350 | $this->min_size, |
| | 351 | $this->min_size |
| | 352 | ); |
| | 353 | } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { |
| | 354 | $cropped = _copy_image_file( $attachment_id ); |
| | 355 | } else { |
| | 356 | $cropped = get_attached_file( $attachment_id ); |
| | 357 | } |
| | 369 | // Update the attachment |
| | 370 | add_filter( 'intermediate_image_sizes_advanced', array( $this, 'additional_sizes' ) ); |
| | 371 | $attachment_id = $this->insert_attachment( $object, $cropped ); |
| | 372 | remove_filter( 'intermediate_image_sizes_advanced', array( $this, 'additional_sizes' ) ); |
| | 373 | |
| | 374 | // Save the site_icon data into option |
| | 375 | update_option( 'site_icon', $attachment_id ); |
| | 376 | |
| | 377 | } else { |
| | 378 | |
| | 379 | // Get the file path |
| | 380 | $image_url = get_attached_file( $attachment_id ); |
| | 381 | |
| | 382 | // Update meta-data and possibly regenerate intermediate sizes |
| | 383 | add_filter( 'intermediate_image_sizes_advanced', array( $this, 'additional_sizes' ) ); |
| | 384 | $this->update_attachment_metadata( $attachment_id, $image_url ); |
| | 385 | remove_filter( 'intermediate_image_sizes_advanced', array( $this, 'additional_sizes' ) ); |
| | 386 | } |
| | 387 | |
| | 534 | $updated = $this->update_attachment_metadata( $attachment_id, $image_url ); |
| | 535 | if ( false !== $updated ) { |
| | 536 | return $attachment_id; |
| | 537 | } |
| | 538 | |
| | 539 | return false; |
| | 540 | } |
| | 541 | |
| | 542 | /** |
| | 543 | * Update the metadata of an attachment |
| | 544 | * |
| | 545 | * @since 4.3.0 |
| | 546 | * |
| | 547 | * @param int $attachment_id Attachment ID |
| | 548 | * @param string $image_url Cropped image URL. |
| | 549 | * |
| | 550 | * @return bool|int |
| | 551 | */ |
| | 552 | public function update_attachment_metadata( $attachment_id, $image_url ) { |
| | 553 | $metadata = wp_generate_attachment_metadata( $attachment_id, $image_url ); |
| | 554 | |