diff --git a/plugins/woocommerce/changelog/41253-as-update-to-php-81 b/plugins/woocommerce/changelog/41253-as-update-to-php-81 new file mode 100644 index 00000000000..e8be4d9b37e --- /dev/null +++ b/plugins/woocommerce/changelog/41253-as-update-to-php-81 @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Apply type checks and enhancements for PHP 8.1 diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-importers.php b/plugins/woocommerce/includes/admin/class-wc-admin-importers.php index 2d2886afe99..37c59e4dc5b 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-importers.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-importers.php @@ -293,11 +293,11 @@ class WC_Admin_Importers { 'position' => 'done', 'percentage' => 100, 'url' => add_query_arg( array( '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ), - 'imported' => count( $results['imported'] ), - 'imported_variations' => count( $results['imported_variations'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), + 'imported' => is_countable( $results['imported'] ) ? count( $results['imported'] ) : 0, + 'imported_variations' => is_countable( $results['imported_variations'] ) ? count( $results['imported_variations'] ) : 0, + 'failed' => is_countable( $results['failed'] ) ? count( $results['failed'] ) : 0, + 'updated' => is_countable( $results['updated'] ) ? count( $results['updated'] ) : 0, + 'skipped' => is_countable( $results['skipped'] ) ? count( $results['skipped'] ) : 0, ) ); } else { @@ -305,11 +305,11 @@ class WC_Admin_Importers { array( 'position' => $importer->get_file_position(), 'percentage' => $percent_complete, - 'imported' => count( $results['imported'] ), - 'imported_variations' => count( $results['imported_variations'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), + 'imported' => is_countable( $results['imported'] ) ? count( $results['imported'] ) : 0, + 'imported_variations' => is_countable( $results['imported_variations'] ) ? count( $results['imported_variations'] ) : 0, + 'failed' => is_countable( $results['failed'] ) ? count( $results['failed'] ) : 0, + 'updated' => is_countable( $results['updated'] ) ? count( $results['updated'] ) : 0, + 'skipped' => is_countable( $results['skipped'] ) ? count( $results['skipped'] ) : 0, ) ); } diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php b/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php index d5c4862963d..8feac7bc5a6 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php @@ -192,7 +192,7 @@ class WC_Admin_Webhooks { $webhook_id = absint( $_GET['delete'] ); if ( $webhook_id ) { - $this->bulk_delete( array( $webhook_id ) ); + self::bulk_delete( array( $webhook_id ) ); } } } diff --git a/plugins/woocommerce/includes/admin/helper/class-wc-helper.php b/plugins/woocommerce/includes/admin/helper/class-wc-helper.php index f93ab209cd7..fd264411104 100644 --- a/plugins/woocommerce/includes/admin/helper/class-wc-helper.php +++ b/plugins/woocommerce/includes/admin/helper/class-wc-helper.php @@ -408,7 +408,7 @@ class WC_Helper { } $filters = array_fill_keys( array_keys( self::get_filters() ), 0 ); - if ( empty( $subscriptions ) ) { + if ( ! is_array( $subscriptions ) || empty( $subscriptions ) ) { return array(); } @@ -1461,7 +1461,7 @@ class WC_Helper { if ( is_readable( $txt ) ) { $txt = file_get_contents( $txt ); $txt = preg_split( '#\s#', $txt ); - if ( count( $txt ) >= 2 ) { + if ( is_array( $txt ) && count( $txt ) >= 2 ) { $header = sprintf( '%d:%s', $txt[0], $txt[1] ); } } diff --git a/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php b/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php index e07375ffd97..a32b9e9d5d7 100644 --- a/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php +++ b/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php @@ -146,8 +146,8 @@ class WC_Tax_Rate_Importer extends WP_Importer { if ( false !== $handle ) { $header = fgetcsv( $handle, 0, $this->delimiter ); - - if ( 10 === count( $header ) ) { + $count = is_countable( $header ) ? count( $header ) : 0; + if ( 10 === $count ) { $row = fgetcsv( $handle, 0, $this->delimiter ); diff --git a/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php b/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php index 70ef0ddd651..d74a37eebd7 100644 --- a/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php +++ b/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php @@ -80,7 +80,7 @@ if ( ! defined( 'ABSPATH' ) ) { object->get_product_ids(); - - if ( count( $product_ids ) > 0 ) { + if ( is_array( $product_ids ) && count( $product_ids ) > 0 ) { echo esc_html( implode( ', ', $product_ids ) ); } else { echo '–'; diff --git a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php index dca2695ca46..3292ec3d1d6 100644 --- a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php +++ b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php @@ -15,8 +15,7 @@ $arrow_img_url = WC_ADMIN_IMAGES_FOLDER_URL . '/product_data/no-variati ?>