Bug in text_datetime_timestamp_timezone field
-
Hi
I found a bug into
text_datetime_timestamp_timezone field
, when I use this field for any page and save field values it doesn’t save into database but when I change field totext_datetime_timestamp
and save the field values it create entries intopost_meta
table, now again if I changed the field totext_datetime_timestamp_timezone
and save the field values it works but only if oldpost_meta
entries exists.I am using latest WP with GeneratePress theme and Block editor.
Let me know if you need more information
-
Something that would definitely help with testing/confirmation would be a copy of your CMB2 configuration code at the moment. If you have a lot of fields being added at the moment, then just a stripped down to just the essentials version that is still presenting the issue would be ideal.
This way I could try it out on my local and see what I can manage to recreate, if anything.
<?php add_action( 'cmb2_admin_init', function() { /** * Create new instance of cmb2 meta box for slider fields */ $cmb = new_cmb2_box( array( 'id' => 'slider_metabox', 'title' => __( 'Slider Setting', 'ApuestasFree' ), 'object_types' => array( 'post', 'page' ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left ) ); $cmb->add_field( array( 'name' => __( 'Display Slider', 'ApuestasFree' ), 'desc' => __( 'Whether to display slider on this page or not', 'ApuestasFree' ), 'id' => 'display_slider', 'type' => 'checkbox', ) ); $cmb->add_field( array( 'name' => __( 'Slider Start Time', 'ApuestasFree' ), 'desc' => __( 'Display slider on this page from given time', 'ApuestasFree' ), 'id' => 'slider_start_time', 'type' => 'text_datetime_timestamp_timezone', 'attributes' => array( // CMB2 checks for datepicker override data here: 'data-datepicker' => json_encode( array( 'dateFormat' => 'dd-mm-yy', 'minDate' => 'now', ) ), ), ) ); $cmb->add_field( array( 'name' => __( 'Slider End Time', 'ApuestasFree' ), 'desc' => __( 'Display slider on this page till given time', 'ApuestasFree' ), 'id' => 'slider_end_time', 'type' => 'text_datetime_timestamp_timezone', 'attributes' => array( // CMB2 checks for datepicker override data here: 'data-datepicker' => json_encode( array( 'dateFormat' => 'dd-mm-yy', 'minDate' => 'now', ) ), ), ) ); $cmb->add_field( array( 'name' => __( 'Display Caption', 'ApuestasFree' ), 'desc' => __( 'Whether to display caption slider below the image slider or not', 'ApuestasFree' ), 'id' => 'display_caption', 'type' => 'checkbox', ) ); $cmb->add_field( array( 'name' => __( 'Autoplay Speed', 'ApuestasFree' ), 'desc' => __( 'Please write interger value in milliseconds, default 3000', 'ApuestasFree' ), 'id' => 'autoplaySpeed', 'default' => '3000', 'type' => 'text', ) ); $cmb->add_field( array( 'name' => __( 'Slider Location', 'ApuestasFree' ), 'desc' => __( 'Where to display slider on this page', 'ApuestasFree' ), 'id' => 'slider_location', 'type' => 'select', 'default' => 'generate_after_header', // The key of the options array are the hook names available into GeneratePress Theme 'options' => array( 'generate_before_header' => __( 'Before Header', 'ApuestasFree' ), 'generate_after_header' => __( 'After Header', 'ApuestasFree' ), 'generate_inside_site_container' => __( 'Inside Site Container', 'ApuestasFree' ), 'generate_inside_container' => __( 'Inside Container', 'ApuestasFree' ), 'generate_before_main_content' => __( 'Before Main Content', 'ApuestasFree' ), 'generate_after_main_content' => __( 'After Main Content', 'ApuestasFree' ), 'use_as_shortcode' => __( 'Use as Shortcode', 'ApuestasFree' ) ), ) ); $cmb->add_field( array( 'name' => __( 'Shortcode Name', 'ApuestasFree' ), 'desc' => __( 'Use this shortcode when location set as -Use as Shortcode- option', 'ApuestasFree' ), 'id' => 'shortcode_name', 'default' => '[shortcode_slider]', 'type' => 'text', 'attributes' => array( 'readonly' => 'readonly', 'onfocus' => 'this.select();', 'onmouseup' => 'return false;' ), 'save_field' => false, ) ); $group_field_id = $cmb->add_field( array( 'id' => 'slides_group', 'type' => 'group', 'description' => __( 'Add slides here', 'ApuestasFree' ), 'repeatable' => true, 'options' => array( 'group_title' => __( 'Slide {#}', 'ApuestasFree' ), 'add_button' => __( 'Add Another Slide', 'ApuestasFree' ), 'remove_button' => __( 'Remove Slide', 'ApuestasFree' ), 'sortable' => true, ), ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Slide Image', 'ApuestasFree' ), 'id' => 'slide_image', 'type' => 'file', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Slide Caption', 'ApuestasFree' ), 'id' => 'slide_caption', 'type' => 'text' ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Slide Link', 'ApuestasFree' ), 'id' => 'slide_link', 'type' => 'text_url', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Open in new window', 'ApuestasFree' ), 'id' => 'open_new_tab', 'type' => 'checkbox', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Slide Content', 'ApuestasFree' ), 'desc' => __( 'This will show above slide image', 'ApuestasFree' ), 'id' => 'slide_content', 'type' => 'title', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Bethouse Logo', 'ApuestasFree' ), 'id' => 'bethouse_logo', 'type' => 'file', // Optional: 'options' => array( 'url' => false, ), 'query_args' => array( // only allow gif, jpg, or png images 'type' => array( 'image/gif', 'image/jpg', 'image/jpeg', 'image/png', ), ), 'preview_size' => 'thumbnail', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Call To Action', 'ApuestasFree' ), 'desc' => __( 'Call to action button text', 'ApuestasFree' ), 'id' => 'call_to_action', 'type' => 'text', // 'default' => __( 'Claim Now', 'ApuestasFree' ), ) ); $cmb->add_group_field( $group_field_id, array( 'name' => __( 'Legal Text', 'ApuestasFree' ), 'desc' => __( 'Bethouse legal text, T&C text to join bethouse', 'ApuestasFree' ), 'id' => 'legal_text', 'type' => 'textarea_small', ) ); } );
I have these fields for Slider, please let me know if you need anything else
Thanks. Will aim to circle back to this as soon as I can and see what may be going on.
Not quite sure why it’s happening off the top of my head, but when i changed the dashes to be
/
characters, it worked and saved as expected.So instead of
dd-mm-yy
it wasdd/mm/yy
Not sure if this is a detail you’re willing to go with, but it would work at the moment.
-
This reply was modified 3 years, 12 months ago by
Michael Beckwith.
Also seeing similar things over on GitHub regarding formatting of date pickers https://github.com/CMB2/CMB2/issues?q=is%3Aissue+is%3Aopen+datepicker
Yes, I can go with
/
and its workingbut now I am very much confused with the field value, it saves value according to PHP server not according to timezone selected into WordPress site setting.
Basically I am saving a start time and end time into database so whenever user visit site if the current time ( client side through JavaScript ) lies between them then display slider else hide. On local server it worked well but when I put code on remote server my current time never lies between start time and end time even I chose correct time period
For e.g. I am saving date time according to Indian timezone but when I see the database on remote server which is hosted into Spain, the datetime object shows date time according to Spain server. So my current time never lies between start time and end time
According to me, if timezone is given then the date time should be saved according to timezone given not according to server timezone.
I even tried to convert utc timestamp into given timezone but don’t know why it not working as expected
Not sure what to suggest there other than configuring your server, regardless of where it’s hosted, to use the intended time relative to where you expect most things to apply. For example, if it’s all local events only, and not also showing information that could also be relative to Spain, or Australia, or the United states, set the server to use your own timezone.
I have managed to get correct timestamp by adding offset into UTC timestamp. Thanks for your support
Just after setting this issue resolved I found another bug which the client faced, I fixed it too but I think other plugin users must know if they encounter this problem.
Client is from Spain, their date format is dd/mm/yy so the datepicker set the date into dd/mm/yy and when he saved the post, the date changed to some date of year 2022, I fixed it by below code
// CMB2 checks for datepicker override data here: 'data-datepicker' => json_encode( array( 'dateFormat' => 'mm/dd/yy', 'minDate' => 'now', ) ),
So we have to explicitly set
dateFormat
if working into different timezonesThanks for the followups @vikas_khunteta
-
This reply was modified 3 years, 12 months ago by
- The topic ‘Bug in text_datetime_timestamp_timezone field’ is closed to new replies.