Smart Members has a small PHP API and a set of actions and filters. Your plugin or theme uses them to give and take away access, check what a user may see, and react when a membership changes.
All of it ships in the free plugin. Run your code from a small custom plugin, a must-use plugin or a child theme's functions.php.
How access is stored
Each access decision is a grant: user X holds access group Y, from this date until that date, because of this source.
| Concept | In code |
|---|---|
| Access group | An integer ID or a name. AI Weekly — Reader is 672. |
| Grant | SmartMembers\Access\Grant, a read-only value object. |
| Source | The source / source_object / source_id triple, such as woocommerce / order / 1234. |
| Access check | AccessResult: allowed, reason, required groups, mode, message. |
WooCommerce, registration and the Members screen call the same grant service your code does.
Access API
smartmembers_grant(), smartmembers_revoke() and smartmembers_get_grants() are the public contract, with read helpers such as smartmembers_check_access() and smartmembers_user_holds_group(). See Access API: grant, revoke and read.
Hooks
All hooks are prefixed smartmembers_. The key pair is smartmembers_access_granted and smartmembers_access_revoked; emails, role sync and every Pro integration listen to them. See Hooks reference.
Feature checks
smartmembers_capability_available( 'drip' ) says whether a feature is available on this site. An unregistered slug returns false, so a typo closes the gate.
Rules to follow
- Never write to the grants table directly.
smartmembers_grant()handles duplicates, group rules, role sync, caches and the lifecycle action. - Revoke with the source you granted with, or you may remove access someone else paid for.
- Admins bypass restriction. Test as a member or a logged-out visitor.
- Blocked members read as empty. Use
smartmembers_user_is_blocked()to tell the difference. - Load after Smart Members: on
plugins_loadedor later, or onsmartmembers_loaded/smartmembers_init.
A first example
Give Rosa the Reader group for 30 days, and log every grant:
add_action( 'init', function () {
$grant = smartmembers_grant( 42, 672, array( // Rosa Iqbal, AI Weekly — Reader
'source' => 'my-plugin',
'source_id' => 'promo-2026',
'expires_at' => gmdate( 'Y-m-d H:i:s', strtotime( '+30 days' ) ),
) );
if ( is_wp_error( $grant ) ) {
error_log( $grant->get_error_message() );
}
} );
add_action( 'smartmembers_access_granted', function ( $grant, $user_id, $group_id, $context ) {
error_log( "User {$user_id} joined group {$group_id} via {$context['source']}" );
}, 10, 4 );
Repeating the grant with the same source returns the existing grant.
Other ways in
With Pro, wp smartmembers import <file> imports members from a CSV; see Import members from CSV. To reach Smart Members from another system, run code inside WordPress or use the Zapier or Pabbly integration.