Word press management table or list table is widely used in the management field to list posts, pages, users, etc. If you want to add a list table containing your own data to your plug-in, WordPress provides a great way to do this using the wp\u list\u table class. This article describes how to use the WordPress API to add a management table or list table, such as WordPress, to the management screen of a plug-in. WordPress list tables are used almost everywhere on the dashboard. It is used to display posts, pages, users, comments, etc., and can also be found in many popular plug-ins. Over the years, it has become the de facto standard for word press to display tabular information. The
Note: this document is applicable to intermediate word press developers. Before continuing, you need to have a hands-on knowledge of WordPress, PHP, and the WordPress plug-in API. If you are unsure or want to refresh, it is recommended that you read the following: WordPress development for beginners: start WordPress development for beginners: WordPress development for beginners with components and menus: plug-in construction advanced WordPress development: introduction to object-oriented programming this article creates a self-defined management table with the help of plug-ins with object-oriented structure. The plug-in can be ed from here and follow up the article. But before entering the content, let’s first understand what admin tables actually does. The
I will also use the terms admin tables and list tables for the rest of the article. WordPress manage forms – has interacted with the administrator forms when the background dashboard accesses pages such as posts and users. The WordPress management table is implemented using the class \/wp-admin\/includes\/class-wp-list-table in wp\u list\u table. PHP Provides a framework for displaying information in tabular form and visually manipulating data. The following is an overview of common word press management forms: The
The WordPress management table allows you to view familiar batch jobs, row jobs with hover links, paging, and screen options. Since then, all these features have been an essential part of WordPress. Wp\u list\u table of screen options works directly on wp\u list\u table. By limiting the information displayed on the page, you can control column visibility and pagination. If you use WordPress to manage tables, the method provided by the WordPress API to build default list tables does not have to be used. In my opinion, the biggest factor in deciding to use the admin tables provided by WordPress should be the user experience. Using the wp_list_table class, word press handles table UI style assignments. The familiarity, basic appearance and feeling of the operation of admin tables (WordPress as a whole) really help users interact with table data in a smooth way. The
Since wp\u list\u table class analyzed word press version 3.1.0, wp\u list\u table class has become more and more popular among developers. The word press Codex class reference for wp_list_table provides comprehensive information about methods, properties, and usage. The following inpograph briefly shows the building blocks in the management table in the class reference. ‹ wp_list_table’s building block more complex management tables show \
At the top of the table are additional drop-down filters and task links, such as those used in. The
Now, for the admin table and wp\u list\u table classes, we will learn about wp\u list\u table, which uses this knowledge as help for custom plug-ins. Before entering the implementation details of the custom list table plug-in list tables for user meta operations, we will briefly introduce the custom plug-in prepared for this article. You can and imitate it here. It is recommended that you open it in the appropriate editor and install it only in the locally developed word press settings. The plug-in was originally based on the in fork plug-in template of the WordPress plugin boilerplate project. Similar to the original project in many ways, but also supports namespaces and automatic loading. This eliminates the need to have a unique prefix for all classes or functions, and does not end with many include and require statements. But the minimum version of PHP required for my plug-in is 5.6.0. The
Most of us will use the files in the next directory of the plug-in. Inc\/core\/* – the core function of the plug-in inc\/admin\/* – freely configure the plug-in according to its own coding and layout preferences of the plug-in reference library to display the list table in the management area. I like to use the common sentence starting point of one of the many best practices listed in the word press plug-in manual. Objective to customize the plug-in to display all word press users registered in their own management tables. These management tables control screen options, pagination and row operation links to perform operations on user metadata. Each line of action is linked to the plug-in page that performs those actions. The
Since you can use user_row_actions to add functionality to the default word press user page, this use case is obviously not ideal. However, it is intended to implement list tables from scratch. Here we go. To create a wp\u list\u table class inheritance management table, you must define a subclass in the plug-in that extends the core wp\u list\u table class provided by WordPress. Therefore, the first thing to do is the class WP list table under \/wp admin \/ include \/. Copy the PHP file to the plug-in. It is strongly recommended to use the core class because it is proprietary and potential changes to the class or method by word press will not interrupt the plug-in. The
I copied an inc\/library file from my plug-in and added the namespace directive. If you do not use namespaces, you must prefix all items. Copy the WP list table class file, and then expand the inc\/admin\/class user list table of the default wp\u list\u table class under the inc\/library folder of the plug-in. Defines the PHP subclass user_list_table in PHP. Key points during the loading of nstudio\/1a20f5773972973e11cf8d1cf7d02786, the above snipt is a bare metal implementation with two methods that need to be redefined. Obviously, there is a lot of work to be done in subclasses, but I want to start by rendering the empty list table. The
In this step, you can choose to add the creator and other methods to the subclass. However, you prefer to render the empty list table first. I found that this top-down method can see the output of the list table in each step, so it is very effective and can eliminate possible errors more easily. List table
Rendering usually requires the following three steps: Before rendering the sublist table class to instantiate the table, call prepare_items() call display() to handle data preparation – perform the actual rendering of the table. Both methods move the wheels. So let’s take a look at where and how the plug-in calls these methods. The
The add plug-in menu page plug-in contains a submenu page that displays a custom user list table under users. To see how to add a menu page or user submenu page in the list table, check a, and then use the define_admin_hooks() method inc\/core\/class-init. PHP and add\u plugin\admin\menu() methods inc\/admin\/class-admin. PHP plug-in. Please pay attention to the important points nuance designstudio\/449e2abbbc804ef22ac5a09a7c2a4b3: the callback of add\users\u page() load\user\list\u table(). The prepare_items() and display() methods are called. However, the page mounted callback load\u user\u list\u table\u screen\u options() is instantiating subclasses. After the plug-in page is run before loading and my subclass instance is created in it, WordPress can automatically add the columns in the list table to the on-screen option panel. Will be added to the screen option that controls the paging of the list table. Load summary nuncesignstudio\/175725cb497860f657dfba58ccf must also wrap display() in HTML format to take advantage of the same functionality as batch operations. I prefer not to mix HTML. This is the partials WP list table demo display of the method I finally called with the include_once instruction. This is why PHP is loaded. When opening the plug-in page from the load summary nuncesignstudio\/ff386ed565aee2039719f3353dd0e152 beiben list table setting confirmation user menu, WordPress noticed that the list table was being requested. No data was provided here, so \
If the post lookup list of is well configured, the code required to fill the data in the database into the list table is added to prepare\u items(). Wp\u list\u table::prepare\u items() table data must provide its own prepare\u items() implementation. This method must be called explicitly before rendering the table. Therefore, all data related operations (such as import, sorting, paging, filtering, etc.) must be processed here before the table can be displayed. To load the table data, fetch_table_data() queries the WordPress database and saves the results in an array before assigning them to the items variable of the parent class. Load summary nuncesignstudio\/baa43ea0882c5aeb6d5173053470e927, but this is not enough to display data in the table. To complete the display, you must also provide a column_* () implementation using the column_* () method. The get\u columns() method on wp\u list\u table::column\u default() provides column logs for each column. These tracers can be used to identify single column analysis methods. Although it is a good idea to provide column specific methods for each column, you can simply use the column_default () method. The wp\u list\u table class defaults to column\u default (), unless the wp\u list\u table method is found. Load the summary nuncesignstudio\/323a50f39743617ae29f0aafbad1 to render the columns. You can view the data in my list table. After adding column\u default() method, if you want to use batch operation to process wp\u list\u table::column\u cb() rows that list table data, you must also provide the implementation of column\u cb() method, especially column\u cb(). Load summary nuncesignstudio\/112d1afec60fb6792753700750153852 renders check boxes for all rows in my list table. The value of the checkbox field must be unique, such as user_login or ID, to distinguish records. We then added support for sorting and paging to the list tables. You can sort the columns specified in the list table by redefining the sorting using wp_list_table::get\u sortable \u columns(). But in fact, the code for sorting data must be written in prepare_items(). In my example, when importing data from fetch_table_data(), the SQL itself performs sorting. When sorting columns in the nuance designstudio\/4a72ddc7d9b4ba34fb90f43b4e0dce53 load, this reference can be used through superglobals$\u get[\
Search box, batch operation and row operation are added to the table. To add a wp_list_table::search_box() search box, you must wrap the hidden fields and form together and submit them to the plug-in page. Before display (), I set its partials WP list table demo display. PHP Data processing for search is completed in prepare\u items(). Key points during the loading process of the fine design studio\/095 bd1c1dd8c0d64f908806d85a3f748, if you perform additional search in the search box on the list table, you can use the search key through the super global $\u request[\