Skip to content

Commit

Permalink
Nav Unification: Remove preferred-view param after update (#21632)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtr authored Nov 4, 2021
1 parent 42492d1 commit 39fb67b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down

0 comments on commit 39fb67b

Please sign in to comment.