Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/13/2022 12:16:46 PM (20 months ago)
Author:
imath
Message:

Media: add support for the .webp image file type

NB: this support will only be available when the community site uses WP >= 5.8.

Props dcavins

Fixes #8643

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-attachments.php

    r13263 r13315  
    157157 *
    158158 * @since 2.4.0
     159 * @since 11.0.0 Adds the support for .webp images to Avatars and Cover images.
    159160 *
    160161 * @param string $type The extension types to get.
     
    164165function bp_attachments_get_allowed_types( $type = 'avatar' ) {
    165166    // 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 ) {
    174174        // Reset the default exts.
    175         $exts = array();
     175        $exts    = array();
     176        $wp_exts = wp_get_ext_types();
    176177
    177178        if ( 'video' === $type ) {
     
    690691            'crunching'                 => __( 'Crunching…', 'buddypress' ),
    691692            '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' ),
    692694
    693695            /* translators: %s: File name. */
     
    778780    if ( ! empty( $args['max_file_size'] ) ) {
    779781        $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;
    780791    }
    781792
Note: See TracChangeset for help on using the changeset viewer.