Skip to content

Commit 28343d1

Browse files
agent-sandbox-automattic[bot]haqadnmatticbot
authored
SEO: Keep the menu item when SEO tools is off (#53940)
* SEO: keep the sidebar menu item visible when seo-tools module is off Dropping 'module' => 'seo-tools' from Admin_Page::add_menu_item()'s args stops the visibility resolver from hiding the item when the module is inactive. The key 'jetpack-seo' is kept so hosts can still control it via the jetpack_admin_menu_visibility filter. Co-authored-by: matticbot <matticbot@users.noreply.github.com> * SEO: Make the menu fix changelog entry comment-only The new SEO page is still behind its rollout gate. --------- Co-authored-by: haqadn <adnan.haque@automattic.com> Co-authored-by: matticbot <matticbot@users.noreply.github.com> Co-authored-by: Adnan Haque <adnan007.id@gmail.com>
1 parent 6aed93b commit 28343d1

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
Comment: Keep the SEO menu item in the sidebar when the seo-tools module is off. The new SEO page is gated.
4+

‎projects/packages/seo/src/class-admin-page.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ public static function add_menu_item() {
8484
self::MENU_SLUG,
8585
$callback,
8686
null,
87-
// SEO has no My Jetpack product class, so the module is the only gate available.
87+
// No module gate: the menu must stay visible even when seo-tools is off so the
88+
// user can turn it back on from the page. Hosts may still use the
89+
// jetpack_admin_menu_visibility filter to hide it via the 'jetpack-seo' key.
8890
array(
89-
'module' => 'seo-tools',
90-
'key' => 'jetpack-seo',
91+
'key' => 'jetpack-seo',
9192
)
9293
);
9394

‎projects/packages/seo/tests/php/AdminPageTest.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,32 @@ public function test_alias_screen_id_round_trip() {
212212
$this->assertSame( 'jetpack_page_jetpack-seo', get_current_screen()->id );
213213
}
214214

215+
/**
216+
* The menu must be visible even when seo-tools is off, so the user can turn it back on.
217+
* Verified by checking that no module gate is declared on the registered item.
218+
*/
219+
public function test_menu_item_is_registered_without_a_module_gate() {
220+
Admin_Page::add_menu_item();
221+
222+
$menu_items = new \ReflectionProperty( Admin_Menu::class, 'menu_items' );
223+
if ( \PHP_VERSION_ID < 80100 ) {
224+
$menu_items->setAccessible( true );
225+
}
226+
$items = $menu_items->getValue( null );
227+
228+
$seo_item = null;
229+
foreach ( $items as $item ) {
230+
if ( Admin_Page::MENU_SLUG === $item['menu_slug'] ) {
231+
$seo_item = $item;
232+
break;
233+
}
234+
}
235+
236+
$this->assertNotNull( $seo_item, 'SEO menu item was not registered' );
237+
$this->assertArrayNotHasKey( 'module', $seo_item['args'] ?? array() );
238+
$this->assertSame( 'jetpack-seo', $seo_item['args']['key'] ?? null );
239+
}
240+
215241
/**
216242
* The dashboard opts the screen Admin_Menu registers out of JITMs, and no other.
217243
*/

0 commit comments

Comments
 (0)