Filter tin-canny-learndash-reporting

uo_tin_can_filter_actions

Filters the actions for the TinyMCE editor, allowing modifications before they are processed.

add_filter( 'uo_tin_can_filter_actions', $callback, 10, 1 );

Description

Allows developers to modify the available actions shown in the Tin Can filter dropdown. This hook provides access to the `$actions` array, enabling the addition, removal, or modification of filter options. Primarily used for customizing the reporting interface.


Usage

add_filter( 'uo_tin_can_filter_actions', 'your_function_name', 10, 1 );

Parameters

$actions (mixed)
This parameter contains the existing list of actions that can be filtered for Tin Can reporting.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the actions available in the Tin Can filter.
 *
 * This filter allows you to modify the list of actions that users can filter by
 * in the Tin Can reporting. For instance, you might want to add a custom action
 * or remove one that's not relevant for your use case.
 *
 * @param array $actions An array of actions. Each action is expected to be an array
 *                       with at least a 'verb' key.
 * @return array The modified array of actions.
 */
add_filter( 'uo_tin_can_filter_actions', 'my_custom_tin_can_actions', 10, 1 );

function my_custom_tin_can_actions( $actions ) {
    // Ensure $actions is an array, if not, initialize it.
    if ( ! is_array( $actions ) ) {
        $actions = array();
    }

    // Example: Add a custom action if it doesn't already exist.
    $custom_action_verb = 'completed_module';
    $custom_action_exists = false;
    foreach ( $actions as $action ) {
        if ( isset( $action['verb'] ) && $action['verb'] === $custom_action_verb ) {
            $custom_action_exists = true;
            break;
        }
    }

    if ( ! $custom_action_exists ) {
        $actions[] = array(
            'verb' => $custom_action_verb,
            'label' => __( 'Module Completed', 'uncanny-learndash-reporting' ), // Example translation
        );
    }

    // Example: Remove an existing action, for instance, 'answered'.
    // We need to iterate and build a new array excluding the unwanted action.
    $filtered_actions = array();
    $action_to_remove = 'answered';
    foreach ( $actions as $action ) {
        if ( ! isset( $action['verb'] ) || $action['verb'] !== $action_to_remove ) {
            $filtered_actions[] = $action;
        }
    }

    // Return the modified array of actions.
    return $filtered_actions;
}
?>

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/reporting/tin-can/templates/tc-tincan-filter.php:215

/* translators: %s: Course label */
				                                __( 'All %s', 'uncanny-learndash-reporting' ),
				                                apply_filters( 'uo_tin_can_filter_action_label', esc_html_x( 'actions', 'Tin Can Filter Action name', 'uncanny-learndash-reporting' ), true )
			                                )
		                                );
		                                ?>
                                    </option>
	                                <?php $actions = apply_filters( 'uo_tin_can_filter_actions', $actions ); ?>
	                                <?php if ( ! empty( $actions ) ) { ?>
		                                <?php foreach ( $actions as $action ) { ?>
			                                <?php $action_selected = strtolower( ultc_get_filter_var( 'tc_filter_action', '' ) ) === $action['verb'] ? ' selected="selected"' : ''; ?>
                                            <option value="<?php echo esc_attr( $action['verb'] ); ?>"<?php echo esc_attr( $action_selected ); ?>>
				                                <?php echo esc_html( ucfirst( $action['verb'] ) ); ?>
                                            </option>
		                                <?php } ?>


Scroll to Top