Changeset 53751
- Timestamp:
- 07/21/2022 06:01:01 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/vendor/plupload/handlers.js
r51947 r53751 487 487 times = tryAgainCount[ file.id ]; 488 488 489 if ( times && times > 4) {489 if ( times && times > ) { 490 490 /* 491 491 * The file may have been uploaded and attachment post created, -
trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js
r51227 r53751 139 139 times = tryAgainCount[ file.id ]; 140 140 141 if ( times && times > 4) {141 if ( times && times > ) { 142 142 /* 143 143 * The file may have been uploaded and attachment post created, -
trunk/src/wp-admin/includes/image.php
r53547 r53751 78 78 * 79 79 * @since 5.3.0 80 * 81 * @param int $attachment_id The image attachment post ID. 80 * @since 6.1.0 The $mime_type parameter was added. 81 * 82 * @param int $attachment_id The image attachment post ID. 83 * @param string $mime_type Optional. The mime type to check for missing sizes. Default is the primary image mime. 82 84 * @return array[] Associative array of arrays of image sub-size information for 83 85 * missing image sizes, keyed by image size name. 84 86 */ 85 function wp_get_missing_image_subsizes( $attachment_id ) {87 function wp_get_missing_image_subsizes( $attachment_id ) { 86 88 if ( ! wp_attachment_is_image( $attachment_id ) ) { 87 89 return array(); 90 91 92 93 94 88 95 } 89 96 … … 130 137 * as the image may have been used in an older post. 131 138 */ 132 $missing_sizes = array_diff_key( $possible_sizes, $image_meta['sizes'] ); 139 $missing_sizes = array(); 140 foreach ( $possible_sizes as $size_name => $size_data ) { 141 if ( ! isset( $image_meta['sizes'][ $size_name ] ) ) { 142 $missing_sizes[ $size_name ] = $size_data; 143 continue; 144 } 145 146 if ( ( isset( $size_data['mime-type'] ) && $size_data['mime-type'] === $mime_type ) || isset( $size_data['sources'][ $mime_type ] ) ) { 147 continue; 148 } 149 150 $missing_sizes[ $size_name ] = $size_data; 151 } 152 153 // Filter secondary mime types to those sizes that are enabled. 154 if ( $primary_mime_type !== $mime_type ) { 155 $missing_sizes = _wp_filter_image_sizes_additional_mime_type_support( $missing_sizes, $attachment_id ); 156 } 133 157 134 158 /** … … 136 160 * 137 161 * @since 5.3.0 162 138 163 * 139 164 * @param array[] $missing_sizes Associative array of arrays of image sub-size information for … … 141 166 * @param array $image_meta The image meta data. 142 167 * @param int $attachment_id The image attachment post ID. 168 143 169 */ 144 return apply_filters( 'wp_get_missing_image_subsizes', $missing_sizes, $image_meta, $attachment_id );170 return apply_filters( 'wp_get_missing_image_subsizes', $missing_sizes, $image_meta, $attachment_id ); 145 171 } 146 172 … … 150 176 * 151 177 * @since 5.3.0 178 152 179 * 153 180 * @param int $attachment_id The image attachment post ID. … … 168 195 } 169 196 } else { 170 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); 171 172 if ( empty( $missing_sizes ) ) { 173 return $image_meta; 174 } 175 176 // This also updates the image meta. 177 $image_meta = _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); 197 // Get the primary and additional mime types to generate. 198 list( $primary_mime_type, $additional_mime_types ) = _wp_get_primary_and_additional_mime_types( $image_file, $attachment_id ); 199 200 // Generate missing 'full' image files for additional mime types. 201 if ( ! empty( $additional_mime_types ) ) { 202 if ( isset( $image_meta['sources'] ) ) { 203 $missing_mime_types = array_diff( $additional_mime_types, array_keys( $image_meta['sources'] ) ); 204 } else { 205 $missing_mime_types = $additional_mime_types; 206 } 207 if ( ! empty( $missing_mime_types ) ) { 208 $image_meta = _wp_make_additional_mime_types( $missing_mime_types, $image_file, $image_meta, $attachment_id ); 209 } 210 } 211 212 // Generate missing image sub-sizes for each mime type. 213 $all_mime_types = array_merge( array( $primary_mime_type ), $additional_mime_types ); 214 foreach ( $all_mime_types as $mime_type ) { 215 $missing_sizes = wp_get_missing_image_subsizes( $attachment_id, $mime_type ); 216 217 if ( empty( $missing_sizes ) ) { 218 continue; 219 } 220 221 // This also updates the image meta. 222 $image_meta = _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id, $mime_type ); 223 } 178 224 } 179 225 … … 223 269 224 270 /** 225 * Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.271 * Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata. 226 272 * 227 273 * Intended for use after an image is uploaded. Saves/updates the image metadata after each … … 229 275 * 230 276 * @since 5.3.0 277 231 278 * 232 279 * @param string $file Full path to the image file. … … 249 296 'filesize' => wp_filesize( $file ), 250 297 'sizes' => array(), 298 251 299 ); 252 300 … … 258 306 } 259 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 260 412 // Do not scale (large) PNG images. May result in sub-sizes that have greater file size than the original. See #48736. 261 if ( 'image/png' !== $imagesize['mime'] ) { 262 413 if ( 'image/png' !== $mime_type ) { 263 414 /** 264 415 * Filters the "BIG image" threshold value. … … 286 437 // If the original image's dimensions are over the threshold, 287 438 // scale the image and use it as the "full" size. 288 if ( $threshold && ( $image_meta['width'] > $threshold || $image_meta['height'] > $threshold ) ) { 289 $editor = wp_get_image_editor( $file ); 290 291 if ( is_wp_error( $editor ) ) { 292 // This image cannot be edited. 293 return $image_meta; 294 } 295 439 if ( $threshold && ( $imagesize[0] > $threshold || $imagesize[1] > $threshold ) ) { 296 440 // Resize the image. 297 441 $resized = $editor->resize( $threshold, $threshold ); 298 $rotated = null;299 442 300 443 // If there is EXIF data, rotate according to EXIF Orientation. 301 444 if ( ! is_wp_error( $resized ) && is_array( $exif_meta ) ) { 302 $resized = $editor->maybe_exif_rotate(); 303 $rotated = $resized; 304 } 305 306 if ( ! is_wp_error( $resized ) ) { 307 // Append "-scaled" to the image file name. It will look like "my_image-scaled.jpg". 308 // This doesn't affect the sub-sizes names as they are generated from the original image (for best quality). 309 $saved = $editor->save( $editor->generate_filename( 'scaled' ) ); 310 311 if ( ! is_wp_error( $saved ) ) { 312 $image_meta = _wp_image_meta_replace_original( $saved, $file, $image_meta, $attachment_id ); 313 314 // If the image was rotated update the stored EXIF data. 315 if ( true === $rotated && ! empty( $image_meta['image_meta']['orientation'] ) ) { 316 $image_meta['image_meta']['orientation'] = 1; 317 } 318 } else { 319 // TODO: Log errors. 320 } 321 } else { 322 // TODO: Log errors. 445 $rotated = $editor->maybe_exif_rotate(); 323 446 } 324 447 } elseif ( ! empty( $exif_meta['orientation'] ) && 1 !== (int) $exif_meta['orientation'] ) { 325 448 // Rotate the whole original image if there is EXIF data and "orientation" is not 1. 326 327 $editor = wp_get_image_editor( $file );328 329 if ( is_wp_error( $editor ) ) {330 // This image cannot be edited.331 return $image_meta;332 }333 334 // Rotate the image.335 449 $rotated = $editor->maybe_exif_rotate(); 336 337 if ( true === $rotated ) { 338 // Append `-rotated` to the image file name. 339 $saved = $editor->save( $editor->generate_filename( 'rotated' ) ); 340 341 if ( ! is_wp_error( $saved ) ) { 342 $image_meta = _wp_image_meta_replace_original( $saved, $file, $image_meta, $attachment_id ); 343 344 // Update the stored EXIF data. 345 if ( ! empty( $image_meta['image_meta']['orientation'] ) ) { 346 $image_meta['image_meta']['orientation'] = 1; 347 } 348 } else { 349 // TODO: Log errors. 350 } 351 } 352 } 353 } 354 355 /* 356 * Initial save of the new metadata. 357 * At this point the file was uploaded and moved to the uploads directory 358 * but the image sub-sizes haven't been created yet and the `sizes` array is empty. 359 */ 360 wp_update_attachment_metadata( $attachment_id, $image_meta ); 361 362 $new_sizes = wp_get_registered_image_subsizes(); 363 364 /** 365 * Filters the image sizes automatically generated when uploading an image. 366 * 367 * @since 2.9.0 368 * @since 4.4.0 Added the `$image_meta` argument. 369 * @since 5.3.0 Added the `$attachment_id` argument. 370 * 371 * @param array $new_sizes Associative array of image sizes to be created. 372 * @param array $image_meta The image meta data: width, height, file, sizes, etc. 373 * @param int $attachment_id The attachment post ID for the image. 374 */ 375 $new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id ); 376 377 return _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ); 450 } 451 } 452 453 return array( $editor, $resized, $rotated ); 454 } 455 456 /** 457 * Gets the suffix to use for image files based on resizing and rotating. 458 * 459 * @since 6.1.0 460 * @access private 461 * 462 * @param bool|WP_Error Whether the image was resized, or an error if resizing failed. 463 * @param bool|WP_Error Whether the image was rotated, or an error if rotating failed. 464 * @return string The suffix to use for the file name, or empty string if none. 465 */ 466 function _wp_get_image_suffix( $resized, $rotated ) { 467 if ( $resized && ! is_wp_error( $resized ) ) { 468 // Append "-scaled" to the image file name. It will look like "my_image-scaled.jpg". 469 // This doesn't affect the sub-sizes names as they are generated from the original image (for best quality). 470 return 'scaled'; 471 } 472 473 if ( true === $rotated ) { 474 // Append `-rotated` to the image file name. 475 return 'rotated'; 476 } 477 478 if ( is_wp_error( $resized ) || is_wp_error( $rotated ) ) { 479 // TODO: Log errors. 480 } 481 return ''; 482 } 483 484 /** 485 * Gets a sources array element from a meta. 486 * 487 * @since 6.1.0 488 * @access private 489 * 490 * @param array $meta The meta to get the source from. 491 * @return array The source array element. 492 */ 493 function _wp_get_sources_from_meta( $meta ) { 494 return array( 495 'file' => isset( $meta['file'] ) ? wp_basename( $meta['file'] ) : '', 496 'filesize' => isset( $meta['filesize'] ) ? $meta['filesize'] : wp_filesize( $meta['path'] ), 497 ); 378 498 } 379 499 … … 385 505 * 386 506 * @since 5.3.0 507 387 508 * @access private 388 509 * 389 * @param array $new_sizes Array defining what sizes to create. 390 * @param string $file Full path to the image file. 391 * @param array $image_meta The attachment meta data array. 392 * @param int $attachment_id Attachment ID to process. 510 * @param array $new_sizes Array defining what sizes to create. 511 * @param string $file Full path to the image file. 512 * @param array $image_meta The attachment meta data array. 513 * @param int $attachment_id Attachment ID to process. 514 * @param string $mime_type Optional. The mime type to check for missing sizes. Default is the image mime of $file. 393 515 * @return array The attachment meta data with updated `sizes` array. Includes an array of errors encountered while resizing. 394 516 */ 395 function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) {517 function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) { 396 518 if ( empty( $image_meta ) || ! is_array( $image_meta ) ) { 397 519 // Not an image attachment. 398 520 return array(); 521 522 523 524 399 525 } 400 526 … … 408 534 */ 409 535 if ( array_key_exists( $size_name, $new_sizes ) ) { 410 unset( $new_sizes[ $size_name ] ); 536 // Unset the size if it is either the required mime type already exists either as main mime type or 537 // within sources. 538 if ( $size_meta['mime-type'] === $mime_type || isset( $size_meta['sources'][ $mime_type ] ) ) { 539 unset( $new_sizes[ $size_name ] ); 540 } 411 541 } 412 542 } … … 434 564 $new_sizes = array_filter( array_merge( $priority, $new_sizes ) ); 435 565 436 $editor = wp_get_image_editor( $file );566 $editor = wp_get_image_editor( $file ); 437 567 438 568 if ( is_wp_error( $editor ) ) { … … 440 570 return $image_meta; 441 571 } 572 573 442 574 443 575 // If stored EXIF data exists, rotate the source image before creating sub-sizes. … … 458 590 } else { 459 591 // Save the size meta value. 460 $image_meta['sizes'][ $new_size_name ] = $new_size_meta; 592 if ( ! isset( $image_meta['sizes'][ $new_size_name ] ) ) { 593 $image_meta['sizes'][ $new_size_name ] = $new_size_meta; 594 } else { 595 // Remove any newly generated images that are larger than the primary mime type. 596 $new_size = isset( $new_size_meta['filesize'] ) ? $new_size_meta['filesize'] : 0; 597 $primary_size = isset( $image_meta['sizes'][ $new_size_name ]['filesize'] ) ? $image_meta['sizes'][ $new_size_name ]['filesize'] : 0; 598 599 if ( $new_size && $primary_size && $new_size >= $primary_size ) { 600 wp_delete_file( dirname( $file ) . '/' . $new_size_meta['file'] ); 601 continue; 602 } 603 } 604 if ( ! isset( $image_meta['sizes'][ $new_size_name ]['sources'] ) ) { 605 $image_meta['sizes'][ $new_size_name ]['sources'] = array(); 606 } 607 $image_meta['sizes'][ $new_size_name ]['sources'][ $mime_type ] = _wp_get_sources_from_meta( $new_size_meta ); 461 608 wp_update_attachment_metadata( $attachment_id, $image_meta ); 462 609 } … … 467 614 468 615 if ( ! empty( $created_sizes ) ) { 469 $image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes ); 616 foreach ( $created_sizes as $created_size_name => $created_size_meta ) { 617 618 // Primary mime type is set in 'sizes' array. 619 if ( ! isset( $image_meta['sizes'][ $created_size_name ] ) ) { 620 $image_meta['sizes'][ $created_size_name ] = $created_size_meta; 621 } else { 622 // Remove any newly generated images that are larger than the primary mime type. 623 $new_size = isset( $created_size_meta['filesize'] ) ? $created_size_meta['filesize'] : 0; 624 $primary_size = isset( $image_meta['sizes'][ $created_size_name ]['filesize'] ) ? $image_meta['sizes'][ $created_size_name ]['filesize'] : 0; 625 626 if ( $new_size && $primary_size && $new_size >= $primary_size ) { 627 wp_delete_file( dirname( $file ) . '/' . $created_size_meta['file'] ); 628 continue; 629 } 630 } 631 if ( ! isset( $image_meta['sizes'][ $created_size_name ]['sources'] ) ) { 632 $image_meta['sizes'][ $created_size_name ]['sources'] = array(); 633 } 634 $image_meta['sizes'][ $created_size_name ]['sources'][ $mime_type ] = _wp_get_sources_from_meta( $new_size_meta ); 635 } 470 636 wp_update_attachment_metadata( $attachment_id, $image_meta ); 471 637 } … … 473 639 474 640 return $image_meta; 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 475 760 } 476 761 … … 631 916 632 917 // Create sub-sizes saving the image meta after each. 633 $metadata = _wp_make_subsizes( $merged_sizes, $image_file, $metadata, $attachment_id );918 $metadata = _wp_make_subsizes( $merged_sizes, $image_file, $metadata, $attachment_id ); 634 919 } 635 920 } … … 1158 1443 return $dst_file; 1159 1444 } 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 -
trunk/src/wp-includes/class-wp-image-editor.php
r53547 r53751 334 334 protected function get_output_format( $filename = null, $mime_type = null ) { 335 335 $new_ext = null; 336 337 338 339 340 336 341 337 342 // By default, assume specified type takes priority. … … 426 431 427 432 /** 428 * Builds an output filename based on current file, and adding proper suffix 429 * 430 * @since 3.5.0 431 * 432 * @param string $suffix 433 * @param string $dest_path 434 * @param string $extension 435 * @return string filename 433 * Builds an output filename based on current file, and adding proper suffix. 434 * 435 * @since 3.5.0 436 * @since 6.1.0 Skips adding a suffix when set to an empty string. When the 437 * file extension being generated doesn't match the image file extension, 438 * add the extension to the suffix 439 * 440 * @param string $suffix Optional. Suffix to add to the filename. The default null 441 * will result in a 'widthxheight' suffix. Passing 442 * an empty string will result in no suffix. 443 * @param string $dest_path Optional. The path to save the file to. The default null 444 * will use the image file path. 445 * @param string $extension Optional. The file extension to use. The default null 446 * will use the image file extension. 447 * @return string filename The generated file name. 436 448 */ 437 449 public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 438 450 // $suffix will be appended to the destination filename, just before the extension. 439 if ( !$suffix ) {451 if ( $suffix ) { 440 452 $suffix = $this->get_suffix(); 441 453 } … … 458 470 } 459 471 460 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 472 if ( empty( $suffix ) ) { 473 $suffix = ''; 474 } else { 475 $suffix = "-{$suffix}"; 476 } 477 478 // When the file extension being generated doesn't match the image file extension, 479 // add the extension to the suffix to ensure a unique file name. Prevents 480 // name conflicts when a single image type can have multiple extensions, 481 // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions. 482 if ( ! empty( $extension ) && $extension !== $ext ) { 483 $suffix .= "-{$ext}"; 484 } 485 486 return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; 461 487 } 462 488 … … 638 664 return wp_get_default_extension_for_mime_type( $mime_type ); 639 665 } 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 640 690 } 641 -
trunk/src/wp-includes/media.php
r53715 r53751 1853 1853 } 1854 1854 1855 1856 1857 1858 1859 1855 1860 /** 1856 1861 * Filters an img tag within the content for a given context. … … 1897 1902 1898 1903 return $content; 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 1899 2015 } 1900 2016 -
trunk/src/wp-includes/post.php
r53723 r53751 6482 6482 6483 6483 foreach ( $meta['sizes'] as $size => $sizeinfo ) { 6484 $intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file ); 6485 6486 if ( ! empty( $intermediate_file ) ) { 6487 $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); 6488 6489 if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { 6490 $deleted = false; 6484 6485 // Check for alternate size mime types in the sizeinfo['sources'] array to delete. 6486 if ( isset( $sizeinfo['sources'] ) && is_array( $sizeinfo['sources'] ) ) { 6487 foreach ( $sizeinfo['sources'] as $mime => $properties ) { 6488 $intermediate_file = str_replace( wp_basename( $file ), $properties['file'], $file ); 6489 if ( ! empty( $intermediate_file ) ) { 6490 $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); 6491 if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { 6492 $deleted = false; 6493 } 6494 } 6495 } 6496 } else { 6497 // Otherwise, delete files from the sizeinfo data. 6498 $intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file ); 6499 6500 if ( ! empty( $intermediate_file ) ) { 6501 $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); 6502 6503 if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { 6504 $deleted = false; 6505 } 6491 6506 } 6492 6507 } … … 6510 6525 } 6511 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6512 6546 if ( is_array( $backup_sizes ) ) { 6547 6513 6548 $del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) ); 6514 6549 // Delete the root (edited) file which was not deleted above. 6550 if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) { 6551 $deleted = false; 6552 } 6515 6553 foreach ( $backup_sizes as $size ) { 6516 $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); 6517 6518 if ( ! empty( $del_file ) ) { 6519 $del_file = path_join( $uploadpath['basedir'], $del_file ); 6520 6521 if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { 6522 $deleted = false; 6554 // Delete files from 'sources' data if available, otherwise from 'sizes' data. 6555 if ( isset( $meta['sources'] ) && is_array( $meta['sources'] ) ) { 6556 // Delete any backup images stored in the 'sources' array. 6557 if ( isset( $size['sources'] ) && is_array( $size['sources'] ) ) { 6558 foreach ( $size['sources'] as $mime => $properties ) { 6559 $del_file = path_join( dirname( $meta['file'] ), $properties['file'] ); 6560 if ( ! empty( $del_file ) ) { 6561 $del_file = path_join( $uploadpath['basedir'], $del_file ); 6562 if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { 6563 $deleted = false; 6564 } 6565 } 6566 } 6567 } 6568 } else { 6569 $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); 6570 6571 if ( ! empty( $del_file ) ) { 6572 $del_file = path_join( $uploadpath['basedir'], $del_file ); 6573 if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { 6574 $deleted = false; 6575 } 6523 6576 } 6524 6577 } 6525 6578 } 6526 }6527 6528 if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) {6529 $deleted = false;6530 6579 } 6531 6580 -
trunk/tests/phpunit/tests/image/editor.php
r52248 r53751 132 132 133 133 // Removing PNG to WEBP conversion on save. Quality setting should reset to the default. 134 134 135 remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) ); 135 136 $editor->save(); … … 155 156 156 157 // After removing the conversion the quality setting should reset to the filtered value for the original image type, JPEG. 158 157 159 remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) ); 158 160 $editor->save(); … … 227 229 228 230 // Test with a suffix only. 229 $this->assertSame( 'canola-100x50 .png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );231 $this->assertSame( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); 230 232 231 233 // Combo! 232 $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new .png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );234 $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); 233 235 234 236 // Test with a stream destination. … … 363 365 } 364 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 365 767 } -
trunk/tests/phpunit/tests/image/functions.php
r53542 r53751 640 640 } 641 641 642 643 644 642 645 $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf'; 643 646 $test_file = get_temp_dir() . 'wordpress-gsoc-flyer.pdf'; … … 678 681 'mime-type' => 'image/jpeg', 679 682 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-232x300.jpg' ), 683 684 685 686 687 688 680 689 ), 681 690 'large' => array( … … 685 694 'mime-type' => 'image/jpeg', 686 695 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-791x1024.jpg' ), 696 697 698 699 700 701 687 702 ), 688 703 'thumbnail' => array( … … 692 707 'mime-type' => 'image/jpeg', 693 708 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-116x150.jpg' ), 709 710 711 712 713 714 694 715 ), 695 716 ), … … 703 724 unlink( $temp_dir . $size['file'] ); 704 725 } 726 705 727 } 706 728 … … 716 738 717 739 update_option( 'medium_crop', 1 ); 740 741 742 718 743 719 744 $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf'; … … 755 780 'mime-type' => 'image/jpeg', 756 781 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-300x300.jpg' ), 782 783 784 785 786 787 757 788 ), 758 789 'large' => array( … … 762 793 'mime-type' => 'image/jpeg', 763 794 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-791x1024.jpg' ), 795 796 797 798 799 800 801 764 802 ), 765 803 'thumbnail' => array( … … 769 807 'mime-type' => 'image/jpeg', 770 808 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-116x150.jpg' ), 809 810 811 812 813 814 771 815 ), 772 816 ), … … 780 824 unlink( $temp_dir . $size['file'] ); 781 825 } 826 827 782 828 } 783 829 … … 789 835 $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); 790 836 } 837 838 839 791 840 792 841 $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf'; … … 822 871 'mime-type' => 'image/jpeg', 823 872 'filesize' => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-77x100.jpg' ), 873 874 875 876 877 878 824 879 ); 825 880 … … 837 892 unlink( $temp_dir . $size['file'] ); 838 893 } 894 839 895 } 840 896 … … 1027 1083 ); 1028 1084 } 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1029 1512 } -
trunk/tests/phpunit/tests/media.php
r53558 r53751 2252 2252 add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2253 2253 add_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2254 2254 2255 2255 2256 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); … … 2257 2258 remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2258 2259 remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2260 2261 2259 2262 } 2260 2263 … … 2290 2293 $img = wp_img_tag_add_decoding_attr( $img, 'the_content' ); 2291 2294 $img = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $img ); 2295 2292 2296 2293 2297 // The content filter should return the image unchanged. 2294 2298 $this->assertSame( $img, wp_filter_content_tags( $img ) ); 2299 2300 2295 2301 } 2296 2302 … … 2362 2368 add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2363 2369 add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' ); 2370 2364 2371 2365 2372 add_filter( … … 2424 2431 */ 2425 2432 public function test_wp_filter_content_tags_schemes() { 2433 2426 2434 $image_meta = wp_get_attachment_metadata( self::$large_id ); 2427 2435 $size_array = $this->get_image_size_array_from_meta( $image_meta, 'medium' ); … … 2469 2477 2470 2478 $this->assertSame( $expected, $actual ); 2479 2471 2480 } 2472 2481 … … 2962 2971 add_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2963 2972 add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2973 2964 2974 2965 2975 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); … … 2967 2977 remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2968 2978 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2979 2969 2980 } 2970 2981 … … 3042 3053 add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 3043 3054 add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 3055 3044 3056 3045 3057 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); … … 3047 3059 remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 3048 3060 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 3061 3049 3062 } 3050 3063 … … 3075 3088 add_filter( 'wp_lazy_loading_enabled', '__return_true' ); 3076 3089 3090 3091 3077 3092 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); 3078 3093 remove_filter( 'wp_lazy_loading_enabled', '__return_true' ); 3079 3094 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 3095 3096 3080 3097 } 3081 3098 … … 3102 3119 add_filter( 'wp_lazy_loading_enabled', '__return_false' ); 3103 3120 3121 3122 3104 3123 $this->assertSame( $content, wp_filter_content_tags( $content ) ); 3105 3124 remove_filter( 'wp_lazy_loading_enabled', '__return_false' ); 3106 3125 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 3126 3107 3127 } 3108 3128 … … 3530 3550 function test_wp_filter_content_tags_with_wp_get_loading_attr_default() { 3531 3551 global $wp_query, $wp_the_query; 3552 3532 3553 3533 3554 $img1 = get_image_tag( self::$large_id, '', '', '', 'large' ); … … 3565 3586 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 3566 3587 } 3588 3567 3589 3568 3590 // After filtering, the first image should not be lazy-loaded while the other ones should be. … … 3614 3636 remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 ); 3615 3637 } 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3616 3801 } 3617 3802
Note: See TracChangeset
for help on using the changeset viewer.