Filter uncanny-automator-pro

automator_certificate_save_path

Filters the default path for saving LearnDash certificates, allowing custom directory configurations.

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

Description

Filters the default save path for PDF certificates generated by Uncanny Automator Pro for LearnDash courses. Developers can modify this path to store certificates in a custom directory on the server, for example, for organizational or backup purposes. Ensure the specified directory is writable.


Usage

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

Return Value

The filtered value.


Examples

add_filter(
	'automator_certificate_save_path',
	'my_custom_certificate_save_path',
	10,
	1
);

/**
 * Changes the default save path for Uncanny Automator certificates to a custom directory.
 *
 * @param string $default_save_path The default save path provided by Uncanny Automator.
 * @return string The custom save path.
 */
function my_custom_certificate_save_path( $default_save_path ) {
	// Define your custom directory path.
	// It's recommended to use a subdirectory within uploads for organization.
	$custom_path = WP_CONTENT_DIR . '/my-custom-automator-certs/';

	// Ensure the custom directory exists.
	if ( ! is_dir( $custom_path ) ) {
		wp_mkdir_p( $custom_path ); // Use WordPress function for directory creation.
	}

	// Return the custom path to be used for saving certificates.
	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

uncanny-automator-pro/src/integrations/learndash/actions/ld-emailcertificate-a.php:257

if ( ! empty( $reply_to ) ) {
			$headers[] = "Reply-To: $reply_to";
		}

		$headers[] = 'Content-Type: text/html; charset=UTF-8';

		/* Save Path on Server under Upload & allow overwrite */
		$save_path = apply_filters( 'automator_certificate_save_path', WP_CONTENT_DIR . '/uploads/automator-certificates/' );

		if ( ! is_dir( $save_path ) ) {
			mkdir( $save_path, 0755 );
			// Prevent direct web access to certificate files.
			file_put_contents( $save_path . '.htaccess', "Order deny,allownDeny from alln" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
			file_put_contents( $save_path . 'index.php', '<?php // Silence is golden.' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
		}


Scroll to Top