10up / distributor

Share content between your websites.
https://distributorplugin.com
GNU General Public License v2.0
628 stars 155 forks source link

Check return value of get_post_meta #1167

Closed dhanendran closed 1 month ago

dhanendran commented 9 months ago

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 );
  2. Run wp shell and call the function with an invalid post ID: \Distributor\Utils\prepare_meta('bug');
  3. 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:

kirtangajjar commented 2 months ago

@faisal-alvi Made the requested changes. LMk if there are any more