WP_Upgrader::maintenance_mode() WordPress Method

The WP_Upgrader::maintenance_mode() method puts the website into maintenance mode by creating a file called .maintenance in the website's root directory. This file contains the message that will be displayed to visitors while the website is in maintenance mode.

WP_Upgrader::maintenance_mode( bool $enable = false ) #

Toggle maintenance mode for the site.


Description

Creates/deletes the maintenance file to enable/disable maintenance mode.


Top ↑

Parameters

$enable

(bool)(Optional)True to enable maintenance mode, false to disable.

Default value: false


Top ↑

Source

File: wp-admin/includes/class-wp-upgrader.php

	public function maintenance_mode( $enable = false ) {
		global $wp_filesystem;
		$file = $wp_filesystem->abspath() . '.maintenance';
		if ( $enable ) {
			$this->skin->feedback( 'maintenance_start' );
			// Create maintenance file to signal that we are upgrading.
			$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
			$wp_filesystem->delete( $file );
			$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
		} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
			$this->skin->feedback( 'maintenance_end' );
			$wp_filesystem->delete( $file );
		}
	}

Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.