Custom Fields
Re-Envisioned
Support General PHP warning when using clone w/ date formatting

This topic contains 9 replies, has 2 voices, and was last updated by  ComSi 1 month ago.

  • Creator
    Topic
  • #16068
    Resolved
    ComSi
    Participant

    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).

    https://pastebin.com/zv7TYAxS

    Kind regards,
    Ronald

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #16087

    Anh Tran
    Keymaster

    Hi Ronald,

    Thanks for bug reporting. It’s fixed here.

    #16092

    ComSi
    Participant

    Hi Anh,

    This fixed it for me.
    Thank you for the quick support, much appreciated!

    Ronald

    #16289

    ComSi
    Participant

    Hi 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

    #16315

    Anh Tran
    Keymaster

    Hi Erik,

    I couldn’t replicate the bug with your initial code. Is there any change since it worked for you?

    #16325

    ComSi
    Participant

    Hi 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,
    Ronald

    #16450

    ComSi
    Participant

    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?

    #16455

    Anh Tran
    Keymaster

    Hi,

    I still can’t replicate the bug. I recorded a video here: https://www.loom.com/share/bd04f3fd07654d88a22b37bfb54881dc. Please take a look.

    #16462

    ComSi
    Participant

    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.

    #16605

    ComSi
    Participant

    Hi 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! 👍

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.