Check member permissions
We’ve included three functions for checking if the current signed-in user is subscribed to plans, owns downloads, or has access to podcast feeds. Use them in your WordPress theme’s template files:is_subscribed_to_memberful_plan( $slug )
has_memberful_download( $slug )
has_memberful_feed( $id )
is_subscribed_to_any_memberful_plan($user_id)
.
Basic example
Require a subscription to the Big Awesome plan:Multiple plans
Require a subscription to at least one of the listed plans:Any plan
Require a subscription to any plan. This function accepts any valid user ID, but you’ll typically want to use the current signed-in user, so we’ll get their user ID first.Plan or download
Require a subscription to the Big Awesome plan or require the Super Rad download.Check against a different member / WordPress user
These functions check against the current (signed in) member / WordPress user by default. To specify a different member / WordPress user, pass the function an optional WordPress user ID argument:Check if a user has access to a post based on the Restrict Access tool
Configure access to your posts with the Restrict Access metabox and usememberful_can_user_access_post()
to check if a user has access to a post or not:
You only need to do this if you want to show users some custom content (e.g. content from custom fields).If you just need to protect content in the default WordPress content area (the_content() in your theme), the Restrict Access tool will be sufficient and you won’t need to use this function.
Check which plans a user is subscribed to
The memberful_wp_user_plans_subscribed_to function returns the member’s subscriptions as an array.- id (this refers to the plan’s ID)
- autorenew
- activated_at
- expires_at
- in_trial_period
- trial_start_at
- trial_end_at
Add a custom function that checks if a member is on a trial
We can leverage thememberful_wp_user_plans_subscribed_to
function to create a custom function that checks if a member is currently on a trial for any of their subscriptions.
Add the following custom function to your functions.php
file:
is_on_trial()
will return true
if the member is on a trial (for any subscription).
Show profile information in WordPress themes
We’ve included a few functions for adding profile information to your theme template files:memberful_account_url
memberful_sign_in_url
memberful_sign_out_url
Link to downloads
You can use thememberful_account_get_download_url($slug)
function to link to a download.
The parameter to this function must be the slug of the download you’re linking to. The slug for a download is shown at the bottom of the page when editing that download.
Link to podcasts
If you’re using the private podcasts feature inside of Memberful, you can use thememberful_wp_feed_url($id)
function to link to a member’s unique RSS feed.
The parameter to this function must be the ID of the podcast you’re linking to. If the member doesn’t have access to the given podcast, it returns null
, so we should check for that before rendering the link.