Making WordPress.org


Ignore:
Timestamp:
09/26/2022 10:27:24 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Uploads: Enforce valid photo dimensions.

  • Add client-side JS checks
  • Add server-side checks
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php

    r12090 r12091  
    270270                    'max_file_size' => self::get_maximum_photo_file_size(),
    271271                    'min_file_size' => self::get_minimum_photo_file_size(),
     272
     273                    // File dimensions.
     274                    'err_file_too_long'     => sprintf(
     275                        /** translators: %d: The maximum number of pixels. */
     276                        __( 'The selected file cannot be longer in either length or width than %dpx.', 'wporg-photos' ),
     277                        self::big_image_size_threshold( 0 )
     278                    ),
     279                    'err_file_too_short'    => sprintf(
     280                        /** translators: %d: The minimum number of pixels. */
     281                        __( 'The selected file must be longer in both length and width than %dpx.', 'wporg-photos' ),
     282                        self::get_minimum_photo_dimension()
     283                    ),
     284                    'max_file_dimension' => self::big_image_size_threshold( 0 ),
     285                    'min_file_dimension' => self::get_minimum_photo_dimension(),
     286                    'msg_validating_dimensions' => __( 'Validating photo dimensions…', 'wporg-photos' ),
    272287                ]
    273288            );
     
    383398                        __( 'The file size for your submission is too large. Please submit a photo smaller than %d MB in size.', 'wporg-photos' ),
    384399                        self::get_maximum_photo_file_size( false )
     400                    );
     401                    break;
     402                case 'file-too-long':
     403                    $rejection = sprintf(
     404                        __( 'Your submission is too large. Please submit a photo with length and width each smaller than %dpx.', 'wporg-photos' ),
     405                        self::big_image_size_threshold( 0 )
     406                    );
     407                    break;
     408                case 'file-too-short':
     409                    $rejection = sprintf(
     410                        __( 'Your submission is too small. Please submit a photo with length and width each larger than %dpx.', 'wporg-photos' ),
     411                        self::get_minimum_photo_dimension()
    385412                    );
    386413                    break;
     
    579606        if ( ! in_array( $image_type, [ IMG_JPG, IMG_JPEG ] ) ) {
    580607            return 'file-not-jpg';
     608        }
     609
     610        // Check image dimensions.
     611        $max_dimension = self::big_image_size_threshold( 0 );
     612        $min_dimension = self::get_minimum_photo_dimension();
     613        if ( $width > $max_dimension || $length > $max_dimension ) {
     614            return 'file-too-long';
     615        }
     616        if ( $width < $min_dimension || $length < $min_dimension ) {
     617            return 'file-too-short';
    581618        }
    582619
Note: See TracChangeset for help on using the changeset viewer.