Making WordPress.org

Changeset 4534


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

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login
Files:
4 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}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/partials/register-profilefields.php

    r4470 r4534  
    44 *
    55 * This template expects that the global $user variable is set.
    6  * This template also handles saving of the fields, not ideal, but does the job for now.
    76 *
    87 * @package wporg-login
     
    109
    1110$fields = array(
    12     'url'       => '',
    13     'from'      => '',
    14     'occ'       => '',
    15     'interests' => '',
     11    'url'       => wp_get_current_user()->user_url ?: '',
     12    'from'      => get_user_meta( get_current_user_id(), 'from', true ) ?: '',
     13    'occ'       => get_user_meta( get_current_user_id(), 'occ', true ) ?: '',
     14    'interests' => get_user_meta( get_current_user_id(), 'interests', true ) ?: '',
    1615);
    17 
    18 foreach ( array_keys( $fields ) as $field ) {
    19     if ( $_POST && isset( $_POST['user_fields'][ $field ] ) ) {
    20         $fields[ $field ] = sanitize_text_field( wp_unslash( $_POST['user_fields'][ $field ] ) );
    21         if ( 'url' == $field ) {
    22             wp_update_user( array(
    23                 'ID' => get_current_user_id(),
    24                 'user_url' => esc_url( $fields[ $field ] )
    25             ) );
    26         } else {
    27             update_user_meta( $user->ID, $field, $fields[ $field ] );
    28         }
    29     } else {
    30         $fields[ $field ] = ( 'url' === $field ) ? $user->user_url : get_user_meta( $user->ID, $field, true );
    31     }
    32 }
    3316
    3417?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/register-confirm.php

    r4470 r4534  
    3333} elseif ( !empty( $_POST['user_pass'] ) ) {
    3434    $user_pass = wp_unslash( $_POST['user_pass'] );
     35
     36    wporg_login_save_profile_fields();
    3537
    3638    add_filter( 'send_email_change_email', '__return_false' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/register-profile.php

    r4470 r4534  
    2525}
    2626
     27wporg_login_save_profile_fields();
     28
    2729wp_enqueue_script( 'wporg-registration' );
    2830
Note: See TracChangeset for help on using the changeset viewer.