Skip to content

Commit

Permalink
PHPCS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiva Poudel committed Feb 10, 2018
1 parent 25d77e3 commit 939d804
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
44 changes: 23 additions & 21 deletions includes/admin/class-wc-admin-api-keys-table-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* @version 2.4.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
defined( 'ABSPATH' ) || exit;

if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}

/**
* API Keys table list class.
*/
class WC_Admin_API_Keys_Table_List extends WP_List_Table {

/**
Expand Down Expand Up @@ -53,23 +54,23 @@ public function get_columns() {
/**
* Column cb.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_cb( $key ) {
return sprintf( '<input type="checkbox" name="key[]" value="%1$s" />', $key['key_id'] );
}

/**
* Return description column.
* Return title column.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_title( $key ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=api&section=keys&edit-key=' . $key['key_id'] );

$output = '<strong>';
$output = '<strong>';
$output .= '<a href="' . esc_url( $url ) . '" class="row-title">';
if ( empty( $key['description'] ) ) {
$output .= esc_html__( 'API key', 'woocommerce' );
Expand All @@ -79,8 +80,9 @@ public function column_title( $key ) {
$output .= '</a>';
$output .= '</strong>';

// Get actions
// Get actions.
$actions = array(
/* translators: %s: API key ID. */
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ),
'edit' => '<a href="' . esc_url( $url ) . '">' . __( 'View/Edit', 'woocommerce' ) . '</a>',
'trash' => '<a class="submitdelete" aria-label="' . esc_attr__( 'Revoke API key', 'woocommerce' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key['key_id'] ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ) . '">' . __( 'Revoke', 'woocommerce' ) . '</a>',
Expand All @@ -100,7 +102,7 @@ public function column_title( $key ) {
/**
* Return truncated consumer key column.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_truncated_key( $key ) {
Expand All @@ -110,7 +112,7 @@ public function column_truncated_key( $key ) {
/**
* Return user column.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_user( $key ) {
Expand All @@ -130,7 +132,7 @@ public function column_user( $key ) {
/**
* Return permissions column.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_permissions( $key ) {
Expand All @@ -151,7 +153,7 @@ public function column_permissions( $key ) {
/**
* Return last access column.
*
* @param array $key
* @param array $key Key data.
* @return string
*/
public function column_last_access( $key ) {
Expand Down Expand Up @@ -187,7 +189,7 @@ public function prepare_items() {
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();

// Column headers
// Column headers.
$this->_column_headers = array( $columns, $hidden, $sortable );

$current_page = $this->get_pagenum();
Expand All @@ -199,21 +201,21 @@ public function prepare_items() {

$search = '';

if ( ! empty( $_REQUEST['s'] ) ) {
$search = "AND description LIKE '%" . esc_sql( $wpdb->esc_like( wc_clean( $_REQUEST['s'] ) ) ) . "%' ";
if ( ! empty( $_REQUEST['s'] ) ) { // WPCS: input var okay, CSRF ok.
$search = "AND description LIKE '%" . esc_sql( $wpdb->esc_like( wc_clean( wp_unslash( $_REQUEST['s'] ) ) ) ) . "%' "; // WPCS: input var okay, CSRF ok.
}

// Get the API keys
// Get the API keys.
$keys = $wpdb->get_results(
"SELECT key_id, user_id, description, permissions, truncated_key, last_access FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1 {$search}" .
$wpdb->prepare( "ORDER BY key_id DESC LIMIT %d OFFSET %d;", $per_page, $offset ), ARRAY_A
);
$wpdb->prepare( 'ORDER BY key_id DESC LIMIT %d OFFSET %d;', $per_page, $offset ), ARRAY_A
); // WPCS: unprepared SQL ok.

$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1 {$search};" );
$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1 {$search};" ); // WPCS: unprepared SQL ok.

$this->items = $keys;

// Set the pagination
// Set the pagination.
$this->set_pagination_args( array(
'total_items' => $count,
'per_page' => $per_page,
Expand Down
12 changes: 5 additions & 7 deletions includes/admin/class-wc-admin-webhooks-table-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
/**
* WooCommerce Webhooks Table List
*
* @package WooCommerce/Admin
* @version 3.3.0
* @package WooCommerce\Admin
* @version 3.3.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
defined( 'ABSPATH' ) || exit;

if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}

/**
Expand Down Expand Up @@ -283,7 +281,7 @@ public function prepare_items() {
// Get total items.
$args['limit'] = -1;
$args['offset'] = 0;
$total_items = count( $data_store->search_webhooks( $args ) );
$total_items = count( $data_store->search_webhooks( $args ) );

// Set the pagination.
$this->set_pagination_args( array(
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<rule ref="WordPress">
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery" />
<exclude name="WordPress.VIP.FileSystemWritesDisallow.file_ops_fwrite" />
<exclude name="WordPress.VIP.OrderByRand" />
<exclude name="WordPress.VIP.RestrictedFunctions" />
Expand Down

0 comments on commit 939d804

Please sign in to comment.