Skip to content

Commit

Permalink
Jetpack: Check $submenu is not NULL before adding Scan option (#39424)
Browse files Browse the repository at this point in the history
* Check $submenu is not NULL before accessing it

* Add changelog

---------

Co-authored-by: mmtr <[email protected]>
  • Loading branch information
ecairol and mmtr authored Oct 1, 2024
1 parent f5396a8 commit 75f87b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix for WP.com sites


Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 75f87b5

Please sign in to comment.