eighteen73/custom-tables-api

这是一个用于通过更简单的API注册WordPress自定义表CRUD页面的辅助库。

dev-main 2024-05-03 09:43 UTC

This package is auto-updated.

Last update: 2024-09-03 10:24:38 UTC


README

通过使用面向对象的方法,简化自定义表CRUD页面的创建。

示例

use Eighteen73\CustomTablesApi\CustomTablesApi;

$custom_table = new CustomTablesApi(
	'my_custom_table',
	'My Custom Table Data',
	[
		'id' => [
			'type' => 'bigint',
			'length' => '20',
			'auto_increment' => true,
			'primary_key' => true,
		],
		'title' => [
			'type' => 'varchar',
			'length' => '50',
		],
		'status' => [
			'type' => 'varchar',
			'length' => '50',
		],
		'date' => [
			'type' => 'datetime',
		]
	],
	1,
	[
		'title' => [
			'label' => __( 'Title' ),
			'sortable' => 'title', // ORDER BY title ASC
		],
		'status' => [
			'label' => __( 'Status' ),
			'sortable' => [ 'status', false ], // ORDER BY status ASC
		],
		'date' => [
			'label' => __( 'Date' ),
			'sortable' => [ 'date', true ], // ORDER BY date DESC
		],
	]
);

add_action( 'ct_init', [ $custom_table, 'init' ] );

致谢

主要基于Ruben Garcia的CT