Skip to main content

benecaster_get_active_template()

Template Free
benecaster_get_active_template(): array|null|WP_Error

Returns the manifest of the design template currently in force. The usual reason to call it is the guard that keeps an add-on update from silently restyling a live site: if the podcaster has chosen a template, do not activate yours over the top of it.

Return Value

Type: array|null|WP_Error

The active template's manifest as an array — name, slug, version, requires, author, author_url, description, screenshot, install_path, built_in — or null when the stored slug matches nothing, or a WP_Error with code benecaster_template_lookup_failed.

Example

$active = benecaster_get_active_template();

// WP_Error means "could not tell" — never act on a failed read.
if ( is_wp_error( $active ) ) {
    return;
}

// built_in is what answers "has the owner chosen a template?".
// A built-in one means the site is on an untouched default.
if ( null !== $active && ! $active['built_in'] ) {
    return; // the podcaster picked this — leave it alone
}

Notes

A fresh install is not "no active template", so do not write that guard as a null check. The plugin ships two built-in templates and default-light is active from the moment it is installed, which is what the Templates admin screen shows. This function reports it, so null !== $active is true on every ordinary site and a null-based guard never fires.

built_in is the field that answers "has the owner chosen?"true means the site is on a shipped default, and replacing it overrides nobody's decision.

null means exactly one thing: a dangling slug. The stored active template matches nothing installed or built in — one uninstalled around a stale option, say. It is not an error, because the question a caller is asking is "is a template in force right now?", and a slug pointing at nothing is not one.

null and WP_Error are both falsy, so test is_wp_error() first. A bare if ( ! $active ) treats "I could not read this site's state" as "this site has no template" and installs over it.

It returns an array, not a TemplateManifest. Use $active['slug'], not $active->slug. The array is the manifest's own to_array() shape, so nothing is lost but the class reference.

Need this built rather than just documented? See our services →