public static function activate($data, $key) { // data to send in our API request if (!$data) { $item_name = self::REG_ITEM_NAME; $item_key = 'core'; } else { $item_name = $data->item_name; $item_key = $data->key; } $api_params = array('edd_action' => 'activate_license', 'license' => $key, 'item_name' => urlencode($item_name), 'url' => home_url()); $response = wp_remote_post(self::API_URL, array('timeout' => 15, 'sslverify' => FALSE, 'body' => $api_params)); if (is_wp_error($response)) { // Try again with post $response = wp_remote_get(add_query_arg($api_params, self::API_URL), array('timeout' => 15, 'sslverify' => FALSE)); if (is_wp_error($response)) { echo '<div class="error"><p>' . WPIMCore::__('When attempting to activate license, could not reach license site.') . '</p></div>'; return FALSE; } } if (!$response) { echo '<div class="error"><p>' . WPIMCore::__('When attempting to activate license, no response was received.') . '</p></div>'; } else { if (wp_remote_retrieve_response_code($response) != 200) { echo '<div class="error"><p>' . sprintf(WPIMCore::__('When attempting to activate license, a response code of %d was returned.'), wp_remote_retrieve_response_code($response)) . '</p>'; echo '<p><strong>Debugging Information: Please provide the information below to support.</strong></p>'; var_dump($response); echo '</div>'; } else { $response = json_decode(wp_remote_retrieve_body($response)); if ($response->license != 'valid') { echo '<div class="error"><p>' . sprintf(WPIMCore::__('The license entered for %s is invalid.'), $item_name) . '</p></div>'; $key = array('key' => '', 'expires' => NULL, 'valid' => FALSE); } else { echo '<div class="updated"><p>' . sprintf(WPIMCore::__('Congratulations! The %s license entered is valid.'), $item_name); if ($item_key != 'core') { echo ' <a href="' . admin_url('admin.php?page=manage_settings') . '">' . sprintf(WPIMCore::__('(Click to refresh if %s is not visible.)'), $item_name) . '</a>'; } echo '</p></div>'; $key = array('key' => $key, 'expires' => strtotime($response->expires), 'valid' => TRUE); } } $all_reg_info = WPIMCore::get_reg_info(); $all_reg_info[$item_key] = $key; update_option('wpim_license', $all_reg_info); } }