Make WordPress Core

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

File my-list-table-plugin.2.php, 840 bytes (added by bgoewert, 2 years ago)

Updated example plugin for table list class

Line 
1<?php
2/*
3Plugin Name: My List Table Plugin
4Author: scribu
5Version: 2.0
6*/
7
8class 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
39new My_Admin_Screen();
40