Create smart tags for post taxonomy tags to be used in WP Forms 🙂
/**
* Create Post Tags Smart Tags.
*
* @link https://wpforms.com/developers/how-to-create-more-user-smart-tags/
*/
function wpf_dev_register_user_profile_smart_tags ( $tags ) {
// Key is the tag, item is the tag name.
$tags[ 'wp_post_tags' ] = 'Post Tags';
return $tags;
}
add_filter( 'wpforms_smart_tags', 'wpf_dev_register_user_profile_smart_tags', 10, 1 );
/**
* Process the User Smart Tags from the tags taxonomy
*
* @link https://wpforms.com/developers/how-to-create-more-user-smart-tags/
*/
function wpf_dev_process_user_profile_smart_tags( $content, $tag ) {
if ( 'wp_post_tags' === $tag ) {
$wp_post_tag = get_the_tags();
foreach($wp_post_tag as $wp_post_tags) {
return $wp_post_tags->name;
}
$content = str_replace( '{wp_post_tags}', $wp_post_tag, $content );
}
return $content;
}
add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_user_profile_smart_tags', 10, 2 );