Skip to main content

benecaster_block_subscriber_wpadmin

Filter Free

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.

Let a non-editor into wp-admin

Free Beginner

Exempt specific people from the subscriber wp-admin redirect, with benecaster_block_subscriber_wpadmin.

Signature: benecaster_block_subscriber_wpadmin( bool $should_block, int $user_id ): bool. Free, never licence-gated. Default true.

Why a recipe rather than a footnote: the condition is capability-based, not Benecaster-based. Benecaster redirects every logged-in user who fails current_user_can( 'edit_posts' ), so on a site where Benecaster sits beside a shop or a forum, those customers and members are redirected to the podcast account page too. That is the specified behaviour, and this filter is the only way out.

Return false to let somebody through. Branch on $user_id (or on roles, or on whether the person actually has a Benecaster token) 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. You do not need to re-check any of those in your callback.

benecaster_get_user_tier_for_show() returns the BASE tier only, and '' for somebody with no active token — which is the test the second example below wants. It is not a buy-up check; see benecaster_user_has_buyup() for that. On a multi-show install there is no equivalent one-call answer, which is why the example bails rather than guessing.

<?php
// Let shop customers keep their WooCommerce account pages in wp-admin,
// while podcast subscribers are still sent to the Benecaster account page.
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
);

// Or, on a single-show site: only redirect people who actually hold a tier
// on that show, and leave every other non-editor alone.
add_filter(
    'benecaster_block_subscriber_wpadmin',
    function ( bool $should_block, int $user_id ): bool {
        $show_id = benecaster_get_sole_show_id();

        if ( null === $show_id ) {
            return $should_block; // Multi-show install — no single answer.
        }

        // Returns '' when the user has no active token on that show.
        return $should_block
            && '' !== benecaster_get_user_tier_for_show( $show_id, $user_id );
    },
    10,
    2
);

View on GitHub →

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 →