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

This topic contains 2 replies, has 2 voices, and was last updated by  ComSi 1 week, 4 days 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).

    $meta_boxes[] = array(
        'id'          => 'ce_info',
        'title'       => __('CE info', 'comsi-ce'),
        'post_types'  => 'comsi_ce',
        'context'     => 'normal',
        'priority'    => 'high',
        'fields'      => array(
            // this works
            array(
                'name'            => __('Recurring start date', 'comsi-ce'),
                'id'              => 'comsi_start_date',
                'type'            => 'date',
                'inline'          => false,
                'timestamp'       => false,
                'size'            => '14',
                'save_format'     => 'Y-m-d',
                'js_options'      => array(
                    'dateFormat'      => 'dd-mm-yy',
                    'showButtonPanel' => false,
                ),
            ),
            // this does not work
            // 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
            array(
                'name'              => __('Recurring dates', 'comsi-ce'),
                'id'                => 'comsi_dates_recurring',
                'type'              => 'date',
                'clone'             => true, // << this is the problem
                'clone_as_multiple' => true,
                'inline'            => false,
                'timestamp'         => false,
                'size'              => '14',
                'save_format'       => 'Y-m-d',
                'js_options'        => array(
                    'dateFormat'        => 'dd-mm-yy',
                    'showButtonPanel'   => false,
                ),
            ),
        )
    );

    Kind regards,
    Ronald

Viewing 2 replies - 1 through 2 (of 2 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

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

You must be logged in to reply to this topic.