/**
  * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function access_settings()
 {
     if (sensei_all_access()) {
         return true;
     }
     if (isset($this->settings->settings['access_permission']) && true == $this->settings->settings['access_permission']) {
         if (is_user_logged_in()) {
             return true;
         } else {
             return false;
         }
         // End If Statement
     } else {
         return true;
     }
     // End If Statement
 }
    /**
     * Outputs the lessons course signup lingk
     *
     * This hook runs inside the single lesson page.
     *
     * @since 1.9.0
     */
    public static function course_signup_link()
    {
        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
        if (empty($course_id) || 'course' != get_post_type($course_id) || sensei_all_access()) {
            return;
        }
        ?>

        <section class="course-signup lesson-meta">

            <?php 
        $wc_post_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
        if (Sensei_WC::is_woocommerce_active() && 0 < $wc_post_id) {
            global $current_user;
            if (is_user_logged_in()) {
                wp_get_current_user();
                $course_purchased = Sensei_Utils::sensei_customer_bought_product($current_user->user_email, $current_user->ID, $wc_post_id);
                if ($course_purchased) {
                    $prereq_course_id = get_post_meta($course_id, '_course_prerequisite', true);
                    $course_link = '<a href="' . esc_url(get_permalink($prereq_course_id)) . '" title="' . esc_attr(get_the_title($prereq_course_id)) . '">' . __('the previous course', 'woothemes-sensei') . '</a>';
                    ?>
                            <div class="sensei-message info">

                                <?php 
                    echo sprintf(__('Please complete %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
                    ?>

                            </div>

                    <?php 
                } else {
                    ?>

                        <div class="sensei-message info">

                            <?php 
                    $course_link = '<a href="' . esc_url(get_permalink($course_id)) . '"title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>';
                    echo sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
                    ?>

                        </div>
                    <?php 
                }
                ?>

                <?php 
            } else {
                ?>

                    <div class="sensei-message info"><?php 
                echo sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>');
                ?>
</div>

                <?php 
            }
            ?>

            <?php 
        } else {
            ?>

            <?php 
            if (!Sensei_Utils::user_started_course($course_id, get_current_user_id()) && sensei_is_login_required()) {
                ?>

                <div class="sensei-message alert">
                    <?php 
                $course_link = '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Sign Up', 'woothemes-sensei') . '">' . __('course', 'woothemes-sensei') . '</a>';
                if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
                    echo sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
                } else {
                    echo sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
                }
                ?>
                </div>

            <?php 
            }
            ?>

            <?php 
        }
        // End If Statement
        ?>

        </section>

        <?php 
    }
 *
 * @author 		WooThemes
 * @package 	Sensei/Templates
 * @version     1.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
global $woothemes_sensei, $post, $current_user;
// Get User Meta
get_currentuserinfo();
// Check if the user is taking the course
$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($post->ID, $current_user->ID);
// Content Access Permissions
$access_permission = false;
if (isset($woothemes_sensei->settings->settings['access_permission']) && !$woothemes_sensei->settings->settings['access_permission'] || sensei_all_access()) {
    $access_permission = true;
}
// End If Statement
?>
	<?php 
/**
 * woocommerce_before_single_product hook
 *
 * @hooked woocommerce_show_messages - 10
 */
if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) {
    do_action('woocommerce_before_single_product');
}
// End If Statement
?>
/**
 * Template function to determine if the current user can
 * access the current lesson content being viewed.
 *
 * This function checks in the folowing order
 * - if the current user has all access based on their permissions
 * - If the access permission setting is enabled for this site, if not the user has accces
 * - if the lesson has a pre-requisite and if the user has completed that
 * - If it is a preview the user has access as well
 *
 * @since 1.9.0
 *
 * @param string $lesson_id
 * @return bool
 */
function sensei_can_user_view_lesson($lesson_id = '', $user_id = '')
{
    if (empty($lesson_id)) {
        $lesson_id = get_the_ID();
    }
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    // Check for prerequisite lesson completions
    $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete($lesson_id, $user_id);
    $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
    $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, $user_id);
    $is_preview = false;
    if (Sensei_Utils::is_preview_lesson($lesson_id)) {
        $is_preview = true;
        $pre_requisite_complete = true;
    }
    $user_can_access_lesson = false;
    if (is_user_logged_in() && $user_taking_course) {
        $user_can_access_lesson = true;
    }
    $access_permission = false;
    if (!Sensei()->settings->get('access_permission') || sensei_all_access()) {
        $access_permission = true;
    }
    $can_user_view_lesson = $access_permission || $user_can_access_lesson && $pre_requisite_complete || $is_preview;
    /**
     * Filter the can user view lesson function
     *
     * @since 1.9.0
     *
     * @hooked Sensei_WC::alter_can_user_view_lesson
     *
     * @param bool $can_user_view_lesson
     * @param string $lesson_id
     * @param string $user_id
     */
    return apply_filters('sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id);
}
Beispiel #5
0
 /**
  * Hooking into the single lesson page to alter the
  * user access permissions based on if they have purchased the
  * course the lesson belongs to.
  *
  * This function will only return false or the passed in user_access value.
  * It doesn't return true in order to avoid altering other options.
  *
  * @since 1.9.0
  *
  * @param $can_user_view_lesson
  * @param $lesson_id
  * @param $user_id
  * @return bool
  */
 public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id)
 {
     // do not override access to admins
     if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)) {
         return true;
     }
     // check if the course has a valid product attached to it
     // which the user should have purchased if they want to access
     // the current lesson
     $course_id = get_post_meta($lesson_id, '_lesson_course', true);
     $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
     $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
     if (isset($product) && is_object($product)) {
         // valid product found
         $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
         // product has a successful order so this user may access the content
         // this function may only return false or the default
         // returning true may override other negatives which we don't want
         if (!$order_id) {
             return false;
         }
     }
     // return the passed in value
     return $can_user_view_lesson;
 }
Beispiel #6
0
 /**
  * Filter the single course content
  * taking into account if the user has access.
  *
  * @1.9.0
  *
  * @param string $content
  * @return string $content or $excerpt
  */
 public static function single_course_content($content)
 {
     if (!is_singular('course')) {
         return $content;
     }
     // Content Access Permissions
     $access_permission = false;
     if (!Sensei()->settings->get('access_permission') || sensei_all_access()) {
         $access_permission = true;
     }
     // End If Statement
     // Check if the user is taking the course
     $is_user_taking_course = Sensei_Utils::user_started_course(get_the_ID(), get_current_user_id());
     if (Sensei_WC::is_woocommerce_active()) {
         $wc_post_id = get_post_meta(get_the_ID(), '_course_woocommerce_product', true);
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
         $has_product_attached = isset($product) && is_object($product);
     } else {
         $has_product_attached = false;
     }
     if (is_user_logged_in() && $is_user_taking_course || $access_permission && !$has_product_attached || 'full' == Sensei()->settings->get('course_single_content_display')) {
         return $content;
     } else {
         return '<p class="course-excerpt">' . get_post(get_the_ID())->post_excerpt . '</p>';
     }
 }