0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Empty Minimal WP_List_Table Examples

Posted at

function WP_List_Table::prepare_items() must be overridden in a subclass.

image.png

<?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.

image.png

image.png

<?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()を呼び出さない場合

image.png

image.png

<?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.

image.png

image.png

<?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');

完成

image.png

image.png

<?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');

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?