pmpro_toggleMembershipCategory

Pmpro_toggleMembershipCategory() creates or deletes a linking entry between the membership level and post category tables.

Description

pmpro_toggleMembershipCategory( $level, $category, $value ); 

$level may either be the ID or name of the desired membership_level. $category must be a valid post category ID.

Return values: Success returns boolean true. Failure returns a string containing the error message.

Parameters (3)

0. $level
The level.
1. $category
The category.
2. $value
The value.

Usage

  1. if ( !function_exists( 'pmpro_toggleMembershipCategory' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The level. 
  5. $level = null; 
  6.  
  7. // The category. 
  8. $category = null; 
  9.  
  10. // The value. 
  11. $value = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_toggleMembershipCategory($level, $category, $value); 
  15.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_toggleMembershipCategory( $level, $category, $value ) 
  2. global $wpdb; 
  3. $category = intval($category); 
  4.  
  5. if ( ($level = intval($level)) <= 0 ) 
  6. $safe = addslashes($level); 
  7. if ( ($level = intval($wpdb->get_var("SELECT id FROM {$wpdb->pmpro_membership_levels} WHERE name = '$safe' LIMIT 1"))) <= 0 ) 
  8. return __("Membership level not found.", 'paid-memberships-pro' ); 
  9.  
  10. if ( $value ) 
  11. $sql = "REPLACE INTO {$wpdb->pmpro_memberships_categories} (`membership_id`, `category_id`) VALUES ('$level', '$category')"; 
  12. $wpdb->query($sql); 
  13. if($wpdb->last_error) return $wpdb->last_error; 
  14. else 
  15. $sql = "DELETE FROM {$wpdb->pmpro_memberships_categories} WHERE `membership_id` = '$level' AND `category_id` = '$category' LIMIT 1"; 
  16. $wpdb->query($sql); 
  17. if($wpdb->last_error) return $wpdb->last_error; 
  18.  
  19. return true;