• Resolved geoj

    (@georgjoutras)


    Getting this same error over and over on my site:
    [04-Nov-2020 05:12:40 UTC] PHP Warning: array_merge(): Expected parameter 1 to be an array, null given in /home/ylm7sm1a17rt/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code on line 28

    I think it points to a bad snippet (I have 3 activated, about 10 not activated). Don’t know which one…any help you can point me towards?

    Thanks!

    The page I need help with: [log in to see the link]

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

    (@bungeshea)

    Hi!

    That message is definitely coming from one of your snippets – one of the ones which is activated. I can’t give you the name of the one causing the problem, but I can tell you it’ll be the one with array_merge on line 28 of its code.

    To narrow the list down, you can search for the text array_merge in the snippet search box.

    Thread Starter geoj

    (@georgjoutras)

    Figured it out. Bad array_merge funtion in one of the code snippets I added.

    Plugin Author Shea Bunge

    (@bungeshea)

    Good to hear that it’s sorted!

    Thread Starter geoj

    (@georgjoutras)

    Thanks for the quick reply. I have figured out it is the code to add a new report to the ORDERS tab.

    Here is the code that is causing the issue.

    add_filter( ‘woocommerce_admin_reports’, ‘bbloomer_admin_add_report_orders_tab’ );

    function bbloomer_admin_add_report_orders_tab( $reports )
    {

    $tab_array = array(
    ‘sales_by_state’ => array(
    ‘title’ => ‘Sales by State via snippet’,
    ‘description’ => ”,
    ‘hide_title’ => true,
    ‘callback’ => ‘bbloomer_yearly_sales_by_state’),
    );
    $reports[‘orders’][‘reports’] = array_merge($reports[‘orders’][‘reports’],$tab_array);

    return $reports;
    }

    For the life on me, I can’t figure out why the array_merge is failing…any thoughts would be greatly appreciated!

    -Georg

    Plugin Author Shea Bunge

    (@bungeshea)

    It’s possible that sometimes the $reports['orders'] variable is empty, or $reports['orders']['reports'] is set to a different value.

    You should be able to fix this by adding a line to check whether that element is set and an array near the top of the function, and exit the function if so:

    if ( ! isset( $reports['orders']['reports'] ) || ! is_array( $reports['orders']['reports'] ) return;

    Thread Starter geoj

    (@georgjoutras)

    Thank you, Shea! That did the trick.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP Warning: array_merge(): Expected parameter 1 to be an array, null given’ is closed to new replies.