WordPress / wporg-news-2021

The WordPress.org News Theme
https://wordpress.org/news/
31 stars 21 forks source link

Avoid a PHP Warning in the rest api #423

Closed dd32 closed 5 months ago

dd32 commented 5 months ago
E_WARNING: count(): Parameter must be an array or an object that implements Countable in wp-content/themes/wporg-news-2021/functions.php:162

Source: GET https://wordpress.org/news/wp-json/wp/v2/posts?per_page=1
File: wp-content/themes/wporg-news-2021/functions.php:162

Unsure why this has suddenly started, but the above PHP Warning is happening in the REST api fairly frequently.

Looking at the WP_Query object, it appears to be uninitialised, so this seems like a shortcut we can take to avoid it..

dd32 commented 5 months ago
Screenshot 2024-06-07 at 11 58 17 AM
ryelle commented 5 months ago

Looks like this started right when I updated GB to 18.5… yep, in 18.3 they started passing post classes back in the API. I think it's safe to shortcut like this and skip returning the custom classes, since we don't really use the editor on News anyway.