The gform_web_api_capability_post_forms filter allows you to change the capability required to create forms via the web API.
Usage
add_filter('gform_web_api_capability_post_forms', 'my_custom_capability_function');
function my_custom_capability_function($capability) {
// Your custom code here
return $capability;
}
Parameters
- $capability (string): The capability required. Defaults to ‘gravityforms_create_form’.
More information
See Gravity Forms Docs: gform_web_api_capability_post_forms
Examples
Change the required capability to ‘edit_posts’
Change the required capability for creating forms via the web API to ‘edit_posts’.
add_filter('gform_web_api_capability_post_forms', 'change_capability_to_edit_posts');
function change_capability_to_edit_posts($capability) {
return 'edit_posts';
}
Restrict form creation to administrators
Restrict form creation via the web API to users with the ‘manage_options’ capability (usually administrators).
add_filter('gform_web_api_capability_post_forms', 'restrict_form_creation_to_administrators');
function restrict_form_creation_to_administrators($capability) {
return 'manage_options';
}
Allow editors to create forms
Allow users with the ‘edit_others_posts’ capability (usually editors) to create forms via the web API.
add_filter('gform_web_api_capability_post_forms', 'allow_editors_to_create_forms');
function allow_editors_to_create_forms($capability) {
return 'edit_others_posts';
}
Custom capability check
Create a custom capability check by using a custom function.
add_filter('gform_web_api_capability_post_forms', 'custom_capability_check');
function custom_capability_check($capability) {
// Custom capability check logic
$custom_capability = 'my_custom_capability';
return $custom_capability;
}
Disable form creation via the web API
Disable form creation via the web API by returning a non-existent capability.
add_filter('gform_web_api_capability_post_forms', 'disable_form_creation');
function disable_form_creation($capability) {
return 'non_existent_capability';
}