uo_quiz_certificate_save_path
Filters the save path for user quiz certificates, allowing customization of where they are stored.
add_filter( 'uo_quiz_certificate_save_path', $callback, 10, 1 );
Description
This filter allows developers to customize the directory where generated user quiz certificates are saved. The default path is `WP_CONTENT_DIR . '/uploads/user-certificates/'`. Modify this filter to specify an alternative location for certificate storage.
Usage
add_filter( 'uo_quiz_certificate_save_path', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'uo_quiz_certificate_save_path', 'my_custom_certificate_save_path', 10, 1 );
/**
* Custom function to change the default save path for user certificates.
*
* This filter allows developers to specify a different directory
* where generated user certificates should be stored.
*
* @param string $default_save_path The default save path provided by the plugin.
* @return string The modified save path.
*/
function my_custom_certificate_save_path( $default_save_path ) {
// Example: Append a sub-directory based on the current year and month for better organization.
$year_month = date( 'Y/m' );
$custom_path = trailingslashit( $default_save_path ) . $year_month . '/';
// Ensure the custom directory exists, creating it if necessary.
if ( ! file_exists( $custom_path ) ) {
wp_mkdir_p( $custom_path );
}
return $custom_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/generate-p-d-f-email.php:121
}
self::$current_time_stamp = $current_time;
do_action( 'uo_quiz_completion_time', self::$current_time_stamp, $post->ID );
$certificate_post = $setup_parameters['certificate-post'];
$save_path = apply_filters( 'uo_quiz_certificate_save_path', WP_CONTENT_DIR . '/uploads/user-certificates/' );
$completion_time = self::$current_time_stamp;
$quiz_title = html_entity_decode( get_the_title( $post->ID ) );
/* Creating a fileName that is going to be stored on the server. Certificate-QUIZID-USERID-NONCE_String */
$file_name = sanitize_title( $current_user->ID . '-' . $quiz_title . '-' . wp_create_nonce( $completion_time ) );
$file_name = apply_filters( 'uo_quiz_completion_certificate_filename', $file_name, $current_user->ID, $quiz_id, $certificate_post, self::$current_time_stamp );
if ( ! file_exists( $save_path ) && ! mkdir( $save_path, 0755 ) && ! is_dir( $save_path ) ) {