Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Last active February 3, 2023 15:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save slaFFik/892f969afba7616dc60a3425392d558b to your computer and use it in GitHub Desktop.
WPForms: new smart tag - current date and time, also Unix timestamp
<?php
// Register the smart tag.
add_filter( 'wpforms_smart_tags', static function( $tags ) {
// Key is the tag, value is the tag name.
$tags['current_time'] = 'Current Date/Time';
return $tags;
} );
// Replace its value on form render on front-end.
add_filter( 'wpforms_process_smart_tags', static function( $field_val, $form_data ) {
return str_replace( '{current_time}', date_i18n( 'Y-m-d H:i:s' ), $field_val );
}, 10, 2 );
// Register the smart tag.
add_filter( 'wpforms_smart_tags', static function( $tags ) {
// Key is the tag, value is the tag name.
$tags['current_unix_time'] = 'Current Unix Time';
return $tags;
} );
// Replace its value on form render on front-end.
add_filter( 'wpforms_process_smart_tags', static function( $field_val, $form_data ) {
return str_replace( '{current_unix_time}', wp_date( 'U' ), $field_val );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment