Filter
uncanny-automator
automator_set_learndash_group_{$type}_tokens
Filters the tokens available for Learndash group actions based on the token type.
add_filter( 'automator_set_learndash_group_{$type}_tokens', $callback, 10, 1 );
Description
Fires when LearnDash group tokens are being generated for Uncanny Automator. Developers can filter the `$tokens` array to add, modify, or remove available tokens related to LearnDash groups. This hook is ideal for custom integrations or modifying default token behavior within the LearnDash integration.
Usage
add_filter( 'automator_set_learndash_group_{$type}_tokens', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of tokens that represent available data points related to LearnDash groups.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the automator_set_learndash_group_{$type}_tokens filter.
*
* This example demonstrates how to add a custom token for the LearnDash Group
* name to the available tokens for an automator trigger or action related to LearnDash Groups.
* The specific type ('{$type}') will be determined by the context where this filter is applied
* within the Uncanny Automator plugin (e.g., 'trigger', 'action').
*/
add_filter( 'automator_set_learndash_group_trigger_tokens', 'my_custom_learndash_group_tokens', 10, 1 );
function my_custom_learndash_group_tokens( $tokens ) {
// Assuming $tokens is an array of token definitions, let's add a new one.
// We need to know the $type variable from the context, which is usually passed
// implicitly by the apply_filters call. However, for this standalone example,
// we'll assume a 'trigger' type based on the hook name in the example.
// In a real scenario within Uncanny Automator, $type would be available.
// Let's simulate adding a token for the Group Name.
// The actual implementation within Uncanny Automator would likely fetch this
// from the LearnDash Group object.
$group_name_token_key = 'LEARNDASH_GROUP_NAME'; // A unique key for our token.
$tokens[ $group_name_token_key ] = array(
'name' => esc_attr_x( 'LearnDash Group Name', 'LearnDash Token', 'my-text-domain' ),
'type' => 'text', // The data type of the token value.
// In a real scenario, you might add a 'callback' or 'value' to fetch dynamically,
// but this filter focuses on defining the token's metadata.
);
// You can also modify existing tokens if needed.
// For example, let's say we wanted to ensure the 'Group featured image ID' is always
// displayed as a simple text field, even if it might sometimes be an integer.
if ( isset( $tokens['LEARNDASH_GROUP_THUMB_URL'] ) ) {
$tokens['LEARNDASH_GROUP_THUMB_URL']['type'] = 'text';
}
// Always return the modified array of tokens.
return $tokens;
}
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/learndash/helpers/learndash-helpers.php:552
public function get_group_relevant_tokens( $type = 'trigger', $option_code = 'LDGROUP' ) {
$tokens = array(
$option_code => array(
'name' => esc_attr_x( 'Group title', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_ID' => array(
'name' => esc_attr_x( 'Group ID', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'int',
),
$option_code . '_URL' => array(
'name' => esc_attr_x( 'Group URL', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_THUMB_ID' => array(
'name' => esc_attr_x( 'Group featured image ID', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'int',
),
$option_code . '_THUMB_URL' => array(
'name' => esc_attr_x( 'Group featured image ID', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
);
return apply_filters( "automator_set_learndash_group_{$type}_tokens", $tokens );
}