Give_Customer::add_note PHP Method

add_note() public method

Add a note for the customer.
Since: 1.0
public add_note ( string $note = '' ) : string | boolean
$note string The note to add. Default is empty.
return string | boolean The new note if added successfully, false otherwise.
    public function add_note($note = '')
    {
        $note = trim($note);
        if (empty($note)) {
            return false;
        }
        $notes = $this->get_raw_notes();
        if (empty($notes)) {
            $notes = '';
        }
        $note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')) . ' - ' . $note;
        $new_note = apply_filters('give_customer_add_note_string', $note_string);
        $notes .= "\n\n" . $new_note;
        do_action('give_customer_pre_add_note', $new_note, $this->id);
        $updated = $this->update(array('notes' => $notes));
        if ($updated) {
            $this->notes = $this->get_notes();
        }
        do_action('give_customer_post_add_note', $this->notes, $new_note, $this->id);
        // Return the formatted note, so we can test, as well as update any displays
        return $new_note;
    }

Usage Example

Ejemplo n.º 1
0
/**
 * Save a customer note being added
 *
 * @since  1.0
 *
 * @param  array $args The $_POST array being passeed
 *
 * @return int         The Note ID that was saved, or 0 if nothing was saved
 */
function give_customer_save_note($args)
{
    $customer_view_role = apply_filters('give_view_customers_role', 'view_give_reports');
    if (!is_admin() || !current_user_can($customer_view_role)) {
        wp_die(__('You do not have permission to edit this donor.', 'give'));
    }
    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?!', 'give'));
    }
    if (empty($customer_note)) {
        give_set_error('empty-customer-note', __('A note is required', 'give'));
    }
    if (give_get_errors()) {
        return;
    }
    $customer = new Give_Customer($customer_id);
    $new_note = $customer->add_note($customer_note);
    do_action('give_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;
}
All Usage Examples Of Give_Customer::add_note