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.

Method Overview

ClassGFAPI
Functionget_notes
Parameterssee_below
Returnssee_below

Source Code

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

Parameters

ParamTypeDescription
$search_criteriaarrayOptional.
An associative array containing the search arguments.
$sortingarrayOptional.
An associative array containing the sorting arguments.

Search Arguments

An associative array supporting the following properties.

PropTypeDescription
idintegerThe ID of the note to be retrieved.
entry_idinteger|arrayThe ID of the entry the notes are to be retrieved for, or an array of entry IDs.
user_idintegerThe ID of the user the notes are to be retrieved for.
user_namestringThe user_name of the user the notes are to be retrieved for.
note_typestringThe type of note to be retrieved. If the note is triggered by a Notification the note_type will be “notification”, if it is triggered by an add-on it will use that add-on slug, for GravityFlow it will be “gravityflow”.
sub_typestringThe sub type of note to be retrieved. See sub type values.
start_datestringRetrieves notes created on or after the date and time specified in the Y-m-d H:i:s format.
end_datestringRetrieves notes created on or before the date and time specified in the Y-m-d H:i:s format. A time of 00:00:00 searches through the end of that day.

Sorting Arguments

An optional associative array supporting the following properties.

PropTypeDescription
keystringThe column to sort by: id, entry_id, user_id, user_name, user_email, date_created, value, note_type, or sub_type. Defaults to id.
directionstringThe direction to sort by: ASC or DESC. Defaults to 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.

Method Overview

ClassGFAPI
Functionget_note
Parameterssee_below
Returnssee_below

Source Code

public static function get_note( $note_id ) {}

Parameters

ParamTypeDescription
$note_idintegerThe 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.

Method Overview

ClassGFAPI
Functionadd_note
Parameterssee_below
Returnssee_below

Source Code

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

Parameters

ParamTypeDescription
$entry_idintegerThe ID of the entry the note is being added to.
$user_idintegerThe ID of the user adding the note.
$user_namestringThe user_name of the user adding the note.
$notestringThe content of the note being added.
$note_typestringOptional. The type of note being added. Defaults to user. If the note is triggered by a Notification the note_type will be “notification”, if it is triggered by an add-on it will use that add-on slug. For example, for Gravity Flow it will be “gravityflow”.
$sub_typestringOptional. The subtype of the note being added. See sub type values.

Sub Type Values

Any string up to 50 characters is accepted. sub_type is not a fixed list. Third-party add-ons can also add their own values. The entry detail screen applies built-in styling to the following values.

ValueDescription
successStyled as a success note. Used when a notification is passed to the sending server, and for successful payment actions.
errorStyled as an error note. Used when a notification, feed, payment action, or entry value save fails.
warningStyled as a warning note. Available for add-ons and custom code.
infoStyled as an info note. Available for add-ons and custom code.

Any other value is stored and shown with the default note styling. On the entry detail screen, the note content is given the class gforms_note_{sub_type}, which can be used to style a custom value.

Returns

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

Usage Example

Adding a user note

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

Adding a Success note for a Notification

$result = GFAPI::add_note( $entry_id, $user_id, $user_name, 'This is a success note for Notification', 'notification', 'success' );

delete_note

Deletes the specified note.

Method Overview

ClassGFAPI
Functiondelete_note
Parameterssee_below
Returnssee_below

Source Code

public static function delete_note( $note_id ) {}

Parameters

ParamTypeDescription
$note_idintegerThe ID of the note to be deleted.

Returns

  • $result WP_Error|int
    A WP_Error if the note does not exist, or the number of rows deleted on success.

Usage Example

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

update_note

Updates the specified note.

Method Overview

ClassGFAPI
Functionupdate_note
Parameterssee_below
Returnssee_below

Source Code

public static function update_note( $note, $note_id = '' ) {}

Parameters

ParamTypeDescription
$notearrayAn associative array containing the note properties.
$note_idintegerOptional. The ID of the note to be updated when not included in the $note array.

Note Properties

An associative array supporting the following properties. Omitted properties keep their current values.

PropTypeDescription
idintegerThe ID of the note to be updated.
entry_idintegerThe ID of the entry the note is for.
user_idintegerThe ID of the user the note was added by.
user_namestringThe user_name of the user the note was added by.
date_createdstringThe date the note was created in the Y-m-d H:i:s format.
valuestringThe content of the note.
note_typestringThe note type.
sub_typestringThe note sub type. See sub type values.

Returns

  • $result WP_Error|int|bool
    A WP_Error if the note is missing or the input is invalid, the number of rows updated on success, or false if the database update fails.

Usage Example

Updating the note content

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