From 0fd2123ea4c04ccb91ea17c4715cfc72179c43b2 Mon Sep 17 00:00:00 2001 From: Esteban Cairol Date: Tue, 17 Sep 2024 15:58:05 -0600 Subject: [PATCH 1/2] Check $submenu is not NULL before accessing it --- .../src/admin-menu/class-atomic-admin-menu.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php b/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php index 7b81df2be6ee3..4a22f09c7d1af 100644 --- a/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php +++ b/projects/packages/masterbar/src/admin-menu/class-atomic-admin-menu.php @@ -328,11 +328,15 @@ public function add_jetpack_menu() { parent::add_jetpack_menu(); } + $scan_position = $this->get_submenu_item_count( 'jetpack' ) - 1; + global $submenu; - $backup_submenu_label = __( 'Backup', 'jetpack-masterbar' ); - $submenu_labels = array_column( $submenu['jetpack'], 3 ); - $backup_position = array_search( $backup_submenu_label, $submenu_labels, true ); - $scan_position = $backup_position !== false ? $backup_position + 1 : $this->get_submenu_item_count( 'jetpack' ) - 1; + if ( isset( $submenu['jetpack'] ) ) { + $backup_submenu_label = __( 'Backup', 'jetpack-masterbar' ); + $submenu_labels = array_column( $submenu['jetpack'], 3 ); + $backup_position = array_search( $backup_submenu_label, $submenu_labels, true ); + $scan_position = $backup_position !== false ? $backup_position + 1 : $this->get_submenu_item_count( 'jetpack' ) - 1; + } // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. add_submenu_page( 'jetpack', esc_attr__( 'Scan', 'jetpack-masterbar' ), __( 'Scan', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/scan/history/' . $this->domain, null, $scan_position ); From 5ef08e9289ea381b4519955fcca7ac039e36c773 Mon Sep 17 00:00:00 2001 From: mmtr <1233880+mmtr@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:56:15 +0200 Subject: [PATCH 2/2] Add changelog --- .../packages/masterbar/changelog/fix-submenu-jetpack-null | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 projects/packages/masterbar/changelog/fix-submenu-jetpack-null diff --git a/projects/packages/masterbar/changelog/fix-submenu-jetpack-null b/projects/packages/masterbar/changelog/fix-submenu-jetpack-null new file mode 100644 index 0000000000000..6519110c5c524 --- /dev/null +++ b/projects/packages/masterbar/changelog/fix-submenu-jetpack-null @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Fix for WP.com sites + +