How to Put Site into Maintenance Mode (updates, development)

When updating code on the site, it is recommended to put the site in maintenance mode (block for the duration of the update), so that sudden visits from users could not affect the process of updating files or DB.

To enable such a mode you need:

Option 1:

Create file .maintenance in the root of the site (directory where wp-admin folder is located) with the following code:

<?php
// UNIX time stamp after which + 10 minutes,
// the site will exit development mode.
$upgrading = 1652995051; // time();

Option 2:

Create an empty file ABSPATH . '.maintenance' and manually at an early stage, for example in the wp-config.php file specify a global variable $upgrading:

// UNIX time stamp after which + 10 minutes,
// the site will exit development mode.
$GLOBALS['upgrading'] = 1652995051; // time();

Done!

Refresh the page and see the maintenance message:

The site is briefly closed for maintenance. Come back in a minute.

This Note embeded into: wp_maintenance()