Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetpack: Check $submenu is not NULL before adding Scan option #39424

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading