Skip to content

Instantly share code, notes, and snippets.

@ihslimn
Last active December 15, 2023 21:05
Show Gist options
  • Save ihslimn/e953cf7e848e01ef06c66bfda26b42b7 to your computer and use it in GitHub Desktop.
Save ihslimn/e953cf7e848e01ef06c66bfda26b42b7 to your computer and use it in GitHub Desktop.
Format date string macro
add_filter( 'jet-engine/listings/macros-list', 'register_format_date_string_macro' );
function register_format_date_string_macro( $macros_list ) {
$macros_list['format_date'] = array(
'label' => 'Format date string',
'cb' => '_get_format_date_string',
'args' => array( 'format' => array(
'label' => 'Format',
'type' => 'text',
),
'date_string' => array(
'label' => 'Date string',
'type' => 'text',
),
),
);
return $macros_list;
}
function _get_format_date_string( $field_value = null, $args ) {
$args = explode( '|', $args );
$format = $args[0];
$date_string = $args[1];
$timestamp = strtotime( $date_string ) + get_option( 'gmt_offset' )*3600;
return wp_date( $format, $timestamp );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment