You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the return value of get_post_meta() is mixed, it is not guaranteed that $meta contains an empty array. Before using the data in a foreach loop, the variable should be validated.
Run wp shell and call the function with an invalid post ID: \Distributor\Utils\prepare_meta('bug');
Open the debug.log file in your wp-content directory and observe the warning is thrown: PHP Warning: Invalid argument supplied for foreach() in .../includes/utils.php on line 427
@jeffpaul It's a long term problem and an edge case (I picked it up while testing a PR that needed a little further work) so I think it can wait until after 2.0.0.
Describe the bug
The
prepare_meta()
utility function accepts a post ID and prepares the meta data for consumption/distribution.distributor/includes/utils.php
Lines 420 to 427 in ba8834c
As the return value of
get_post_meta()
is mixed, it is not guaranteed that$meta
contains an empty array. Before using the data in aforeach
loop, the variable should be validated.Steps to Reproduce
wp shell
and call the function with an invalid post ID:\Distributor\Utils\prepare_meta('bug');
debug.log
file in your wp-content directory and observe the warning is thrown:PHP Warning: Invalid argument supplied for foreach() in .../includes/utils.php on line 427
Screenshots, screen recording, code snippet
Error log and stack trace:
Environment information
No response
WordPress information
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: