{"id":8098,"date":"2013-01-11T22:25:18","date_gmt":"2013-01-11T22:25:18","guid":{"rendered":"http:\/\/2slick.com\/web\/?p=8098"},"modified":"2013-01-11T22:44:39","modified_gmt":"2013-01-11T22:44:39","slug":"send-username-contact-form-7","status":"publish","type":"post","link":"https:\/\/2slick.com\/web\/send-username-contact-form-7\/affordablewebsitestips\/tutorials","title":{"rendered":"Send username Contact Form 7"},"content":{"rendered":"<p>Many WordPress websites include user registration and login functionality, and it's nice to include the username of the person&nbsp;submitting&nbsp;the form.&nbsp;In this tutorial I will show you how to have the username&nbsp;automatically&nbsp;send with a Contact Form 7 form submission.&nbsp;&nbsp;If you don't know what <a title=\"contact form 7\" href=\"http:\/\/contactform7.com\/\" target=\"_blank\">Contact Form 7<\/a> is, it's a popular WordPress plugin that allows you to create custom email forms on your WordPress website.<\/p>\n<p>Contact Form 7 has what are called '<a title=\"special mail tags\" href=\"http:\/\/contactform7.com\/special-mail-tags\/\" target=\"_blank\">Special Mail Tags<\/a>' built in to the plugin. The user optionally enters these special mail tags into the 'Message body' section of the Contact Form 7 admin when creating and editing custom forms. In the tutorial below I will show you how to add a new custom 'Special Mail Tag' allowing you to include the logged in username in the form message.<\/p>\n<h3>Creating a custom 'username' Special Mail Tag in Contact Form 7<\/h3>\n<ol>\n<li>Log into WordPress and make sure you have the Contact Form 7 plugin installed.<\/li>\n<li>Click on 'Plugins'.<\/li>\n<li>Click on 'Edit' under the 'Contact Form 7' plugin.<\/li>\n<li>Click on the link 'contact-form-7\/modules\/special-mail-tags.php' on the right side of the page.<\/li>\n<li>Somewhere in the source code enter this code snippet:<!--DEVFMTCODE--><pre class=\"devcodeblock\" title=\"PHP\"><table class=\"devcodetools\"><tbody><tr><td>&nbsp;PHP&nbsp;|&nbsp;<\/td><td style=\"background-image:url('https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/img\/devformatter-copy.png');background-repeat:no-repeat;background-position:50% 50%;width:16px;height:16px;\"\/><embed id=\"ZeroClipboard1\" src=\"https:\/\/2slick.com\/web\/wp-content\/plugins\/devformatter\/_zclipboard.swf\" loop=\"false\" menu=\"false\" quality=\"best\" bgcolor=\"#ffffff\" width=\"16px\" height=\"16px\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" flashvars=\"id=1&width=16&height=16\" wmode=\"transparent\" \/><\/td><td>&nbsp;copy&nbsp;code&nbsp;|<\/td><td style=\"cursor:pointer\" title=\"DevFormatter Plugin\" onclick=\"devfmt_credits()\">?<\/td><td width=\"99%\">&nbsp;<\/td><\/tr><\/tbody><\/table><div class=\"devcodeoverflow\"><table class=\"devcodearea\" width=\"100%\"><tr><td class=\"devcodelines\" width=\"1%\">01<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">02<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\">add_filter<span style=\"color: #009900;\">&#40;<\/span> <span style=\"color: #0000ff;\">'wpcf7_special_mail_tags'<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000ff;\">'wpcf7_special_mail_tag_userdata'<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #cc66cc;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #cc66cc;\">2<\/span> <span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">03<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\">&nbsp;<\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">04<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"><span style=\"color: #000000; font-weight: bold;\">function<\/span> wpcf7_special_mail_tag_userdata<span style=\"color: #009900;\">&#40;<\/span> <span style=\"color: #000088;\">$output<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #000088;\">$name<\/span> <span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">05<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\">&nbsp;<\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">06<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"> <span style=\"color: #666666; font-style: italic;\">\/\/ For backwards compat.<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">07<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"> <span style=\"color: #000088;\">$name<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #990000;\">preg_replace<\/span><span style=\"color: #009900;\">&#40;<\/span> <span style=\"color: #0000ff;\">'\/^wpcf7\\.\/'<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000ff;\">'_'<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #000088;\">$name<\/span> <span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">08<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\">&nbsp;<\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">09<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"> <span style=\"color: #000000; font-weight: bold;\">global<\/span> <span style=\"color: #000088;\">$current_user<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">10<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\">&nbsp;<\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">11<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"> <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span> <span style=\"color: #0000ff;\">'user_login'<\/span> <span style=\"color: #339933;\">==<\/span> <span style=\"color: #000088;\">$name<\/span> <span style=\"color: #009900;\">&#41;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">12<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"> <span style=\"color: #000088;\">$output<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #000088;\">$current_user<\/span><span style=\"color: #339933;\">-&gt;<\/span><span style=\"color: #004000;\">user_login<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">13<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\">&nbsp;<\/pre><\/td><\/tr><tr><td class=\"devcodelines devcodelinesodd devcodelinesodd\" width=\"1%\">14<\/td><td class=\"devcodelinesarea devcodelinesareaodd devcodelinesareaodd\"><pre class=\"devcode devcodeline\"> <span style=\"color: #b1b100;\">return<\/span> <span style=\"color: #000088;\">$output<\/span><span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><tr><td class=\"devcodelines\" width=\"1%\">15<\/td><td class=\"devcodelinesarea\"><pre class=\"devcode devcodeline\"><span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div><\/pre><!--END_DEVFMTCODE--><\/li>\n<li>Click the 'Update File' button.<\/li>\n<\/ol>\n<h3>Make a form include the username of the logged in user<\/h3>\n<ol>\n<li>Click on the 'Contact' tab.<\/li>\n<li>From the list of 'Contact Form 7' forms, click the one you want to edit so that the username sends with the form data.<\/li>\n<li>Enter the tag&nbsp;[user_login] somewhere in your 'Message body' field, and it will automatically be replaced with the username of the person sending the form, if they are logged in.\n<p><strong>Example:<\/strong> \"Username: [user_login] \"&nbsp;<\/li>\n<li>Click the 'Save' button.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many WordPress websites include user registration and login functionality, and it&#8217;s nice to include the username of the person&nbsp;submitting&nbsp;the form.&nbsp;In this tutorial I will show you how to have the username&nbsp;automatically&nbsp;send with a Contact Form 7 form submission.&nbsp;&nbsp;If you don&#8217;t know what Contact Form 7 is, it&#8217;s a popular WordPress plugin that allows you to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7792,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[285,143,4,492,6],"tags":[312,503,69],"class_list":["post-8098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-affordablewebsitestips","category-internet-tips","category-tutorials","category-websites-2","category-wordpress","tag-contact-form-7","tag-username","tag-wordpress-2"],"_links":{"self":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/comments?post=8098"}],"version-history":[{"count":8,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8098\/revisions"}],"predecessor-version":[{"id":8100,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8098\/revisions\/8100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/media\/7792"}],"wp:attachment":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/media?parent=8098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/categories?post=8098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/tags?post=8098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}