pmpro_getLevel

Pmpro_getLevel() returns the level object for a level.

Description

pmpro_getLevel( $level ); 

$level may be the level id or name

Return values: Success returns the level object. Failure returns false.

Parameters (1)

0. $level
The level.

Usage

  1. if ( !function_exists( 'pmpro_getLevel' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The level. 
  5. $level = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_getLevel($level); 
  9.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_getLevel($level) 
  2. global $pmpro_levels; 
  3.  
  4. if(is_object($level) && !empty($level->id)) 
  5. $level = $level->id; 
  6.  
  7. //was a name passed? (Todo: make sure level names have at least one non-numeric character. 
  8. if(is_numeric($level)) 
  9. $level_id = intval($level); 
  10. if(isset($pmpro_levels[$level_id])) 
  11. return $pmpro_levels[$level_id]; 
  12. else 
  13. global $wpdb; 
  14. $pmpro_levels[$level_id] = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_levels WHERE id = '" . $level_id . "' LIMIT 1"); 
  15. return $pmpro_levels[$level_id]; 
  16. else 
  17. global $wpdb; 
  18. $level_obj = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_levels WHERE name = '" . esc_sql($level) . "' LIMIT 1"); 
  19.  
  20. if(!empty($level_obj)) 
  21. $level_id = $level_obj->id; 
  22. else 
  23. return false; 
  24.  
  25. $pmpro_levels[$level_id] = $level_obj; 
  26. return $pmpro_levels[$level_id];