How to limit WordPress pages during updates?

I will be doing upgrades to the design and content of my WordPress site. During this time I only want the homepage to be available. Is there a good way to lock this down (through a plug-in, etc.).

I’m having trouble coming up with answers from Google.

Read More

Thanks,
Jason

Related posts

Leave a Reply

2 comments

  1. Here is a little snipit of code that I used for my site while it was under construction

    <?php
    /* ROUGH METHOD OF DENY ACCESS */
        $underconstruct = array(121, 46, 124, 97);
        if(!is_user_logged_in() && !in_array(get_the_ID(), $underconstruct)) {
            wp_redirect(get_permalink(121));
            exit();
        }
    ?>
    

    I put this at the top of my header.php.
    the $underconstruct array is the page/post ids that all not logged in users can see. If they are not logged in and are not on one of the pages that they should be, they get redirected. If the user is logged in, then everything will proceed as normal.

  2. As WordPress is a dynamic web app, it’s hard to have your homepage available when everything else is being updated.

    Anytime you run an update for a plugin or WordPress core, it will trigger its maintenance mode. This shows the ‘Briefly unavailable’ page.

    Even using the approach above will result in a visitor seeing the standard maintenance page if they try to visit the site as the update script is run.

    The best approach I think is to create your own maintenance.php file and this is better than a static page.

    .. NB I’m only showing a screen grab of my maintenance page to give you a bit of an idea of what could be achieved.
    enter image description here

    You can see my maintenance.php in action

    Maintenance mode
    To put WordPress in Maintenance Mode create a file called .maintenance in your /wordpress folder.

    I always have mine saved as aaaa.maintenance so I can find it.

    Maintenance mode – logged in users allowed.
    This step allows logged in users to access WP-admin and visit the front end.

    Edit the aaaa.maintenance and insert this code:

    <?php
    function is_user_logged_in() {
    $loggedin = false;
    foreach ( (array) $_COOKIE as $cookie => $value ) {
        if ( stristr($cookie, 'wordpress_logged_in_') )
            $loggedin = true;
    }
    return $loggedin;
    }
    if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'],         '/wp-login.php') && ! is_user_logged_in() )
    $upgrading = time();
    ?>
    

    Create your own maintenance.php
    Under wp-content create a file called maintenance.php

    Open the file and add this code:

    <?php
    $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' );
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    <!--- insert HTML here including hard coding your CSS -->
    
    </body>
    </html>
    <?php die(); ?>
    

    Make sure the bottom of the file has the <?php die(); ?>

    So now you have your own static page you can invoke anytime you rename aaaa.maintenance to .maintenance

    and you can visit /wp-admin even if you are not logged in.