/**
 * Save a customer note being added
 *
 * @since  2.3
 * @param  array $args The $_POST array being passeed
 * @return int         The Note ID that was saved, or 0 if nothing was saved
 */
function edd_customer_save_note($args)
{
    $customer_view_role = apply_filters('edd_view_customers_role', 'view_shop_reports');
    if (!is_admin() || !current_user_can($customer_view_role)) {
        wp_die(__('You do not have permission to edit this customer.', 'edd'));
    }
    if (empty($args)) {
        return;
    }
    $customer_note = trim(sanitize_text_field($args['customer_note']));
    $customer_id = (int) $args['customer_id'];
    $nonce = $args['add_customer_note_nonce'];
    if (!wp_verify_nonce($nonce, 'add-customer-note')) {
        wp_die(__('Cheatin\' eh?!', 'edd'));
    }
    if (empty($customer_note)) {
        edd_set_error('empty-customer-note', __('A note is required', 'edd'));
    }
    if (edd_get_errors()) {
        return;
    }
    $customer = new EDD_Customer($customer_id);
    $new_note = $customer->add_note($customer_note);
    do_action('edd_pre_insert_customer_note', $customer_id, $new_note);
    if (!empty($new_note) && !empty($customer->id)) {
        ob_start();
        ?>
		<div class="customer-note-wrapper dashboard-comment-wrap comment-item">
			<span class="note-content-wrap">
				<?php 
        echo stripslashes($new_note);
        ?>
			</span>
		</div>
		<?php 
        $output = ob_get_contents();
        ob_end_clean();
        if (defined('DOING_AJAX') && DOING_AJAX) {
            echo $output;
            exit;
        }
        return $new_note;
    }
    return false;
}
/**
 * Process the 'remove' URL on the profile editor when customers wish to remove an email address
 *
 * @since  2.6
 * @return void
 */
function edd_process_profile_editor_remove_email()
{
    if (!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($_GET['_wpnonce'], 'edd-remove-customer-email')) {
        return false;
    }
    if (empty($_GET['email']) || !is_email($_GET['email'])) {
        return false;
    }
    $customer = new EDD_Customer(get_current_user_id(), true);
    if ($customer->remove_email($_GET['email'])) {
        $url = add_query_arg('updated', true, $_GET['redirect']);
        $user = wp_get_current_user();
        $user_login = !empty($user->user_login) ? $user->user_login : '******';
        $customer_note = __(sprintf('Email address %s removed by %s', $_GET['email'], $user_login), 'easy-digital-downloads');
        $customer->add_note($customer_note);
    } else {
        edd_set_error('profile-remove-email-failure', __('Error removing email address from profile. Please try again later.', 'easy-digital-downloads'));
        $url = $_GET['redirect'];
    }
    wp_safe_redirect($url);
    exit;
}