Changeset 52932
- Timestamp:
- 03/14/2022 04:30:35 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/file.php
r52837 r52932 2556 2556 return false; 2557 2557 } 2558 2559 /**2560 * Wrapper for PHP filesize with filters and casting the result as an integer.2561 *2562 * @since 6.0.02563 *2564 * @link https://www.php.net/manual/en/function.filesize.php2565 *2566 * @param string $path Path to the file.2567 * @return int The size of the file in bytes, or 0 in the event of an error.2568 */2569 function wp_filesize( $path ) {2570 /**2571 * Filters the result of wp_filesize before the PHP function is run.2572 *2573 * @since 6.0.02574 *2575 * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.2576 * @param string $path Path to the file.2577 */2578 $size = apply_filters( 'pre_wp_filesize', null, $path );2579 2580 if ( is_int( $size ) ) {2581 return $size;2582 }2583 2584 $size = (int) @filesize( $path );2585 2586 /**2587 * Filters the size of the file.2588 *2589 * @since 6.0.02590 *2591 * @param int $size The result of PHP filesize on the file.2592 * @param string $path Path to the file.2593 */2594 return (int) apply_filters( 'wp_filesize', $size, $path );2595 } -
trunk/src/wp-includes/functions.php
r52929 r52932 3460 3460 3461 3461 /** 3462 * Wrapper for PHP filesize with filters and casting the result as an integer. 3463 * 3464 * @since 6.0.0 3465 * 3466 * @link https://www.php.net/manual/en/function.filesize.php 3467 * 3468 * @param string $path Path to the file. 3469 * @return int The size of the file in bytes, or 0 in the event of an error. 3470 */ 3471 function wp_filesize( $path ) { 3472 /** 3473 * Filters the result of wp_filesize before the PHP function is run. 3474 * 3475 * @since 6.0.0 3476 * 3477 * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call. 3478 * @param string $path Path to the file. 3479 */ 3480 $size = apply_filters( 'pre_wp_filesize', null, $path ); 3481 3482 if ( is_int( $size ) ) { 3483 return $size; 3484 } 3485 3486 $size = (int) @filesize( $path ); 3487 3488 /** 3489 * Filters the size of the file. 3490 * 3491 * @since 6.0.0 3492 * 3493 * @param int $size The result of PHP filesize on the file. 3494 * @param string $path Path to the file. 3495 */ 3496 return (int) apply_filters( 'wp_filesize', $size, $path ); 3497 } 3498 3499 /** 3462 3500 * Retrieve list of allowed mime types and file extensions. 3463 3501 * -
trunk/tests/phpunit/tests/file.php
r52837 r52932 263 263 return $keys; 264 264 } 265 266 /**267 * @ticket 49412268 * @covers ::wp_filesize269 */270 function test_wp_filesize_with_nonexistent_file() {271 $file = 'nonexistent/file.jpg';272 $this->assertEquals( 0, wp_filesize( $file ) );273 }274 275 /**276 * @ticket 49412277 * @covers ::wp_filesize278 */279 function test_wp_filesize() {280 $file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';281 282 $this->assertEquals( filesize( $file ), wp_filesize( $file ) );283 284 $filter = function() {285 return 999;286 };287 288 add_filter( 'wp_filesize', $filter );289 290 $this->assertEquals( 999, wp_filesize( $file ) );291 292 $pre_filter = function() {293 return 111;294 };295 296 add_filter( 'pre_wp_filesize', $pre_filter );297 298 $this->assertEquals( 111, wp_filesize( $file ) );299 }300 265 } -
trunk/tests/phpunit/tests/functions.php
r52328 r52932 2107 2107 $this->assertFalse( wp_get_default_extension_for_mime_type( null ), 'false not returned when null as mime type supplied' ); 2108 2108 } 2109 2110 /** 2111 * @ticket 49412 2112 * @covers ::wp_filesize 2113 */ 2114 function test_wp_filesize_with_nonexistent_file() { 2115 $file = 'nonexistent/file.jpg'; 2116 $this->assertEquals( 0, wp_filesize( $file ) ); 2117 } 2118 2119 /** 2120 * @ticket 49412 2121 * @covers ::wp_filesize 2122 */ 2123 function test_wp_filesize() { 2124 $file = DIR_TESTDATA . '/images/test-image-upside-down.jpg'; 2125 2126 $this->assertEquals( filesize( $file ), wp_filesize( $file ) ); 2127 2128 $filter = function() { 2129 return 999; 2130 }; 2131 2132 add_filter( 'wp_filesize', $filter ); 2133 2134 $this->assertEquals( 999, wp_filesize( $file ) ); 2135 2136 $pre_filter = function() { 2137 return 111; 2138 }; 2139 2140 add_filter( 'pre_wp_filesize', $pre_filter ); 2141 2142 $this->assertEquals( 111, wp_filesize( $file ) ); 2143 } 2109 2144 }
Note: See TracChangeset
for help on using the changeset viewer.