Hi, thanx for your feedback.
Done by copying WPMM $default_options and running ajax :
if ( is_plugin_active( 'wp-maintenance-mode/wp-maintenance-mode.php') ) {
/**
* Status auto-update at the end of downcount
*/
// Check status
function isWpmmActive( $countdown = null ) {
$setting = get_option( 'wpmm_settings' );
// Active mode
if ( 1 === $setting['general']['status'] ) {
if ( $countdown ) {
// Countdown active
if ( 1 === $setting['modules'] ['countdown_status'] ) return true;
return false;
}
return true;
}
return false;
}
if ( isWpmmActive() )
{
// No enqueue from WPMM, use wpmm_styles to load default CSS
add_filter( 'wpmm_styles', 'wpmm_moem_styles' );
function wpmm_moem_styles( $styles ) {
$styles['wpmm-moem'] = CHILD_TMPL. '/assets/css/wpmm.css';
return $styles;
}
}
if ( isWpmmActive( 'countdown' ) )
{
// Reset WP maintenance mode on ajax call
add_action( 'wp_ajax_meom_disable_maintenance_mode', 'meom_disable_maintenance_mode' );
add_action( 'wp_ajax_nopriv_meom_disable_maintenance_mode', 'meom_disable_maintenance_mode' );
function meom_disable_maintenance_mode() {
if ( ! isset($_POST['count']) ) return wp_send_json_error('ajax');
if ( intval($_POST['count']) > 0 ) return wp_send_json_error('count');
$default_options = array( /* pasted from WPMM */ );
if ( update_option( 'wpmm_settings', $default_options ) )
return wp_send_json_success();
return wp_send_json_error('update');
}
/**
* No enqueue from WPMM, use wpmm_footer and write JS from PHP to call admin-ajax.php
*/
add_filter( 'wpmm_footer', 'wpmm_moem_footer', 10, 1 );
function wpmm_moem_footer() { ?>
<script>(function ($) {
function updateWpmmOptions( count ) {
$.ajax({
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
type: "POST",
cache: false,
dataType: 'json',
data: { action: 'meom_disable_maintenance_mode', count: count }
}).done(function(response){
if ( response.success ) location.reload()
})
}
// Check the end of countdown
function checkTimer() {
let count = 0
$('.countdown span').each(function() {
if ( ! $(this).hasClass('separator') ) {
count += parseInt( $(this).text() )
}
})
return count
}
$(document).ready(function () {
// Call ajax when countdown == 0
let checkCountdown = setInterval(function () {
let timer = checkTimer()
// On timer 0:00:00:00
if ( 0 === timer ) {
// Remove bounce animation
if ( $('.wrap').hasClass('bounce') ) $('.wrap').removeClass('bounce')
// Slowly show loader after delay
$('body').prepend('<div id="loader" style="opacity:0"></div>')
if ( $('#loader').length ) {
$('#loader').animate({ opacity: 1 }, 2000)
// Call ajax
updateWpmmOptions( timer )
clearTimeout(checkCountdown)
}
}
}, 1000)
})
})(jQuery)
</script>
<?php }
}
}