Skip to content

Instantly share code, notes, and snippets.

@mikemanger
Last active September 14, 2021 02:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mikemanger/2b72f072038d5df7c215 to your computer and use it in GitHub Desktop.
Save mikemanger/2b72f072038d5df7c215 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 conponments), 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 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment