Changeset 61980
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r61841 r61980 233 233 $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, $files['file']['type'] ?? null ); 234 234 235 // When the client handles image processing (generate_sub_sizes is false), 236 // skip the server-side image editor support check. 237 if ( false === $request['generate_sub_sizes'] ) { 238 $prevent_unsupported_uploads = false; 239 } 240 235 241 // If the upload is an image, check if the server can handle the mime type. 236 242 if ( … … 279 285 280 286 // Handle generate_sub_sizes parameter. 281 if ( isset( $request['generate_sub_sizes'] ) && !$request['generate_sub_sizes'] ) {287 if ( false === $request['generate_sub_sizes'] ) { 282 288 add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array', 100 ); 283 289 add_filter( 'fallback_intermediate_image_sizes', '__return_empty_array', 100 ); -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r61947 r61980 2931 2931 2932 2932 /** 2933 * Test that unsupported image type check is skipped when not generating sub-sizes. 2934 * 2935 * When the client handles image processing (generate_sub_sizes is false), 2936 * the server should not check image editor support. 2937 * 2938 * Tests the permissions check directly with file params set, since the core 2939 * check uses get_file_params() which is only populated for multipart uploads. 2940 * 2941 * @ticket 64836 2942 */ 2943 public function test_upload_unsupported_image_type_skipped_when_not_generating_sub_sizes() { 2944 wp_set_current_user( self::$author_id ); 2945 2946 add_filter( 'wp_image_editors', '__return_empty_array' ); 2947 2948 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 2949 $request->set_file_params( 2950 array( 2951 'file' => array( 2952 'name' => 'avif-lossy.avif', 2953 'type' => 'image/avif', 2954 'tmp_name' => self::$test_avif_file, 2955 'error' => 0, 2956 'size' => filesize( self::$test_avif_file ), 2957 ), 2958 ) 2959 ); 2960 $request->set_param( 'generate_sub_sizes', false ); 2961 2962 $controller = new WP_REST_Attachments_Controller( 'attachment' ); 2963 $result = $controller->create_item_permissions_check( $request ); 2964 2965 // Should pass because generate_sub_sizes is false (client handles processing). 2966 $this->assertTrue( $result ); 2967 } 2968 2969 /** 2970 * Test that unsupported image type check is enforced when generating sub-sizes. 2971 * 2972 * When the server handles image processing (generate_sub_sizes is true), 2973 * the server should still check image editor support. 2974 * 2975 * Tests the permissions check directly with file params set, since the core 2976 * check uses get_file_params() which is only populated for multipart uploads. 2977 * 2978 * @ticket 64836 2979 */ 2980 public function test_upload_unsupported_image_type_enforced_when_generating_sub_sizes() { 2981 wp_set_current_user( self::$author_id ); 2982 2983 add_filter( 'wp_image_editors', '__return_empty_array' ); 2984 2985 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 2986 $request->set_file_params( 2987 array( 2988 'file' => array( 2989 'name' => 'avif-lossy.avif', 2990 'type' => 'image/avif', 2991 'tmp_name' => self::$test_avif_file, 2992 'error' => 0, 2993 'size' => filesize( self::$test_avif_file ), 2994 ), 2995 ) 2996 ); 2997 2998 $controller = new WP_REST_Attachments_Controller( 'attachment' ); 2999 $result = $controller->create_item_permissions_check( $request ); 3000 3001 // Should fail because the server needs to generate sub-sizes but can't. 3002 $this->assertWPError( $result ); 3003 $this->assertSame( 'rest_upload_image_type_not_supported', $result->get_error_code() ); 3004 } 3005 3006 /** 2933 3007 * Test that uploading an SVG image doesn't throw a `rest_upload_image_type_not_supported` error. 2934 3008 *
Note: See TracChangeset
for help on using the changeset viewer.