Changeset 13315
- Timestamp:
- 08/13/2022 12:16:46 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-attachments.php
r13263 r13315 157 157 * 158 158 * @since 2.4.0 159 * @since 11.0.0 Adds the support for .webp images to Avatars and Cover images. 159 160 * 160 161 * @param string $type The extension types to get. … … 164 165 function bp_attachments_get_allowed_types( $type = 'avatar' ) { 165 166 // Defaults to BuddyPress supported image extensions. 166 $exts = array( 'jpeg', 'gif', 'png' ); 167 $wp_exts = wp_get_ext_types(); 168 169 /** 170 * It's not a BuddyPress feature, get the allowed extensions 171 * matching the $type requested. 172 */ 173 if ( 'avatar' !== $type && 'cover_image' !== $type ) { 167 $exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 168 if ( bp_is_running_wp( '5.8.0', '>=' ) ) { 169 $exts[] = 'webp'; 170 } 171 172 // Avatar and cover image are images. 173 if ( 'image' !== $type && 'avatar' !== $type && 'cover_image' !== $type ) { 174 174 // Reset the default exts. 175 $exts = array(); 175 $exts = array(); 176 $wp_exts = wp_get_ext_types(); 176 177 177 178 if ( 'video' === $type ) { … … 690 691 'crunching' => __( 'Crunching…', 'buddypress' ), 691 692 'unique_file_warning' => __( 'Make sure to upload a unique file', 'buddypress' ), 693 'noneditable_image' => __( 'This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.', 'buddypress' ), 692 694 693 695 /* translators: %s: File name. */ … … 778 780 if ( ! empty( $args['max_file_size'] ) ) { 779 781 $defaults['filters']['max_file_size'] = $args['max_file_size'] . 'b'; 782 } 783 784 if ( isset( $args['mime_types'] ) && $args['mime_types'] ) { 785 $defaults['filters']['mime_types'] = array( array( 'extensions' => $args['mime_types'] ) ); 786 } 787 788 // Check if WebP images can be edited. 789 if ( bp_is_running_wp( '5.8.0', '>=' ) && ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { 790 $defaults['webp_upload_error'] = true; 780 791 } 781 792 -
trunk/src/bp-core/classes/class-bp-attachment-avatar.php
r13215 r13315 399 399 // Get default script data. 400 400 $script_data = parent::script_data(); 401 402 // Adds the list of supported image types. 403 $script_data['mime_types'] = implode( ',', bp_core_get_allowed_avatar_types() ); 401 404 402 405 // Defaults to Avatar Backbone script. -
trunk/src/bp-core/classes/class-bp-attachment-cover-image.php
r12602 r13315 196 196 // Get default script data. 197 197 $script_data = parent::script_data(); 198 199 // Adds the list of supported image types. 200 $script_data['mime_types'] = implode( ',', bp_attachments_get_allowed_types( 'cover_image' ) ); 198 201 199 202 if ( bp_is_user() ) { -
trunk/src/bp-core/classes/class-bp-attachment.php
r13175 r13315 494 494 } 495 495 496 /** 497 * WordPress image supported types. 498 * @see wp_attachment_is() 499 */ 500 $supported_image_types = array( 501 'jpg' => 1, 502 'jpeg' => 1, 503 'jpe' => 1, 504 'gif' => 1, 505 'png' => 1, 506 ); 496 // Set supported image types. 497 $supported_image_types = array_fill_keys( bp_attachments_get_allowed_types( 'image' ), 1 ); 507 498 508 499 foreach ( $check_types as $file ) { -
trunk/src/bp-core/js/bp-plupload.js
r13152 r13315 160 160 // Ignore failed uploads. 161 161 if ( plupload.FAILED === file.status ) { 162 return; 163 } 164 165 if ( file.type === 'image/webp' && uploader.settings.webp_upload_error ) { 166 // Disallow uploading of WebP images if the server cannot edit them. 167 $( self ).trigger( 'bp-uploader-warning', self.strings.noneditable_image ); 168 uploader.removeFile( file ); 162 169 return; 163 170 } -
trunk/tests/phpunit/testcases/core/avatars.php
r13314 r13315 258 258 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 259 259 260 $this->assertEquals( array( 'jp eg', 'gif', 'png' ), bp_core_get_allowed_avatar_types() );260 $this->assertEquals( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() ); 261 261 262 262 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); … … 264 264 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 265 265 266 $this->assertEquals( array( ' gif', 'png' ), bp_core_get_allowed_avatar_types() );266 $this->assertEquals( array( 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() ); 267 267 268 268 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); … … 270 270 add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 271 271 272 $this->assertEquals( array( 'jp eg', 'gif', 'png' ), bp_core_get_allowed_avatar_types() );272 $this->assertEquals( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() ); 273 273 274 274 remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); … … 282 282 $mimes = bp_core_get_allowed_avatar_mimes(); 283 283 284 $this->assertEqualSets( array( 'jp eg', 'gif', 'png', 'jpg' ), array_keys( $mimes ) );285 $this->assertEqualSets( array( 'image/jpeg', 'image/ gif', 'image/png', 'image/jpeg' ), array_values( $mimes ) );284 $this->assertEqualSets( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), array_keys( $mimes ) ); 285 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( $mimes ) ); 286 286 287 287 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 288 288 289 $this->assertEqualSets( array( 'image/jpeg', 'image/ gif', 'image/png', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) );289 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 290 290 291 291 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); … … 293 293 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 294 294 295 $this->assertEqualSets( array( 'image/ gif', 'image/png' ), array_values( bp_core_get_allowed_avatar_mimes() ) );295 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 296 296 297 297 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); … … 299 299 add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 300 300 301 $this->assertEqualSets( array( 'image/jpeg', 'image/ gif', 'image/png', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) );301 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 302 302 303 303 remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); -
trunk/tests/phpunit/testcases/core/functions.php
r13314 r13315 785 785 */ 786 786 public function test_bp_attachments_get_allowed_types() { 787 $supported = array( 'jp eg', 'gif', 'png' );787 $supported = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); 788 788 789 789 $avatar = bp_attachments_get_allowed_types( 'avatar' );
Note: See TracChangeset
for help on using the changeset viewer.