Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use additional_capabilities_display filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
September 23, 2022
5 minutes read

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

    Below are the 2 parameters required to use this hook:

  • $enable: (bool) Whether to display the capabilities. Default true.
  • $profile_user: (WP_User) The current WP_User object.

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.

Access Premium WordPress Plugins

If you’re having any trouble using this hook or need customization, feel free to Contact Us. We’d be happy to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.