Last active
January 26, 2022 22:41
-
-
Save thomasplevy/421aa2273384dc73b127be6b37cbcc67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
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
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