Beispiel #1
0
 function sensei_check_woocommerce_version($version = '2.1')
 {
     if (Sensei_WC::is_woocommerce_active()) {
         global $woocommerce;
         if (version_compare($woocommerce->version, $version, ">=")) {
             return true;
         }
     }
     return false;
 }
 /**
  * Constructor function.
  * @since  1.0.0
  * @return  void
  */
 public function __construct()
 {
     /* Widget variable settings. */
     $this->woo_widget_cssclass = 'widget_sensei_course_component';
     $this->woo_widget_description = __('This widget will output a list of Courses - New, Featured, Free, Paid, Active, Completed.', 'woothemes-sensei');
     $this->woo_widget_idbase = 'sensei_course_component';
     $this->woo_widget_title = __('Sensei - Course Component', 'woothemes-sensei');
     $this->woo_widget_componentslist = array('usercourses' => __('New Courses', 'woothemes-sensei'), 'featuredcourses' => __('Featured Courses', 'woothemes-sensei'), 'activecourses' => __('My Active Courses', 'woothemes-sensei'), 'completedcourses' => __('My Completed Courses', 'woothemes-sensei'));
     // Add support for the WooCommerce shelf.
     if (Sensei_WC::is_woocommerce_active()) {
         $this->woo_widget_componentslist['freecourses'] = __('Free Courses', 'woothemes-sensei');
         $this->woo_widget_componentslist['paidcourses'] = __('Paid Courses', 'woothemes-sensei');
     }
     /* Widget settings. */
     $widget_ops = array('classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description);
     /* Widget control settings. */
     $control_ops = array('width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase);
     /* Create the widget. */
     parent::__construct($this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops);
 }
 *
 * @since 1.8.0
 */
function Sensei()
{
    return Sensei_Main::instance();
}
// set the sensei version number
Sensei()->version = '1.9.2';
//backwards compatibility
global $woothemes_sensei;
$woothemes_sensei = Sensei();
/**
 * Hook in WooCommerce functionality
 */
if (Sensei_WC::is_woocommerce_active()) {
    add_action('init', array('Sensei_WC', 'load_woocommerce_integration_hooks'));
}
/**
 * Load all Template hooks
 */
if (!is_admin()) {
    require_once 'includes/hooks/template.php';
}
/**
 * Plugin updates
 * @since  1.0.1
 */
woothemes_queue_update(plugin_basename(__FILE__), 'bad2a02a063555b7e2bee59924690763', 152116);
/**
 * Sensei Activation Hook registration
    /**
     * 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 
    }
Beispiel #5
0
 /**
  * Check if WooCommerce is active.
  *
  * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active
  * @access public
  * @since  1.0.2
  * @static
  * @return boolean
  */
 public static function sensei_is_woocommerce_activated()
 {
     return Sensei_WC::is_woocommerce_active();
 }
/**
 * sensei_simple_course_price function.
 *
 * @access public
 * @param mixed $post_id
 * @return void
 */
function sensei_simple_course_price($post_id)
{
    //WooCommerce Pricing
    if (Sensei_WC::is_woocommerce_active()) {
        $wc_post_id = get_post_meta($post_id, '_course_woocommerce_product', true);
        if (0 < $wc_post_id) {
            // Get the product
            $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
            if (isset($product) && !empty($product) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart($wc_post_id)) {
                ?>
    	    		<span class="course-price"><?php 
                echo $product->get_price_html();
                ?>
</span>
    	    	<?php 
            }
            // End If Statement
        }
        // End If Statement
    }
    // End If Statement
}
Beispiel #7
0
 /**
  * Load the WooCommerce single product actions above
  * single courses if woocommerce is active allowing purchase
  * information and actions to be hooked from WooCommerce.
  */
 public static function do_single_course_wc_single_product_action()
 {
     /**
      * this hooks is documented within the WooCommerce plugin.
      */
     if (Sensei_WC::is_woocommerce_active()) {
         do_action('woocommerce_before_single_product');
     }
     // End If Statement
 }
 /**
  * Activate single course if already purchases
  * @return void
  */
 public function activate_purchased_single_course()
 {
     global $post, $current_user;
     if (Sensei_WC::is_woocommerce_active()) {
         if (!is_user_logged_in()) {
             return;
         }
         if (!isset($post->ID)) {
             return;
         }
         $user_id = $current_user->ID;
         $course_id = $post->ID;
         $course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
         if (!$course_product_id) {
             return;
         }
         $user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id);
         // Ignore course if already completed
         if (Sensei_Utils::user_completed_course($user_course_status)) {
             return;
         }
         // Ignore course if already started
         if ($user_course_status) {
             return;
         }
         // Get all user's orders
         $order_args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-processing', 'wc-completed'), 'meta_query' => array(array('key' => '_customer_user', 'value' => $user_id)), 'fields' => 'ids');
         $orders = get_posts($order_args);
         foreach ($orders as $order_post_id) {
             // Get course product IDs from order
             $order = new WC_Order($order_post_id);
             $items = $order->get_items();
             foreach ($items as $item) {
                 $product = wc_get_product($item['product_id']);
                 // handle product bundles
                 if (is_object($product) && $product->is_type('bundle')) {
                     $bundled_product = new WC_Product_Bundle($product->id);
                     $bundled_items = $bundled_product->get_bundled_items();
                     foreach ($bundled_items as $bundled_item) {
                         if ($bundled_item->product_id == $course_product_id) {
                             Sensei_Utils::user_start_course($user_id, $course_id);
                             return;
                         }
                     }
                 } else {
                     // handle regular products
                     if ($item['product_id'] == $course_product_id) {
                         Sensei_Utils::user_start_course($user_id, $course_id);
                         return;
                     }
                 }
             }
         }
     }
 }
Beispiel #9
0
 /**
  * If customer has purchased the course, update Sensei to indicate that they are taking the course.
  *
  * @since  1.0.0
  * @since 1.9.0 move to class Sensei_WC
  *
  * @param  int 			$course_id  (default: 0)
  * @param  array/Object $order_user (default: array()) Specific user's data.
  *
  * @return bool|int
  */
 public static function course_update($course_id = 0, $order_user = array())
 {
     global $current_user;
     if (!isset($current_user) || !$current_user->ID > 0) {
         return false;
     }
     $data_update = false;
     // Get the product ID
     $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
     // Check if in the admin
     if (is_admin()) {
         $user_login = $order_user['user_login'];
         $user_email = $order_user['user_email'];
         $user_url = $order_user['user_url'];
         $user_id = $order_user['ID'];
     } else {
         $user_login = $current_user->user_login;
         $user_email = $current_user->user_email;
         $user_url = $current_user->user_url;
         $user_id = $current_user->ID;
     }
     // End If Statement
     // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
     $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
     if (0 < absint($course_prerequisite_id)) {
         $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
         if (!$prereq_course_complete) {
             // Remove all course user meta
             return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
         }
     }
     $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
     if (!$is_user_taking_course) {
         if (Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id) && 0 < $wc_post_id) {
             $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
             $is_user_taking_course = false;
             if (true == $activity_logged) {
                 $is_user_taking_course = true;
             }
             // End If Statement
         }
         // End If Statement
     }
     // end if is user taking course
     return $is_user_taking_course;
 }
Beispiel #10
0
 /**
  * sensei_woocommerce_complete_order description
  * @since   1.0.3
  * @access  public
  * @param   int $order_id WC order ID
  * @return  void
  */
 public function sensei_woocommerce_complete_order($order_id = 0)
 {
     $order_user = array();
     // Check for WooCommerce
     if (Sensei_WC::is_woocommerce_active() && 0 < $order_id) {
         // Get order object
         $order = new WC_Order($order_id);
         $user = get_user_by('id', $order->get_user_id());
         $order_user['ID'] = $user->ID;
         $order_user['user_login'] = $user->user_login;
         $order_user['user_email'] = $user->user_email;
         $order_user['user_url'] = $user->user_url;
         // Run through each product ordered
         if (0 < sizeof($order->get_items())) {
             foreach ($order->get_items() as $item) {
                 $product_type = '';
                 if (isset($item['variation_id']) && 0 < $item['variation_id']) {
                     $item_id = $item['variation_id'];
                     $product_type = 'variation';
                 } else {
                     $item_id = $item['product_id'];
                 }
                 // End If Statement
                 $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type);
                 // Get courses that use the WC product
                 $courses = $this->post_types->course->get_product_courses($_product->id);
                 // Loop and update those courses
                 foreach ($courses as $course_item) {
                     $update_course = $this->woocommerce_course_update($course_item->ID, $order_user);
                 }
                 // End For Loop
             }
             // End For Loop
         }
         // End If Statement
         // Add meta to indicate that payment has been completed successfully
         update_post_meta($order_id, 'sensei_payment_complete', '1');
     }
     // End If Statement
 }
Beispiel #11
0
    /**
     * Output the course actions like start taking course, register, add to cart etc.
     *
     * @since 1.9.0
     */
    public static function the_course_enrolment_actions()
    {
        ?>
        <section class="course-meta course-enrolment">
        <?php 
        global $post, $current_user;
        $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID);
        if (is_user_logged_in() && !$is_user_taking_course) {
            // Get the product ID
            $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true));
            // Check for woocommerce
            if (Sensei_WC::is_woocommerce_active() && 0 < intval($wc_post_id)) {
                sensei_wc_add_to_cart($post->ID);
            } else {
                sensei_start_course_form($post->ID);
            }
            // End If Statement
        } elseif (is_user_logged_in()) {
            // Check if course is completed
            $user_course_status = Sensei_Utils::user_course_status($post->ID, $current_user->ID);
            $completed_course = Sensei_Utils::user_completed_course($user_course_status);
            // Success message
            if ($completed_course) {
                ?>
                <div class="status completed"><?php 
                _e('Completed', 'woothemes-sensei');
                ?>
</div>
                <?php 
                $has_quizzes = Sensei()->course->course_quizzes($post->ID, true);
                if (has_filter('sensei_results_links') || $has_quizzes) {
                    ?>
                    <p class="sensei-results-links">
                        <?php 
                    $results_link = '';
                    if ($has_quizzes) {
                        $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink($post->ID) . '">' . __('View results', 'woothemes-sensei') . '</a>';
                    }
                    /**
                     * Filter documented in Sensei_Course::the_course_action_buttons
                     */
                    $results_link = apply_filters('sensei_results_links', $results_link, $post->ID);
                    echo $results_link;
                    ?>
</p>
                <?php 
                }
                ?>
            <?php 
            } else {
                ?>
                <div class="status in-progress"><?php 
                echo __('In Progress', 'woothemes-sensei');
                ?>
</div>
            <?php 
            }
        } else {
            // Get the product ID
            $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true));
            // Check for woocommerce
            if (Sensei_WC::is_woocommerce_active() && 0 < intval($wc_post_id)) {
                sensei_wc_add_to_cart($post->ID);
            } else {
                if (get_option('users_can_register')) {
                    $my_courses_page_id = '';
                    /**
                     * Filter to force Sensei to output the default WordPress user
                     * registration link.
                     *
                     * @since 1.9.0
                     * @param bool $wp_register_link default false
                     */
                    $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
                    $settings = Sensei()->settings->get_settings();
                    if (isset($settings['my_course_page']) && 0 < intval($settings['my_course_page'])) {
                        $my_courses_page_id = $settings['my_course_page'];
                    }
                    // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
                    // is false, link to My Courses. If not, link to default WordPress registration page.
                    if (!empty($my_courses_page_id) && $my_courses_page_id && !$wp_register_link) {
                        $my_courses_url = get_permalink($my_courses_page_id);
                        $register_link = '<a href="' . $my_courses_url . '">' . __('Register', 'woothemes-sensei') . '</a>';
                        echo '<div class="status register">' . $register_link . '</div>';
                    } else {
                        wp_register('<div class="status register">', '</div>');
                    }
                }
                // end if user can register
            }
            // End If Statement
        }
        // End If Statement
        ?>

        </section><?php 
    }
Beispiel #12
0
 /**
  * check_user_permissions function.
  *
  * @access public
  * @param string $page (default: '')
  *
  * @return bool
  */
 public function check_user_permissions($page = '')
 {
     global $current_user, $post;
     // if user is not logged in skipped for single lesson
     if (empty($current_user->caps) && Sensei()->settings->get('access_permission') && 'lesson-single' != $page) {
         $this->permissions_message['title'] = __('Restricted Access:', 'woothemes-sensei');
         $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type());
         return false;
     }
     $user_allowed = false;
     switch ($page) {
         case 'course-single':
             // check for prerequisite course or lesson,
             $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true);
             $update_course = Sensei_WC::course_update($post->ID);
             // Count completed lessons
             if (0 < absint($course_prerequisite_id)) {
                 $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID);
             } else {
                 $prerequisite_complete = true;
             }
             // End If Statement
             // Handles restrictions
             if (!$prerequisite_complete && 0 < absint($course_prerequisite_id)) {
                 $this->permissions_message['title'] = get_the_title($post->ID) . ': ' . __('Restricted Access', 'woothemes-sensei');
                 $course_link = '<a href="' . esc_url(get_permalink($course_prerequisite_id)) . '">' . __('course', 'woothemes-sensei') . '</a>';
                 $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link);
             } else {
                 $user_allowed = true;
             }
             // End If Statement
             break;
         case 'lesson-single':
             // Check for WC purchase
             $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true);
             $update_course = Sensei_WC::course_update($lesson_course_id);
             $is_preview = Sensei_Utils::is_preview_lesson($post->ID);
             if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) {
                 $user_allowed = true;
             } elseif ($this->access_settings() && false == $is_preview) {
                 $user_allowed = true;
             } else {
                 $this->permissions_message['title'] = get_the_title($post->ID) . ': ' . __('Restricted Access', 'woothemes-sensei');
                 $course_link = '<a href="' . esc_url(get_permalink($lesson_course_id)) . '">' . __('course', 'woothemes-sensei') . '</a>';
                 $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true);
                 if (Sensei_WC::is_woocommerce_active() && 0 < $wc_post_id) {
                     if ($is_preview) {
                         $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
                     } else {
                         $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link);
                     }
                 } else {
                     if ($is_preview) {
                         $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
                     } else {
                         /** This filter is documented in class-woothemes-sensei-frontend.php */
                         $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
                     }
                 }
                 // End If Statement
             }
             // End If Statement
             break;
         case 'quiz-single':
             $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true);
             $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
             $update_course = Sensei_WC::course_update($lesson_course_id);
             if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) || sensei_all_access()) {
                 // Check for prerequisite lesson for this quiz
                 $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
                 $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID);
                 // Handle restrictions
                 if (sensei_all_access()) {
                     $user_allowed = true;
                 } else {
                     if (0 < absint($lesson_prerequisite_id) && !$user_lesson_prerequisite_complete) {
                         $this->permissions_message['title'] = get_the_title($post->ID) . ': ' . __('Restricted Access', 'woothemes-sensei');
                         $lesson_link = '<a href="' . esc_url(get_permalink($lesson_prerequisite_id)) . '">' . __('lesson', 'woothemes-sensei') . '</a>';
                         $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link);
                     } else {
                         $user_allowed = true;
                     }
                     // End If Statement
                 }
                 // End If Statement
             } elseif ($this->access_settings()) {
                 // Check if the user has started the course
                 if (is_user_logged_in() && !Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) && (isset($this->settings->settings['access_permission']) && true == $this->settings->settings['access_permission'])) {
                     $user_allowed = false;
                     $this->permissions_message['title'] = get_the_title($post->ID) . ': ' . __('Restricted Access', 'woothemes-sensei');
                     $course_link = '<a href="' . esc_url(get_permalink($lesson_course_id)) . '">' . __('course', 'woothemes-sensei') . '</a>';
                     $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true);
                     if (Sensei_WC::is_woocommerce_active() && 0 < $wc_post_id) {
                         $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link);
                     } else {
                         $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link);
                     }
                     // End If Statement
                 } else {
                     $user_allowed = true;
                 }
                 // End If Statement
             } else {
                 $this->permissions_message['title'] = get_the_title($post->ID) . ': ' . __('Restricted Access', 'woothemes-sensei');
                 $course_link = '<a href="' . esc_url(get_permalink(get_post_meta(get_post_meta($post->ID, '_quiz_lesson', true), '_lesson_course', true))) . '">' . __('course', 'woothemes-sensei') . '</a>';
                 $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link);
             }
             // End If Statement
             break;
         default:
             $user_allowed = true;
             break;
     }
     // End Switch Statement
     /**
      * filter the permissions message shown on sensei post types.
      *
      * @since 1.8.7
      *
      * @param array $permissions_message{
      *
      *   @type string $title
      *   @type string $message
      *
      * }
      * @param string $post_id
      */
     $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID);
     if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) {
         $user_allowed = true;
     }
     /**
      * Filter the permissions check final result. Which determines if the user has
      * access to the given page.
      *
      * @since 1.0
      *
      * @param boolean $user_allowed
      * @param integer $user_id
      *
      */
     return apply_filters('sensei_access_permissions', $user_allowed, $current_user->ID);
 }