Kadence Cloud - So erstellst du Pro Templates

Kadence Pattern Hub - Create Pro Templates and Block Access

With the Kadence Cloud Plugin (formerly Kadence Cloud) you can also sell individual templates as Pro Templates in your free Pattern Hub Library. Learn how to do this technically, with an additional category and three code snippets.

I use the Kadence theme for this, but you can also use any other WordPress theme.

What do I need for this tutorial?

The following video shows the setup for the Kadence Cloud Premium templates:

How to offer Pro Templates in a free cloud

If you are selling access to your Pattern Hub, you may want to offer limited free access. One way is to create a simple access key in the Kadence Cloud settings and give it to anyone who wants the free access.

Then you can apply a filter to that key and make sure it blocks access to all library items in a particular “Pro” category.

In this tutorial, you will learn how to install Pro Templates step by step.

How to use the Code Snippets

In steps 2 to 3 you will find Code Snippets that you need to insert for WordPress. You can do this directly in the WordPress Child Theme of your WordPress installation, or you can use a plugin.

functions.php

Open the functions.php file with an editor of your choice or directly in the WordPress admin design > theme editor. Here you can add the snippets at the very end.

Advanced Scripts Plugin

If you don’t use a child theme, or you don’t feel comfortable with your code file, you can use a plugin like Advanced Scripts and create the snippets there. At Location, you can select “Administration area”.

It looks like this for me:

Example how to create the code snipptes with Advanced Scripts.
Example how to create the code snipptes with Advanced Scripts.

In the following instructions I assume that you have already installed the Kadence Cloud Plugin. If not, check out the Kadence Pattern Hub article beforehand, it explains everything in detail.

Step 1 – Create and assign a “Pro” category

Create the Pro category for Kadence Cloud.
Create the Pro category for Kadence Cloud.

Create a category named “Pro” in the Pattern Hub > Categories menu. This works the same way as the categories for posts.

Assign the Pro category to your template.
Assign the Pro category to your template.

Now you can assign the Pro category to any template.

Step 2 – Identify templates as Pro

To assign a Pro label to one of your categories, you can use the following filter.

This example assumes that you created a category with the slug “pro” in the previous step. Otherwise you have to change the string to has_term inside the single quotes.

/**
 * Apply a pro tag based on the cloud library category.
 *
 * @param boolean $enabled true or false based on if pro.
 * @param object $post the current cloud library item post object.
 * @param array $request_extras an array of extra information.
 * @return boolean based on if access should be labeled pro.
 */
function custom_kadence_cloud_add_pro_tag( $enabled, $post, $request_extras ) {
	if ( has_term( 'pro', 'kadence-cloud-categories', $post ) ) {
		return true;
	}
	return $enabled;
}
add_filter( 'kadence_cloud_post_is_pro', 'custom_kadence_cloud_add_pro_tag', 10, 3 );

Step 3 – Check the access level of the key

Next, we want to add a tag that we can reference to see if the given request is for our free key. If so, we’ll make sure that the per-category items are locked.

The code below assumes your free access key is “free”.

/**
 * Checks if key is "free" and adds request extra specifying.
 *
 * @param array $args true or false based on access.
 * @param WP_REST_Request $request full details about the request.
 * @return array with variables for request.
 */
function custom_kadence_cloud_add_extra_args( $args, $request ) {
	$key = $request->get_param( 'key' );
	$args['pro_access'] = true;
	if ( 'free' === $key ) {
		$args['pro_access'] = false;
	}
	return $args;
}
add_filter( 'kadence_cloud_rest_request_extras', 'custom_kadence_cloud_add_extra_args', 20, 2 );

Step 4 – Filter access to pro items

Using the “pro_access” argument we filtered above, for each element we check if we need to lock the element as a Pro template for the user.

/**
 * Lock access to specific cloud library items.
 *
 * @param boolean $enabled true or false based on if pro.
 * @param object $post the current cloud library item post object.
 * @param array $request_extras an array of extra information.
 * @return boolean based on if access should be labeled pro.
 */
function custom_kadence_cloud_lock_pro_tag( $enabled, $post, $request_extras ) {
	if ( has_term( 'pro', 'kadence-cloud-categories', $post ) && ! $request_extras['pro_access'] ) {
		return true;
	}
	return $enabled;
}
add_filter( 'kadence_cloud_post_is_locked', 'custom_kadence_cloud_lock_pro_tag', 10, 3 );

Pro templates are now locked

"Pro required for this item" - No access without Pro access
“Pro required for this item” – No access without Pro access

As you can see on the screenshot, I can’t insert the template marked “PRO”. It is locked and tells me that I need a Pro access.

Kadence Theme

Create stunning websites in minutes with this sleek and fast WordPress theme. Advanced web design!

Kadence Blocks

Kadence Blocks provides tools that allow you to create unique and meaningful content more easily in the native WordPress editor.

If you are making these changes after the fact and already had the library connected, you may have to wait a bit for the new settings to become active.

For me, updating via the circle icon in the upper right didn’t take effect right away either. However, when connecting on another blog, the Pro Templates were immediately locked. So it is a cache problem. Read all other Kadence WP articles.

Leave a Reply

Your email address will not be published. Required fields are marked *