WP_Upgrader::maintenance_mode( bool $enable = false )

In this article

Toggles maintenance mode for the site.

Description

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

Parameters

$enablebooloptional
True to enable maintenance mode, false to disable.

Default:false

Source

public function maintenance_mode( $enable = false ) {
	global $wp_filesystem;

	if ( ! $wp_filesystem ) {
		require_once ABSPATH . 'wp-admin/includes/file.php';
		WP_Filesystem();
	}

	$file = $wp_filesystem->abspath() . '.maintenance';
	if ( $enable ) {
		if ( ! wp_doing_cron() ) {
			$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 ) ) {
		if ( ! wp_doing_cron() ) {
			$this->skin->feedback( 'maintenance_end' );
		}
		$wp_filesystem->delete( $file );
	}
}

Changelog

VersionDescription
2.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.