Demi allows theme developers to provide premium demos that are only accessible to verified users. This is useful when distributing paid themes or restricting certain demos to licensed customers.
Premium demos can be marked using the is_pro flag in your demo registration. By default, Pro demos are restricted, and users cannot import them unless access is explicitly granted.
You can control access to these demos using the demi_is_pro_demo_allowed filter hook.
Using Hook
The demi_is_pro_demo_allowed hook allows you to check whether a user is allowed to import a premium demo. You can validate this using:
- A theme license status
- A purchase code
- Any other custom logic
Here is an example:
add_filter( 'demi_is_pro_demo_allowed',function ( $is_allowed, $slug, $demo_data ) { $is_theme_licensed = get_option( 'my_theme_license_status' ) === 'active'; if ( $is_theme_licensed ) { return true; // Allow import for licensed users } return $is_allowed; // Default is false for PRO demos },10,3);
How This Works
- Filter Hook:
demi_is_pro_demo_allowedpasses three parameters:$is_allowed– Boolean, default false for pro demos$slug– Demo slug being imported$demo_data– Full demo array from registration
- License Check: Inside the hook, you can check any condition you want (e.g., theme license, API validation).
- Return Value:
- Return
trueif the demo import should be allowed. - Return
$is_allowed(orfalse) to keep the demo restricted.
- Return
This ensures that only verified users can access premium demos, while free demos remain open to everyone.
Benefits for Theme Developers
- Protect premium demo content from unauthorized use
- Integrate with existing license or purchase code systems
- Maintain a clean demo import experience for users
- Combine with
demi_import_demosto create a mix of free and pro demos
