From 018da951ce20f3a865db5db6db8d7d63fe7f873a Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Tue, 6 Feb 2018 01:30:12 +0545 Subject: [PATCH] Save and use the per page screen option value for API Keys --- .../class-wc-admin-api-keys-table-list.php | 8 +++----- includes/admin/class-wc-admin-api-keys.php | 20 ++++++++++++++----- includes/admin/class-wc-admin-menus.php | 2 +- includes/admin/class-wc-admin-webhooks.php | 4 +--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/includes/admin/class-wc-admin-api-keys-table-list.php b/includes/admin/class-wc-admin-api-keys-table-list.php index b4df72c7fa4..a521d560b9d 100644 --- a/includes/admin/class-wc-admin-api-keys-table-list.php +++ b/includes/admin/class-wc-admin-api-keys-table-list.php @@ -2,10 +2,8 @@ /** * WooCommerce API Keys Table List * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin - * @version 2.4.0 + * @package WooCommerce\Admin + * @version 2.4.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -177,7 +175,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table { public function prepare_items() { global $wpdb; - $per_page = apply_filters( 'woocommerce_api_keys_settings_items_per_page', 10 ); + $per_page = $this->get_items_per_page( 'wc_api_keys_per_page' ); $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); diff --git a/includes/admin/class-wc-admin-api-keys.php b/includes/admin/class-wc-admin-api-keys.php index 6df9aa252ea..9f58f307070 100644 --- a/includes/admin/class-wc-admin-api-keys.php +++ b/includes/admin/class-wc-admin-api-keys.php @@ -2,10 +2,8 @@ /** * WooCommerce Admin API Keys Class * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin - * @version 2.4.0 + * @package WooCommerce\Admin + * @version 2.4.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -22,6 +20,7 @@ class WC_Admin_API_Keys { */ public function __construct() { add_action( 'admin_init', array( $this, 'actions' ) ); + add_action( 'woocommerce_settings_page_init', array( $this, 'screen_option' ) ); } /** @@ -54,11 +53,22 @@ class WC_Admin_API_Keys { } } + /** + * Add screen option. + */ + public function screen_option() { + if ( ! isset( $_GET['create-key'], $_GET['edit-key'] ) && $this->is_api_keys_settings_page() ) { + add_screen_option( 'per_page', array( + 'default' => 10, + 'option' => 'wc_api_keys_per_page', + ) ); + } + } + /** * Table list output. */ private static function table_list_output() { - global $wpdb; echo '

' . __( 'Keys/Apps', 'woocommerce' ) . ' ' . __( 'Add key', 'woocommerce' ) . '

'; diff --git a/includes/admin/class-wc-admin-menus.php b/includes/admin/class-wc-admin-menus.php index be5ff753294..b67f65810ec 100644 --- a/includes/admin/class-wc-admin-menus.php +++ b/includes/admin/class-wc-admin-menus.php @@ -229,7 +229,7 @@ class WC_Admin_Menus { * @param int $value The number of rows to use. */ public function set_screen_option( $status, $option, $value ) { - if ( in_array( $option, array( 'wc_webhooks_per_page' ), true ) ) { + if ( in_array( $option, array( 'wc_webhooks_per_page', 'wc_api_keys_per_page' ), true ) ) { return $value; } diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index 098e53059b0..92e5c1a75c3 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -272,11 +272,9 @@ 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() ) { add_screen_option( 'per_page', array( - 'default' => 20, + 'default' => 10, 'option' => 'wc_webhooks_per_page', ) ); }