/** * Give the user options for how to handle their legacy Stream records * * @action admin_notices * @return void */ public static function migrate_notice() { if (!self::show_migrate_notice()) { return; } $notice = sprintf('<strong id="stream-migrate-title">%s</strong></p><p id="stream-migrate-message">%s</p><div id="stream-migrate-progress"><progress value="0" max="100"></progress> <strong>0%</strong> <em></em> <button id="stream-migrate-actions-close" class="button button-secondary">%s</button><div class="clear"></div></div><p id="stream-migrate-actions"><button id="stream-start-migrate" class="button button-primary">%s</button> <button id="stream-migrate-reminder" class="button button-secondary">%s</button> <a href="#" id="stream-delete-records" class="delete">%s</a>', __('Migrate Stream Records', 'stream'), sprintf(__('We found %s existing Stream records that need to be migrated to your Stream account.', 'stream'), number_format(self::$record_count)), __('Close', 'stream'), __('Start Migration Now', 'stream'), __('Remind Me Later', 'stream'), __('Delete Existing Records', 'stream')); WP_Stream::notice($notice, false); }
/** * Output specific update * * @action admin_notices * @return string */ public static function admin_notices() { $message = wp_stream_filter_input(INPUT_GET, 'message'); $notice = false; switch ($message) { case 'settings_reset': $notice = esc_html__('All site settings have been successfully reset.', 'stream'); break; case 'connected': if (!WP_Stream_Migrate::show_migrate_notice()) { $notice = sprintf('<strong>%s</strong></p><p>%s', esc_html__('You have successfully connected to Stream!', 'stream'), esc_html__('Check back here regularly to see a history of the changes being made to this site.', 'stream')); } break; } if ($notice) { WP_Stream::notice($notice, false); } }
/** * Helper function to query the marketplace API via wp_remote_request. * * @param string The url to access. * @param string The method of the request. * @param array The headers sent during the request. * @param bool Allow API calls to be cached. * @param int Set transient expiration in seconds. * * @return object The results of the wp_remote_request request. */ protected function remote_request($url = '', $args = array(), $allow_cache = true, $expiration = 300) { if (empty($url)) { return false; } $defaults = array('headers' => array(), 'method' => 'GET', 'body' => '', 'sslverify' => true); $this->count++; $args = wp_parse_args($args, $defaults); $args['headers']['Stream-Site-API-Key'] = $this->api_key; $args['headers']['Accept-Version'] = $this->api_version; $args['headers']['Content-Type'] = 'application/json'; if (WP_Stream::is_development_mode()) { $args['blocking'] = true; } add_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10, 3); $transient = 'wp_stream_' . md5($url); if ('GET' === $args['method'] && $allow_cache) { if (false === ($request = get_transient($transient))) { $request = wp_remote_request($url, $args); set_transient($transient, $request, $expiration); } } else { $request = wp_remote_request($url, $args); } remove_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10); // Return early if the request is non blocking if (isset($args['blocking']) && false === $args['blocking']) { return true; } if (!is_wp_error($request)) { $data = apply_filters('wp_stream_api_request_data', json_decode($request['body']), $url, $args); // Loose comparison needed if (200 == $request['response']['code'] || 201 == $request['response']['code']) { return $data; } else { // Disconnect if unauthorized or no longer exists, loose comparison needed if (403 == $request['response']['code'] || 410 == $request['response']['code']) { WP_Stream_Admin::remove_api_authentication(); } $this->errors['errors']['http_code'] = $request['response']['code']; } if (isset($data->error)) { $this->errors['errors']['api_error'] = $data->error; } } else { $this->errors['errors']['remote_request_error'] = $request->get_error_message(); WP_Stream::notice(sprintf('<strong>%s</strong> %s.', __('Stream API Error.', 'stream'), $this->errors['errors']['remote_request_error'])); } if (!empty($this->errors)) { delete_transient($transient); } return false; }