TryDemo is built to be extended. This page documents the hooks, helper functions, and template overrides available to developers.
Template overrides
TryDemo renders its front-end markup from files in the plugin’s templates/ folder. To customize any of them, copy the file into a trydemo/ folder inside your theme:
your-theme/trydemo/shortcodes/try-demo.php
TryDemo looks in the theme first, then falls back to its bundled template. You can change the lookup folder with the tdemo_template_path filter (default trydemo/).
Helper functions for rendering:
| Function | Purpose |
|---|---|
tdemo_locate_template( $template_name ) | Resolve a template path, honouring theme overrides |
tdemo_get_template_html( $template, $args = [] ) | Render a template (relative path, no extension) to a string |
tdemo_render_template( $template, $args = [] ) | Echo a rendered template |
Filters
Suitability & registration
| Filter | Signature | Description |
|---|---|---|
tdemo_is_suitable_site | bool $suitable | Override the multisite suitability check (subdirectory multisite required by default) |
tdemo_registration_disabled | bool $disabled | Programmatically enable/disable new demo requests |
Restrictions
| Filter | Signature | Description |
|---|---|---|
tdemo_forbidden_pages | array $pages | Adjust which admin page slugs are blocked inside demos |
tdemo_hide_plugins | bool $hide, array $menu_perms | Override whether the Plugins menu is hidden inside demos |
Templates
| Filter | Signature | Description |
|---|---|---|
tdemo_template_path | string $path | Theme subfolder searched for template overrides (default trydemo/) |
tdemo_locate_template | string $template, string $template_name | Filter the resolved template path |
Cloning engine
| Filter | Signature | Description |
|---|---|---|
tdemo_global_tables | string[] $tables | Table base names that must never be cloned into a demo |
tdemo_global_folders | string[] $folders | Upload sub-folders that must never be copied into a demo |
tdemo_target_site_slug | string $slug, array $user_data | Customize the generated sandbox slug |
tdemo_create_redirect | string $url, int $target_id, string $site_address, string $redirect | Change where the visitor is sent after their demo is created |
tdemo_delete_demo_logout | bool $logout | Whether to destroy user sessions when a demo is deleted |
tdemo_activate_plugin | bool $activate, string $plugin | Force-reactivate a specific plugin in a freshly cloned demo |
tdemo_query_count | int $count (default 4) | Row batch size used when copying table data |
User identity
| Filter | Signature | Description |
|---|---|---|
tdemo_user_name | string $email | The username assigned to the demo user (defaults to their email) |
tdemo_user_email | string $email | The email assigned to the demo user |
Actions
| Action | Signature | Fires |
|---|---|---|
tdemo_create_demo | int $source_id, int $target_id | After a demo site has been cloned and set up |
tdemo_delete_demo | int $blog_id | Before a demo site is deleted |
Example: seed extra data into every new demo:
add_action( 'tdemo_create_demo', function ( $source_id, $target_id ) {
switch_to_blog( $target_id );
update_option( 'my_plugin_demo_mode', 1 );
restore_current_blog();
}, 10, 2 );
Helper functions
| Function | Returns | Description |
|---|---|---|
tdemo_is_demo( $blog_id = '' ) | bool | Whether the given (or current) blog is a demo site |
tdemo_registration_disabled() | bool | Whether new demo requests are disabled |
tdemo_is_forbidden_page( $page_slug ) | bool | Whether an admin page slug is blocked inside demos |
tdemo_hide_plugins() | bool | Whether the Plugins menu is hidden inside demos |
tdemo_is_admin_user() | bool | Whether the current user is a network administrator |
tdemo_get_sites( $args = [] ) | array | Network sites as ['blog_id' => int] pairs |
tdemo_table( $name ) | string | Fully-qualified network table name — 'users' or 'demos' |
tdemo_submenu_uri( $parent, $submenu ) | string | Compose an admin submenu URI |
The trydemo() instance
trydemo() returns the main plugin instance, exposing:
trydemo()->settings( $key )— a settings object (general,mail,toolbar,mailchimp,restrictions,sandbox).trydemo()->demos()— the demos repository.trydemo()->users()— the demo-users repository.
// Read the configured demo lifetime (seconds).
$lifespan = (int) trydemo()->settings( 'general' )->get( 'lifespan' );
Database tables
TryDemo stores its data in two network-wide tables on the base prefix (shared across all sites):
| Table | Contents |
|---|---|
{base_prefix}tdemo_users | Demo requesters (email, name, generated password, linked WP user) |
{base_prefix}tdemo_demos | Demo sandboxes (source/target blog IDs, status, secret, dates, lifetime flag) |
Access them by logical name with tdemo_table( 'users' ) / tdemo_table( 'demos' ) rather than hardcoding the prefix.
Cron
The hourly purge job runs on the tdemo_purge_event hook (scheduled on the hourly interval). It’s registered on activation and cleared on deactivation. See The demo lifecycle.