#39293 closed defect (bug) (fixed)
WordPress REST API warnings
Reported by: | dreamon11 | Owned by: | jnylen0 |
---|---|---|---|
Milestone: | 4.7.1 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests commit fixed-major |
Focuses: | rest-api | Cc: |
Description (last modified by )
Hello everybody,
A simple get request to wp-json/wp/v2/posts (or anything get request) give me these warnings:
( ! ) Warning: array_values() expects parameter 1 to be array, null given in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 1925 ( ! ) Warning: array_merge(): Argument #2 is not an array in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 1925 ( ! ) Warning: array_values() expects parameter 1 to be array, null given in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 1925 ( ! ) Warning: array_merge(): Argument #2 is not an array in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 1925 ( ! ) Warning: array_values() expects parameter 1 to be array, null given in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 1925 ( ! ) Warning: Cannot modify header information - headers already sent by (output started at /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:1925) in /srv/www/xxx.fr/current/web/wp/wp-includes/rest-api/class-wp-rest-server.php on line 1244
At the end, expected result is here but warnings prevent software whichi make get request to retrieve it.
Attachments (1)
Change History (17)
#2
@
8 years ago
Hi @dreamon11,
Thank you for using the WordPress REST API! I am sorry you came across these warnings. From a quick look at the code, this is most likely occurring due to the active theme not supporting any post formats. There should be some safeguards put in place to prevent these PHP warnings. Thank you for reporting your issue. I will be double checking to verify if that is the problem.
#3
@
8 years ago
I can't duplicate the warnings what do get as a return value for get_theme_support( 'post_formats' )
?
#4
@
8 years ago
Hi @dreamon11 I couldn't reproduce this warnings. I also tried removing all post formats manually and checked it, still can't reproduce this issue. Can you give us more information on this ticket as requested by @ChopinBach.
#5
@
8 years ago
Problem fixed.
In my theme functions.php file, I have the following code:
add_theme_support('post-formats');
Replace with:
add_theme_support('post-formats', []);
Or simply remove post-formats theme support.
And no more warnings ;)
#6
@
8 years ago
@ChopinBach @dhanendran Thanks for help.
Do you know how can I edit the first comment? Or contact an admin to edit it?
#7
@
8 years ago
- Keywords needs-patch added
It's valid to call add_theme_support( 'post-formats' )
with no additional arguments (docs), though I'm not sure how useful that is.
Per the `get_theme_support` documentation the function will return true
in this situation (and it could also return false
in other situations). So we should add is_array
checks for both $supports_formats
and $supports_formats[0]
here.
#9
@
8 years ago
Okay, I will write a patch for this later today then, at the very least it will prevent this from happening to anyone else.
@
8 years ago
39293 Adds a test to handle edge case uses of add_theme_support. When add_theme_support( 'post-formats' ) is called, it resolves to true. This caused PHP to throw warnings expecting an array. This patch resolves this problem for any themes/plugins accidentally triggering this.
#11
@
8 years ago
- Milestone changed from Awaiting Review to 4.7.1
- Owner set to jnylen0
- Status changed from new to accepted
#14
@
8 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Needs to be ported to the 4.7 branch.
#16
@
5 years ago
I think the fix is missing the original point of this ticket - JSON results back from the API are returning WARNINGS. Not errors, but warnings, in the text of the response. and yeah, WP_DEBUG is not set to True, display_errors = Off in php.ini. I had a completely different case where this same thing happens and this is really unexpected.
There will always be some potential for some odd plugin that gives a warning, but even when display_errors=Off this is still returning ["Warning: ... and array with warning errors as the json in a WP_REST_Response.
Hummm... I cannot edit my first comment. If anyone can, please edit first line warning to delete my website domain. Thanks :)