From d56992082585ca92016b3a6936627cfe2bbd544d Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Fri, 13 Apr 2018 11:25:58 +0100 Subject: [PATCH 1/4] Cast coupon's $post->ID to int --- includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php index c8689b2ad8b..00184e23e8e 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php @@ -27,7 +27,8 @@ class WC_Meta_Box_Coupon_Data { public static function output( $post ) { wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); - $coupon = new WC_Coupon( $post->ID ); + $coupon_id = absint( $post->ID ); + $coupon = new WC_Coupon( $coupon_id ); ?> From 615815353f43ba01d985c45f1cf05b471b06cba2 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Fri, 13 Apr 2018 11:27:30 +0100 Subject: [PATCH 2/4] Make Order Factory return an int as well from $post->ID --- includes/class-wc-order-factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-order-factory.php b/includes/class-wc-order-factory.php index be36e032346..9286334b75a 100644 --- a/includes/class-wc-order-factory.php +++ b/includes/class-wc-order-factory.php @@ -117,7 +117,7 @@ class WC_Order_Factory { global $post; if ( false === $order && is_a( $post, 'WP_Post' ) && 'shop_order' === get_post_type( $post ) ) { - return $post->ID; + return absint( $post->ID ); } elseif ( is_numeric( $order ) ) { return $order; } elseif ( $order instanceof WC_Abstract_Order ) { From 73e0e3a60e5f931d5d64d2dd7487ef0bf322a0f6 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Fri, 13 Apr 2018 11:28:42 +0100 Subject: [PATCH 3/4] Make Product Factory return an int from $post->ID --- includes/class-wc-product-factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-product-factory.php b/includes/class-wc-product-factory.php index 7b60c6eae2f..64528edd8ad 100644 --- a/includes/class-wc-product-factory.php +++ b/includes/class-wc-product-factory.php @@ -103,7 +103,7 @@ class WC_Product_Factory { */ private function get_product_id( $product ) { if ( false === $product && isset( $GLOBALS['post'], $GLOBALS['post']->ID ) && 'product' === get_post_type( $GLOBALS['post']->ID ) ) { - return $GLOBALS['post']->ID; + return absint( $GLOBALS['post']->ID ); } elseif ( is_numeric( $product ) ) { return $product; } elseif ( $product instanceof WC_Product ) { From ff3fcf0d2b21ea1b0cf009c94da54b879fa2f485 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Fri, 13 Apr 2018 11:29:33 +0100 Subject: [PATCH 4/4] Make Product Factory use global $post instead of $GLOBALS['post'] --- includes/class-wc-product-factory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-product-factory.php b/includes/class-wc-product-factory.php index 64528edd8ad..8e5791deddd 100644 --- a/includes/class-wc-product-factory.php +++ b/includes/class-wc-product-factory.php @@ -102,8 +102,10 @@ class WC_Product_Factory { * @return int|bool false on failure */ private function get_product_id( $product ) { - if ( false === $product && isset( $GLOBALS['post'], $GLOBALS['post']->ID ) && 'product' === get_post_type( $GLOBALS['post']->ID ) ) { - return absint( $GLOBALS['post']->ID ); + global $post; + + if ( false === $product && isset( $post, $post->ID ) && 'product' === get_post_type( $post->ID ) ) { + return absint( $post->ID ); } elseif ( is_numeric( $product ) ) { return $product; } elseif ( $product instanceof WC_Product ) {