Guest User

Untitled

a guest
Jul 10th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 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="' . $_SERVER['REQUEST_URI'] . '" 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. wp_update_user( array ('ID' => $user, 'role' => 'pending_user') ) ;
  121. update_user_meta( $user, 'ihc_user_levels ', 4);
  122. $table_name = $wpdb->prefix . "ihc_user_levels";
  123. $wpdb->insert($table_name, array(
  124. "user_id" => $user,
  125. "level_id" => 4,
  126. ));
  127.  
  128. $admin_email =get_option('admin_email');
  129.  
  130. $to = $admin_email;
  131. $subject = 'surveyor Ragistration';
  132. $body = 'username=<b>'.$username.'</b><br>
  133. email=<b>'.$email.'</b><br>
  134. password=<b>'.$password.'</b><br>';
  135. $headers = array('Content-Type: text/html; charset=UTF-8');
  136. wp_mail( $to, $subject, $body, $headers );
  137. // echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
  138. echo 'Registration complete. Goto ';
  139. }
  140. }
  141.  
  142. function custom_registration_function() {
  143. if ( isset($_POST['submit'] ) ) {
  144. registration_validation(
  145. $_POST['username'],
  146. $_POST['password'],
  147. $_POST['email']
  148. );
  149.  
  150. // sanitize user form input
  151. global $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/;
  152. $username = sanitize_user( $_POST['username'] );
  153. $password = esc_attr( $_POST['password'] );
  154. $email = sanitize_email( $_POST['email'] );
  155.  
  156.  
  157. // call @function complete_registration to create the user
  158. // only when no WP_error is found
  159. complete_registration(
  160. $username,
  161. $password,
  162. $email
  163.  
  164. );
  165. }
  166.  
  167. registration_form(
  168. $username,
  169. $password,
  170. $email
  171.  
  172. );
  173. }
  174.  
  175. // Register a new shortcode: [cr_custom_registration]
  176. add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
  177.  
  178. // The callback function that will replace [book]
  179. function custom_registration_shortcode() {
  180. ob_start();
  181. custom_registration_function();
  182. return ob_get_clean();
  183. }
Add Comment
Please, Sign In to add comment