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.
示例#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;
}
示例#2
0
 public function test_customer_notes()
 {
     $customer = new Give_Customer('*****@*****.**');
     $this->assertInternalType('array', $customer->notes);
     $this->assertEquals(0, $customer->get_notes_count());
     $note_1 = $customer->add_note('Testing');
     $this->assertEquals(0, array_search($note_1, $customer->notes));
     $this->assertEquals(1, $customer->get_notes_count());
     $note_2 = $customer->add_note('Test 2nd Note');
     $this->assertEquals(1, array_search($note_1, $customer->notes));
     $this->assertEquals(0, array_search($note_2, $customer->notes));
     $this->assertEquals(2, $customer->get_notes_count());
     // Verify we took out all empty rows
     $this->assertEquals(count($customer->notes), count(array_values($customer->notes)));
     // Test 1 note per page, page 1
     $newest_note = $customer->get_notes(1);
     $this->assertEquals(1, count($newest_note));
     $this->assertEquals($newest_note[0], $note_2);
     // Test 1 note per page, page 2
     $second_note = $customer->get_notes(1, 2);
     $this->assertEquals(1, count($second_note));
     $this->assertEquals($second_note[0], $note_1);
 }