diff --git a/includes/Core/Admin/Screen.php b/includes/Core/Admin/Screen.php index 5d68c1dc677..7a2c010180d 100644 --- a/includes/Core/Admin/Screen.php +++ b/includes/Core/Admin/Screen.php @@ -129,8 +129,7 @@ public function add( Context $context ) { function() use ( $context ) { $this->render( $context ); }, - $context->url( 'dist/assets/images/logo-g_white_small.png' ), - 3 + $context->url( 'dist/assets/images/logo-g_white_small.png' ) ); $menu_slug = $this->slug; } diff --git a/includes/Core/Admin/Screens.php b/includes/Core/Admin/Screens.php index c25057d1168..a1c7391a574 100644 --- a/includes/Core/Admin/Screens.php +++ b/includes/Core/Admin/Screens.php @@ -127,6 +127,21 @@ function() { add_action( 'admin_notices', $remove_notices_callback, -9999 ); add_action( 'network_admin_notices', $remove_notices_callback, -9999 ); add_action( 'all_admin_notices', $remove_notices_callback, -9999 ); + + add_filter( 'custom_menu_order', '__return_true' ); + add_filter( + 'menu_order', + function( array $menu_order ) { + $new_order = array(); + foreach ( $menu_order as $index => $item ) { + if ( 'index.php' === $item || 0 === strpos( $item, self::PREFIX ) ) { + $new_order[] = $item; + unset( $menu_order[ $index ] ); + } + } + return array_values( array_merge( $new_order, $menu_order ) ); + } + ); } /** diff --git a/tests/phpunit/integration/Core/Admin/ScreensTest.php b/tests/phpunit/integration/Core/Admin/ScreensTest.php index f0101ef0fe3..eb15eab8de2 100644 --- a/tests/phpunit/integration/Core/Admin/ScreensTest.php +++ b/tests/phpunit/integration/Core/Admin/ScreensTest.php @@ -95,4 +95,31 @@ public function test_removal_of_admin_notices_outside_sitekit( $hookname ) { do_action( $hookname ); $this->assertNotEmpty( ob_get_clean() ); } + + public function test_menu_order() { + $menu_order = array( + 'index.php', + 'third-party-plugin', + 'edit.php', + 'options-general.php', + 'googlesitekit-dashboard', + ); + + $this->screens->register(); + + // Imitate WordPress core running these filters. + if ( apply_filters( 'custom_menu_order', false ) ) { + $menu_order = apply_filters( 'menu_order', $menu_order ); + } + + $expected_order = array( + 'index.php', + 'googlesitekit-dashboard', + 'third-party-plugin', + 'edit.php', + 'options-general.php', + ); + + $this->assertEquals( $expected_order, $menu_order ); + } }