Add extra protections against wrong filter values in the Command Palette logic (#41773)

* Add extra protections against wrong filter values in the Command Palette logic

* Add changefile(s) from automation for the following project(s): woocommerce

* Add protection to make sure  is an array

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Albert Juhé Lluveras 2023-12-01 10:07:34 +01:00 committed by GitHub
parent 6b77f71ea7
commit 34cfbd94b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 8 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Comment: Prevent Command Palette logic showing PHP errors if buggy extensions add incorrect settings tabs or analytics reports.

View File

@ -567,11 +567,16 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
if ( is_array( $settings_tabs ) && count( $settings_tabs ) > 0 ) {
$formatted_settings_tabs = array();
foreach ($settings_tabs as $key => $label) {
if (
is_string( $key ) && $key !== "" &&
is_string( $label ) && $label !== ""
) {
$formatted_settings_tabs[] = array(
'key' => is_string( $key ) ? $key : '',
'label' => is_string( $label ) ? $label : '',
'key' => $key,
'label' => $label,
);
}
}
WCAdminAssets::register_script( 'wp-admin-scripts', 'command-palette' );
wp_localize_script(
@ -588,11 +593,23 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
$analytics_reports = Analytics::get_report_pages();
if ( is_array( $analytics_reports ) && count( $analytics_reports ) > 0 ) {
$formatted_analytics_reports = array_map( function( $report ) {
if ( ! is_array( $report ) ) {
return null;
}
$title = array_key_exists( 'title', $report ) ? $report['title'] : '';
$path = array_key_exists( 'path', $report ) ? $report['path'] : '';
if (
is_string( $title ) && $title !== "" &&
is_string( $path ) && $path !== ""
) {
return array(
'title' => is_string( $report['title'] ) ? $report['title']: '' ,
'path' => is_string( $report['path'] ) ? $report['path']: '',
'title' => $title,
'path' => $path,
);
}
return null;
}, $analytics_reports );
$formatted_analytics_reports = array_filter( $formatted_analytics_reports, 'is_array' );
WCAdminAssets::register_script( 'wp-admin-scripts', 'command-palette-analytics' );
wp_localize_script(