Filter uncanny-toolkit-pro

uo_download_certificates_in_bulk_folder

Generate group certificates method. Filters the directory path where bulk group certificates are generated and saved.

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

Description

Filters the folder path used for bulk certificate downloads. Developers can modify this path to save generated certificates in a custom directory. This hook fires during the group certificate generation process. Ensure the provided path is writable by the web server.


Usage

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

Return Value

void public static function generate_group_certificate( $user_id, $object_id, $batch_id, $type = 'group' ) { $user = new WP_User( $user_id ); $setup_parameters = self::setup_parameters( $object_id, $user_id, $type ); if ( 1 !== (int) $setup_parameters['print-certificate'] ) { return; } self::$current_time_stamp = time(); $new_folder = '/bulk_export_' . $type . '_' . date_i18n( 'Y-m-d' ) . '_' . $batch_id . '/'; $certificate_post = $setup_parameters['certificate-post']; Save Path on Server under Upload & allow overwrite */


Examples

// Example of how to filter the default bulk certificate folder path.
// This example appends a user ID specific subfolder to the default path.
add_filter( 'uo_download_certificates_in_bulk_folder', 'my_custom_bulk_certificates_folder', 10, 1 );

/**
 * Custom function to modify the bulk certificate download folder.
 *
 * @param string $default_folder The default folder path.
 * @return string The modified folder path.
 */
function my_custom_bulk_certificates_folder( $default_folder ) {
    // In the context of the original function, $user_id is available.
    // We'll assume we can access it or a relevant identifier.
    // For demonstration, let's assume we want to create a subfolder per user.
    // In a real scenario, you might need to pass $user_id to this filter,
    // which would require modifying the hook's internal usage.
    // For now, we'll simulate a user ID.

    // Let's pretend we have access to the current user's ID.
    // This is a placeholder and might need adjustment based on how $user_id
    // is actually accessible within the context of the filter.
    // If the filter's context doesn't directly provide $user_id, you'd need
    // to get it via global $current_user or another mechanism if applicable.

    $current_user_id = get_current_user_id(); // Get the ID of the currently logged-in user.

    if ( $current_user_id ) {
        // Append a user-specific subfolder.
        return $default_folder . 'user_' . $current_user_id . '/';
    }

    // If no current user ID is found or it's not applicable, return the default.
    return $default_folder;
}

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/download-certificates-in-bulk.php:582
src/classes/download-certificates-in-bulk.php:704
src/classes/download-certificates-in-bulk.php:706
src/classes/download-certificates-in-bulk.php:1660
src/classes/download-certificates-in-bulk.php:1989

public static function generate_group_certificate( $user_id, $object_id, $batch_id, $type = 'group' ) {

		$user = new WP_User( $user_id );

		$setup_parameters = self::setup_parameters( $object_id, $user_id, $type );
		if ( 1 !== (int) $setup_parameters['print-certificate'] ) {
			return;
		}

		self::$current_time_stamp = time();
		$new_folder               = '/bulk_export_' . $type . '_' . date_i18n( 'Y-m-d' ) . '_' . $batch_id . '/';

		$certificate_post = $setup_parameters['certificate-post'];
		/* Save Path on Server under Upload & allow overwrite */
		$save_path = WP_CONTENT_DIR . apply_filters( 'uo_download_certificates_in_bulk_folder', '/uploads/bulk-certificates' ) . $new_folder;

		$uo_dir = WP_CONTENT_DIR . apply_filters( 'uo_download_certificates_in_bulk_folder', '/uploads/bulk-certificates' );
		if ( ! is_dir( $uo_dir ) ) {
			mkdir( $uo_dir, 0755 );
		}

		/**
		 * 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
		 * @var $save_path
		 */
		$save_path = apply_filters( 'uo_download_certificates_in_bulk_upload_dir', $save_path, $user, $object_id, $certificate_post, self::$current_time_stamp );

		/* Creating a fileName that is going to be stored on the server. Certificate-QUIZID-USERID-NONCE_String */
		$file_name = sanitize_title( $user->user_email . '-' . $object_id . '-' . $certificate_post . '-' . date_i18n( 'Y-m-d', self::$current_time_stamp ) . '-' . wp_create_nonce( self::$current_time_stamp ) );

		//Allow overwrite of custom filename
		$file_name = apply_filters( 'uo_download_certificates_in_bulk_filename', $file_name, $user, $object_id, $certificate_post, self::$current_time_stamp );
		if ( ! file_exists( $save_path ) && ! mkdir( $save_path, 0755 ) && ! is_dir( $save_path ) ) { // phpcs:ignore
			throw new RuntimeException( sprintf( 'Directory "%s" was not created', $save_path ) );
		}

		$full_path          = $save_path . $file_name;
		self::$pdf_filename = $full_path;

		//Allow PDF args to be modified
		$generate_pdf_args = apply_filters(
			'uo_download_certificates_in_bulk_pdf_args',
			array(
				'certificate_post' => $certificate_post,
				'save_path'        => $save_path,
				'user'             => $user,
				'file_name'        => $file_name,
				'parameters'       => $setup_parameters,
				'type'             => $type,
				'bulk_generator'   => 'yes',
			),
			$object_id,
			$user_id
		);
		self::generate_pdf( $generate_pdf_args, $type );
	}


Scroll to Top