uo_tincanny_tincan_xapi_report_date_end
Filters the end date of the XAPI report for Tincanny, allowing for customization of the reporting period.
add_filter( 'uo_tincanny_tincan_xapi_report_date_end', $callback, 10, 1 );
Description
Filters the end date parameter for XAPI reports. Allows developers to modify or override the default end date derived from the 'tc_filter_end' request parameter. The hook fires before the date is applied to the report query, providing an opportunity for custom date formatting or validation.
Usage
add_filter( 'uo_tincanny_tincan_xapi_report_date_end', 'your_function_name', 10, 1 );
Parameters
-
$request(mixed) - This parameter contains the request object from which the end date filter parameter 'tc_filter_end' is retrieved.
Return Value
The filtered value.
Examples
/**
* Example function to modify the end date for Xapi reports.
*
* This function demonstrates how to hook into 'uo_tincanny_tincan_xapi_report_date_end'
* to adjust the end date parameter used for filtering Xapi reports.
* In this example, we'll ensure the end date is set to the very end of the day
* if a date is provided, or fall back to the current date if no filter is applied.
*
* @param string $request_date_end The date string passed in the request, potentially empty.
* @return string The modified end date string.
*/
add_filter( 'uo_tincanny_tincan_xapi_report_date_end', function( $request_date_end ) {
// If a date was provided in the request and it's not empty,
// we've already added '23:59:59' in the main code.
// So, we just return it as is to preserve that.
if ( ! empty( $request_date_end ) ) {
return $request_date_end;
}
// If no date was provided in the request, default to the current date
// and set the time to the end of the day. This ensures that if no
// specific end date is filtered, the report includes data up to the
// current moment.
return date( 'Y-m-d H:i:s', strtotime( 'today' ) + DAY_IN_SECONDS - 1 );
}, 10, 1 );
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:600
if ( $request->has_param( 'tc_filter_end' ) && ! empty( $request->get_param( 'tc_filter_end' ) ) ) {
self::$tincan_database->dateEnd = sanitize_text_field( $request->get_param( 'tc_filter_end' ) ) . ' 23:59:59';
}
break;
case 'custom':
self::$tincan_database->dateStart = apply_filters( 'uo_tincanny_tincan_xapi_report_date_start', sanitize_text_field( $request->get_param( 'tc_filter_start' ) ) );
self::$tincan_database->dateEnd = apply_filters( 'uo_tincanny_tincan_xapi_report_date_end', sanitize_text_field( $request->get_param( 'tc_filter_end' ) ) );
break;
}
}
}
/**
* @return void