pmpro_getAllLevels

Function to populate pmpro_levels with all levels.

Description

pmpro_getAllLevels( (constant) $include_hidden = false, (constant) $force = false ); 

We query the DB every time just to be sure we have the latest. This should be called if you want to be sure you get all levels as $pmpro_levels may only have a subset of levels.

Parameters (2)

0. $include_hidden — Optional. (constant) => false
The include hidden.
1. $force — Optional. (constant) => false
The force.

Usage

  1. if ( !function_exists( 'pmpro_getAllLevels' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The include hidden. 
  5. $include_hidden = false; 
  6.  
  7. // The force. 
  8. $force = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_getAllLevels($include_hidden, $force); 
  12.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_getAllLevels($include_hidden = false, $force = false) 
  2. global $pmpro_levels, $wpdb; 
  3.  
  4. //just use what's cached (doesn't take intoaccountinclude_hidden setting) 
  5. if(!empty($pmpro_levels) && !$force) 
  6. return $pmpro_levels; 
  7.  
  8. //build query 
  9. $sqlQuery = "SELECT * FROM $wpdb->pmpro_membership_levels "; 
  10. if(!$include_hidden) 
  11. $sqlQuery .= " WHERE allow_signups = 1ORDERBY id"; 
  12.  
  13. //get levels from the DB 
  14. $raw_levels = $wpdb->get_results($sqlQuery); 
  15.  
  16. //lets put them into an array where the key is the id of the level 
  17. $pmpro_levels = array(); 
  18. foreach($raw_levels as $raw_level) 
  19. $pmpro_levels[$raw_level->id] = $raw_level; 
  20.  
  21. return $pmpro_levels;