Filter tin-canny-learndash-reporting

tincanny_module_allow_db_capture

Filters whether database capture is allowed for the Tincanny module, providing control over data collection.

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

Description

Filters whether to capture LRS data to the WordPress database. Developers can use this to conditionally prevent or modify data capture based on specific logic before it's saved. This filter fires just before data is written to the database.


Usage

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

Parameters

$db_data (mixed)
This parameter determines whether the LRS data should be captured in the database.

Return Value

The filtered value.


Examples

/**
 * Prevent saving certain Tincanny module data to the database if the user's role
 * does not have permission to do so.
 *
 * @param mixed $allow_db_capture The default value, true, indicating data should be captured.
 * @param mixed $db_data          The data intended for database capture.
 * @return bool|mixed Returns false if the user role is not allowed, otherwise returns the original value.
 */
function my_tincanny_restrict_db_capture_by_role( $allow_db_capture, $db_data ) {
    // Check if the current user has a specific role that should not capture data.
    // For example, if you don't want 'subscriber' role to save Tincanny data.
    if ( current_user_can( 'subscriber' ) ) {
        // If the user has the 'subscriber' role, prevent database capture.
        return false;
    }

    // Otherwise, allow the database capture to proceed as normal.
    return $allow_db_capture;
}
add_filter( 'tincanny_module_allow_db_capture', 'my_tincanny_restrict_db_capture_by_role', 10, 2 );

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/uncanny-tincan/classes/TinCanRequest.php:379

'target_name',
			'verb',
			'result',
			'maximum',
			'completion',
			'user_id'
		);
		$allow_db_capture = apply_filters( 'tincanny_module_allow_db_capture', true, $db_data );

		if ( true !== $allow_db_capture ) {
			return $db_data;
		}

		// Save
		$database = new Database();


Scroll to Top