Last active
October 19, 2022 09:21
-
-
Save mklasen/7931140ed5499abf7dc8207ab6df40f8 to your computer and use it in GitHub Desktop.
A test gist for https://github.com/CMB2/CMB2/issues/1465
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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