/** * Initializes CleverReach API if credentials are valid. * * @access public * @return bool|null */ public function initialize_api() { if (!extension_loaded('soap')) { return false; } if (!is_null($this->api)) { return true; } /* Get the plugin settings */ $settings = $this->get_plugin_settings(); /* If the API Key is empty, return null. */ if (rgblank($settings['api_key'])) { return null; } $this->log_debug(__METHOD__ . "(): Validating API info."); /* Setup a new CleverReach API object. */ $cleverreach = new SoapClient($this->api_url); /* Run a test request. */ $api_test = $cleverreach->clientGetDetails($settings['api_key']); if ($api_test->statuscode == 0) { /* Assign API object to class. */ $this->api = $cleverreach; /* Assign API Key to class. */ $this->api_key = $settings['api_key']; /* Log that test passed. */ $this->log_debug(__METHOD__ . '(): API credentials are valid.'); return true; } else { /* Log that test failed. */ $this->log_error(__METHOD__ . '(): API credentials are invalid; ' . $api_test->message); return false; } }