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/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?>
Note: See TracChangeset for help on using the changeset viewer.