uo_group_certificate_save_path
Filters the directory path where group certificates are saved.
add_filter( 'uo_group_certificate_save_path', $callback, 10, 1 );
Description
Allows developers to customize the server directory where group completion certificates are saved. By default, certificates are stored in `WP_CONTENT_DIR . '/uploads/group-certificates/'`. Use this filter to dynamically change the save path, for example, to a custom directory or a different storage location.
Usage
add_filter( 'uo_group_certificate_save_path', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uo_group_certificate_save_path' filter hook.
* This example modifies the default save path for group certificates to include a subdirectory
* based on the current year and month, helping to organize certificates chronologically.
*/
add_filter(
'uo_group_certificate_save_path',
function( $default_save_path ) {
// Ensure the default path ends with a slash for consistent concatenation.
$default_save_path = trailingslashit( $default_save_path );
// Get the current year and month.
$current_year = date( 'Y' );
$current_month = date( 'm' );
// Construct the new, organized save path.
$organized_save_path = $default_save_path . $current_year . '/' . $current_month . '/';
// Create the directory if it doesn't exist. This is good practice to ensure the path is writable.
if ( ! wp_mkdir_p( $organized_save_path ) ) {
// If directory creation fails, fall back to the default path to avoid errors.
// In a real-world scenario, you might want to log this error or handle it more robustly.
return $default_save_path;
}
// Return the newly constructed and potentially created save path.
return $organized_save_path;
},
10, // Priority: 10 is the default, meaning it runs at the normal order.
1 // Accepted Args: 1, as the filter passes only the default save path.
);
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/group-completion-certificate.php:270
if ( 1 !== (int) $setup_parameters['print-certificate'] ) {
return;
}
$certificate_post = $setup_parameters['certificate-post'];
/* Save Path on Server under Upload & allow overwrite */
$save_path = apply_filters( 'uo_group_certificate_save_path', WP_CONTENT_DIR . '/uploads/group-certificates/' );
/**
* New filter added so that arguments can be passed. Adding arguments
* to previous filter above might break sites since
* there might be no argument supplied with override function
*
* @since 3.6.4
* @author Saad