• Resolved SLV

    (@dwnl)


    Hello,

    I have this PHP Warning: Undefined array key “standard” in /public_html/wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php on line 254\n
    That line contains: $atts[‘standard’] = wcj_sanitize_input_attribute_values( $atts[‘standard’] );

    The PHP warning, Undefined array key “standard”, occurs because the array key “standard” is not defined in the $atts array when it is being accessed. This can happen if the shortcode that the code is handling doesn’t include the standard attribute.

    I have Booster Plus for WooCommerce version 7.2.2

    How to solve this?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support David G

    (@gravid7)

    Hi @dwnl,

    Thanks for reaching out to us.

    If possible you can contact us from our website. So, we can take a deeper look and help you.

    Thread Starter SLV

    (@dwnl)

    It is not possible to contact you on your website. But chatGTP says:

    The PHP warning I’m seeing indicates that there is an attempt to access an array key named "standard" that does not exist in the array. This warning occurs in the file /home/###/domains/###/public_html/wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php on line 254.

    Steps to Resolve the Issue:

    1. Locate the Code:
      • Open the file at /public_html/wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php.
      • Go to line 254 to find where the array key "standard" is being accessed.
    2. Check the Array:
      • Examine the array before line 254 to see how it is being constructed or assigned.
      • Ensure that the "standard" key is supposed to be part of the array.
    3. Prevent Undefined Key Warnings:
      • Use isset() or array_key_exists(): Before accessing the "standard" key, check if it exists.
        if (isset($array['standard'])) { // Safe to use $array['standard'] } else { // Handle the case where 'standard' does not exist }
      • Provide a Default Value: If the key does not exist, you can provide a default value using the null coalescing operator (??):
        $standard_value = $array['standard'] ?? 'default_value';
      • Initialize the Array Key: Ensure that the "standard" key is set in the array before line 254:
        $array['standard'] = $array['standard'] ?? 'default_value';
    4. Update the Plugin (if applicable):
      • If this issue is due to a bug in the plugin, check if there’s an updated version of the Booster Plus for WooCommerce plugin that fixes this problem.
      • You can report this issue to the plugin developers if it persists after applying a temporary fix.
    5. Test the Fix:
      • After applying the fix, monitor your logs to ensure that the warning no longer appears and that the functionality of your site is not negatively affected.

    Example Fix:

    Here’s an example of how you might adjust the code:

    if (isset($your_array['standard'])) { $standard_value = $your_array['standard']; } else { $standard_value = 'default_value'; // Provide a sensible default value or handle the error }

    By following these steps, you should be able to eliminate the warning and ensure that the code handles the case where the "standard" key is not present in the array.

    Thread Starter SLV

    (@dwnl)

    It is not only used in /public_html/wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php on line 254\n, but it in more files, see: https://ibb.co/k5hdx8j….

    But this particular line: 254 contains: $atts[‘standard’]?= wcj_sanitize_input_attribute_values( $atts[‘standard’] );

    If I replace this whole line with:
    if ( isset( $atts[‘standard’] ) ) { $atts[‘standard’] = wcj_sanitize_input_attribute_values( $atts[‘standard’] ); } else { $atts[‘standard’] = ”; // Standard value if ‘standard’ not excists }

    The error is gone.
    But as I said it is in more files, see: https://ibb.co/k5hdx8j, so can you fix this a.s.a.p. please @gravid7?
    Can you speed things up, please?

    • This reply was modified 1 month, 1 week ago by SLV.
    Plugin Support David G

    (@gravid7)

    Hi @dwnl,

    Thank you for your message.

    Please kindly replace the attached file at the following path to fix the issue:

    File: https://we.tl/t-b2zA4V8A04

    Path: /wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php

    Before replacing the file, please ensure you take a safe backup of the original file.

    Thread Starter SLV

    (@dwnl)

    Hello @gravid7,
    Solved!

    So you just added:

                    'standard'                    => '',

    At line 144?

    Ha! Well, that was simple.
    I assume you will implement this in your next update?

    Thanks!

    Plugin Support David G

    (@gravid7)

    Hi @dwnl,

    Thank you for your message.

    Yes, that’s correct. We have added 'standard' => '' at line 144.

    exact same issue in logs here for me… I assume this is something you’ll be pushing in next release ?

    I’m unable to use the link to the fix since the file has expired ??

    Thread Starter SLV

    (@dwnl)

    @pckeys) just put: ‘standard’ => ”, at line 144
    So after line 143 hit the enter key and put in: ‘standard’ => ”,

    Save the file.

    Path: /wp-content/plugins/booster-plus-for-woocommerce/includes/shortcodes/class-wcj-orders-shortcodes.php

    @dwnl …that is the very first thing I tried and promptly broke the entire site… an hour to restore.

    I am not going to waste time don’t that again, although I am sure your instructions would include disabling the plugin first which I did not do.

    Just tried disabling plugin then editing file, re-enabling plugin completely breaks the site.

    • This reply was modified 1 month, 1 week ago by pckeys.
    Thread Starter SLV

    (@dwnl)

    I did not disable the plugin first…
    But here is the file if you want to try again?
    https://filebin.net/ckwju2bh656ewypp
    Link expires 6 days from now.

    Rename the original first so that will be your back-up.

    • This reply was modified 1 month, 1 week ago by SLV.

    appreciate the link ?? I’ll have a play around with in the morning .. many thanks

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