uo_download_certificates_allow_clear
Filters whether the option to clear downloaded certificates should be allowed after download.
add_filter( 'uo_download_certificates_allow_clear', $callback, 10, 1 );
Description
Controls whether to allow clearing previous certificate runs for bulk downloads. Developers can filter this boolean to conditionally enable or disable the "clear previous runs" option, useful for custom logic or integrations. Defaults to 'yes' if the `allow-clear` attribute is set to 'yes'.
Usage
add_filter( 'uo_download_certificates_allow_clear', 'your_function_name', 10, 1 );
Parameters
-
$allow_clear(mixed) - This parameter determines whether or not to allow the clearing of previous download certificate runs.
Return Value
The filtered value.
Examples
/**
* Example: Conditionally disable the "Clear previous runs" option based on user role.
*
* This filter allows developers to control whether the "Allow clear previous runs"
* checkbox is displayed or functional. In this example, we'll disable it for
* administrators to prevent them from accidentally clearing all user data.
*/
add_filter(
'uo_download_certificates_allow_clear',
function ( $allow_clear ) {
// Check if the current user has the 'administrator' role.
if ( current_user_can( 'administrator' ) ) {
// If they are an administrator, force the option to 'no'
// to prevent clearing previous runs.
return 'no';
}
// Otherwise, return the original value passed to the filter.
return $allow_clear;
},
10, // Priority: Default priority.
1 // Accepted Args: The number of arguments the filter callback accepts.
);
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:1207
<?php // Dynamic labels.
$group_label = LearnDash_Custom_Label::get_label( 'group' );
$course_label = LearnDash_Custom_Label::get_label( 'course' );
$quiz_label = LearnDash_Custom_Label::get_label( 'quiz' );
// Add Allow clear previous runs checkbox
$allow_clear = 'yes' === strtolower( $atts['allow-clear'] ) ? 'yes' : 'no';
$allow_clear = apply_filters( 'uo_download_certificates_allow_clear', $allow_clear );
?>
<div id="uo_download_certificates">
<div class="uo-grid-wrapper" id="uo_certificatesdropdown">
<div class="ultp-download-certificates-filter uo-dropdowns-certificates"
id="ultp-download-certificates-filter-type">
<label