Filter uncanny-toolkit-pro

uo_quiz_completion_generate_pdf_args

Filters arguments used to generate a PDF certificate after a quiz is completed.

add_filter( 'uo_quiz_completion_generate_pdf_args', $callback, 10, 1 );

Description

Filters the arguments used to generate a PDF certificate upon quiz completion. Developers can modify parameters like the filename, saving path, or other PDF generation settings to customize the output. This hook fires before the PDF is actually created.


Usage

add_filter( 'uo_quiz_completion_generate_pdf_args', 'your_function_name', 10, 1 );

Parameters

$certificate_post (mixed)
This parameter contains the WordPress post object representing the generated certificate.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into 'uo_quiz_completion_generate_pdf_args'
 * to modify the arguments used for generating a quiz completion PDF.
 *
 * In this example, we'll add a custom watermark text to the PDF.
 */
add_filter( 'uo_quiz_completion_generate_pdf_args', function( $args ) {

    // Ensure we have a valid certificate post object to work with.
    if ( ! isset( $args['certificate_post'] ) || ! $args['certificate_post'] instanceof WP_Post ) {
        return $args; // Return original args if no valid certificate post.
    }

    // Add a custom watermark argument.
    // This assumes the PDF generation library being used by the plugin
    // supports a 'watermark' argument.
    $args['watermark_text'] = 'Confidential - ' . get_the_title( $args['certificate_post'] );

    // Optionally, you could also modify the save path or file name here.
    // For instance, to add a prefix to the file name:
    // $args['file_name'] = 'processed-' . $args['file_name'];

    return $args;
}, 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.
?>

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:132

$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 ) ) {
			throw new RuntimeException( sprintf( 'Directory "%s" was not created', $save_path ) );
		}

		$generate_pdf_args = apply_filters(
			'uo_quiz_completion_generate_pdf_args',
			array(
				'certificate_post' => $certificate_post,
				'save_path'        => $save_path,
				'file_name'        => $file_name,
				'quiz_id'          => $quiz_id,
				'completion_time'  => $completion_time,


Scroll to Top