Suma’s API

Suma extends the basic authorization and access control of Wordpress with the concept of Subscriptions and Subscribers. Through Suma’s Public API (see below) your code running in other plugins or themes can interface with Suma in order to determine if a user is a subscriber and whether they have access to a particular post or page.

You could use this API, for example, to build a Wordpress site that only allows certain plugins to be accessible by subscribers; or you could use it to make certain functions of the website only available to subscribers that have a particular membership level (via content classes).

Suma’s Public API is documented below. (Note that it is using the Object Oriented syntax of PHP5.)

	/**
	* Determine if a user is a current subscriber in good standing.
	*
	* This is a necessary pre-requisite of any subscriber if
	* they are to be allowed to view restricted content.
	*
	* A subscriber is a current subscriber in good standing iff:
	* they have at least one Subscription Profile which is
	* Active or Cancelled but the nextPaymentDate is in the future
	* (meaning they have unused credit on their plan) and the
	* OutstandngAmount is zero (meaning they weren't
	* behind in their payments).
	*
	* @param  optional Wordpress UserID of a user.
	* 	If this argument is not provided, then the current
	* 	user is assumed.
	* @return true if the user is a current subscriber in
	* 	good standing, false otherwise.
	*/
	function
	SumaSubscriptionProfiles::isGoodStandingSubscriber( $userID = null )

	/**
	* Determine if the current user has access to at
	* least one of the specified Suma Content Classes.
	*
	* The current user must be logged in and have a subscription
	* in good standing - see previous function - and be subscribed
	* to a plan which has been associated with at least one of
	* the supplied Content Classes.
	*
	* @param array $contentClasses  an array of Suma Content
	* Class identifiers.
	* @return true if user is logged in, is in good standing with
	* their subscription and whose plan has been associated with
	* at least one of the supplied Content Classes, false otherwise.
	*/
	function
	SumaContentClasses::hasAccessToClasses( $contentClasses )



To call these methods your code would look something like this:

	if (SumaSubscriptionProfiles::isGoodStandingSubscriber()) {
		// treat current user as a current subscriber
	} else {
		// don't treat current user as a subscriber
	}


or

	// assuming ContentClasses 1,3 and 6 are defined
	// and associated with a subscription plan
	$aContentClassList = array(1,3,6);

	if (SumaContentClasses::hasAccessToClasses($aContentClassList)) {
		// this user is a subscriber with access to at least
		// one of the content classes from the $aContentClassList.
	} else {
		// user doesn't have access to these content classes
	}