I鈥檝e upgraded on a staging site wc 4.01 to 4.1 with no problems, but i鈥檓 getting notices on my logs(lots of them) when clicking any sub-menu under analytics(orders, categories, coupons, etc.)
The analytics info is displayed fine, but each time i鈥檓 using it(only analytics) a notice like this is logged:
[01-May-2020 17:08:46 UTC] PHP Notice: Undefined index: items in /xxx.xxx/wp-includes/rest-api.php on line 1245
I鈥檓 using wordpress 5.4.1, woocommerce release candidate 2 and php 7.3.16. This only happens on rc2, wc 4.01 with exactly the same configuration on production site doesn鈥檛 make those notices appear when using analytics.
Everything else works great! Thanks for making woocommerce such a great work!
Expected behavior
The notices shouldn't appear anymore
Isolating the problem (mark completed items with an [x]):
WordPress Environment
Wp 5.4.1 wc 4.1 rc2 php 7.3.16 after upgrading from wc 4.01
Hi @Danielspain22 ,
Thanks for your kind words and for reporting the bug.
I can see this happening (but not sure why my PHP instance does not log this). I'm going to transfer this issue to the WC Admin repository, where this code lives.
Side notes:
/wp-json/wc-analytics/reports/orders/stats?after=2020-05-01T00:00:00&before=2020-05-04T23:59:59&fields[0]=orders_count&fields[1]=net_revenue&fields[2]=avg_order_value&fields[3]=avg_items_per_order&interval=day&order=asc&per_page=100&_locale=userfields parameter is an array, so WP code assumes it has items defined. items section with data type to $params['fields'] in get_collection_params methods of the controllers should be an easy fix: $params['fields'] = array(
'description' => __( 'Limit stats fields to the specified items.', 'woocommerce' ),
'type' => 'array',
'sanitize_callback' => 'wp_parse_slug_list',
'validate_callback' => 'rest_validate_request_arg',
'items' => array(
'type' => 'string',
),
);
If we wanted to be more specific, I think sth like this should work, but it needs more work/polish, I just looked at it while reproducing the issue:
$params['fields'] = array(
'description' => __( 'Limit stats fields to the specified items.', 'woocommerce' ),
'type' => 'array',
'sanitize_callback' => 'wp_parse_slug_list',
'validate_callback' => 'rest_validate_request_arg',
'items' => array(
'type' => 'string',
'enum' => isset( self::get_item_schema()['properties']['totals']['properties'] ) && is_array ( self::get_item_schema()['properties']['totals']['properties'] ) ? array_keys( self::get_item_schema()['properties']['totals']['properties'] ) : '',
),
);
Landed here searching for this issue. I am curious about 4.1 being rolled out without fixing this
Hi @KoolPal, we've discovered this quite late in the release cycle and to us, it seems like it's not a critical issue, therefore we haven't prioritized this before releasing 4.1. Please let us know if you think otherwise.
@peterfabian Thanks. Is there some code snippet which can be used until a fix is released?
Hi @KoolPal
Just checked quickly and I see no easy way to filter this, so unless I missed something, I guess it's better to wait for the fix. Apologies.
Adding one more report here - https://wordpress.org/support/topic/undefined-index-items/
And I was also able to replicate it on my sites
After chatting with Beau, we concluded it might be good to get this one fixed for 4.2. WDYT @ObliviousHarmony @timmyc ?
Most helpful comment
After chatting with Beau, we concluded it might be good to get this one fixed for 4.2. WDYT @ObliviousHarmony @timmyc ?