/** * Shows the course list. * * @since 1.0.0 */ function course_list($atts) { extract(shortcode_atts(array('course_id' => '', 'status' => 'publish', 'instructor' => '', 'instructor_msg' => __('The Instructor does not have any courses assigned yet.', 'cp'), 'student' => '', 'student_msg' => __('You have not yet enrolled in a course. Browse courses %s', 'cp'), 'two_column' => 'yes', 'title_column' => 'none', 'left_class' => '', 'right_class' => '', 'course_class' => '', 'title_link' => 'yes', 'title_class' => 'course-title', 'title_tag' => 'h3', 'course_status' => 'all', 'list_wrapper_before' => 'div', 'list_wrapper_before_class' => 'course-list %s', 'list_wrapper_after' => 'div', 'show' => 'dates,enrollment_dates,class_size,cost', 'show_button' => 'yes', 'show_divider' => 'yes', 'show_media' => 'false', 'show_title' => 'yes', 'media_type' => get_option('listings_media_type', 'image'), 'media_priority' => get_option('listings_media_priority', 'image'), 'admin_links' => 'false', 'manage_link_title' => __('Manage Course', 'cp'), 'finished_link_title' => __('View Course', 'cp'), 'limit' => -1, 'order' => 'ASC', 'class' => ''), $atts, 'course_list')); if (!empty($course_id)) { $course_id = (int) $course_id; } $status = sanitize_html_class($status); $instructor = sanitize_text_field($instructor); $instructor_msg = sanitize_text_field($instructor_msg); $student = sanitize_text_field($student); $student_msg = sanitize_text_field($student_msg); $two_column = sanitize_html_class($two_column); $title_column = sanitize_text_field($title_column); $left_class = sanitize_html_class($left_class); $right_class = sanitize_html_class($right_class); $course_class = sanitize_html_class($course_class); $title_link = sanitize_html_class($title_link); $title_class = sanitize_html_class($title_class); $title_tag = sanitize_html_class($title_tag); $course_status = sanitize_text_field($course_status); $list_wrapper_before = sanitize_html_class($list_wrapper_before); $list_wrapper_after = sanitize_html_class($list_wrapper_after); $show = sanitize_text_field($show); $show_button = sanitize_html_class($show_button); $show_divider = sanitize_html_class($show_divider); $show_title = sanitize_html_class($show_title); $show_media = sanitize_html_class($show_media); $media_type = !empty($media_type) ? sanitize_text_field($media_type) : 'image'; $media_priority = !empty($media_priority) ? sanitize_text_field($media_priority) : 'image'; $admin_links = sanitize_text_field($admin_links); $admin_links = 'true' == $admin_links ? true : false; $manage_link_title = sanitize_text_field($manage_link_title); $finished_link_title = sanitize_text_field($finished_link_title); $limit = (int) $limit; $order = sanitize_html_class($order); $class = sanitize_html_class($class); $status = 'published' == $status ? 'publish' : $status; // student or instructor ids provided $user_provided = false; $user_provided = empty($student) ? empty($instructor) ? false : true : true; $content = ''; $courses = array(); if (!empty($instructor)) { $include_ids = array(); $instructors = explode(',', $instructor); if (!empty($instructors)) { foreach ($instructors as $ins) { $ins = (int) $ins; if ($ins) { $ins = new Instructor($ins); $course_ids = $ins->get_assigned_courses_ids($status); if ($course_ids) { $include_ids = array_unique(array_merge($include_ids, $course_ids)); } } } } else { $instructor = (int) $instructor; if ($instructor) { $instructor = new Instructor($ins); $course_ids = $instructor->get_assigned_courses_ids($status); if ($course_ids) { $include_ids = array_unique(array_merge($include_ids, $course_ids)); } } } } if (!empty($student)) { $include_ids = array(); $students = explode(',', $student); if (!empty($students)) { foreach ($students as $stud) { $stud = (int) $stud; if ($stud) { $stud = new Student($stud); $course_ids = $stud->get_assigned_courses_ids($status); if ($course_ids) { $include_ids = array_unique(array_merge($include_ids, $course_ids)); } } } } else { $student = (int) $student; if ($student) { $student = new Student($student); $course_ids = $student->get_assigned_courses_ids($status); if ($course_ids) { $include_ids = array_unique(array_merge($include_ids, $course_ids)); } } } } $post_args = array('order' => $order, 'post_type' => 'course', 'meta_key' => 'enroll_type', 'post_status' => $status, 'posts_per_page' => $limit); if (!empty($include_ids)) { $post_args = wp_parse_args(array('include' => $include_ids), $post_args); } if ($user_provided && !empty($include_ids) || !$user_provided) { $courses = get_posts($post_args); } //<div class="course-list %s"> $content .= 0 < count($courses) && !empty($list_wrapper_before) ? '<' . $list_wrapper_before . ' class=' . $list_wrapper_before_class . '>' : ''; foreach ($courses as $course) { if (!empty($student) && 'all' != strtolower($course_status) && !is_array($student)) { // $completion = new Course_Completion( $course->ID ); // $completion->init_student_status( $student ); $course->completed = Student_Completion::is_course_complete($student, $course->ID); // Skip if we wanted a completed course but got an incomplete if ('completed' == strtolower($course_status) && !$course->completed) { continue; } // Skip if we wanted an incompleted course but got a completed if ('incomplete' == strtolower($course_status) && $course->completed) { continue; } } $content .= '<div class="course-list-item ' . $course_class . '">'; if ('yes' == $show_media) { $content .= do_shortcode('[course_media course_id="' . $course->ID . '" type="' . $media_type . '" priority="' . $media_priority . '"]'); } if ('none' == $title_column) { $content .= do_shortcode('[course_title course_id="' . $course->ID . '" link="' . $title_link . '" class="' . $title_class . '" title_tag="' . $title_tag . '"]'); } if ('yes' == $two_column) { $content .= '<div class="course-list-box-left ' . $left_class . '">'; } if ('left' == $title_column) { $content .= do_shortcode('[course_title course_id="' . $course->ID . '" link="' . $title_link . '" class="' . $title_class . '" title_tag="' . $title_tag . '"]'); } // One liner.. $content .= do_shortcode('[course show="' . $show . '" show_title="yes" course_id="' . $course->ID . '"]'); if ('yes' == $two_column) { $content .= '</div>'; $content .= '<div class="course-list-box-right ' . $right_class . '">'; } if ('right' == $title_column) { $content .= do_shortcode('[course_title course_id="' . $course->ID . '" link="' . $title_link . '" class="' . $title_class . '" title_tag="' . $title_tag . '"]'); } if ('yes' == $show_button) { if (!empty($course->completed)) { $content .= do_shortcode('[course_join_button course_id="' . $course->ID . '" continue_learning_text="' . $finished_link_title . '"]'); } else { $content .= do_shortcode('[course_join_button course_id="' . $course->ID . '"]'); } } if ($admin_links) { $content .= '<button class="manage-course" data-link="' . admin_url('admin.php?page=course_details&course_id=' . $course->ID) . '">' . $manage_link_title . '</button>'; } // Add action links if student if (!empty($student)) { $content .= do_shortcode('[course_action_links course_id="' . $course->ID . '"]'); } if ('yes' == $two_column) { $content .= '</div>'; } if ('yes' == $show_divider) { $content .= '<div class="divider" ></div>'; } $content .= '</div>'; //course-list-item } // foreach if ((!$courses || 0 == count($courses)) && !empty($instructor)) { $content .= $instructor_msg; } if ((!$courses || 0 == count($courses)) && !empty($student)) { $content .= sprintf($student_msg, '<a href="' . trailingslashit(home_url() . '/' . CoursePress::instance()->get_course_slug()) . '">' . __('here', 'cp') . '</a>'); } // </div> course-list $content .= 0 < count($courses) && !empty($list_wrapper_before) ? '</' . $list_wrapper_after . '>' : ''; return $content; }
><?php _e('All Courses', 'cp'); ?> </option> <?php } ?> <?php $args = array('post_type' => 'course', 'post_status' => 'any', 'posts_per_page' => -1); $courses = get_posts($args); $available_course_options = 0; //coursepress_create_my_assigned_notification_cap foreach ($courses as $course) { //if ( $notification_id == 0 ) { $instructor = new Instructor(get_current_user_id()); $instructor_courses = $instructor->get_assigned_courses_ids(); $my_course = in_array($course->ID, $instructor_courses); $my_course = CoursePress_Capabilities::is_course_instructor($course->ID); //} if ($notification_id == 0) { if (current_user_can('manage_options') || current_user_can('coursepress_create_notification_cap') || current_user_can('coursepress_create_my_notification_cap') && $course->post_author == get_current_user_ID() || current_user_can('coursepress_create_my_assigned_notification_cap') && $my_course) { ?> <option value="<?php echo $course->ID; ?> " <?php selected($meta_course_id, $course->ID); ?> ><?php echo $course->post_title; ?>
/** * Is the user an instructor of this course? * * @since 1.0.0 * * @return bool */ public static function is_course_instructor($course_id, $user_id = '') { if (empty($user_id)) { $user_id = get_current_user_id(); } $instructor = new Instructor($user_id); $instructor_courses = $instructor->get_assigned_courses_ids(); return in_array($course_id, $instructor_courses); }
function remove_course_instructor() { $instructor_id = (int) $_POST['instructor_id']; $user_id = (int) $_POST['user_id']; $course_id = (int) $_POST['course_id']; $nonce_check = wp_verify_nonce($_POST['instructor_nonce'], 'manage-instructors-' . $user_id); $cap = CoursePress_Capabilities::can_assign_course_instructor($course_id, $user_id); // same capability as adding $doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false; $ajax_response = array(); if ($nonce_check && $cap && $doing_ajax) { $instructors = get_post_meta($course_id, 'instructors', true); $updated_instructors = array(); foreach ($instructors as $instructor) { if ($instructor != $instructor_id) { $updated_instructors[] = $instructor; } } $global_option = !is_multisite(); update_post_meta($course_id, 'instructors', $updated_instructors); delete_user_option($instructor_id, 'course_' . $course_id, $global_option); // Legacy delete_user_meta($instructor_id, 'course_' . $course_id, $course_id); $instructor = new Instructor($instructor_id); // If user is no longer an instructor of any courses, remove his capabilities. $assigned_courses_ids = $instructor->get_assigned_courses_ids(); if (empty($assigned_courses_ids)) { $this->drop_instructor_capabilities($instructor_id); delete_user_option($instructor_id, 'role_ins', $global_option); // Legacy delete_user_meta($instructor_id, 'role_ins'); } $ajax_response['instructor_removed'] = true; /** * Instructor has been removed from course. * * @since 1.2.1 * * @param int course_id The course instructor was added to. * @param int instructor_id The user ID of the new instructor. * */ do_action('coursepress_course_instructor_removed', $course_id, $instructor_id); // Nonce failed, User doesn't have the capability } else { $ajax_response['instructor_removed'] = false; $ajax_response['reason'] = __('Invalid request. Security check failed.', 'cp'); /** * Instructor has NOT been removed from course. * * @since 1.2.1 * * @param int course_id The course instructor was added to. * @param int instructor_id The user ID of the new instructor. * */ do_action('coursepress_course_instructor_not_removed', $course_id, $instructor_id); } $response = array('what' => 'instructor_invite', 'action' => 'instructor_invite', 'id' => 1, 'data' => json_encode($ajax_response)); ob_end_clean(); ob_start(); $xmlResponse = new WP_Ajax_Response($response); $xmlResponse->send(); ob_end_flush(); }
<?php /** * The Template for displaying instructor profile. * * @package CoursePress */ get_header(); $user = $vars['user']; //get user info from the CoursePress plugin $instructor = new Instructor($user->ID); $assigned_courses = $instructor->get_assigned_courses_ids('publish'); ?> <div id="primary" class="content-area content-instructor-profile"> <main id="main" class="site-main" role="main"> <h1 class="h1-instructor-title"><?php echo $instructor->display_name; ?> </h1> <?php // Avatar echo do_shortcode('[course_instructor_avatar instructor_id="' . $user->ID . '" thumb_size="235" class="instructor_avatar_full"]'); // Bio echo get_user_meta($user->ID, 'description', true); ?> <h2 class="h2-instructor-bio"><?php _e('Courses', 'cp'); ?> </h2>