• Resolved HighKay

    (@hlorenz)


    Hi,

    I’m experiencing a recurring PHP fatal error on multiple WordPress sites running Autoptimize with PHP 8.3. The error appears in the server error log during high crawler traffic (typically at night) and results in HTTP 500 responses.

    Error message:

    PHP Fatal error: Uncaught Error: Using $this when not in object context in autoptimize/classes/autoptimizeImages.php on line 1061
    
    #0 autoptimizeImages.php(912): autoptimizeImages::create_img_preload_tag()
    #1 autoptimizeImages->filter_lazyload_images()

    Environment:

    • PHP 8.3
    • WordPress (latest)
    • Autoptimize (latest)
    • Hosting: LiteSpeed server

    Observations:

    • The error occurs in the image optimization / lazy load functionality
    • It does not occur consistently – it seems triggered by concurrent requests
    • Temporarily disabling and re-enabling the image optimization feature does not resolve the issue permanently
    • The error affects multiple sites with the same setup

    Has anyone else encountered this? Is there a known fix or workaround short of permanently disabling image optimization?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    not a real solution, but as a workaround can you try if disabling the “metabox” option near the bottom of the main settings or (better) to find all pages which have LCP preloads in the “autoptimize this page” metabox being filled in the metabox of the individual page) and remove them there?

    re. the root cause; I’ll look into that! 🙂

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, I *think* I know what the problem is, but (a) I can’t reproduce it (also PHP 8.3 on my development environment) and (b) it’s not logical the error would not always happen, as opposed to only under heavy load?

    Anyway, could you make the following small (but in the end logical) change to wp-content/plugins/autoptimize/classes/autoptimizeImages.php on line 1042 change

    public static function create_img_preload_tag( $tag ) {
    into
    public function create_img_preload_tag( $tag ) {

    because indeed in a static function you can’t call $this, my bad!

    looking forward to your feedback 🙂

    frank

    Thread Starter HighKay

    (@hlorenz)

    Hi Frank,

    I just applied the code change to my websites.

    We’ll have to wait until tomorrow, to see if it worked, since I can’t find Live error log. Only the one from tonight.

    I’ll tell you tomorrow & thanks for the ultra-quick response!

    Thanks

    Heike

    • This reply was modified 2 months, 1 week ago by HighKay.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    pushing out the fix now as version 3.1.15.1, sorry for the inconvenience!

    frank

    Thread Starter HighKay

    (@hlorenz)

    Thanks 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.