1: <?php
2: if ( ! defined( 'ABSPATH' ) ) exit;
3:
4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Sensei_Frontend {
15:
16: public $messages;
17: public $data;
18:
19: 20: 21: 22:
23: public function __construct () {
24:
25:
26: add_action( 'sensei_before_main_content', array( $this, 'sensei_output_content_wrapper' ), 10 );
27: add_action( 'sensei_after_main_content', array( $this, 'sensei_output_content_wrapper_end' ), 10 );
28: add_action( 'sensei_lesson_archive_lesson_title', array( $this, 'sensei_lesson_archive_lesson_title' ), 10 );
29:
30:
31: add_action( 'wp_head', array( $this, 'sensei_complete_lesson' ), 10 );
32: add_action( 'wp_head', array( $this, 'sensei_complete_course' ), 10 );
33: add_action( 'sensei_frontend_messages', array( $this, 'sensei_frontend_messages' ) );
34: add_action( 'sensei_lesson_video', array( $this, 'sensei_lesson_video' ), 10, 1 );
35: add_action( 'sensei_complete_lesson_button', array( $this, 'sensei_complete_lesson_button' ) );
36: add_action( 'sensei_reset_lesson_button', array( $this, 'sensei_reset_lesson_button' ) );
37:
38: add_action( 'sensei_course_archive_meta', array( $this, 'sensei_course_archive_meta' ) );
39:
40: add_action( 'sensei_lesson_tag_main_content', array( $this, 'sensei_lesson_archive_main_content' ), 10 );
41: add_action( 'sensei_no_permissions_main_content', array( $this, 'sensei_no_permissions_main_content' ), 10 );
42:
43: add_action( 'sensei_lesson_meta', array( $this, 'sensei_lesson_meta' ), 10 );
44: add_action( 'sensei_single_course_content_inside_before', array( $this, 'sensei_course_start' ), 10 );
45:
46:
47: add_filter( 'the_title', array( $this, 'sensei_lesson_preview_title' ), 10, 2 );
48:
49:
50: add_filter( 'wp_login_failed', array( $this, 'sensei_login_fail_redirect' ), 10 );
51: add_filter( 'init', array( $this, 'sensei_handle_login_request' ), 10 );
52:
53: add_action( 'init', array( $this, 'sensei_process_registration' ), 2 );
54:
55: add_action( 'sensei_pagination', array( $this, 'sensei_breadcrumb' ), 80, 1 );
56:
57:
58: add_filter( 'pre_get_posts', array( $this, 'sensei_course_archive_pagination' ) );
59:
60:
61: add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
62: add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
63:
64:
65: add_filter( 'wp_setup_nav_menu_item', array( $this, 'sensei_setup_nav_menu_item' ) );
66: add_filter( 'wp_nav_menu_objects', array( $this, 'sensei_wp_nav_menu_objects' ) );
67:
68: add_filter( 'post_class', array( $this, 'sensei_search_results_classes' ), 10 );
69:
70: add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) );
71:
72:
73: add_action( 'init', array( $this, 'sensei_show_admin_bar') );
74:
75:
76: add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
77: add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
78: add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
79: add_action( 'woocommerce_order_status_processing_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
80: add_action( 'woocommerce_order_status_completed_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
81: add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
82:
83:
84: add_action( 'sensei_before_my_courses', array( $this, 'activate_purchased_courses' ), 10, 1 );
85: add_action( 'sensei_single_course_content_inside_before', array( $this, 'activate_purchased_single_course' ), 10 );
86:
87:
88: add_action( 'sensei_lesson_meta_extra', array( $this, 'lesson_tags_display' ), 10, 1 );
89: add_action( 'pre_get_posts', array( $this, 'lesson_tag_archive_filter' ), 10, 1 );
90: add_filter( 'sensei_lessons_archive_text', array( $this, 'lesson_tag_archive_header' ) );
91: add_action( 'sensei_loop_lesson_inside_before', array( $this, 'lesson_tag_archive_description' ), 11 );
92:
93:
94: add_filter( 'wp_list_comments_args', array( $this, 'hide_sensei_activity' ) );
95: }
96:
97: 98: 99: 100: 101: 102: 103:
104: public function __get( $key ) {
105:
106: if ( 'lesson' == $key || 'course' == $key ) {
107: if ( WP_DEBUG ) {
108: trigger_error( sprintf( 'Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3' ) );
109: }
110: return Sensei()->$key;
111: }
112:
113: return null;
114: }
115:
116: 117: 118: 119: 120:
121: public function enqueue_scripts () {
122:
123: $disable_js = false;
124: if ( isset( Sensei()->settings->settings[ 'js_disable' ] ) ) {
125: $disable_js = Sensei()->settings->settings[ 'js_disable' ];
126: }
127: if ( ! $disable_js ) {
128:
129: $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
130:
131:
132: wp_register_script( Sensei()->token . '-user-dashboard', esc_url( Sensei()->plugin_url . 'assets/js/user-dashboard' . $suffix . '.js' ), array( 'jquery-ui-tabs' ), Sensei()->version, true );
133: wp_enqueue_script( Sensei()->token . '-user-dashboard' );
134:
135:
136:
137: if( is_post_type_archive( 'course' ) ){
138:
139: wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
140: wp_enqueue_script( 'sensei-course-archive-js' );
141:
142: }
143:
144:
145:
146: do_action( 'sensei_additional_scripts' );
147:
148: }
149:
150: }
151:
152: 153: 154: 155: 156:
157: public function enqueue_styles () {
158:
159: $disable_styles = false;
160: if ( isset( Sensei()->settings->settings[ 'styles_disable' ] ) ) {
161: $disable_styles = Sensei()->settings->settings[ 'styles_disable' ];
162: }
163:
164:
165: $disable_styles = apply_filters( 'sensei_disable_styles', $disable_styles );
166:
167: if ( ! $disable_styles ) {
168:
169: wp_register_style( Sensei()->token . '-frontend', Sensei()->plugin_url . 'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen' );
170: wp_enqueue_style( Sensei()->token . '-frontend' );
171:
172:
173: do_action( 'sensei_additional_styles' );
174:
175: }
176:
177: }
178:
179:
180: 181: 182: 183: 184: 185: 186: 187: 188:
189: function sensei_get_template_part( $slug, $name = '' ) {
190:
191: Sensei_Templates::get_part( $slug, $name );
192:
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205:
206: function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
207:
208: _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
209: Sensei_Templates::get_template($template_name, $args, $template_path, $default_path );
210:
211: }
212:
213:
214: 215: 216: 217: 218: 219: 220: 221: 222:
223: function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) {
224:
225: _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
226: Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
227:
228: }
229:
230:
231: 232: 233: 234: 235: 236:
237: function sensei_output_content_wrapper() {
238:
239:
240: $backwards_compatible_wrapper_location = array(
241: Sensei()->template_url . 'wrappers/wrapper-start.php',
242: 'wrappers/wrapper-start.php'
243: );
244:
245: $template = locate_template( $backwards_compatible_wrapper_location );
246: if( !empty( $template ) ){
247:
248: Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
249: return;
250:
251: }
252:
253: Sensei_Templates::get_template( 'globals/wrapper-start.php' );
254:
255: }
256:
257:
258: 259: 260: 261: 262: 263:
264: function sensei_output_content_wrapper_end() {
265:
266:
267: $backwards_compatible_wrapper_location = array(
268: Sensei()->template_url . 'wrappers/wrapper-end.php',
269: 'wrappers/wrapper-end.php'
270: );
271:
272: $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
273: if( !empty( $backwards_compatible_template ) ){
274:
275: Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
276: return;
277:
278: }
279:
280:
281: Sensei_Templates::get_template( 'globals/wrapper-end.php' );
282:
283: }
284:
285:
286: 287: 288: 289: 290: 291:
292: public static function load_content_pagination() {
293:
294: if( is_singular('course') ) {
295:
296:
297: $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
298: if( !empty( $template ) ){
299:
300: Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
301: return;
302:
303: }
304:
305: Sensei_Templates::get_template( 'globals/pagination-posts.php' );
306:
307: } elseif( is_singular('lesson') ) {
308:
309:
310: $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) );
311: if( !empty( $template ) ){
312:
313: Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
314: return;
315:
316: }
317:
318: Sensei_Templates::get_template( 'globals/pagination-lesson.php' );
319:
320: } elseif( is_singular('quiz') ) {
321:
322:
323: $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) );
324: if( !empty( $template ) ){
325:
326: Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
327: return;
328:
329: }
330:
331: Sensei_Templates::get_template( 'globals/pagination-quiz.php' );
332:
333: } else {
334:
335:
336: $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) );
337: if( !empty( $template ) ){
338:
339: Sensei_Templates::get_template( 'wrappers/pagination.php' );
340: return;
341:
342: }
343:
344: Sensei_Templates::get_template( 'globals/pagination.php' );
345:
346: }
347:
348: }
349:
350: 351: 352: 353: 354:
355: function sensei_output_comments() {
356:
357: Sensei_Lesson::output_comments();
358:
359: }
360:
361: 362: 363: 364: 365: 366: 367: 368: 369:
370: public function sensei_setup_nav_menu_item( $item ) {
371: global $pagenow, $wp_rewrite;
372:
373: if( 'nav-menus.php' != $pagenow && !defined('DOING_AJAX') && isset( $item->url ) && 'custom' == $item->type ) {
374:
375:
376: $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
377: $my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
378:
379: $course_page_url = Sensei_Course::get_courses_page_url();
380: $lesson_archive_url = get_post_type_archive_link( 'lesson' );
381: $my_courses_url = get_permalink( $my_account_page_id );
382: $my_messages_url = get_post_type_archive_link( 'sensei_message' );
383:
384: switch ( $item->url ) {
385: case '#senseicourses':
386: $item->url = $course_page_url;
387: break;
388:
389: case '#senseilessons':
390: $item->url = $lesson_archive_url;
391: break;
392:
393: case '#senseimycourses':
394: $item->url = $my_courses_url;
395: break;
396:
397: case '#senseimymessages':
398: $item->url = $my_messages_url;
399:
400:
401: if( ! $item->url ){
402:
403: $item->url = '#senseimymessages';
404:
405: }
406: break;
407:
408: case '#senseilearnerprofile':
409: $item->url = esc_url( Sensei()->learner_profiles->get_permalink() );
410: break;
411:
412: case '#senseiloginlogout':
413: $logout_url = wp_logout_url( home_url() );
414:
415: $login_url = $my_courses_url;
416:
417: $item->url = ( is_user_logged_in() ? $logout_url : $login_url );
418:
419:
420: if ( is_user_logged_in() ) {
421: $menu_title = __( 'Logout' ,'woothemes-sensei');
422: } else {
423: $menu_title = __( 'Login' ,'woothemes-sensei');
424: }
425:
426: 427: 428: 429: 430: 431: 432:
433: $item->title = apply_filters( 'sensei_login_logout_menu_title', $menu_title );
434:
435: break;
436:
437: default:
438: break;
439: }
440:
441: $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
442: $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
443: $item_url = untrailingslashit( $item->url );
444: $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
445:
446: if ( $item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {
447: $item->classes[] = 'current-menu-item current_page_item';
448: }
449:
450: }
451:
452: return $item;
453:
454: }
455:
456: 457: 458: 459: 460: 461: 462: 463: 464:
465: public function sensei_wp_nav_menu_objects( $sorted_menu_items ) {
466:
467: foreach( $sorted_menu_items as $k=>$item ) {
468:
469:
470: if( ! get_post_type_archive_link( 'sensei_message' )
471: && '#senseimymessages' == $item->url ) {
472:
473: if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) {
474:
475: unset( $sorted_menu_items[$k] );
476:
477: }
478: }
479:
480: if( Sensei()->learner_profiles->get_permalink() == $item->url ) {
481:
482: if ( !is_user_logged_in() || ! ( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] ) && Sensei()->settings->settings[ 'learner_profile_enable' ] ) ) {
483:
484: unset( $sorted_menu_items[$k] );
485:
486: }
487: }
488: }
489: return $sorted_menu_items;
490: }
491:
492:
493: function sensei_search_results_classes($classes) {
494: global $post;
495:
496: if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
497: $classes[] = 'post';
498: }
499: return $classes;
500: }
501:
502: 503: 504: 505: 506: 507:
508: function the_single_title() {
509:
510: _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0');
511:
512: }
513:
514: 515: 516: 517: 518: 519: 520: 521: 522: 523:
524: function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) {
525:
526: if ( ! $return ) {
527:
528: echo Sensei()->course->course_image( $course_id, $width, $height );
529: return '';
530:
531: }
532:
533: return Sensei()->course->course_image( $course_id, $width, $height );
534:
535: }
536:
537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547:
548: function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) {
549:
550: if( ! $return ){
551:
552: echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
553: return '';
554: }
555:
556: return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
557:
558: }
559:
560: 561: 562: 563:
564: function sensei_course_archive_pagination( $query ) {
565:
566: if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) {
567:
568: $amount = 0;
569: if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
570: $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
571: }
572:
573: if( $amount ) {
574: $query->set( 'posts_per_page', $amount );
575: }
576:
577: $query->set( 'orderby', 'menu_order date' );
578:
579: }
580: }
581:
582: 583: 584: 585: 586: 587: 588: 589:
590: function sensei_course_archive_header( ) {
591:
592: trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
593: WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
594:
595: }
596:
597: 598: 599: 600: 601: 602: 603: 604:
605: public function sensei_lesson_archive_header( ) {
606: _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
607: Sensei()->lesson->the_archive_header();
608: }
609:
610: 611: 612:
613: public function sensei_message_archive_header( ){
614: _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
615: Sensei_Messages::the_archive_header();
616: }
617:
618: 619: 620: 621: 622: 623:
624: function sensei_course_archive_course_title( $post_item ) {
625: if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) {
626: $post_id = absint( $post_item->ID );
627: $post_title = $post_item->post_title;
628: } else {
629: $post_id = get_the_ID();
630: $post_title = get_the_title();
631: }
632: ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
633: }
634:
635: 636: 637: 638: 639:
640: public function sensei_lesson_archive_lesson_title() {
641: $post_id = get_the_ID();
642: $post_title = get_the_title();
643: ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
644: }
645:
646: 647: 648: 649: 650: 651:
652: public function sensei_breadcrumb( $id = 0 ) {
653:
654:
655: if( ! ( is_tax( 'module' ) || is_singular( 'lesson' ) || is_singular( 'quiz' ) ) ) return;
656:
657: if( empty( $id ) ){
658:
659: $id = get_the_ID();
660:
661: }
662:
663: $sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' );
664: $separator = apply_filters( 'sensei_breadcrumb_separator', '>' );
665:
666: $html = '<section class="sensei-breadcrumb">' . $sensei_breadcrumb_prefix;
667:
668: if ( is_singular( 'lesson' ) && 0 < intval( $id ) ) {
669: $course_id = intval( get_post_meta( $id, '_lesson_course', true ) );
670: if( ! $course_id ) {
671: return;
672: }
673: $html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>';
674: }
675:
676: if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) {
677: $lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) );
678: if( ! $lesson_id ) {
679: return;
680: }
681: $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>';
682: }
683:
684:
685: $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
686: $html .= '</section>';
687:
688: echo $html;
689: }
690:
691:
692: 693: 694:
695: public function sensei_lesson_course_signup_link( ) {
696:
697: _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
698: WooThemes_Sensei_Lesson::course_signup_link();
699: }
700:
701: public function lesson_tags_display( $lesson_id = 0 ) {
702: if( $lesson_id ) {
703: $tags = wp_get_post_terms( $lesson_id, 'lesson-tag' );
704: if( $tags && count( $tags ) > 0 ) {
705: $tag_list = '';
706: foreach( $tags as $tag ) {
707: $tag_link = get_term_link( $tag, 'lesson-tag' );
708: if( ! is_wp_error( $tag_link ) ) {
709: if( $tag_list ) { $tag_list .= ', '; }
710: $tag_list .= '<a href="' . $tag_link . '">' . $tag->name . '</a>';
711: }
712: }
713: if( $tag_list ) {
714: ?><section class="lesson-tags">
715: <?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?>
716: </section><?php
717: }
718: }
719: }
720: }
721:
722: 723: 724:
725: public function lesson_tag_archive_filter( $query ) {
726: if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
727:
728: $query->set( 'post_type', 'lesson' );
729:
730:
731: $query->set( 'orderby', 'menu_order' );
732: $query->set( 'order', 'ASC' );
733:
734: }
735: }
736:
737: public function lesson_tag_archive_header( $title ) {
738: if( is_tax( 'lesson-tag' ) ) {
739: $title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) );
740: }
741: return $title;
742: }
743:
744: public function lesson_tag_archive_description() {
745: if( is_tax( 'lesson-tag' ) ) {
746: $tag = get_queried_object();
747: echo '<p class="archive-description lesson-description">' . apply_filters( 'sensei_lesson_tag_archive_description', nl2br( $tag->description ), $tag->term_id ) . '</p>';
748: }
749: }
750:
751: public function sensei_complete_lesson() {
752: global $post, $current_user;
753:
754: if ( isset( $_POST['quiz_action'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_lesson_noonce' ], 'woothemes_sensei_complete_lesson_noonce' ) ) {
755:
756: $sanitized_submit = esc_html( $_POST['quiz_action'] );
757:
758: switch ($sanitized_submit) {
759: case 'lesson-complete':
760:
761: Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true );
762:
763: break;
764:
765: case 'lesson-reset':
766:
767: Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID );
768:
769: $this->messages = '<div class="sensei-message note">' . __( 'Lesson Reset Successfully.', 'woothemes-sensei' ) . '</div>';
770: break;
771:
772: default:
773:
774: break;
775:
776: }
777:
778: }
779:
780: }
781:
782: public function sensei_complete_course() {
783: global $post, $current_user, $wp_query;
784: if ( isset( $_POST['course_complete'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_course_noonce' ], 'woothemes_sensei_complete_course_noonce' ) ) {
785:
786: $sanitized_submit = esc_html( $_POST['course_complete'] );
787: $sanitized_course_id = absint( esc_html( $_POST['course_complete_id'] ) );
788:
789: switch ($sanitized_submit) {
790: case __( 'Mark as Complete', 'woothemes-sensei' ):
791:
792:
793: $course_metadata = array(
794: 'start' => current_time('mysql'),
795: 'percent' => 0,
796: 'complete' => 0,
797: );
798: $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata );
799:
800: if ( $activity_logged ) {
801:
802: $course_lesson_ids = Sensei()->course->course_lessons( $sanitized_course_id, 'any', 'ids' );
803:
804: foreach ( $course_lesson_ids as $lesson_item_id ){
805:
806: $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_item_id, $current_user->ID, $complete = true );
807: }
808:
809:
810: $course_metadata = array(
811: 'percent' => 100,
812: 'complete' => count($course_lesson_ids),
813: );
814: $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'complete', $course_metadata );
815:
816: do_action( 'sensei_user_course_end', $current_user->ID, $sanitized_course_id );
817:
818:
819: $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s marked as complete.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>';
820: }
821:
822: break;
823:
824: case __( 'Delete Course', 'woothemes-sensei' ):
825:
826: Sensei_Utils::sensei_remove_user_from_course( $sanitized_course_id, $current_user->ID );
827:
828:
829: $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s deleted.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>';
830: break;
831:
832: default:
833:
834: break;
835: }
836:
837: }
838: }
839:
840: 841: 842: 843: 844:
845: public function sensei_get_user_quiz_answers( $lesson_id = 0 ) {
846: global $current_user;
847:
848: $user_answers = array();
849:
850: if ( 0 < intval( $lesson_id ) ) {
851: $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $lesson_id );
852: foreach( $lesson_quiz_questions as $question ) {
853: $answer = maybe_unserialize( base64_decode( Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content' ) ) ) );
854: $user_answers[ $question->ID ] = $answer;
855: }
856: }
857:
858: return $user_answers;
859: }
860:
861: public function sensei_has_user_completed_lesson( $post_id = 0, $user_id = 0 ) {
862: _deprecated_function( __FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()" );
863: return Sensei_Utils::user_completed_lesson( $post_id, $user_id );
864: }
865:
866: 867: 868:
869: public function sensei_frontend_messages() {
870: Sensei()->notices->maybe_print_notices();
871: }
872:
873: public function sensei_lesson_video( $post_id = 0 ) {
874: if ( 0 < intval( $post_id ) ) {
875: $lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true );
876: if ( 'http' == substr( $lesson_video_embed, 0, 4) ) {
877:
878: $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed ) );
879: }
880: if ( '' != $lesson_video_embed ) {
881: ?><div class="video"><?php echo do_shortcode( html_entity_decode( $lesson_video_embed ) ); ?></div><?php
882: }
883: }
884: }
885:
886: public function sensei_complete_lesson_button() {
887: global $post;
888:
889: $quiz_id = 0;
890:
891:
892: $course_id = Sensei()->lesson->get_course_id( $post->ID );
893: if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){
894: return;
895: }
896:
897:
898: $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID );
899: $pass_required = true;
900: if( $quiz_id ) {
901:
902: $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
903: }
904: if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) {
905: ?>
906: <form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
907: <input type="hidden"
908: name="woothemes_sensei_complete_lesson_noonce"
909: id="woothemes_sensei_complete_lesson_noonce"
910: value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>"
911: />
912:
913: <input type="hidden" name="quiz_action" value="lesson-complete" />
914:
915: <input type="submit"
916: name="quiz_complete"
917: class="quiz-submit complete"
918: value="<?php _e( 'Complete Lesson', 'woothemes-sensei' ); ?>"/>
919:
920: </form>
921: <?php
922: }
923: }
924:
925: public function sensei_reset_lesson_button() {
926: global $post;
927:
928: $quiz_id = 0;
929:
930:
931: $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID );
932: $reset_allowed = true;
933: if( $quiz_id ) {
934:
935: $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
936: }
937: if ( ! $quiz_id || !empty($reset_allowed) ) {
938: ?>
939: <form method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
940:
941: <input
942: type="hidden"
943: name="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>"
944: id="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>"
945: value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" />
946:
947: <input type="hidden" name="quiz_action" value="lesson-reset" />
948:
949: <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e( 'Reset Lesson', 'woothemes-sensei' ); ?>"/>
950:
951: </form>
952: <?php
953: }
954: }
955:
956: 957: 958:
959: public function sensei_lesson_quiz_meta( ) {
960:
961: Sensei_Lesson::footer_quiz_call_to_action();
962:
963: }
964:
965: public function sensei_course_archive_meta() {
966: global $post;
967:
968: $post_id = get_the_ID();
969: $post_title = get_the_title();
970: $author_display_name = get_the_author();
971: $author_id = get_the_author_meta('ID');
972: $category_output = get_the_term_list( $post_id, 'course-category', '', ', ', '' );
973: $free_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $post_id ) );
974: ?><section class="entry">
975: <p class="sensei-course-meta">
976: <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
977: <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span>
978: <?php }
979: <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?></span>
980: <?php if ( '' != $category_output ) { ?>
981: <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
982: <?php }
983: <?php sensei_simple_course_price( $post_id ); ?>
984: </p>
985: <p class="course-excerpt"><?php the_excerpt(); ?></p>
986: <?php if ( 0 < $free_lesson_count ) {
987: $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
988: <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p>
989: <?php } ?>
990: </section><?php
991: }
992:
993: 994: 995:
996: public function sensei_single_main_content() {
997: _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0');
998: }
999:
1000: 1001: 1002:
1003: public function sensei_lesson_archive_main_content() {
1004: _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly');
1005: }
1006:
1007: 1008: 1009:
1010: public function sensei_message_archive_main_content() {
1011: _deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' );
1012: }
1013:
1014: 1015: 1016:
1017: public function sensei_no_permissions_main_content() {
1018: _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1019: }
1020:
1021: public function sensei_course_category_main_content() {
1022: global $post;
1023: if ( have_posts() ) { ?>
1024:
1025: <section id="main-course" class="course-container">
1026:
1027: <?php do_action( 'sensei_course_archive_header' ); ?>
1028:
1029: <?php while ( have_posts() ) { the_post(); ?>
1030:
1031: <article class="<?php echo join( ' ', get_post_class( array( 'course', 'post' ), get_the_ID() ) ); ?>">
1032:
1033: <?php sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', get_the_ID() ); ?>
1034:
1035: <?php sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before', $post ); ?>
1036:
1037: <?php do_action( 'sensei_course_archive_meta' ); ?>
1038:
1039: </article>
1040:
1041: <?php }
1042:
1043: </section>
1044:
1045: <?php } else { ?>
1046:
1047: <p>
1048:
1049: <?php _e( 'No courses found that match your selection.', 'woothemes-sensei' ); ?>
1050:
1051: </p>
1052:
1053: <?php }
1054:
1055: }
1056:
1057: public function sensei_login_form() {
1058: ?>
1059: <div id="my-courses">
1060: <?php Sensei()->notices->maybe_print_notices(); ?>
1061: <div class="col2-set" id="customer_login">
1062:
1063: <div class="col-1">
1064: <?php
1065:
1066: Sensei_Templates::get_template( 'user/login-form.php');
1067: ?>
1068: </div>
1069:
1070: <?php
1071: if ( get_option('users_can_register') ) {
1072:
1073:
1074: $action_url = get_permalink();
1075:
1076: ?>
1077:
1078: <div class="col-2">
1079: <h2><?php _e( 'Register', 'woothemes-sensei' ); ?></h2>
1080:
1081: <form method="post" class="register" action="<?php echo esc_url( $action_url ); ?>" >
1082:
1083: <?php do_action( 'sensei_register_form_start' ); ?>
1084:
1085: <p class="form-row form-row-wide">
1086: <label for="sensei_reg_username"><?php _e( 'Username', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1087: <input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty( $_POST['sensei_reg_username'] ) ) esc_attr_e( $_POST['sensei_reg_username'] ); ?>" />
1088: </p>
1089:
1090: <p class="form-row form-row-wide">
1091: <label for="sensei_reg_email"><?php _e( 'Email address', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1092: <input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty( $_POST['sensei_reg_email'] ) ) esc_attr_e( $_POST['sensei_reg_email'] ); ?>" />
1093: </p>
1094:
1095: <p class="form-row form-row-wide">
1096: <label for="sensei_reg_password"><?php _e( 'Password', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1097: <input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty( $_POST['sensei_reg_password'] ) ) esc_attr_e( $_POST['sensei_reg_password'] ); ?>" />
1098: </p>
1099:
1100: <!-- Spam Trap -->
1101: <div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woothemes-sensei' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>
1102:
1103: <?php do_action( 'sensei_register_form_fields' ); ?>
1104: <?php do_action( 'register_form' ); ?>
1105:
1106: <p class="form-row">
1107: <input type="submit" class="button" name="register" value="<?php _e( 'Register', 'woothemes-sensei' ); ?>" />
1108: </p>
1109:
1110: <?php do_action( 'sensei_register_form_end' ); ?>
1111:
1112: </form>
1113: </div>
1114: <?php
1115: }
1116: ?>
1117: </div>
1118: </div>
1119:
1120: <?php
1121: }
1122:
1123: public function sensei_lesson_meta( $post_id = 0 ) {
1124: global $post;
1125: if ( 0 < intval( $post_id ) ) {
1126: $lesson_course_id = absint( get_post_meta( $post_id, '_lesson_course', true ) );
1127: ?><section class="entry">
1128: <p class="sensei-course-meta">
1129: <?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?>
1130: <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span>
1131: <?php } ?>
1132: <?php if ( 0 < intval( $lesson_course_id ) ) { ?>
1133: <span class="lesson-course"><?php echo ' ' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . __( 'View course', 'woothemes-sensei' ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span>
1134: <?php } ?>
1135: </p>
1136: <p class="lesson-excerpt"><?php the_excerpt( ); ?></p>
1137: </section><?php
1138: }
1139: }
1140:
1141: public function sensei_lesson_preview_title_text( $course_id ) {
1142:
1143: $preview_text = __( ' (Preview)', 'woothemes-sensei' );
1144:
1145:
1146: if ( Sensei_WC::is_woocommerce_active() ) {
1147: $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1148: if ( 0 < $wc_post_id ) {
1149: $preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1150: }
1151: }
1152: return $preview_text;
1153: }
1154:
1155: public function sensei_lesson_preview_title( $title = '', $id = 0 ) {
1156: global $post, $current_user;
1157:
1158:
1159:
1160: if( isset( $post->ID ) && $id == $post->ID && 'lesson' == get_post_type( $post ) ) {
1161:
1162:
1163: if( is_main_query() ) {
1164:
1165:
1166: $course_id = get_post_meta( $post->ID, '_lesson_course', true );
1167:
1168:
1169: if( is_singular( 'lesson' ) && Sensei_Utils::is_preview_lesson( $post->ID ) && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID ) && $post->ID == $id ) {
1170: $title .= ' ' . $this->sensei_lesson_preview_title_text( $course_id );
1171: }
1172: }
1173: }
1174: return $title;
1175: }
1176:
1177: public function sensei_course_start() {
1178: global $post, $current_user;
1179:
1180:
1181: $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
1182:
1183: if ( isset( $_POST['course_start'] )
1184: && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1185: && !$is_user_taking_course ) {
1186:
1187:
1188: $activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID );
1189: $this->data = new stdClass();
1190: $this->data->is_user_taking_course = false;
1191: if ( $activity_logged ) {
1192: $this->data->is_user_taking_course = true;
1193:
1194:
1195: ?>
1196:
1197: <script type="text/javascript"> window.location = '<?php echo get_permalink( $post->ID ); ?>'; </script>
1198:
1199: <?php
1200: }
1201: }
1202: }
1203:
1204: 1205: 1206:
1207: public function sensei_course_meta() {
1208: _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1209: Sensei()->course->the_course_meta( get_post() );
1210: }
1211:
1212: 1213: 1214:
1215: public function sensei_course_meta_video() {
1216: _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1217: Sensei_Course::the_course_video();
1218: }
1219:
1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227:
1228: public function sensei_woocommerce_in_cart_message() {
1229: global $post, $woocommerce;
1230:
1231: $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
1232: $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1233: if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
1234:
1235: if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) {
1236: echo '<div class="sensei-message info">' . sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei') . '</div>', '<a class="cart-complete" href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __('complete the purchase', 'woothemes-sensei') . '">' . __('complete the purchase', 'woothemes-sensei') . '</a>' );
1237: }
1238:
1239: }
1240:
1241: }
1242:
1243:
1244: public function sensei_lesson_comment_count( $count ) {
1245: return $count;
1246: }
1247:
1248: 1249: 1250: 1251: 1252:
1253: public function sensei_search_results_excerpt( $content ) {
1254: global $post;
1255:
1256: if( is_search() && in_array( $post->post_type, array( 'course', 'lesson' ) ) ) {
1257:
1258:
1259: remove_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) );
1260:
1261:
1262: $content = '<p class="course-excerpt">' . get_the_excerpt( ) . '</p>';
1263: }
1264:
1265: return $content;
1266: }
1267:
1268: 1269: 1270: 1271: 1272:
1273: public function remove_active_course( $order_id ) {
1274: $order = new WC_Order( $order_id );
1275:
1276: foreach ( $order->get_items() as $item ) {
1277: if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1278:
1279: $item_id = $item['variation_id'];
1280: } else {
1281:
1282: $item_id = $item['product_id'];
1283: }
1284:
1285: if ( $item_id > 0 ) {
1286:
1287: $user_id = get_post_meta( $order_id, '_customer_user', true );
1288:
1289: if( $user_id ) {
1290:
1291:
1292: $args = array(
1293: 'posts_per_page' => -1,
1294: 'post_type' => 'course',
1295: 'meta_query' => array(
1296: array(
1297: 'key' => '_course_woocommerce_product',
1298: 'value' => $item_id
1299: )
1300: ),
1301: 'orderby' => 'menu_order date',
1302: 'order' => 'ASC',
1303: 'fields' => 'ids',
1304: );
1305: $course_ids = get_posts( $args );
1306:
1307: if( $course_ids && count( $course_ids ) > 0 ) {
1308: foreach( $course_ids as $course_id ) {
1309:
1310:
1311: Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1312:
1313: }
1314: }
1315: }
1316: }
1317: }
1318: }
1319:
1320:
1321: 1322: 1323: 1324: 1325: 1326:
1327: public function activate_purchased_courses( $user_id = 0 ) {
1328:
1329: if( $user_id ) {
1330:
1331: if( Sensei_WC::is_woocommerce_active() ) {
1332:
1333:
1334: $order_args = array(
1335: 'post_type' => 'shop_order',
1336: 'post_status' => array( 'wc-processing', 'wc-completed' ),
1337: 'posts_per_page' => -1,
1338: 'meta_query' => array(
1339: array(
1340: 'key' => '_customer_user',
1341: 'value' => $user_id
1342: )
1343: ),
1344: );
1345:
1346: $orders = get_posts( $order_args );
1347:
1348: $product_ids = array();
1349: $order_ids = array();
1350:
1351: foreach( $orders as $post_id ) {
1352:
1353:
1354: $processed = get_post_meta( $post_id, 'sensei_products_processed', true );
1355:
1356: if( $processed && $processed == 'processed' ) {
1357: continue;
1358: }
1359:
1360:
1361: $order = new WC_Order( $post_id );
1362:
1363: $items = $order->get_items();
1364: foreach( $items as $item ) {
1365: if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1366: $item_id = $item['variation_id'];
1367: $product_type = 'variation';
1368: } else {
1369: $item_id = $item['product_id'];
1370: }
1371:
1372: $product_ids[] = $item_id;
1373: }
1374:
1375: $order_ids[] = $post_id;
1376: }
1377:
1378: if( count( $product_ids ) > 0 ) {
1379:
1380:
1381: $course_args = array(
1382: 'post_type' => 'course',
1383: 'posts_per_page' => -1,
1384: 'meta_query' => array(
1385: array(
1386: 'key' => '_course_woocommerce_product',
1387: 'value' => $product_ids,
1388: 'compare' => 'IN'
1389: )
1390: ),
1391: 'orderby' => 'menu_order date',
1392: 'order' => 'ASC',
1393: 'fields' => 'ids',
1394: );
1395: $course_ids = get_posts( $course_args );
1396:
1397: foreach( $course_ids as $course_id ) {
1398:
1399: $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id );
1400:
1401:
1402: if( Sensei_Utils::user_completed_course( $user_course_status ) ) {
1403: continue;
1404: }
1405:
1406:
1407: if( $user_course_status ) {
1408: continue;
1409: }
1410:
1411:
1412: Sensei_Utils::user_start_course( $user_id, $course_id );
1413: }
1414: }
1415:
1416: if( count( $order_ids ) > 0 ) {
1417: foreach( $order_ids as $order_id ) {
1418:
1419: update_post_meta( $order_id, 'sensei_products_processed', 'processed' );
1420: }
1421: }
1422: }
1423: }
1424: }
1425:
1426: 1427: 1428: 1429:
1430: public function activate_purchased_single_course() {
1431: global $post, $current_user;
1432:
1433: if( Sensei_WC::is_woocommerce_active() ) {
1434:
1435: if( ! is_user_logged_in() ) return;
1436: if( ! isset( $post->ID ) ) return;
1437:
1438: $user_id = $current_user->ID;
1439: $course_id = $post->ID;
1440: $course_product_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
1441: if( ! $course_product_id ) {
1442: return;
1443: }
1444:
1445: $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id );
1446:
1447:
1448: if( Sensei_Utils::user_completed_course( $user_course_status ) ) {
1449:
1450: return;
1451: }
1452:
1453:
1454: if( $user_course_status ) {
1455: return;
1456: }
1457:
1458:
1459: $order_args = array(
1460: 'post_type' => 'shop_order',
1461: 'posts_per_page' => -1,
1462: 'post_status' => array( 'wc-processing', 'wc-completed' ),
1463: 'meta_query' => array(
1464: array(
1465: 'key' => '_customer_user',
1466: 'value' => $user_id
1467: )
1468: ),
1469: 'fields' => 'ids',
1470: );
1471: $orders = get_posts( $order_args );
1472:
1473: foreach( $orders as $order_post_id ) {
1474:
1475:
1476: $order = new WC_Order( $order_post_id );
1477:
1478: $items = $order->get_items();
1479: foreach( $items as $item ) {
1480:
1481: $product = wc_get_product( $item['product_id'] );
1482:
1483:
1484: if( is_object( $product ) && $product->is_type('bundle') ){
1485:
1486: $bundled_product = new WC_Product_Bundle( $product->id );
1487: $bundled_items = $bundled_product->get_bundled_items();
1488:
1489: foreach( $bundled_items as $bundled_item ){
1490:
1491: if( $bundled_item->product_id == $course_product_id ) {
1492: Sensei_Utils::user_start_course( $user_id, $course_id );
1493: return;
1494: }
1495:
1496: }
1497:
1498: } else {
1499:
1500:
1501: if( $item['product_id'] == $course_product_id ) {
1502: Sensei_Utils::user_start_course( $user_id, $course_id );
1503: return;
1504: }
1505:
1506: }
1507: }
1508: }
1509:
1510: }
1511: }
1512:
1513: 1514: 1515: 1516: 1517:
1518: public function hide_sensei_activity( $args = array() ) {
1519:
1520: if( is_singular( 'lesson' ) || is_singular( 'course' ) ) {
1521: $args['type'] = 'comment';
1522: }
1523:
1524: return $args;
1525: }
1526:
1527: 1528: 1529: 1530: 1531: 1532:
1533: function sensei_login_fail_redirect( ) {
1534:
1535:
1536:
1537: if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){
1538:
1539: return ;
1540:
1541: }
1542:
1543:
1544: $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1545:
1546:
1547: if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1548:
1549: wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1550: exit;
1551: }
1552: }
1553:
1554: 1555: 1556: 1557: 1558:
1559: function sensei_handle_login_request( ) {
1560:
1561:
1562: if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1563:
1564:
1565: if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1566: return;
1567: }
1568:
1569:
1570: $referrer = $_REQUEST['_wp_http_referer'];
1571:
1572:
1573: if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1574: && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1575:
1576:
1577: $creds = array();
1578:
1579:
1580: if( is_email( trim( $_REQUEST['log'] ) ) ){
1581:
1582: $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) );
1583:
1584:
1585: if( !$user ){
1586:
1587:
1588: wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1589: exit;
1590:
1591: }
1592:
1593:
1594: $creds['user_login'] = $user->user_login ;
1595:
1596: }else{
1597:
1598:
1599: $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1600:
1601: }
1602:
1603:
1604: $creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] );
1605: $creds['remember'] = isset( $_REQUEST['rememberme'] ) ? true : false ;
1606:
1607:
1608: $secure_cookie = is_ssl() ? true : false;
1609: $user = wp_signon( $creds, $secure_cookie );
1610:
1611: if ( is_wp_error($user) ){
1612: wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1613: exit;
1614: }else{
1615:
1616: 1617: 1618: 1619: 1620: 1621: 1622:
1623:
1624: $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) );
1625:
1626: wp_redirect( esc_url_raw( $success_redirect_url ) );
1627: exit;
1628:
1629: }
1630:
1631: }else{
1632:
1633: wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1634: exit;
1635:
1636: }
1637:
1638: }elseif( ( isset( $_GET['login'] ) ) ) {
1639:
1640: $this->login_message_process();
1641:
1642:
1643: return;
1644: }
1645:
1646:
1647: return;
1648:
1649: }
1650:
1651: 1652: 1653: 1654: 1655: 1656:
1657: public function sensei_process_registration(){
1658: global $current_user;
1659:
1660: if( !isset( $_POST['sensei_reg_username'] ) && ! isset( $_POST['sensei_reg_email'] ) && !isset( $_POST['sensei_reg_password'] )){
1661:
1662: return ;
1663: }
1664:
1665: if( isset( $_POST['email_2'] ) && '' !== $_POST['email_2'] ){
1666: $message = 'Error: The spam field should be empty';
1667: Sensei()->notices->add_notice( $message, 'alert');
1668: return;
1669: }
1670:
1671:
1672: $new_user_name = sanitize_user( $_POST['sensei_reg_username'] );
1673: $new_user_email = $_POST['sensei_reg_email'];
1674: $new_user_password = $_POST['sensei_reg_password'];
1675:
1676:
1677: $username_error_notice = '';
1678: if ( $new_user_name == '' ) {
1679: $username_error_notice = __( '<strong>ERROR</strong>: Please enter a username.' );
1680: } elseif ( ! validate_username( $new_user_name ) ) {
1681: $username_error_notice = __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' );
1682: } elseif ( username_exists( $new_user_name ) ) {
1683: $username_error_notice = __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' );
1684: }
1685:
1686:
1687: if( '' !== $username_error_notice ){
1688: Sensei()->notices->add_notice( $username_error_notice , 'alert');
1689: return;
1690: }
1691:
1692:
1693: $email_error_notice = '';
1694: if ( $new_user_email == '' ) {
1695: $email_error_notice = __( '<strong>ERROR</strong>: Please type your e-mail address.' );
1696: } elseif ( ! is_email( $new_user_email ) ) {
1697: $email_error_notice = __( '<strong>ERROR</strong>: The email address isn’t correct.' );
1698: } elseif ( email_exists( $new_user_email ) ) {
1699: $email_error_notice = __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' );
1700: }
1701:
1702:
1703: if( '' !== $email_error_notice ){
1704: Sensei()->notices->add_notice( $email_error_notice , 'alert');
1705: return;
1706: }
1707:
1708:
1709:
1710:
1711: if( empty( $new_user_password ) ){
1712: Sensei()->notices->add_notice( __( '<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.' ) , 'alert');
1713: return;
1714: }
1715:
1716:
1717: $user_id = wp_create_user( $new_user_name, $new_user_password, $new_user_email );
1718: if ( ! $user_id || is_wp_error( $user_id ) ) {
1719: Sensei()->notices->add_notice( sprintf( __( '<strong>ERROR</strong>: Couldn\'t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ), 'alert');
1720: }
1721:
1722:
1723: wp_new_user_notification( $user_id, $new_user_password );
1724:
1725:
1726: $current_user = get_user_by( 'id', $user_id );
1727: wp_set_auth_cookie( $user_id, true );
1728:
1729:
1730: global $wp;
1731: if ( wp_get_referer() ) {
1732: $redirect = esc_url( wp_get_referer() );
1733: } else {
1734: $redirect = esc_url( home_url( $wp->request ) );
1735: }
1736:
1737: wp_redirect( apply_filters( 'sensei_registration_redirect', $redirect ) );
1738: exit;
1739:
1740: }
1741:
1742: 1743: 1744: 1745: 1746: 1747:
1748: public function login_message_process(){
1749:
1750:
1751: $message = '';
1752:
1753:
1754:
1755: if( $_GET['login'] == 'failed' ){
1756:
1757: $message = __('Incorrect login details', 'woothemes-sensei' );
1758:
1759: }elseif( $_GET['login'] == 'emptyfields' ){
1760:
1761: $message= __('Please enter your username and password', 'woothemes-sensei' );
1762: }
1763:
1764: Sensei()->notices->add_notice( $message, 'alert');
1765:
1766: }
1767:
1768:
1769: 1770: 1771: 1772: 1773: 1774: 1775:
1776: public function sensei_show_admin_bar () {
1777:
1778: if (current_user_can('edit_courses')) {
1779:
1780: add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1781:
1782: }
1783:
1784: }
1785:
1786: }
1787:
1788: 1789: 1790: 1791: 1792:
1793: class WooThemes_Sensei_Frontend extends Sensei_Frontend{}
1794: