Ninja Forms plugin menu access

Ninja Forms plugin protects all its menu items with ‘manage_options” user capability by default.

Thanks to plugin developers it’s possible to replace default user capability for every menu item using custom filter:

Ninja Forms – ninja_forms_menu_ninja-forms_capability
Dashboard – ninja_forms_admin_all_forms_capabilities
Add New – ninja_forms_admin_add_new_capabilities
Submissions – ninja_forms_admin_submissions_capabilities
Import/Export – ninja_forms_admin_import_export_capabilities
Settings – ninja_forms_admin_settings_capabilities
Get Help – ninja_forms_admin_status_capabilities
Add-Ons – ninja_forms_admin_extend_capabilities

How to use these filters? Look at the example below:

/*
 * Custom capabilities for Ninja Forms admin menu
 */
 
// Ninja Forms
 add_filter('ninja_forms_menu_ninja-forms_capability', 'ninja_forms_menu_get_cap', 10, 1);
 function ninja_forms_menu_get_cap( $cap ) {
     $cap = 'nf_admin_menu';
     return $cap;
 }

// Ninja Forms -> Dashboard 
 add_filter('ninja_forms_admin_all_forms_capabilities', 'ninja_forms_dashboard_get_cap', 10, 1);
 function ninja_forms_dashboard_get_cap( $cap ) {
     $cap = 'nf_admin_menu';
     return $cap;
 }

// Ninja Forms -> Add New 
 add_filter('ninja_forms_admin_add_new_capabilities', 'ninja_forms_add_new_get_cap', 10, 1);
 function ninja_forms_add_new_get_cap( $cap ) {
     $cap = 'nf_add_new';
     return $cap;
 }

// Ninja Forms -> Submissions 
 add_filter('ninja_forms_admin_submissions_capabilities', 'ninja_forms_submissions_get_cap', 10, 1);
 function ninja_forms_submissions_get_cap( $cap ) {
     $cap = 'nf_submissions';
     return $cap;
 }

// Ninja Forms -> Settings
 add_filter('ninja_forms_admin_settings_capabilities', 'ninja_forms_settings_get_cap', 10, 1);
 function ninja_forms_settings_get_cap( $cap ) {
     $cap = 'nf_settings';
     return $cap;
 }

// Ninja Forms -> Get Help 
 add_filter('ninja_forms_admin_status_capabilities', 'ninja_forms_status_get_cap', 10, 1);
 function ninja_forms_status_get_cap( $cap ) {
     $cap = 'nf_status';
     return $cap;
 }

// Ninja Forms -> Add-Ons 
 add_filter('ninja_forms_admin_extend_capabilities', 'ninja_forms_extend_get_cap', 10, 1);
 function ninja_forms_extend_get_cap( $cap ) {
     $cap = 'nf_addons';
     return $cap;
 }

If you need to change default capability for some add-on, you need to search add-on source code for the class which extends Ninja Forms abstract class NF_Abstracts_Submenu.
Command for Linux:
grep -rn 'NF_Abstracts_Submenu'
For example, for the “File uploads” add-on I found:
includes/admin/menus/uploads.php:5:final class NF_FU_Admin_Menus_Uploads extends NF_Abstracts_Submenu {
Then at the file with needed class look for the menu_slug property value:

final class NF_FU_Admin_Menus_Uploads extends NF_Abstracts_Submenu {

	public $parent_slug = 'ninja-forms';
	public $menu_slug = 'ninja-forms-uploads';

Finally filter for the add-on capability will be looked this way:

add_filter('ninja_forms_submenu_ninja-forms-uploads_capability', 'ninja_forms_uploads_cap', 10, 1);
function ninja_forms_uploads_cap( $cap ) {
  $cap = 'nf_uploads';
return $cap;
}

Pay attention that capability ‘nf_uploads’ you have to create and grant to the needed role(s) manually.

Code above was tested with WordPress 5.3.2 and Ninja Forms 3.4.24.1

Share