Managing Forms with WP-CLI

In this article, we will show you how to do things such as import, export, update, delete, and even create forms using the CLI Add-On for Gravity Forms.

Pre-Requisites

Creating Forms

wp gf form create

Examples

  • Creates a new form with just a title and description.

    wp gf form create 'My Form Title' 'Description Here'


Parameters

ArgumentDescription
<title>The title of the new form. Overrides the title defined in the optional JSON.
[<description>]The description of the new form. Overrides the description defined in the optional JSON.
[--form-json=<value>]The JSON formatted form.
[--porcelain]If used, outputs just the created form ID instead of the standard success message.

Deleting Forms

wp gf form delete

Examples

  • Move form 5 to the trash.

    wp gf form delete 5

  • Permanently delete form 5.

    wp gf form delete 5 --force

Parameters

ArgumentDescription
<form-id>...One or more IDs of forms to be deleted.
[--force]Skips the trash and permanently deletes the form.

Duplicating Forms

wp gf form duplicate

Examples

  • Creates a duplicate copy of form 5.

    wp gf form duplicate 5


Parameters

ArgumentDescription
<form-id>The ID of the form to be duplicated.
[--porcelain]If used, outputs just the duplicate form ID instead of the standard success message.

Editing Forms

wp gf form edit

Examples

  • Launch the editor for form 5.

    wp gf form edit 5


Parameters

ArgumentDescription
<form-id>The ID of the form to be edited.

Exporting Forms

wp gf form export

Examples

  • Exports all forms to the current working directory.

    wp gf form export

  • Exports form 5 to a specific location.

    wp gf form export 5 --dir=/my/custom/path

  • Exports form 5 using a custom filename.

    wp gf form export 5 --filename=testing.json

Parameters

ArgumentDescription
[<form-id>]The ID of the form to export. If not set, exports all forms.
[--dir='value']The path to the location that the export should be stored.
Default: current working directory.
[--filename='value']The filename for the form to export. Defaults to the current date.
[--porcelain]Overrides the standard success message with just the export file path.

Listing Forms

wp gf form list

Examples

  • Get a JSON formatted list of active forms sorted by id.

    wp gf form list --active --sort_column=id --format=json


Parameters

ArgumentDescription
[--active]List active forms.
Default: true.
[--trash]List forms in trash.
Default: false.
[--sort-column=<value>]The column to sort the list by.
Accepted values: id, title, date_created, is_active, and is_trash.
Default: id.
[--sort-dir=<value>]The direction to use when sorting.
Accepted values: ASC or DESC.
Default: ASC.
[--format=<value>]Defines the format in which the forms will be listed.
Accepted values: table, csv, json, and count.
Default: table.

Getting Forms

wp gf form get

Examples

  • Gets the JSON for form 5.

    wp gf form get 5


Parameters

ArgumentDescription
<form-id>The ID of the form to get.

Importing Forms

wp gf form import

Examples

  • Imports one or more forms from the supplied .json file.

    wp gf form import /path/to/my/file.json


Parameters

ArgumentDescription
<json-path>The path to a file containing the JSON formatted form(s) to be imported.

Updating Forms

wp gf form update

Note: This command replaces the existing form object. Always provide a complete and valid JSON form structure. Supplying a partial form object may corrupt the form or result in data loss.

Examples

  • Updates form 5 using the supplied JSON string.

    wp gf form update 5 --form-json='{snip}'

  • Updates form 5 using the supplied .json file.

    wp gf form update 5 --file='/path/to/my/file.json'

Parameters

ArgumentDescription
<form-id>The ID of the form to update.
[--form-json=<value>]The JSON formatted form.
[--file=<value>]The path to a file containing the JSON formatted form.

How To Update A Form

  1. Export a form using WP-CLI: wp gf form export 5 –path=./form-5.json
  2. Edit the file (form-5.json) to change any property
    You can set a form as active/inactive updating the is_active property to true or false.
  3. Apply the update using WP-CLI: wp gf form update 5 –file=./form-5.json

Form Properties Settings Reference

Note: This reference lists top-level properties only. It is not exhaustive and does not include field-level settings.

PropertyTypeDescription
idinteger123
titlestring“Subscribe”
descriptionstring“”
labelPlacementstring“top_label”
fieldsarray2 field objects (Name, Email A)
buttonobject{“type”:”text”,”text”:”Submit”,…}
descriptionPlacementstring“below”
versionstring“2.9.8”
markupVersioninteger2
nextFieldIdinteger3
is_activebooleantrue
useCurrentUserAsAuthorbooleantrue
postContentTemplateEnabledbooleanfalse
postTitleTemplateEnabledbooleanfalse
postTitleTemplatestring“”
postContentTemplatestring“”
lastPageButtonnullnull
paginationnullnull
firstPageCssClassnullnull
validationPlacementstring“below”
subLabelPlacementstring“below”
requiredIndicatorstring“text”
customRequiredIndicatorstring“(Required)”
cssClassstring“”
saveButtonTextstring“Save & Continue”
limitEntriesbooleanfalse
limitEntriesCountstring“”
limitEntriesPeriodstring“”
limitEntriesMessagestring“”
scheduleFormbooleanfalse
scheduleStartstring“”
scheduleEndstring“”
schedulePendingMessagestring“”
scheduleMessagestring“”
requireLoginbooleanfalse
requireLoginMessagestring“”
enableHoneypotbooleantrue
honeypotActionstring“spam”
validationSummarybooleanfalse
deprecatedstring“”
saveEnabledstring“”
enableAnimationbooleanfalse
saveobject{“enabled”:false,”button”:{“type”:”link”,”text”:”Save & Continue”}}
scheduleStartHourstring“”
scheduleStartMinutestring“”
scheduleStartAmpmstring“”
scheduleEndHourstring“”
scheduleEndMinutestring“”
scheduleEndAmpmstring“”
confirmationsarray1 confirmation object (“Default Confirmation”)
notificationsarray1 notification object (“Admin Notification”)