Merge pull request #18817 from shivapoudel/feature/screen-option
Add support screen options for core list tables
This commit is contained in:
commit
de5b60a7e6
|
@ -2,24 +2,23 @@
|
||||||
/**
|
/**
|
||||||
* WooCommerce API Keys Table List
|
* WooCommerce API Keys Table List
|
||||||
*
|
*
|
||||||
* @author WooThemes
|
* @package WooCommerce\Admin
|
||||||
* @category Admin
|
* @version 2.4.0
|
||||||
* @package WooCommerce/Admin
|
|
||||||
* @version 2.4.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! class_exists( 'WP_List_Table' ) ) {
|
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 {
|
class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the webhook table list.
|
* Initialize the API key table list.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct( array(
|
parent::__construct( array(
|
||||||
|
@ -29,6 +28,13 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No items found text.
|
||||||
|
*/
|
||||||
|
public function no_items() {
|
||||||
|
esc_html_e( 'No keys found.', 'woocommerce' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list columns.
|
* Get list columns.
|
||||||
*
|
*
|
||||||
|
@ -37,7 +43,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
public function get_columns() {
|
public function get_columns() {
|
||||||
return array(
|
return array(
|
||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'description' => __( 'Description', 'woocommerce' ),
|
'title' => __( 'Description', 'woocommerce' ),
|
||||||
'truncated_key' => __( 'Consumer key ending in', 'woocommerce' ),
|
'truncated_key' => __( 'Consumer key ending in', 'woocommerce' ),
|
||||||
'user' => __( 'User', 'woocommerce' ),
|
'user' => __( 'User', 'woocommerce' ),
|
||||||
'permissions' => __( 'Permissions', 'woocommerce' ),
|
'permissions' => __( 'Permissions', 'woocommerce' ),
|
||||||
|
@ -48,7 +54,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
/**
|
/**
|
||||||
* Column cb.
|
* Column cb.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_cb( $key ) {
|
public function column_cb( $key ) {
|
||||||
|
@ -56,15 +62,15 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return description column.
|
* Return title column.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_description( $key ) {
|
public function column_title( $key ) {
|
||||||
$url = admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&edit-key=' . $key['key_id'] );
|
$url = admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&edit-key=' . $key['key_id'] );
|
||||||
|
|
||||||
$output = '<strong>';
|
$output = '<strong>';
|
||||||
$output .= '<a href="' . esc_url( $url ) . '" class="row-title">';
|
$output .= '<a href="' . esc_url( $url ) . '" class="row-title">';
|
||||||
if ( empty( $key['description'] ) ) {
|
if ( empty( $key['description'] ) ) {
|
||||||
$output .= esc_html__( 'API key', 'woocommerce' );
|
$output .= esc_html__( 'API key', 'woocommerce' );
|
||||||
|
@ -74,11 +80,14 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
$output .= '</a>';
|
$output .= '</a>';
|
||||||
$output .= '</strong>';
|
$output .= '</strong>';
|
||||||
|
|
||||||
// Get actions
|
// Get actions.
|
||||||
$actions = array(
|
$actions = array(
|
||||||
|
/* translators: %s: API key ID. */
|
||||||
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ),
|
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ),
|
||||||
'edit' => '<a href="' . esc_url( $url ) . '">' . __( 'View/Edit', 'woocommerce' ) . '</a>',
|
'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§ion=keys' ) ), 'revoke' ) ) . '">' . __( 'Revoke', '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§ion=keys' ) ), 'revoke' ) ) . '">' . esc_html__( 'Revoke', 'woocommerce' ) . '</a>',
|
||||||
);
|
);
|
||||||
|
|
||||||
$row_actions = array();
|
$row_actions = array();
|
||||||
|
@ -95,7 +104,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
/**
|
/**
|
||||||
* Return truncated consumer key column.
|
* Return truncated consumer key column.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_truncated_key( $key ) {
|
public function column_truncated_key( $key ) {
|
||||||
|
@ -105,7 +114,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
/**
|
/**
|
||||||
* Return user column.
|
* Return user column.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_user( $key ) {
|
public function column_user( $key ) {
|
||||||
|
@ -125,7 +134,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
/**
|
/**
|
||||||
* Return permissions column.
|
* Return permissions column.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_permissions( $key ) {
|
public function column_permissions( $key ) {
|
||||||
|
@ -146,7 +155,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
/**
|
/**
|
||||||
* Return last access column.
|
* Return last access column.
|
||||||
*
|
*
|
||||||
* @param array $key
|
* @param array $key Key data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_last_access( $key ) {
|
public function column_last_access( $key ) {
|
||||||
|
@ -177,15 +186,9 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
public function prepare_items() {
|
public function prepare_items() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$per_page = apply_filters( 'woocommerce_api_keys_settings_items_per_page', 10 );
|
$per_page = $this->get_items_per_page( 'woocommerce_keys_per_page' );
|
||||||
$columns = $this->get_columns();
|
|
||||||
$hidden = array();
|
|
||||||
$sortable = $this->get_sortable_columns();
|
|
||||||
|
|
||||||
// Column headers
|
|
||||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
|
||||||
|
|
||||||
$current_page = $this->get_pagenum();
|
$current_page = $this->get_pagenum();
|
||||||
|
|
||||||
if ( 1 < $current_page ) {
|
if ( 1 < $current_page ) {
|
||||||
$offset = $per_page * ( $current_page - 1 );
|
$offset = $per_page * ( $current_page - 1 );
|
||||||
} else {
|
} else {
|
||||||
|
@ -194,21 +197,21 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
|
||||||
|
|
||||||
$search = '';
|
$search = '';
|
||||||
|
|
||||||
if ( ! empty( $_REQUEST['s'] ) ) {
|
if ( ! empty( $_REQUEST['s'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
$search = "AND description LIKE '%" . esc_sql( $wpdb->esc_like( wc_clean( $_REQUEST['s'] ) ) ) . "%' ";
|
$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(
|
$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}" .
|
"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;
|
$this->items = $keys;
|
||||||
|
|
||||||
// Set the pagination
|
// Set the pagination.
|
||||||
$this->set_pagination_args( array(
|
$this->set_pagination_args( array(
|
||||||
'total_items' => $count,
|
'total_items' => $count,
|
||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
|
|
|
@ -2,15 +2,11 @@
|
||||||
/**
|
/**
|
||||||
* WooCommerce Admin API Keys Class
|
* WooCommerce Admin API Keys Class
|
||||||
*
|
*
|
||||||
* @author WooThemes
|
* @package WooCommerce\Admin
|
||||||
* @category Admin
|
* @version 2.4.0
|
||||||
* @package WooCommerce/Admin
|
|
||||||
* @version 2.4.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Admin_API_Keys.
|
* WC_Admin_API_Keys.
|
||||||
|
@ -22,52 +18,64 @@ class WC_Admin_API_Keys {
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
add_action( 'admin_init', array( $this, 'actions' ) );
|
add_action( 'admin_init', array( $this, 'actions' ) );
|
||||||
|
add_action( 'woocommerce_settings_page_init', array( $this, 'screen_option' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if is API Keys settings page.
|
* Check if is API Keys settings page.
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function is_api_keys_settings_page() {
|
private function is_api_keys_settings_page() {
|
||||||
return isset( $_GET['page'] )
|
return isset( $_GET['page'], $_GET['tab'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'api' === $_GET['tab'] && 'keys' === $_GET['section']; // WPCS: input var okay, CSRF ok.
|
||||||
&& 'wc-settings' === $_GET['page']
|
|
||||||
&& isset( $_GET['tab'] )
|
|
||||||
&& 'api' === $_GET['tab']
|
|
||||||
&& isset( $_GET['section'] )
|
|
||||||
&& 'keys' === $_GET['section'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page output.
|
* Page output.
|
||||||
*/
|
*/
|
||||||
public static function page_output() {
|
public static function page_output() {
|
||||||
// Hide the save button
|
// Hide the save button.
|
||||||
$GLOBALS['hide_save_button'] = true;
|
$GLOBALS['hide_save_button'] = true;
|
||||||
|
|
||||||
if ( isset( $_GET['create-key'] ) || isset( $_GET['edit-key'] ) ) {
|
if ( isset( $_GET['create-key'] ) || isset( $_GET['edit-key'] ) ) {
|
||||||
$key_id = isset( $_GET['edit-key'] ) ? absint( $_GET['edit-key'] ) : 0;
|
$key_id = isset( $_GET['edit-key'] ) ? absint( $_GET['edit-key'] ) : 0; // WPCS: input var okay, CSRF ok.
|
||||||
$key_data = self::get_key_data( $key_id );
|
$key_data = self::get_key_data( $key_id );
|
||||||
|
|
||||||
include( 'settings/views/html-keys-edit.php' );
|
include 'settings/views/html-keys-edit.php';
|
||||||
} else {
|
} else {
|
||||||
self::table_list_output();
|
self::table_list_output();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add screen option.
|
||||||
|
*/
|
||||||
|
public function screen_option() {
|
||||||
|
global $keys_table_list;
|
||||||
|
|
||||||
|
if ( ! isset( $_GET['create-key'] ) && ! isset( $_GET['edit-key'] ) && $this->is_api_keys_settings_page() ) { // WPCS: input var okay, CSRF ok.
|
||||||
|
$keys_table_list = new WC_Admin_API_Keys_Table_List();
|
||||||
|
|
||||||
|
// Add screen option.
|
||||||
|
add_screen_option( 'per_page', array(
|
||||||
|
'default' => 10,
|
||||||
|
'option' => 'woocommerce_keys_per_page',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table list output.
|
* Table list output.
|
||||||
*/
|
*/
|
||||||
private static function table_list_output() {
|
private static function table_list_output() {
|
||||||
|
global $wpdb, $keys_table_list;
|
||||||
|
|
||||||
global $wpdb;
|
echo '<h2>' . esc_html__( 'Keys/Apps', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&create-key=1' ) ) . '" class="add-new-h2">' . esc_html__( 'Add key', 'woocommerce' ) . '</a></h2>';
|
||||||
|
|
||||||
echo '<h2>' . __( 'Keys/Apps', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&create-key=1' ) ) . '" class="add-new-h2">' . __( 'Add key', 'woocommerce' ) . '</a></h2>';
|
// Get the API keys count.
|
||||||
|
|
||||||
// Get the API keys count
|
|
||||||
$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1;" );
|
$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1;" );
|
||||||
|
|
||||||
if ( absint( $count ) && $count > 0 ) {
|
if ( absint( $count ) && $count > 0 ) {
|
||||||
$keys_table_list = new WC_Admin_API_Keys_Table_List();
|
|
||||||
$keys_table_list->prepare_items();
|
$keys_table_list->prepare_items();
|
||||||
|
|
||||||
echo '<input type="hidden" name="page" value="wc-settings" />';
|
echo '<input type="hidden" name="page" value="wc-settings" />';
|
||||||
|
@ -80,17 +88,17 @@ class WC_Admin_API_Keys {
|
||||||
} else {
|
} else {
|
||||||
echo '<div class="woocommerce-BlankState woocommerce-BlankState--api">';
|
echo '<div class="woocommerce-BlankState woocommerce-BlankState--api">';
|
||||||
?>
|
?>
|
||||||
<h2 class="woocommerce-BlankState-message"><?php _e( 'The WooCommerce REST API allows external apps to view and manage store data. Access is granted only to those with valid API keys.', 'woocommerce' ); ?></h2>
|
<h2 class="woocommerce-BlankState-message"><?php esc_html_e( 'The WooCommerce REST API allows external apps to view and manage store data. Access is granted only to those with valid API keys.', 'woocommerce' ); ?></h2>
|
||||||
<a class="woocommerce-BlankState-cta button-primary button" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&create-key=1' ) ); ?>"><?php _e( 'Create an API key', 'woocommerce' ); ?></a>
|
<a class="woocommerce-BlankState-cta button-primary button" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys&create-key=1' ) ); ?>"><?php esc_html_e( 'Create an API key', 'woocommerce' ); ?></a>
|
||||||
|
<style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions { display: none; }</style>
|
||||||
<?php echo '<style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions { display: none; } </style></div>';
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get key data.
|
* Get key data.
|
||||||
*
|
*
|
||||||
* @param int $key_id
|
* @param int $key_id API Key ID.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private static function get_key_data( $key_id ) {
|
private static function get_key_data( $key_id ) {
|
||||||
|
@ -105,7 +113,7 @@ class WC_Admin_API_Keys {
|
||||||
'last_access' => '',
|
'last_access' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( 0 == $key_id ) {
|
if ( 0 === $key_id ) {
|
||||||
return $empty;
|
return $empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,13 +135,13 @@ class WC_Admin_API_Keys {
|
||||||
*/
|
*/
|
||||||
public function actions() {
|
public function actions() {
|
||||||
if ( $this->is_api_keys_settings_page() ) {
|
if ( $this->is_api_keys_settings_page() ) {
|
||||||
// Revoke key
|
// Revoke key.
|
||||||
if ( isset( $_GET['revoke-key'] ) ) {
|
if ( isset( $_GET['revoke-key'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
$this->revoke_key();
|
$this->revoke_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bulk actions
|
// Bulk actions.
|
||||||
if ( isset( $_GET['action'] ) && isset( $_GET['key'] ) ) {
|
if ( isset( $_GET['action'] ) && isset( $_GET['key'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
$this->bulk_actions();
|
$this->bulk_actions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +151,7 @@ class WC_Admin_API_Keys {
|
||||||
* Notices.
|
* Notices.
|
||||||
*/
|
*/
|
||||||
public static function notices() {
|
public static function notices() {
|
||||||
if ( isset( $_GET['revoked'] ) && 1 == $_GET['revoked'] ) {
|
if ( isset( $_GET['revoked'] ) && 1 === $_GET['revoked'] ) { // WPCS: input var okay, CSRF ok.
|
||||||
WC_Admin_Settings::add_message( __( 'API key revoked successfully.', 'woocommerce' ) );
|
WC_Admin_Settings::add_message( __( 'API key revoked successfully.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,12 +160,15 @@ class WC_Admin_API_Keys {
|
||||||
* Revoke key.
|
* Revoke key.
|
||||||
*/
|
*/
|
||||||
private function revoke_key() {
|
private function revoke_key() {
|
||||||
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'revoke' ) ) {
|
check_admin_referer( 'revoke' );
|
||||||
wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$key_id = absint( $_GET['revoke-key'] );
|
if ( isset( $_GET['revoke-key'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
$this->remove_key( $key_id );
|
$key_id = absint( $_GET['revoke-key'] ); // WPCS: input var okay, CSRF ok.
|
||||||
|
|
||||||
|
if ( $key_id ) {
|
||||||
|
$this->remove_key( $key_id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wp_redirect( esc_url_raw( add_query_arg( array( 'revoked' => 1 ), admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys' ) ) ) );
|
wp_redirect( esc_url_raw( add_query_arg( array( 'revoked' => 1 ), admin_url( 'admin.php?page=wc-settings&tab=api§ion=keys' ) ) ) );
|
||||||
exit();
|
exit();
|
||||||
|
@ -167,21 +178,26 @@ class WC_Admin_API_Keys {
|
||||||
* Bulk actions.
|
* Bulk actions.
|
||||||
*/
|
*/
|
||||||
private function bulk_actions() {
|
private function bulk_actions() {
|
||||||
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
|
check_admin_referer( 'woocommerce-settings' );
|
||||||
wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
|
|
||||||
|
if ( ! current_user_can( 'manage_woocommerce' ) ) {
|
||||||
|
wp_die( esc_html__( 'You do not have permission to edit API Keys', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$keys = array_map( 'absint', (array) $_GET['key'] );
|
if ( isset( $_GET['action'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
|
$action = sanitize_text_field( wp_unslash( $_GET['action'] ) ); // WPCS: input var okay, CSRF ok.
|
||||||
|
$keys = isset( $_GET['key'] ) ? array_map( 'absint', (array) $_GET['key'] ) : array(); // WPCS: input var okay, CSRF ok.
|
||||||
|
|
||||||
if ( 'revoke' == $_GET['action'] ) {
|
if ( 'revoke' === $action ) {
|
||||||
$this->bulk_revoke_key( $keys );
|
$this->bulk_revoke_key( $keys );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk revoke key.
|
* Bulk revoke key.
|
||||||
*
|
*
|
||||||
* @param array $keys
|
* @param array $keys API Keys.
|
||||||
*/
|
*/
|
||||||
private function bulk_revoke_key( $keys ) {
|
private function bulk_revoke_key( $keys ) {
|
||||||
foreach ( $keys as $key_id ) {
|
foreach ( $keys as $key_id ) {
|
||||||
|
@ -192,7 +208,7 @@ class WC_Admin_API_Keys {
|
||||||
/**
|
/**
|
||||||
* Remove key.
|
* Remove key.
|
||||||
*
|
*
|
||||||
* @param int $key_id
|
* @param int $key_id API Key ID.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function remove_key( $key_id ) {
|
private function remove_key( $key_id ) {
|
||||||
|
|
|
@ -2,15 +2,11 @@
|
||||||
/**
|
/**
|
||||||
* Setup menus in WP admin.
|
* Setup menus in WP admin.
|
||||||
*
|
*
|
||||||
* @author Automattic
|
* @package WooCommerce\Admin
|
||||||
* @category Admin
|
* @version 2.5.0
|
||||||
* @package WooCommerce/Admin
|
|
||||||
* @version 2.5.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( class_exists( 'WC_Admin_Menus', false ) ) {
|
if ( class_exists( 'WC_Admin_Menus', false ) ) {
|
||||||
return new WC_Admin_Menus();
|
return new WC_Admin_Menus();
|
||||||
|
@ -39,6 +35,7 @@ class WC_Admin_Menus {
|
||||||
add_action( 'admin_head', array( $this, 'menu_order_count' ) );
|
add_action( 'admin_head', array( $this, 'menu_order_count' ) );
|
||||||
add_filter( 'menu_order', array( $this, 'menu_order' ) );
|
add_filter( 'menu_order', array( $this, 'menu_order' ) );
|
||||||
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
|
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
|
||||||
|
add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
|
||||||
|
|
||||||
// Add endpoints custom URLs in Appearance > Menus > Pages.
|
// Add endpoints custom URLs in Appearance > Menus > Pages.
|
||||||
add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
|
add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
|
||||||
|
@ -69,9 +66,9 @@ class WC_Admin_Menus {
|
||||||
*/
|
*/
|
||||||
public function reports_menu() {
|
public function reports_menu() {
|
||||||
if ( current_user_can( 'manage_woocommerce' ) ) {
|
if ( current_user_can( 'manage_woocommerce' ) ) {
|
||||||
add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ) , 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
|
add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
|
||||||
} else {
|
} else {
|
||||||
add_menu_page( __( 'Sales reports', 'woocommerce' ), __( 'Sales reports', 'woocommerce' ) , 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ), null, '55.6' );
|
add_menu_page( __( 'Sales reports', 'woocommerce' ), __( 'Sales reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ), null, '55.6' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +76,7 @@ class WC_Admin_Menus {
|
||||||
* Add menu item.
|
* Add menu item.
|
||||||
*/
|
*/
|
||||||
public function settings_menu() {
|
public function settings_menu() {
|
||||||
$settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ) , 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) );
|
$settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ), 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) );
|
||||||
|
|
||||||
add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
|
add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
|
||||||
}
|
}
|
||||||
|
@ -113,13 +110,15 @@ class WC_Admin_Menus {
|
||||||
if ( ! empty( $_GET['wc_message'] ) ) { // WPCS: input var okay, CSRF ok.
|
if ( ! empty( $_GET['wc_message'] ) ) { // WPCS: input var okay, CSRF ok.
|
||||||
WC_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['wc_message'] ) ) ); // WPCS: input var okay, CSRF ok.
|
WC_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['wc_message'] ) ) ); // WPCS: input var okay, CSRF ok.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_action( 'woocommerce_settings_page_init' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add menu item.
|
* Add menu item.
|
||||||
*/
|
*/
|
||||||
public function status_menu() {
|
public function status_menu() {
|
||||||
add_submenu_page( 'woocommerce', __( 'WooCommerce status', 'woocommerce' ), __( 'Status', 'woocommerce' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
|
add_submenu_page( 'woocommerce', __( 'WooCommerce status', 'woocommerce' ), __( 'Status', 'woocommerce' ), 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,6 +219,21 @@ class WC_Admin_Menus {
|
||||||
return current_user_can( 'manage_woocommerce' );
|
return current_user_can( 'manage_woocommerce' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate screen options on update.
|
||||||
|
*
|
||||||
|
* @param bool|int $status Screen option value. Default false to skip.
|
||||||
|
* @param string $option The option name.
|
||||||
|
* @param int $value The number of rows to use.
|
||||||
|
*/
|
||||||
|
public function set_screen_option( $status, $option, $value ) {
|
||||||
|
if ( in_array( $option, array( 'woocommerce_keys_per_page', 'woocommerce_webhooks_per_page' ), true ) ) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the reports page.
|
* Init the reports page.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,18 +2,14 @@
|
||||||
/**
|
/**
|
||||||
* WooCommerce Webhooks Table List
|
* WooCommerce Webhooks Table List
|
||||||
*
|
*
|
||||||
* @author Automattic
|
* @package WooCommerce\Admin
|
||||||
* @category Admin
|
* @version 3.3.0
|
||||||
* @package WooCommerce/Admin
|
|
||||||
* @version 3.3.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit; // Exit if accessed directly.
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! class_exists( 'WP_List_Table' ) ) {
|
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';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +28,13 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No items found text.
|
||||||
|
*/
|
||||||
|
public function no_items() {
|
||||||
|
esc_html_e( 'No webhooks found.', 'woocommerce' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list columns.
|
* Get list columns.
|
||||||
*
|
*
|
||||||
|
@ -244,15 +247,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
|
||||||
* Prepare table list items.
|
* Prepare table list items.
|
||||||
*/
|
*/
|
||||||
public function prepare_items() {
|
public function prepare_items() {
|
||||||
$per_page = absint( apply_filters( 'woocommerce_webhooks_settings_posts_per_page', 10 ) );
|
$per_page = $this->get_items_per_page( 'woocommerce_webhooks_per_page' );
|
||||||
$per_page = 0 === $per_page ? 10 : $per_page;
|
|
||||||
$columns = $this->get_columns();
|
|
||||||
$hidden = array();
|
|
||||||
$sortable = $this->get_sortable_columns();
|
|
||||||
|
|
||||||
// Column headers.
|
|
||||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
|
||||||
|
|
||||||
$current_page = $this->get_pagenum();
|
$current_page = $this->get_pagenum();
|
||||||
|
|
||||||
// Query args.
|
// Query args.
|
||||||
|
@ -278,7 +273,7 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
|
||||||
// Get total items.
|
// Get total items.
|
||||||
$args['limit'] = -1;
|
$args['limit'] = -1;
|
||||||
$args['offset'] = 0;
|
$args['offset'] = 0;
|
||||||
$total_items = count( $data_store->search_webhooks( $args ) );
|
$total_items = count( $data_store->search_webhooks( $args ) );
|
||||||
|
|
||||||
// Set the pagination.
|
// Set the pagination.
|
||||||
$this->set_pagination_args( array(
|
$this->set_pagination_args( array(
|
||||||
|
|
|
@ -2,15 +2,11 @@
|
||||||
/**
|
/**
|
||||||
* WooCommerce Admin Webhooks Class
|
* WooCommerce Admin Webhooks Class
|
||||||
*
|
*
|
||||||
* @author Automattic
|
* @package WooCommerce\Admin
|
||||||
* @category Admin
|
* @version 3.3.0
|
||||||
* @package WooCommerce/Admin
|
|
||||||
* @version 3.3.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
defined( 'ABSPATH' ) || exit;
|
||||||
exit; // Exit if accessed directly.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Admin_Webhooks.
|
* WC_Admin_Webhooks.
|
||||||
|
@ -21,8 +17,9 @@ class WC_Admin_Webhooks {
|
||||||
* Initialize the webhooks admin actions.
|
* Initialize the webhooks admin actions.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
add_action( 'woocommerce_save_settings_api_webhooks', array( $this, 'allow_save_settings' ) );
|
|
||||||
add_action( 'admin_init', array( $this, 'actions' ) );
|
add_action( 'admin_init', array( $this, 'actions' ) );
|
||||||
|
add_action( 'woocommerce_settings_page_init', array( $this, 'screen_option' ) );
|
||||||
|
add_filter( 'woocommerce_save_settings_api_webhooks', array( $this, 'allow_save_settings' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,10 +266,29 @@ class WC_Admin_Webhooks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add screen option.
|
||||||
|
*/
|
||||||
|
public function screen_option() {
|
||||||
|
global $webhooks_table_list;
|
||||||
|
|
||||||
|
if ( ! isset( $_GET['edit-webhook'] ) && $this->is_webhook_settings_page() ) { // WPCS: input var okay, CSRF ok.
|
||||||
|
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
|
||||||
|
|
||||||
|
// Add screen option.
|
||||||
|
add_screen_option( 'per_page', array(
|
||||||
|
'default' => 10,
|
||||||
|
'option' => 'woocommerce_webhooks_per_page',
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table list output.
|
* Table list output.
|
||||||
*/
|
*/
|
||||||
private static function table_list_output() {
|
private static function table_list_output() {
|
||||||
|
global $webhooks_table_list;
|
||||||
|
|
||||||
echo '<h2>' . esc_html__( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=0' ) ) . '" class="add-new-h2">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
|
echo '<h2>' . esc_html__( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=0' ) ) . '" class="add-new-h2">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
|
||||||
|
|
||||||
// Get the webhooks count.
|
// Get the webhooks count.
|
||||||
|
@ -280,7 +296,6 @@ class WC_Admin_Webhooks {
|
||||||
$count = count( $data_store->get_webhooks_ids() );
|
$count = count( $data_store->get_webhooks_ids() );
|
||||||
|
|
||||||
if ( 0 < $count ) {
|
if ( 0 < $count ) {
|
||||||
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
|
|
||||||
$webhooks_table_list->prepare_items();
|
$webhooks_table_list->prepare_items();
|
||||||
|
|
||||||
echo '<input type="hidden" name="page" value="wc-settings" />';
|
echo '<input type="hidden" name="page" value="wc-settings" />';
|
||||||
|
@ -295,9 +310,8 @@ class WC_Admin_Webhooks {
|
||||||
?>
|
?>
|
||||||
<h2 class="woocommerce-BlankState-message"><?php esc_html_e( 'Webhooks are event notifications sent to URLs of your choice. They can be used to integrate with third-party services which support them.', 'woocommerce' ); ?></h2>
|
<h2 class="woocommerce-BlankState-message"><?php esc_html_e( 'Webhooks are event notifications sent to URLs of your choice. They can be used to integrate with third-party services which support them.', 'woocommerce' ); ?></h2>
|
||||||
<a class="woocommerce-BlankState-cta button-primary button" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=0' ) ); ?>"><?php esc_html_e( 'Create a new webhook', 'woocommerce' ); ?></a>
|
<a class="woocommerce-BlankState-cta button-primary button" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks&edit-webhook=0' ) ); ?>"><?php esc_html_e( 'Create a new webhook', 'woocommerce' ); ?></a>
|
||||||
|
<style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions { display: none; }</style>
|
||||||
<?php
|
<?php
|
||||||
echo '<style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions { display: none; } </style></div>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
<rule ref="WordPress">
|
<rule ref="WordPress">
|
||||||
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching" />
|
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching" />
|
||||||
|
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery" />
|
||||||
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
|
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
|
||||||
<exclude name="WordPress.VIP.FileSystemWritesDisallow.file_ops_fwrite" />
|
<exclude name="WordPress.VIP.FileSystemWritesDisallow.file_ops_fwrite" />
|
||||||
<exclude name="WordPress.VIP.OrderByRand" />
|
<exclude name="WordPress.VIP.OrderByRand" />
|
||||||
|
|
|
@ -4,13 +4,11 @@
|
||||||
*
|
*
|
||||||
* Uninstalling WooCommerce deletes user roles, pages, tables, and options.
|
* Uninstalling WooCommerce deletes user roles, pages, tables, and options.
|
||||||
*
|
*
|
||||||
* @package WooCommerce/Uninstaller
|
* @package WooCommerce\Uninstaller
|
||||||
* @version 2.3.0
|
* @version 2.3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
global $wpdb, $wp_version;
|
global $wpdb, $wp_version;
|
||||||
|
|
||||||
|
@ -26,8 +24,9 @@ wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );
|
||||||
* and to ensure only the site owner can perform this action.
|
* and to ensure only the site owner can perform this action.
|
||||||
*/
|
*/
|
||||||
if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
|
if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
|
||||||
// Roles + caps.
|
|
||||||
include_once dirname( __FILE__ ) . '/includes/class-wc-install.php';
|
include_once dirname( __FILE__ ) . '/includes/class-wc-install.php';
|
||||||
|
|
||||||
|
// Roles + caps.
|
||||||
WC_Install::remove_roles();
|
WC_Install::remove_roles();
|
||||||
|
|
||||||
// Pages.
|
// Pages.
|
||||||
|
@ -52,6 +51,9 @@ if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
|
||||||
// Delete options.
|
// Delete options.
|
||||||
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce\_%';" );
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce\_%';" );
|
||||||
|
|
||||||
|
// Delete usermeta.
|
||||||
|
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'woocommerce\_%';" );
|
||||||
|
|
||||||
// Delete posts + data.
|
// Delete posts + data.
|
||||||
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" );
|
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" );
|
||||||
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
|
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
|
||||||
|
|
Loading…
Reference in New Issue