isOpenRoute($request->get_route())) { return $result; } return new \WP_Error( 'extendify_site_unpublished', \__('This site is not ready for visitors yet.', 'extendify-local'), ['status' => 503] ); } /** * Whether a REST route still answers while the site is hidden. * * @param string $route The route being dispatched. * @return boolean */ private function isOpenRoute($route) { $route = trim($route, '/'); if ($route === '') { return true; } foreach (self::OPEN_NAMESPACES as $namespace) { if ($route === $namespace || strpos($route, $namespace . '/') === 0) { return true; } } return false; } /** * Keeps the index from naming the site or inventorying its plugins. * * @param \WP_REST_Response $response The index response. * @return \WP_REST_Response */ public function maybeTrimRestIndex($response) { $response->set_data(array_intersect_key( $response->get_data(), array_flip(self::OPEN_INDEX_FIELDS) )); // The site logo returns through _links even when its field is stripped. foreach (array_keys($response->get_links()) as $relation) { $response->remove_link($relation); } return $response; } /** * Keeps site content out of admin-ajax.php while the site is hidden. * * Other plugins register wp_ajax_nopriv_ handlers that read content, so the * gate has to sit in front of the dispatch rather than on any one action. * * @return void */ public function maybeBlockAjax() { if (!\wp_doing_ajax()) { return; } \nocache_headers(); \wp_send_json_error( [ 'code' => 'extendify_site_unpublished', 'message' => \__('This site is not ready for visitors yet.', 'extendify-local'), ], 503 ); } /** * Turns away the comment and trackback endpoints while the site is hidden. * * wp_loaded runs before either file looks up the post. * * @return void */ public function maybeBlockClosedScripts() { if (!in_array($this->currentScript(), self::CLOSED_SCRIPTS, true)) { return; } \nocache_headers(); \wp_die( \esc_html__('This site is not ready for visitors yet.', 'extendify-local'), \esc_html__('Coming soon', 'extendify-local'), ['response' => 503] ); } /** * The PHP file handling this request. * * @return string */ private function currentScript() { if (!isset($_SERVER['SCRIPT_NAME'])) { return ''; } return basename(\sanitize_text_field(\wp_unslash($_SERVER['SCRIPT_NAME']))); } /** * Serves the Coming Soon page instead of whatever was requested. * * @return void */ public function maybeRender() { // 503 keeps search engines from indexing the placeholder as the site. \status_header(503); \nocache_headers(); $this->pageContent(); exit; } /** * Coming Soon page output * * @return void */ private function pageContent() { $title = \__('Coming soon', 'extendify-local'); $message = \__('This site is not ready for visitors yet. Please check back soon.', 'extendify-local'); ?> >