pmpro_listCategories

Function to list WordPress categories in hierarchical format.

Description

pmpro_listCategories( (int) $parent_id = 0, (array) $level_categories = array() ); 

This is a helper function for the Membership Categories section in adminpages/membershiplevels.php

Parameters (2)

0. $parent_id — Optional. (int)
The parent id.
1. $level_categories — Optional. (array) => array()
The level categories.

Usage

  1. if ( !function_exists( 'pmpro_listCategories' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The parent id. 
  5. $parent_id = -1; 
  6.  
  7. // The level categories. 
  8. $level_categories = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_listCategories($parent_id, $level_categories); 
  12.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_listCategories($parent_id = 0, $level_categories = array()) { 
  2.  
  3. $args = array( 
  4. 'parent' => $parent_id,  
  5. 'hide_empty' => false,  
  6. ); 
  7.  
  8. $cats = get_categories(apply_filters('pmpro_list_categories_args', $args)); 
  9.  
  10. if($cats) { 
  11. foreach($cats as $cat) { 
  12. $name = 'membershipcategory_' . $cat->term_id; 
  13. if(!empty($level_categories)) 
  14. $checked = checked(in_array($cat->term_id, $level_categories), true, false); 
  15. else 
  16. $checked = ""; 
  17. echo "<ul><li class=membershipcategory><input type=checkbox name={$name} id={$name} value=yes {$checked}><label for={$name}>{$cat->name}</label>"; 
  18. pmpro_listCategories($cat->term_id, $level_categories); 
  19. echo '</li></ul>';