Advertisement
Guest User

Untitled

a guest
Jul 10th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Custom Registration
  4. Plugin URI: https://www.corewaysolution.com/
  5. Description: Custom Registration
  6. Version: 1.0
  7. Author: Sehjad Ansari
  8. Author URI: Custom Registration
  9. */
  10. add_action('wp_enqueue_scripts','ava_test_init');
  11.  
  12. function ava_test_init() {
  13. wp_enqueue_script( 'plugin_reg', plugins_url( 'plugin_reg.js', __FILE__ ));
  14. wp_enqueue_script( 'validate_reg', plugins_url( 'validate_reg.js', __FILE__ ));
  15. }
  16. function registration_form( $username, $password, $email) {
  17. echo '
  18. <style>
  19. div {
  20. margin-bottom:2px;
  21. }
  22.  
  23. input{
  24. margin-bottom:4px;
  25. }
  26. </style>
  27. ';
  28. echo '<div id="loadingimage" class="loadingimage" style="display: none;">
  29. <div id="loadingimage1" class="loadingimage1"> <img src="http://192.168.1.53/stockfocus/wp-content/themes/strokefocus/images/loading.gif"> </div>
  30. </div>';
  31. echo '
  32. <form action="#" method="post" name="custome_ragistrion">
  33. <div>
  34. <input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '" placeholder="*username">
  35. </div>
  36.  
  37. <div>
  38. <input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '" placeholder="*Password">
  39. </div>
  40.  
  41. <div>
  42. <input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '" placeholder="*Email">
  43. </div>
  44.  
  45. <input type="submit" name="submit" value="Register" class="custome_submit"/>
  46. </form>
  47. ';
  48. }
  49.  
  50. function registration_validation( $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/ ) {
  51. global $reg_errors;
  52. $reg_errors = new WP_Error;
  53.  
  54. if ( empty( $username ) || empty( $password ) || empty( $email ) ) {
  55. $reg_errors->add('field', 'Required form field is missing');
  56. }
  57.  
  58. if ( 4 > strlen( $username ) ) {
  59. $reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
  60. }
  61.  
  62. if ( username_exists( $username ) )
  63. $reg_errors->add('user_name', 'Sorry, that username already exists!');
  64.  
  65.  
  66. if ( ! validate_username( $username ) ) {
  67. $reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
  68. }
  69.  
  70. if ( 5 > strlen( $password ) ) {
  71. $reg_errors->add( 'password', 'Password length must be greater than 5' );
  72. }
  73.  
  74. if ( !is_email( $email ) ) {
  75. $reg_errors->add( 'email_invalid', 'Email is not valid' );
  76. }
  77.  
  78. if ( email_exists( $email ) ) {
  79. $reg_errors->add( 'email', 'Email Already in use' );
  80. }
  81.  
  82. /*if ( ! empty( $website ) ) {
  83. if ( ! filter_var( $website, FILTER_VALIDATE_URL ) ) {
  84. $reg_errors->add( 'website', 'Website is not a valid URL' );
  85. }
  86. }
  87. */
  88. if ( is_wp_error( $reg_errors ) ) {
  89.  
  90. foreach ( $reg_errors->get_error_messages() as $error ) {
  91.  
  92. echo '<div>';
  93. echo '<strong>ERROR</strong>:';
  94. echo $error . '<br/>';
  95. echo '</div>';
  96.  
  97. }
  98.  
  99. }
  100. }
  101.  
  102. function complete_registration() {
  103. global $wpdb;
  104. global $reg_errors, $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/;
  105. if ( 1 > count( $reg_errors->get_error_messages() ) ) {
  106. $userdata = array(
  107. 'user_login' => $username,
  108. 'user_email' => $email,
  109. 'user_pass' => $password
  110. );
  111. $user = wp_insert_user( $userdata );
  112.  
  113. /*$from = "d.developer001@gmail.com";
  114. $to = "d.developer001@gmail.com";
  115. $subject = "PHP Mail Test script";
  116. $message = "This is a test to check the PHP Mail functionality";
  117. $headers = "From:" . $from;
  118. mail($to,$subject,$message, $headers);
  119. echo "Test email sent";*/
  120. $user_obj = new WP_User( $user );
  121. $user_obj->remove_role( 'subscriber' );
  122. $user_obj->add_role( 'editor' );
  123.  
  124. $admin_email =get_option('admin_email');
  125.  
  126. $to = $admin_email;
  127. $subject = 'surveyor Ragistration';
  128. $body = 'username=<b>'.$username.'</b><br>
  129. email=<b>'.$email.'</b><br>
  130. password=<b>'.$password.'</b><br>';
  131. $headers = array('Content-Type: text/html; charset=UTF-8');
  132. wp_mail( $to, $subject, $body, $headers );
  133. // echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
  134. echo 'Registration complete. Goto ';
  135. }
  136. }
  137.  
  138. function custom_registration_function() {
  139. if ( isset($_POST['submit'] ) ) {
  140. registration_validation(
  141. $_POST['username'],
  142. $_POST['password'],
  143. $_POST['email']
  144. );
  145.  
  146. // sanitize user form input
  147. global $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/;
  148. $username = sanitize_user( $_POST['username'] );
  149. $password = esc_attr( $_POST['password'] );
  150. $email = sanitize_email( $_POST['email'] );
  151.  
  152.  
  153. // call @function complete_registration to create the user
  154. // only when no WP_error is found
  155. complete_registration(
  156. $username,
  157. $password,
  158. $email
  159.  
  160. );
  161. }
  162.  
  163. registration_form(
  164. $username,
  165. $password,
  166. $email
  167.  
  168. );
  169. }
  170.  
  171. // Register a new shortcode: [cr_custom_registration]
  172. add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
  173.  
  174. // The callback function that will replace [book]
  175. function custom_registration_shortcode() {
  176. ob_start();
  177. custom_registration_function();
  178. return ob_get_clean();
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement