/** * This function grabs the API key from UD's servers * * @updated 1.36.0 */ public static function get_api_key($args = false) { $args = wp_parse_args($args, array('force_check' => false)); //** check if API key already exists */ $ud_api_key = get_option('ud_api_key'); //** if key exists, and we are not focing a check, return what we have */ if ($ud_api_key && !$args['force_check']) { return $ud_api_key; } $blogname = get_bloginfo('url'); $blogname = urlencode(str_replace(array('http://', 'https://'), '', $blogname)); $system = 'wpp'; $wpp_version = get_option("wpp_version"); $check_url = "http://updates.usabilitydynamics.com/key_generator.php?system={$system}&site={$blogname}&system_version={$wpp_version}"; $response = @wp_remote_get($check_url); if (!$response) { return false; } // Check for errors if (is_wp_error($response)) { WPP_F::log('API Check Error: ' . $response->get_error_message()); return false; } // Quit if failture if ($response['response']['code'] != '200') { return false; } $response['body'] = trim($response['body']); //** If return is not in MD5 format, it is an error */ if (strlen($response['body']) != 40) { if ($args['return']) { return $response['body']; } else { WPP_F::log("API Check Error: " . sprintf(__('An error occurred during API key request: <b>%s</b>.', ud_get_wp_property()->domain), $response['body'])); return false; } } //** update wpp_key is DB */ update_option('ud_api_key', $response['body']); // Go ahead and return, it should just be the API key return $response['body']; }