I have recently upgraded to to php 7.2 and have been systematically searching for issues…here’s the latest, and this is important.
I am very concerned about the following function:
function get_attached_file( $attachment_id ) {
if ( empty( $attachment_id ) ) {
return false;
}
$file_path = get_attached_file( $attachment_id );
if ( ! empty( $file_path ) && strpos( $file_path, 's3' ) !== false ) {
$file_path = get_attached_file( $attachment_id, true );
}
return $file_path;
}
I have S3 active…WITH cname dns set up to pass through the buck
files.networkname.com -> files.networkname.com.s3-us-west-1.amazonaws.com
meaning my s3 paths will reference files.mynetworkname.com instead of a really long ugly name with s3 in it. Its the right way to set things up and can be easily accomplished and should be considered a standard use case.
Your function appears to be looking for s3 in the file path…to make a conclusion of weather or not to get the full server path of where the image would be….this is really bad and can lead to other issues in your code because this function will return the local path of an image that does not exist, not something that it looks like you are expecting.
For example, in the file:
lib/class-wp-smush-resize.php
line 105:
$file_path = $wpsmush_helper->get_attached_file( $id );
even when S3 plugin is active in the settings, $file_path is set to a local file path…
which then the causes this line $this->is_animated( $file_path ) to run the function is_animated to run, and on line 413
$filecontents = file_get_contents( $file_path );
which will fail because there will NEVER be a local file to check….
BUG BUG BUG BUG that needs to be immediately reviewed.
2ndly…this was running when I went to https://networkname.com/subsite/wp-admin/upload.php
which loads in very slow and i’m seeing all the error messages in my logs….why is is_animated even running? And what other overhead is running unnecessarily because of smush here.
Please review the code lines i have given you. Please check to make sure of the following things:
1. Smush is not running unnecessarily on all page loads. I have revealed both domain mapping plugin and ultimate branding are very guilty of that….this appears to be guilty of that too and clogging up servers unnecessarily.
2. in the file lib/class-wp-smush-helper.php line 32:
function get_attached_file in the class WpSmushHelper is straight up broken and using failing logic and needs to be fix it asap as well as a review what other functions are reliant on it.