Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace CN\Registration;
- add_action( 'register_form', __NAMESPACE__.'\\registration_form' );
- function registration_form() {
- $phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
- ?>
- <p>
- <label for="phone"><?php esc_html_e( 'Phone', 'cn' ) ?><br/>
- <input type="text"
- id="phone"
- name="phone"
- value="<?php echo esc_attr( $phone ); ?>"
- class="input"
- />
- </label>
- </p>
- <?php
- }
- add_filter( 'registration_errors', __NAMESPACE__.'\\registration_errors', 10, 3 );
- function registration_errors( $errors, $sanitized_user_login, $user_email ) {
- if ( empty( $_POST['phone'] ) ) {
- $errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
- }
- return $errors;
- }
- add_action( 'user_register', __NAMESPACE__.'\\user_register' );
- function user_register( $user_id ) {
- if ( ! empty( $_POST['phone'] ) ) {
- update_user_meta( $user_id, 'phone', sanitize_text_field($_POST['phone'] ) );
- }
- }
- /**
- * Back end registration
- */
- add_action( 'user_new_form', __NAMESPACE__.'\\crf_admin_registration_form' );
- function admin_registration_form( $operation ) {
- if ( 'add-new-user' !== $operation ) {
- // $operation may also be 'add-existing-user'
- return;
- }
- $phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
- ?>
- <h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
- <table class="form-table">
- <tr>
- <th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'cn' ); ?></span></th>
- <td>
- <input type="text"
- id="phone"
- name="phone"
- value="<?php echo esc_attr( $phone ); ?>"
- class="regular-text"
- />
- </td>
- </tr>
- </table>
- <?php
- }
- add_action( 'user_profile_update_errors', __NAMESPACE__.'\\user_profile_update_errors', 10, 3 );
- function user_profile_update_errors( $errors, $update, $user ) {
- if ( $update ) {
- return;
- }
- if ( empty( $_POST['phone'] ) ) {
- $errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
- }
- }
- add_action( 'edit_user_created_user', __NAMESPACE__.'\\user_register' );
- /**
- * Back end display
- */
- add_action( 'show_user_profile', __NAMESPACE__.'\\show_extra_profile_fields' );
- add_action( 'edit_user_profile', __NAMESPACE__.'\\show_extra_profile_fields' );
- function show_extra_profile_fields( $user ) {
- ?>
- <h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
- <table class="form-table">
- <tr>
- <th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label></th>
- <td><?php echo esc_html( get_the_author_meta( 'Phone', $user->ID ) ); ?></td>
- </tr>
- </table>
- <?php
- }
Add Comment
Please, Sign In to add comment