uo_download_certificates_in_bulk_group_data
Filters the grouped data used for bulk downloading certificates before it is processed.
add_filter( 'uo_download_certificates_in_bulk_group_data', $callback, 10, 2 );
Description
Filters the data used to generate groups for bulk certificate downloads. Developers can modify the `$results` or `$data` to alter which groups are available or how they are presented to the user. This hook fires within the REST API endpoint for retrieving group data.
Usage
add_filter( 'uo_download_certificates_in_bulk_group_data', 'your_function_name', 10, 2 );
Parameters
-
$results(mixed) - This parameter contains the results of the bulk certificate download, which can be modified by the filter.
-
$data(mixed) - This parameter contains the processed group data that has been formatted for display in a dropdown.
Return Value
The filtered value.
Examples
// Modify the group data for bulk certificate downloads, potentially filtering by user or specific criteria.
add_filter( 'uo_download_certificates_in_bulk_group_data', function( $results, $data ) {
// Example: If the $data array contains a 'filter_by_course' key,
// only return groups associated with that specific course.
if ( isset( $data['filter_by_course'] ) && ! empty( $data['filter_by_course'] ) ) {
$filtered_results = array();
$target_course_id = absint( $data['filter_by_course'] );
if ( ! empty( $results ) && is_array( $results ) ) {
foreach ( $results as $group_id => $group_info ) {
// Assuming $group_info['course_id'] exists and holds the course ID for the group.
// This is a hypothetical structure; adjust based on actual $results format.
if ( isset( $group_info['course_id'] ) && $group_info['course_id'] === $target_course_id ) {
$filtered_results[ $group_id ] = $group_info;
}
}
}
$results = $filtered_results;
}
// Example: Add a custom field to each group if it's a specific type.
if ( ! empty( $results ) && is_array( $results ) ) {
foreach ( $results as $group_id => &$group_info ) {
if ( isset( $group_info['group_type'] ) && 'special_group' === $group_info['group_type'] ) {
$group_info['custom_note'] = 'This is a special group requiring extra attention.';
}
}
unset( $group_info ); // Unset the reference
}
// Always return the modified or original results.
return $results;
}, 10, 2 ); // Priority 10, accepts 2 arguments ($results, $data)
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:364
public static function uo_generate_groups_dropdowns( $request ) {
// check if its a valid request.
$data = $request->get_params();
if ( isset( $data['action'] ) && 'get_uo_groups' === $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_group_list( $data['certificates'], $data['uo_current_user'], $data );
$results = apply_filters( 'uo_download_certificates_in_bulk_group_data', $results, $data );
$return = array();
$return['success'] = false;
if ( ! empty( $results ) ) {
$return['success'] = true;
$return['data'] = $results;
} else {
$return['msg'] = __( 'Sorry, no groups are available for you to manage.', 'uncanny-pro-toolkit' );
}
return new WP_REST_Response(
$return,
200
);
}
return new WP_REST_Response(
array(
'msg' => 'Certificate ID or groups not found.',
'success' => false,
),
200
);
}