PHP warning when using clone w/ date formatting
- This topic has 9 replies, 2 voices, and was last updated 5 years, 6 months ago by
ComSi.
-
AuthorPosts
-
September 11, 2019 at 2:23 PM #16068
ComSi
ParticipantI'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).
Kind regards,
RonaldSeptember 12, 2019 at 11:36 AM #16087September 12, 2019 at 2:14 PM #16092ComSi
ParticipantHi Anh,
This fixed it for me.
Thank you for the quick support, much appreciated!Ronald
September 25, 2019 at 10:05 PM #16289ComSi
ParticipantHi Anh,
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?Erik-Jan
September 27, 2019 at 10:14 AM #16315Anh Tran
KeymasterHi Erik,
I couldn't replicate the bug with your initial code. Is there any change since it worked for you?
September 27, 2019 at 2:03 PM #16325ComSi
ParticipantHi Anh,
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.
Thanks again,
RonaldOctober 9, 2019 at 9:12 PM #16450ComSi
ParticipantHi 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?
October 10, 2019 at 2:21 PM #16455Anh Tran
KeymasterHi,
I still can't replicate the bug. I recorded a video here: https://www.loom.com/share/bd04f3fd07654d88a22b37bfb54881dc. Please take a look.
October 10, 2019 at 4:22 PM #16462ComSi
ParticipantSeems 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.
October 18, 2019 at 9:20 PM #16605ComSi
ParticipantHi Anh,
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! ?
-
AuthorPosts
- You must be logged in to reply to this topic.