Filter uncanny-automator

automator_admin_notifications_has_access

Filters whether the current user has access to view admin notifications, allowing customization of access control.

add_filter( 'automator_admin_notifications_has_access', $callback, 10, 1 );

Description

Allows developers to filter the access permission for viewing admin notifications. By default, access is granted if the current user has the automator capability. Use this hook to programmatically grant or deny access based on custom user roles or other conditions before notifications are displayed in the admin area.


Usage

add_filter( 'automator_admin_notifications_has_access', 'your_function_name', 10, 1 );

Parameters

$access (mixed)
This parameter determines whether the current user has access to administrative notifications.

Return Value

The filtered value.


Examples

// Allow specific user roles to access the notifications admin area,
// in addition to the default capability check.
add_filter( 'automator_admin_notifications_has_access', function( $access ) {

	// If access is already granted by the default capability check,
	// no need to do anything further.
	if ( $access ) {
		return $access;
	}

	// Check if the current user has the 'administrator' role.
	if ( current_user_can( 'administrator' ) ) {
		return true;
	}

	// You could also check for other specific roles if needed:
	// if ( current_user_can( 'editor' ) ) {
	// 	return true;
	// }

	// If none of the above conditions are met, deny access.
	return $access;

}, 10, 1 );

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/core/admin/notifications/notifications.php:105

public function has_access() {

		$access = false;

		if ( current_user_can( automator_get_capability() ) ) {
			$access = true;
		}

		return apply_filters( 'automator_admin_notifications_has_access', $access );
	}

Scroll to Top