All public functions available to use in your theme templates and files.
Overview
ThemePlus provides a small set of global helper functions for retrieving and updating option values, checking plugin status, and registering sections and fields. These are the only functions your theme needs to interact with ThemePlus directly.
Option Functions
themeplus_get_option()
Retrieves a saved option value. If no key is provided, returns all options as an array.
themeplus_get_option( ?string $key = null, mixed $default = '' ): mixed
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string|null | null | The option field ID. Pass null or omit to get all options. |
$default | mixed | '' | Value to return if the option has not been saved yet. |
Returns: The saved option value, the $default if the option is not set, or an array of all options when $key is null. Returns $default if ThemePlus is not active.
Examples
// Get a single scalar option
$color = themeplus_get_option( 'primary_color', '#2271b1' );
$enabled = themeplus_get_option( 'enable_preloader', true );
// Get all options at once β recommended when using more than two fields
$options = themeplus_get_option();
$color = $options['primary_color'] ?? '#2271b1';
$enabled = $options['enable_preloader'] ?? true;
// Structured fields return arrays β always read by key
$logo = themeplus_get_option( 'site_logo', [] );
$logo_url = $logo['url'] ?? '';
$logo_alt = $logo['alt'] ?? get_bloginfo( 'name' );
// Social Media returns an array of rows
$social = themeplus_get_option( 'social_links', [] );
foreach ( $social as $item ) {
$platform = $item['platform'] ?? '';
$url = $item['url'] ?? '';
}
Performance tip: If your template uses more than two or three options, call
themeplus_get_option()once with no arguments and access values from the returned array. This reads the database only once instead of once per field.
themeplus_update_option()
Updates a single option value in the database.
themeplus_update_option( string $key, mixed $value ): bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The option field ID to update. |
$value | mixed | The new value to store. |
Returns: true on success, false on failure or if ThemePlus is not active.
Example
themeplus_update_option( 'primary_color', '#ff6b6b' );
Important:
themeplus_update_option()writes directly to the database without sanitization. When calling this programmatically, sanitize the value yourself before passing it β for examplesanitize_hex_color()for color values orsanitize_text_field()for strings. Values saved through the ThemePlus admin panel are sanitized automatically viaThemePlus_Sanitizer.
Status Functions
themeplus_is_active()
Checks whether ThemePlus is installed and active. Safe to call at any point β it simply checks whether the ThemePlus_Settingsclass exists.
themeplus_is_active(): bool
Example
if ( themeplus_is_active() ) {
$color = themeplus_get_option( 'primary_color', '#2271b1' );
} else {
$color = '#2271b1';
}themeplus_get_version()
Returns the current ThemePlus plugin version string.
themeplus_get_version(): string
Example
$version = themeplus_get_version();
// Returns: '1.0.0'
Config Functions
themeplus_framework_config()
Configures the ThemePlus framework with your themeβs white-label settings. Must be called on the after_setup_theme hook.
themeplus_framework_config( array $config ): void
See the Framework Configuration article for the full list of available options.
themeplus_add_section()
Registers a new section in the options panel sidebar. Must be called on the init hook.
themeplus_add_section( array $section ): void
Example
themeplus_add_section([
'id' => 'general',
'title' => __( 'General Settings', 'your-textdomain' ),
'icon' => 'cog', // FontAwesome name only β not the full class
'priority' => 10,
'fields' => [],
]);See the Sections & Subsections article for the full reference.
themeplus_add_subsection()
Attaches a subsection to an already-registered parent section. Must be called on the init hook at priority 20 or later.
themeplus_add_subsection( string $parent_id, array $subsection ): void
Parameters
| Parameter | Type | Description |
|---|---|---|
$parent_id | string | The id of the parent section. |
$subsection | array | Subsection config with id, title, icon, and fields. |
Example
add_action( 'init', function () {
if ( ! function_exists( 'themeplus_add_subsection' ) ) {
return;
}
themeplus_add_subsection( 'header', [
'id' => 'logo',
'title' => __( 'Logo', 'your-textdomain' ),
'icon' => 'image',
'fields' => [
[
'id' => 'logo_image',
'type' => 'image',
'title' => __( 'Logo Image', 'your-textdomain' ),
],
],
]);
}, 20 );themeplus_get_sections()
Returns all registered sections as an array.
themeplus_get_sections(): array
themeplus_get_section()
Returns a single section by its ID, or null if not found.
themeplus_get_section( string $section_id ): array|null
themeplus_get_all_fields()
Returns all registered fields across all sections as a flat array keyed by field ID.
themeplus_get_all_fields(): array
Safety Pattern
Always wrap ThemePlus function calls in an existence check when writing theme code. This ensures your theme works correctly even if ThemePlus is deactivated or not yet installed:
// Guard at the top of a config file
if ( ! function_exists( 'themeplus_framework_config' ) ) {
return;
}
// Guard around individual calls
if ( function_exists( 'themeplus_get_option' ) ) {
$color = themeplus_get_option( 'primary_color', '#2271b1' );
} else {
$color = '#2271b1';
}
// Or use themeplus_is_active() as a single guard
if ( themeplus_is_active() ) {
$options = themeplus_get_option();
}Function Reference Summary
| Function | Description |
|---|---|
themeplus_get_option( $key, $default ) | Get a single option or all options |
themeplus_update_option( $key, $value ) | Update a single option (no sanitization β callerβs responsibility) |
themeplus_is_active() | Check if ThemePlus is active |
themeplus_get_version() | Get the plugin version string |
themeplus_framework_config( $config ) | Configure the framework |
themeplus_add_section( $section ) | Register a section |
themeplus_add_subsection( $parent_id, $subsection ) | Attach a subsection to an existing section |
themeplus_get_sections() | Get all registered sections |
themeplus_get_section( $section_id ) | Get a section by ID |
themeplus_get_all_fields() | Get all registered fields as a flat array |