/** * Shortcode: educator_courses. * * @param array $atts * @param string $content * @return string */ function educator_courses_shortcode($atts, $content = null) { $atts = shortcode_atts(array('show_price' => 1, 'ids' => '', 'number' => 15, 'categories' => null), $atts); $output = '<div class="courses-carousel owl-carousel">'; $params = array('post_type' => 'ib_educator_course', 'orderby' => 'menu_order', 'posts_per_page' => intval($atts['number'])); if ($atts['ids']) { $ids = explode(' ', $atts['ids']); $params['post__in'] = array(); foreach ($ids as $id) { $params['post__in'][] = intval($id); } $params['posts_per_page'] = -1; $params['orderby'] = 'post__in'; } if ($atts['categories']) { $categories = explode(' ', $atts['categories']); foreach ($categories as $key => $term_id) { $categories[$key] = intval($term_id); } $params['tax_query'] = array(array('taxonomy' => 'ib_educator_category', 'field' => 'term_id', 'terms' => $categories)); } $query = new WP_Query($params); if ($query->have_posts()) { $course_id = 0; while ($query->have_posts()) { $query->the_post(); $course_id = get_the_ID(); $output .= '<article class="' . esc_attr(implode(' ', get_post_class('post-grid'))) . '">'; if (has_post_thumbnail()) { $output .= '<div class="post-thumb"><a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail($course_id, 'ib-educator-grid') . '</a></div>'; } $output .= '<div class="post-body">'; $output .= '<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '">' . the_title('', '', false) . '</a></h2>'; if (1 == $atts['show_price'] && 'closed' != ib_edu_registration($course_id)) { $output .= '<div class="price">' . ib_edu_format_course_price(ib_edu_get_course_price($course_id)) . '</div>'; } ob_start(); the_excerpt(); $output .= '<div class="post-excerpt">' . ob_get_clean() . '</div>'; $output .= '</div>'; if (function_exists('educator_course_meta')) { $output .= '<footer class="post-meta">' . educator_course_meta($course_id, array('num_lessons', 'difficulty')) . educator_share('menu') . '</footer>'; } $output .= '</article>'; } wp_reset_postdata(); } $output .= '</div>'; return $output; }
$object_id = intval($_POST['membership_id']); } if ($object_id) { $post = get_post($object_id); } } // Check whether the selected item exists. if (!$post || !in_array($post->post_type, array('ib_educator_course', 'ib_edu_membership'))) { echo '<p>' . esc_html__('Please select a course to continue.', 'training') . '</p>'; return; } // Determine whether a user can pay for the item. $access_status = ''; if ('ib_educator_course' == $post->post_type) { // Registration allowed? if ('closed' == ib_edu_registration($post->ID)) { echo '<p>' . esc_html__('Registration for this course is closed.', 'training') . '</p>'; return; } $access_status = IB_Educator::get_instance()->get_access_status($post->ID, $user_id); if (!in_array($access_status, array('course_complete', 'forbidden'))) { echo '<p>' . ib_edu_get_access_status_message($access_status) . '</p>'; return; } } // Show a login link to non-authenticated users. if (!$user_id) { $login_url = apply_filters('ib_educator_login_url', ''); if (empty($login_url)) { if ('ib_educator_course' == $post->post_type) { $login_url = wp_login_url(ib_edu_get_endpoint_url('edu-course', $post->ID, get_permalink()));
"><?php the_post_thumbnail('ib-educator-grid'); ?> </a> </div> <?php } ?> <div class="post-body"> <?php the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?> <div class="price"> <?php if ('closed' != ib_edu_registration($course_id)) { echo ib_edu_format_price(ib_edu_get_course_price($course_id)); } ?> </div> <div class="post-excerpt"><?php the_excerpt(); ?> </div> </div> <footer class="post-meta"> <?php echo educator_course_meta($course_id, array('num_lessons', 'difficulty')); echo educator_share('menu'); ?>
/** * Get HTML for the course price widget. * * @param int $course_id * @param int $user_id * @param string $before * @param string $after * @return string */ function ib_edu_get_price_widget($course_id, $user_id, $before = '<div class="ib-edu-course-price">', $after = '</div>') { // Registration allowed? if ('closed' == ib_edu_registration($course_id)) { return ''; } // Check membership. $membership_access = IB_Educator_Memberships::get_instance()->membership_can_access($course_id, $user_id); /** * Filter the course price widget. * * @since 1.3.2 * * @param bool $membership_access Whether the user's current membership allows him/her to take the course. */ $output = apply_filters('ib_educator_course_price_widget', null, $membership_access, $course_id, $user_id); if (null !== $output) { return $output; } // Generate the widget. $output = $before; if ($membership_access) { $register_url = ib_edu_get_endpoint_url('edu-action', 'join', get_permalink($course_id)); $output .= '<form action="' . esc_url($register_url) . '" method="post">'; $output .= '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('ib_educator_join') . '">'; $output .= '<input type="submit" class="ib-edu-button" value="' . __('Join', 'ibeducator') . '">'; $output .= '</form>'; } else { $price = ib_edu_get_course_price($course_id); $price = 0 == $price ? __('Free', 'ibeducator') : ib_edu_format_course_price($price); $register_url = ib_edu_get_endpoint_url('edu-course', $course_id, get_permalink(ib_edu_page_id('payment'))); $output .= '<span class="price">' . $price . '</span><a href="' . esc_url($register_url) . '" class="ib-edu-button">' . __('Register', 'ibeducator') . '</a>'; } $output .= $after; return $output; }
/** * Join the course if membership allows. */ public static function join() { if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ib_educator_join')) { return; } // Get the current user id. $user_id = get_current_user_id(); if (!$user_id) { return; } // Get course id. $course_id = get_the_ID(); if (!$course_id) { return; } // Registration allowed? if ('closed' == ib_edu_registration($course_id)) { return; } // Get course. $course = get_post($course_id); if (!$course || 'ib_educator_course' != $course->post_type) { return; } $api = IB_Educator::get_instance(); $errors = new WP_Error(); // Check the course prerequisites. if (!$api->check_prerequisites($course_id, $user_id)) { $prerequisites_html = ''; $prerequisites = $api->get_prerequisites($course_id); $courses = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'include' => $prerequisites)); if (!empty($courses)) { foreach ($courses as $course) { $prerequisites_html .= '<br><a href="' . esc_url(get_permalink($course->ID)) . '">' . esc_html($course->post_title) . '</a>'; } } $errors->add('prerequisites', sprintf(__('You have to complete the prerequisites for this course: %s', 'ibeducator'), $prerequisites_html)); ib_edu_message('course_join_errors', $errors); return; } // Make sure the user can join this course. $ms = IB_Educator_Memberships::get_instance(); if (!$ms->membership_can_access($course_id, $user_id)) { return; } // Check if the user already has an inprogress entry for this course. $entries = $api->get_entries(array('course_id' => $course_id, 'user_id' => $user_id, 'entry_status' => 'inprogress')); if (!empty($entries)) { return; } $user_membership = $ms->get_user_membership($user_id); $entry = IB_Educator_Entry::get_instance(); $entry->course_id = $course_id; $entry->object_id = $user_membership['membership_id']; $entry->user_id = $user_id; $entry->entry_origin = 'membership'; $entry->entry_status = 'inprogress'; $entry->entry_date = date('Y-m-d H:i:s'); $entry->save(); }
/** * Get related courses. * * @param int $post_id * @return string */ function educator_related_courses($post_id) { $terms = get_the_terms($post_id, 'ib_educator_category'); if (!$terms || is_wp_error($terms)) { return; } $args = array('post_type' => 'ib_educator_course', 'posts_per_page' => 3, 'post__not_in' => array($post_id)); $terms_ids = array(); foreach ($terms as $term) { $terms_ids[] = $term->term_id; } $args['tax_query'] = array(array('taxonomy' => 'ib_educator_category', 'terms' => $terms_ids)); $query = new WP_Query($args); if ($query->have_posts()) { $output = '<section class="related-courses">'; $output .= '<h1>' . __('Related Courses', 'ib-educator') . '</h1>'; $api = IB_Educator::get_instance(); $course_id = 0; while ($query->have_posts()) { $query->the_post(); $course_id = get_the_ID(); $output .= '<article class="' . esc_attr(implode(' ', get_post_class('clearfix'))) . '">'; if (has_post_thumbnail()) { $output .= '<div class="post-thumb"><a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail($course_id, 'thumbnail') . '</a></div>'; } $output .= '<div class="post-summary">' . '<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '">' . the_title('', '', false) . '</a></h2>'; ob_start(); the_excerpt(); $output .= '<div class="post-excerpt">' . ob_get_clean() . '</div>'; $output .= '<div class="post-meta">'; if ('closed' != ib_edu_registration($course_id)) { $output .= '<span class="price">' . ib_edu_format_course_price(ib_edu_get_course_price($course_id)) . '</span>'; } $output .= educator_course_meta($course_id, array('num_lessons', 'difficulty')); $output .= '</div>'; $output .= '</div>'; $output .= '</article>'; } wp_reset_postdata(); $output .= '</section>'; return $output; } return ''; }