general_settings_update_permission
Filters whether the user has permission to update general settings, returning the required capability check.
add_filter( 'general_settings_update_permission', $callback, 10, 1 );
Description
Filters the capability required to update general settings via the REST API. Developers can return a different capability string to modify or restrict who can perform these updates. Defaults to 'manage_options'.
Usage
add_filter( 'general_settings_update_permission', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'general_settings_update_permission', 'my_custom_group_settings_permission', 10, 1 );
/**
* Custom permission check for group settings updates.
*
* This filter allows developers to override the default 'manage_options'
* capability required to save general group settings. For example,
* we might want to allow a custom role to save these settings instead.
*
* @param string $capability The current capability required. Defaults to 'manage_options'.
* @return string The updated capability required.
*/
function my_custom_group_settings_permission( $capability ) {
// Example: Allow users with the 'edit_groups' capability to save settings.
// This is a fictional capability for demonstration purposes.
// In a real-world scenario, you'd likely check for a specific custom role or capability.
if ( current_user_can( 'edit_groups' ) ) {
return 'edit_groups';
}
// If the custom capability isn't met, fall back to the default.
return $capability;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/admin/class-admin-rest-api.php:118
src/classes/admin/class-admin-rest-api.php:502
// Was an action received, and is the actions allowed
if ( ! $request->has_param( 'action' ) || ! in_array( $request->get_param( 'action' ), $permitted_actions ) ) {
$data['message'] = __( 'Select an action.', 'uncanny-learndash-groups' );
wp_send_json_error( $data );
}
// Does the current user have permission
$permission = apply_filters( 'general_settings_update_permission', 'manage_options' );
if ( ! current_user_can( $permission ) ) {
$data['message'] = __( 'You do not have permission to save settings.', 'uncanny-learndash-groups' );
wp_send_json_error( $data );
}
if ( $request->has_param( 'ulgm_term_condition' ) ) {