List Tables
If the menu type is list_table
, the administration menu callback defines the list table instead of the menu page. The list table callback involves defining and returning an array consisting of strings, arrays or callbacks. You can also use callbacks in the list table definition for dynamic strings or arrays.
The documentation is based on Cars sample dataset.
function saturn_tables_cars_list_table_func($page = "", $item = array(), $page_number = 1) { /* BASED ON CARS DATA SET */ /* STANDARD LIST TABLE DEFINITIONS */ $add_new_link = admin_url("/admin.php/?page=my-cars-add-edit-car&id=0"); $list_table_definitions['menu_title'] = '<h1 class="wp-heading-inline">View Cars</h1><a href="' . $add_new_link . '" class="page-title-action">Add New</a>'; $list_table_definitions['notices'] = 'saturn_tables_cars_admin_notices'; $list_table_definitions['header'] = '<p>The cars database is a short list of car information.</p>' ; $list_table_definitions['columns'] = array('cb' => '<input type="checkbox" />', 'make' => "Make", 'model' => "Model", 'mpg' => "MPG", 'cylinders' => "Cylinders", 'weight' => "Weight", 'model_year' => "Model Year", 'country' => "Country"); $list_table_definitions['get_data'] = 'saturn_tables_cars_return_items'; $list_table_definitions['get_data_count'] = 'saturn_tables_cars_return_items_count'; /* LIST TABLE ACTION DEFINITION VALUES */ $list_table_definitions['column_markup'] = call_user_func('saturn_tables_cars_list_table_markup', $page, $item, $page_number); $list_table_definitions['link_actions'] = call_user_func('saturn_tables_cars_list_table_actions', $page, $item, $page_number); $list_table_definitions['process_link_actions'] = 'saturn_tables_cars_process_link_actions'; $list_table_definitions['checkbox_id'] = 'id' ; $list_table_definitions['bulk_actions'] = isset($_GET['status']) && ($_GET['status'] == "trash") ? array( 'bulk_delete' => 'Delete' ) : array( 'bulk_trash' => 'Trash' ); $list_table_definitions['process_bulk_actions'] = 'saturn_tables_cars_process_bulk_actions'; /* EXTRA LIST TABLE DEFINITION VALUES */ $list_table_definitions['views'] = call_user_func("saturn_tables_cars_views"); $list_table_definitions['search'] = array('label'=> "Search Make and Model", 'id' => "search_id"); $list_table_definitions['extra_navigation'] = "saturn_tables_cars_make_dropdown"; $list_table_definitions['filter_button'] = array('text' => "Filter By Make"); $list_table_definitions['sortable'] = array( 'make' => array( 'make', true ), 'model' => array( 'model', false ) ); $list_table_definitions['footer'] = '<p>Powered by <a href="https://saturntables.com/" target="_blank" rel="noopener noreferrer">Saturn Tables</a></p>'; return $list_table_definitions; }