ms_has_membership

Template tag: Check if the current user has a specific membership.

Description

ms_has_membership( (int) $id = 0 ); 

Multiple memberships can be specified by adding more parameters to the function call.

Examples:

ms_has_membership() ) : ?> Current user has *any* membership?

Current user has membership 100?

Current user has membership 100 or 110?

Parameters (1)

0. $id — Optional. (int)
Membership-ID to check. If no value is specified the function will check if the member has any membership at all. Guest/Default memberships are ignored.

Usage

  1. if ( !function_exists( 'ms_has_membership' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'membership-2/app/controller/class-ms-controller-api.php'; 
  3. $id = -1; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ms_has_membership($id); 
  7.  

Defined (1)

The function is defined in the following location(s).

/app/controller/class-ms-controller-api.php  
  1. function ms_has_membership( $id = 0 ) { 
  2. $result = false; 
  3. $current_member = MS_Plugin::$api->get_current_member(); 
  4.  
  5. // Check all params and return true if the member has any membership. 
  6. foreach ( func_get_args() as $check_id ) { 
  7. if ( $current_member->has_membership( $check_id ) ) { 
  8. $result = true; 
  9. break; 
  10.  
  11. return $result;