{"id":417,"date":"2011-11-08T15:59:07","date_gmt":"2011-11-08T15:59:07","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=417"},"modified":"2011-11-08T16:04:55","modified_gmt":"2011-11-08T16:04:55","slug":"customizing-wordpress-comments-form","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/customizing-wordpress-comments-form\/","title":{"rendered":"Customizing the WordPress comments form"},"content":{"rendered":"<p>There are numerous plugins out there that enhance the &quot;outta-the-box&quot; WordPress comments form in various ways. But, if you are looking for very specific functionality, you may not have considered simply creating your own from scratch.<\/p>\n<p>You&#39;ve no doubt heard about all the negatives to customizing any files within the WordPress &quot;core&quot;, as they would be overwritten by any upgrade you apply.<\/p>\n<p>But, by creating your own comments form within your theme&#39;s loop-single.php or single.php, you can get around this issue.<\/p>\n<p>High-level, we need three things:<\/p>\n<ol>\n<li>To modify the loop-single.php or single.php file and add our own comments form.<\/li>\n<li>In WordPress Admin -&gt; Discussion, turn off allowing new comments (essentially hiding the default WordPress comments form)<\/li>\n<li>Create your own script for validating, then adding the comment to the WordPress comments table.<\/li>\n<\/ol>\n<h3>Creating the comments form:<\/h3>\n<p><code>&lt;form action=&quot;\/your_comments_processing_scipt.php&quot; method=&quot;post&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;input type=&quot;hidden&quot; name=&quot;came_from&quot; value=&quot;&lt;?php echo $_SERVER[&#39;REDIRECT_URL&#39;]; ?&gt;&quot; \/&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;input type=&quot;hidden&quot; name=&quot;post_id&quot; value=&quot;&lt;?php echo $post-&gt;ID; ?&gt;&quot; \/&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;label for=&quot;comment-fullname&quot;&gt;Name&lt;\/label&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;input type=&quot;text&quot; name=&quot;fullname&quot; id=&quot;comment-fullname&quot; value=&quot;&lt;?php echo $_REQUEST[&#39;fullname&#39;]; ?&gt;&quot; \/&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;label for=&quot;comment-email&quot;&gt;Email&lt;\/label&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;input type=&quot;email&quot; name=&quot;email&quot; id=&quot;comment-email&quot; value=&quot;&lt;?php echo $_REQUEST[&#39;email&#39;]; ?&gt;&quot; \/&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;label for=&quot;comment-text&quot;&gt;Comment&lt;\/label&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;textarea name=&quot;comment&quot; id=&quot;comment-text&quot;&gt;&lt;?php echo $_REQUEST[&#39;comment&#39;]; ?&gt;&lt;\/textarea&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; \/&gt;<br \/>\n\t&lt;\/form&gt;<\/p>\n<p>\t<\/code><\/p>\n<h3>The Processing Script<\/h3>\n<p><code>&lt;?php<br \/>\n\t\/\/ your validation goes here<\/p>\n<p>\trequire(&#39;wp-config.php&#39;);<br \/>\n\t$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);<br \/>\n\tmysql_select_db(DB_NAME);<br \/>\n\t<\/code><\/p>\n<p><code><br \/>\n\t$sql = &quot;INSERT INTO wp_comments<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_post_ID,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_author,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_author_email,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_author_url,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_author_IP,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_date,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_date_gmt,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_content,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_karma,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_approved,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_agent,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_type,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comment_parent,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; user_id,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fbconnect<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; VALUES<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {$_REQUEST[&#39;post_id&#39;]},<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;{$_REQUEST[&#39;fullname&#39;]}&#39;,&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;{$_REQUEST[&#39;email&#39;]}&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;{$_SERVER[&#39;REMOTE_ADDR&#39;]}&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NOW(),<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; UTC_TIMESTAMP(),<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;{$_REQUEST[&#39;comment&#39;]}&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;0&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;{$_SERVER[&#39;HTTP_USER_AGENT&#39; ]}&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#39;&#39;,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0,<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )&quot;;<\/p>\n<p>\t$result = mysql_query($sql);<br \/>\n\tmysql_close($conn);<br \/>\n\theader(&#39;Location: &#39; . $_REQUEST[&#39;came_from&#39;]);<br \/>\n\t?&gt; <br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are numerous plugins out there that enhance the &quot;outta-the-box&quot; WordPress comments form in various ways. But, if you are looking for very specific functionality,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[103],"tags":[138],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/417"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":3,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/417\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}