From ba57d8da29d585e13bf63efea42a540038e0859c Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 31 May 2023 15:18:57 -0300 Subject: [PATCH] ensure parameter datatype for array_slice (#38529) * ensure parameter datatype for array_slice * add phpdocs to existing filters * fix spacing --------- Co-authored-by: Ron Rennick --- .../woocommerce/changelog/fix-38292-array_slice | 4 ++++ .../includes/wc-template-functions.php | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-38292-array_slice diff --git a/plugins/woocommerce/changelog/fix-38292-array_slice b/plugins/woocommerce/changelog/fix-38292-array_slice new file mode 100644 index 00000000000..018e6e241b0 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-38292-array_slice @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +ensure parameter datatype for array_slice diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php index 4d0ef67c979..a5cceece06d 100644 --- a/plugins/woocommerce/includes/wc-template-functions.php +++ b/plugins/woocommerce/includes/wc-template-functions.php @@ -2113,7 +2113,13 @@ if ( ! function_exists( 'woocommerce_upsell_display' ) ) { $orderby = apply_filters( 'woocommerce_upsells_orderby', isset( $args['orderby'] ) ? $args['orderby'] : $orderby ); $order = apply_filters( 'woocommerce_upsells_order', isset( $args['order'] ) ? $args['order'] : $order ); - $limit = apply_filters( 'woocommerce_upsells_total', isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : $limit ); + /** + * Filter the number of upsell products should on the product page. + * + * @param int $limit number of upsell products. + * @since 3.0.0 + */ + $limit = intval( apply_filters( 'woocommerce_upsells_total', $args['posts_per_page'] ?? $limit ) ); // Get visible upsells then sort them at random, then limit result set. $upsells = wc_products_array_orderby( array_filter( array_map( 'wc_get_product', $product->get_upsell_ids() ), 'wc_products_array_filter_visible' ), $orderby, $order ); @@ -2193,7 +2199,13 @@ if ( ! function_exists( 'woocommerce_cross_sell_display' ) ) { $orderby = apply_filters( 'woocommerce_cross_sells_orderby', $orderby ); $order = apply_filters( 'woocommerce_cross_sells_order', $order ); $cross_sells = wc_products_array_orderby( $cross_sells, $orderby, $order ); - $limit = apply_filters( 'woocommerce_cross_sells_total', $limit ); + /** + * Filter the number of cross sell products should on the product page. + * + * @param int $limit number of cross sell products. + * @since 3.0.0 + */ + $limit = intval( apply_filters( 'woocommerce_cross_sells_total', $limit ) ); $cross_sells = $limit > 0 ? array_slice( $cross_sells, 0, $limit ) : $cross_sells; wc_get_template(