Commit e221887047 for woocommerce
commit e221887047e9f986a9f439e5ff9b3cedc52aade3
Author: kkmuffme <11071985+kkmuffme@users.noreply.github.com>
Date: Mon Dec 1 16:45:52 2025 +0100
Fix PHP notice 55353 (#55354)
* Fix PHP notice 55353
Fix https://github.com/woocommerce/woocommerce/issues/55353
* Add changefile(s) from automation for the following project(s): woocommerce
* Add changefile(s) from automation for the following project(s): woocommerce
* Add a basic test
---------
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/55354-fix-notice-55353 b/plugins/woocommerce/changelog/55354-fix-notice-55353
new file mode 100644
index 0000000000..be704e216c
--- /dev/null
+++ b/plugins/woocommerce/changelog/55354-fix-notice-55353
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix PHP warning undefined array key "post_type".
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-orders.php b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-orders.php
index b1ca6b1a9c..0cd662bb1a 100644
--- a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-orders.php
+++ b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-orders.php
@@ -708,7 +708,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
public function search_custom_fields( $wp ) {
global $pagenow;
- if ( 'edit.php' !== $pagenow || 'shop_order' !== $wp->query_vars['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ if ( 'edit.php' !== $pagenow || ! isset( $wp->query_vars['post_type'] ) || 'shop_order' !== $wp->query_vars['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
diff --git a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-orders-test.php b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-orders-test.php
index 0e321c915f..b3ccc320f6 100644
--- a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-orders-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-orders-test.php
@@ -269,4 +269,40 @@ class WC_Admin_List_Table_Orders_Test extends WC_Unit_Test_Case {
wp_delete_post( $product->get_id(), true );
wp_delete_post( $dummy_order->get_id(), true );
}
+
+ /**
+ * Test that the search without post_type in query does not trigger warnings.
+ * This is a regression test for https://github.com/woocommerce/woocommerce/pull/55353.
+ */
+ public function test_search_without_post_type_in_query_does_not_trigger_warning() {
+ $GLOBALS['pagenow'] = 'edit.php'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+
+ new WC_Admin_List_Table_Orders();
+
+ $warnings = array();
+ set_error_handler( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
+ function () use ( &$warnings ) {
+ $warnings[] = true;
+ }
+ );
+
+ // Do not set post_type in the query.
+ new WP_Query(
+ array(
+ 'post_status' => 'all',
+ 'fields' => 'ids',
+ )
+ );
+
+ restore_error_handler();
+
+ // Check no warnings were triggered.
+ $this->assertEmpty(
+ $warnings,
+ 'No PHP warnings or notices should be triggered when no post_type is set in WP_Query for admin order search.'
+ );
+
+ // Cleanup.
+ unset( $GLOBALS['pagenow'] );
+ }
}