Skip to content

Listing Types

Functions for working with inventory types.

See the Type object reference for all methods available on the returned object.


Functions

dms_get_type( string|int $id ): Type

Retrieves a single inventory type by ID or slug.

Parameters

Name Type Default Description
$id string\|int - The type ID or its slug

Returns - Type

Example

// By ID
$type = dms_get_type( 1 );

// By slug
$type = dms_get_type( 'vehicles' );

echo esc_html( $type->get( 'plural' ) );

dms_get_types( bool $array_format = false ): array

Returns all registered inventory types.

Parameters

Name Type Default Description
$array_format bool false When true, returns a flat array of slugs instead of Type objects

Returns - Type[] or string[] when $array_format is true

Example

// All Type objects
$types = dms_get_types();

foreach ( $types as $type ) {
    echo esc_html( $type->get( 'plural' ) );
}

// Just slugs
$slugs = dms_get_types( true );
// e.g. [ 'vehicles', 'boats' ]

dms_get_current_type(): bool|Type

Detects and returns the active inventory type from the current request context (admin screen, front-end query, AJAX, REST, Elementor editor). Returns false if no type can be determined.

Returns - Type or false

Example

$type = dms_get_current_type();

if ( $type && $type->exists() ) {
    echo esc_html( $type->get( 'plural' ) );
}

dms_set_current_type( int $type_id ): void

Forces a specific inventory type to be treated as the current type by setting the dms-type query var.

Parameters

Name Type Default Description
$type_id int - The type ID to set as current

Returns - void

Example

dms_set_current_type( 1 );

dms_add_type( array $type_data ): bool|int

Creates a new inventory type. Returns the new type ID on success, false on failure.

Parameters

Name Type Default Description
$type_data array - Type data including singular, plural, and slug keys

Returns - int\|bool

Example

$type_id = dms_add_type( [
    'singular' => 'Boat',
    'plural'   => 'Boats',
    'slug'     => 'boats',
] );

dms_is_dms_post_type( string $post_type ): bool

Checks whether a given post type slug belongs to a registered DMS inventory type.

Parameters

Name Type Default Description
$post_type string - The post type slug to check

Returns - bool

Example

if ( dms_is_dms_post_type( get_post_type() ) ) {
    // We are on a DMS listing
}

dms_add_type_tab( array $tab_data ): void

Registers a custom options tab that will appear on the inventory type settings page for all types.

Parameters

Name Type Default Description
$tab_data array - Tab definition including id, title, icon, and fields keys

Returns - void

Example

dms_add_type_tab( [
    'id'     => 'my-plugin-settings',
    'title'  => 'My Plugin',
    'icon'   => 'plug',
    'fields' => [
        'my_option' => [
            'id'   => 'my_option',
            'type' => 'toggle',
            'name' => 'Enable My Feature',
        ],
    ],
] );

dms_get_type_options(): array

Returns all registered type option field definitions.

Returns - array

Example

$options = dms_get_type_options();