WordPress Integration
Use Toggly Feature Management as a WordPress plugin via the Composer package
toggly/wordpress (depends on
toggly/feature-management-php
core). This is not the abandoned demo folder in the multi-language monorepo.
Grab the printable WordPress cheat sheet (download PDF) — install, settings, templates, shortcodes, cron, and hooks.
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher, through PHP 8.5
- Composer (to install package dependencies)
The maintained plugin package is currently validated on WordPress 7.1 with PHP 8.5. This does not replace the retained WordPress 5.0+ support floor.
Installation
- Require the WordPress package (or place it under
wp-content/plugins/toggly/so WordPress loads the bootstrap filetoggly.php):
composer require toggly/wordpress
If you install with Composer outside wp-content/plugins, copy or symlink the
package directory so toggly.php is at wp-content/plugins/toggly/toggly.php
(plugin header: Toggly Feature Management).
- Install Composer dependencies in the plugin directory if needed:
cd wp-content/plugins/toggly
composer install
- In WordPress Admin → Plugins, activate Toggly Feature Management.
The bootstrap registers Toggly\WordPress\TogglyPlugin on plugins_loaded and the admin Settings → Toggly page via Toggly\WordPress\Admin\SettingsPage.
Configuration
Open Settings → Toggly and set:
| Field | Purpose |
|---|---|
| App Key | Your Toggly App Key from toggly.io |
| Environment | Environment name (case sensitive; default Production) |
| Base URL | Optional. Leave blank to use the SDK default |
| Use Signed Definitions | Optional. Enable ECDSA signature verification |
Click Save Changes.
Settings are stored in the toggly_settings WordPress option.
Template helper
<?php if (toggly_is_enabled('new-header')): ?>
<?php get_template_part('header', 'new'); ?>
<?php endif; ?>
Signature: toggly_is_enabled(string $featureKey, ?array $context = null): bool.
Optional context is passed through to feature evaluation (for example user identity fields your filters expect):
<?php if (toggly_is_enabled('premium-content', ['userId' => (string) get_current_user_id()])): ?>
<!-- premium block -->
<?php endif; ?>
Shortcode
Enclose content that should render only when a feature is enabled:
[toggly_feature name="premium-content"]
<!-- shown when the feature is on -->
[/toggly_feature]
Attributes:
name(required) — feature keycontext(optional) — JSON object decoded to an associative array for evaluation
If name is empty, the shortcode renders nothing.
Programmatic API
$plugin = \Toggly\WordPress\TogglyPlugin::getInstance();
if ($plugin->isEnabled('my-feature')) {
// Feature is enabled
}
if ($plugin->isEnabled('my-feature', ['email' => wp_get_current_user()->user_email])) {
// With context
}
Action hooks
Listen for feature state-change actions in a theme or plugin:
add_action('toggly_feature_turns_on', function ($featureKey) {
if ($featureKey === 'new-theme') {
// React when this feature turns on
}
});
add_action('toggly_feature_turns_off', function ($featureKey) {
if ($featureKey === 'new-theme') {
// React when this feature turns off
}
});
WP-Cron
The plugin registers custom intervals and schedules:
| Hook | Interval | Behavior |
|---|---|---|
toggly_refresh_features | Every 5 minutes (toggly_refresh_interval) | Calls FeatureProvider::refreshFeatures() |
toggly_send_stats | Every minute (toggly_send_interval) | Sends usage stats and metrics |
You can trigger them manually:
do_action('toggly_refresh_features');
do_action('toggly_send_stats');
Ensure WP-Cron is running in production (or use a real system cron that hits wp-cron.php).
Snapshot storage
By default the plugin stores feature snapshots with the WordPress Transients API (CacheSnapshotProvider + WordPressCacheAdapter, document name toggly_features).
Frontend script and admin bar
When an App Key is configured, the plugin enqueues https://cdn.toggly.io/toggly-ui.js on the front end and localizes togglyConfig.appKey.
Administrators see a Toggly item in the admin bar listing up to five feature keys with ON/OFF status.
Request context
WordPressFeatureContextProvider supplies a default context identifier from the logged-in user’s email (or user ID), falling back to the request IP when anonymous.
Related docs
Do not confuse this plugin with Toggly.FeatureManagement/Toggly.FeatureManagement.Wordpress/ in the multi-language monorepo. That folder is an unrelated abandoned demo and is not the product documented here.