Filter
uncanny-automator-pro
uap_option_all_ld_certificates
Filters the array of all LearnDash certificates available for use with the Uncanny Automator integration.
add_filter( 'uap_option_all_ld_certificates', $callback, 10, 1 );
Description
Fires when Uncanny Automator prepares the list of LearnDash certificates for token integration. Developers can use this filter to modify the certificate options and their corresponding token names, allowing for custom certificate representation or exclusion within Uncanny Automator recipes.
Usage
add_filter( 'uap_option_all_ld_certificates', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the value of the LearnDash certificates option, which can be of mixed types and is applied as a filter.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_all_ld_certificates', 'my_custom_learndash_certificate_tokens', 10, 1 );
/**
* Adds custom tokens for LearnDash certificates to Uncanny Automator Pro.
*
* This function intercepts the default tokens provided by Uncanny Automator Pro
* for LearnDash certificates and adds custom ones, such as a link to download
* the certificate directly.
*
* @param array $option The original array of certificate options.
* @return array The modified array of certificate options with added custom tokens.
*/
function my_custom_learndash_certificate_tokens( $option ) {
// Assuming $option is an array and has a 'relevant_tokens' key.
// If not, we might want to handle this case gracefully, but for a realistic example,
// we'll assume the expected structure.
if ( isset( $option['relevant_tokens'] ) && is_array( $option['relevant_tokens'] ) ) {
// Example: Add a token for a direct download URL of the certificate.
// This would require some logic to generate the URL based on the certificate data.
// For demonstration, let's assume we have a way to get the certificate ID and user ID.
// In a real scenario, this data would likely be available within the context where this filter is applied.
// Placeholder for getting dynamic data. In a real plugin, this would be passed or accessible.
$certificate_id = '123'; // Replace with actual certificate ID
$user_id = get_current_user_id(); // Or get user ID from context
// Constructing a hypothetical download URL. This is purely illustrative.
// The actual URL structure would depend on how LearnDash and Uncanny Automator handle certificates.
$certificate_download_url = home_url( '/my-custom-certificates/download/?cert_id=' . $certificate_id . '&user_id=' . $user_id );
// Add the custom token
$option['relevant_tokens']['MY_CERT_DOWNLOAD_URL'] = __( 'Certificate Direct Download Link', 'my-text-domain' );
// You could also potentially modify existing tokens or add more based on your needs.
// For example, if you wanted to modify the Certificate ID token:
// $option['relevant_tokens']['some_existing_cert_id_token'] = __( 'Learndash Certificate Identifier', 'my-text-domain' );
// If you need to store the generated URL to be used with the MY_CERT_DOWNLOAD_URL token,
// you might need to modify how Uncanny Automator Pro retrieves token values.
// This example focuses on *adding* the token definition. The actual value retrieval
// would be handled by Uncanny Automator Pro based on the token key.
// Often, plugins will have a separate mechanism or filter to provide the *value* for custom tokens.
}
// It's crucial to return the modified $option array.
return $option;
}
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
uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:444
public function all_ld_certificates( $label = null, $option_code = 'LDCERTIFICATES', $args = array() ) {
if ( ! $label ) {
$label = __( 'Certificate', 'uncanny-automator-pro' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$include_all = key_exists( 'include_all', $args ) ? $args['include_all'] : false;
$args = array(
'post_type' => 'sfwd-certificates',
'posts_per_page' => 9999,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->options->wp_query( $args, $include_all, __( 'Any certificate', 'uncanny-automator-pro' ) );
$pattern = get_shortcode_regex();
foreach ( $options as $key => $option ) {
$content = get_post_field( 'post_content', $key );
if ( preg_match_all( '/' . $pattern . '/s', $content, $matches )
&& array_key_exists( 2, $matches )
&& ( in_array( 'quizinfo', $matches[2] ) || in_array( 'courseinfo', $matches[2] ) )
) {
// shortcode is being used
unset( $options[ $key ] );
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => __( 'Certificate title', 'uncanny-automator-pro' ),
$option_code . '_ID' => __( 'Certificate ID', 'uncanny-automator-pro' ),
$option_code . '_URL' => __( 'Certificate URL', 'uncanny-automator-pro' ),
),
);
return apply_filters( 'uap_option_all_ld_certificates', $option );
}