-
-
Save New0/06d5b7664a8cfbb256a13bc68de0aa98 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Filter hook used in the API route permission callback to retrieve submissions | |
* | |
* return bool as for authorized or not. | |
*/ | |
add_filter( 'ninja_forms_api_allow_get_submissions', 'nf_define_permission_level', 10, 2 ); | |
add_filter( 'ninja_forms_api_allow_delete_submissions', 'nf_define_permission_level', 10, 2 ); | |
add_filter( 'ninja_forms_api_allow_update_submission', 'nf_define_permission_level', 10, 2 ); | |
add_filter( 'ninja_forms_api_allow_handle_extra_submission', 'nf_define_permission_level', 10, 2 ); | |
add_filter( 'ninja_forms_api_allow_email_action', 'nf_define_permission_level', 10, 2 ); | |
function nf_define_permission_level() { | |
$allowed = \current_user_can("delete_others_posts"); | |
return $allowed; | |
} |
Thank you @ouija , originally this function was written inside a filter hook and I forgot to remove the closing tags.
Thanks also for sharing your example of use, we're returning a boolean so the conditions that lead to it can be designed as needed. That will certainly help others to determine what they need.
Thank you @ouija , originally this function was written inside a filter hook and I forgot to remove the closing tags.
No problem! I was actually going to create my own gist but came across yours and figured I'd add to it instead, and have also shared this with some threads in the Wordpress Support Forums.
@New0 May I know how to implement your code? Is it just put your code into a specific folder or add the code into a specific php file? Many thanks for your help.
Hello @Banilancer you can use this code in the functions.php file of your (child-) theme or in a custom plugin if you add the plugin header information at the top of this file and upload it in the plugins folder of your WP installation.
Thanks New0 and ouija for this help - this update has really caused some issues for my clients situation - following on from Banilancer, can/do I add the...
// Must use all three filters for this to work properly.
add_filter( 'ninja_forms_admin_parent_menu_capabilities', 'nf_subs_capabilities' ); // Parent Menu
add_filter( 'ninja_forms_admin_all_forms_capabilities', 'nf_subs_capabilities' ); // Forms Submenu
add_filter( 'ninja_forms_admin_submissions_capabilities', 'nf_subs_capabilities' ); // Submissions Submenu
function nf_subs_capabilities( $cap ) {
return 'edit_posts'; // EDIT: User Capability
}
...to the functions.php file too. I'm not having much luck as yet. Also are the User_capability and current_user_can related?
Awesome, thanks. Note that you have an unnecessary closing bracket at the end of your function.
I ran into issues with this after the plugin got updated last week, specifically with users assigned to the shop_manager role, and (after looking at the source code for the related /wp-content/plugins/ninja-forms/includes/Routes/Submissions.php page, which defines access for the ninjaforms submissions api endpoint now being utilized in the submissions admin page), I realized that this latest update is now checking if the user role has the manage_options permission (which the modified shop_manager role in my client's configuration does not) and instead I've opted to instead modify this code to check against the role itself, rather than a certain permission.
For example:
Alternativly, you could also install the User Role Editor plugin and modify whatever role you need to have this manage_options permission:
Hope this helps anyone else looking to achive somethig similar.