uo_group_certificate_upload_dir
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 Filters the directory where group certificates are saved, allowing customization of the save path with user, group, and certificate details.
add_filter( 'uo_group_certificate_upload_dir', $callback, 10, 3 );
Description
Filters the directory where group completion certificates are saved. This hook allows developers to dynamically alter the save path based on user, group ID, certificate post, and timestamp, ensuring backward compatibility by accepting multiple arguments. Use this to customize certificate storage locations.
Usage
add_filter( 'uo_group_certificate_upload_dir', 'your_function_name', 10, 3 );
Parameters
-
$save_path(mixed) - - **$user** `mixed`
-
$group_id(mixed) - - **$certificate_post** `mixed`
-
$current_time_stamp(mixed)
Return Value
The filtered value.
Examples
// Add a custom directory for group certificates based on user ID.
add_filter( 'uo_group_certificate_upload_dir', function( $save_path, $user, $group_id, $certificate_post, $current_time_stamp ) {
// Ensure the user object is valid.
if ( ! is_a( $user, 'WP_User' ) ) {
return $save_path; // Return original path if user is not a WP_User object.
}
// Define a subdirectory structure like uploads/group-certificates/user-id/
$custom_subdir = 'group-certificates/' . $user->ID . '/';
// Construct the full path.
$new_save_path = trailingslashit( $save_path['basedir'] ) . $custom_subdir;
// Ensure the directory exists.
if ( ! wp_mkdir_p( $new_save_path ) ) {
return $save_path; // Return original path if directory creation fails.
}
// Update the $save_path array with the new directory information.
$save_path['path'] = $new_save_path;
$save_path['url'] = trailingslashit( $save_path['baseurl'] ) . $custom_subdir;
$save_path['basedir'] = $new_save_path; // Update basedir as well for consistency.
return $save_path;
}, 10, 5 );
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:280
* to previous filter above might break sites since
* there might be no argument supplied with override function
*
* @since 3.6.4
* @author Saad
* @var $save_path
*/
$save_path = apply_filters( 'uo_group_certificate_upload_dir', $save_path, $user, $group_id, $certificate_post, self::$current_time_stamp );
$group_cert_meta = '_uo-group-cert-' . $group_id;
/* Creating a fileName that is going to be stored on the server. Certificate-QUIZID-USERID-NONCE_String */
$file_name = sanitize_title( $user->user_email . '-' . $group_id . '-' . $certificate_post . '-' . date( 'Ymd', self::$current_time_stamp ) . '-' . wp_create_nonce( self::$current_time_stamp ) );
//Allow overwrite of custom filename