installed plugin Easy Digital Downloads version 3.1.0.3

This commit is contained in:
2022-11-27 15:03:07 +00:00
committed by Gitium
parent 555673545b
commit c5dce2cec6
1200 changed files with 238970 additions and 0 deletions

View File

@ -0,0 +1,453 @@
<?php
/**
* Customer Email Addresses Table Class
*
* @package EDD
* @subpackage Reports
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Admin\List_Table;
/**
* EDD_Customer_Addresses_Table Class
*
* Renders the Customer Reports table
*
* @since 3.0
*/
class EDD_Customer_Addresses_Table extends List_Table {
/**
* Get things started
*
* @since 3.0
* @see WP_List_Table::__construct()
*/
public function __construct() {
parent::__construct( array(
'singular' => 'address',
'plural' => 'addresses',
'ajax' => false
) );
$this->process_bulk_action();
$this->get_counts();
}
/**
* Gets the name of the primary column.
*
* @since 2.5
* @access protected
*
* @return string Name of the primary column.
*/
protected function get_primary_column_name() {
return 'address';
}
/**
* This function renders most of the columns in the list table.
*
* @since 3.0
*
* @param array $item Contains all the data of the customers
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'type' :
$value = edd_get_address_type_label( $item['type'] );
if ( ! empty( $item['is_primary'] ) ) {
$value .= '&nbsp;&nbsp;<span class="edd-chip">' . esc_html__( 'Primary', 'easy-digital-downloads' ) . '</span>';
}
break;
case 'date_created' :
$value = '<time datetime="' . esc_attr( $item['date_created'] ) . '">' . edd_date_i18n( $item['date_created'], 'M. d, Y' ) . '<br>' . edd_date_i18n( $item['date_created'], 'H:i' ) . ' ' . edd_get_timezone_abbr() . '</time>';
break;
default:
$value = ! empty( $item[ $column_name ] )
? esc_html( $item[ $column_name ] )
: '&mdash;';
break;
}
// Filter & return
return apply_filters( 'edd_customers_column_' . $column_name, $value, $item['id'] );
}
/**
* Return the contents of the "Name" column
*
* @since 3.0
*
* @param array $item
* @return string
*/
public function column_address( $item ) {
$state = $extra = '';
$status = $this->get_status();
$address = ! empty( $item['address'] ) ? $item['address'] : '&mdash;';
$address2 = ! empty( $item['address2'] ) ? $item['address2'] : '';
$city = ! empty( $item['city'] ) ? $item['city'] : '';
$code = ! empty( $item['postal_code'] ) ? $item['postal_code'] : '';
// Address2
if ( ! empty( $address2 ) ) {
$extra .= '<br>' . $address2;
}
// City & Zip
if ( ! empty( $city ) || ! empty( $code ) ) {
$extra .= '<br>' . implode( ' ', array( $city, $code ) );
}
// Get the item status
$item_status = ! empty( $item['status'] )
? $item['status']
: 'verified';
// Get the customer ID
$customer_id = ! empty( $item['customer_id'] )
? absint( $item['customer_id'] )
: 0;
// Link to customer
$customer_url = edd_get_admin_url( array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer_id ),
) );
// State
if ( ( ! empty( $status ) && ( $status !== $item_status ) ) || ( $item_status !== 'active' ) ) {
switch ( $status ) {
case 'pending' :
$value = __( 'Pending', 'easy-digital-downloads' );
break;
case 'verified' :
case '' :
default :
$value = __( 'Active', 'easy-digital-downloads' );
break;
}
$state = ' &mdash; ' . $value;
}
// Concatenate and return
return '<strong><a class="row-title" href="' . esc_url( $customer_url ) . '#edd_general_addresses">' . esc_html( $address ) . '</a>' . esc_html( $state ) . '</strong>' . $extra . $this->row_actions( $this->get_row_actions( $item ) );
}
/**
* Gets the row actions for the customer address.
*
* @since 3.0
* @param array $item
* @return array
*/
private function get_row_actions( $item ) {
// Link to customer
$customer_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['customer_id'] ),
)
);
// Actions
$actions = array(
'view' => '<a href="' . esc_url( $customer_url ) . '#edd_general_addresses">' . esc_html__( 'View', 'easy-digital-downloads' ) . '</a>'
);
if ( empty( $item['is_primary'] ) ) {
$delete_url = wp_nonce_url( edd_get_admin_url( array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['id'] ),
'edd_action' => 'customer-remove-address'
) ), 'edd-remove-customer-address' );
$actions['delete'] = '<a href="' . esc_url( $delete_url ) . '">' . esc_html__( 'Delete', 'easy-digital-downloads' ) . '</a>';
}
/**
* Filter the customer address row actions.
*
* @since 3.0
* @param array $actions The array of row actions.
* @param array $item The specific item (customer address).
*/
return apply_filters( 'edd_customer_address_row_actions', $actions, $item );
}
/**
* Return the contents of the "Name" column
*
* @since 3.0
*
* @param array $item
* @return string
*/
public function column_customer( $item ) {
// Get the customer ID
$customer_id = ! empty( $item['customer_id'] )
? absint( $item['customer_id'] )
: 0;
// Bail if no customer ID
if ( empty( $customer_id ) ) {
return '&mdash;';
}
// Try to get the customer
$customer = edd_get_customer( $customer_id );
// Bail if customer no longer exists
if ( empty( $customer ) ) {
return '&mdash;';
}
// Link to customer
$customer_url = edd_get_admin_url( array(
'page' => 'edd-customers',
'page_type' => 'physical',
's' => 'c:' . absint( $customer_id )
) );
// Concatenate and return
return '<a href="' . esc_url( $customer_url ) . '">' . esc_html( $customer->name ) . '</a>';
}
/**
* Render the checkbox column
*
* @access public
* @since 3.0
*
* @param array $item Address object.
*
* @return string Displays a checkbox
*/
public function column_cb( $item ) {
$customer = edd_get_customer_by( 'id', $item['customer_id'] );
$name = sprintf(
/* translators: customer address id */
__( 'Address ID: %s', 'easy-digital-downloads' ),
$item['id']
);
if ( ! empty( $customer->name ) ) {
$name = $customer->name;
}
return sprintf(
'<input type="checkbox" name="%1$s[]" id="%1$s-%2$s" value="%2$s" /><label for="%1$s-%2$s" class="screen-reader-text">%3$s</label>',
/*$1%s*/ 'customer',
/*$2%s*/ esc_attr( $item['id'] ),
/* translators: customer name or address id */
esc_html( sprintf( __( 'Select %s', 'easy-digital-downloads' ), $name ) )
);
}
/**
* Retrieve the customer counts
*
* @access public
* @since 3.0
* @return void
*/
public function get_counts() {
$this->counts = edd_get_customer_address_counts();
}
/**
* Retrieve the table columns
*
* @since 3.0
* @return array $columns Array of all the list table columns
*/
public function get_columns() {
return apply_filters( 'edd_report_customer_columns', array(
'cb' => '<input type="checkbox" />',
'address' => __( 'Address', 'easy-digital-downloads' ),
'region' => __( 'Region', 'easy-digital-downloads' ),
'country' => __( 'Country', 'easy-digital-downloads' ),
'customer' => __( 'Customer', 'easy-digital-downloads' ),
'type' => __( 'Type', 'easy-digital-downloads' ),
'date_created' => __( 'Date', 'easy-digital-downloads' )
) );
}
/**
* Get the sortable columns
*
* @since 2.1
* @return array Array of all the sortable columns
*/
public function get_sortable_columns() {
return array(
'date_created' => array( 'date_created', true ),
'address' => array( 'address', false ),
'region' => array( 'region', true ),
'country' => array( 'country', true ),
'customer' => array( 'customer_id', false ),
'type' => array( 'type', false )
);
}
/**
* Retrieve the bulk actions
*
* @access public
* @since 3.0
* @return array Array of the bulk actions
*/
public function get_bulk_actions() {
return array(
'delete' => __( 'Delete', 'easy-digital-downloads' )
);
}
/**
* Process the bulk actions
*
* @access public
* @since 3.0
*/
public function process_bulk_action() {
if ( empty( $_REQUEST['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-addresses' ) ) {
return;
}
$ids = isset( $_GET['customer'] )
? $_GET['customer']
: false;
if ( ! is_array( $ids ) ) {
$ids = array( $ids );
}
foreach ( $ids as $id ) {
switch ( $this->current_action() ) {
case 'delete' :
edd_delete_customer_address( $id );
break;
}
}
}
/**
* Get all of the items to display, given the current filters
*
* @since 3.0
*
* @return array $data All the row data
*/
public function get_data() {
$data = array();
$search = $this->get_search();
$args = array( 'status' => $this->get_status() );
// Customer ID
if ( strpos( $search, 'c:' ) !== false ) {
$args['customer_id'] = trim( str_replace( 'c:', '', $search ) );
// Country
} elseif ( strpos( $search, 'country:' ) !== false ) {
$search = substr( $search, strlen( 'country:' ) );
$args['search'] = $search;
$args['search_columns'] = array( 'country' );
// Zip
} elseif ( strpos( $search, 'zip:' ) !== false ) {
$search = substr( $search, strlen( 'zip:' ) );
$args['search'] = $search;
$args['search_columns'] = array( 'zip' );
// Region
} elseif ( strpos( $search, 'region:' ) !== false ) {
$search = substr( $search, strlen( 'region:' ) );
$args['search'] = $search;
$args['search_columns'] = array( 'region' );
// City
} elseif ( strpos( $search, 'city:' ) !== false ) {
$search = substr( $search, strlen( 'city:' ) );
$args['search'] = $search;
$args['search_columns'] = array( 'city' );
// Any...
} else {
$args['search'] = $search;
$args['search_columns'] = array( 'address', 'address2', 'city', 'region', 'country', 'postal_code' );
}
// Parse pagination
$this->args = $this->parse_pagination_args( $args );
// Get the data
$addresses = edd_get_customer_addresses( $this->args );
if ( ! empty( $addresses ) ) {
foreach ( $addresses as $address ) {
$data[] = array(
'id' => $address->id,
'customer_id' => $address->customer_id,
'status' => $address->status,
'type' => $address->type,
'address' => $address->address,
'address2' => $address->address2,
'city' => $address->city,
'region' => $address->region,
'postal_code' => $address->postal_code,
'country' => $address->country,
'date_created' => $address->date_created,
'date_modified' => $address->date_modified,
'is_primary' => $address->is_primary,
);
}
}
return $data;
}
/**
* Setup the final data for the table
*
* @since 3.0
* @return void
*/
public function prepare_items() {
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
$this->items = $this->get_data();
$status = $this->get_status( 'total' );
// Setup pagination
$this->set_pagination_args( array(
'total_pages' => ceil( $this->counts[ $status ] / $this->per_page ),
'total_items' => $this->counts[ $status ],
'per_page' => $this->per_page
) );
}
}

View File

@ -0,0 +1,440 @@
<?php
/**
* Customer Email Addresses Table Class
*
* @package EDD
* @subpackage Reports
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Admin\List_Table;
/**
* EDD_Customer_Email_Addresses_Table Class
*
* Renders the Customer Reports table
*
* @since 3.0
*/
class EDD_Customer_Email_Addresses_Table extends List_Table {
/**
* Get things started
*
* @since 3.0
* @see WP_List_Table::__construct()
*/
public function __construct() {
parent::__construct( array(
'singular' => 'email',
'plural' => 'emails',
'ajax' => false
) );
$this->process_bulk_action();
$this->get_counts();
}
/**
* Gets the name of the primary column.
*
* @since 2.5
* @access protected
*
* @return string Name of the primary column.
*/
protected function get_primary_column_name() {
return 'email';
}
/**
* This function renders most of the columns in the list table.
*
* @since 3.0
*
* @param array $item Contains all the data of the customers
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'id' :
$value = $item['id'];
break;
case 'email' :
$value = '<a href="mailto:' . rawurlencode( $item['email'] ) . '">' . esc_html( $item['email'] ) . '</a>';
break;
case 'type' :
$value = ( 'primary' === $item['type'] )
? esc_html__( 'Primary', 'easy-digital-downloads' )
: esc_html__( 'Secondary', 'easy-digital-downloads' );
break;
case 'date_created' :
$value = '<time datetime="' . esc_attr( $item['date_created'] ) . '">' . edd_date_i18n( $item['date_created'], 'M. d, Y' ) . '<br>' . edd_date_i18n( $item['date_created'], 'H:i' ) . ' ' . edd_get_timezone_abbr() . '</time>';
break;
default:
$value = isset( $item[ $column_name ] )
? $item[ $column_name ]
: null;
break;
}
// Filter & return
return apply_filters( 'edd_customers_column_' . $column_name, $value, $item['id'] );
}
/**
* Return the contents of the "Name" column
*
* @since 3.0
*
* @param array $item
* @return string
*/
public function column_email( $item ) {
$state = '';
$status = $this->get_status();
$email = ! empty( $item['email'] ) ? $item['email'] : '&mdash;';
// Get the item status
$item_status = ! empty( $item['status'] )
? $item['status']
: 'verified';
// Get the customer ID
$customer_id = ! empty( $item['customer_id'] )
? absint( $item['customer_id'] )
: 0;
// Link to customer
$customer_url = edd_get_admin_url( array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer_id ),
) );
// State
if ( ( ! empty( $status ) && ( $status !== $item_status ) ) || ( $item_status !== 'active' ) ) {
switch ( $status ) {
case 'pending' :
$value = __( 'Pending', 'easy-digital-downloads' );
break;
case 'verified' :
case '' :
default :
$value = __( 'Active', 'easy-digital-downloads' );
break;
}
$state = ' &mdash; ' . $value;
}
// Concatenate and return
return '<strong><a class="row-title" href="' . esc_url( $customer_url ) . '#edd_general_emails">' . esc_html( $email ) . '</a>' . esc_html( $state ) . '</strong>' . $this->row_actions( $this->get_row_actions( $item ) );
}
/**
* Gets the row actions for the customer email address.
*
* @since 3.0
* @param array $item
* @return array
*/
private function get_row_actions( $item ) {
// Link to customer
$customer_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['customer_id'] ),
)
);
// Actions
$actions = array(
'view' => '<a href="' . esc_url( $customer_url ) . '#edd_general_emails">' . __( 'View', 'easy-digital-downloads' ) . '</a>',
);
// Non-primary email actions
if ( ! empty( $item['email'] ) && ( empty( $item['type'] ) || 'primary' !== $item['type'] ) ) {
$delete_url = wp_nonce_url( edd_get_admin_url( array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['customer_id'] ),
'email' => rawurlencode( $item['email'] ),
'edd_action' => 'customer-remove-email',
) ), 'edd-remove-customer-email' );
$actions['delete'] = '<a href="' . esc_url( $delete_url ) . '">' . esc_html__( 'Delete', 'easy-digital-downloads' ) . '</a>';
}
/**
* Filter the customer email address row actions.
*
* @since 3.0
* @param array $actions The array of row actions.
* @param array $item The specific item (customer email address).
*/
return apply_filters( 'edd_customer_email_address_row_actions', $actions, $item );
}
/**
* Return the contents of the "Name" column
*
* @since 3.0
*
* @param array $item
* @return string
*/
public function column_customer( $item ) {
// Get the customer ID
$customer_id = ! empty( $item['customer_id'] )
? absint( $item['customer_id'] )
: 0;
// Bail if no customer ID
if ( empty( $customer_id ) ) {
return '&mdash;';
}
// Try to get the customer
$customer = edd_get_customer( $customer_id );
// Bail if customer no longer exists
if ( empty( $customer ) ) {
return '&mdash;';
}
// Link to customer
$customer_url = edd_get_admin_url( array(
'page' => 'edd-customers',
'page_type' => 'emails',
's' => 'c:' . absint( $customer_id )
) );
// Concatenate and return
return '<a href="' . esc_url( $customer_url ) . '">' . esc_html( $customer->name ) . '</a>';
}
/**
* Render the checkbox column
*
* @access public
* @since 3.0
*
* @param array $item
*
* @return string Displays a checkbox
*/
public function column_cb( $item ) {
$is_primary = ! empty( $item['type'] ) && 'primary' === $item['type'];
$primary_attributes = $is_primary ? ' disabled' : '';
$title = $is_primary ? __( 'Primary email addresses cannot be deleted.', 'easy-digital-downloads' ) : '';
return sprintf(
'<input type="checkbox" name="%1$s[]" id="%1$s-%2$s" value="%2$s" title="%4$s"%5$s /><label for="%1$s-%2$s" class="screen-reader-text">%3$s</label>',
/*$1%s*/ esc_attr( 'customer' ),
/*$2%s*/ esc_attr( $item['id'] ),
/* translators: customer email */
esc_html( sprintf( __( 'Select %s', 'easy-digital-downloads' ), $item['email'] ) ),
/*$4%s*/ esc_attr( $title ),
/*$5%s*/ $primary_attributes
);
}
/**
* Retrieve the customer counts
*
* @access public
* @since 3.0
* @return void
*/
public function get_counts() {
$this->counts = edd_get_customer_email_address_counts();
}
/**
* Retrieve the table columns
*
* @since 3.0
* @return array $columns Array of all the list table columns
*/
public function get_columns() {
return apply_filters( 'edd_report_customer_columns', array(
'cb' => '<input type="checkbox" />',
'email' => __( 'Email', 'easy-digital-downloads' ),
'customer' => __( 'Customer', 'easy-digital-downloads' ),
'type' => __( 'Type', 'easy-digital-downloads' ),
'date_created' => __( 'Date', 'easy-digital-downloads' )
) );
}
/**
* Get the sortable columns
*
* @since 2.1
* @return array Array of all the sortable columns
*/
public function get_sortable_columns() {
return array(
'date_created' => array( 'date_created', true ),
'email' => array( 'email', true ),
'customer' => array( 'customer_id', false ),
'type' => array( 'type', false )
);
}
/**
* Retrieve the bulk actions
*
* @access public
* @since 3.0
* @return array Array of the bulk actions
*/
public function get_bulk_actions() {
return array(
'delete' => __( 'Delete', 'easy-digital-downloads' )
);
}
/**
* Process the bulk actions
*
* @access public
* @since 3.0
*/
public function process_bulk_action() {
if ( empty( $_REQUEST['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-emails' ) ) {
return;
}
$ids = isset( $_GET['customer'] )
? $_GET['customer']
: false;
if ( ! is_array( $ids ) ) {
$ids = array( $ids );
}
/*
* Only non-primary email addresses can be deleted, so we're building up a safelist using the provided
* IDs. Each ID will be matched against this prior to deletion.
*/
$non_primary_address_ids = edd_get_customer_email_addresses( array(
'id__in' => $ids,
'type__not_in' => array( 'primary' ),
'fields' => 'id'
) );
foreach ( $ids as $id ) {
switch ( $this->current_action() ) {
case 'delete' :
if ( in_array( $id, $non_primary_address_ids ) ) {
edd_delete_customer_email_address( $id );
}
break;
}
}
}
/**
* Get all of the items to display, given the current filters
*
* @since 3.0
*
* @return array $data All the row data
*/
public function get_data() {
$data = array();
$search = $this->get_search();
$args = array( 'status' => $this->get_status() );
// Account for search stripping the "+" from emails.
if ( strpos( $search, ' ' ) ) {
$original_query = $search;
$search = str_replace( ' ', '+', $search );
if ( ! is_email( $search ) ) {
$search = $original_query;
}
}
// Email.
if ( is_email( $search ) ) {
$args['email'] = $search;
// Address ID.
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
// Customer ID.
} elseif ( strpos( $search, 'c:' ) !== false ) {
$args['customer_id'] = trim( str_replace( 'c:', '', $search ) );
// Any...
} else {
$args['search'] = $search;
$args['search_columns'] = array( 'email' );
}
// Parse pagination.
$this->args = $this->parse_pagination_args( $args );
// Get the data.
$emails = edd_get_customer_email_addresses( $this->args );
if ( ! empty( $emails ) ) {
foreach ( $emails as $customer ) {
$data[] = array(
'id' => $customer->id,
'email' => $customer->email,
'customer_id' => $customer->customer_id,
'status' => $customer->status,
'type' => $customer->type,
'date_created' => $customer->date_created,
);
}
}
return $data;
}
/**
* Setup the final data for the table
*
* @since 3.0
* @return void
*/
public function prepare_items() {
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
$this->items = $this->get_data();
$status = $this->get_status( 'total' );
// Setup pagination
$this->set_pagination_args( array(
'total_pages' => ceil( $this->counts[ $status ] / $this->per_page ),
'total_items' => $this->counts[ $status ],
'per_page' => $this->per_page
) );
}
}

View File

@ -0,0 +1,433 @@
<?php
/**
* Customer Reports Table Class
*
* @package EDD
* @subpackage Reports
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.5
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Admin\List_Table;
/**
* EDD_Customer_Reports_Table Class
*
* Renders the Customer Reports table
*
* @since 1.5
*/
class EDD_Customer_Reports_Table extends List_Table {
/**
* Get things started
*
* @since 1.5
* @see WP_List_Table::__construct()
*/
public function __construct() {
parent::__construct( array(
'singular' => 'customer',
'plural' => 'customers',
'ajax' => false
) );
$this->process_bulk_action();
$this->get_counts();
}
/**
* Gets the name of the primary column.
*
* @since 2.5
* @access protected
*
* @return string Name of the primary column.
*/
protected function get_primary_column_name() {
return 'name';
}
/**
* This function renders most of the columns in the list table.
*
* @since 1.5
*
* @param array $item Contains all the data of the customers
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_default( $item, $column_name ) {
$timezone_abbreviation = edd_get_timezone_abbr();
switch ( $column_name ) {
case 'id' :
$value = esc_html( $item['id'] );
break;
case 'email' :
$value = '<a href="mailto:' . rawurlencode( $item['email'] ) . '">' . esc_html( $item['email'] ) . '</a>';
break;
case 'order_count' :
$url = edd_get_admin_url( array(
'page' => 'edd-payment-history',
'customer' => rawurlencode( $item['id'] ),
) );
$value = '<a href="' . esc_url( $url ) . '">' . esc_html( number_format_i18n( $item['order_count'] ) ) . '</a>';
break;
case 'spent' :
$value = edd_currency_filter( edd_format_amount( $item[ $column_name ] ) );
break;
case 'date_created' :
$value = '<time datetime="' . esc_attr( $item['date_created'] ) . '">' . edd_date_i18n( $item['date_created'], 'M. d, Y' ) . '<br>' . edd_date_i18n( $item['date_created'], 'H:i' ) . ' ' . $timezone_abbreviation . '</time>';
break;
default:
$value = isset( $item[ $column_name ] )
? esc_html( $item[ $column_name ] )
: null;
break;
}
// Filter & return
return apply_filters( 'edd_customers_column_' . esc_attr( $column_name ), $value, $item['id'] );
}
/**
* Return the contents of the "Name" column
*
* @since 3.0
*
* @param array $item
* @return string
*/
public function column_name( $item ) {
$state = '';
$status = $this->get_status();
$name = ! empty( $item['name'] ) ? $item['name'] : '&mdash;';
$item_status = ! empty( $item['status'] )
? $item['status']
: 'active';
// State
if ( ( ! empty( $status ) && ( $status !== $item_status ) ) || ( $item_status !== 'active' ) ) {
switch ( $status ) {
case 'pending' :
$value = __( 'Pending', 'easy-digital-downloads' );
break;
case 'active' :
case '' :
default :
$value = __( 'Active', 'easy-digital-downloads' );
break;
}
$state = ' &mdash; ' . $value;
}
// Get the customer's avatar
$avatar = get_avatar( $item['email'], 32 );
// View URL
$view_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['id'] ),
)
);
// Concatenate and return
return $avatar . '<strong><a class="row-title" href="' . esc_url( $view_url ) . '">' . esc_html( $name ) . '</a>' . esc_html( $state ) . '</strong>' . $this->row_actions( $this->get_row_actions( $item ) );
}
/**
* Gets the row actions for the customer.
*
* @since 3.0
* @param array $item
* @return array
*/
private function get_row_actions( $item ) {
$view_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $item['id'] ),
)
);
$logs_url = edd_get_admin_url(
array(
'page' => 'edd-tools',
'tab' => 'logs',
'customer' => urlencode( $item['id'] ),
)
);
$delete_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'delete',
'id' => urlencode( $item['id'] ),
)
);
$actions = array(
'view' => '<a href="' . esc_url( $view_url ) . '">' . __( 'Edit', 'easy-digital-downloads' ) . '</a>',
'logs' => '<a href="' . esc_url( $logs_url ) . '">' . __( 'Logs', 'easy-digital-downloads' ) . '</a>',
'delete' => '<a href="' . esc_url( $delete_url ) . '#edd_general_delete">' . __( 'Delete', 'easy-digital-downloads' ) . '</a>',
);
/**
* Filter the customer row actions.
*
* @since 3.0
* @param array $actions The array of row actions.
* @param array $item The specific item (customer).
*/
return apply_filters( 'edd_customer_row_actions', $actions, $item );
}
/**
* Render the checkbox column
*
* @since 3.0
*
* @param array $item Customer data.
*
* @return string Displays a checkbox
*/
public function column_cb( $item ) {
$name = empty( $item['name'] ) ? $item['email'] : $item['name'];
return sprintf(
'<input type="checkbox" name="%1$s[]" id="%1$s-%2$s" value="%2$s" /><label for="%1$s-%2$s" class="screen-reader-text">%3$s</label>',
/*$1%s*/ 'customer',
/*$2%s*/ esc_attr( $item['id'] ),
/* translators: customer name or email */
esc_html( sprintf( __( 'Select %s', 'easy-digital-downloads' ), $name ) )
);
}
/**
* Retrieve the customer counts
*
* @since 3.0
* @return void
*/
public function get_counts() {
$this->counts = edd_get_customer_counts();
}
/**
* Retrieve the table columns
*
* @since 1.5
* @return array $columns Array of all the list table columns
*/
public function get_columns() {
return apply_filters( 'edd_report_customer_columns', array(
'cb' => '<input type="checkbox" />',
'name' => __( 'Name', 'easy-digital-downloads' ),
'email' => __( 'Email', 'easy-digital-downloads' ),
'order_count' => __( 'Orders', 'easy-digital-downloads' ),
'spent' => __( 'Spent', 'easy-digital-downloads' ),
'date_created' => __( 'Date', 'easy-digital-downloads' )
) );
}
/**
* Get the sortable columns
*
* @since 2.1
* @return array Array of all the sortable columns
*/
public function get_sortable_columns() {
return array(
'date_created' => array( 'date_created', true ),
'name' => array( 'name', true ),
'email' => array( 'email', true ),
'order_count' => array( 'purchase_count', false ),
'spent' => array( 'purchase_value', false )
);
}
/**
* Retrieve the bulk actions
*
* @since 3.0
* @return array Array of the bulk actions
*/
public function get_bulk_actions() {
return array(
'delete' => __( 'Delete', 'easy-digital-downloads' )
);
}
/**
* Process the bulk actions
*
* @since 3.0
*/
public function process_bulk_action() {
if ( empty( $_REQUEST['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-customers' ) ) {
return;
}
check_admin_referer( 'bulk-customers' );
$ids = isset( $_GET['customer'] )
? $_GET['customer']
: false;
if ( ! is_array( $ids ) ) {
$ids = array( $ids );
}
foreach ( $ids as $id ) {
switch ( $this->current_action() ) {
case 'delete' :
edd_delete_customer( $id );
break;
}
}
}
/**
* Builds and retrieves all the reports data.
*
* @since 1.5
* @deprecated 3.0 Use get_data()
*
* @return array All the data for customer reports.
*/
public function reports_data() {
_edd_deprecated_function( __METHOD__, '3.0', 'EDD_Customer_Reports_Table::get_data()' );
return $this->get_data();
}
/**
* Retrieves all of the items to display, given the current filters.
*
* @since 3.0
*
* @return array $data All the row data.
*/
public function get_data() {
$data = array();
$search = $this->get_search();
$args = array( 'status' => $this->get_status() );
// Account for search stripping the "+" from emails.
if ( strpos( $search, ' ' ) ) {
$original_query = $search;
$search = str_replace( ' ', '+', $search );
if ( ! is_email( $search ) ) {
$search = $original_query;
}
}
// Email search.
if ( is_email( $search ) ) {
$args['email'] = $search;
// Customer ID.
} elseif ( is_numeric( $search ) ) {
$args['id'] = $search;
} elseif ( strpos( $search, 'c:' ) !== false ) {
$args['id'] = trim( str_replace( 'c:', '', $search ) );
// User ID.
} elseif ( strpos( $search, 'user:' ) !== false ) {
$args['user_id'] = trim( str_replace( 'u:', '', $search ) );
} elseif ( strpos( $search, 'u:' ) !== false ) {
$args['user_id'] = trim( str_replace( 'u:', '', $search ) );
// Other...
} else {
$args['search'] = $search;
$args['search_columns'] = array( 'name', 'email' );
}
// Parse pagination
$this->args = $this->parse_pagination_args( $args );
if ( is_email( $search ) ) {
$customer_emails = new EDD\Database\Queries\Customer_Email_Address();
$customer_ids = $customer_emails->query(
array(
'fields' => 'customer_id',
'email' => $search,
)
);
$customers = edd_get_customers(
array(
'id__in' => $customer_ids,
)
);
} else {
$customers = edd_get_customers( $this->args );
}
// Get the data
if ( ! empty( $customers ) ) {
foreach ( $customers as $customer ) {
$data[] = array(
'id' => $customer->id,
'user_id' => $customer->user_id,
'name' => $customer->name,
'email' => $customer->email,
'order_count' => $customer->purchase_count,
'spent' => $customer->purchase_value,
'date_created' => $customer->date_created,
);
}
}
return $data;
}
/**
* Setup the final data for the table
*
* @since 1.5
* @return void
*/
public function prepare_items() {
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
$this->items = $this->get_data();
$status = $this->get_status( 'total' );
// Add condition to be sure we don't divide by zero.
// If $this->per_page is 0, then set total pages to 1.
$total_pages = $this->per_page ? ceil( (int) $this->counts[ $status ] / (int) $this->per_page ) : 1;
// Setup pagination
$this->set_pagination_args( array(
'total_pages' => $total_pages,
'total_items' => $this->counts[ $status ],
'per_page' => $this->per_page,
) );
}
}

View File

@ -0,0 +1,635 @@
<?php
/**
* Customers - Admin Actions.
*
* @package EDD
* @subpackage Admin/Customers
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.3
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Update customer.
*
* @since 2.3
* @since 3.0 Updated to use new query methods and custom tables.
*
* @param array $args Form data being passed.
* @return false|array $output Response message.
*/
function edd_edit_customer( $args = array() ) {
// Bail if nothing new to edit.
if ( empty( $args ) || empty( $args['customerinfo'] ) || empty( $args['_wpnonce'] ) ) {
return false;
}
$customer_edit_role = edd_get_edit_customers_role();
// Bail if user cannot edit customers.
if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
wp_die( esc_html__( 'You do not have permission to edit this customer.', 'easy-digital-downloads' ) );
}
$customer_info = $args['customerinfo'];
$customer_id = (int) $customer_info['id'];
$nonce = $args['_wpnonce'];
// Bail if nonce check fails
if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) {
wp_die( esc_html__( 'Cheatin\' eh?!', 'easy-digital-downloads' ) );
}
// Bail if customer does not exist.
$customer = edd_get_customer( $customer_id );
if ( ! $customer ) {
return false;
}
// Parse customer info with defaults.
$customer_info = wp_parse_args( $customer_info, array(
'name' => '',
'email' => '',
'date_created' => '',
'user_id' => 0
) );
if ( ! is_email( $customer_info['email'] ) ) {
edd_set_error( 'edd-invalid-email', __( 'Please enter a valid email address.', 'easy-digital-downloads' ) );
}
if ( (int) $customer_info['user_id'] !== (int) $customer->user_id ) {
// Make sure we don't already have this user attached to a customer
if ( ! empty( $customer_info['user_id'] ) && false !== edd_get_customer_by( 'user_id', $customer_info['user_id'] ) ) {
edd_set_error( 'edd-invalid-customer-user_id', sprintf( __( 'The User ID %d is already associated with a different customer.', 'easy-digital-downloads' ), $customer_info['user_id'] ) );
}
// Make sure it's actually a user
$user = get_user_by( 'id', $customer_info['user_id'] );
if ( ! empty( $customer_info['user_id'] ) && false === $user ) {
edd_set_error( 'edd-invalid-user_id', sprintf( __( 'The User ID %d does not exist. Please assign an existing user.', 'easy-digital-downloads' ), $customer_info['user_id'] ) );
}
}
// Record this for later
$previous_user_id = $customer->user_id;
// Bail if errors exist.
if ( edd_get_errors() ) {
return false;
}
$user_id = absint( $customer_info['user_id'] );
if ( empty( $user_id ) && ! empty( $customer_info['user_login'] ) ) {
// See if they gave an email, otherwise we'll assume login
$user_by_field = is_email( $customer_info['user_login'] )
? 'email'
: 'login';
$user = get_user_by( $user_by_field, $customer_info['user_login'] );
if ( $user ) {
$user_id = $user->ID;
} else {
edd_set_error( 'edd-invalid-user-string', sprintf( __( 'Failed to attach user. The login or email address %s was not found.', 'easy-digital-downloads' ), $customer_info['user_login'] ) );
}
}
// Setup the customer address, if present.
$address = array();
$address['address'] = isset( $customer_info['address'] )
? $customer_info['address']
: '';
$address['address2'] = isset( $customer_info['address2'] )
? $customer_info['address2']
: '';
$address['city'] = isset( $customer_info['city'] )
? $customer_info['city']
: '';
$address['country'] = isset( $customer_info['country'] )
? $customer_info['country']
: '';
$address['postal_code'] = isset( $customer_info['postal_code'] )
? $customer_info['postal_code']
: '';
$address['region'] = isset( $customer_info['region'] )
? $customer_info['region']
: '';
// Sanitize the inputs
$customer_data = array();
$customer_data['name'] = strip_tags( stripslashes( $customer_info['name'] ) );
$customer_data['email'] = $customer_info['email'];
$customer_data['user_id'] = $user_id;
$customer_data['date_created'] = gmdate( 'Y-m-d H:i:s', strtotime( $customer_info['date_created'] ) );
$customer_data = apply_filters( 'edd_edit_customer_info', $customer_data, $customer_id );
$address = apply_filters( 'edd_edit_customer_address', $address, $customer_id );
$customer_data = array_map( 'sanitize_text_field', $customer_data );
$address = array_map( 'sanitize_text_field', $address );
do_action( 'edd_pre_edit_customer', $customer_id, $customer_data, $address );
$output = array();
$previous_email = $customer->email;
// Add new address before update to skip exists checks
if ( $previous_email !== $customer_data['email'] ) {
$customer->add_email( $customer_data['email'], true );
}
// Update customer
if ( $customer->update( $customer_data ) ) {
$current_address = $customer->get_address();
$address['customer_id'] = $customer->id;
if ( $current_address ) {
edd_update_customer_address( $current_address->id, $address );
} else {
$address['is_primary'] = true;
edd_add_customer_address( $address );
}
$output['success'] = true;
$customer_data = array_merge( $customer_data, $address );
$output['customer_info'] = $customer_data;
} else {
$output['success'] = false;
}
do_action( 'edd_post_edit_customer', $customer_id, $customer_data );
if ( edd_doing_ajax() ) {
wp_send_json( $output );
}
return $output;
}
add_action( 'edd_edit-customer', 'edd_edit_customer', 10, 1 );
/**
* Add an email address to the customer from within the admin and log a customer note
*
* @since 2.6
* @param array $args Array of arguments: nonce, customer id, and email address
* @return mixed Echos JSON if doing AJAX. Returns array of success (bool) and message (string) if not AJAX.
*/
function edd_add_customer_email( $args = array() ) {
$customer_edit_role = edd_get_edit_customers_role();
if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
wp_die( __( 'You do not have permission to edit this customer.', 'easy-digital-downloads' ) );
}
$output = array();
if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) {
$output['success'] = false;
if ( empty( $args['email'] ) ) {
$output['message'] = __( 'Email address is missing.', 'easy-digital-downloads' );
} else if ( empty( $args['customer_id'] ) ) {
$output['message'] = __( 'Customer ID is required.', 'easy-digital-downloads' );
} else {
$output['message'] = __( 'An error has occured. Please try again.', 'easy-digital-downloads' );
}
} else if ( ! wp_verify_nonce( $args['_wpnonce'], 'edd-add-customer-email' ) ) {
$output = array(
'success' => false,
'message' => __( 'Nonce verification failed.', 'easy-digital-downloads' ),
);
} else if ( ! is_email( $args['email'] ) ) {
$output = array(
'success' => false,
'message' => __( 'Invalid email address.', 'easy-digital-downloads' ),
);
} else {
$email = sanitize_email( $args['email'] );
$customer_id = (int) $args['customer_id'];
$primary = 'true' === $args['primary'] ? true : false;
$customer = new EDD_Customer( $customer_id );
$customer_email_id = $customer->add_email( $email, $primary );
if ( false === $customer_email_id ) {
if ( in_array( $email, $customer->emails, true ) ) {
$output = array(
'success' => false,
'message' => __( 'Email already associated with this customer.', 'easy-digital-downloads' ),
);
} else {
$output = array(
'success' => false,
'message' => __( 'Email address is already associated with another customer.', 'easy-digital-downloads' ),
);
}
} else {
$redirect = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer_id ),
'edd-message' => 'email-added',
'edd-email-id' => absint( $customer_email_id ),
)
);
$output = array(
'success' => true,
'message' => __( 'Email successfully added to customer.', 'easy-digital-downloads' ),
'redirect' => $redirect . '#edd_general_emails',
);
$user = wp_get_current_user();
$user_login = ! empty( $user->user_login ) ? $user->user_login : edd_get_bot_name();
$customer_note = sprintf( __( 'Email address %s added by %s', 'easy-digital-downloads' ), $email, $user_login );
$customer->add_note( $customer_note );
if ( $primary ) {
$customer_note = sprintf( __( 'Email address %s set as primary by %s', 'easy-digital-downloads' ), $email, $user_login );
$customer->add_note( $customer_note );
}
}
}
if ( ! isset( $customer_id ) ) {
$customer_id = isset( $args['customer_id'] ) ? $args['customer_id'] : false;
}
do_action( 'edd_post_add_customer_email', $customer_id, $args );
if ( edd_doing_ajax() ) {
wp_send_json( $output );
}
return $output;
}
add_action( 'edd_customer-add-email', 'edd_add_customer_email', 10, 1 );
/**
* Remove an email address to the customer from within the admin and log a customer note
* and redirect back to the customer interface for feedback
*
* @since 2.6
* @return void
*/
function edd_remove_customer_email() {
if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
return false;
}
if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
return false;
}
if ( empty( $_GET['_wpnonce'] ) ) {
return false;
}
$nonce = $_GET['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'edd-remove-customer-email' ) ) {
wp_die( __( 'Nonce verification failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
}
$customer = new EDD_Customer( $_GET['id'] );
if ( $customer->remove_email( $_GET['email'] ) ) {
$url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $customer->id ),
'edd-message' => 'email-removed',
)
);
$user = wp_get_current_user();
$user_login = ! empty( $user->user_login ) ? $user->user_login : edd_get_bot_name();
$customer_note = sprintf( __( 'Email address %s removed by %s', 'easy-digital-downloads' ), sanitize_email( $_GET['email'] ), $user_login );
$customer->add_note( $customer_note );
} else {
$url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $customer->id ),
'edd-message' => 'email-remove-failed',
)
);
}
edd_redirect( $url . '#edd_general_emails' );
}
add_action( 'edd_customer-remove-email', 'edd_remove_customer_email', 10 );
/**
* Set an email address as the primary for a customer from within the admin and log a customer note
* and redirect back to the customer interface for feedback
*
* @since 2.6
* @return void
*/
function edd_set_customer_primary_email() {
if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
return false;
}
if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
return false;
}
if ( empty( $_GET['_wpnonce'] ) ) {
return false;
}
$nonce = $_GET['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'edd-set-customer-primary-email' ) ) {
wp_die( __( 'Nonce verification failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
}
$customer = new EDD_Customer( $_GET['id'] );
if ( $customer->set_primary_email( $_GET['email'] ) ) {
$url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $customer->id ),
'edd-message' => 'primary-email-updated',
)
);
$user = wp_get_current_user();
$user_login = ! empty( $user->user_login ) ? $user->user_login : edd_get_bot_name();
$customer_note = sprintf( __( 'Email address %s set as primary by %s', 'easy-digital-downloads' ), sanitize_email( $_GET['email'] ), $user_login );
$customer->add_note( $customer_note );
} else {
$url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $customer->id ),
'edd-message' => 'primary-email-failed',
)
);
}
edd_redirect( $url . '#edd_general_emails' );
}
add_action( 'edd_customer-primary-email', 'edd_set_customer_primary_email', 10 );
/**
* Delete a customer
*
* @since 2.3
* @param array $args The $_POST array being passed
* @return int Whether it was a successful deletion
*/
function edd_customer_delete( $args = array() ) {
$customer_edit_role = edd_get_edit_customers_role();
if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
wp_die( __( 'You do not have permission to delete this customer.', 'easy-digital-downloads' ) );
}
if ( empty( $args ) ) {
return;
}
$customer_id = (int)$args['customer_id'];
$confirm = ! empty( $args['edd-customer-delete-confirm'] );
$remove_data = ! empty( $args['edd-customer-delete-records'] );
$nonce = $args['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'delete-customer' ) ) {
wp_die( __( 'Cheatin\' eh?!', 'easy-digital-downloads' ) );
}
if ( ! $confirm ) {
edd_set_error( 'customer-delete-no-confirm', __( 'Please confirm you want to delete this customer', 'easy-digital-downloads' ) );
}
if ( edd_get_errors() ) {
edd_redirect(
edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer_id ),
)
)
);
}
$customer = new EDD_Customer( $customer_id );
do_action( 'edd_pre_delete_customer', $customer_id, $confirm, $remove_data );
$success = false;
if ( $customer->id > 0 ) {
$payments_array = explode( ',', $customer->payment_ids );
$success = edd_destroy_customer( $customer->id );
if ( $success ) {
if ( $remove_data ) {
// Remove all payments, logs, etc
foreach ( $payments_array as $payment_id ) {
edd_destroy_order( $payment_id );
}
} else {
// Just set the payments to customer_id of 0
foreach ( $payments_array as $payment_id ) {
edd_update_payment_meta( $payment_id, '_edd_payment_customer_id', 0 );
}
}
$redirect = edd_get_admin_url( array( 'page' => 'edd-customers', 'edd-message' => 'customer-deleted' ) );
} else {
edd_set_error( 'edd-customer-delete-failed', __( 'Error deleting customer', 'easy-digital-downloads' ) );
$redirect = edd_get_admin_url( array( 'page' => 'edd-customers', 'view' => 'delete', 'id' => absint( $customer_id ) ) );
}
} else {
edd_set_error( 'edd-customer-delete-invalid-id', __( 'Invalid Customer ID', 'easy-digital-downloads' ) );
$redirect = edd_get_admin_url( array( 'page' => 'edd-customers' ) );
}
edd_redirect( $redirect );
}
add_action( 'edd_delete-customer', 'edd_customer_delete', 10, 1 );
/**
* Disconnect a user ID from a customer
*
* @since 2.3
* @param array $args Array of arguments
* @return bool If the disconnect was successful
*/
function edd_disconnect_customer_user_id( $args = array() ) {
$customer_edit_role = edd_get_edit_customers_role();
if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
wp_die( __( 'You do not have permission to edit this customer.', 'easy-digital-downloads' ) );
}
if ( empty( $args ) ) {
return;
}
$customer_id = (int)$args['customer_id'];
$nonce = $args['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) {
wp_die( __( 'Cheatin\' eh?!', 'easy-digital-downloads' ) );
}
$customer = new EDD_Customer( $customer_id );
if ( empty( $customer->id ) ) {
return false;
}
do_action( 'edd_pre_customer_disconnect_user_id', $customer_id, $customer->user_id );
$customer_args = array( 'user_id' => 0 );
if ( $customer->update( $customer_args ) ) {
$output['success'] = true;
} else {
$output['success'] = false;
edd_set_error( 'edd-disconnect-user-fail', __( 'Failed to disconnect user from customer', 'easy-digital-downloads' ) );
}
do_action( 'edd_post_customer_disconnect_user_id', $customer_id );
if ( edd_doing_ajax() ) {
wp_send_json( $output );
}
return $output;
}
add_action( 'edd_disconnect-userid', 'edd_disconnect_customer_user_id', 10, 1 );
/**
* Process manual verification of customer account by admin
*
* @since 2.4.8
* @return void
*/
function edd_process_admin_user_verification() {
if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
return false;
}
if ( empty( $_GET['_wpnonce'] ) ) {
return false;
}
$nonce = $_GET['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'edd-verify-user' ) ) {
wp_die( __( 'Nonce verification failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
}
$customer = new EDD_Customer( $_GET['id'] );
edd_set_user_to_verified( $customer->user_id );
$url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer->id ),
'edd-message' => 'user-verified',
)
);
edd_redirect( $url );
}
add_action( 'edd_verify_user_admin', 'edd_process_admin_user_verification' );
/**
* Register the reset single customer stats batch processor
* @since 2.5
*/
function edd_register_batch_single_customer_recount_tool() {
add_action( 'edd_batch_export_class_include', 'edd_include_single_customer_recount_tool_batch_processer', 10, 1 );
}
add_action( 'edd_register_batch_exporter', 'edd_register_batch_single_customer_recount_tool', 10 );
/**
* Loads the tools batch processing class for recounting stats for a single customer
*
* @since 2.5
* @param string $class The class being requested to run for the batch export
* @return void
*/
function edd_include_single_customer_recount_tool_batch_processer( $class ) {
if ( 'EDD_Tools_Recount_Single_Customer_Stats' === $class ) {
require_once EDD_PLUGIN_DIR . 'includes/admin/tools/class-edd-tools-recount-single-customer-stats.php';
}
}
/**
* Removes a customer address
*
* @since 3.0
* @return void
*/
function edd_remove_customer_address() {
if ( ! is_admin() || ! current_user_can( edd_get_edit_customers_role() ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'easy-digital-downloads' ) );
}
if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) || empty( $_GET['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'edd-remove-customer-address' ) ) {
wp_die( __( 'Nonce verification failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
}
$address = edd_fetch_customer_address( absint( $_GET['id'] ) );
$removed = $address instanceof EDD\Customers\Customer_Address ? edd_delete_customer_address( absint( $_GET['id'] ) ) : false;
$url = edd_get_admin_url( array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => urlencode( $address->customer_id ),
'edd-message' => 'address-removed'
) );
if ( $removed ) {
$url = add_query_arg( 'edd-message', 'address-removed', $url );
} else {
$url = add_query_arg( 'edd-message', 'address-remove-failed', $url );
}
edd_redirect( $url . '#edd_general_addresses' );
}
add_action( 'edd_customer-remove-address', 'edd_remove_customer_address', 10 );

View File

@ -0,0 +1,185 @@
<?php
/**
* Customers - Admin Functions.
*
* @package EDD
* @subpackage Admin/Customers
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.3
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Register a view for the single customer view
*
* @since 2.3
* @param array $views An array of existing views
* @return array The altered list of views
*/
function edd_register_default_customer_views( $views ) {
return array_merge( $views, array(
'overview' => 'edd_customers_view',
'emails' => 'edd_customers_emails_view',
'addresses' => 'edd_customers_addresses_view',
'delete' => 'edd_customers_delete_view',
'notes' => 'edd_customer_notes_view',
'tools' => 'edd_customer_tools_view',
) );
}
add_filter( 'edd_customer_views', 'edd_register_default_customer_views', 1, 1 );
/**
* Register a tab for the single customer view
*
* @since 2.3
* @param array $tabs An array of existing tabs
* @return array The altered list of tabs
*/
function edd_register_default_customer_tabs( $tabs ) {
return array_merge( $tabs, array(
'overview' => array( 'dashicon' => 'dashicons-admin-users', 'title' => _x( 'Profile', 'Customer Details tab title', 'easy-digital-downloads' ) ),
'emails' => array( 'dashicon' => 'dashicons-email', 'title' => _x( 'Emails', 'Customer Emails tab title', 'easy-digital-downloads' ) ),
'addresses' => array( 'dashicon' => 'dashicons-admin-home', 'title' => _x( 'Addresses', 'Customer Addresses tab title', 'easy-digital-downloads' ) ),
'notes' => array( 'dashicon' => 'dashicons-admin-comments', 'title' => _x( 'Notes', 'Customer Notes tab title', 'easy-digital-downloads' ) ),
'tools' => array( 'dashicon' => 'dashicons-admin-tools', 'title' => _x( 'Tools', 'Customer Tools tab title', 'easy-digital-downloads' ) )
) );
}
add_filter( 'edd_customer_tabs', 'edd_register_default_customer_tabs', 1, 1 );
/**
* Register the Delete icon as late as possible so it's at the bottom
*
* @since 2.3.1
* @param array $tabs An array of existing tabs
* @return array The altered list of tabs, with 'delete' at the bottom
*/
function edd_register_delete_customer_tab( $tabs ) {
$tabs['delete'] = array(
'dashicon' => 'dashicons-trash',
'title' => _x( 'Delete', 'Delete Customer tab title', 'easy-digital-downloads' )
);
return $tabs;
}
add_filter( 'edd_customer_tabs', 'edd_register_delete_customer_tab', PHP_INT_MAX, 1 );
/**
* Remove the admin bar edit profile link when the user is not verified
*
* @since 2.4.4
* @return void
*/
function edd_maybe_remove_adminbar_profile_link() {
if ( current_user_can( 'manage_shop_settings' ) ) {
return;
}
if ( edd_user_pending_verification() ) {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'edit-profile', 'user-actions' );
}
}
add_action( 'wp_before_admin_bar_render', 'edd_maybe_remove_adminbar_profile_link' );
/**
* Remove the admin menus and disable profile access for non-verified users
*
* @since 2.4.4
* @return void
*/
function edd_maybe_remove_menu_profile_links() {
if ( edd_doing_ajax() ) {
return;
}
if ( current_user_can( 'manage_shop_settings' ) ) {
return;
}
if ( edd_user_pending_verification() ) {
if( defined( 'IS_PROFILE_PAGE' ) && true === IS_PROFILE_PAGE ) {
$url = esc_url( edd_get_user_verification_request_url() );
$message = sprintf( __( 'Your account is pending verification. Please click the link in your email to activate your account. No email? <a href="%s">Click here</a> to send a new activation code.', 'easy-digital-downloads' ), esc_url( $url ) );
$title = __( 'Account Pending Verification', 'easy-digital-downloads' );
$args = array(
'response' => 403,
);
wp_die( $message, $title, $args );
}
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
}
}
add_action( 'admin_init', 'edd_maybe_remove_menu_profile_links' );
/**
* Add Customer column to Users list table.
*
* @since 3.0
*
* @param array $columns Existing columns.
*
* @return array $columns Columns with `Customer` added.
*/
function edd_add_customer_column_to_users_table( $columns ) {
$columns['edd_customer'] = __( 'Customer', 'easy-digital-downloads' );
return $columns;
}
add_filter( 'manage_users_columns', 'edd_add_customer_column_to_users_table' );
/**
* Display customer details on Users list table.
*
* @since 3.0
*
* @param string $value Existing value of the custom column.
* @param string $column_name Column name.
* @param int $user_id User ID.
*
* @return string URL to Customer page, existing value otherwise.
*/
function edd_render_customer_column( $value, $column_name, $user_id ) {
if ( 'edd_customer' === $column_name ) {
$customer = new EDD_Customer( $user_id, true );
if ( $customer->id > 0 ) {
$name = '#' . $customer->id . ' ';
$name .= ! empty( $customer->name ) ? $customer->name : '<em>' . __( 'Unnamed Customer', 'easy-digital-downloads' ) . '</em>';
$view_url = edd_get_admin_url(
array(
'page' => 'edd-customers',
'view' => 'overview',
'id' => absint( $customer->id ),
)
);
return '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>';
}
}
return $value;
}
add_action( 'manage_users_custom_column', 'edd_render_customer_column', 10, 3 );
/**
* Renders the customer details header (gravatar/name).
*
* @since 3.0
* @param \EDD_Customer $customer
* @return void
*/
function edd_render_customer_details_header( \EDD_Customer $customer ) {
?>
<div class="edd-item-header-small">
<?php echo get_avatar( $customer->email, 30 ); ?> <span><?php echo esc_html( $customer->name ); ?></span>
</div>
<?php
}

File diff suppressed because it is too large Load Diff