$subscriptions
$subscriptions : array
Member's active subscriptions.
Note: This field is populated by MS_Factory when the Member instance is created.
Member model.
Defines several details about a WordPress user. The Member object allows us to quickly check if the user did subscribe to a certain membership, and other useful stuff.
Note that all properties are declared protected but they can be access
directly (e.g. $membership->type
to get the type value).
There are magic methods __get() and __set() that do some validation before
accessing the properties.
$is_member : boolean
Indicator if the user is an active M2 Member.
This is a convenience/redudant flag to speed up SQL queries. Actually everyone that has an active or trial status membership is considered an active member.
This flag is set when:
This flag is reset when:
save() : \MS_Model_Member
Save member.
Create a new user is id is empty. Save member fields to wp_user and wp_usermeta tables. Set cache for further use in MSFactory::load. The usermeta are prefixed with 'ms'.
The saved member object.
set_custom_data(string $key, mixed $value)
Either creates or updates the value of a custom data field.
Note: Remember to prefix the $key with a unique string to prevent conflicts with other plugins that also use this function.
string | $key | The field-key. |
mixed | $value | The new value to assign to the field. |
add_membership(integer $membership_id, string $gateway_id = 'admin', integer|string $move_from_id) : object|null
Add a new membership.
If multiple membership is disabled, may move existing membership.
Only add a membership if a user is not already a member.
integer | $membership_id | The membership id to add to. |
string | $gateway_id | Optional. The gateway used to add the membership. |
integer|string | $move_from_id | Optional. The membership id(s) to cancel. |
$subscription
has_membership(integer $membership_id) : boolean
Check membership relationship status.
Canceled status is allowed until it expires.
integer | $membership_id | Optional. The specific membership to verify. If empty, verify against all memberships. |
True if has a valid membership.
get_subscription(integer|string $membership_id, $key = -1) : \MS_Model_Relationship
Return the subscription object for the specified membership.
integer|string | $membership_id | The specific membership to return. Value 'priority' will return the subcription with lowest priority. |
$key |
The subscription object.
cancel_ids_on_subscription(integer $membership_id) : array
Returns an array of existing subscriptions that should be cancelled when the user signs up to the specified membership.
integer | $membership_id | A membership ID. |
Might be an empty array or a list of membership IDs.