Example #1
0
/**
 * Die with a maintenance message when conditions are met.
 *
 * Checks for a file in the WordPress root directory named ".maintenance".
 * This file will contain the variable $upgrading, set to the time the file
 * was created. If the file was created less than 10 minutes ago, WordPress
 * enters maintenance mode and displays a message.
 *
 * The default message can be replaced by using a drop-in (maintenance.php in
 * the wp-content directory).
 *
 * @since 3.0.0
 * @access private
 *
 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
 */
function wp_maintenance()
{
    if (!file_exists(ABSPATH . '.maintenance') || wp_installing()) {
        return;
    }
    global $upgrading;
    include ABSPATH . '.maintenance';
    // If the $upgrading timestamp is older than 10 minutes, don't die.
    if (time() - $upgrading >= 600) {
        return;
    }
    if (file_exists(WP_CONTENT_DIR . '/maintenance.php')) {
        require_once WP_CONTENT_DIR . '/maintenance.php';
        die;
    }
    wp_load_translations_early();
    $protocol = wp_get_server_protocol();
    header("{$protocol} 503 Service Unavailable", true, 503);
    header('Content-Type: text/html; charset=utf-8');
    header('Retry-After: 600');
    ?>
	<!DOCTYPE html>
	<html xmlns="http://www.w3.org/1999/xhtml"<?php 
    if (is_rtl()) {
        echo ' dir="rtl"';
    }
    ?>
>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php 
    _e('Maintenance');
    ?>
</title>

	</head>
	<body>
		<h1><?php 
    _e('Briefly unavailable for scheduled maintenance. Check back in a minute.');
    ?>
</h1>
	</body>
	</html>
<?php 
    die;
}
Example #2
0
/**
 * Set HTTP status header.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$description` parameter.
 *
 * @see get_status_header_desc()
 *
 * @param int    $code        HTTP status code.
 * @param string $description Optional. A custom description for the HTTP status.
 */
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        /**
         * Filter an HTTP status header.
         *
         * @since 2.2.0
         *
         * @param string $status_header HTTP status header.
         * @param int    $code          HTTP status code.
         * @param string $description   Description for the status code.
         * @param string $protocol      Server protocol.
         */
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}
Example #3
0
/**
 * Die with a maintenance message when conditions are met.
 *
 * Checks for a file in the WordPress root directory named ".maintenance".
 * This file will contain the variable $upgrading, set to the time the file
 * was created. If the file was created less than 10 minutes ago, WordPress
 * enters maintenance mode and displays a message.
 *
 * The default message can be replaced by using a drop-in (maintenance.php in
 * the wp-content directory).
 *
 * @since 3.0.0
 * @access private
 *
 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
 */
function wp_maintenance()
{
    if (!file_exists(ABSPATH . '.maintenance') || wp_installing()) {
        return;
    }
    global $upgrading;
    include ABSPATH . '.maintenance';
    // If the $upgrading timestamp is older than 10 minutes, don't die.
    if (time() - $upgrading >= 600) {
        return;
    }
    /**
     * Bypass the maintenance mode check
     *
     * This filter should *NOT* be used by plugins. It is designed for non-web
     * runtimes. If this filter returns true, maintenance mode will not be  
     * active which can cause problems during updates for web site views.
     *
     * @since 4.6.0
     *
     * @param bool True to bypass maintenance
     */
    if (apply_filters('bypass_maintenance_mode', false)) {
        return;
    }
    if (file_exists(WP_CONTENT_DIR . '/maintenance.php')) {
        require_once WP_CONTENT_DIR . '/maintenance.php';
        die;
    }
    wp_load_translations_early();
    $protocol = wp_get_server_protocol();
    header("{$protocol} 503 Service Unavailable", true, 503);
    header('Content-Type: text/html; charset=utf-8');
    header('Retry-After: 600');
    ?>
	<!DOCTYPE html>
	<html xmlns="http://www.w3.org/1999/xhtml"<?php 
    if (is_rtl()) {
        echo ' dir="rtl"';
    }
    ?>
>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php 
    _e('Maintenance');
    ?>
</title>

	</head>
	<body>
		<h1><?php 
    _e('Briefly unavailable for scheduled maintenance. Check back in a minute.');
    ?>
</h1>
	</body>
	</html>
<?php 
    die;
}
Example #4
0
/**
 * Die with a maintenance message when conditions are met.
 *
 * Checks for a file in the WordPress root directory named ".maintenance".
 * This file will contain the variable $upgrading, set to the time the file
 * was created. If the file was created less than 10 minutes ago, WordPress
 * enters maintenance mode and displays a message.
 *
 * The default message can be replaced by using a drop-in (maintenance.php in
 * the wp-content directory).
 *
 * @since 3.0.0
 * @access private
 *
 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
 */
function wp_maintenance()
{
    if (!file_exists(ABSPATH . '.maintenance') || wp_installing()) {
        return;
    }
    global $upgrading;
    include ABSPATH . '.maintenance';
    // If the $upgrading timestamp is older than 10 minutes, don't die.
    if (time() - $upgrading >= 600) {
        return;
    }
    /**
     * Filters whether to enable maintenance mode.
     *
     * This filter runs before it can be used by plugins. It is designed for
     * non-web runtimes. If this filter returns true, maintenance mode will be
     * active and the request will end. If false, the request will be allowed to
     * continue processing even if maintenance mode should be active.
     *
     * @since 4.6.0
     *
     * @param bool $enable_checks Whether to enable maintenance mode. Default true.
     * @param int  $upgrading     The timestamp set in the .maintenance file.
     */
    if (!apply_filters('enable_maintenance_mode', true, $upgrading)) {
        return;
    }
    if (file_exists(WP_CONTENT_DIR . '/maintenance.php')) {
        require_once WP_CONTENT_DIR . '/maintenance.php';
        die;
    }
    wp_load_translations_early();
    $protocol = wp_get_server_protocol();
    header("{$protocol} 503 Service Unavailable", true, 503);
    header('Content-Type: text/html; charset=utf-8');
    header('Retry-After: 600');
    ?>
	<!DOCTYPE html>
	<html xmlns="http://www.w3.org/1999/xhtml"<?php 
    if (is_rtl()) {
        echo ' dir="rtl"';
    }
    ?>
>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php 
    _e('Maintenance');
    ?>
</title>

	</head>
	<body>
		<h1><?php 
    _e('Briefly unavailable for scheduled maintenance. Check back in a minute.');
    ?>
</h1>
	</body>
	</html>
<?php 
    die;
}
function status_header($code, $description = '')
{
    if (!$description) {
        $description = get_status_header_desc($code);
    }
    if (empty($description)) {
        return;
    }
    $protocol = wp_get_server_protocol();
    $status_header = "{$protocol} {$code} {$description}";
    if (function_exists('apply_filters')) {
        $status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
    }
    @header($status_header, true, $code);
}
 /**
  * Start page caching and hook into requests to complete it later
  *
  * @since 2.1.0
  *
  * @return void
  */
 protected function start()
 {
     // Disabled
     if ($this->max_age < 1) {
         return;
     }
     // Necessary to prevent clients using cached version after login cookies
     // set. If this is a problem, comment it out and remove all
     // Last-Modified headers.
     @header('Vary: Cookie', false);
     // Things that define a unique page.
     if (isset($_SERVER['QUERY_STRING'])) {
         parse_str($_SERVER['QUERY_STRING'], $this->query);
     }
     // Get the server protocol
     $protocol = wp_get_server_protocol();
     // Build different versions for HTTP/1.1 and HTTP/2.0
     if ('HTTP/1.0' !== $protocol) {
         $this->unique['server_protocol'] = $_SERVER['SERVER_PROTOCOL'];
     }
     // Setup keys
     $this->keys = array('host' => $_SERVER['HTTP_HOST'], 'method' => $_SERVER['REQUEST_METHOD'], 'path' => ($this->pos = strpos($_SERVER['REQUEST_URI'], '?')) ? substr($_SERVER['REQUEST_URI'], 0, $this->pos) : $_SERVER['REQUEST_URI'], 'query' => $this->query, 'extra' => $this->unique, 'ssl' => $this->is_ssl());
     // Recreate the permalink from the URL
     $scheme = true === $this->keys['ssl'] ? 'https://' : 'http://';
     $this->permalink = $scheme . $this->keys['host'] . $this->keys['path'] . (isset($this->keys['query']['p']) ? "?p=" . $this->keys['query']['p'] : '');
     $this->url_key = md5($this->permalink);
     $this->url_version = (int) wp_cache_get("{$this->url_key}_version", $this->group);
     // Setup keys and variants
     $this->do_variants();
     $this->generate_keys();
     // Get the spider_cache
     $this->cache = wp_cache_get($this->key, $this->group);
     // Are we only caching frequently-requested pages?
     if ($this->seconds < 1 || $this->times < 2) {
         $this->do = true;
         // No spider_cache item found, or ready to sample traffic again at
         // the end of the spider_cache life?
     } elseif (!is_array($this->cache) || $this->started >= $this->cache['time'] + $this->max_age - $this->seconds) {
         wp_cache_add($this->req_key, 0, $this->group);
         $this->requests = wp_cache_incr($this->req_key, 1, $this->group);
         $this->do = (bool) ($this->requests >= $this->times);
     }
     // If the document has been updated and we are the first to notice, regenerate it.
     if (true === $this->do && isset($this->cache['version']) && $this->cache['version'] < $this->url_version) {
         $this->genlock = wp_cache_add("{$this->url_key}_genlock", 1, $this->group, 10);
     }
     // Did we find a spider_cached page that hasn't expired?
     if (isset($this->cache['time']) && false === $this->genlock && $this->started < $this->cache['time'] + $this->cache['max_age']) {
         // Issue redirect if cached and enabled
         if ($this->cache['redirect_status'] && $this->cache['redirect_location'] && $this->cache_redirects) {
             $status = $this->cache['redirect_status'];
             $location = $this->cache['redirect_location'];
             // From vars.php
             $is_IIS = strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false;
             $this->do_headers($this->headers);
             if (!empty($is_IIS)) {
                 @header("Refresh: 0;url={$location}");
             } else {
                 if (php_sapi_name() !== 'cgi-fcgi') {
                     $texts = array(300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect');
                     isset($texts[$status]) ? @header("{$protocol} {$status} {$texts[$status]}") : @header("{$protocol} 302 Found");
                 }
                 @header("Location: {$location}");
             }
             exit;
         }
         // Respect ETags served with feeds.
         $three_oh_four = false;
         if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && isset($this->cache['headers']['ETag'][0]) && $_SERVER['HTTP_IF_NONE_MATCH'] == $this->cache['headers']['ETag'][0]) {
             $three_oh_four = true;
             // Respect If-Modified-Since.
         } elseif ($this->cache_control && isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             $client_time = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
             $cache_time = isset($this->cache['headers']['Last-Modified'][0]) ? strtotime($this->cache['headers']['Last-Modified'][0]) : $this->cache['time'];
             if ($client_time >= $cache_time) {
                 $three_oh_four = true;
             }
         }
         // Use the spider_cache save time for Last-Modified so we can issue
         // "304 Not Modified" but don't clobber a cached Last-Modified header.
         if ($this->cache_control && !isset($this->cache['headers']['Last-Modified'][0])) {
             @header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->cache['time']) . ' GMT', true);
             @header('Cache-Control: max-age=' . ($this->cache['max_age'] - $this->started + $this->cache['time']) . ', must-revalidate', true);
         }
         // Add some debug info just before </head>
         if (true === $this->debug) {
             $this->add_debug_from_cache();
         }
         $this->do_headers($this->headers, $this->cache['headers']);
         // Bail if not modified
         if (true === $three_oh_four) {
             @header("HTTP/1.1 304 Not Modified", true, 304);
             die;
         }
         // Set header if cached
         if (!empty($this->cache['status_header'])) {
             @header($this->cache['status_header'], true);
         }
         // Have you ever heard a death rattle before?
         die($this->cache['output']);
     }
     // Didn't meet the minimum condition?
     if (false === $this->do && false === $this->genlock) {
         return;
     }
     // Headers and such
     add_filter('status_header', array($this, 'status_header'), 10, 2);
     add_filter('wp_redirect_status', array($this, 'redirect_status'), 10, 2);
     // Start the spidey-sense listening
     ob_start(array($this, 'ob'));
 }