/** * Prepares the list of items for displaying * * This is where you prepare your data for display. This method will usually * be used to query the database, sort and filter the data, and generally * get it ready to be displayed. At a minimum, we should set $this->items and * $this->set_pagination_args(). * * @since 0.1 * * @return void */ function prepare_items() { $this->_column_headers = array($this->get_columns(), $this->get_hidden_columns(), $this->get_sortable_columns()); /* * REQUIRED for pagination. */ $user = get_current_user_id(); $screen = get_current_screen(); $option = $screen->get_option('per_page', 'option'); $per_page = get_user_meta($user, $option, true); if (empty($per_page) || $per_page < 1) { $per_page = $screen->get_option('per_page', 'default'); } // $current_page = $this->get_pagenum(); $current_page = isset($_REQUEST['paged']) ? absint($_REQUEST['paged']) : 1; /* * REQUIRED. Assign sorted and paginated data to the items property, where * it can be used by the rest of the class. */ $total_items = MLAData::mla_count_list_table_items($_REQUEST, ($current_page - 1) * $per_page, $per_page); $this->items = MLAData::mla_query_list_table_items($_REQUEST, ($current_page - 1) * $per_page, $per_page); /* * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
/** * Prepares the list of items for displaying * * This is where you prepare your data for display. This method will usually * be used to query the database, sort and filter the data, and generally * get it ready to be displayed. At a minimum, we should set $this->items and * $this->set_pagination_args(). * * @since 0.1 */ function prepare_items() { // Initialize $this->_column_headers $this->get_column_info(); /* * Calculate and filter pagination arguments. */ $user = get_current_user_id(); $option = $this->screen->get_option('per_page', 'option'); $per_page = (int) get_user_meta($user, $option, true); if (empty($per_page) || $per_page < 1) { $per_page = (int) $this->screen->get_option('per_page', 'default'); } $current_page = isset($_REQUEST['paged']) ? absint($_REQUEST['paged']) : 1; $pagination = apply_filters_ref_array('mla_list_table_prepare_items_pagination', array(compact(array('per_page', 'current_page')), &$this)); $per_page = isset($pagination['per_page']) ? $pagination['per_page'] : $per_page; $current_page = isset($pagination['current_page']) ? $pagination['current_page'] : $current_page; /* * Assign sorted and paginated data to the items property, where * it can be used by the rest of the class. */ $total_items = apply_filters_ref_array('mla_list_table_prepare_items_total_items', array(NULL, &$this)); if (is_null($total_items)) { $total_items = MLAData::mla_count_list_table_items($_REQUEST, ($current_page - 1) * $per_page, $per_page); } /* * Register the pagination options & calculations. */ $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); $this->items = apply_filters_ref_array('mla_list_table_prepare_items_the_items', array(NULL, &$this)); if (is_null($this->items)) { $this->items = MLAData::mla_query_list_table_items($_REQUEST, ($current_page - 1) * $per_page, $per_page); } do_action_ref_array('mla_list_table_prepare_items', array(&$this)); }