Using the API of WP Full Members

Documentation of the API that lets developers query membership levels and members, and set/get the visibility of protected content.

Introduction

WP Full Members has an API which provides functionality to expose the internal state of the plugin.

This article documents every function of the API.

How to use the API

Invoking API functions

API functions are exposed as static methods of the WPFM_API_v1 PHP class.

For example, you can query the plugin version by the following method call: 

WPFM_API_v1::getPluginVersion()

Versioning

The API version is added as a postfix of the API class name, hence the WPFM_API_v1 class name.

Future API versions will raise the version number, so the next one will be WPFM_API_v2.

Compatibility

A new API version extends the functionality of the previous API version, without breaking compatibility, unless noted otherwise.

Let’s say that the makePostPublic() function is added in v1. This function can be used without any modification also in v2, so any of the following method calls would work:

  • WPFM_API_v1::makePostPublic( 1044 );
  • WPFM_API_v2::makePostPublic( 1044 );

Error handling

The API functions might throw exceptions, and you should deal with them properly.

The documentation contains the exceptions that functions can throw.

API functionality

Table of contents for the API functions, click on a link to jump to the selected function:

getPluginVersion()

Returns the semantic version number of WP Full Members.

Parameters and return value:

Name Description
Return value Plugin version number in the v[MM].[mm].[pp] format (see below)

The v[MM].[mm].[pp] format, where:

  • MM is the major version
  • mm is the minor version
  • pp is the patch version

As an example, the return value can be: 

v1.10.0

getMembershipLevels()

Returns the configured membership levels that can be used to set the visibility of content.

Parameters and return value:

Name Description
Return value

An array of hashes, each hash is a membership level:

[ ‘id’ = ‘wpfs_all_access’, name => ‘All Access’, ‘priority’ => 9999 ]

makePostProtected()

Make the page or post protected, visible only at the specified membership level and beyond.

Parameters and return value:

Name Description
$postId Identifier of the page or post
$membershipLevelId Identifier of the membership level
   
Throws Exception if the post or membership level doesn’t exist

makePostPublic()

Make the page or post public, removing visibility protection.

Parameters and return value:

Name Description
$postId Identifier of the page or post
   
Throws Exception if the post doesn’t exist

getPostProtectionData()

Returns a hash indicating whether the post is protected, and if it is then at which membership level.

Parameters and return value:

Name Description
$postId Identifier of the page or post
   
Return value

A hash which contains protection data:

[ ‘isProtected’ = true, ‘membershipLevelId’ => ‘wpfs_gold’ ]

Throws Exception if the post doesn’t exist

getMemberData()

Returns a hash containing all information about a member.

Parameters and return value:

Name Description
$wpUserId Identifier of Wordpress user for which the member should be returned
$isLiveMode Boolean indicating whether the member should be returned in live or test Stripe API mode
   
Return value

A hash containig member data:

[ ‘wordpressUserId’ = 6436, ‘membershipLevelId’ => ‘wpfs_gold’, subscriptionStatus => ‘active’, ‘stripePlanId’ => ‘price_rvmt745hfbDv4t’, stripeSubscriptionId => ‘sub_5Yvb8FB4t5’, ‘stripeCustomerId’ => ‘cus_Vy54eHmd8456G’ ]

Throws Exception if the member doesn’t exist
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us