From 59ab53d84f167846718307e7b4efb1d584ef8833 Mon Sep 17 00:00:00 2001 From: Champ Camba Date: Mon, 21 Jan 2019 19:39:38 +0800 Subject: [PATCH] Fix cover photo resize and filenaming conventions --- includes/core/class-uploader.php | 10 +++++++++- includes/um-short-functions.php | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/includes/core/class-uploader.php b/includes/core/class-uploader.php index 298f05fe..11a37fcb 100644 --- a/includes/core/class-uploader.php +++ b/includes/core/class-uploader.php @@ -1006,8 +1006,16 @@ if ( ! class_exists( 'um\core\Uploader' ) ) { $sizes_array[ ] = array ('width' => $size ); } - $image->multi_resize( $sizes_array ); + $resize = $image->multi_resize( $sizes_array ); + // change filenames of resized images + foreach( $resize as $row ){ + $new_filename = str_replace( "x{$row['height']}" , "", $row["file"] ); + $old_filename = $row["file"]; + + rename( dirname( $image_path ) . DIRECTORY_SEPARATOR . $old_filename, dirname( $image_path ) . DIRECTORY_SEPARATOR . $new_filename ); + } + } else { wp_send_json_error( esc_js( __( "Unable to crop image file: {$src}", 'ultimate-member' ) ) ); } diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index d8b11614..aaca0a5f 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -1811,22 +1811,22 @@ function um_get_cover_uri( $image, $attrs ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo{$ext}?" . current_time( 'timestamp' ); } - if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) { - $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' ); - } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) { + if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo-{$attrs}{$ext}?" . current_time( 'timestamp' ); - } + }elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) { + $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' ); + } } if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo{$ext}?" . current_time( 'timestamp' ); } - if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) { - $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' ); - } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) { + if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo-{$attrs}{$ext}?" . current_time( 'timestamp' ); - } + }elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "cover_photo-{$attrs}x{$height}{$ext}" ) ) { + $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$height}{$ext}?". current_time( 'timestamp' ); + } if ( ! empty( $uri_common ) && empty( $uri ) ) { $uri = $uri_common;