From 2cd4dc39b97f0a74ebf58a8fbb5408bdd44b22d5 Mon Sep 17 00:00:00 2001 From: Poonam Date: Fri, 18 Sep 2026 00:12:14 +0530 Subject: [PATCH 1/2] Fix maintenance mode changing front page setting --- includes/classes/wp-maintenance-mode.php | 12 +++++++++++- tests/page-state-test.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/includes/classes/wp-maintenance-mode.php b/includes/classes/wp-maintenance-mode.php index 4bc43db..440aaf9 100644 --- a/includes/classes/wp-maintenance-mode.php +++ b/includes/classes/wp-maintenance-mode.php @@ -126,7 +126,17 @@ private function __construct() { } } - update_option( 'show_on_front', 'page' ); + // Make the maintenance page the front page for blocked visitors without changing the site's Reading settings. + add_filter( + 'pre_option_show_on_front', + function ( $value ) { + if ( ( ! $this->check_user_role() && ! $this->check_exclude() ) && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) { + return 'page'; + } + + return $value; + } + ); add_filter( 'pre_option_page_on_front', function ( $value ) { diff --git a/tests/page-state-test.php b/tests/page-state-test.php index a7adf55..2cc7b28 100644 --- a/tests/page-state-test.php +++ b/tests/page-state-test.php @@ -745,4 +745,23 @@ public function test_plugin_deactivation_restores_selected_page() { $this->assertSame( 'private', get_post_status( $page_id ) ); } + + public function test_maintenance_front_page_does_not_change_the_reading_setting() { + $page_id = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + ) + ); + + update_option( 'show_on_front', 'posts' ); + wp_set_current_user( 0 ); + $this->boot_plugin( $this->make_settings( 1, $page_id ) ); + + $this->assertSame( 'page', get_option( 'show_on_front' ) ); + + $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); + wp_set_current_user( $admin_id ); + $this->assertSame( 'posts', get_option( 'show_on_front' ) ); + } } From 1d0856e61d6af28762be6a70e794588ad5323463 Mon Sep 17 00:00:00 2001 From: Poonam Date: Fri, 18 Sep 2026 13:36:14 +0530 Subject: [PATCH 2/2] Restore front page setting after maintenance mode --- includes/classes/wp-maintenance-mode.php | 17 ++++++---------- includes/functions/helpers.php | 26 ++++++++++++++++++++++++ tests/page-state-test.php | 23 +++++++++++++++------ uninstall.php | 1 + 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/includes/classes/wp-maintenance-mode.php b/includes/classes/wp-maintenance-mode.php index 440aaf9..6d49396 100644 --- a/includes/classes/wp-maintenance-mode.php +++ b/includes/classes/wp-maintenance-mode.php @@ -126,17 +126,8 @@ private function __construct() { } } - // Make the maintenance page the front page for blocked visitors without changing the site's Reading settings. - add_filter( - 'pre_option_show_on_front', - function ( $value ) { - if ( ( ! $this->check_user_role() && ! $this->check_exclude() ) && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) { - return 'page'; - } - - return $value; - } - ); + wpmm_record_show_on_front(); + update_option( 'show_on_front', 'page' ); add_filter( 'pre_option_page_on_front', function ( $value ) { @@ -172,6 +163,8 @@ function ( $value ) { add_action( 'wpmm_before_scripts', array( $this, 'add_bot_extras' ) ); add_action( 'wpmm_footer', array( $this, 'add_js_files' ) ); } else { + wpmm_restore_show_on_front(); + // restore the maintenance page to its original state when maintenance mode is disabled add_action( 'init', @@ -694,6 +687,8 @@ public static function single_activate( $network_wide = false ) { * @since 2.0.0 */ public static function single_deactivate() { + wpmm_restore_show_on_front(); + // give the selected page back to the site in its original state $settings = get_option( 'wpmm_settings' ); if ( ! empty( $settings['design']['page_id'] ) ) { diff --git a/includes/functions/helpers.php b/includes/functions/helpers.php index c174b05..2355003 100644 --- a/includes/functions/helpers.php +++ b/includes/functions/helpers.php @@ -598,6 +598,32 @@ function wpmm_restore_page_state( $page_id ) { delete_post_meta( $page_id, '_wpmm_applied_status' ); } +/** + * Record the site's front-page setting before maintenance mode changes it. + * The first recorded value is kept until maintenance mode is disabled. + * + * @return void + */ +function wpmm_record_show_on_front() { + add_option( 'wpmm_original_show_on_front', get_option( 'show_on_front', 'posts' ) ); +} + +/** + * Restore the front-page setting recorded when maintenance mode was enabled. + * + * @return void + */ +function wpmm_restore_show_on_front() { + $original_value = get_option( 'wpmm_original_show_on_front', false ); + + if ( false === $original_value ) { + return; + } + + update_option( 'show_on_front', $original_value ); + delete_option( 'wpmm_original_show_on_front' ); +} + /** * Get option page URL. */ diff --git a/tests/page-state-test.php b/tests/page-state-test.php index 2cc7b28..02e0abd 100644 --- a/tests/page-state-test.php +++ b/tests/page-state-test.php @@ -736,17 +736,23 @@ public function test_plugin_deactivation_restores_selected_page() { ) ); + update_option( 'show_on_front', 'posts' ); + // Maintenance mode is active: the page is taken over and published. $this->boot_plugin( $this->make_settings( 1, $page_id ) ); $this->assertSame( 'publish', get_post_status( $page_id ) ); + $this->assertSame( 'page', get_option( 'show_on_front' ) ); + $this->assertSame( 'posts', get_option( 'wpmm_original_show_on_front' ) ); - // Deactivating the plugin hands the page back, private again. + // Deactivating the plugin hands both the page and Reading setting back. WP_Maintenance_Mode::single_deactivate(); $this->assertSame( 'private', get_post_status( $page_id ) ); + $this->assertSame( 'posts', get_option( 'show_on_front' ) ); + $this->assertFalse( get_option( 'wpmm_original_show_on_front', false ) ); } - public function test_maintenance_front_page_does_not_change_the_reading_setting() { + public function test_disabling_maintenance_mode_restores_the_initial_reading_setting() { $page_id = self::factory()->post->create( array( 'post_type' => 'page', @@ -755,13 +761,18 @@ public function test_maintenance_front_page_does_not_change_the_reading_setting( ); update_option( 'show_on_front', 'posts' ); - wp_set_current_user( 0 ); $this->boot_plugin( $this->make_settings( 1, $page_id ) ); - $this->assertSame( 'page', get_option( 'show_on_front' ) ); + $this->assertSame( 'posts', get_option( 'wpmm_original_show_on_front' ) ); + + // Another active request must not overwrite the recorded initial value. + $this->boot_plugin( $this->make_settings( 1, $page_id ) ); + $this->assertSame( 'posts', get_option( 'wpmm_original_show_on_front' ) ); + + $this->boot_plugin( $this->make_settings( 0, $page_id ) ); + do_action( 'init' ); - $admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); - wp_set_current_user( $admin_id ); $this->assertSame( 'posts', get_option( 'show_on_front' ) ); + $this->assertFalse( get_option( 'wpmm_original_show_on_front', false ) ); } } diff --git a/uninstall.php b/uninstall.php index 5729061..5223337 100755 --- a/uninstall.php +++ b/uninstall.php @@ -17,6 +17,7 @@ function single_uninstall() { 'wpmm_settings', 'wpmm_notice', 'wpmm_version', + 'wpmm_original_show_on_front', ); foreach ( $options_to_delete as $option ) {