benecaster_register_field_cpt()
benecaster_register_field_cpt( string $cpt_slug, string $label ): void
Opens your own post type up to Benecaster’s field groups, so podcasters can attach custom fields to it the same way they do to episodes.
Call it on init, from the callback you pass to benecaster_register_addon() — the one that runs only while your add-on is switched on for at least one show — never straight from a benecaster_boot callback. benecaster_boot fires whether or not your add-on is switched on anywhere, so the Fields screen would offer your post type on a site where it is not registered. From the gated callback the two come and go together: an add-on off for every show drops out of the “Attached to” list, and its field groups stay until it is back. init because the label is translated, and WordPress 6.7 and later warn about translations loaded before init. That is never too late: Benecaster reads the list only when the Fields screen asks for it.
Values go with the post. When a post of a registered type is permanently deleted, by any route, Benecaster removes its stored field values, so your add-on needs no clean-up of its own. A post type whose slug starts benecaster_ is cleaned even while its add-on is deactivated. Read a value you still need on your post type’s own deletion action at priority 10 or earlier; by priority 20 of before_delete_post it may be gone.
What you get for one line. Your post type appears in the “Attached to” dropdown in Benecaster → Fields; podcasters build groups against it without you writing an editor; the REST endpoints that read and write field values accept it; and benecaster_field_groups fires for it, so groups can be injected programmatically exactly as they can for episodes. Benecaster registers benecaster_episode this way — your post type is not a second-class citizen.
Registering the same slug twice replaces the label rather than erroring. That is deliberate: it lets a parent plugin set a default that an add-on can override.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
$cpt_slug |
string |
— | Yes | Your registered post type slug — e.g. 'benecaster_guest'. |
$label |
string |
— | Yes | What a podcaster should see in the "Attached to" dropdown — e.g. 'Guest'. Translate it; this is human-facing. |
Return Value
Type:
void
Nothing.
Example
add_action( 'benecaster_boot', function ( \Benecaster\Container $container ) {
benecaster_register_addon(
'benecaster-addon-guest-manager',
static function ( \Benecaster\Container $container ): void {
// Runs only while the add-on is switched on for at least one show.
add_action( 'init', static function (): void {
benecaster_register_field_cpt( 'benecaster_guest', __( 'Guest', 'benecaster-guest-manager' ) );
} );
}
);
} );
Need this built rather than just documented? See our services →