uo_tincanny_reporting_sanitize_suspend_data
Filters the data being suspended for Tincanny reporting to allow modification before it's saved.
add_filter( 'uo_tincanny_reporting_sanitize_suspend_data', $callback, 10, 2 );
Description
Filters the data being suspended for Tincan reporting. Developers can modify or validate the suspended data before it's saved, allowing for custom logic or data enrichment. The hook receives the data to be suspended, the module ID, and the request method ('GET').
Usage
add_filter( 'uo_tincanny_reporting_sanitize_suspend_data', 'your_function_name', 10, 2 );
Parameters
-
$return(mixed) - This parameter contains the data that has been sanitized and is ready to be returned.
-
$module_id_value(mixed) - This parameter holds the data that has already been processed and is ready to be returned, allowing it to be further modified before being saved.
Return Value
The filtered value.
Examples
add_filter( 'uo_tincanny_reporting_sanitize_suspend_data', 'my_custom_tincanny_suspend_data_sanitization', 10, 3 );
/**
* Custom sanitization function for Tincanny suspend data.
*
* This example demonstrates how to modify the suspend data before it's returned.
* For instance, you might want to remove personally identifiable information (PII)
* or specific fields that shouldn't be stored long-term.
*
* @param mixed $return The suspend data to be sanitized.
* @param mixed $module_id_value The ID of the module the suspend data belongs to.
* @param string $request_type The type of request (e.g., 'GET').
*
* @return mixed The sanitized suspend data.
*/
function my_custom_tincanny_suspend_data_sanitization( $return, $module_id_value, $request_type ) {
// Only apply sanitization if it's a GET request and the data is not empty.
if ( 'GET' === $request_type && ! empty( $return ) ) {
// Attempt to decode the suspend data, assuming it's JSON.
$decoded_data = json_decode( $return, true );
// If decoding was successful and it's an array
if ( is_array( $decoded_data ) ) {
// Example: Remove a specific key like 'user_email' if it exists.
if ( isset( $decoded_data['user_email'] ) ) {
unset( $decoded_data['user_email'] );
}
// Example: Remove another key like 'temporary_token'.
if ( isset( $decoded_data['temporary_token'] ) ) {
unset( $decoded_data['temporary_token'] );
}
// Re-encode the data back to JSON.
$return = json_encode( $decoded_data );
}
// If the data is not JSON but needs cleaning, you'd handle it differently here.
// For instance, if it was a simple string, you might use str_replace or regex.
}
return $return;
}
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/Database/State.php:76
src/uncanny-tincan/classes/Database/State.php:101
src/uncanny-tincan/classes/Database/State.php:136
public function get_state( $url, $state_id ) {
global $wpdb;
if ( ! $this->set_user_id() ) {
return false;
}
// Sync table columns
$this->add_course_lesson_columns();
// Get course and lesson id from request
list( $course_id, $lesson_id ) = $this->fetch_course_lesson_ids();
$module_id = $this->get_slide_id_from_url( $url );
$table_name = $wpdb->prefix . self::TABLE_RESUME;
$module_id_value = isset( $module_id[1] ) ? $module_id[1] : '';
// SELECT with course and lesson ids
$query = $wpdb->prepare(
"SELECT `value` FROM {$table_name}
WHERE
`user_id` = %s AND
`module_id` = %s AND
`course_id` = %s AND
`lesson_id` = %s AND
`state` = %s
LIMIT 1
",
self::$user_id,
$module_id_value,
$course_id,
$lesson_id,
$state_id
);
$return = $wpdb->get_var( $query );
if ( ! empty( $return ) ) {
if ( 'suspend_data' === $state_id ) {
$return = apply_filters( 'uo_tincanny_reporting_sanitize_suspend_data', $return, $module_id_value, 'GET' );
}
return $return;
}
$fallback_query = apply_filters( 'uo_tincanny_reporting_get_state_fallback_query', true, $module_id_value );
if ( true === $fallback_query ) {
$query = $wpdb->prepare(
"SELECT `value` FROM {$table_name}
WHERE
`user_id` = %s AND
`module_id` = %s AND
`state` = %s
LIMIT 1
",
self::$user_id,
$module_id_value,
$state_id
);
$return = $wpdb->get_var( $query );
if ( ! empty( $return ) ) {
if ( 'suspend_data' === $state_id ) {
$return = apply_filters( 'uo_tincanny_reporting_sanitize_suspend_data', $return, $module_id_value, 'GET' );
}
return $return;
}
}
return null;
}