wp_maintenance

Die with a maintenance message when conditions are met.

Description

wp_maintenance(); 

Checks for a file in the WordPress root directory named .maintenance.. This file will contain the variable $upgrading, set to the time the file was created. If the file was created less than 10 minutes ago, WordPress enters maintenance mode and displays a message.

The default message can be replaced by using a drop-in (maintenance.php in the wp-content directory).


Usage

  1. if ( !function_exists( 'wp_maintenance' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_maintenance(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_maintenance() { 
  2. if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) 
  3. return; 
  4.  
  5. global $upgrading; 
  6.  
  7. include( ABSPATH . '.maintenance' ); 
  8. // If the $upgrading timestamp is older than 10 minutes, don't die. 
  9. if ( ( time() - $upgrading ) >= 600 ) 
  10. return; 
  11.  
  12. /** 
  13. * Filters whether to enable maintenance mode. 
  14. * This filter runs before it can be used by plugins. It is designed for 
  15. * non-web runtimes. If this filter returns true, maintenance mode will be 
  16. * active and the request will end. If false, the request will be allowed to 
  17. * continue processing even if maintenance mode should be active. 
  18. * @since 4.6.0 
  19. * @param bool $enable_checks Whether to enable maintenance mode. Default true. 
  20. * @param int $upgrading The timestamp set in the .maintenance file. 
  21. */ 
  22. if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { 
  23. return; 
  24.  
  25. if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { 
  26. require_once( WP_CONTENT_DIR . '/maintenance.php' ); 
  27. die(); 
  28.  
  29.  
  30. $protocol = wp_get_server_protocol(); 
  31. header( "$protocol 503 Service Unavailable", true, 503 ); 
  32. header( 'Content-Type: text/html; charset=utf-8' ); 
  33. header( 'Retry-After: 600' ); 
  34. ?> 
  35. <!DOCTYPE html> 
  36. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> 
  37. <head> 
  38. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  39. <title><?php _e( 'Maintenance' ); ?></title> 
  40.  
  41. </head> 
  42. <body> 
  43. <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1> 
  44. </body> 
  45. </html> 
  46. <?php 
  47. die();