Go Back to Parent Doc

Developer Reference

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:

FunctionPurpose
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

FilterSignatureDescription
tdemo_is_suitable_sitebool $suitableOverride the multisite suitability check (subdirectory multisite required by default)
tdemo_registration_disabledbool $disabledProgrammatically enable/disable new demo requests

Restrictions

FilterSignatureDescription
tdemo_forbidden_pagesarray $pagesAdjust which admin page slugs are blocked inside demos
tdemo_hide_pluginsbool $hide, array $menu_permsOverride whether the Plugins menu is hidden inside demos

Templates

FilterSignatureDescription
tdemo_template_pathstring $pathTheme subfolder searched for template overrides (default trydemo/)
tdemo_locate_templatestring $template, string $template_nameFilter the resolved template path

Cloning engine

FilterSignatureDescription
tdemo_global_tablesstring[] $tablesTable base names that must never be cloned into a demo
tdemo_global_foldersstring[] $foldersUpload sub-folders that must never be copied into a demo
tdemo_target_site_slugstring $slug, array $user_dataCustomize the generated sandbox slug
tdemo_create_redirectstring $url, int $target_id, string $site_address, string $redirectChange where the visitor is sent after their demo is created
tdemo_delete_demo_logoutbool $logoutWhether to destroy user sessions when a demo is deleted
tdemo_activate_pluginbool $activate, string $pluginForce-reactivate a specific plugin in a freshly cloned demo
tdemo_query_countint $count (default 4)Row batch size used when copying table data

User identity

FilterSignatureDescription
tdemo_user_namestring $emailThe username assigned to the demo user (defaults to their email)
tdemo_user_emailstring $emailThe email assigned to the demo user

Actions

ActionSignatureFires
tdemo_create_demoint $source_id, int $target_idAfter a demo site has been cloned and set up
tdemo_delete_demoint $blog_idBefore 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

FunctionReturnsDescription
tdemo_is_demo( $blog_id = '' )boolWhether the given (or current) blog is a demo site
tdemo_registration_disabled()boolWhether new demo requests are disabled
tdemo_is_forbidden_page( $page_slug )boolWhether an admin page slug is blocked inside demos
tdemo_hide_plugins()boolWhether the Plugins menu is hidden inside demos
tdemo_is_admin_user()boolWhether the current user is a network administrator
tdemo_get_sites( $args = [] )arrayNetwork sites as ['blog_id' => int] pairs
tdemo_table( $name )stringFully-qualified network table name — 'users' or 'demos'
tdemo_submenu_uri( $parent, $submenu )stringCompose an admin submenu URI

The trydemo() instance

trydemo() returns the main plugin instance, exposing:

  • trydemo()->settings( $key ) — a settings object (generalmailtoolbarmailchimprestrictionssandbox).
  • 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):

TableContents
{base_prefix}tdemo_usersDemo requesters (email, name, generated password, linked WP user)
{base_prefix}tdemo_demosDemo 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.

← Back to docs

Shopping Cart
  • Your cart is empty.