WC_Admin_API_Keys_Table_List::prepare_items()publicWC 1.0

Prepare table list items.

Method of the class: WC_Admin_API_Keys_Table_List{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Admin_API_Keys_Table_List = new WC_Admin_API_Keys_Table_List();
$WC_Admin_API_Keys_Table_List->prepare_items();

WC_Admin_API_Keys_Table_List::prepare_items() code WC 9.4.2

public function prepare_items() {
	global $wpdb;

	$per_page     = $this->get_items_per_page( 'woocommerce_keys_per_page' );
	$current_page = $this->get_pagenum();

	if ( 1 < $current_page ) {
		$offset = $per_page * ( $current_page - 1 );
	} else {
		$offset = 0;
	}

	$search = '';

	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.
	$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
	); // WPCS: unprepared SQL ok.

	$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.
	$this->set_pagination_args(
		array(
			'total_items' => $count,
			'per_page'    => $per_page,
			'total_pages' => ceil( $count / $per_page ),
		)
	);
}