• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_process_profile_editor_updates() – Process Profile Updater Form

You appear to be a bot. Output may be restricted

Description

Process Profile Updater Form

Processes the profile updater form by updating the necessary fields

Usage

$void = edd_process_profile_editor_updates( $data );

Parameters

$data
( array ) required – Data sent from the profile editor

Returns

void

Source

File name: easy-digital-downloads/includes/shortcodes.php
Lines:

1 to 100 of 105
function edd_process_profile_editor_updates( $data ) {
  // Profile field change request
  if ( empty( $_POST['edd_profile_editor_submit'] ) && !is_user_logged_in() ) {
    return false;
  }

  // Pending users can't edit their profile
  if ( edd_user_pending_verification() ) {
    return false;
  }

  // Nonce security
  if ( ! wp_verify_nonce( $data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce' ) ) {
    return false;
  }

  $user_id       = get_current_user_id();
  $old_user_data = get_userdata( $user_id );

  $display_name = isset( $data['edd_display_name'] )    ? sanitize_text_field( $data['edd_display_name'] )    : $old_user_data->display_name;
  $first_name   = isset( $data['edd_first_name'] )      ? sanitize_text_field( $data['edd_first_name'] )      : $old_user_data->first_name;
  $last_name    = isset( $data['edd_last_name'] )       ? sanitize_text_field( $data['edd_last_name'] )       : $old_user_data->last_name;
  $email        = isset( $data['edd_email'] )           ? sanitize_email( $data['edd_email'] )                : $old_user_data->user_email;
  $line1        = isset( $data['edd_address_line1'] )   ? sanitize_text_field( $data['edd_address_line1'] )   : '';
  $line2        = isset( $data['edd_address_line2'] )   ? sanitize_text_field( $data['edd_address_line2'] )   : '';
  $city         = isset( $data['edd_address_city'] )    ? sanitize_text_field( $data['edd_address_city'] )    : '';
  $state        = isset( $data['edd_address_state'] )   ? sanitize_text_field( $data['edd_address_state'] )   : '';
  $zip          = isset( $data['edd_address_zip'] )     ? sanitize_text_field( $data['edd_address_zip'] )     : '';
  $country      = isset( $data['edd_address_country'] ) ? sanitize_text_field( $data['edd_address_country'] ) : '';

  $userdata = array(
    'ID'           => $user_id,
    'first_name'   => $first_name,
    'last_name'    => $last_name,
    'display_name' => $display_name,
    'user_email'   => $email
  );


  $address = array(
    'line1'    => $line1,
    'line2'    => $line2,
    'city'     => $city,
    'state'    => $state,
    'zip'      => $zip,
    'country'  => $country
  );

  do_action( 'edd_pre_update_user_profile', $user_id, $userdata );

  // New password
  if ( ! empty( $data['edd_new_user_pass1'] ) ) {
    if ( $data['edd_new_user_pass1'] !== $data['edd_new_user_pass2'] ) {
      edd_set_error( 'password_mismatch', __( 'The passwords you entered do not match. Please try again.', 'easy-digital-downloads' ) );
    } else {
      $userdata['user_pass'] = $data['edd_new_user_pass1'];
    }
  }

  // Make sure the new email doesn't belong to another user
  if( $email != $old_user_data->user_email ) {
    // Make sure the new email is valid
    if( ! is_email( $email ) ) {
      edd_set_error( 'email_invalid', __( 'The email you entered is invalid. Please enter a valid email.', 'easy-digital-downloads' ) );
    }

    // Make sure the new email doesn't belong to another user
    if( email_exists( $email ) ) {
      edd_set_error( 'email_exists', __( 'The email you entered belongs to another user. Please use another.', 'easy-digital-downloads' ) );
    }
  }

  // Check for errors
  $errors = edd_get_errors();

  if( $errors ) {
    // Send back to the profile editor if there are errors
    wp_redirect( $data['edd_redirect'] );
    edd_die();
  }

  // Update the user
  $meta    = update_user_meta( $user_id, '_edd_user_address', $address );
  $updated = wp_update_user( $userdata );

  // Possibly update the customer
  $customer    = new EDD_Customer( $user_id, true );
  if ( $customer->email === $email || ( is_array( $customer->emails ) && in_array( $email, $customer->emails ) ) ) {
    $customer->set_primary_email( $email );
  };

  if ( $customer->id > 0 ) {
    $update_args = array(
      'name'  => stripslashes( $first_name . ' ' . $last_name ),
    );

    $customer->update( $update_args );
  }

  if ( $updated ) {
 
[1] [2] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: edd_process_profile_editor_updates
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/shortcodes.php
File ref: includes/shortcodes.php
Deprecated?: No
API Letters: E,P,U

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites