Last active
February 3, 2023 15:01
-
-
Save slaFFik/892f969afba7616dc60a3425392d558b to your computer and use it in GitHub Desktop.
WPForms: new smart tag - current date and time, also Unix timestamp
This file contains 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 | |
// 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