diff --git a/projects/plugins/jetpack/changelog/remove-nav-unification-preferred-view-param b/projects/plugins/jetpack/changelog/remove-nav-unification-preferred-view-param new file mode 100644 index 0000000000000..03650a387d6f8 --- /dev/null +++ b/projects/plugins/jetpack/changelog/remove-nav-unification-preferred-view-param @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Nav Unification: Removes the `preferred-view` param from the URL after changing the preffered view. This fix only affects WP.com sites. diff --git a/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php b/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php index 8db8e53c480ae..c71a602a84088 100644 --- a/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php +++ b/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php @@ -639,14 +639,19 @@ public function handle_preferred_view() { */ \do_action( 'jetpack_dashboard_switcher_changed_view', $current_screen, $preferred_view ); - // Redirect to default view if that's the newly preferred view. if ( self::DEFAULT_VIEW === $preferred_view ) { + // Redirect to default view if that's the newly preferred view. $menu_mappings = require __DIR__ . '/menu-mappings.php'; if ( isset( $menu_mappings[ $current_screen ] ) ) { // Using `wp_redirect` intentionally because we're redirecting to Calypso. wp_redirect( $menu_mappings[ $current_screen ] . $this->domain ); // phpcs:ignore WordPress.Security.SafeRedirect exit; } + } elseif ( self::CLASSIC_VIEW === $preferred_view ) { + // Removes the `preferred-view` param from the URL to avoid issues with + // screens that don't expect this param to be present in the URL. + wp_safe_redirect( remove_query_arg( 'preferred-view' ) ); + exit; } // phpcs:enable WordPress.Security.NonceVerification } diff --git a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-base-admin-menu.php b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-base-admin-menu.php index b86a73f0137b0..bc66fbc22151f 100644 --- a/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-base-admin-menu.php +++ b/projects/plugins/jetpack/tests/php/modules/masterbar/test-class-base-admin-menu.php @@ -143,6 +143,9 @@ public function test_handle_preferred_view() { global $pagenow; $pagenow = 'test.php'; $_GET['preferred-view'] = 'classic'; + + $this->expectException( ExitException::class ); + static::$admin_menu->handle_preferred_view(); $this->assertSame( 'classic', static::$admin_menu->get_preferred_view( 'test.php' ) );