Skip to content

Instantly share code, notes, and snippets.

@gmmedia
Created September 25, 2022 12:28
Show Gist options
  • Save gmmedia/d9ff8b73d3ebf7be3dfc992230839ec1 to your computer and use it in GitHub Desktop.
Save gmmedia/d9ff8b73d3ebf7be3dfc992230839ec1 to your computer and use it in GitHub Desktop.
Kadence Cloud Settings: Pro Tag
/**
* 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 );
/**
* 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 ( 'TxrD8cFsVG5a' === $key ) {
$args['pro_access'] = false;
}
return $args;
}
add_filter( 'kadence_cloud_rest_request_extras', 'custom_kadence_cloud_add_extra_args', 20, 2 );
/**
* 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment