uo_tincanny_tincan_xapi_report_date_range_type
Filters the Xapi report date range type, allowing customization before it's applied to the request.
add_filter( 'uo_tincanny_tincan_xapi_report_date_range_type', $callback, 10, 1 );
Description
This filter allows developers to modify the date range parameter used for XAPI reports. It's applied before the date range is processed and stored, enabling custom date filtering logic or validation. The `$request` parameter contains the current request object.
Usage
add_filter( 'uo_tincanny_tincan_xapi_report_date_range_type', 'your_function_name', 10, 1 );
Parameters
-
$request(mixed) - This parameter contains the request object, which is used to access and process incoming data from the user's request.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the uo_tincanny_tincan_xapi_report_date_range_type filter.
*
* This filter allows you to modify the date range type returned by the Tincanny plugin.
* For example, you might want to add a custom date range option or change how an existing
* option is interpreted.
*/
add_filter(
'uo_tincanny_tincan_xapi_report_date_range_type',
'my_custom_tincanny_date_range',
10, // Priority: 10 is the default, adjust if needed.
1 // Accepted arguments: The filter expects one argument.
);
/**
* Custom function to handle the date range type.
*
* @param string $date_range The raw date range value from the request.
* @return string The modified or validated date range type.
*/
function my_custom_tincanny_date_range( $date_range ) {
// Let's assume the original $date_range could be 'last', 'custom', or something else.
// We'll add a new option 'this_week' and ensure existing ones are handled.
$allowed_ranges = array(
'last', // Example: Last N days/weeks/months
'custom', // Example: Specific start and end dates
'this_week', // Our new custom option
'this_month',// Another example
);
// Sanitize and normalize the input to lowercase for easier comparison.
$sanitized_date_range = strtolower( sanitize_text_field( $date_range ) );
// If the sanitized date range is one of our allowed options, return it.
if ( in_array( $sanitized_date_range, $allowed_ranges, true ) ) {
return $sanitized_date_range;
}
// If it's not an allowed range, we can either:
// 1. Default to a safe value (e.g., 'last').
// 2. Return an empty string or null to indicate no specific range should be applied (and let other logic handle it).
// For this example, let's default to 'last' to ensure a range is always applied if not specified correctly.
return 'last';
}
?>
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/shortcode-tincanny/shortcode-tincanny.php:553
// Result
if ( $request->has_param( 'tc_filter_results' ) && ! empty( $request->get_param( 'tc_filter_results' ) ) ) {
self::$tincan_database->results = strtolower( sanitize_text_field( $request->get_param( 'tc_filter_results' ) ) );
}
// Date
if ( $request->has_param( 'tc_filter_date_range' ) && ! empty( $request->get_param( 'tc_filter_date_range' ) ) ) {
$date_range = apply_filters( 'uo_tincanny_tincan_xapi_report_date_range_type', sanitize_text_field( $request->get_param( 'tc_filter_date_range' ) ) );
$current_time = current_time( 'timestamp' ); // Current timestamp
switch ( $date_range ) {
case 'last':
if ( $request->has_param( 'tc_filter_date_range_last' ) && ! empty( $request->get_param( 'tc_filter_date_range_last' ) ) ) {
$date_range_last = apply_filters( 'uo_tincanny_tincan_xapi_report_date_range_last_type', sanitize_text_field( $request->get_param( 'tc_filter_date_range_last' ) ) );
switch ( $date_range_last ) {