• Resolved ricard76rr

    (@ricard76rr)


    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)
  • Hello @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 for W3 Total Cache and WP Super Cache).

    Here you can see the default content of wpmm_settings option: github repo

    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 8 years, 10 months ago by George J.
    • This reply was modified 8 years, 10 months ago by George J.
    • This reply was modified 8 years, 10 months ago by George J.
    • This reply was modified 8 years, 10 months ago by George J.
    Thread Starter ricard76rr

    (@ricard76rr)

    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.