Skip to content

Instantly share code, notes, and snippets.

@scyt
Created May 5, 2020 14:10
Show Gist options
  • Save scyt/40b5f0e4575f33f5ffea29501677c7e9 to your computer and use it in GitHub Desktop.
Save scyt/40b5f0e4575f33f5ffea29501677c7e9 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Time Merge Tags
<?php
/**
* Gravity Wiz // Gravity Forms // Time Merge Tags
*
* Adds {time_hh}, {time_hh:12}, {time_hh:24}, {time_mm}, and {time_am_pm} merge tags.
*
* @version 1.0
* @author Ryan Donovan <ryan@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
* @copyright 2020 Gravity Wiz
*
* Usage:
*
* {time_hh} 12-hour format of an hour with leading zeros
* {time_hh:12} 12-hour format of an hour with leading zeros
* {time_hh:24} 24-hour format of an hour with leading zeros
* {time_mm} Minutes with leading zeros
* {time_am_pm} Uppercase Ante meridiem and Post meridiem
*
*/
add_filter( 'gform_replace_merge_tags', 'gwiz_current_time_merge_tags', 10 );
function gwiz_current_time_merge_tags( $text ) {
$local_timestamp = GFCommon::get_local_timestamp( time() );
$time_hh = date( 'h', $local_timestamp );
$time_hh_24 = date( 'H', $local_timestamp );
$time_mm = date( 'i', $local_timestamp );
$time_am_pm = date( 'A', $local_timestamp );
$text = str_replace( '{time_hh}', $time_hh, $text );
$text = str_replace( '{time_hh:12}', $time_hh, $text );
$text = str_replace( '{time_hh:24}', $time_hh_24, $text );
$text = str_replace( '{time_mm}', $time_mm, $text );
$text = str_replace( '{time_am_pm}', $time_am_pm, $text );
return $text;
}
@frankprim
Copy link

Hi
I need the function for the date perhaps there is this code already I have only so far nothing found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment