Skip to:
Content

BuddyPress.org

Ticket #8643: 8643.patch

File 8643.patch, 5.8 KB (added by imath, 4 years ago)
  • src/bp-core/bp-core-attachments.php

    diff --git src/bp-core/bp-core-attachments.php src/bp-core/bp-core-attachments.php
    index 8a4c1dab2..7be6f1a17 100644
    function bp_attachments_get_max_upload_file_size( $type = '' ) {  
    156156 * Get allowed types for any attachment.
    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.
    161162 *                     Default: 'avatar'.
    function bp_attachments_get_max_upload_file_size( $type = '' ) {  
    163164 */
    164165function bp_attachments_get_allowed_types( $type = 'avatar' ) {
    165166        // Defaults to BuddyPress supported image extensions.
    166         $exts    = array( 'jpeg', 'gif', 'png' );
     167        $exts    = array( 'jpeg', 'gif', 'png', 'webp' );
    167168        $wp_exts = wp_get_ext_types();
    168169
    169170        /**
    function bp_attachments_get_plupload_l10n() {  
    689690                        'dismiss'                   => __( 'Dismiss', 'buddypress' ),
    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. */
    694696                        'error_uploading'           => __( '“%s” has failed to upload.', 'buddypress' ),
    function bp_attachments_enqueue_scripts( $class = '' ) {  
    779781                $defaults['filters']['max_file_size'] = $args['max_file_size'] . 'b';
    780782        }
    781783
     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 ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
     790                $defaults['webp_upload_error'] = true;
     791        }
     792
    782793        // Specific to BuddyPress Avatars.
    783794        if ( 'bp_avatar_upload' === $defaults['multipart_params']['action'] ) {
    784795
  • src/bp-core/classes/class-bp-attachment-avatar.php

    diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php
    index 21bfedd94..4559ffe5d 100644
    class BP_Attachment_Avatar extends BP_Attachment {  
    399399                // Get default script data.
    400400                $script_data = parent::script_data();
    401401
     402                // Adds the list of supported image types.
     403                $script_data['mime_types'] = $this->get_supported_image_types( 'csv' );
     404
    402405                // Defaults to Avatar Backbone script.
    403406                $js_scripts = array( 'bp-avatar' );
    404407
  • src/bp-core/classes/class-bp-attachment-cover-image.php

    diff --git src/bp-core/classes/class-bp-attachment-cover-image.php src/bp-core/classes/class-bp-attachment-cover-image.php
    index 14a5a2ef8..22dba7d68 100644
    class BP_Attachment_Cover_Image extends BP_Attachment {  
    196196                // Get default script data.
    197197                $script_data = parent::script_data();
    198198
     199                // Adds the list of supported image types.
     200                $script_data['mime_types'] = $this->get_supported_image_types( 'csv' );
     201
    199202                if ( bp_is_user() ) {
    200203                        $item_id = bp_displayed_user_id();
    201204
  • src/bp-core/classes/class-bp-attachment.php

    diff --git src/bp-core/classes/class-bp-attachment.php src/bp-core/classes/class-bp-attachment.php
    index 17bb3c553..5c6bb8a1e 100644
    abstract class BP_Attachment {  
    493493                        $check_types['dst_file'] = array( 'file' => $r['dst_file'], 'error' => _x( 'destination file', 'Attachment destination file', 'buddypress' ) );
    494494                }
    495495
    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 = $this->get_supported_image_types();
    507498
    508499                foreach ( $check_types as $file ) {
    509500                        $is_image      = wp_check_filetype( $file['file'] );
    abstract class BP_Attachment {  
    536527                return wp_crop_image( $r['original_file'], (int) $r['crop_x'], (int) $r['crop_y'], (int) $r['crop_w'], (int) $r['crop_h'], (int) $r['dst_w'], (int) $r['dst_h'], $r['src_abs'], $r['dst_file'] );
    537528        }
    538529
     530        /**
     531         * Returns the list of supported image types.
     532         *
     533         * @since 11.0.0
     534         *
     535         * @param string $return The format to use to return the supported image types.
     536         *                       Possible values are 'array' for an array keyed by image types
     537         *                       or 'csv' for a comma separated list of image types.
     538         * @return array|string  The list of supported image types.
     539         */
     540        public function get_supported_image_types( $return = 'array' ) {
     541                /**
     542                 * WordPress image supported types.
     543                 * @see wp_attachment_is()
     544                 */
     545                $supported_types = array(
     546                        'jpg'  => 1,
     547                        'jpeg' => 1,
     548                        'jpe'  => 1,
     549                        'gif'  => 1,
     550                        'png'  => 1,
     551                        'webp' => 1,
     552                );
     553
     554                if ( 'csv' === $return ) {
     555                        return implode( ',', array_keys( $supported_types ) );
     556                }
     557
     558                return $supported_types;
     559        }
     560
    539561        /**
    540562         * Build script datas for the Uploader UI.
    541563         *
  • src/bp-core/js/bp-plupload.js

    diff --git src/bp-core/js/bp-plupload.js src/bp-core/js/bp-plupload.js
    index 3416de196..e81e7bb57 100644
    window.bp = window.bp || {};  
    162162                                        return;
    163163                                }
    164164
     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 );
     169                                        return;
     170                                }
     171
    165172                                if ( max > hundredmb && file.size > hundredmb && uploader.runtime !== 'html5' ) {
    166173                                        _this.uploadSizeError( uploader, file, true );
    167174                                } else {