diff --git a/includes/admin/reports/class-wc-report-coupon-usage.php b/includes/admin/reports/class-wc-report-coupon-usage.php index 7e8a72ec7a0..dadee28b414 100644 --- a/includes/admin/reports/class-wc-report-coupon-usage.php +++ b/includes/admin/reports/class-wc-report-coupon-usage.php @@ -1,7 +1,12 @@ coupon_codes = array_filter( array_map( 'sanitize_text_field', $_GET['coupon_codes'] ) ); + $this->coupon_codes = array_filter( array_map( 'sanitize_text_field', wp_unslash( $_GET['coupon_codes'] ) ) ); } elseif ( isset( $_GET['coupon_codes'] ) ) { - $this->coupon_codes = array_filter( array( sanitize_text_field( $_GET['coupon_codes'] ) ) ); + $this->coupon_codes = array_filter( array( sanitize_text_field( wp_unslash( $_GET['coupon_codes'] ) ) ) ); } } @@ -138,7 +143,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { 'coupon_count' => '#d4d9dc', ); - $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; + $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day'; if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) { $current_range = '7day'; @@ -171,56 +176,58 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { */ public function coupons_widget() { ?> -

+

get_order_report_data( array( - 'data' => array( - 'order_item_name' => array( - 'type' => 'order_item', - 'order_item_type' => 'coupon', - 'function' => '', - 'distinct' => true, - 'name' => 'order_item_name', - ), + $used_coupons = $this->get_order_report_data( array( + 'data' => array( + 'order_item_name' => array( + 'type' => 'order_item', + 'order_item_type' => 'coupon', + 'function' => '', + 'distinct' => true, + 'name' => 'order_item_name', ), - 'where' => array( - array( - 'key' => 'order_item_type', - 'value' => 'coupon', - 'operator' => '=', - ), + ), + 'where' => array( + array( + 'key' => 'order_item_type', + 'value' => 'coupon', + 'operator' => '=', ), - 'query_type' => 'get_col', - 'filter_range' => false, - ) ); + ), + 'query_type' => 'get_col', + 'filter_range' => false, + ) ); - if ( ! empty( $used_coupons ) && is_array( $used_coupons ) ) : + if ( ! empty( $used_coupons ) && is_array( $used_coupons ) ) : ?> + - - - - - - + + + + + + + - +
-

+

coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> - - + + '; } } else { - echo ''; + echo ''; } ?>
' . $coupon->coupon_count . '' . $coupon->coupon_code . '' . esc_html( $coupon->coupon_count ) . '' . esc_html( $coupon->coupon_code ) . '
' . __( 'No coupons found in range', 'woocommerce' ) . '
' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '
-

+

coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> - + '; + // @codingStandardsIgnoreEnd } } else { - echo ''; + echo ''; } ?>
' . wc_price( $coupon->discount_amount ) . '' . $coupon->coupon_code . '' . esc_html( $coupon->coupon_code ) . '
' . __( 'No coupons found in range', 'woocommerce' ) . '
' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '
@@ -342,17 +351,17 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { * Output an export link. */ public function get_export_button() { - $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; + $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( wp_unslash( $_GET['range'] ) ) : '7day'; ?> - + array( 'order_item_name' => array( @@ -435,11 +444,11 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { $order_coupon_counts = $this->get_order_report_data( $order_coupon_counts_query ); $order_discount_amounts = $this->get_order_report_data( $order_discount_amounts_query ); - // Prepare data for report + // Prepare data for report. $order_coupon_counts = $this->prepare_chart_data( $order_coupon_counts, 'post_date', 'order_coupon_count' , $this->chart_interval, $this->start_date, $this->chart_groupby ); $order_discount_amounts = $this->prepare_chart_data( $order_discount_amounts, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby ); - // Encode in json format + // Encode in json format. $chart_data = json_encode( array( 'order_coupon_counts' => array_values( $order_coupon_counts ), 'order_discount_amounts' => array_values( $order_discount_amounts ), @@ -452,15 +461,15 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { var main_chart; jQuery(function(){ - var order_data = jQuery.parseJSON( '' ); + var order_data = jQuery.parseJSON( '' ); var drawGraph = function( highlight ) { var series = [ { label: "", data: order_data.order_coupon_counts, - color: 'chart_colours['coupon_count']; ?>', - bars: { fillColor: 'chart_colours['coupon_count']; ?>', fill: true, show: true, lineWidth: 0, barWidth: barwidth; ?> * 0.5, align: 'center' }, + color: 'chart_colours['coupon_count'] ); ?>', + bars: { fillColor: 'chart_colours['coupon_count'] ); ?>', fill: true, show: true, lineWidth: 0, barWidth: barwidth ); ?> * 0.5, align: 'center' }, shadowSize: 0, hoverable: false }, @@ -468,11 +477,11 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { label: "", data: order_data.order_discount_amounts, yaxis: 2, - color: 'chart_colours['discount_amount']; ?>', + color: 'chart_colours['discount_amount'] ); ?>', points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true }, lines: { show: true, lineWidth: 4, fill: false }, shadowSize: 0, - get_currency_tooltip(); ?> + get_currency_tooltip() ); ?> } ]; @@ -510,7 +519,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report { timeformat: "chart_groupby ) ? '%d %b' : '%b'; ?>", monthNames: month_abbrev ) ) ?>, tickLength: 1, - minTickSize: [1, "chart_groupby; ?>"], + minTickSize: [1, "chart_groupby ); ?>"], font: { color: "#aaa" }