PHP Warning: Invalid argument supplied for foreach() occuring on Fresh WP Setup
desaiuditd opened this issue · comments
On Fresh WordPress setup; when there are no records of the Stream activities in the database this PHP warning pops up when you come to Stream Records screen:
PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/rcwp.local.com/htdocs/wp-content/plugins/wp-stream/includes/list-table.php on line 572
Root cause:
In WP_Stream_Date_Interval
class, filter_predefined_intervals
method is returning false
if no records are found; which results in a non-array i.e., $date_interval->intervals
being passed to the foreach
loop on line 572 of list-table.php
Solution would be either change the defination of filter_predefined_intervals
to make it return an array value; even if it's empty array or handle this scenario in the list-table.php file on line 572.
Suggestions are welcomed.
@desaiuditd Yes, always returning an array value for predefined intervals is the way to go.