/** * Check if the account ID is valid. * * @return bool|null */ public function has_valid_account_id() { /* Load the Emma API library. */ require_once 'includes/api/Emma.php'; /* Get the plugin settings */ $settings = $this->get_plugin_settings(); /* If any of the account information fields are empty, return null. */ if (rgblank($settings['account_id']) || rgblank($settings['public_api_key']) || rgblank($settings['private_api_key'])) { return null; } $emma = new Emma($settings['account_id'], $settings['public_api_key'], $settings['private_api_key'], false); try { /* Run test request. */ $emma->myGroups(); return true; } catch (Exception $e) { /* Log that test failed based on HTTP code. */ if ($e->getHttpCode() == 403) { $this->log_error(__METHOD__ . '(): API credentials are valid, Account ID is invalid; ' . $e->getMessage()); } return false; } }