/** * Validate a key * * @since 1.0.0 * @param string $key * @return mixed|string|WP_Error */ public function validate_key($key) { if (empty($key)) { return ''; } $key = preg_replace('/\\s/', '', sanitize_text_field($key)); $response = $this->api_client($key)->get_site(); if (is_wp_error($response) or !in_array($response['response']['code'], array(200, 401, 503))) { return Prompt_Logging::add_error('key_http_error', __('There\'s a problem verifying your key. Please try later or report this error.', 'Postmatic'), $response); } if (503 == $response['response']['code']) { $message = sprintf(__('Postmatic service is temporarily unavailable, see <a href="%s">our twitter feed</a> for updates.', 'Postmatic'), Prompt_Enum_Urls::TWITTER); return new WP_Error('service_unavailable', $message); } if (401 == $response['response']['code']) { $message = sprintf(__('We didn\'t recognize the key "%s". Please make sure it exactly matches the key we supplied you. <a href="%s" target="_blank">Visit your Postmatic dashboard for assistance</a>. ', 'Postmatic'), $key, Prompt_Enum_Urls::MANAGE); return new WP_Error('invalid_key', $message); } $configuration = json_decode($response['body']); if (!self::site_matches($configuration->site->url)) { $message = sprintf(__('Your key was registered for a different site. Please request a key for this site\'s dedicated use, or <a href="%s" target="_blank">contact us</a> for assistance. Thanks!', 'Postmatic'), Prompt_Enum_Urls::BUG_REPORTS); return new WP_Error('wrong_key', $message); } if (Prompt_Core::$options->get('enable_digests') and !in_array(Prompt_Enum_Message_Types::DIGEST, $configuration->configuration->enabled_message_types)) { $configuration->configuration->enable_digests = false; } $configurator = Prompt_Factory::make_configurator($this->api_client()); $configurator->update_configuration($configuration); return $key; }
public static function receive_pull_configuration() { self::validate_or_die(); $configurator = Prompt_Factory::make_configurator(); self::set_return_code_and_die($configurator->pull_configuration()); }