?>
<h2><?php 
_e('Course Units', 'cp');
echo ' ' . $complete_message;
?>
</h2>
<div class="units-archive">
	<ul class="units-archive-list">
		<?php 
if (have_posts()) {
    ?>
			<?php 
    while (have_posts()) {
        the_post();
        $draft = get_post_status() !== 'publish';
        $show_draft = $draft && cp_can_see_unit_draft();
        if ($draft && !$show_draft) {
            continue;
        }
        $additional_class = '';
        $additional_li_class = '';
        $unit_id = get_the_ID();
        $additional_content = '';
        if (!Unit::is_unit_available($unit_id)) {
            $additional_class = 'locked-unit';
            $additional_li_class = 'li-locked-unit';
            $additional_content = '<div class="' . esc_attr($additional_class) . '"></div>';
        }
        $unit_progress = do_shortcode('[course_unit_percent course_id="' . $course_id . '" unit_id="' . $unit_id . '" format="true" style="flat"]');
        ?>
				<li class="<?php 
 /**
  * Shows the course title.
  *
  * @since 1.0.0
  */
 function course_unit_title($atts)
 {
     extract(shortcode_atts(array('unit_id' => in_the_loop() ? get_the_ID() : '', 'title_tag' => '', 'link' => 'no', 'class' => '', 'last_page' => 'no'), $atts, 'course_unit_title'));
     $unit_id = (int) $unit_id;
     $title_tag = sanitize_html_class($title_tag);
     $link = sanitize_html_class($link);
     $last_page = sanitize_html_class($last_page);
     $class = sanitize_html_class($class);
     $title = get_the_title($unit_id);
     $draft = get_post_status() !== 'publish';
     $show_draft = $draft && cp_can_see_unit_draft();
     if ('yes' == $last_page) {
         $course_id = do_shortcode('[get_parent_course_id]');
         $course_id = (int) $course_id;
         $last_visited_page = cp_get_last_visited_unit_page($unit_id);
         $the_permalink = Unit::get_permalink($unit_id, $course_id) . 'page/' . trailingslashit($last_visited_page);
     } else {
         $the_permalink = Unit::get_permalink($unit_id, $course_id);
     }
     $content = '';
     if (!$draft || $draft && $show_draft) {
         $content = !empty($title_tag) ? '<' . $title_tag . ' class="course-unit-title course-unit-title-' . $unit_id . ' ' . $class . '">' : '';
         $content .= 'yes' == $link ? '<a href="' . esc_url($the_permalink) . '" title="' . $title . '" class="unit-archive-single-title">' : '';
         $content .= $title;
         $content .= 'yes' == $link ? '</a>' : '';
         $content .= !empty($title_tag) ? '</' . $title_tag . '>' : '';
     }
     // Return the html in the buffer.
     return $content;
 }
 function get_unit_id_by_name($slug, $course_id = 0)
 {
     if (empty($course_id)) {
         $course_id = Course::get_course_id_by_name($wp->query_vars['coursename']);
     }
     if (!cp_can_see_unit_draft()) {
         $post = get_posts(array('post_type' => array('unit'), 'name' => $slug, 'post_per_page' => 1, 'post_status' => 'publish', 'post_parent' => $course_id, 'suppress_filters' => false));
     } else {
         $post_id = cp_get_id_by_post_name($slug, $course_id);
         $post = get_post($post_id);
     }
     $post = !empty($post) && is_array($post) ? array_pop($post) : $post;
     return !empty($post) ? $post->ID : false;
 }