• 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_anonymize_customer() – Given a customer ID, anonymize the data related to that customer.

You appear to be a bot. Output may be restricted

Description

Given a customer ID, anonymize the data related to that customer.

Only the customer record is affected in this function. The data that is changed:

  • The name is changed to 'Anonymized Customer'
  • The email address is anonymized, but kept in a format that passes is_email checks
  • The date created is set to the timestamp of 0 (January 1, 1970)
  • Notes are fully cleared
  • Any additional email addresses are removed

Once completed, a note is left stating when the customer was anonymized.

Usage

$array = _edd_anonymize_customer( $customer_id );

Parameters

$customer_id
( int ) optional –

Returns

array

Source

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

1 to 80 of 80
function _edd_anonymize_customer( $customer_id = 0 ) {

  $customer = new EDD_Customer( $customer_id );
  if ( empty( $customer->id ) ) {
    return array( 'success' => false, 'message' => sprintf( __( 'No customer with ID %d', 'easy-digital-downloads' ), $customer_id ) );
  }

  
/**
 * Determines if this customer should be allowed to be anonymized.
 *
 * Developers and extensions can use this filter to make it possible to not anonymize a customer. A sample use case
 * would be if the customer has pending orders, and that payment requires shipping, anonymizing the customer may
 * not be ideal.
 *
 * @since 2.9.2
 *
 * @param array {
 *     Contains data related to if the anonymization should take place
 *
 *     @type bool   $should_anonymize If the customer should be anonymized.
 *     @type string $message          A message to display if the customer could not be anonymized.
 * }
 */
  $should_anonymize_customer = apply_filters( 'edd_should_anonymize_customer', array( 'should_anonymize' => true, 'message' => '' ), $customer );

  if ( empty( $should_anonymize_customer['should_anonymize'] ) ) {
    return array( 'success' => false, 'message' => $should_anonymize_customer['message'] );
  }

  // Now we should look at payments this customer has associated, and if there are any payments that should not be modified,
  // do not modify the customer.
  $payments = edd_get_payments( array(
    'customer' => $customer->id,
    'output'   => 'payments',
    'number'   => -1,
  ) );

  foreach ( $payments as $payment ) {
    $action = _edd_privacy_get_payment_action( $payment );
    if ( 'none' === $action ) {
      return array(
        'success' => false,
        'message' => __( 'Customer could not be anonymized due to payments that could not be anonymized or deleted.', 'easy-digital-downloads' )
      );
    }
  }

  // Loop through all their email addresses, and remove any additional email addresses.
  foreach ( $customer->emails as $email ) {
    $customer->remove_email( $email );
  }

  if ( $customer->user_id > 0 ) {
    delete_user_meta( $customer->user_id, '_edd_user_address' );
  }

  $customer->update( array(
    'name'         => __( 'Anonymized Customer', 'easy-digital-downloads' ),
    'email'        => edd_anonymize_email( $customer->email ),
    'date_created' => date( 'Y-m-d H:i:s', 0 ),
    'notes'        => '',
    'user_id'      => 0,
  ) );

  
/**
 * Run further anonymization on a customer
 *
 * Developers and extensions can use the EDD_Customer object passed into the edd_anonymize_customer action
 * to complete further anonymization.
 *
 * @since 2.9.2
 *
 * @param EDD_Customer $customer The EDD_Customer object that was found.
 */
  do_action( 'edd_anonymize_customer', $customer );

  $customer->add_note( __( 'Customer anonymized successfully', 'easy-digital-downloads' ) );
  return array( 'success' => true, 'message' => sprintf( __( 'Customer ID %d successfully anonymized.', 'easy-digital-downloads' ), $customer_id ) );

}
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: _edd_anonymize_customer
Plugin ref: Easy Digital Downloads
Version: 2.10.1
Sourcefile: includes/privacy-functions.php
File ref: includes/privacy-functions.php
API type: private
Deprecated?: No
API Letters: _,A,C,E

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.7
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-2021. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites