sensei-certificates icon indicating copy to clipboard operation
sensei-certificates copied to clipboard

Add support for bulk downloading certificates

Open jenhooks opened this issue 6 years ago • 5 comments

The user in #1192327-zen has over 4,200 certificates that they need to download and save. Can we enable/add bulk downloading of certificates?

jenhooks avatar May 30 '18 14:05 jenhooks

+1 on forum thread: https://wordpress.org/support/topic/how-to-export-all-certificates/

@m1r0 is it worth logging this also in the Sensei repo or logging it here is enough?

StefMattana avatar Aug 07 '23 08:08 StefMattana

Here is good. Thanks, Stef.

m1r0 avatar Aug 07 '23 10:08 m1r0

Thank you all for looking into it! In the meantime - Does anyone know of any technique to download them all quickly (easier than clicking on each one?). Do you all know how I can get a list of all the certificate urls? I might be able to write a cron / php script to get them... (thinking out loud sorry) thank you all for your help 🙏

Tison avatar Aug 07 '23 13:08 Tison

Hey @Tison, the certificates are stored as posts so for getting all URLs, something like the following might do the trick:

add_action( 'wp_loaded', function () {
	$certificates = get_posts( [
		'post_type'      => 'certificate',
		'posts_per_page' => -1,
		'post_status'    => 'publish',
	] );

	foreach ( $certificates as $certificate ) {
		$url = get_permalink( $certificate->ID ); // -> https://sensei.test/certificate/5370cfee/
	}
} );

For generating the PDFs, you can try:

$hash = get_post_meta( $certificate->ID, 'certificate_hash', true );
$pdf  = new WooThemes_Sensei_PDF_Certificate( $hash );
$pdf->generate_pdf();

Hope this helps. 🙂

m1r0 avatar Aug 09 '23 12:08 m1r0

@m1r0 This is helpful in the meantime! I will give it a try, thank you

Tison avatar Aug 09 '23 18:08 Tison