Merge pull request #18098 from woocommerce/update/orders-list-table-phpcs

Fix PHPCS violations on class-wc-admin-list-table-orders.php
This commit is contained in:
Rodrigo Primo 2017-12-13 10:21:47 -02:00 committed by GitHub
commit 1b6c5fb9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 104 additions and 75 deletions

View File

@ -17,7 +17,7 @@ if ( class_exists( 'WC_Admin_List_Table_Orders', false ) ) {
} }
if ( ! class_exists( 'WC_Admin_List_Table', false ) ) { if ( ! class_exists( 'WC_Admin_List_Table', false ) ) {
include_once( 'abstract-class-wc-admin-list-table.php' ); include_once 'abstract-class-wc-admin-list-table.php';
} }
/** /**
@ -57,7 +57,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
/** /**
* Define primary column. * Define primary column.
* *
* @return array * @return string
*/ */
protected function get_primary_column() { protected function get_primary_column() {
return 'order_number'; return 'order_number';
@ -153,7 +153,8 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
global $the_order; global $the_order;
if ( empty( $this->object ) || $this->object->get_id() !== $post_id ) { if ( empty( $this->object ) || $this->object->get_id() !== $post_id ) {
$this->object = $the_order = wc_get_order( $post_id ); $this->object = wc_get_order( $post_id );
$the_order = $this->object;
} }
} }
@ -190,11 +191,13 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$approved_comments_count = absint( $comment_count['approved'] ); $approved_comments_count = absint( $comment_count['approved'] );
if ( $approved_comments_count ) { if ( $approved_comments_count ) {
$latest_notes = wc_get_order_notes( array( $latest_notes = wc_get_order_notes(
'order_id' => $this->object->get_id(), array(
'limit' => 1, 'order_id' => $this->object->get_id(),
'orderby' => 'date_created_gmt', 'limit' => 1,
) ); 'orderby' => 'date_created_gmt',
)
);
$latest_note = current( $latest_notes ); $latest_note = current( $latest_notes );
@ -223,7 +226,11 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$order_timestamp = $this->object->get_date_created()->getTimestamp(); $order_timestamp = $this->object->get_date_created()->getTimestamp();
if ( $order_timestamp > strtotime( '-1 day', current_time( 'timestamp', true ) ) ) { if ( $order_timestamp > strtotime( '-1 day', current_time( 'timestamp', true ) ) ) {
$show_date = sprintf( _x( '%s ago', '%s = human-readable time difference', 'woocommerce' ), human_time_diff( $this->object->get_date_created()->getTimestamp(), current_time( 'timestamp', true ) ) ); $show_date = sprintf(
/* translators: %s: human-readable time difference */
_x( '%s ago', '%s = human-readable time difference', 'woocommerce' ),
human_time_diff( $this->object->get_date_created()->getTimestamp(), current_time( 'timestamp', true ) )
);
} else { } else {
$show_date = $this->object->get_date_created()->date_i18n( apply_filters( 'woocommerce_admin_order_date_format', __( 'M j, Y', 'woocommerce' ) ) ); $show_date = $this->object->get_date_created()->date_i18n( apply_filters( 'woocommerce_admin_order_date_format', __( 'M j, Y', 'woocommerce' ) ) );
} }
@ -259,17 +266,17 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
if ( $this->object->has_status( array( 'pending', 'on-hold' ) ) ) { if ( $this->object->has_status( array( 'pending', 'on-hold' ) ) ) {
$actions['processing'] = array( $actions['processing'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ), 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Processing', 'woocommerce' ), 'name' => __( 'Processing', 'woocommerce' ),
'action' => 'processing', 'action' => 'processing',
); );
} }
if ( $this->object->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) { if ( $this->object->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
$actions['complete'] = array( $actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ), 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Complete', 'woocommerce' ), 'name' => __( 'Complete', 'woocommerce' ),
'action' => 'complete', 'action' => 'complete',
); );
} }
@ -286,12 +293,14 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
* Render columm: billing_address. * Render columm: billing_address.
*/ */
protected function render_billing_address_column() { protected function render_billing_address_column() {
if ( $address = $this->object->get_formatted_billing_address() ) { $address = $this->object->get_formatted_billing_address();
if ( $address ) {
echo esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) ); echo esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) );
if ( $this->object->get_payment_method() ) { if ( $this->object->get_payment_method() ) {
/* translators: %s: payment method */ /* translators: %s: payment method */
echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $this->object->get_payment_method_title() ) ) . '</span>'; echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $this->object->get_payment_method_title() ) ) . '</span>'; // WPCS: XSS ok.
} }
} else { } else {
echo '&ndash;'; echo '&ndash;';
@ -302,11 +311,13 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
* Render columm: shipping_address. * Render columm: shipping_address.
*/ */
protected function render_shipping_address_column() { protected function render_shipping_address_column() {
if ( $address = $this->object->get_formatted_shipping_address() ) { $address = $this->object->get_formatted_shipping_address();
if ( $address ) {
echo '<a target="_blank" href="' . esc_url( $this->object->get_shipping_address_map_url() ) . '">' . esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) ) . '</a>'; echo '<a target="_blank" href="' . esc_url( $this->object->get_shipping_address_map_url() ) . '">' . esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) ) . '</a>';
if ( $this->object->get_shipping_method() ) { if ( $this->object->get_shipping_method() ) {
/* translators: %s: shipping method */ /* translators: %s: shipping method */
echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $this->object->get_shipping_method() ) ) . '</span>'; echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $this->object->get_shipping_method() ) ) . '</span>'; // WPCS: XSS ok.
} }
} else { } else {
echo '&ndash;'; echo '&ndash;';
@ -326,6 +337,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
<section class="wc-backbone-modal-main" role="main"> <section class="wc-backbone-modal-main" role="main">
<header class="wc-backbone-modal-header"> <header class="wc-backbone-modal-header">
<mark class="order-status status-{{ data.status }}"><span>{{ data.status_name }}</span></mark> <mark class="order-status status-{{ data.status }}"><span>{{ data.status_name }}</span></mark>
<?php /* translators: %s: order ID */ ?>
<h1><?php echo esc_html( sprintf( __( 'Order #%s', 'woocommerce' ), '{{ data.order_number }}' ) ); ?></h1> <h1><?php echo esc_html( sprintf( __( 'Order #%s', 'woocommerce' ), '{{ data.order_number }}' ) ); ?></h1>
<button class="modal-close modal-close-link dashicons dashicons-no-alt"> <button class="modal-close modal-close-link dashicons dashicons-no-alt">
<span class="screen-reader-text"><?php esc_html_e( 'Close modal panel', 'woocommerce' ); ?></span> <span class="screen-reader-text"><?php esc_html_e( 'Close modal panel', 'woocommerce' ); ?></span>
@ -402,26 +414,30 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
* @return string * @return string
*/ */
public static function get_order_preview_item_html( $order ) { public static function get_order_preview_item_html( $order ) {
$hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array( $hidden_order_itemmeta = apply_filters(
'_qty', 'woocommerce_hidden_order_itemmeta', array(
'_tax_class', '_qty',
'_product_id', '_tax_class',
'_variation_id', '_product_id',
'_line_subtotal', '_variation_id',
'_line_subtotal_tax', '_line_subtotal',
'_line_total', '_line_subtotal_tax',
'_line_tax', '_line_total',
'method_id', '_line_tax',
'cost', 'method_id',
) ); 'cost',
)
);
$line_items = apply_filters( 'woocommerce_admin_order_preview_line_items', $order->get_items(), $order ); $line_items = apply_filters( 'woocommerce_admin_order_preview_line_items', $order->get_items(), $order );
$columns = apply_filters( 'woocommerce_admin_order_preview_line_item_columns', array( $columns = apply_filters(
'product' => __( 'Product', 'woocommerce' ), 'woocommerce_admin_order_preview_line_item_columns', array(
'quantity' => __( 'Quantity', 'woocommerce' ), 'product' => __( 'Product', 'woocommerce' ),
'tax' => __( 'Tax', 'woocommerce' ), 'quantity' => __( 'Quantity', 'woocommerce' ),
'total' => __( 'Total', 'woocommerce' ), 'tax' => __( 'Tax', 'woocommerce' ),
), $order ); 'total' => __( 'Total', 'woocommerce' ),
), $order
);
if ( ! wc_tax_enabled() ) { if ( ! wc_tax_enabled() ) {
unset( $columns['tax'] ); unset( $columns['tax'] );
@ -457,7 +473,9 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$html .= '<div class="wc-order-item-sku">' . esc_html( $product_object->get_sku() ) . '</div>'; $html .= '<div class="wc-order-item-sku">' . esc_html( $product_object->get_sku() ) . '</div>';
} }
if ( $meta_data = $item->get_formatted_meta_data( '' ) ) { $meta_data = $item->get_formatted_meta_data( '' );
if ( $meta_data ) {
$html .= '<table cellspacing="0" class="wc-order-item-meta">'; $html .= '<table cellspacing="0" class="wc-order-item-meta">';
foreach ( $meta_data as $meta_id => $meta ) { foreach ( $meta_data as $meta_id => $meta ) {
@ -478,7 +496,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
case 'total': case 'total':
$html .= wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) ); $html .= wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
break; break;
default : default:
$html .= apply_filters( 'woocommerce_admin_order_preview_line_item_column_' . sanitize_key( $column ), '', $item, $item_id, $order ); $html .= apply_filters( 'woocommerce_admin_order_preview_line_item_column_' . sanitize_key( $column ), '', $item, $item_id, $order );
break; break;
} }
@ -508,25 +526,25 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
if ( $order->has_status( array( 'pending' ) ) ) { if ( $order->has_status( array( 'pending' ) ) ) {
$status_actions['on-hold'] = array( $status_actions['on-hold'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=on-hold&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ), 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=on-hold&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'On-hold', 'woocommerce' ), 'name' => __( 'On-hold', 'woocommerce' ),
'action' => 'on-hold', 'action' => 'on-hold',
); );
} }
if ( $order->has_status( array( 'pending', 'on-hold' ) ) ) { if ( $order->has_status( array( 'pending', 'on-hold' ) ) ) {
$status_actions['processing'] = array( $status_actions['processing'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ), 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Processing', 'woocommerce' ), 'name' => __( 'Processing', 'woocommerce' ),
'action' => 'processing', 'action' => 'processing',
); );
} }
if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) { if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
$status_actions['complete'] = array( $status_actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ), 'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Completed', 'woocommerce' ), 'name' => __( 'Completed', 'woocommerce' ),
'action' => 'complete', 'action' => 'complete',
); );
} }
@ -554,30 +572,38 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$payment_via = $order->get_payment_method_title(); $payment_via = $order->get_payment_method_title();
$payment_method = $order->get_payment_method(); $payment_method = $order->get_payment_method();
$payment_gateways = WC()->payment_gateways() ? WC()->payment_gateways->payment_gateways() : array(); $payment_gateways = WC()->payment_gateways() ? WC()->payment_gateways->payment_gateways() : array();
$transaction_id = $order->get_transaction_id();
if ( $transaction_id = $order->get_transaction_id() ) { if ( $transaction_id ) {
if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) { $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order );
if ( isset( $payment_gateways[ $payment_method ] ) && $url ) {
$payment_via .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)'; $payment_via .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
} else { } else {
$payment_via .= ' (' . esc_html( $transaction_id ) . ')'; $payment_via .= ' (' . esc_html( $transaction_id ) . ')';
} }
} }
return apply_filters( 'woocommerce_admin_order_preview_get_order_details', array( $billing_address = $order->get_formatted_billing_address();
'data' => $order->get_data(), $shipping_address = $order->get_formatted_shipping_address();
'order_number' => $order->get_order_number(),
'item_html' => WC_Admin_List_Table_Orders::get_order_preview_item_html( $order ), return apply_filters(
'actions_html' => WC_Admin_List_Table_Orders::get_order_preview_actions_html( $order ), 'woocommerce_admin_order_preview_get_order_details', array(
'ship_to_billing' => wc_ship_to_billing_address_only(), 'data' => $order->get_data(),
'needs_shipping' => $order->needs_shipping_address(), 'order_number' => $order->get_order_number(),
'formatted_billing_address' => ( $address = $order->get_formatted_billing_address() ) ? $address : __( 'N/A', 'woocommerce' ), 'item_html' => WC_Admin_List_Table_Orders::get_order_preview_item_html( $order ),
'formatted_shipping_address' => ( $address = $order->get_formatted_shipping_address() ) ? $address: __( 'N/A', 'woocommerce' ), 'actions_html' => WC_Admin_List_Table_Orders::get_order_preview_actions_html( $order ),
'shipping_address_map_url' => $order->get_shipping_address_map_url(), 'ship_to_billing' => wc_ship_to_billing_address_only(),
'payment_via' => $payment_via, 'needs_shipping' => $order->needs_shipping_address(),
'shipping_via' => $order->get_shipping_method(), 'formatted_billing_address' => $billing_address ? $billing_address : __( 'N/A', 'woocommerce' ),
'status' => $order->get_status(), 'formatted_shipping_address' => $shipping_address ? $shipping_address : __( 'N/A', 'woocommerce' ),
'status_name' => wc_get_order_status_name( $order->get_status() ), 'shipping_address_map_url' => $order->get_shipping_address_map_url(),
), $order ); 'payment_via' => $payment_via,
'shipping_via' => $order->get_shipping_method(),
'status' => $order->get_status(),
'status_name' => wc_get_order_status_name( $order->get_status() ),
), $order
);
} }
/** /**
@ -605,7 +631,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
} }
$changed = 0; $changed = 0;
$ids = array_map( 'absint', $ids ); $ids = array_map( 'absint', $ids );
foreach ( $ids as $id ) { foreach ( $ids as $id ) {
$order = wc_get_order( $id ); $order = wc_get_order( $id );
@ -614,12 +640,14 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$changed++; $changed++;
} }
$redirect_to = add_query_arg( array( $redirect_to = add_query_arg(
'post_type' => $this->list_table_type, array(
$report_action => true, 'post_type' => $this->list_table_type,
'changed' => $changed, $report_action => true,
'ids' => join( ',', $ids ), 'changed' => $changed,
), $redirect_to ); 'ids' => join( ',', $ids ),
), $redirect_to
);
return esc_url_raw( $redirect_to ); return esc_url_raw( $redirect_to );
} }
@ -669,10 +697,11 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
$user_id = ''; $user_id = '';
if ( ! empty( $_GET['_customer_user'] ) ) { // WPCS: input var ok. if ( ! empty( $_GET['_customer_user'] ) ) { // WPCS: input var ok.
$user_id = absint( $_GET['_customer_user'] ); // WPCS: input var ok, sanitization ok. $user_id = absint( $_GET['_customer_user'] ); // WPCS: input var ok, sanitization ok.
$user = get_user_by( 'id', $user_id ); $user = get_user_by( 'id', $user_id );
/* translators: 1: user display name 2: user ID 3: user email */
$user_string = sprintf( $user_string = sprintf(
/* translators: 1: user display name 2: user ID 3: user email */
esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ), esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
$user->display_name, $user->display_name,
absint( $user->ID ), absint( $user->ID ),