Making WordPress.org


Ignore:
Timestamp:
12/15/2016 06:33:13 AM (8 years ago)
Author:
dd32
Message:

Login: Move saving of extra profile fields from the template to a function.

See #148

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-registration.php

    r4470 r4534  
    3838
    3939    $user_id = wpmu_create_user( wp_slash( $user_login ), wp_generate_password(), wp_slash( $user_email ) );
    40     if ( ! $user_id || is_wp_error( $user_id ) ) {
     40    if ( ! $user_id ) {
    4141        wp_die( __( 'Error! Something went wrong with your registration. Try again?', 'wporg-login' ) );
    4242    }
     
    7979    die();
    8080}
     81
     82function wporg_login_save_profile_fields() {
     83    if ( ! $_POST || empty( $_POST['user_fields'] ) ) {
     84        return;
     85    }
     86    $fields = array( 'url', 'from', 'occ', 'interests' );
     87
     88    foreach ( $fields as $field ) {
     89        if ( isset( $_POST['user_fields'][ $field ] ) ) {
     90            $value = sanitize_text_field( wp_unslash( $_POST['user_fields'][ $field ] ) );
     91            if ( 'url' == $field ) {
     92                wp_update_user( array(
     93                    'ID' => get_current_user_id(),
     94                    'user_url' => esc_url_raw( $value )
     95                ) );
     96            } else {
     97                update_user_meta( $user->ID, $field, $value );
     98            }
     99        }
     100    }
     101}
Note: See TracChangeset for help on using the changeset viewer.