{"id":141,"date":"2020-04-30T11:12:00","date_gmt":"2020-04-30T05:42:00","guid":{"rendered":"https:\/\/codexcoach.com\/?p=50"},"modified":"2023-01-30T07:42:53","modified_gmt":"2023-01-30T07:42:53","slug":"wordpress-register-form-without-plugin","status":"publish","type":"post","link":"https:\/\/codexcoach.com\/wordpress-register-form-without-plugin\/","title":{"rendered":"WordPress Register Form Without Plugin"},"content":{"rendered":"\n<p>Are you need simple register form without plugin for your WordPress website? Yes, Then i have created <strong>[cxc_register_form]<\/strong> shortcode with quick simple code. So you can add register form anywhere like in Pages, Posts and Widget etc\u2026 Therefore you just need to put <strong>[cxc_register_form]<\/strong> shortcode where you need register form. So you need to follow below steps.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-twentytwentyone-border\"><img loading=\"lazy\" width=\"1223\" height=\"395\" src=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/screenshot-webbydemo.in-2022.11.29-15_51_35.png\" alt=\"\" class=\"wp-image-1366\" srcset=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/screenshot-webbydemo.in-2022.11.29-15_51_35.png 1223w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/screenshot-webbydemo.in-2022.11.29-15_51_35-300x97.png 300w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/screenshot-webbydemo.in-2022.11.29-15_51_35-1024x331.png 1024w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/screenshot-webbydemo.in-2022.11.29-15_51_35-768x248.png 768w\" sizes=\"(max-width: 1223px) 100vw, 1223px\" \/><\/figure>\n\n\n\n<h2>Code for shortcode.<\/h2>\n\n\n\n<p>You need to put below code in theme&#8217;s <strong>functions.php<\/strong> file. If you have created child theme then add this in function file of child theme.<\/p>\n\n\n\n<h2><strong>Register Form | Shortcode: [cxc_register_form]<\/strong><\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"functoion.php\" data-lang=\"PHP\"><code>&lt;?php\n  add_shortcode( &#39;cxc_register_form&#39;, &#39;cxc_register_form_callback&#39; );\n\nfunction cxc_register_form_callback() {\n\tob_start();\n\n\tif ( !is_user_logged_in() ) {\n\n\t\tglobal $registrationError, $registrationSuccess;\n\n\t\tif ( !empty( $registrationError ) ) {\n\t\t\t?&gt;\n\t\t\t&lt;div class=&quot;alert alert-danger&quot;&gt;\n\t\t\t\t&lt;?php echo $registrationError; ?&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;?php } ?&gt;\n\n\t\t&lt;?php if ( !empty( $registrationSuccess ) ) { ?&gt;\n\t\t\t&lt;br\/&gt;\n\t\t\t&lt;div class=&quot;alert alert-success&quot;&gt;\n\t\t\t\t&lt;?php echo $registrationSuccess; ?&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;?php } ?&gt;\n\n\t\t&lt;form method=&quot;post&quot; class=&quot;wc-register-form&quot;&gt;\n\t\t\t&lt;div class=&quot;register_form&quot;&gt;\n\t\t\t\t&lt;div class=&quot;log_user&quot;&gt;\n\t\t\t\t\t&lt;label for=&quot;user_name&quot;&gt;User name&lt;\/label&gt;\n\t\t\t\t\t&lt;?php $user_name = isset($_POST[&#39;user_name&#39;]) ? $_POST[&#39;user_name&#39;] : &#39;&#39;; ?&gt;\n\t\t\t\t\t&lt;input type=&quot;text&quot; name=&quot;user_name&quot; id=&quot;user_name&quot; value=&quot;&lt;?php echo $user_name; ?&gt;&quot; \/&gt;\n\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t&lt;div class=&quot;log_user&quot;&gt;\n\t\t\t\t\t&lt;label for=&quot;user_email&quot;&gt;Email address&lt;\/label&gt;\n\t\t\t\t\t&lt;?php $user_email = isset($_POST[&#39;user_email&#39;]) ? $_POST[&#39;user_email&#39;] : &#39;&#39;; ?&gt;\n\t\t\t\t\t&lt;input type=&quot;email&quot; name=&quot;user_email&quot; id=&quot;user_email&quot; value=&quot;&lt;?php echo $user_email; ?&gt;&quot; \/&gt;\n\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t&lt;div class=&quot;log_pass&quot;&gt;\n\t\t\t\t\t&lt;label for=&quot;user_password&quot;&gt;Password&lt;\/label&gt;\n\t\t\t\t\t&lt;input type=&quot;password&quot; name=&quot;user_password&quot; id=&quot;user_password&quot; \/&gt;\n\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t&lt;div class=&quot;log_pass&quot;&gt;\n\t\t\t\t\t&lt;label for=&quot;user_cpassword&quot;&gt;Password again&lt;\/label&gt;\n\t\t\t\t\t&lt;input type=&quot;password&quot; name=&quot;user_cpassword&quot; id=&quot;user_cpassword&quot; \/&gt;\n\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t&lt;div class=&quot;log_pass&quot;&gt;\n\t\t\t\t\t&lt;?php\n\t\t\t\t\tob_start();\n\t\t\t\t\tdo_action( &#39;register_form&#39; );\n\t\t\t\t\techo ob_get_clean();\n\t\t\t\t\t?&gt;\n\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t&lt;div class=&quot;log_user&quot;&gt;\n\t\t\t\t\t&lt;?php wp_nonce_field( &#39;userRegister&#39;, &#39;formType&#39; ); ?&gt;\n\t\t\t\t\t&lt;button type=&quot;submit&quot; class=&quot;register_user&quot;&gt;Register&lt;\/button&gt;\n\t\t\t\t&lt;\/div&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;\/form&gt;\n\t\t&lt;?php\n\t} else {\n\t\techo &#39;&lt;p class=&quot;error-logged&quot;&gt;You are already logged in.&lt;\/p&gt;&#39;;\n\t}\n\t$register_form = ob_get_clean();\n\treturn $register_form;\n}\n?&gt;<\/code><\/pre><\/div>\n\n\n\n<h2>Code for Register<\/h2>\n\n\n\n<p>In this code i am validating form and sign up in WordPress on <strong>wp<\/strong> action. Add it in <strong>functions.php<\/strong> file after above code. If this code will not work then change action <strong>wp<\/strong> to <strong>init<\/strong>.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"function.php\" data-lang=\"PHP\"><code>&lt;?php\nadd_action( &#39;wp&#39;, &#39;cxc_user_register_callback&#39; );\n\nfunction cxc_user_register_callback() {\n\tif ( isset( $_POST[&#39;formType&#39;] ) && wp_verify_nonce( $_POST[&#39;formType&#39;], &#39;userRegister&#39;) ) {\n\n\t\tglobal $registrationError, $registrationSuccess;\n\n\t\t$u_name = trim( $_POST[&#39;user_name&#39;] );\n\t\t$u_email = trim( $_POST[&#39;user_email&#39;] );\n\t\t$u_pwd = trim( $_POST[&#39;user_password&#39;] );\n\t\t$u_cpwd = trim( $_POST[&#39;user_cpassword&#39;] );\n\n\t\tif ( $u_name == &#39;&#39; ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Enter User name.,&#39;;\n\t\t}\n\n\t\tif ( username_exists( $u_name ) ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Username In Use!.,&#39;;\n\t\t}\n\n\t\tif ( $u_email == &#39;&#39; ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Enter Email.,&#39;;\n\t\t}\n\n\t\tif ( $u_pwd == &#39;&#39; || $u_cpwd == &#39;&#39; ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Enter Password.,&#39;;\n\t\t}\n\n\t\tif ( strlen( $u_pwd ) &lt; 7) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Use minimum 7 character in password.,&#39;;\n\t\t}\n\n\t\tif ( $u_pwd != $u_cpwd ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Password are not matching.,&#39;;\n\t\t}\n\n\t\tif ( $u_email != &#39;&#39; && !is_email( $u_email ) ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; Invalid e-mail address.,&#39;;\n\t\t}\n\n\t\tif ( email_exists( $u_email ) != false ) {\n\t\t\t$registrationError .= &#39;&lt;strong&gt;Error! &lt;\/strong&gt; This Email is already registered.,&#39;;\n\t\t}\n\n\t\t$registrationError = trim( $registrationError, &#39;,&#39; );\n\t\t$registrationError = str_replace( &quot;,&quot;, &quot;&lt;br\/&gt;&quot;, $registrationError );\n\n\t\tif ( empty( $registrationError ) ) {\n\n\t\t\t$user_login = $u_name;\n\t\t\t$user_email = $u_email;\n\n\t\t\t$userdata = array(\n\t\t\t\t&#39;user_login&#39; =&gt; $user_login,\n\t\t\t\t&#39;user_pass&#39; =&gt; $u_pwd,\n\t\t\t\t&#39;user_email&#39; =&gt; $user_email\n\t\t\t);\n\n\t\t\t$user_id = wp_insert_user( $userdata );\n\n\t\t\tif ( is_wp_error( $user ) ) {\n\t\t\t\t$registrationError = $user-&gt;get_error_message();\n\t\t\t} else {\n\t\t\t\t$registrationSuccess = &#39;&lt;strong&gt;Success! &lt;\/strong&gt; Application submitted. Please wait for user approval.&#39;;\t\n\t\t\t\t$user = get_userdata( $user_id );\t\t\t\t\t\t\n\t\t\t\twp_set_current_user( $user-&gt;ID );\n\t\t\t\twp_set_auth_cookie( $user-&gt;ID );\n\t\t\t\tdo_action( &#39;wp_login&#39;, $user-&gt;user_login, $user );\n\t\t\t\twp_redirect( site_url() );\n\t\t\t\texit;\n\t\t\t}\n\t\t}\n\t}\n}\n?&gt;<\/code><\/pre><\/div>\n<div id=\"ezoic-pub-ad-placeholder-118\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Are you need simple register form without plugin for your WordPress website? Yes, Then i have created [cxc_register_form] shortcode with quick simple code. So you can add register form anywhere like in Pages, Posts and Widget etc\u2026 Therefore you just need to put [cxc_register_form] shortcode where you need register form. So you need to follow [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":2515,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_aib_schema_json_ld":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/141"}],"collection":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":3,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":1976,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/141\/revisions\/1976"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/media\/2515"}],"wp:attachment":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}