uo_tincanny_reporting_upload_path
Filters the upload path for Tincanny reporting data before it is saved or accessed.
add_filter( 'uo_tincanny_reporting_upload_path', $callback, 10, 1 );
Description
Filters the base upload URL for Tincanny reporting files. Developers can modify this URL to point to a custom directory or storage location for uploaded course content. This hook fires when Tincanny initially determines its reporting upload directory. Ensure the modified path is accessible by WordPress.
Usage
add_filter( 'uo_tincanny_reporting_upload_path', 'your_function_name', 10, 1 );
Parameters
-
$upload_url(mixed) - This parameter contains the base URL for uploads, including the directory name for Uncanny Toolkit's Articulate and Captivate content.
Return Value
The filtered value.
Examples
/**
* Modify the upload path for Tincanny reporting if the site is using a CDN.
*
* By default, Tincanny reports are stored in the WordPress uploads directory.
* If a CDN is configured, we might want to point to the CDN URL instead.
*
* @param string $upload_url The default upload URL.
* @return string The modified upload URL.
*/
add_filter( 'uo_tincanny_reporting_upload_path', function( $upload_url ) {
// Check if a CDN URL is configured for media uploads.
// This is a common scenario for sites using a CDN.
$cdn_url = get_option( 'wp_cdn_url' ); // Assuming a custom option for CDN URL
if ( ! empty( $cdn_url ) ) {
// Replace the default WordPress upload URL with the CDN URL.
// We need to ensure we're replacing the correct part of the URL.
$wp_upload_dir = wp_upload_dir();
$base_url = $wp_upload_dir['baseurl'];
// Only replace if the $upload_url actually starts with the WordPress base URL.
// This prevents unexpected replacements if $upload_url is already something else.
if ( strpos( $upload_url, $base_url ) === 0 ) {
// Construct the new URL using the CDN URL and the relative path.
$relative_path = str_replace( $base_url, '', $upload_url );
return trailingslashit( $cdn_url ) . $relative_path;
}
}
// If no CDN is configured or the URL structure doesn't match, return the original.
return $upload_url;
}, 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/uncanny-articulate-and-captivate/classes/FileSystem/traitModule.php:54
static protected function get_url_path() {
if ( ! self::$upload_url ) {
$wp_upload_dir = wp_upload_dir();
self::$upload_url = $wp_upload_dir['baseurl'] . '/' . SnC_UPLOAD_DIR_NAME;
// some edge case sites not returning proper http
self::$upload_url = is_ssl() ? str_replace( 'http://', 'https://', self::$upload_url ) : self::$upload_url;
self::$upload_url = str_replace( get_site_url(), '', self::$upload_url );
}
return apply_filters( 'uo_tincanny_reporting_upload_path', self::$upload_url );
}