Filter
uncanny-automator
uap_option_all_wpcw_units
Filters all WP Courseware units before they are retrieved for display, allowing for modification of the unit data.
add_filter( 'uap_option_all_wpcw_units', $callback, 10, 1 );
Description
Fires within Uncanny Automator's WP Courseware integration to allow modification of the available tokens for WP Courseware units. Developers can add or remove tokens to customize what unit-related data can be used in automations, such as unit titles, IDs, or URLs. This hook is called when building the array of available options for token selection.
Usage
add_filter( 'uap_option_all_wpcw_units', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter likely holds the current value of the option being filtered, allowing it to be modified before being returned.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the uap_option_all_wpcw_units filter.
* This example adds an additional token to the available options for WP Courseware units,
* specifically to include the unit's status (published, draft, etc.).
*/
add_filter(
'uap_option_all_wpcw_units',
function ( $option ) {
// Ensure the option is an array and has the 'relevant_tokens' key before proceeding.
if ( is_array( $option ) && isset( $option['relevant_tokens'] ) ) {
// Assuming $option_code is available within the original filter context,
// but in a standalone example, we'll simulate it or use a fixed one if known.
// For demonstration, let's assume the original $option_code refers to the unit title key.
// If $option_code is not globally available in your context, you might need to
// derive it or add it to the $option array itself before the filter is applied.
// In this context, the filter likely receives an array structure where a key
// represents the base for tokens. Let's assume the first key in 'relevant_tokens'
// is the base $option_code.
$base_option_code = key( $option['relevant_tokens'] );
if ( $base_option_code ) {
// Add a new token for the Unit Status.
$option['relevant_tokens'][ $base_option_code . '_STATUS' ] = esc_attr__( 'Unit Status', 'uncanny-automator' );
}
}
return $option;
},
10, // Priority
1 // Accepted args
);
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/wp-courseware/helpers/wp-courseware-helpers.php:172
public function all_wpcw_units( $label = null, $option_code = 'WPCW_UNIT', $any_option = true ) {
if ( ! $label ) {
$label = esc_attr__( 'Unit', 'uncanny-automator' );
}
$args = array(
'post_type' => 'course_unit',
'posts_per_page' => 9999,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any unit', 'uncanny-automator' ) );
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
// to setup example, lets define the value the child will be based on
'current_value' => false,
'validation_type' => 'text',
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Unit title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Unit ID', 'uncanny-automator' ),
$option_code . '_URL' => esc_attr__( 'Unit URL', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_wpcw_units', $option );
}