Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active October 19, 2022 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklasen/7931140ed5499abf7dc8207ab6df40f8 to your computer and use it in GitHub Desktop.
Save mklasen/7931140ed5499abf7dc8207ab6df40f8 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: CMB2 text_datetime_timestamp_timezone Test
* Test file for CMB2 Bug Report: https://github.com/CMB2/CMB2/issues/1465
*/
add_action(
'cmb2_admin_init',
function() {
$details = new_cmb2_box(
array(
'id' => 'cmb2_test',
'title' => __( 'Details', 'cmb2' ),
'object_types' => array( 'post' ),
)
);
$details->add_field(
array(
'name' => 'Date',
'type' => 'text_datetime_timestamp_timezone',
'id' => 'date',
'after_field' => function() {
$serialized_date = get_post_meta( get_the_ID(), 'date', true );
if ( ! empty( $serialized_date ) ) {
$date = maybe_unserialize( $serialized_date );
echo '<br><br>Date/Time: ' . $date->format( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) . ' e' ) . '<br>';
}
},
)
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment