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:
parent
6b77f71ea7
commit
34cfbd94b4
|
@ -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.
|
||||
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue