Load list tables before columns are rendered in screen option

This commit is contained in:
Shiva Poudel 2018-02-06 01:35:16 +05:45
parent 018da951ce
commit 5c991a6929
2 changed files with 13 additions and 3 deletions

View File

@ -57,7 +57,12 @@ class WC_Admin_API_Keys {
* Add screen option.
*/
public function screen_option() {
global $keys_table_list;
if ( ! isset( $_GET['create-key'], $_GET['edit-key'] ) && $this->is_api_keys_settings_page() ) {
$keys_table_list = new WC_Admin_API_Keys_Table_List();
// Add screen option.
add_screen_option( 'per_page', array(
'default' => 10,
'option' => 'wc_api_keys_per_page',
@ -69,7 +74,7 @@ class WC_Admin_API_Keys {
* Table list output.
*/
private static function table_list_output() {
global $wpdb;
global $wpdb, $keys_table_list;
echo '<h2>' . __( 'Keys/Apps', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=api&section=keys&create-key=1' ) ) . '" class="add-new-h2">' . __( 'Add key', 'woocommerce' ) . '</a></h2>';
@ -77,7 +82,6 @@ class WC_Admin_API_Keys {
$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1;" );
if ( absint( $count ) && $count > 0 ) {
$keys_table_list = new WC_Admin_API_Keys_Table_List();
$keys_table_list->prepare_items();
echo '<input type="hidden" name="page" value="wc-settings" />';

View File

@ -272,7 +272,12 @@ 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() ) {
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
// Add screen option.
add_screen_option( 'per_page', array(
'default' => 10,
'option' => 'wc_webhooks_per_page',
@ -284,6 +289,8 @@ class WC_Admin_Webhooks {
* 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&section=webhooks&edit-webhook=0' ) ) . '" class="add-new-h2">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
// Get the webhooks count.
@ -291,7 +298,6 @@ class WC_Admin_Webhooks {
$count = count( $data_store->get_webhooks_ids() );
if ( 0 < $count ) {
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
$webhooks_table_list->prepare_items();
echo '<input type="hidden" name="page" value="wc-settings" />';