Title: activate maintenance mode programatically
Last modified: May 17, 2017

---

# activate maintenance mode programatically

 *  Resolved [ricard76rr](https://wordpress.org/support/users/ricard76rr/)
 * (@ricard76rr)
 * [9 years ago](https://wordpress.org/support/topic/activate-maintenance-mode-programatically/)
 * Hello,
 * I need to enable maintenance mode via php script.
 * Every day I run a script on my website to update content, I would like during
   the execution of the scritp my website to appear in maintenance mode.
 * Is it possible to enable / disable maintenance mode of the plugin with some code
   written in my php script?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [George J](https://wordpress.org/support/users/georgejipa/)
 * (@georgejipa)
 * [9 years ago](https://wordpress.org/support/topic/activate-maintenance-mode-programatically/#post-9142349)
 * Hello [@ricard76rr](https://wordpress.org/support/users/ricard76rr/),
 * You can update `wpmm_settings` option and set status to 1. But you also have 
   to clear the cache (programmatically) if you have a cache plugin installed and
   activated ([example](https://github.com/Designmodocom/WP-Maintenance-Mode/blob/master/includes/classes/wp-maintenance-mode-admin.php#L414)
   for W3 Total Cache and WP Super Cache).
 * Here you can see the default content of `wpmm_settings` option: [github repo](https://github.com/Designmodocom/WP-Maintenance-Mode/blob/master/includes/classes/wp-maintenance-mode.php#L82)
 * So you need something like this:
 *     ```
       function wpmm_custom_trigger($status) {
       	if (!in_array($status, array(0, 1))) {
       		return;
       	}
   
       	if (!class_exists('WP_Maintenance_Mode')) {
       		return;
       	}
   
       	// get settings
       	$settings = WP_Maintenance_Mode::get_instance()->get_plugin_settings();
   
       	// set status
       	$settings['general']['status'] = $status;
       	$settings['general']['status_date'] = date('Y-m-d H:i:s');
   
       	// save settings
       	update_option('wpmm_settings', $settings);
   
       	// here must be a clear cache mechanism if you have a cache plugin installed and activated...
       }
   
       wpmm_custom_trigger(1); // to enable
       wpmm_custom_trigger(0); // to disable
       ```
   
 * Thanks.
    -  This reply was modified 9 years ago by [George J](https://wordpress.org/support/users/georgejipa/).
    -  This reply was modified 9 years ago by [George J](https://wordpress.org/support/users/georgejipa/).
    -  This reply was modified 9 years ago by [George J](https://wordpress.org/support/users/georgejipa/).
    -  This reply was modified 9 years ago by [George J](https://wordpress.org/support/users/georgejipa/).
 *  Thread Starter [ricard76rr](https://wordpress.org/support/users/ricard76rr/)
 * (@ricard76rr)
 * [9 years ago](https://wordpress.org/support/topic/activate-maintenance-mode-programatically/#post-9144299)
 * Hello George, you’re gorgeous :).
 * This works perfectly.
 * Thanks for your help, you do a great job,
 * Best regards,
 * Ricard.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘activate maintenance mode programatically’ is closed to new replies.

 * ![](https://ps.w.org/wp-maintenance-mode/assets/icon-256x256.gif?rev=3027645)
 * [LightStart - Maintenance Mode, Coming Soon and Landing Page Builder](https://wordpress.org/plugins/wp-maintenance-mode/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-maintenance-mode/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-maintenance-mode/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-maintenance-mode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-maintenance-mode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-maintenance-mode/reviews/)

## Tags

 * [programatically](https://wordpress.org/support/topic-tag/programatically/)
 * [script](https://wordpress.org/support/topic-tag/script/)

 * 2 replies
 * 2 participants
 * Last reply from: [ricard76rr](https://wordpress.org/support/users/ricard76rr/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/activate-maintenance-mode-programatically/#post-9144299)
 * Status: resolved