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.
As an Indian developer who loves working with WordPress, I know how crucial hooks can be in customizing and extending the functionality of your site. One such hook is the restrict_manage_sites action. This hook is fired before the Filter button on the MS sites list table, and it’s pretty handy when you want to add custom functionality.
How to Use restrict_manage_sites Action
To use the restrict_manage_sites action, you first need to register it using add_action. You can place this code in the functions.php
file of your activated theme or in a custom WordPress Plugin. Creating a custom plugin is often preferred to prevent any issues when updating your WordPress Theme in the future.
Live Example 1: Adding Custom Filter
Here’s a simple example of how you can use this hook to add a custom filter option to the site list table.
function weplugins_add_custom_filter($which){ if ( 'top' === $which ) { // Output custom filter HTML echo '<select name="weplugins_custom_filter"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> </select>'; } } add_action( 'restrict_manage_sites', 'weplugins_add_custom_filter', 10, 1 );
Live Example 2: Customizing Site List Table
In this example, we add a custom message to the site list table using the hook.
function weplugins_customize_sites_table($which){ if ( 'bottom' === $which ) { // Display custom message echo 'Custom message displayed at the bottom of the table.'; } } add_action( 'restrict_manage_sites', 'weplugins_customize_sites_table', 10, 1 );
Live Example 3: Removing Custom Functionality
If you need to remove a registered hook, you can use remove_action like in the example below.
remove_action( 'restrict_manage_sites', 'weplugins_add_custom_filter', 10, 1 );
Ensure you provide the same callback function name, priority, and number of arguments when removing the hook callback.
If you’re having any trouble using this hook or need customization, please Contact Us, and 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.