From 44af56ff75da0285e79321970af44e6559c3b36e Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 27 Nov 2014 15:40:39 +0000 Subject: [PATCH] Simplify feature_product() --- includes/class-wc-ajax.php | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 2f2a8e678df..91274600eb3 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -334,32 +334,17 @@ class WC_AJAX { * Feature a product from admin */ public static function feature_product() { - if ( ! current_user_can( 'edit_products' ) ) { - wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce' ), '', array( 'response' => 403 ) ); + if ( current_user_can( 'edit_products' ) && check_admin_referer( 'woocommerce-feature-product' ) ) { + $product_id = absint( $_GET['product_id'] ); + + if ( 'product' === get_post_type( $product_id ) ) { + update_post_meta( $product_id, '_featured', get_post_meta( $product_id, '_featured', true ) === 'yes' ? 'no' : 'yes' ); + + delete_transient( 'wc_featured_products' ); + } } - if ( ! check_admin_referer( 'woocommerce-feature-product' ) ) { - wp_die( __( 'You have taken too long. Please go back and retry.', 'woocommerce' ), '', array( 'response' => 403 ) ); - } - - $post_id = ! empty( $_GET['product_id'] ) ? (int) $_GET['product_id'] : ''; - - if ( ! $post_id || get_post_type( $post_id ) !== 'product' ) { - die; - } - - $featured = get_post_meta( $post_id, '_featured', true ); - - if ( 'yes' === $featured ) { - update_post_meta( $post_id, '_featured', 'no' ); - } else { - update_post_meta( $post_id, '_featured', 'yes' ); - } - - delete_transient( 'wc_featured_products' ); - wp_safe_redirect( wp_get_referer() ? remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) : admin_url( 'edit.php?post_type=shop_order' ) ); - die(); }