This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Ever wondered how to enable the ‘Additional Capabilities’ section in WordPress? Well, let me walk you through it. This section is only enabled if the number of the user’s capabilities exceeds their number of roles. To use the `additional_capabilities_display` filter, you first need to register it using `add_filter`. You can integrate this code into the `functions.php` file of your activated theme or even better, in a custom WordPress Plugin.
Here at WePlugins, we always prefer creating a custom WordPress Plugin when using hooks to ensure nothing breaks when you update your WordPress Theme in the future.
In the following live examples, we have defined a function `weplugins_modify_additional_capabilities_display_defaults` which takes 2 parameters and is registered using `add_filter`. The first parameter `additional_capabilities_display` is the name of the hook, the second parameter `weplugins_modify_additional_capabilities_display_defaults` is the name of the function to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed to the registered function.
Sometimes, you may need to remove a registered hook, and for that, you can use `remove_filter` to remove the `additional_capabilities_display` filter.
Parameters
- $enable: (bool) Whether to display the capabilities. Default true.
- $profile_user: (WP_User) The current WP_User object.
Below are the 2 parameters required to use this hook:
Live Example 1: Basic Usage
Below is an example of how you can use this hook:
function weplugins_modify_additional_capabilities_display_defaults($enable, $profile_user) { // Update the $enable variable according to your website requirements and return this variable. You can modify the $enable variable conditionally too if you want. return $enable; } // add the filter add_filter( "additional_capabilities_display", "weplugins_modify_additional_capabilities_display_defaults", 10, 2 );
Live Example 2: Conditional Display
Here’s an example where we conditionally control the display of additional capabilities:
function weplugins_modify_additional_capabilities_display_conditional($enable, $profile_user) { if ($profile_user->has_cap('administrator')) { $enable = true; } else { $enable = false; } return $enable; } // add the filter add_filter( "additional_capabilities_display", "weplugins_modify_additional_capabilities_display_conditional", 10, 2 );
Live Example 3: Removing the Hook
To remove a hook callback, use the example below:
remove_filter( "additional_capabilities_display", "weplugins_modify_additional_capabilities_display_defaults", 10, 2 );
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
If you’re having any trouble using this hook or need customization, feel free to Contact Us. We’d be happy to assist you.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.