The PMPro_Membership_Level class holds information about a particular PMPro membership level and can be used to create, update, delete, or get information about membership levels.

Example of the PMPro_Membership_Level Class

To instantiate this class, use:

$membership_level = new PMPro_Membership_Level();

Constructor Parameters

string $id = null

The membership level that should be  used to populate this object. If null, a blank PMPro_Membership_Level object is created.

For example, this code would create a PMPro_Membership_Level object for level ID 1:

$membership_level = new PMPro_Membership_Level( '1' );

Properties

string id

Unique identifier for this membership level.

string name

Name of the membership level.

string description

Description of the membership level that is shown on the checkout page.

string confirmation

Confirmation that is displayed after a user checks out for this membership level.

string initial_payment

The amount that a user is charged at checkout.

string billing_amount

The amount that a user is charged during recurring payments.

string cycle_number

The number of billing cycles between recurring payments.

string cycle_period

The length of a billing cycle. Possible values are “Day”, “Week”, “Month”, and “Year”.

string billing_limit

The maximum number of recurring payments will be charged (“0” for unlimited).

string trial_amount

The amount that a user is charged for recurring payments during a trial period.

string trial_limit

The number of recurring payments that should be considered a trial.

string allow_signups

Set to “1” if users can sign up for this level, “0” otherwise.

string expiration_number

The number of expiration periods until a membership expires.

string expiration_period

The length of an expiration period. Possible values are “Day”, “Week”, “Month”, and “Year”.

array categories

Post categories which are restricted to this membership level.

Public Methods

__get( string $key )

Returns the corresponding property from this PMPro_Membership_Level object or queries the pmpro_membership_levelmeta table for the given meta_key.

Parameters

  • string $key – The name of the property or meta_key to search for.

Return

Mixed type, or NULL if no match found for $key.

Examples

Gets the level meta value for membership ID 1 and meta key “meta_key_1”:

$membership_level = new PMPro_Membership_Level( '1' );
$membership_level_name = $membership_level->meta_key_1;

get_empty_membership_level()

Clears all properties for the current PMPro_Membership_Level object.

Return

PMPro_Membership_Level object which was cleared.

Example

Removes the data for level ID 1 from the PMPro_Membership_Level object:

$membership_level = new PMPro_Membership_Level( '1' );
$membership_level = $membership_level->get_empty_membership_level();

get_membership_level( string $id )

Populates all properties for the current PMPro_Membership_Level object.

Parameters

  • string $id – The membership level that should be used to populate this object

Return

PMPro_Membership_Level object which was populated, or false if invalid $id passed.

Example

Loads the data for level ID 1 to the PMPro_Membership_Level object:

$membership_level = new PMPro_Membership_Level();
$membership_level = $membership_level->get_membership_level( '1' );

get_membership_level_categories( $id )

Gets posts categories that should be restricted to the passed membership level ID by querying the pmpro_memberships_categories table

Parameters

  • string $id – The membership level to get categories for

Return

array of category strings to restrict

Example

Gets the post categories restricted by level ID 1:

$membership_level = new PMPro_Membership_Level();
$categories = $membership_level->get_membership_level_categories( '1' );

get_membership_level_object( $id )

Gets an object containing data for all rows of the pmpro_membership_levels table for the passed membership level ID

Parameters

  • string $id – The membership level get object for

Return

Object with properties mirroring pmpro_membership_levels table

Example

Gets the data from the pmpro_membership_levels table for level ID 1:

$membership_level = new PMPro_Membership_Level();
$categories = $membership_level->get_membership_level_object( '1' );

save()

Add the membership level to the pmpro_membership_levels table, or update the row if an entry with the same membership id already exists. Also updates the pmpro_memberships_categories table with the restricted categories for the current membership id.

Example

Updates the name for level ID 1 to “Gold”:

$membership_level = new PMPro_Membership_Level( '1' );
$membership_level->name = "Gold";
$membership_level->save();

delete()

Removes all entries with the current membership ID from the pmpro_membership_levels table, cancels all active memberships for this level, and clears all restricted categories for this level from the pmpro_memberships_categories table.

Example

Deletes level ID 1:

$membership_level = new PMPro_Membership_Level( '1' );
$membership_level->delete();

Action and Filter Hooks

Was this article helpful?
YesNo