Guest User

Untitled

a guest
Jul 2nd, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.52 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Bootstrap Registration
  4. Plugin URI: #
  5. Description: .
  6. Version: 1.0
  7. Author: Hammad Hassan Hashmi
  8. Author URI:
  9. License: GPLv2 or later
  10. */
  11.  
  12. function bootstrap_reg_install(){
  13. global $wpdb;
  14. $table_name = $wpdb->prefix . "bootstrap_registartion";
  15. $charset_collate = $wpdb->get_charset_collate();
  16. $sql = "CREATE TABLE IF NOT EXISTS $table_name (
  17. id mediumint(11) NOT NULL AUTO_INCREMENT,
  18. username VARCHAR(50) NOT NULL,
  19. fullname VARCHAR(255) NOT NULL,
  20. email VARCHAR(255) NOT NULL,
  21. phone VARCHAR(255) NOT NULL,
  22. identitynumber VARCHAR(255) NOT NULL,
  23. address VARCHAR(255) NOT NULL,
  24. postcode VARCHAR(255) NOT NULL,
  25. city VARCHAR(255) NOT NULL,
  26. country VARCHAR(255) NOT NULL,
  27. password VARCHAR(255) NOT NULL,
  28. regDate DATETIME DEFAULT CURRENT_TIMESTAMP,
  29. PRIMARY KEY (id)
  30. ) $charset_collate;";
  31. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  32. dbDelta( $sql );
  33. }
  34. register_activation_hook( __FILE__, 'bootstrap_reg_install' );
  35.  
  36. function bootstrap_reg_uninstall(){
  37. global $wpdb;
  38. $table_name = $wpdb->prefix . "bootstrap_registartion";
  39. $sql = "DROP TABLE IF EXISTS $table_name;";
  40. $wpdb->query($sql);
  41. }
  42. register_deactivation_hook( __FILE__, 'bootstrap_reg_uninstall' );
  43.  
  44. add_action('init', 'bootstrapReg_script');
  45. function bootstrapReg_script(){
  46. wp_register_script( 'bootstrap-js', plugins_url('/assets/bootstrap.min.js', __FILE__), array('jquery'), '2.5.1' );
  47. wp_register_style( 'bootstrap', plugins_url('/assets/bootstrap.min.css', __FILE__), false, '1.0.0', 'all');
  48. }
  49.  
  50. // use the registered jquery and style above
  51. add_action('wp_enqueue_scripts', 'bootstrapReg_enqueue_style');
  52. function bootstrapReg_enqueue_style(){
  53. wp_enqueue_script('bootstrap-js');
  54. wp_enqueue_style( 'bootstrap' );
  55. }
  56.  
  57. function bootstrapReg_form_code() {
  58. ?>
  59. <div class="container">
  60. <div class="row main">
  61. <div class="panel-heading">
  62. <div class="panel-title text-center">
  63. <h1 class="title">Company Name</h1>
  64. <hr />
  65. </div>
  66. </div>
  67. <div class="main-login main-center">
  68. <form class="form-horizontal" method="post" action="<?php the_permalink();?>">
  69.  
  70. <div class="form-group">
  71. <label for="username" class="cols-sm-2 control-label">Username</label>
  72. <div class="cols-sm-10">
  73. <div class="input-group">
  74. <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
  75. <input type="text" class="form-control" name="username" id="username" placeholder="Enter your Name"/>
  76. </div>
  77. </div>
  78. </div>
  79.  
  80. <div class="form-group">
  81. <label for="fullname" class="cols-sm-2 control-label">Full Name</label>
  82. <div class="cols-sm-10">
  83. <div class="input-group">
  84. <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
  85. <input type="text" class="form-control" name="fullname" id="fullname" placeholder="Full Name"/>
  86. </div>
  87. </div>
  88. </div>
  89.  
  90. <div class="form-group">
  91. <label for="email" class="cols-sm-2 control-label">Email</label>
  92. <div class="cols-sm-10">
  93. <div class="input-group">
  94. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  95. <input type="text" class="form-control" name="email" id="email" placeholder="Email"/>
  96. </div>
  97. </div>
  98. </div>
  99.  
  100. <div class="form-group">
  101. <label for="phone" class="cols-sm-2 control-label">Phone Number</label>
  102. <div class="cols-sm-10">
  103. <div class="input-group">
  104. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  105. <input type="text" class="form-control" name="phone" id="phone" placeholder="Phone Number"/>
  106. </div>
  107. </div>
  108. </div>
  109.  
  110. <div class="form-group">
  111. <label for="identitynumber" class="cols-sm-2 control-label">Identity Number</label>
  112. <div class="cols-sm-10">
  113. <div class="input-group">
  114. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  115. <input type="text" class="form-control" name="identitynumber" id="identitynumber" placeholder="Identity Number"/>
  116. </div>
  117. </div>
  118. </div>
  119.  
  120. <div class="form-group">
  121. <label for="address" class="cols-sm-2 control-label">Address</label>
  122. <div class="cols-sm-10">
  123. <div class="input-group">
  124. <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
  125. <input type="text" class="form-control" name="address" id="address" placeholder="Address" />
  126. </div>
  127. </div>
  128. </div>
  129.  
  130. <div class="form-group">
  131. <label for="postcode" class="cols-sm-2 control-label">Postal Code</label>
  132. <div class="cols-sm-10">
  133. <div class="input-group">
  134. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  135. <input type="text" class="form-control" name="postcode" id="postcode" placeholder="Postal Code"/>
  136. </div>
  137. </div>
  138. </div>
  139.  
  140. <div class="form-group">
  141. <label for="city" class="cols-sm-2 control-label">City</label>
  142. <div class="cols-sm-10">
  143. <div class="input-group">
  144. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  145. <input type="text" class="form-control" name="city" id="city" placeholder="City" />
  146. </div>
  147. </div>
  148. </div>
  149.  
  150. <div class="form-group">
  151. <label for="country" class="cols-sm-2 control-label">Country</label>
  152. <div class="cols-sm-10">
  153. <div class="input-group">
  154. <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
  155. <input type="text" class="form-control" name="country" id="country" placeholder="Country" />
  156. </div>
  157. </div>
  158. </div>
  159.  
  160. <div class="form-group">
  161. <label for="password" class="cols-sm-2 control-label">Password</label>
  162. <div class="cols-sm-10">
  163. <div class="input-group">
  164. <span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
  165. <input type="password" class="form-control" name="password" id="password" placeholder="Enter your Password"/>
  166. </div>
  167. </div>
  168. </div>
  169.  
  170. <div class="form-group">
  171. <label for="confirm" class="cols-sm-2 control-label">Confirm Password</label>
  172. <div class="cols-sm-10">
  173. <div class="input-group">
  174. <span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
  175. <input type="password" class="form-control" name="confirm" id="confirm" placeholder="Confirm your Password"/>
  176. </div>
  177. </div>
  178. </div>
  179.  
  180. <div class="form-group ">
  181. <input type="submit" name="register" class="btn btn-primary btn-lg btn-block login-button" value="Register">
  182. </div>
  183. </form>
  184. </div>
  185. </div>
  186. </div>
  187. <?php
  188. }
  189.  
  190. function bootstrapReg_registration() {
  191. global $wpdb;
  192. $table_name = $wpdb->prefix . "bootstrap_registartion";
  193. if(isset($_POST['register']) && !empty($_POST['register'])){
  194. $error = array();
  195. $username = sanitize_text_field($_POST["username"] );
  196. $fullname = sanitize_text_field($_POST["fullname"] );
  197. $email = sanitize_email($_POST["email"] );
  198. $phone = sanitize_text_field($_POST["phone"] );
  199. $identitynumber = sanitize_text_field($_POST["identitynumber"] );
  200. $address = sanitize_text_field($_POST["address"] );
  201. $postcode = sanitize_text_field($_POST["postcode"] );
  202. $city = sanitize_text_field($_POST["city"] );
  203. $country = sanitize_text_field($_POST["country"] );
  204. $password = sanitize_text_field($_POST["password"] );
  205. //print_r($_POST);
  206. if(empty($_POST['username'])){
  207. $error[] = "Username can't be empty.";
  208. }
  209. if(empty($_POST['fullname'])){
  210. $error[] = "Full name can't be empty.";
  211. }
  212.  
  213. if(empty($_POST['email'])){
  214. $error[] = "Email can't be empty.";
  215. }
  216.  
  217. if(! is_email($_POST['email'])){
  218. $error[] = "Invalid email address.";
  219. }
  220.  
  221. if(empty($_POST['phone'])) {
  222. $error[] = "Phone number can't be empty.";
  223. }
  224.  
  225. if(!preg_match('/^\(?\+?([0-9]{1,4})\)?[-\. ]?(\d{3})[-\. ]?([0-9]{7})$/', trim($_POST['phone']))) {
  226. $error[] = 'Please enter a valid phone number';
  227. }
  228.  
  229. if (empty($_POST['identitynumber'])) {
  230. $error[] = "Identity number can't be empty.";
  231. }
  232.  
  233. if (preg_match('/[^0-9]/', $_POST['identitynumber'])) {
  234. $error[] = "Please enter a valid identity number.";
  235. }
  236.  
  237. if(empty($_POST['address'])){
  238. $error[] = "Address can't be empty.";
  239. }
  240.  
  241. if(empty($_POST['postcode'])){
  242. $error[] = "Postcode can't be empty.";
  243. }
  244.  
  245. if(preg_match('/[^0-9]/', $_POST['postcode'])){
  246. $error[] = "Please enter a valid Postcode.";
  247. }
  248.  
  249. if(empty($_POST['city'])){
  250. $error[] = "City can't be empty.";
  251. }
  252.  
  253. if(empty($_POST['country'])){
  254. $error[] = "Country can't be empty.";
  255. }
  256.  
  257. if(empty($_POST['password'])){
  258. $error[] = "Pasword can't be empty.";
  259. }
  260.  
  261. if(empty($_POST['confirm'])){
  262. $error[] = "Confirm pasword can't be empty.";
  263. }
  264.  
  265. if($_POST['password'] !== $_POST['confirm']){
  266. $error[] = "Pasword does not match.";
  267. }
  268. if(count($error) > 0){
  269. foreach ($error as $errors) {
  270. echo $errors . "<br/>";
  271. }
  272. }else{
  273. $table_name = $wpdb->prefix . "bootstrap_registartion";
  274. $reg = $wpdb->insert( $table_name, array(
  275. 'username' => $username,
  276. 'fullname' => $fullname,
  277. 'email' => $email,
  278. 'phone' => $phone,
  279. 'identitynumber' => $identitynumber,
  280. 'address' => $address,
  281. 'postcode' => $postcode,
  282. 'city' => $city,
  283. 'country' => $country,
  284. 'password' => wp_hash_password($password)
  285. ));
  286.  
  287. if($reg){
  288. $to = get_option('admin_email');
  289. $subject = "User Registration Email";
  290. $headers = 'From: '. $email . "\r\n" .
  291. 'Reply-To: ' . $email . "\r\n";
  292. $message = "Username: {$username} <br> Full Name: {$fullname} <br> Email: {$email} <br>
  293. Phone: {$phone} <br> Identity Number: {$identitynumber} <br> Address: {$address} <br> Post Code: {$postcode} <br> City: {$city} <br> Post Code: {$postcode} <br> Country: {$country} <br> ";
  294. $sent = wp_mail($to, $subject, strip_tags($message), $headers);
  295. //if($sent){
  296. //echo "Registration has been successful";
  297. //echo $url = get_permalink();
  298. //}
  299.  
  300. //wp_redirect( $url );
  301. exit;
  302. }
  303. }
  304. }
  305.  
  306. }
  307.  
  308. function bootstrapReg_shortcode() {
  309. bootstrapReg_form_code();
  310. bootstrapReg_registration();
  311. }
  312. add_shortcode( 'bootstrap_registration', 'bootstrapReg_shortcode' );
Add Comment
Please, Sign In to add comment