Registering Plugin Settings

Ninja Forms THREE provides a Settings submenu page for registering plugin settings for both the main plugin as well as add-ons. Settings registered with this system will be displayed and saved by Ninja Forms automatically. Creating a separate setting submenu for an add-on will require developing your own process for displaying, processing, and saving settings. Add-ons requiring heavy customization for plugin settings are free to create a new submenu page, but basic settings are easily handled by Ninja Forms.

For more details on the below mentioned WordPress Hooks, see the WordPress Hooks Plugin Settings documentation.

Register Plugin Settings

Individual settings can be added to the master $settings array, underneath a settings group array key. For example:

  • Settings Groups 1
    • Setting A
    • Setting B
  • Settings Group 2
    • Setting C

Settings are configured following the same format as Action Settings and Field Settings. Refer to the Settings Configuration documentation for an example list of setting properties, with descriptions. Note: not all properties are supported.

Register Settings Groups

Settings are registered underneath a setting group. A new Settings Group can be created by filtering the $groups array.

Defining a new Settings Group requires a unique id (which should match the array key) and a translatable label.

Each Settings Group is rendered as a metabox on the Ninja Forms Settings submenu page in the WordPress Admin.

Checking Setting Values

Hook: ninja_forms_check_setting_{$id}

Example: ninja_forms_check_setting_example_setting

Each time the Ninja Forms Settings submenu page is loaded, a WordPress filter hook is fired for every setting. This filter hook allows for add-ons to check (validate) the value of each setting. When checking or validating a setting’s value, the setting can be updated with errors before being passed back through the filter.

Errors added to a setting will display an Admin Notice at the top of the Settings submenu page, which links to an inline error displayed below the appropriate setting.

An error can be added as a translatable string to the $setting[ ‘error’ ] array item (Note: array key is NOT required, only the value).

Updating Setting’s Values

Hook: ninja_forms_update_setting_{$id}

Example: ninja_forms_update_setting_example_setting

Before a setting’s value is saved, the value is first sanitized, the filtered.

Saving Setting’s Values

Hook: ninja_forms_save_setting_{$id}

Example: ninja_forms_save_setting_example_setting

After a setting’s value has been saved, a WordPress Action Hook is triggered, passing the setting’s value, for further processing.

Full Code Example

The following example organizes all of the add-on related Ninja Forms Settings hooks inside of a dedicated plugin settings class: