Created
August 31, 2017 09:16
-
-
Save mikewing94/757b8a4f36b43c2cf49c49b1b997c608 to your computer and use it in GitHub Desktop.
Sensei Display course certificate on quiz pages
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
add_action( 'sensei_before_main_content', 'senseiBeforeMainContent', 10 ); | |
function senseiBeforeMainContent() { | |
if( !is_singular('quiz') ) return; | |
global $post, $current_user; | |
if(isset($post->post_parent) && $post->post_parent != 0) { | |
$lessonPost = get_post($post->post_parent); | |
$courseID = get_post_meta($lessonPost->ID, '_lesson_course', true); | |
$availableCertificates = get_posts(array( | |
'post_type' => 'certificate', | |
'meta_query' => array( | |
array( | |
'key' => 'course_id', | |
'value' => $courseID | |
), | |
array( | |
'key' => 'learner_id', | |
'value' => $current_user->ID | |
) | |
), | |
)); | |
if(!empty($availableCertificates)) { | |
foreach($availableCertificates as $availableCertificate) { | |
echo '<a class="sensei-certificate-link" href="' . $availableCertificate->guid . '" target="_blank">' . __("View Certificate") . '</a>'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment