Merge branch 'master' of github.com:woocommerce/woocommerce

This commit is contained in:
Rodrigo Primo 2018-04-09 18:08:51 -03:00
commit d6bfd22dfb
2 changed files with 11 additions and 6 deletions

View File

@ -65,7 +65,7 @@ class WC_Admin_Meta_Boxes {
add_action( 'woocommerce_process_shop_coupon_meta', 'WC_Meta_Box_Coupon_Data::save', 10, 2 );
// Save Rating Meta Boxes.
add_action( 'comment_edit_redirect', 'WC_Meta_Box_Product_Reviews::save', 1, 2 );
add_filter( 'wp_update_comment_data', 'WC_Meta_Box_Product_Reviews::save', 1 );
// Error handling (for showing errors from meta boxes on next page load).
add_action( 'admin_notices', array( $this, 'output_errors' ) );

View File

@ -40,17 +40,22 @@ class WC_Meta_Box_Product_Reviews {
/**
* Save meta box data
*
* @param mixed $location
* @param int $comment_id
* @param mixed $data
*
* @return mixed
*/
public static function save( $location, $comment_id ) {
public static function save( $data ) {
// Not allowed, return regular value without updating meta
if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) {
return $location;
return $data;
}
if ( $_POST['rating'] > 5 || $_POST['rating'] < 0 ) {
return $data;
}
$comment_id = $data['comment_ID'];
// Update meta
update_comment_meta(
$comment_id,
@ -59,6 +64,6 @@ class WC_Meta_Box_Product_Reviews {
);
// Return regular value after updating
return $location;
return $data;
}
}