Home / Archive / WPForms: new smart tag – Current Unix Time
Duplicate Snippet

Embed Snippet on Your Site

WPForms: new smart tag – Current Unix Time

Using wp_date() function to output a Unix time where the smart tag is used.

Code Preview
php
<?php
// 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 );

Comments

Add a Comment