I've made an example that is pretty bare-bones, hopefully this helps out.
In this example there are two date-metaboxes, only difference is that the second has clone=true (and clone_as_multiple=true which does not change anything). With clone=true I get the following error:
Warning: DateTime::createFromFormat() expects parameter 2 to be string, array given in /Users/ronald/Sites/ronald.local:5757/wp-content/plugins/comsi-ce/vendor/meta-box/meta-box/inc/fields/datetime.php on line 175
If I change that line 175 and add a timestamp to the DateTime::createFromFormat(), the error disappears and it works as expected.
[..], $meta . ' 00:00:00' );
But again, this is only the case when clone=true (second example).
This fixed it for me.
Thank you for the quick support, much appreciated!
We still getting an warning when we are using a cloneable datetime fields with a save_format.
Warning: DateTime::createFromFormat() expects parameter 2 to be string, array given in .....\vendor\meta-box\meta-box\inc\fields\datetime.php on line 175
When i change
$date = DateTime::createFromFormat( $field['save_format'], $meta ); into
$date = is_array($meta) ? false : DateTime::createFromFormat( $field['save_format'], $meta ); it works. Can you investigate if it's a solid solution, or provide another one?
I couldn't replicate the bug with your initial code. Is there any change since it worked for you?
Thank you for your quick replies, they are much appreciated.
My colleague Erik will be unavailable for two weeks, and since I cannot replicate this either I'll ask him to work up a simple test case with some working code when he's back in.
Hi Ahn, I figured out what is causing the PHP error.
When we add a field of the 'date' type, and add the 'save_format' option on that, it throws an error:
array( 'name' => 'Example PHP DateTime error', 'id' => 'some_unique_id', 'type' => 'date', 'clone' => true, 'clone_as_multiple' => true, 'inline' => false, 'timestamp' => false, 'js_options' => array( 'dateFormat' => $js_date_format, 'showButtonPanel' => false, ), 'save_format' => 'Y-m-d' // this throws the error )
This results in the error:
Warning: DateTime::createFromFormat() expects parameter 2 to be string, array given in /Users/ronald/Sites/metabox-debug.dev/wp-content/plugins/metabox-debug/vendor/meta-box/meta-box/inc/fields/datetime.php on line 175
When you remove (or comment out) the 'save_format' option (documented here) the error disappears.
Hopefully you replicate this too?
I still can't replicate the bug. I recorded a video here: https://www.loom.com/share/bd04f3fd07654d88a22b37bfb54881dc. Please take a look.
Seems like a compatibility issue where we have two plugins that both bundled your plugin(s) via Composer, as you documented this might cause problems. I guess we'll have to find a way to work around that.
Thanks again for taking the time to check it on your end.
We double-tripple checked and have it all sorted out now, the bug happened because of an older plugin that never updated from 4.18 version to the ^5 branch. Since that plugin was called before our other plugin it was causing problems. After updating every plugin to ^5 via composer, it was all sorted.
Thanks again! ?