function WP_List_Table::prepare_items() must be overridden in a subclass.
<?php
/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class My_List_Table extends WP_List_Table
{
}
function my_render_list_page()
{
$myListTable = new My_List_Table();
$myListTable->prepare_items();
$myListTable->display();
}
function my_add_menu_items()
{
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');
function WP_List_Table::get_columns() must be overridden in a subclass.
<?php
/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class My_List_Table extends WP_List_Table
{
public function prepare_items() {
}
}
function my_render_list_page()
{
$myListTable = new My_List_Table();
$myListTable->prepare_items();
$myListTable->display();
}
function my_add_menu_items()
{
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');
No items found.
prepare_items()
を呼び出さない場合
<?php
/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class My_List_Table extends WP_List_Table
{
public function get_columns()
{
}
}
function my_render_list_page()
{
$myListTable = new My_List_Table();
$myListTable->display();
}
function my_add_menu_items()
{
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');
No items found.
<?php
/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class My_List_Table extends WP_List_Table
{
public function prepare_items() {
}
public function get_columns() {
}
}
function my_render_list_page()
{
$myListTable = new My_List_Table();
$myListTable->prepare_items();
$myListTable->display();
}
function my_add_menu_items()
{
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');
完成
<?php
/*
Plugin Name: Hello Dolly
Version: 1.7.2
*/
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class My_List_Table extends WP_List_Table
{
public function prepare_items()
{
$this->items = [
['name' => 'りんご', 'color' => '赤', 'price' => 100],
['name' => 'バナナ', 'color' => '黄', 'price' => 60],
['name' => 'メロン', 'color' => '緑', 'price' => 300],
];
$this->_column_headers = [$this->get_columns()];
}
public function get_columns()
{
return [
'name' => '名前',
'color' => '色',
'price' => '値段'
];
}
public function column_default($item, $column_name)
{
return $item[$column_name];
}
}
function my_render_list_page()
{
$myListTable = new My_List_Table();
$myListTable->prepare_items();
$myListTable->display();
}
function my_add_menu_items()
{
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');