Filter
uncanny-automator
automator_set_learndash_quiz_{$type}_tokens
Filters LearnDash quiz tokens before they are used by the Automator.
add_filter( 'automator_set_learndash_quiz_{$type}_tokens', $callback, 10, 1 );
Description
Fires after LearnDash quiz tokens are generated. Developers can use this filter to add, remove, or modify tokens associated with LearnDash quizzes before they are used in automations. The `$tokens` parameter contains the existing token array.
Usage
add_filter( 'automator_set_learndash_quiz_{$type}_tokens', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of available tokens that can be used to represent quiz-related data within the automation.
Return Value
The filtered value.
Examples
/**
* Example of using the 'automator_set_learndash_quiz_{$type}_tokens' filter.
* This example adds a custom token to the list of available tokens for LearnDash quizzes
* of type 'completed'. The new token will display the quiz title.
*/
add_filter( 'automator_set_learndash_quiz_completed_tokens', function( $tokens ) {
// Ensure $tokens is an array before proceeding.
if ( ! is_array( $tokens ) ) {
return $tokens;
}
// Define the new token.
// Assuming $option_code is available in the context where this filter is applied.
// If not, you might need to pass it or find a way to access it.
// For this example, let's assume $option_code is something like 'MY_CUSTOM_QUIZ_TITLE'.
$custom_option_code = 'MY_CUSTOM_QUIZ_TITLE';
$tokens[ $custom_option_code ] = array(
'name' => esc_attr_x( 'Quiz Title', 'LearnDash Token', 'your-text-domain' ),
'type' => 'text',
);
return $tokens;
}, 10, 1 );
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:684
public function get_quiz_relevant_tokens( $type = 'trigger', $option_code = 'LDQUIZ' ) {
$tokens = array(
$option_code => array(
'name' => esc_attr_x( 'Quiz title', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_ID' => array(
'name' => esc_attr_x( 'Quiz ID', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'int',
),
$option_code . '_URL' => array(
'name' => esc_attr_x( 'Quiz URL', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_THUMB_ID' => array(
'name' => esc_attr_x( 'Quiz featured image ID', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'int',
),
$option_code . '_THUMB_URL' => array(
'name' => esc_attr_x( 'Quiz featured image URL', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_TIME' => array(
'name' => esc_attr_x( 'Quiz time spent', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_SCORE' => array(
'name' => esc_attr_x( 'Quiz score', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_CORRECT' => array(
'name' => esc_attr_x( 'Quiz number of correct answers', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'int',
),
$option_code . '_CATEGORY_SCORES' => array(
'name' => esc_attr_x( 'Quiz category scores', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_Q_AND_A' => array(
'name' => esc_attr_x( 'Quiz questions and answers', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
$option_code . '_Q_AND_A_CSV' => array(
'name' => esc_attr_x( 'Quiz question & answers (unformatted)', 'LearnDash Token', 'uncanny-automator' ),
'type' => 'text',
),
);
return apply_filters( "automator_set_learndash_quiz_{$type}_tokens", $tokens );
}