When importing matches with roster information from an external JSON API, I found the wpcm_players meta value (for any wpcm_match post type) is automatically serialized.
When viewing the wp-admin side of any match, I'm seeing an issue where no players are appearing but the serialized data for that match is in the database.
The error log shows the following message:
PHP Warning: unserialize() expects parameter 1 to be string, array given in /wp-club-manager/includes/admin/post-types/meta-boxes/class-wpcm-meta-box-match-players.php on line 287
This is because the imported data was only serialized once and not twice.
Using the WordPress function maybe_unserialize() instead of PHP's unserialize() resolves this issue as it will check the data prior to unserializing and will only unserialize if it absolutely needs to.
When importing matches with roster information from an external JSON API, I found the
wpcm_players
meta value (for anywpcm_match
post type) is automatically serialized.When viewing the wp-admin side of any match, I'm seeing an issue where no players are appearing but the serialized data for that match is in the database.
The error log shows the following message:
This is because the imported data was only serialized once and not twice.
Using the WordPress function
maybe_unserialize()
instead of PHP'sunserialize()
resolves this issue as it will check the data prior to unserializing and will only unserialize if it absolutely needs to.