distributor icon indicating copy to clipboard operation
distributor copied to clipboard

Check return value of get_post_meta

Open dhanendran opened this issue 2 years ago • 0 comments

Description of the Change

Validate the return value of get_post_meta and make sure it is array.

Closes #1107

How to test the Change

  1. Enable debug logging in wp-config
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
  1. Run wp shell and call the function with an invalid post ID: \Distributor\Utils\prepare_meta('bug');
  2. Open the debug.log file in your wp-content directory and observe the no warning is thrown: PHP Warning: Invalid argument supplied for foreach() in .../includes/utils.php on line 427

Changelog Entry

Fixed - PHP warning about invalid argument supplied for foreach in \Distributor\Utils\prepare_meta()

Credits

Props @dhanendran

Checklist:

  • [x] I agree to follow this project's Code of Conduct.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my change.
  • [ ] All new and existing tests pass.

dhanendran avatar Dec 08 '23 18:12 dhanendran