Skip to content

Instantly share code, notes, and snippets.

@DumahX
Created May 11, 2022 17:17
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 DumahX/718109dcf2943c76419eff5f5d57859a to your computer and use it in GitHub Desktop.
Save DumahX/718109dcf2943c76419eff5f5d57859a to your computer and use it in GitHub Desktop.
<?php
add_shortcode('mpcs-unenrolled-courses', function() {
$unenrolled_courses = array();
$current_user = MeprUtils::get_currentuserinfo();
$mepr_user = new MeprUser($current_user->ID);
$courses = get_posts(array('post_type' => 'mpcs-course', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby'=> 'title', 'order' => 'ASC'));
if(false == MeprUtils::is_logged_in_and_an_admin()) {
$courses = array_filter($courses, function($course) use ( $mepr_user ) {
return true == \MeprRule::is_locked_for_user($mepr_user, $course);
});
}
$courses_ids = array_map(function($c) {
return is_object($c) ? $c->ID : $c['ID'];
}, $courses);
if (empty($courses_ids)) {
$courses_ids = array ( 0 );
}
$course_query = new \WP_Query(array('post_type' => 'mpcs-course', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby'=> 'post__in', 'order' => 'ASC', 'post__in' => $courses_ids));
$course_posts = $course_query->get_posts();
foreach ($course_posts as $course) {
$unenrolled_courses[] = $course;
}
$content = '<ul>';
foreach($unenrolled_courses as $course) {
$content .= '<li>' . $course->post_title . '</li>';
}
$content .= '</ul>';
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment