2016-12-12 13:00:08 +00:00
< ? php
/**
* Product Reviews
*
* Functions for displaying product reviews data meta box .
*
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Admin\Meta Boxes
2016-12-12 13:00:08 +00:00
*/
2018-05-01 12:00:49 +00:00
defined ( 'ABSPATH' ) || exit ;
2016-12-12 13:00:08 +00:00
/**
* WC_Meta_Box_Product_Reviews
*/
class WC_Meta_Box_Product_Reviews {
/**
2018-05-01 12:00:49 +00:00
* Output the metabox .
2017-05-15 11:50:52 +00:00
*
2018-05-01 12:00:49 +00:00
* @ param object $comment Comment being shown .
2016-12-12 13:00:08 +00:00
*/
public static function output ( $comment ) {
wp_nonce_field ( 'woocommerce_save_data' , 'woocommerce_meta_nonce' );
$current = get_comment_meta ( $comment -> comment_ID , 'rating' , true );
?>
< select name = " rating " id = " rating " >
2018-03-05 18:59:17 +00:00
< ? php
for ( $rating = 1 ; $rating <= 5 ; $rating ++ ) {
2018-05-01 12:00:49 +00:00
printf ( '<option value="%1$s"%2$s>%1$s</option>' , $rating , selected ( $current , $rating , false ) ); // WPCS: XSS ok.
2018-03-05 18:59:17 +00:00
}
?>
2016-12-12 13:00:08 +00:00
</ select >
< ? php
}
/**
* Save meta box data
2017-05-15 11:50:52 +00:00
*
2018-05-01 12:00:49 +00:00
* @ param mixed $data Data to save .
2017-05-15 11:50:52 +00:00
* @ return mixed
2016-12-12 13:00:08 +00:00
*/
2018-04-07 06:50:14 +00:00
public static function save ( $data ) {
2018-05-01 12:00:49 +00:00
// Not allowed, return regular value without updating meta.
if ( ! isset ( $_POST [ 'woocommerce_meta_nonce' ], $_POST [ 'rating' ] ) || ! wp_verify_nonce ( wp_unslash ( $_POST [ 'woocommerce_meta_nonce' ] ), 'woocommerce_save_data' ) ) { // WPCS: input var ok, sanitization ok.
2018-04-07 09:13:35 +00:00
return $data ;
2017-03-07 20:24:24 +00:00
}
2016-12-12 13:00:08 +00:00
2018-05-01 12:00:49 +00:00
if ( $_POST [ 'rating' ] > 5 || $_POST [ 'rating' ] < 0 ) { // WPCS: input var ok.
2018-04-09 12:13:13 +00:00
return $data ;
}
2018-04-07 06:50:14 +00:00
$comment_id = $data [ 'comment_ID' ];
2018-05-01 12:00:49 +00:00
update_comment_meta ( $comment_id , 'rating' , intval ( wp_unslash ( $_POST [ 'rating' ] ) ) ); // WPCS: input var ok.
2016-12-12 13:00:08 +00:00
2018-05-01 12:00:49 +00:00
// Return regular value after updating.
2018-04-07 06:50:14 +00:00
return $data ;
2016-12-12 13:00:08 +00:00
}
}