Managing Notes with the GFAPI

Introduction

The GFAPI methods for managing notes were added in Gravity Forms 2.4.18.

See the GFAPI article for other available methods.

get_notes

Returns the notes for the given search criteria.

public static function get_notes( $search_criteria = array(), $sorting = null ) {}

Parameters

  • $search_criteriaarray
    Optional. An array containing one or more of the following arguments:
    • id int
      The ID of the note to be retrieved.
    • entry_id int
      The ID of the entry the notes are to be retrieved for.
    • user_id int
      The ID of the user the notes are to be retrieved for.
    • user_name string
      The user_name of the user the notes are to be retrieved for.
    • note_type string
      The type of note to be retrieved.
    • sub_type string
      The sub type of note to be retrieved.
    • start_date string
      Retrieves notes created on or after the date and time specified in the Y-m-d H:i:s format.
    • end_date string
      Retrieves notes created before the date and time specified in the Y-m-d H:i:s format.
  • $sortingarray
    Optional. An array containing the sorting arguments

The default sorting arguments are defined like so:

$sorting = array( 'key' => 'id', 'direction' => 'ASC' );

Returns

Usage Example

Getting all notes for the specified entry

$search_criteria = array( 'entry_id' => $entry_id );
$result = GFAPI::get_notes( $search_criteria );

get_note

Returns the specified note.

public static function get_note( $note_id ) {}

Parameters

  • $note_id int
    The ID of the note to be retrieved.

Returns

Usage Example

$result = GFAPI::get_note( $note_id );

add_note

Adds a note to the specified entry.

public static function add_note( $entry_id, $user_id, $user_name, $note, $note_type = 'user', $sub_type = null ) {}

Parameters

  • $entry_id int
    The ID of the entry the note is being added to.
  • $user_id int
    The ID of the user adding the note.
  • $user_name string
    The user_name of the user adding the note.
  • $note string
    The content of the note being added.
  • $note_type string
    Optional. The type of note being added.
  • $sub_type string
    Optional. The sub type of note being added.

Returns

  • $result WP_Error|int
    A WP_Error if an error occurs, or the ID of the note returned by the database.

Usage Example

Adding a user note

$result = GFAPI::add_note( $entry_id, $user_id, $user_name, 'this is a test note' );

delete_note

Deletes the specified note.

public static function delete_note( $note_id ) {}

Parameters

  • $note_id int
    The ID of the note to be retrieved.

Returns

  • $result WP_Error|bool
    A WP_Error if an error occurs, or true on success.

Usage Example

$result = GFAPI::delete_note( $note_id );

update_note

Updates the specified note.

Parameters

  • $notearray
    An array containing one or more of the following arguments.
    • id int
      The ID of the note to be updated.
    • entry_id int
      The ID of the entry the note is for.
    • user_id int
      The ID of the user the note was added by.
    • user_name string
      The user_name of the user the note was added by.
    • date_created string
      The date the note was created in the Y-m-d H:i:s format.
    • value string
      The note content.
    • note_type string
      The note type.
    • sub_type string
      The note sub type.
  • $note_id string|int
    Optional. The ID of the note to be updated when not included in the $note array.

Returns

  • $result WP_Error|bool
    A WP_Error if an error occurs, or true on success.

Usage Example

Updating the note content

$note = array( 'value' => 'the updated note' );
$result = GFAPI::update_note( $note, $note_id );