ActionScheduler_Abstract_ListTable::prepare_items()publicWC 1.0

Prepares the data to feed WP_Table_List.

This has the core for selecting, sorting and filting data. To keep the code simple its logic is split among many methods (get_items_query_*).

Beside populating the items this function will also count all the records that matches the filtering criteria and will do fill the pagination variables.

Method of the class: ActionScheduler_Abstract_ListTable{}

No Hooks.

Return

null. Nothing (null).

Usage

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

ActionScheduler_Abstract_ListTable::prepare_items() code WC 8.7.0

public function prepare_items() {
	global $wpdb;

	$this->process_bulk_action();

	$this->process_row_actions();

	if ( ! empty( $_REQUEST['_wp_http_referer'] && ! empty( $_SERVER['REQUEST_URI'] ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
		// _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter
		wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
		exit;
	}

	$this->prepare_column_headers();

	$limit   = $this->get_items_query_limit();
	$offset  = $this->get_items_query_offset();
	$order   = $this->get_items_query_order();
	$where   = array_filter(
		array(
			$this->get_items_query_search(),
			$this->get_items_query_filters(),
		)
	);
	$columns = '`' . implode( '`, `', $this->get_table_columns() ) . '`';

	if ( ! empty( $where ) ) {
		$where = 'WHERE (' . implode( ') AND (', $where ) . ')';
	} else {
		$where = '';
	}

	$sql = "SELECT $columns FROM {$this->table_name} {$where} {$order} {$limit} {$offset}";

	$this->set_items( $wpdb->get_results( $sql, ARRAY_A ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

	$query_count = "SELECT COUNT({$this->ID}) FROM {$this->table_name} {$where}";
	$total_items = $wpdb->get_var( $query_count ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
	$per_page    = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page );
	$this->set_pagination_args(
		array(
			'total_items' => $total_items,
			'per_page'    => $per_page,
			'total_pages' => ceil( $total_items / $per_page ),
		)
	);
}