pmpro_license_check_key

The Paid Memberships Pro pmpro license check key function.

Description

pmpro_license_check_key( (constant) $key = NULL ); 

Parameters (1)

0. $key — Optional. (constant) => NULL
The key.

Usage

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

Defined (1)

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

/includes/license.php  
  1. function pmpro_license_check_key($key = NULL) { 
  2. //get key 
  3. if(empty($key)) 
  4. $key = get_option('pmpro_license_key'); 
  5.  
  6. //key? check with server 
  7. if(!empty($key)) 
  8. //check license server 
  9. $url = add_query_arg(array('license'=>$key, 'domain'=>site_url()), PMPRO_LICENSE_SERVER); 
  10.  
  11. /** 
  12. * Filter to change thetimeoutfor this wp_remote_get() request. 
  13. * @since 1.8.5.1 
  14. * @param int $timeout The number of seconds before the request times out 
  15. */ 
  16. $timeout = apply_filters("pmpro_license_check_key_timeout", 5); 
  17.  
  18. $r = wp_remote_get($url, array("timeout" => $timeout)); 
  19.  
  20. //test response 
  21. if(is_wp_error($r)) { 
  22. //error 
  23. pmpro_setMessage("Could not connect to the PMPro License Server to check key Try again later.", "error"); 
  24. elseif(!empty($r) && $r['response']['code'] == 200) 
  25. $r = json_decode($r['body']); 
  26.  
  27. if($r->active == 1) 
  28. //valid key save enddate 
  29. if(!empty($r->enddate)) 
  30. $enddate = strtotime($r->enddate, current_time('timestamp')); 
  31. else 
  32. $enddate = strtotime("+1 Year", current_time("timestamp")); 
  33.  
  34. delete_option('pmpro_license_check'); 
  35. add_option('pmpro_license_check', array('license'=>$r->license, 'enddate'=>$enddate), NULL, 'no');  
  36. return true; 
  37. elseif(!empty($r->error)) 
  38. //invalid key 
  39. global $pmpro_license_error; 
  40. $pmpro_license_error = $r->error; 
  41.  
  42. delete_option('pmpro_license_check'); 
  43. add_option('pmpro_license_check', array('license'=>false, 'enddate'=>0), NULL, 'no'); 
  44.  
  45. }  
  46.  
  47. //no key or there was an error 
  48. return false;