benecaster_block_subscriber_wpadmin
Filters whether a logged-in WordPress user who lacks the edit_posts capability is redirected out of wp-admin to the Benecaster subscriber account page. Default true.
This is the ONLY way to opt out. The condition is ! current_user_can( 'edit_posts' ) by specification, so every non-editor on the install is in scope whether or not they have anything to do with Benecaster — a WooCommerce customer or bbPress participant is redirected too on a site where Benecaster is one plugin among many. Branch on $user_id (or on roles, or on whether the person actually holds a Benecaster token) inside the callback to exempt a group without switching the redirect off site-wide.
The redirect already exempts logged-out requests, wp_doing_ajax(), wp_doing_cron() and admin-post.php — a callback does not need to re-check any of those.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$should_block |
bool |
— | Whether to redirect this user out of wp-admin; default true |
$user_id |
int |
— | WordPress user ID of the user about to be redirected |
Returns:
bool
Examples
Exempt a specific role
add_filter( 'benecaster_block_subscriber_wpadmin', function ( bool $should_block, int $user_id ): bool {
$user = get_userdata( $user_id );
if ( $user && in_array( 'customer', (array) $user->roles, true ) ) {
return false;
}
return $should_block;
}, 10, 2 );
Notes
Applied in Admin\SubscriberAdminRedirect, on every wp-admin request site-wide. Exemptions already applied before this filter runs, and which a callback need not re-check: logged out, wp_doing_ajax(), wp_doing_cron(), admin-post.php.
Affects
- Subscriber Account Page
- wp-admin access for non-editor users
Need this built rather than just documented? See our services →