Make WordPress Core

Ticket #15386: my-list-table-plugin.php

File my-list-table-plugin.php, 984 bytes (added by scribu, 14 years ago)

Example plugin that uses list table class

Line 
1<?php
2/*
3Plugin Name: My List Table Plugin
4Author: scribu
5Version: 1.0
6*/
7
8class My_Admin_Screen {
9        function __construct() {
10                add_filter( 'get_list_table_My_List_Table', array( $this, 'register_list_table' ) );
11                add_action( '_admin_menu', array( $this, '_init' ) );
12        }
13
14        function register_list_table( $class ) {
15                require_once dirname( __FILE__ ) . '/my-list-table-class.php';
16
17                return $class;
18        }
19
20        function _init() {
21                $screen_id = add_menu_page( 'Test', 'Test', 'manage_options', 'test', array( $this, 'display' ) );
22
23                add_action( "load-$screen_id", array( $this, '_init_list_table' ) );
24        }
25
26        // The list table class has to be instantiated before screen_meta() is called
27        function _init_list_table() {
28                $this->list_table = get_list_table('My_List_Table');
29        }
30
31        function display() {
32                echo "<div class='wrap'>\n";
33                screen_icon();
34                echo "<h2>Test</h2>\n";
35
36                $this->list_table->prepare_items();
37                $this->list_table->display();
38
39                echo "</div>\n";
40        }
41}
42
43new My_Admin_Screen();
44