Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Varun Singh

Disable Smart Filter

Hi,

How can I disable the smart filter for certain roles? I don’t want certain users to see Add Filter button.

thanks
Varun

3 years, 12 months ago
Stefan van den Dungen Gronovius
Developer

Hello,

The only way to do that, is by using a hook.
The following snippets explain how to disable it for administrators globally or for a specific overview.

// Simply disable search for all overview pages for a specific role
add_filter( 'acp/search/is_active', function ( $is_active ) {
	$user = wp_get_current_user();

	if ( in_array( 'administrator', (array) $user->roles ) ) {
		$is_active = false;
	}

	return $is_active;
}, 10, 1 );

// More control per overview
add_filter( 'acp/search/is_active', function ( $is_active, AC\ListScreen $list_screen ) {
	$user = wp_get_current_user();

	if ( in_array( 'administrator', (array) $user->roles ) && $list_screen instanceof AC\ListScreen\Post && 'page' === $list_screen->get_post_type() ) {
		$is_active = false;
	}

	return $is_active;
}, 10, 2 );
3 years, 12 months ago

You must be logged in to reply to this topic.