Merge pull request #19710 from javorszky/issue/19704

Cast post IDs to integers in admin meta boxes for coupons, products, orders
This commit is contained in:
Mike Jolley 2018-04-13 18:41:35 +01:00 committed by GitHub
commit d8502349c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -27,7 +27,8 @@ class WC_Meta_Box_Coupon_Data {
public static function output( $post ) { public static function output( $post ) {
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); 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 );
?> ?>

View File

@ -117,7 +117,7 @@ class WC_Order_Factory {
global $post; global $post;
if ( false === $order && is_a( $post, 'WP_Post' ) && 'shop_order' === get_post_type( $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 ) ) { } elseif ( is_numeric( $order ) ) {
return $order; return $order;
} elseif ( $order instanceof WC_Abstract_Order ) { } elseif ( $order instanceof WC_Abstract_Order ) {

View File

@ -102,8 +102,10 @@ class WC_Product_Factory {
* @return int|bool false on failure * @return int|bool false on failure
*/ */
private function get_product_id( $product ) { private function get_product_id( $product ) {
if ( false === $product && isset( $GLOBALS['post'], $GLOBALS['post']->ID ) && 'product' === get_post_type( $GLOBALS['post']->ID ) ) { global $post;
return $GLOBALS['post']->ID;
if ( false === $product && isset( $post, $post->ID ) && 'product' === get_post_type( $post->ID ) ) {
return absint( $post->ID );
} elseif ( is_numeric( $product ) ) { } elseif ( is_numeric( $product ) ) {
return $product; return $product;
} elseif ( $product instanceof WC_Product ) { } elseif ( $product instanceof WC_Product ) {