pmpro_replaceUserMeta

The Paid Memberships Pro pmpro replaceUserMeta function.

Description

pmpro_replaceUserMeta( $user_id, $meta_keys, $meta_values, (constant) $prev_values = NULL ); 

Parameters (4)

0. $user_id
The user id.
1. $meta_keys
The meta keys.
2. $meta_values
The meta values.
3. $prev_values — Optional. (constant) => NULL
The prev values.

Usage

  1. if ( !function_exists( 'pmpro_replaceUserMeta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = null; 
  6.  
  7. // The meta keys. 
  8. $meta_keys = null; 
  9.  
  10. // The meta values. 
  11. $meta_values = null; 
  12.  
  13. // The prev values. 
  14. $prev_values = NULL; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = pmpro_replaceUserMeta($user_id, $meta_keys, $meta_values, $prev_values); 
  18.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_replaceUserMeta($user_id, $meta_keys, $meta_values, $prev_values = NULL) 
  2. //expects all arrays for last 3 params or all strings 
  3. if(!is_array($meta_keys)) 
  4. $meta_keys = array($meta_keys); 
  5. $meta_values = array($meta_values); 
  6. $prev_values = array($prev_values); 
  7.  
  8. for($i = 0; $i < count($meta_values); $i++) 
  9. if($prev_values[$i]) 
  10. update_user_meta($user_id, $meta_keys[$i], $meta_values[$i], $prev_values[$i]); 
  11. else 
  12. $old_value = get_user_meta($user_id, $meta_keys[$i], true); 
  13. if($old_value) 
  14. update_user_meta($user_id, $meta_keys[$i], $meta_values[$i], $old_value); 
  15. else 
  16. update_user_meta($user_id, $meta_keys[$i], $meta_values[$i]); 
  17.  
  18. return $i;