Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when having image size with integer name #888

Closed
wordpressfan opened this issue May 23, 2024 · 6 comments · Fixed by #892
Closed

Fatal error when having image size with integer name #888

wordpressfan opened this issue May 23, 2024 · 6 comments · Fixed by #892
Assignees
Milestone

Comments

@wordpressfan
Copy link
Contributor

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version Yes
  • Used the search feature to ensure that the bug hasn’t been reported before Yes

Describe the bug

In a customer's site we face the following error:

[23-May-2024 08:15:14 UTC] PHP Fatal error:  Uncaught TypeError: strpos() expects parameter 1 to be string, int given in /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/classes/Optimization/Process/AbstractProcess.php:1641
Stack trace:
#0 /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/classes/Optimization/Process/AbstractProcess.php(1641): strpos(200, '@imagify-webp')
#1 [internal function]: Imagify\Optimization\Process\AbstractProcess->Imagify\Optimization\Process\{closure}(200)
#2 /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/classes/Optimization/Process/AbstractProcess.php(1642): array_filter(Array, Object(Closure))
#3 /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/inc/functions/admin-ui.php(100): Imagify\Optimization\Process\AbstractProcess->is_full_next_gen()
#4 /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/inc/functions/admin-ui.php(529): g in /home/customer/www/staging2.xxx.com/public_html/wp-content/plugins/imagify/classes/Optimization/Process/AbstractProcess.php on line 1641

and this happens exactly here:

return strpos( $key, $this->format ) === false;

In the PR (#877) we fixed similar issue when the image size name is not integer, but we once the image is optimized we save the sizes in the attachment metas to be grabbed later on the mentioned line (as far as I understand) but in php if the array has numeric keys even if u added them as strings, this will be cast to be integer then it throws the previously mentioned fatal error.

To Reproduce
Steps to reproduce the behavior:

  1. Add the following snippet
add_action( 'after_setup_theme', function() {
    add_image_size( '200', 200, 200 );
} );
  1. Optimize any image and wait till it's optimized for this new size.
  2. Open any post and choose the featured image
  3. once media modal is opened, fatal error should be thrown and images not loaded in the modal.

Expected behavior
Images should load without a problem.

I fixed this by casting the $key variable here:

return strpos( $key, $this->format ) === false;

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Acceptance Criteria (for WP Media team use only)
Clear instructions for developers, to be added before the grooming

@piotrbak piotrbak added this to the 2.2.3 milestone Jun 3, 2024
@saranshj4
Copy link

@saranshj4
Copy link

imagify.2.2.2.zip
A patched version that resolved the issue on some user sites.

@saranshj4
Copy link

@markonikolic985
Copy link
Contributor

Another relevant ticket with proposed solution https://secure.helpscout.net/conversation/2680413623/507765?folderId=676697

My hosting support was able to determine the issue.
It seems that the Imagify plugin is not fully compatible with your version of the WordPress core and/or PHP 8.2.
The Wordpress error dump identified line 1641 in /home/cypresspainting/www/www/wp-content/plugins/imagify/classes/Optimization/Process/AbstractProcess.php.
They did come up with a fix for this problem
Replaced
return strpos( $key, $this->format ) === false;
with this:
return is_string($key) && strpos( $key, $this->format ) === false;

@saranshj4
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants