uo_download_certificates_user_can_download
Filters whether a user can download certificates, allowing modification of the download permission.
add_filter( 'uo_download_certificates_user_can_download', $callback, 10, 2 );
Description
Filters whether a user has permission to download certificates. Modify this filter to programmatically grant or deny download access based on custom user roles, capabilities, or other conditions beyond the default role check. This hook fires before the download process is initiated.
Usage
add_filter( 'uo_download_certificates_user_can_download', 'your_function_name', 10, 2 );
Parameters
-
$can_download_modules(mixed) - This parameter is a boolean that indicates whether the current user is allowed to download certificates.
-
$user(mixed) - This parameter indicates whether the user is allowed to download certificates based on their role.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'uo_download_certificates_user_can_download' hook.
* This example grants download permission to users with the 'editor' role
* in addition to the default roles checked by the plugin.
*/
add_filter( 'uo_download_certificates_user_can_download', function( $can_download_modules, $user ) {
// Check if the user is already allowed to download based on existing logic.
// If so, no need to modify further.
if ( $can_download_modules ) {
return $can_download_modules;
}
// Define an additional role that should have download permission.
$additional_allowed_role = 'editor';
// Check if the user has the additional allowed role.
if ( user_can( $user, $additional_allowed_role ) ) {
return true; // User has the additional role, so they can download.
}
// If none of the conditions are met, return the original value.
return $can_download_modules;
}, 10, 2 );
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:1175
$can_download = in_array( $allowed_role, (array) $user->roles, true );
if( $can_download ) {
$can_download_modules = true;
break;
}
}
$can_download_modules = apply_filters( 'uo_download_certificates_user_can_download', $can_download_modules, $user );
// Check if it has enough space
$does_has_enough_space = self::uo_check_disk_space() >= 2;
// Create error message
$error_message = '';
if ( ! $can_download_modules ) {