uo_course_certificate_save_path
Filters the save path for generated course certificates before they are saved to the filesystem.
add_filter( 'uo_course_certificate_save_path', $callback, 10, 1 );
Description
Allows developers to modify the default directory where course completion certificates are saved. This filter fires before a certificate file path is finalized, enabling custom save locations. Ensure the provided path is writable by the web server.
Usage
add_filter( 'uo_course_certificate_save_path', 'your_function_name', 10, 1 );
Parameters
-
$save_path(mixed) - This parameter represents the filesystem path where course certificates will be saved.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Change the default save path for course certificates to a custom subdirectory.
*
* This filter hook allows developers to modify the directory where course certificates
* are saved. The default path is typically within the WordPress uploads directory.
* This example demonstrates how to append a custom subfolder named 'my-custom-certificates'.
*
* @param string $save_path The current save path for course certificates.
* @return string The modified save path.
*/
add_filter( 'uo_course_certificate_save_path', 'my_custom_certificate_save_path', 10, 1 );
function my_custom_certificate_save_path( $save_path ) {
// Ensure the save path ends with a slash before appending the custom directory.
$save_path = trailingslashit( $save_path );
// Append a custom subdirectory.
$custom_directory = 'my-custom-certificates/';
// Return the modified save path.
return $save_path . $custom_directory;
}
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/course-completion-certificate.php:268
$upload_dir = wp_upload_dir();
if ( ! empty( $upload_dir['basedir'] ) ) {
$save_path = trailingslashit( $upload_dir['basedir'] ) . 'course-certificates/';
} else {
// Fallback to WP_CONTENT_DIR if basedir is unavailable
$save_path = trailingslashit( WP_CONTENT_DIR . '/uploads' ) . 'course-certificates/';
}
$save_path = apply_filters( 'uo_course_certificate_save_path', $save_path );
/**
* 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