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