function unit_discussion($atts) { global $wp; if (array_key_exists('unitname', $wp->query_vars)) { $unit = new Unit(); $unit_id = $unit->get_unit_id_by_name($wp->query_vars['unitname']); } else { $unit_id = 0; } $comments_args = array('label_submit' => 'Send', 'title_reply' => 'Write a Reply or Comment', 'comment_notes_after' => '', 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun') . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>'); ob_start(); comment_form($comments_args, $unit_id); $content = ob_get_clean(); return $content; }
function action_parse_request(&$wp) { global $wp_query; do_action('coursepress_pre_parse_action'); /* Show instructor invite pages */ $pg = $this->instructor_invite_confirmation(); /* Show Units archive template */ if (array_key_exists('course_category', $wp->query_vars)) { $category_template_file = locate_template(array('archive-course-' . $wp->query_vars['course_category'] . '.php')); if ($category_template_file != '') { do_shortcode('[courses_loop]'); require_once $category_template_file; exit; } else { $theme_file = locate_template(array('archive-course.php')); if ($theme_file != '') { do_shortcode('[courses_loop]'); require_once $theme_file; exit; } else { $theme_file = locate_template(array('archive.php')); if ($theme_file != '') { do_shortcode('[courses_loop]'); require_once $theme_file; exit; } } } } /* Show Discussion single template */ if (array_key_exists('discussion_name', $wp->query_vars)) { $this->remove_pre_next_post(); $vars['discussion_name'] = $wp->query_vars['discussion_name']; $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); } /* Add New Discussion template */ if (array_key_exists('discussion_archive', $wp->query_vars) || array_key_exists('discussion_name', $wp->query_vars) && $wp->query_vars['discussion_name'] == $this->get_discussion_slug_new()) { $this->remove_pre_next_post(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); if (array_key_exists('discussion_name', $wp->query_vars) && $wp->query_vars['discussion_name'] == $this->get_discussion_slug_new()) { $this->units_archive_subpage = 'discussions'; $theme_file = locate_template(array('page-add-new-discussion.php')); if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Add New Discussion', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-add-new-discussion.php', $vars), 'type' => 'discussion', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } else { /* Archive Discussion template */ $this->units_archive_subpage = 'discussions'; $theme_file = locate_template(array('archive-discussions.php')); if ($theme_file != '') { //do_shortcode( '[course_notifications_loop]' ); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // DISCUSSIONS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-discussion-archive.php', $vars), 'type' => 'discussions', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_discussion_loop]'); } } } /* Show Instructor single template only if the user is an instructor of at least 1 course */ if (array_key_exists('instructor_username', $wp->query_vars)) { //&& 0 < Instructor::get_courses_number( cp_get_userdatabynicename( $wp->query_vars[ 'instructor_username' ] )->ID ) $this->remove_pre_next_post(); $vars = array(); $vars['instructor_username'] = $wp->query_vars['instructor_username']; $user = wp_cache_get($wp->query_vars['instructor_username'], 'cp_instructor_hash'); if (false === $user) { if (get_option('show_instructor_username', 1) == 1) { $username = str_replace('%20', ' ', $wp->query_vars['instructor_username']); //support for usernames with spaces $user = Instructor::instructor_by_login($username); } else { $user = Instructor::instructor_by_hash($wp->query_vars['instructor_username']); wp_cache_set($wp->query_vars['instructor_username'], $user, 'cp_instructor_hash'); } } $vars['user'] = $user; $theme_file = locate_template(array('single-instructor.php')); // $course_count = Instructor::get_courses_number( $vars['user']->ID ); // if ( $course_count <= 1 ) { // exit; // } if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __($vars['user']->display_name, 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/instructor-single.php', $vars), 'type' => 'virtual_page'); $pg = new CoursePress_Virtual_Page($args); } $user_id = get_current_user_id(); $this->set_latest_activity($user_id); } $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); $inbox_page = false; $new_message_page = false; $sent_messages_page = false; if (preg_match('/' . $this->get_inbox_slug() . '/', $url)) { $inbox_page = true; } if (preg_match('/' . $this->get_new_message_slug() . '/', $url)) { $new_message_page = true; } if (preg_match('/' . $this->get_sent_messages_slug() . '/', $url)) { $sent_messages_page = true; } if ($inbox_page) { $this->inbox_subpage = 'inbox'; $theme_file = locate_template(array('page-inbox.php')); if ($theme_file != '') { require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Inbox', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-inbox.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } if ($sent_messages_page) { $this->inbox_subpage = 'sent_messages'; $theme_file = locate_template(array('page-sent-messages.php')); if ($theme_file != '') { //do_shortcode( '[course_units_loop]' ); require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('Sent Message', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-sent-messages.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } if ($new_message_page) { $this->inbox_subpage = 'new_message'; $theme_file = locate_template(array('page-new-message.php')); if ($theme_file != '') { //do_shortcode( '[course_units_loop]' ); require_once $theme_file; exit; } else { $args = array('slug' => $wp->request, 'title' => __('New Message', 'cp'), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/page-new-message.php', array(), true), 'type' => 'page', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } /* Show Units archive template */ if (array_key_exists('coursename', $wp->query_vars) && !array_key_exists('unitname', $wp->query_vars)) { $this->remove_pre_next_post(); $units_archive_page = false; $units_archive_grades_page = false; $notifications_archive_page = false; $units_workbook_page = false; $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if (preg_match('/' . $this->get_units_slug() . '/', $url)) { $units_archive_page = true; } if (preg_match('/' . $this->get_grades_slug() . '/', $url)) { $units_archive_grades_page = true; } if (preg_match('/' . $this->get_workbook_slug() . '/', $url)) { $units_workbook_page = true; } if (preg_match('/' . $this->get_notifications_slug() . '/', $url)) { $notifications_archive_page = true; } $vars = array(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); if ($notifications_archive_page) { $this->units_archive_subpage = 'notifications'; $theme_file = locate_template(array('archive-notifications.php')); if ($theme_file != '') { do_shortcode('[course_notifications_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // NOTIFICATIONS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-notifications-archive.php', $vars), 'type' => 'notifications', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_notifications_loop]'); } } if ($units_archive_page) { $this->units_archive_subpage = 'units'; $theme_file = locate_template(array('archive-unit.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // COURSE UNITS $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-archive.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $user_id = get_current_user_id(); $this->set_latest_activity($user_id); $this->upgrade_user_meta($user_id, $course_id); } if ($units_archive_grades_page) { $this->units_archive_subpage = 'grades'; $theme_file = locate_template(array('archive-unit-grades.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // COURSE GRADES $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-archive-grades.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $this->set_latest_activity(get_current_user_id()); } if ($units_workbook_page) { $this->units_archive_subpage = 'workbook'; $theme_file = locate_template(array('archive-unit-workbook.php')); if ($theme_file != '') { do_shortcode('[course_units_loop]'); require_once $theme_file; exit; } else { $course_id = do_shortcode('[get_parent_course_id]'); // WORKBOOK do_shortcode('[course_units_loop]'); $args = array('slug' => $wp->request, 'title' => get_the_title($course_id), 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/archive-unit-workbook.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); do_shortcode('[course_units_loop]'); } $this->set_latest_activity(get_current_user_id()); } } /* Show Unit single template */ if (array_key_exists('coursename', $wp->query_vars) && array_key_exists('unitname', $wp->query_vars)) { $this->remove_pre_next_post(); $vars = array(); $unit = new Unit(); $vars['course_id'] = Course::get_course_id_by_name($wp->query_vars['coursename']); $vars['unit_id'] = $unit->get_unit_id_by_name($wp->query_vars['unitname'], $vars['course_id']); //$this->set_course_visited( get_current_user_id(), Course::get_course_id_by_name( $wp->query_vars['coursename'] ) ); $unit = new Unit($vars['unit_id']); $this->set_unit_visited(get_current_user_id(), $vars['unit_id']); $theme_file = locate_template(array('single-unit.php')); $forced_previous_completion_template = locate_template(array('single-previous-unit.php')); if (!Unit::is_unit_available($vars['unit_id']) && (!current_user_can('manage_options') && !CoursePress_Capabilities::can_update_course($vars['course_id']))) { if ($forced_previous_completion_template != '') { do_shortcode('[course_unit_single]'); //required for getting unit results require_once $forced_previous_completion_template; exit; } else { $args = array('slug' => $wp->request, 'title' => $unit->details->post_title, 'content' => __('This Unit is not available at the moment. Please check back later.', 'cp'), 'type' => 'page', 'is_page' => true, 'is_singular' => false, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } } else { if ($theme_file != '') { global $wp; do_shortcode('[course_unit_single unit_id="' . $vars['unit_id'] . '"]'); //required for getting unit results require_once $theme_file; do_action('wp'); //fix for gravity exit; } else { $args = array('slug' => $wp->request, 'title' => isset($unit->details) ? get_the_title($unit->details->post_parent) : '', 'content' => $this->get_template_details($this->plugin_dir . 'includes/templates/course-units-single.php', $vars), 'type' => 'unit', 'is_page' => true, 'is_singular' => true, 'is_archive' => false); $pg = new CoursePress_Virtual_Page($args); } $this->set_latest_activity(get_current_user_id()); } } }