• Resolved keithtroyerwebsites

    (@keithtroyerwebsites)


    Hi,

    We are trying to update the PHP from 7.4 to 8.0 or 8.2 and it sends all our websites on our server into critical error. We were told it is the Code Snippets plugin that is causing the issue. When we deactivate the code snippets plugin the websites work again. Is there anyway you can help? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @keithtroyerwebsites,

    We develop the plugin on PHP 8.3, so I’d be surprised if it was the Code Snippets plugin itself causing this issue – I suspect it’s coming from one of your snippets.

    I recommend disabling all your snippets before upgrading, and enabling them one-by-one until you identify which one might be causing the problem. Once you’ve identified it, feel free to post here and I can give you some tips on how to fix it up.

    Thread Starter keithtroyerwebsites

    (@keithtroyerwebsites)

    Below is the snippet causing the issue. Can you please help fix it.

    add_filter( ‘woocommerce_get_image_size_gallery_thumbnail’, function( $size ) {
    return array(
    ‘width’ => 111,
    ‘height’ => 111,
    ‘crop’ => 1,
    );
    }
    );

    add_filter( ‘woocommerce_product_thumbnails_columns’, create_function( ”, ‘return 5;’ ) );

    Why does the error occur?

    • create_function() removed: In PHP 8.x, create_function() is no longer available. Attempting to use it results in a fatal error.
    • Syntax errors due to quotation marks: Curly quotation marks are not recognized by PHP as valid string delimiters and lead to syntax errors.

    By implementing these changes, your code should function without errors in both PHP 7.x and PHP 8.x:

    add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
    return array(
    'width' => 111,
    'height' => 111,
    'crop' => 1,
    );
    });

    add_filter( 'woocommerce_product_thumbnails_columns', function() {
    return 5;
    });
    Plugin Author Shea Bunge

    (@bungeshea)

    networka is correct – anonymous functions are the correct way to do this instead of create_function..

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.