Advertisement
MrPauloeN

Add extra user registration fields in WordPress

Nov 22nd, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. # Add extra user registration fields
  2.  
  3. function czystespalanie__registration_fields() {
  4.  
  5.     # Get and set any values already sent
  6.     $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name'] : '';
  7.     $last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name'] : '';
  8.     $tel = ( isset( $_POST['tel'] ) ) ? $_POST['tel'] : '';
  9.  
  10.     # Simple spam bots and crawlers protection system
  11.  
  12.     $a = mt_rand( 1, 9 );
  13.     $b = mt_rand( 1, 9 );
  14.  
  15.     if( mt_rand( 0, 1 ) === 1 ) {
  16.         $sum = $a + $b;
  17.         $sign = " + ";
  18.     } elseif  ( ( $a - $b ) === 0 ) {
  19.         $sum = ++$a - $b;
  20.         $sign = " - ";
  21.     } else {
  22.         $sum = $a - $b;
  23.         $sign = " - ";
  24.     }
  25.  
  26.     ## Hash sum before send with POST
  27.  
  28.     $_pre_captcha = md5 ( $sum );
  29.  
  30. ?>
  31.  
  32. <h4><?php _e( '*) Profile information', 'czystespalanie' ); ?></h4>
  33. <hr style="margin-bottom: 5px;"/>
  34. <p>
  35. <label for="first_name"><?php _e( 'First name', 'czystespalanie' ) ?></label>
  36. <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( stripslashes( $first_name ) ); ?>" required>
  37.  
  38. </p>
  39. <p>
  40. <label for="last_name"><?php _e( 'Surname', 'czystespalanie' ) ?></label>
  41. <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr( stripslashes( $last_name ) ); ?>" required>
  42.  
  43. </p>
  44. <p>
  45. <label for="tel"><?php _e( 'Telephon:', 'czystespalanie' ) ?></label>
  46. <input type="tel" name="tel" id="tel" class="input" value="<?php echo esc_attr( stripslashes( $tel ) ); ?>" required>
  47.  
  48. </p>
  49.  
  50. <p><h4><?php _e( 'Anti-spam protection', 'czystespalanie' ); ?> <img class="anti-spam-shield" src="<?php echo get_template_directory_uri() . '/inc/images/anti-spam-protection.png'; ?>"></h4>
  51. <hr style="margin-bottom: 5px;"/>
  52.     <label for="captcha" class="col-sm-4 control-label">
  53.     <?php _e( 'Solve the equation:', 'czystespalanie' ); echo ' ' . $a . $sign . $b; ?> = ?
  54.     </label>
  55.     <input type="hidden" name="czystespalanie__pre_captcha" value="<?php echo esc_attr( $_pre_captcha ); ?>">
  56.     <input type="text" name="czystespalanie_captcha" class="form-control" id="captcha">
  57. </p>
  58. <p style="margin-bottom: 5px;"><small><?php _e( '*) No additional profile details are required. You can complete them later in the dashboard.', 'czystespalanie' ); ?></small></p>
  59. <hr/>
  60.     <?php
  61. }
  62. add_action( 'register_form', 'czystespalanie__registration_fields' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement