Make WordPress Core

Ticket #64796: dummy-list-table.php

File dummy-list-table.php, 1.3 KB (added by johnbillion, 2 months ago)

Dummy list table plugin

Line 
1<?php
2/**
3 * Plugin Name: Dummy List Table
4 * Description: Minimal list table example with extra_tablenav button.
5 */
6
7add_action( 'admin_menu', function() {
8        add_management_page(
9                'Dummy List Table',
10                'Dummy List Table',
11                'manage_options',
12                'dummy-list-table',
13                function() {
14                        $table = new Dummy_List_Table();
15                        $table->prepare_items();
16                        echo '<div class="wrap">';
17                        echo '<h1>Dummy List Table</h1>';
18                        echo '<form method="post">';
19                        $table->display();
20                        echo '</form>';
21                        echo '</div>';
22                }
23        );
24} );
25
26add_action( 'admin_init', function() {
27        class Dummy_List_Table extends WP_List_Table {
28                public function get_columns() {
29                        return array(
30                                'title' => 'Title',
31                                'value' => 'Value',
32                        );
33                }
34
35                public function prepare_items() {
36                        $this->_column_headers = array( $this->get_columns(), array(), array() );
37                        $this->items = array(
38                                array( 'title' => 'Item One', 'value' => 'Alpha' ),
39                                array( 'title' => 'Item Two', 'value' => 'Beta' ),
40                                array( 'title' => 'Item Three', 'value' => 'Gamma' ),
41                        );
42                }
43
44                protected function column_default( $item, $column_name ) {
45                        return esc_html( $item[ $column_name ] );
46                }
47
48                protected function extra_tablenav( $which ) {
49                        printf(
50                                '<button class="button" type="submit" name="dummy_action" value="export">%s</button>',
51                                esc_html( 'Export' )
52                        );
53                }
54        }
55} );