Home » Docs » Actions and Filters

Actions and Filters

Members Only provides a number of actions and filters so you can run custom code during certain events and/or customize how the system behaves.

Action Hooks

members_only_event_stripe_charge

Fired inside includes/stripe/stripe-rest-api-endpoints.php whenever a Stripe charge or dispute event is processed for a user. The hook passes the full Stripe Charge object, the WordPress user ID that owns the Stripe customer, and the exact Stripe event type (charge.succeeded, charge.dispute.created, etc.).

Example:

add_action( 'members_only_event_stripe_charge', function( \Stripe\Charge $charge, int $user_id, string $event_type ) {
    error_log( sprintf( 'User %d saw charge event %s for %s', $user_id, $event_type, $charge['id'] ) );
}, 10, 3 );

members_only_event_stripe_checkout_session

Fired when a Stripe Checkout session completes for a Members Only user. Receives the Stripe Session object, the owning user ID, and the Stripe event type. Useful for tagging analytics or kicking off downstream fulfilment once the checkout succeeds.

Example:

add_action( 'members_only_event_stripe_checkout_session', function( \Stripe\Checkout\Session $session, int $user_id, string $event_type ) {
    // Create a custom log entry or post-purchase action for the session.
}, 10, 3 );

members_only_event_stripe_customer

Triggered for Stripe customer lifecycle events (customer.created, customer.deleted, etc.). Arguments are the Stripe Customer object, the linked WordPress user ID, and the event type. Use it to reconcile customer metadata or notify your team when a customer record is deleted from Stripe.

Example:

add_action( 'members_only_event_stripe_customer', function( \Stripe\Customer $customer, int $user_id, string $event_type ) {
    if ( 'customer.deleted' === $event_type ) {
        // Clean up third-party records tied to this customer once Stripe deletes it.
    }
}, 10, 3 );

members_only_event_stripe_subscription

Fired for every subscription-related Stripe webhook (customer.subscription.created, ...deleted, ...updated, etc.). Subscribers receive the Stripe Subscription object, user ID, and event type. Use it to synchronize membership state with other systems.

Example:

add_action( 'members_only_event_stripe_subscription', function( \Stripe\Subscription $subscription, int $user_id, string $event_type ) {
    // Store the latest subscription status on the user meta.
    update_user_meta( $user_id, 'my_plugin_subscription_status', $subscription['status'] );
}, 10, 3 );

members_only_event_stripe_invoice

Triggered when Stripe invoices are created/paid/failed/voided. Arguments: Stripe Invoice object, user ID, event type. Ideal for updating billing dashboards or firing alert emails when a payment fails.

Example:

add_action( 'members_only_event_stripe_invoice', function( \Stripe\Invoice $invoice, int $user_id, string $event_type ) {
    if ( 'invoice.payment_failed' === $event_type ) {
        // Notify support that this customer needs attention.
    }
}, 10, 3 );

members_only_event_stripe_refund

Fired on refund lifecycle events. Receives the Stripe Refund, owning user ID, and event type. Use it to revoke additional entitlements or log refund reasoning.

Example:

add_action( 'members_only_event_stripe_refund', function( \Stripe\Refund $refund, int $user_id, string $event_type ) {
    // e.g. revoke a coupon or log the refund in your CRM.
}, 10, 3 );

members_only_event_stripe_review

Triggered when Stripe opens or closes a review on a charge. Arguments mirror the other hooks: Stripe Review, user ID, and event type. Useful for pausing access until a disputed charge is resolved.

Example:

add_action( 'members_only_event_stripe_review', function( \Stripe\Review $review, int $user_id, string $event_type ) {
    if ( 'review.opened' === $event_type ) {
        // Temporarily flag the membership until the review completes.
    }
}, 10, 3 );

members_only_stripe_subscription_cancelled

Fired after cancel_subscription() successfully cancels a Stripe subscription. Provides the Subscription object and the WordPress user ID. Great for clearing per-user caches or sending a custom cancellation survey.

Example:

add_action( 'members_only_stripe_subscription_cancelled', function( \Stripe\Subscription $subscription, int $user_id ) {
    delete_user_meta( $user_id, 'my_plugin_subscription_tokens' );
}, 10, 2 );

Filters

members_only_should_send_email

Runs before send_mail() actually calls wp_mail(), letting you short-circuit email delivery (e.g., to route through an external provider in dev environments). Receives the default boolean decision plus the recipient, subject, and message.

Example:

add_filter( 'members_only_should_send_email', function( bool $should_send, array|string $to, string $subject, string $message ) {
    // Never send emails during local development.
    if ( wp_get_environment_type() === 'local' ) {
        return false;
    }
    return $should_send;
}, 10, 4 );

members_only_prevent_wpadmin_access

Filters the boolean that decides whether non-editing users should be sent away from /wp-admin. Gets the calculated value and current user ID, so you can override things for specific roles or contextual flags.

Example:

add_filter( 'members_only_prevent_wpadmin_access', function( bool $prevent, int $user_id ) {
    return user_can( get_user_by( 'id', $user_id ), 'manage_options' ) ? false : $prevent;
}, 10, 2 );

members_only_hide_admin_bar

Controls whether the admin bar is hidden for subscribers. Receives the plugin’s decision and the user ID. Use it to keep the bar visible for specific users even if the plugin would otherwise hide it.

Example:

add_filter( 'members_only_hide_admin_bar', function( bool $hide, int $user_id ) {
    return ( $user_id === 7 ? false : $hide ); // Always show admin bar for user 7.
}, 10, 2 );