Guest User

Untitled

a guest
Nov 7th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2.  
  3. namespace CN\Registration;
  4.  
  5.  
  6. add_action( 'register_form', __NAMESPACE__.'\\registration_form' );
  7. function registration_form() {
  8.  
  9. $phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
  10.  
  11. ?>
  12. <p>
  13. <label for="phone"><?php esc_html_e( 'Phone', 'cn' ) ?><br/>
  14. <input type="text"
  15. id="phone"
  16. name="phone"
  17. value="<?php echo esc_attr( $phone ); ?>"
  18. class="input"
  19. />
  20. </label>
  21. </p>
  22. <?php
  23. }
  24.  
  25. add_filter( 'registration_errors', __NAMESPACE__.'\\registration_errors', 10, 3 );
  26. function registration_errors( $errors, $sanitized_user_login, $user_email ) {
  27.  
  28. if ( empty( $_POST['phone'] ) ) {
  29. $errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
  30. }
  31.  
  32.  
  33. return $errors;
  34. }
  35.  
  36. add_action( 'user_register', __NAMESPACE__.'\\user_register' );
  37.  
  38. function user_register( $user_id ) {
  39. if ( ! empty( $_POST['phone'] ) ) {
  40. update_user_meta( $user_id, 'phone', sanitize_text_field($_POST['phone'] ) );
  41. }
  42. }
  43.  
  44. /**
  45. * Back end registration
  46. */
  47.  
  48. add_action( 'user_new_form', __NAMESPACE__.'\\crf_admin_registration_form' );
  49. function admin_registration_form( $operation ) {
  50. if ( 'add-new-user' !== $operation ) {
  51. // $operation may also be 'add-existing-user'
  52. return;
  53. }
  54.  
  55. $phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
  56.  
  57. ?>
  58. <h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
  59.  
  60. <table class="form-table">
  61. <tr>
  62. <th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'cn' ); ?></span></th>
  63. <td>
  64. <input type="text"
  65. id="phone"
  66. name="phone"
  67. value="<?php echo esc_attr( $phone ); ?>"
  68. class="regular-text"
  69. />
  70. </td>
  71. </tr>
  72. </table>
  73. <?php
  74. }
  75.  
  76. add_action( 'user_profile_update_errors', __NAMESPACE__.'\\user_profile_update_errors', 10, 3 );
  77. function user_profile_update_errors( $errors, $update, $user ) {
  78. if ( $update ) {
  79. return;
  80. }
  81.  
  82. if ( empty( $_POST['phone'] ) ) {
  83. $errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
  84. }
  85.  
  86. }
  87.  
  88. add_action( 'edit_user_created_user', __NAMESPACE__.'\\user_register' );
  89.  
  90.  
  91. /**
  92. * Back end display
  93. */
  94.  
  95. add_action( 'show_user_profile', __NAMESPACE__.'\\show_extra_profile_fields' );
  96. add_action( 'edit_user_profile', __NAMESPACE__.'\\show_extra_profile_fields' );
  97.  
  98. function show_extra_profile_fields( $user ) {
  99. ?>
  100. <h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
  101.  
  102. <table class="form-table">
  103. <tr>
  104. <th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label></th>
  105. <td><?php echo esc_html( get_the_author_meta( 'Phone', $user->ID ) ); ?></td>
  106. </tr>
  107. </table>
  108. <?php
  109. }
Add Comment
Please, Sign In to add comment