For the complete documentation index, see llms.txt. This page is also available as Markdown.

save_acpt_table

Create or update a custom table definition

Create or update a custom table definition.

Performs an upsert: if a table with the given name already exists its id is reused, so calling this function twice with the same name is safe. This function only saves the metadata — it does not create or alter the physical database table. Call sync_acpt_table() afterwards to apply the schema.

Usage

// Minimal example
save_acpt_table([
    'name'  => 'products',
    'label' => 'Products',
]);

// Full example with columns, ID strategy, and REST API exposure
save_acpt_table([
    'name'         => 'products',
    'label'        => 'Products',
    'idStrategy'   => 'auto_increment',
    'restApi'      => ['read', 'create', 'update', 'delete'],
    'icon'         => 'dashicons-cart',
    'menuPosition' => 25,
    'capability'   => 'manage_options',
    'timestamps'   => true,
    'softDelete'   => false,
    'columns'      => [
        [
            'name'    => 'title',
            'uiType'  => 'Text',
        ],
        [
            'name'    => 'price',
            'uiType'  => 'Currency',
        ],
        [
            'name'   => 'notes',
            'type'   => 'TEXT',
            'length' => '',
        ],
    ],
]);

Parameters

Parameter
Type
Required
Description

name

string

Required

Machine name (slug) of the table

label

string

Optional

Human-readable label shown in the admin menu

idStrategy

string

Optional

Primary key strategy: none, auto_increment, UUID, or ULID

restApi

array

Optional

REST API operations to expose: read, create, update, delete

icon

string

Optional

Dashicon slug for the admin menu entry (e.g. dashicons-cart)

menuPosition

int

Optional

Admin menu position number

capability

string

Optional

WordPress capability required to access the table in the admin

timestamps

bool

Optional

Automatically add created_at and updated_at columns

softDelete

bool

Optional

Automatically add a deleted_at column for soft deletes

columns

array

Optional

Array of column definitions — see column fields below

indexes

array

Optional

Array of index definitions

foreignKeys

array

Optional

Array of foreign key definitions

location

array

Optional

Array of location rule definitions controlling where the table appears

Column definition fields

Field
Type
Description

name

string

Column name

uiType

string

UI type slug (e.g. Text, Number, Currency). Drives type and length automatically

type

string

MySQL column type (e.g. VARCHAR, INT, TEXT). Overrides the value derived from uiType

length

string

MySQL column length (e.g. 255). Overrides the value derived from uiType

Return

Type
Description

bool

true on success, false on failure or unrecognised uiType

Last updated