Skip to content

Instantly share code, notes, and snippets.

@thomasplevy
Last active January 26, 2022 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasplevy/421aa2273384dc73b127be6b37cbcc67 to your computer and use it in GitHub Desktop.
Save thomasplevy/421aa2273384dc73b127be6b37cbcc67 to your computer and use it in GitHub Desktop.
<?php // don't copy this to functions.php file
/**
* Add custom merge codes to an LLMS certificate
* @param int $user_id WP_User ID
* @param int $cert_id WP_Post ID of the generated certificate
* @param int $related_post_id WP_Post ID of the post which triggered the certificate generation
* @return void
*/
function my_custom_cert_merge_codes( $user_id, $cert_id, $related_post_id ) {
$cert_post = get_post( $cert_id );
$content = str_replace( '{course_title}', get_the_title( $related_post_id ), $cert_post->post_content );
wp_update_post( array(
'ID' => $cert_id,
'post_content' => $content
) );
}
add_action( 'llms_user_earned_certificate', 'my_custom_cert_merge_codes', 999, 3 );
<?php // don't copy this to functions.php file
/**
* Add custom merge codes to an LLMS certificate
* @param int $user_id WP_User ID
* @param int $cert_id WP_Post ID of the generated certificate
* @param int $related_post_id WP_Post ID of the post which triggered the certificate generation
* @return void
*/
function my_custom_cert_merge_codes( $user_id, $cert_id, $related_post_id ) {
$cert_post = get_post( $cert_id );
$content = str_replace( '{your_merge_code}', get_user_meta( $user_id, 'your_user_meta_key', true ), $cert_post->post_content );
wp_update_post( array(
'ID' => $cert_id,
'post_content' => $content
) );
}
add_action( 'llms_user_earned_certificate', 'my_custom_cert_merge_codes', 999, 3 );
<?php // don't copy this to functions.php file
/**
* Add custom merge codes to an LLMS certificate
* @param int $user_id WP_User ID
* @param int $cert_id WP_Post ID of the generated certificate
* @param int $related_post_id WP_Post ID of the post which triggered the certificate generation
* @return void
*/
function my_custom_cert_merge_codes( $user_id, $cert_id, $related_post_id ) {
$cert_post = get_post( $cert_id );
$content = str_replace( '{student_id}', $user_id, $cert_post->post_content );
wp_update_post( array(
'ID' => $cert_id,
'post_content' => $content
) );
}
add_action( 'llms_user_earned_certificate', 'my_custom_cert_merge_codes', 999, 3 );
@lkchamorro
Copy link

Hi, I´m interested in use the files to my wordpress, but I don´t know about where located this file
Please help me about

@thomasplevy
Copy link
Author

Hey @lkchamorro

These hooks would be added to your site, probably via a functions.php file in a child theme. See WP core docs for more info: https://developer.wordpress.org/reference/functions/add_action/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment