A Cozmoslabs Product

Useful Functions

This is a non-comprehensive list of functions from the plugin that might be useful.

Content Restriction

Check if user is member

These functions can be useful if you want to add restricted content directly in your PHP templates. It lets you check if a user is subscribed to one or more subscription plans.

pms_is_member( $user_id = '', $subscription_plans = array() );
  1. $user_id -> the user ID we want to check, defaults to currently logged in user if empty
  2. $subscription_plans -> array of subscription plan ids the user should be subscribed to
pms_is_member_of_plan( $subscription_plans, $user_id = '' );

This is similar to the function above, it just has the parameter in the reverse order.

Both functions will return true or false.

Example:

if( pms_is_member_of_plan( array( 123 ) ) ) {
    echo 'Content for plan 123';
}

Check if post is restricted for current user

pms_is_post_restricted( $post_id );

This function lets you check if a particular post is restricted for the current user or not. It will return true or false.

As an example, this function could be useful on an archive page if you want to display a custom icon for posts that the current user can’t access.

Member information

Retrieve information about a member

$member = pms_get_member( $user_id );

This function will return a PMS_Member object which contains information about the given user. The object has the following keys:

Get a list of members

$args = array(
    'order'                      => 'DESC',
    'orderby'                    => 'ID',
    'number'                     => 10,
    'offset'                     => '',
    'subscription_plan_id'       => '',
    'member_subscription_status' => '',
    'search'                     => '',
    'group_owner'                => '',
    'payment_gateway'            => '',
    'start_date_beginning'       => '',
    'start_date_end'             => '',
    'expiration_date_beginning'  => '',
    'expiration_date_end'        => '',
);

// array with member objects based on arguments
$members = pms_get_members( $args );

Using this function you can grab a list of member objects based on certain arguments.

The function also takes a second parameter $count that can be set to `true` to make the function return the number of users instead of the member objects:

$members = pms_get_members( $args, true );

Payments

Retrieve information about a payment

$payment = pms_get_payment( $payment_id );

This function will return a PMS_Payment object which contains information about a certain payment. The object has the following keys:

Get a list of payments

$args = array(
    'order'                => 'DESC',
    'orderby'              => 'id',
    'number'               => 10,
    'offset'               => '',
    'status'               => '',
    'type'                 => '',
    'user_id'              => '',
    'subscription_plan_id' => '',
    'profile_id'           => '',
    'transaction_id'       => '',
    'date'                 => '',
    'search'               => ''
);
 
$payments = pms_get_payments( $args );

Using this function you can grab a list of payments based on certain arguments.

Payments meta

Paid Member Subscriptions is using a meta system similar to WordPress Posts or Users for it’s custom payments. You can interact with it through the following functions:

pms_get_payment_meta( $payment_id = 0, $meta_key = '', $single = false );

For more info see: https://developer.wordpress.org/reference/functions/get_metadata/

pms_add_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $unique = false );

For more info see: https://developer.wordpress.org/reference/functions/add_metadata/

pms_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' );

For more info see: https://developer.wordpress.org/reference/functions/update_metadata/

pms_delete_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $delete_all = false );

For more info see: https://developer.wordpress.org/reference/functions/delete_metadata/

Subscriptions

Retrieve information about a subscription

$subscription = pms_get_member_subscription( $subscription_id );

This function will return a PMS_Member_Subscription object which contains information about a certain subscription. The object has the following keys:

Get a list of subscriptions

$args = array(
  'order'                       => 'DESC',
  'orderby'                     => 'id',
  'number'                      => 1000,
  'offset'                      => '',
  'status'                      => '',
  'user_id'                     => '',
  'subscription_plan_id'        => '',
  'start_date'                  => '',
  'start_date_after'            => '',
  'start_date_before'           => '',
  'expiration_date'             => '',
  'expiration_date_after'       => '',
  'expiration_date_before'      => '',
  'billing_next_payment'        => '',
  'billing_next_payment_after'  => '',
  'billing_next_payment_before' => '',
  'include_abandoned'           => false,
);

$subscriptions = pms_get_member_subscriptions( $args );

Using this function you can grab a list of subscriptions based on certain arguments.

Paid Member Subscriptions Pro

Accept (recurring) payments, create subscription plans and restrict content on your website. Easily setup a WordPress membership site using Paid Member Subscriptions.

Get Paid Member Subscriptions

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket