Extra Smart Tags for WPForms
Adds {current_year}, {user_role} and {site_name_plain} smart tags you can use in WPForms notifications, confirmations and default values.
Opens WPIDE on
Code
add_filter( 'wpforms_smart_tags', function ( $tags ) {
$tags['current_year'] = 'Current Year';
$tags['user_role'] = 'User Role';
$tags['site_name_plain'] = 'Site Name (plain text)';
return $tags;
} );
add_filter( 'wpforms_smarttags_process_value', function ( $value, $tag_name ) {
switch ( $tag_name ) {
case 'current_year':
return wp_date( 'Y' );
case 'user_role':
$roles = is_user_logged_in() ? (array) wp_get_current_user()->roles : array();
return $roles ? (string) reset( $roles ) : '';
case 'site_name_plain':
return wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
}
return $value;
}, 10, 2 );
Notes
The tags appear in the Smart Tags list of the form builder.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.