uo_download_certificates_in_bulk_course_data
Filters the course data used for bulk certificate downloads, allowing modification before processing.
add_filter( 'uo_download_certificates_in_bulk_course_data', $callback, 10, 2 );
Description
Filters the course data array before it's returned for bulk certificate downloads. Developers can modify the course data (e.g., add/remove courses, alter data points) passed to the frontend for the bulk certificate generation process.
Usage
add_filter( 'uo_download_certificates_in_bulk_course_data', 'your_function_name', 10, 2 );
Parameters
-
$results(mixed) - This parameter contains the results of the bulk download operation, which can be modified by the filter.
-
$data(mixed) - This parameter contains the data that will be returned by the filter.
Return Value
The filtered value.
Examples
add_filter(
'uo_download_certificates_in_bulk_course_data',
'my_custom_course_certificate_data_filter',
10,
2
);
/**
* Example filter to modify course data for bulk certificate downloads.
*
* This function demonstrates how to alter the course data returned by the
* default Uncanny Owl function. In this example, we'll add a custom
* field to each course result, indicating if a specific certificate type
* is available for it.
*
* @param array $results The original array of course data.
* @param array $data The original request data passed to the filter.
*
* @return array The modified array of course data.
*/
function my_custom_course_certificate_data_filter( $results, $data ) {
// Check if we have any results to process.
if ( empty( $results ) ) {
return $results;
}
// Assuming $data['certificates'] contains an array of certificate IDs or names
// that we want to check availability for.
$allowed_certificates = isset( $data['certificates'] ) ? (array) $data['certificates'] : array();
// Iterate through each course result and add our custom field.
foreach ( $results as &$course_item ) {
// Example: Add a boolean flag indicating if a specific certificate is "available".
// In a real scenario, you'd likely have a more complex logic here,
// perhaps querying post meta or another data source to determine availability.
$course_item['has_specific_certificate'] = false;
// For demonstration, let's assume a certificate named 'advanced-quiz-cert'
// is the one we're interested in checking.
if ( in_array( 'advanced-quiz-cert', $allowed_certificates, true ) ) {
// Here you would implement logic to check if this specific certificate
// is actually associated with or generatable for this $course_item.
// For now, we'll just set it to true if it's in the requested list.
$course_item['has_specific_certificate'] = true;
}
// You could also add other custom fields or modify existing ones.
// For example, modifying the course title:
// $course_item['title'] = 'Modified: ' . $course_item['title'];
}
// Return the modified results array.
return $results;
}
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:412
public static function uo_generate_courses_dropdowns( $request ) {
// check if its a valid request.
$data = $request->get_params();
if ( isset( $data['action'] ) && 'get_uo_courses' === $data['action'] ) {
if ( ! self::validate_user_id( $data ) ) {
return new WP_REST_Response(
array(
'msg' => __( 'You do not have sufficient permission to perform this action.', 'uncanny-pro-toolkit' ),
'success' => false,
),
200
);
}
$results = self::ld_get_courses_list( $data['group_id'], $data['certificates'], $data );
$results = apply_filters( 'uo_download_certificates_in_bulk_course_data', $results, $data );
$return = array();
$return['success'] = false;
if ( ! empty( $results ) ) {
$return['success'] = true;
$return['data'] = $results;
} else {
$return['msg'] = __( 'Sorry, no certificates were found for courses in the selected group. Please choose another group.', 'uncanny-pro-toolkit' );
}
return new WP_REST_Response(
$return,
200
);
}
return new WP_REST_Response(
array(
'msg' => 'No group ID passed or courses not found.',
'success' => false,
),
200
);
}