Skip to content

Instantly share code, notes, and snippets.

@ControlledChaos
Forked from mikemanger/.maintenance
Last active March 30, 2023 21:59
Show Gist options
  • Save ControlledChaos/af9d1fa6d212a619b039bd901222bd34 to your computer and use it in GitHub Desktop.
Save ControlledChaos/af9d1fa6d212a619b039bd901222bd34 to your computer and use it in GitHub Desktop.
Example WordPress .maintenance file. maintenance.php is optional but useful for styling the message the public will see (it is also used when updating WordPress components), drop it in your wp-content folder.
<?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
if ( stristr( $cookie, 'wordpress_logged_in_' ) ) {
$loggedin = true;
}
}
return $loggedin;
}
$check_ip = true;
$your_ip = '';
$client_ip = '';
if ( ! stristr( $_SERVER['REQUEST_URI'], '/wp-admin' ) && ! stristr( $_SERVER['REQUEST_URI'], '/wp-login.php' ) && ! is_user_logged_in() ) {
if ( $check_ip && $_SERVER['REMOTE_ADDR'] != $your_ip && $_SERVER['REMOTE_ADDR'] != $client_ip ) {
$upgrading = time();
}
}
<?php
/* Tell search engines that the site is temporarily unavailable */
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) {
$protocol = 'HTTP/1.0';
}
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 600' );
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Maintenance In Progress - Company Name</title>
<style type="text/css" media="screen">
/* inline styles here (don't link them as they might not be available) */
</style>
</head>
<body>
<h1>Apologies, we are busy updating our website.</h1>
<p>Please bear with us as we try to do this as fast as we can.</p>
/* Aditional content information here, Twitter link etc. */
</body>
</html>
<?php
/* This passes control back to the WordPress upgrade routine */
die();
/* Don't change this */
@aqres
Copy link

aqres commented Sep 13, 2021

Use of file .maintenance triggers PHP Fatal error: Cannot redeclare is_user_logged_in() (previously declared in /[serverpath]/.maintenance on line 3) in [serverpath]/.maintenance on line 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment