uo_file_expiry_time
Filters the expiration time for uploaded files, allowing customization of how long files remain accessible.
add_filter( 'uo_file_expiry_time', $callback, 10, 1 );
Description
Filters the default file expiry time for downloaded certificates. Developers can use this hook to modify the default expiry duration (86400 seconds / 24 hours) before files are automatically deleted. This allows for custom expiry periods to suit specific needs.
Usage
add_filter( 'uo_file_expiry_time', 'your_function_name', 10, 1 );
Parameters
-
$file_expiry_time(mixed) - This parameter represents the duration in seconds after which a downloaded file will expire.
Return Value
The filtered value.
Examples
/**
* Customizes the expiry time for downloaded files.
*
* This example sets the file expiry time to 7 days (604800 seconds) if a
* specific user role ('premium_member') is detected. Otherwise, it uses the
* default expiry time.
*/
add_filter( 'uo_file_expiry_time', 'my_custom_file_expiry_time', 10, 1 );
function my_custom_file_expiry_time( $file_expiry_time ) {
// Get the current user.
$current_user = wp_get_current_user();
// Check if the user has the 'premium_member' role.
if ( in_array( 'premium_member', (array) $current_user->roles ) ) {
// Set expiry time to 7 days (7 * 24 * 60 * 60 seconds).
$new_expiry_time = 604800;
return $new_expiry_time;
}
// Return the original expiry time if the user is not a premium member.
return $file_expiry_time;
}
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/classes/download-certificates-in-bulk.php:135
public static function uo_file_expiry_time( $file_expiry_time = 86400 ) {
return apply_filters( 'uo_file_expiry_time', $file_expiry_time );
}