Filter tin-canny-learndash-reporting

uo_tincanny_tincan_xapi_report_date_start

Filters the start date of the XAPI report to allow modification before it's generated.

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

Description

Filters the start date for XAPI reports when a custom date range is selected. Developers can modify the default start date sanitization or alter its format before it's used to query XAPI data. The `$request` parameter provides access to the original filtered start date.


Usage

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

Parameters

$request (mixed)
This parameter contains the request object from which filter parameters can be retrieved.

Return Value

The filtered value.


Examples

/**
 * Adjust the XAPI report start date if a specific date format is required.
 *
 * This filter allows for modification of the default start date format
 * for XAPI reports. For instance, if the system expects a UNIX timestamp
 * instead of a formatted date string, this filter can be used to convert it.
 *
 * @param string $request The raw start date parameter from the request.
 * @return string The potentially modified start date string.
 */
add_filter( 'uo_tincanny_tincan_xapi_report_date_start', function( $request ) {
    // Example: Convert the date to a UNIX timestamp if it's in YYYY-MM-DD format.
    // This assumes the underlying system might need a timestamp for date comparisons.
    if ( preg_match( '/^d{4}-d{2}-d{2}$/', $request ) ) {
        // Attempt to create a DateTime object and get the timestamp.
        $date_obj = DateTime::createFromFormat( 'Y-m-d', $request );
        if ( $date_obj ) {
            return $date_obj->getTimestamp();
        }
    }

    // If no specific conversion is needed or the format is unexpected, return the original.
    return $request;
}, 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:599

}

					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;
			}
		}
	}

	/**


Scroll to Top