@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct () { |
25 | 25 | |
26 | - //register admin styles |
|
26 | + //register admin styles |
|
27 | 27 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) ); |
28 | 28 | |
29 | - //register admin scripts |
|
30 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
29 | + //register admin scripts |
|
30 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
31 | 31 | |
32 | 32 | add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) ); |
33 | 33 | add_action( 'settings_before_form', array( $this, 'install_pages_output' ) ); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) ); |
37 | 37 | add_action( 'admin_init', array( $this, 'page_redirect' ) ); |
38 | 38 | add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) ); |
39 | - add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
39 | + add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
40 | 40 | |
41 | 41 | // Duplicate lesson & courses |
42 | 42 | add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 ); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | if( $menu_cap ) { |
89 | 89 | $menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' ); |
90 | - add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
90 | + add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) ); |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | $submenu_file = 'edit-tags.php?taxonomy=course-category&post_type=course'; |
145 | 145 | $parent_file = 'edit.php?post_type=course'; |
146 | 146 | |
147 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
147 | + } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
148 | 148 | |
149 | - $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
150 | - $parent_file = 'edit.php?post_type=course'; |
|
149 | + $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
150 | + $parent_file = 'edit.php?post_type=course'; |
|
151 | 151 | |
152 | 152 | } elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) { |
153 | 153 | |
154 | - $submenu_file = 'edit.php?post_type=sensei_message'; |
|
154 | + $submenu_file = 'edit.php?post_type=sensei_message'; |
|
155 | 155 | $parent_file = 'sensei'; |
156 | 156 | |
157 | 157 | } |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | */ |
180 | 180 | function install_pages_output() { |
181 | 181 | |
182 | - if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
182 | + if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
183 | 183 | |
184 | - ?> |
|
184 | + ?> |
|
185 | 185 | <div id="message" class="updated sensei-message sensei-connect"> |
186 | 186 | <p><?php _e( '<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p> |
187 | 187 | <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a> |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | </div> |
190 | 190 | <?php |
191 | 191 | |
192 | - } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | } // End install_pages_output() |
195 | 195 | |
@@ -221,18 +221,18 @@ discard block |
||
221 | 221 | endif; |
222 | 222 | |
223 | 223 | $page_data = array( |
224 | - 'post_status' => 'publish', |
|
225 | - 'post_type' => 'page', |
|
226 | - 'post_author' => 1, |
|
227 | - 'post_name' => $slug, |
|
228 | - 'post_title' => $page_title, |
|
229 | - 'post_content' => $page_content, |
|
230 | - 'post_parent' => $post_parent, |
|
231 | - 'comment_status' => 'closed' |
|
232 | - ); |
|
233 | - $page_id = wp_insert_post( $page_data ); |
|
234 | - |
|
235 | - update_option( $option, $page_id ); |
|
224 | + 'post_status' => 'publish', |
|
225 | + 'post_type' => 'page', |
|
226 | + 'post_author' => 1, |
|
227 | + 'post_name' => $slug, |
|
228 | + 'post_title' => $page_title, |
|
229 | + 'post_content' => $page_content, |
|
230 | + 'post_parent' => $post_parent, |
|
231 | + 'comment_status' => 'closed' |
|
232 | + ); |
|
233 | + $page_id = wp_insert_post( $page_data ); |
|
234 | + |
|
235 | + update_option( $option, $page_id ); |
|
236 | 236 | } // End create_page() |
237 | 237 | |
238 | 238 | |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | function create_pages() { |
246 | 246 | |
247 | 247 | // Courses page |
248 | - $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), $this->token . '_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' ); |
|
248 | + $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), $this->token . '_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' ); |
|
249 | 249 | |
250 | 250 | // User Dashboard page |
251 | - $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), $this->token . '_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' ); |
|
251 | + $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), $this->token . '_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' ); |
|
252 | 252 | |
253 | 253 | } // End create_pages() |
254 | 254 | |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | wp_register_style( Sensei()->token . '-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' ); |
270 | 270 | wp_enqueue_style( Sensei()->token . '-global' ); |
271 | 271 | |
272 | - // Select 2 styles |
|
273 | - wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
272 | + // Select 2 styles |
|
273 | + wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
274 | 274 | |
275 | 275 | // Test for Write Panel Pages |
276 | 276 | if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) { |
@@ -283,32 +283,32 @@ discard block |
||
283 | 283 | } // End admin_styles_global() |
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * Globally register all scripts needed in admin. |
|
288 | - * |
|
289 | - * The script users should enqueue the script when needed. |
|
290 | - * |
|
291 | - * @since 1.8.2 |
|
292 | - * @access public |
|
293 | - */ |
|
294 | - public function register_scripts( $hook ){ |
|
286 | + /** |
|
287 | + * Globally register all scripts needed in admin. |
|
288 | + * |
|
289 | + * The script users should enqueue the script when needed. |
|
290 | + * |
|
291 | + * @since 1.8.2 |
|
292 | + * @access public |
|
293 | + */ |
|
294 | + public function register_scripts( $hook ){ |
|
295 | 295 | |
296 | - $screen = get_current_screen(); |
|
296 | + $screen = get_current_screen(); |
|
297 | 297 | |
298 | - // Allow developers to load non-minified versions of scripts |
|
299 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
298 | + // Allow developers to load non-minified versions of scripts |
|
299 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
300 | 300 | |
301 | - // Select2 script used to enhance all select boxes |
|
302 | - wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
301 | + // Select2 script used to enhance all select boxes |
|
302 | + wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
303 | 303 | |
304 | - // load edit module scripts |
|
305 | - if( 'edit-module' == $screen->id ){ |
|
304 | + // load edit module scripts |
|
305 | + if( 'edit-module' == $screen->id ){ |
|
306 | 306 | |
307 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
307 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | 314 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @return void |
319 | 319 | */ |
320 | 320 | function admin_install_notice() { |
321 | - ?> |
|
321 | + ?> |
|
322 | 322 | <div id="message" class="updated sensei-message sensei-connect"> |
323 | 323 | |
324 | 324 | <p> |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * @return void |
354 | 354 | */ |
355 | 355 | function admin_installed_notice() { |
356 | - ?> |
|
356 | + ?> |
|
357 | 357 | <div id="message" class="updated sensei-message sensei-connect"> |
358 | 358 | <p><?php _e( '<strong>Sensei has been installed</strong> – You\'re ready to start creating courses!', 'woothemes-sensei' ); ?></p> |
359 | 359 | <p class="submit"><a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woothemes-sensei' ); ?></a> <a class="docs button-primary" href="http://www.woothemes.com/sensei-docs/"><?php _e('Documentation', 'woothemes-sensei'); ?></a></p> |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | </div> |
363 | 363 | <?php |
364 | 364 | |
365 | - // Set installed option |
|
366 | - update_option('sensei_installed', 0); |
|
365 | + // Set installed option |
|
366 | + update_option('sensei_installed', 0); |
|
367 | 367 | } // End admin_installed_notice() |
368 | 368 | |
369 | 369 | |
@@ -395,21 +395,21 @@ discard block |
||
395 | 395 | function admin_notices_styles() { |
396 | 396 | |
397 | 397 | // Installed notices |
398 | - if ( 1 == get_option( 'sensei_installed' ) ) { |
|
398 | + if ( 1 == get_option( 'sensei_installed' ) ) { |
|
399 | 399 | |
400 | - wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
400 | + wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
401 | 401 | |
402 | - if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
403 | - add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
404 | - } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
405 | - add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
406 | - } // End If Statement |
|
402 | + if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
403 | + add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
404 | + } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
405 | + add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
406 | + } // End If Statement |
|
407 | 407 | |
408 | - } // End If Statement |
|
408 | + } // End If Statement |
|
409 | 409 | |
410 | - if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
411 | - add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
412 | - } |
|
410 | + if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
411 | + add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
412 | + } |
|
413 | 413 | |
414 | 414 | } // End admin_notices_styles() |
415 | 415 | |
@@ -525,30 +525,30 @@ discard block |
||
525 | 525 | */ |
526 | 526 | private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) { |
527 | 527 | |
528 | - $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
529 | - $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
528 | + $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
529 | + $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
530 | 530 | |
531 | - // duplicate the generic wp post information |
|
531 | + // duplicate the generic wp post information |
|
532 | 532 | $new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' ); |
533 | 533 | |
534 | 534 | //update the new lesson data |
535 | - add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
535 | + add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
536 | 536 | |
537 | 537 | //update the new quiz data |
538 | - add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
539 | - wp_update_post( |
|
540 | - array( |
|
541 | - 'ID' => $new_quiz->ID, |
|
542 | - 'post_parent' => $new_lesson_id |
|
543 | - ) |
|
544 | - ); |
|
538 | + add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
539 | + wp_update_post( |
|
540 | + array( |
|
541 | + 'ID' => $new_quiz->ID, |
|
542 | + 'post_parent' => $new_lesson_id |
|
543 | + ) |
|
544 | + ); |
|
545 | 545 | |
546 | 546 | foreach( $old_quiz_questions as $question ) { |
547 | 547 | |
548 | 548 | // copy the question order over to the new quiz |
549 | 549 | $old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true ); |
550 | - $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
551 | - add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
550 | + $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
551 | + add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
552 | 552 | |
553 | 553 | // Add question to quiz |
554 | 554 | add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false ); |
@@ -870,21 +870,21 @@ discard block |
||
870 | 870 | break; |
871 | 871 | |
872 | 872 | case 'checkbox': |
873 | - //backwards compatibility |
|
874 | - if( empty( $data ) || 'on' == $data ){ |
|
875 | - $checked_value = 'on'; |
|
876 | - }elseif( 'yes' == $data ) { |
|
873 | + //backwards compatibility |
|
874 | + if( empty( $data ) || 'on' == $data ){ |
|
875 | + $checked_value = 'on'; |
|
876 | + }elseif( 'yes' == $data ) { |
|
877 | 877 | |
878 | - $checked_value = 'yes'; |
|
878 | + $checked_value = 'yes'; |
|
879 | 879 | |
880 | - }elseif( 'auto' == $data ) { |
|
880 | + }elseif( 'auto' == $data ) { |
|
881 | 881 | |
882 | - $checked_value = 'auto'; |
|
882 | + $checked_value = 'auto'; |
|
883 | 883 | |
884 | - } else { |
|
885 | - $checked_value = 1; |
|
886 | - $data = intval( $data ); |
|
887 | - } |
|
884 | + } else { |
|
885 | + $checked_value = 1; |
|
886 | + $data = intval( $data ); |
|
887 | + } |
|
888 | 888 | $checked = checked( $checked_value, $data, false ); |
889 | 889 | $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n"; |
890 | 890 | break; |
@@ -988,26 +988,26 @@ discard block |
||
988 | 988 | |
989 | 989 | if( 0 < count( $courses ) ) { |
990 | 990 | |
991 | - // order the courses as set by the users |
|
992 | - $all_course_ids = array(); |
|
993 | - foreach( $courses as $course ){ |
|
991 | + // order the courses as set by the users |
|
992 | + $all_course_ids = array(); |
|
993 | + foreach( $courses as $course ){ |
|
994 | 994 | |
995 | - $all_course_ids[] = (string)$course->ID; |
|
995 | + $all_course_ids[] = (string)$course->ID; |
|
996 | 996 | |
997 | - } |
|
998 | - $order_string = $this->get_course_order(); |
|
997 | + } |
|
998 | + $order_string = $this->get_course_order(); |
|
999 | 999 | |
1000 | - if( !empty( $order_string ) ){ |
|
1001 | - $ordered_course_ids = explode(',' , $order_string ); |
|
1002 | - $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1003 | - } |
|
1000 | + if( !empty( $order_string ) ){ |
|
1001 | + $ordered_course_ids = explode(',' , $order_string ); |
|
1002 | + $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1003 | + } |
|
1004 | 1004 | |
1005 | 1005 | |
1006 | 1006 | $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
1007 | 1007 | $html .= '<ul class="sortable-course-list">' . "\n"; |
1008 | 1008 | $count = 0; |
1009 | 1009 | foreach ( $all_course_ids as $course_id ) { |
1010 | - $course = get_post( $course_id ); |
|
1010 | + $course = get_post( $course_id ); |
|
1011 | 1011 | $count++; |
1012 | 1012 | $class = 'course'; |
1013 | 1013 | if ( $count == 1 ) { $class .= ' first'; } |
@@ -1122,73 +1122,73 @@ discard block |
||
1122 | 1122 | |
1123 | 1123 | $displayed_lessons = array(); |
1124 | 1124 | |
1125 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1126 | - |
|
1127 | - foreach( $modules as $module ) { |
|
1128 | - |
|
1129 | - $args = array( |
|
1130 | - 'post_type' => 'lesson', |
|
1131 | - 'post_status' => 'publish', |
|
1132 | - 'posts_per_page' => -1, |
|
1133 | - 'meta_query' => array( |
|
1134 | - array( |
|
1135 | - 'key' => '_lesson_course', |
|
1136 | - 'value' => intval( $course_id ), |
|
1137 | - 'compare' => '=' |
|
1138 | - ) |
|
1139 | - ), |
|
1140 | - 'tax_query' => array( |
|
1141 | - array( |
|
1142 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
1143 | - 'field' => 'id', |
|
1144 | - 'terms' => intval( $module->term_id ) |
|
1145 | - ) |
|
1146 | - ), |
|
1147 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
1148 | - 'orderby' => 'meta_value_num date', |
|
1149 | - 'order' => 'ASC', |
|
1150 | - 'suppress_filters' => 0 |
|
1151 | - ); |
|
1152 | - |
|
1153 | - $lessons = get_posts( $args ); |
|
1154 | - |
|
1155 | - if( count( $lessons ) > 0 ) { |
|
1156 | - $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1157 | - $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1158 | - |
|
1159 | - $count = 0; |
|
1160 | - foreach( $lessons as $lesson ) { |
|
1161 | - $count++; |
|
1162 | - $class = 'lesson'; |
|
1163 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1164 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1165 | - if ( $count % 2 != 0 ) { |
|
1166 | - $class .= ' alternate'; |
|
1167 | - } |
|
1168 | - |
|
1169 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1170 | - |
|
1171 | - $displayed_lessons[] = $lesson->ID; |
|
1172 | - } |
|
1173 | - |
|
1174 | - $html .= '</ul>' . "\n"; |
|
1175 | - |
|
1176 | - $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1177 | - } |
|
1178 | - } |
|
1179 | - |
|
1180 | - |
|
1181 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1125 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1126 | + |
|
1127 | + foreach( $modules as $module ) { |
|
1128 | + |
|
1129 | + $args = array( |
|
1130 | + 'post_type' => 'lesson', |
|
1131 | + 'post_status' => 'publish', |
|
1132 | + 'posts_per_page' => -1, |
|
1133 | + 'meta_query' => array( |
|
1134 | + array( |
|
1135 | + 'key' => '_lesson_course', |
|
1136 | + 'value' => intval( $course_id ), |
|
1137 | + 'compare' => '=' |
|
1138 | + ) |
|
1139 | + ), |
|
1140 | + 'tax_query' => array( |
|
1141 | + array( |
|
1142 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
1143 | + 'field' => 'id', |
|
1144 | + 'terms' => intval( $module->term_id ) |
|
1145 | + ) |
|
1146 | + ), |
|
1147 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
1148 | + 'orderby' => 'meta_value_num date', |
|
1149 | + 'order' => 'ASC', |
|
1150 | + 'suppress_filters' => 0 |
|
1151 | + ); |
|
1152 | + |
|
1153 | + $lessons = get_posts( $args ); |
|
1154 | + |
|
1155 | + if( count( $lessons ) > 0 ) { |
|
1156 | + $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1157 | + $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1158 | + |
|
1159 | + $count = 0; |
|
1160 | + foreach( $lessons as $lesson ) { |
|
1161 | + $count++; |
|
1162 | + $class = 'lesson'; |
|
1163 | + if ( $count == 1 ) { $class .= ' first'; } |
|
1164 | + if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1165 | + if ( $count % 2 != 0 ) { |
|
1166 | + $class .= ' alternate'; |
|
1167 | + } |
|
1168 | + |
|
1169 | + $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1170 | + |
|
1171 | + $displayed_lessons[] = $lesson->ID; |
|
1172 | + } |
|
1173 | + |
|
1174 | + $html .= '</ul>' . "\n"; |
|
1175 | + |
|
1176 | + $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1177 | + } |
|
1178 | + } |
|
1179 | + |
|
1180 | + |
|
1181 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1182 | 1182 | |
1183 | 1183 | if( 0 < count( $lessons ) ) { |
1184 | 1184 | |
1185 | - //get module term ids, will be used to exclude lessons |
|
1186 | - $module_items_ids = array(); |
|
1187 | - if( ! empty( $modules ) ) { |
|
1188 | - foreach ($modules as $module) { |
|
1189 | - $module_items_ids[] = $module->term_id; |
|
1190 | - } |
|
1191 | - } |
|
1185 | + //get module term ids, will be used to exclude lessons |
|
1186 | + $module_items_ids = array(); |
|
1187 | + if( ! empty( $modules ) ) { |
|
1188 | + foreach ($modules as $module) { |
|
1189 | + $module_items_ids[] = $module->term_id; |
|
1190 | + } |
|
1191 | + } |
|
1192 | 1192 | |
1193 | 1193 | if( 0 < count( $displayed_lessons ) ) { |
1194 | 1194 | $html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n"; |
@@ -1198,13 +1198,13 @@ discard block |
||
1198 | 1198 | $count = 0; |
1199 | 1199 | foreach ( $lessons as $lesson ) { |
1200 | 1200 | |
1201 | - // if lesson belongs to one fo the course modules then exclude it here |
|
1202 | - // as it is listed above |
|
1203 | - if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1201 | + // if lesson belongs to one fo the course modules then exclude it here |
|
1202 | + // as it is listed above |
|
1203 | + if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1204 | 1204 | |
1205 | - continue; |
|
1205 | + continue; |
|
1206 | 1206 | |
1207 | - } |
|
1207 | + } |
|
1208 | 1208 | |
1209 | 1209 | $count++; |
1210 | 1210 | $class = 'lesson'; |
@@ -1248,23 +1248,23 @@ discard block |
||
1248 | 1248 | |
1249 | 1249 | if( $course_id ) { |
1250 | 1250 | |
1251 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1251 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1252 | 1252 | |
1253 | - foreach( $modules as $module ) { |
|
1253 | + foreach( $modules as $module ) { |
|
1254 | 1254 | |
1255 | - $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ]; |
|
1255 | + $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ]; |
|
1256 | 1256 | |
1257 | - if( $module_order_string ) { |
|
1258 | - $order = explode( ',', $module_order_string ); |
|
1259 | - $i = 1; |
|
1260 | - foreach( $order as $lesson_id ) { |
|
1261 | - if( $lesson_id ) { |
|
1262 | - update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1263 | - ++$i; |
|
1264 | - } |
|
1265 | - } |
|
1266 | - } |
|
1267 | - } |
|
1257 | + if( $module_order_string ) { |
|
1258 | + $order = explode( ',', $module_order_string ); |
|
1259 | + $i = 1; |
|
1260 | + foreach( $order as $lesson_id ) { |
|
1261 | + if( $lesson_id ) { |
|
1262 | + update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1263 | + ++$i; |
|
1264 | + } |
|
1265 | + } |
|
1266 | + } |
|
1267 | + } |
|
1268 | 1268 | |
1269 | 1269 | |
1270 | 1270 | if( $order_string ) { |
@@ -1347,47 +1347,47 @@ discard block |
||
1347 | 1347 | |
1348 | 1348 | /** |
1349 | 1349 | * Adding admin notice if the current |
1350 | - * installed theme is not compatible |
|
1351 | - * |
|
1350 | + * installed theme is not compatible |
|
1351 | + * |
|
1352 | 1352 | * @return void |
1353 | 1353 | */ |
1354 | 1354 | public function theme_compatibility_notices() { |
1355 | 1355 | |
1356 | - if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1357 | - switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1356 | + if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1357 | + switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1358 | 1358 | case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break; |
1359 | 1359 | case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break; |
1360 | 1360 | } |
1361 | - } |
|
1361 | + } |
|
1362 | 1362 | |
1363 | - // white list templates that are already support by default and do not show notice for them |
|
1364 | - $template = get_option( 'template' ); |
|
1363 | + // white list templates that are already support by default and do not show notice for them |
|
1364 | + $template = get_option( 'template' ); |
|
1365 | 1365 | |
1366 | - $white_list = array( 'twentyeleven', |
|
1367 | - 'twentytwelve', |
|
1368 | - 'twentyfourteen', |
|
1369 | - 'twentyfifteen', |
|
1370 | - 'twentysixteen', |
|
1371 | - 'storefront', |
|
1372 | - ); |
|
1366 | + $white_list = array( 'twentyeleven', |
|
1367 | + 'twentytwelve', |
|
1368 | + 'twentyfourteen', |
|
1369 | + 'twentyfifteen', |
|
1370 | + 'twentysixteen', |
|
1371 | + 'storefront', |
|
1372 | + ); |
|
1373 | 1373 | |
1374 | - if ( in_array( $template, $white_list ) ) { |
|
1374 | + if ( in_array( $template, $white_list ) ) { |
|
1375 | 1375 | |
1376 | - return; |
|
1376 | + return; |
|
1377 | 1377 | |
1378 | - } |
|
1378 | + } |
|
1379 | 1379 | |
1380 | - // don't show the notice if the user chose to hide it |
|
1381 | - $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1382 | - if( $hide_theme_check_notice ) { |
|
1380 | + // don't show the notice if the user chose to hide it |
|
1381 | + $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1382 | + if( $hide_theme_check_notice ) { |
|
1383 | 1383 | |
1384 | - return; |
|
1384 | + return; |
|
1385 | 1385 | |
1386 | - } |
|
1386 | + } |
|
1387 | 1387 | |
1388 | - // show the notice for themes not supporting sensei |
|
1389 | - if ( ! current_theme_supports( 'sensei' ) ) { |
|
1390 | - ?> |
|
1388 | + // show the notice for themes not supporting sensei |
|
1389 | + if ( ! current_theme_supports( 'sensei' ) ) { |
|
1390 | + ?> |
|
1391 | 1391 | |
1392 | 1392 | <div id="message" class="error sensei-message sensei-connect"> |
1393 | 1393 | <p> |
@@ -1417,7 +1417,7 @@ discard block |
||
1417 | 1417 | public function reset_theme_check_notices() { |
1418 | 1418 | global $current_user; |
1419 | 1419 | wp_get_current_user(); |
1420 | - $user_id = $current_user->ID; |
|
1420 | + $user_id = $current_user->ID; |
|
1421 | 1421 | |
1422 | 1422 | delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' ); |
1423 | 1423 | } |
@@ -1437,60 +1437,60 @@ discard block |
||
1437 | 1437 | return $prevent_access; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - /** |
|
1441 | - * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
1442 | - * on the sensei settings page. |
|
1443 | - * |
|
1444 | - * The function |
|
1445 | - * |
|
1446 | - * @since 1.8.7 |
|
1447 | - */ |
|
1448 | - public static function install_pages(){ |
|
1440 | + /** |
|
1441 | + * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
1442 | + * on the sensei settings page. |
|
1443 | + * |
|
1444 | + * The function |
|
1445 | + * |
|
1446 | + * @since 1.8.7 |
|
1447 | + */ |
|
1448 | + public static function install_pages(){ |
|
1449 | 1449 | |
1450 | - // only fire on the settings page |
|
1451 | - if( ! isset( $_GET['page'] ) |
|
1452 | - || 'woothemes-sensei-settings' != $_GET['page'] |
|
1453 | - || 1 == get_option('skip_install_sensei_pages') ){ |
|
1450 | + // only fire on the settings page |
|
1451 | + if( ! isset( $_GET['page'] ) |
|
1452 | + || 'woothemes-sensei-settings' != $_GET['page'] |
|
1453 | + || 1 == get_option('skip_install_sensei_pages') ){ |
|
1454 | 1454 | |
1455 | - return; |
|
1455 | + return; |
|
1456 | 1456 | |
1457 | - } |
|
1457 | + } |
|
1458 | 1458 | |
1459 | - // Install/page installer |
|
1460 | - $install_complete = false; |
|
1459 | + // Install/page installer |
|
1460 | + $install_complete = false; |
|
1461 | 1461 | |
1462 | - // Add pages button |
|
1463 | - $settings_url = ''; |
|
1464 | - if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
1462 | + // Add pages button |
|
1463 | + $settings_url = ''; |
|
1464 | + if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
1465 | 1465 | |
1466 | - Sensei()->admin->create_pages(); |
|
1467 | - update_option('skip_install_sensei_pages', 1); |
|
1468 | - $install_complete = true; |
|
1469 | - $settings_url = remove_query_arg('install_sensei_pages'); |
|
1466 | + Sensei()->admin->create_pages(); |
|
1467 | + update_option('skip_install_sensei_pages', 1); |
|
1468 | + $install_complete = true; |
|
1469 | + $settings_url = remove_query_arg('install_sensei_pages'); |
|
1470 | 1470 | |
1471 | - // Skip button |
|
1472 | - } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
1471 | + // Skip button |
|
1472 | + } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
1473 | 1473 | |
1474 | - update_option('skip_install_sensei_pages', 1); |
|
1475 | - $install_complete = true; |
|
1476 | - $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
1474 | + update_option('skip_install_sensei_pages', 1); |
|
1475 | + $install_complete = true; |
|
1476 | + $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
1477 | 1477 | |
1478 | - } |
|
1478 | + } |
|
1479 | 1479 | |
1480 | - if ($install_complete) { |
|
1480 | + if ($install_complete) { |
|
1481 | 1481 | |
1482 | - // Flush rules after install |
|
1483 | - flush_rewrite_rules( true ); |
|
1482 | + // Flush rules after install |
|
1483 | + flush_rewrite_rules( true ); |
|
1484 | 1484 | |
1485 | - // Set installed option |
|
1486 | - update_option('sensei_installed', 0); |
|
1485 | + // Set installed option |
|
1486 | + update_option('sensei_installed', 0); |
|
1487 | 1487 | |
1488 | - $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1489 | - wp_redirect( $complete_url ); |
|
1488 | + $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1489 | + wp_redirect( $complete_url ); |
|
1490 | 1490 | |
1491 | - } |
|
1491 | + } |
|
1492 | 1492 | |
1493 | - }// end install_pages |
|
1493 | + }// end install_pages |
|
1494 | 1494 | |
1495 | 1495 | } // End Class |
1496 | 1496 |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Administration Class |
@@ -210,13 +213,15 @@ discard block |
||
210 | 213 | |
211 | 214 | $option_value = get_option( $option ); |
212 | 215 | |
213 | - if ( $option_value > 0 && get_post( $option_value ) ) |
|
214 | - return; |
|
216 | + if ( $option_value > 0 && get_post( $option_value ) ) { |
|
217 | + return; |
|
218 | + } |
|
215 | 219 | |
216 | 220 | $page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
217 | 221 | if ( $page_found ) : |
218 | - if ( ! $option_value ) |
|
219 | - update_option( $option, $page_found ); |
|
222 | + if ( ! $option_value ) { |
|
223 | + update_option( $option, $page_found ); |
|
224 | + } |
|
220 | 225 | return; |
221 | 226 | endif; |
222 | 227 | |
@@ -723,7 +728,9 @@ discard block |
||
723 | 728 | $types = array( 'course', 'lesson', 'question' ); |
724 | 729 | |
725 | 730 | foreach( $types as $type ) { |
726 | - if( ! post_type_exists( $type ) ) continue; |
|
731 | + if( ! post_type_exists( $type ) ) { |
|
732 | + continue; |
|
733 | + } |
|
727 | 734 | |
728 | 735 | $num_posts = wp_count_posts( $type ); |
729 | 736 | |
@@ -791,7 +798,9 @@ discard block |
||
791 | 798 | |
792 | 799 | $html = ''; |
793 | 800 | |
794 | - if( 0 == count( $settings ) ) return $html; |
|
801 | + if( 0 == count( $settings ) ) { |
|
802 | + return $html; |
|
803 | + } |
|
795 | 804 | |
796 | 805 | $html .= '<div class="sensei-options-panel">' . "\n"; |
797 | 806 | |
@@ -873,11 +882,11 @@ discard block |
||
873 | 882 | //backwards compatibility |
874 | 883 | if( empty( $data ) || 'on' == $data ){ |
875 | 884 | $checked_value = 'on'; |
876 | - }elseif( 'yes' == $data ) { |
|
885 | + } elseif( 'yes' == $data ) { |
|
877 | 886 | |
878 | 887 | $checked_value = 'yes'; |
879 | 888 | |
880 | - }elseif( 'auto' == $data ) { |
|
889 | + } elseif( 'auto' == $data ) { |
|
881 | 890 | |
882 | 891 | $checked_value = 'auto'; |
883 | 892 |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @access public |
201 | 201 | * @param mixed $slug |
202 | - * @param mixed $option |
|
202 | + * @param string $option |
|
203 | 203 | * @param string $page_title (default: '') |
204 | 204 | * @param string $page_content (default: '') |
205 | 205 | * @param int $post_parent (default: 0) |
@@ -1047,6 +1047,9 @@ discard block |
||
1047 | 1047 | ?></div><?php |
1048 | 1048 | } |
1049 | 1049 | |
1050 | + /** |
|
1051 | + * @return string |
|
1052 | + */ |
|
1050 | 1053 | public function get_course_order() { |
1051 | 1054 | return get_option( 'sensei_course_order', '' ); |
1052 | 1055 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Administration Class |
@@ -21,51 +21,51 @@ discard block |
||
21 | 21 | * @since 1.0.0 |
22 | 22 | * @return void |
23 | 23 | */ |
24 | - public function __construct () { |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | 26 | //register admin styles |
27 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) ); |
|
27 | + add_action('admin_enqueue_scripts', array($this, 'admin_styles_global')); |
|
28 | 28 | |
29 | 29 | //register admin scripts |
30 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
30 | + add_action('admin_enqueue_scripts', array($this, 'register_scripts')); |
|
31 | 31 | |
32 | - add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) ); |
|
33 | - add_action( 'settings_before_form', array( $this, 'install_pages_output' ) ); |
|
34 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
35 | - add_action( 'menu_order', array( $this, 'admin_menu_order' ) ); |
|
36 | - add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) ); |
|
37 | - add_action( 'admin_init', array( $this, 'page_redirect' ) ); |
|
38 | - add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) ); |
|
39 | - add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
32 | + add_action('admin_print_styles', array($this, 'admin_notices_styles')); |
|
33 | + add_action('settings_before_form', array($this, 'install_pages_output')); |
|
34 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
35 | + add_action('menu_order', array($this, 'admin_menu_order')); |
|
36 | + add_action('admin_head', array($this, 'admin_menu_highlight')); |
|
37 | + add_action('admin_init', array($this, 'page_redirect')); |
|
38 | + add_action('admin_init', array($this, 'sensei_add_custom_menu_items')); |
|
39 | + add_action('admin_init', array(__CLASS__, 'install_pages')); |
|
40 | 40 | |
41 | 41 | // Duplicate lesson & courses |
42 | - add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 ); |
|
43 | - add_action( 'admin_action_duplicate_lesson', array( $this, 'duplicate_lesson_action' ) ); |
|
44 | - add_action( 'admin_action_duplicate_course', array( $this, 'duplicate_course_action' ) ); |
|
45 | - add_action( 'admin_action_duplicate_course_with_lessons', array( $this, 'duplicate_course_with_lessons_action' ) ); |
|
42 | + add_filter('post_row_actions', array($this, 'duplicate_action_link'), 10, 2); |
|
43 | + add_action('admin_action_duplicate_lesson', array($this, 'duplicate_lesson_action')); |
|
44 | + add_action('admin_action_duplicate_course', array($this, 'duplicate_course_action')); |
|
45 | + add_action('admin_action_duplicate_course_with_lessons', array($this, 'duplicate_course_with_lessons_action')); |
|
46 | 46 | |
47 | 47 | // Handle lessons list table filtering |
48 | - add_action( 'restrict_manage_posts', array( $this, 'lesson_filter_options' ) ); |
|
49 | - add_filter( 'request', array( $this, 'lesson_filter_actions' ) ); |
|
48 | + add_action('restrict_manage_posts', array($this, 'lesson_filter_options')); |
|
49 | + add_filter('request', array($this, 'lesson_filter_actions')); |
|
50 | 50 | |
51 | 51 | // Add Sensei items to 'at a glance' widget |
52 | - add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); |
|
52 | + add_filter('dashboard_glance_items', array($this, 'glance_items'), 10, 1); |
|
53 | 53 | |
54 | 54 | // Handle course and lesson deletions |
55 | - add_action( 'trash_course', array( $this, 'delete_content' ), 10, 2 ); |
|
56 | - add_action( 'trash_lesson', array( $this, 'delete_content' ), 10, 2 ); |
|
55 | + add_action('trash_course', array($this, 'delete_content'), 10, 2); |
|
56 | + add_action('trash_lesson', array($this, 'delete_content'), 10, 2); |
|
57 | 57 | |
58 | 58 | // Delete user activity when user is deleted |
59 | - add_action( 'deleted_user', array( $this, 'delete_user_activity' ), 10, 1 ); |
|
59 | + add_action('deleted_user', array($this, 'delete_user_activity'), 10, 1); |
|
60 | 60 | |
61 | 61 | // Add notices to WP dashboard |
62 | - add_action( 'admin_notices', array( $this, 'theme_compatibility_notices' ) ); |
|
62 | + add_action('admin_notices', array($this, 'theme_compatibility_notices')); |
|
63 | 63 | |
64 | 64 | // Reset theme notices when switching themes |
65 | - add_action( 'switch_theme', array( $this, 'reset_theme_check_notices' ) ); |
|
65 | + add_action('switch_theme', array($this, 'reset_theme_check_notices')); |
|
66 | 66 | |
67 | 67 | // Allow Teacher access the admin area |
68 | - add_filter( 'woocommerce_prevent_admin_access', array( $this, 'admin_access' ) ); |
|
68 | + add_filter('woocommerce_prevent_admin_access', array($this, 'admin_access')); |
|
69 | 69 | |
70 | 70 | } // End __construct() |
71 | 71 | |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | public function admin_menu() { |
78 | 78 | global $menu; |
79 | 79 | $menu_cap = ''; |
80 | - if( current_user_can( 'manage_sensei' ) ) { |
|
80 | + if (current_user_can('manage_sensei')) { |
|
81 | 81 | $menu_cap = 'manage_sensei'; |
82 | 82 | } else { |
83 | - if( current_user_can( 'manage_sensei_grades' ) ) { |
|
83 | + if (current_user_can('manage_sensei_grades')) { |
|
84 | 84 | $menu_cap = 'manage_sensei_grades'; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if( $menu_cap ) { |
|
89 | - $menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' ); |
|
90 | - add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
88 | + if ($menu_cap) { |
|
89 | + $menu[] = array('', 'read', 'separator-sensei', '', 'wp-menu-separator sensei'); |
|
90 | + add_menu_page('Sensei', 'Sensei', $menu_cap, 'sensei', array(Sensei()->analysis, 'analysis_page'), '', '50'); |
|
91 | 91 | } |
92 | 92 | |
93 | - add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) ); |
|
94 | - add_submenu_page( 'edit.php?post_type=lesson', __( 'Order Lessons', 'woothemes-sensei' ), __( 'Order Lessons', 'woothemes-sensei' ), 'edit_lessons', 'lesson-order', array( $this, 'lesson_order_screen' ) ); |
|
93 | + add_submenu_page('edit.php?post_type=course', __('Order Courses', 'woothemes-sensei'), __('Order Courses', 'woothemes-sensei'), 'manage_sensei', 'course-order', array($this, 'course_order_screen')); |
|
94 | + add_submenu_page('edit.php?post_type=lesson', __('Order Lessons', 'woothemes-sensei'), __('Order Lessons', 'woothemes-sensei'), 'edit_lessons', 'lesson-order', array($this, 'lesson_order_screen')); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | * @param array $menu_order Existing menu order |
101 | 101 | * @return array Modified menu order for Sensei |
102 | 102 | */ |
103 | - public function admin_menu_order( $menu_order ) { |
|
103 | + public function admin_menu_order($menu_order) { |
|
104 | 104 | |
105 | 105 | // Initialize our custom order array |
106 | 106 | $sensei_menu_order = array(); |
107 | 107 | |
108 | 108 | // Get the index of our custom separator |
109 | - $sensei_separator = array_search( 'separator-sensei', $menu_order ); |
|
109 | + $sensei_separator = array_search('separator-sensei', $menu_order); |
|
110 | 110 | |
111 | 111 | // Loop through menu order and do some rearranging |
112 | - foreach ( $menu_order as $index => $item ) : |
|
112 | + foreach ($menu_order as $index => $item) : |
|
113 | 113 | |
114 | - if ( ( ( 'sensei' ) == $item ) ) : |
|
114 | + if ((('sensei') == $item)) : |
|
115 | 115 | $sensei_menu_order[] = 'separator-sensei'; |
116 | 116 | $sensei_menu_order[] = $item; |
117 | - unset( $menu_order[$sensei_separator] ); |
|
118 | - elseif ( !in_array( $item, array( 'separator-sensei' ) ) ) : |
|
117 | + unset($menu_order[$sensei_separator]); |
|
118 | + elseif ( ! in_array($item, array('separator-sensei'))) : |
|
119 | 119 | $sensei_menu_order[] = $item; |
120 | 120 | endif; |
121 | 121 | |
@@ -135,24 +135,24 @@ discard block |
||
135 | 135 | |
136 | 136 | $screen = get_current_screen(); |
137 | 137 | |
138 | - if ( $screen->base == 'post' && $post_type == 'course' ) { |
|
138 | + if ($screen->base == 'post' && $post_type == 'course') { |
|
139 | 139 | |
140 | - $parent_file = 'edit.php?post_type=course'; |
|
140 | + $parent_file = 'edit.php?post_type=course'; |
|
141 | 141 | |
142 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'course-category' ) { |
|
142 | + } elseif ($screen->base == 'edit-tags' && $taxonomy == 'course-category') { |
|
143 | 143 | |
144 | 144 | $submenu_file = 'edit-tags.php?taxonomy=course-category&post_type=course'; |
145 | 145 | $parent_file = 'edit.php?post_type=course'; |
146 | 146 | |
147 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
147 | + } elseif ($screen->base == 'edit-tags' && $taxonomy == 'module') { |
|
148 | 148 | |
149 | 149 | $submenu_file = 'edit-tags.php?taxonomy=module'; |
150 | 150 | $parent_file = 'edit.php?post_type=course'; |
151 | 151 | |
152 | - } elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) { |
|
152 | + } elseif (in_array($screen->id, array('sensei_message', 'edit-sensei_message'))) { |
|
153 | 153 | |
154 | 154 | $submenu_file = 'edit.php?post_type=sensei_message'; |
155 | - $parent_file = 'sensei'; |
|
155 | + $parent_file = 'sensei'; |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | } |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @return void |
164 | 164 | */ |
165 | 165 | public function page_redirect() { |
166 | - if( isset( $_GET['page'] ) && $_GET['page'] == 'sensei' ) { |
|
167 | - wp_safe_redirect( 'admin.php?page=sensei_analysis' ); |
|
166 | + if (isset($_GET['page']) && $_GET['page'] == 'sensei') { |
|
167 | + wp_safe_redirect('admin.php?page=sensei_analysis'); |
|
168 | 168 | exit; |
169 | 169 | } |
170 | 170 | } |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | */ |
180 | 180 | function install_pages_output() { |
181 | 181 | |
182 | - if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
182 | + if (isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
183 | 183 | |
184 | 184 | ?> |
185 | 185 | <div id="message" class="updated sensei-message sensei-connect"> |
186 | - <p><?php _e( '<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p> |
|
186 | + <p><?php _e('<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei'); ?></p> |
|
187 | 187 | <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a> |
188 | 188 | <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p> |
189 | 189 | </div> |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | * @param int $post_parent (default: 0) |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - function create_page( $slug, $option, $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
208 | + function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0) { |
|
209 | 209 | global $wpdb; |
210 | 210 | |
211 | - $option_value = get_option( $option ); |
|
211 | + $option_value = get_option($option); |
|
212 | 212 | |
213 | - if ( $option_value > 0 && get_post( $option_value ) ) |
|
213 | + if ($option_value > 0 && get_post($option_value)) |
|
214 | 214 | return; |
215 | 215 | |
216 | - $page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
217 | - if ( $page_found ) : |
|
218 | - if ( ! $option_value ) |
|
219 | - update_option( $option, $page_found ); |
|
216 | + $page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->posts." WHERE post_name = %s LIMIT 1;", $slug)); |
|
217 | + if ($page_found) : |
|
218 | + if ( ! $option_value) |
|
219 | + update_option($option, $page_found); |
|
220 | 220 | return; |
221 | 221 | endif; |
222 | 222 | |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | 'post_parent' => $post_parent, |
231 | 231 | 'comment_status' => 'closed' |
232 | 232 | ); |
233 | - $page_id = wp_insert_post( $page_data ); |
|
233 | + $page_id = wp_insert_post($page_data); |
|
234 | 234 | |
235 | - update_option( $option, $page_id ); |
|
235 | + update_option($option, $page_id); |
|
236 | 236 | } // End create_page() |
237 | 237 | |
238 | 238 | |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | function create_pages() { |
246 | 246 | |
247 | 247 | // Courses page |
248 | - $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), $this->token . '_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' ); |
|
248 | + $this->create_page(esc_sql(_x('courses-overview', 'page_slug', 'woothemes-sensei')), $this->token.'_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]'); |
|
249 | 249 | |
250 | 250 | // User Dashboard page |
251 | - $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), $this->token . '_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' ); |
|
251 | + $this->create_page(esc_sql(_x('my-courses', 'page_slug', 'woothemes-sensei')), $this->token.'_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]'); |
|
252 | 252 | |
253 | 253 | } // End create_pages() |
254 | 254 | |
@@ -258,25 +258,25 @@ discard block |
||
258 | 258 | * @since 1.0.0 |
259 | 259 | * @return void |
260 | 260 | */ |
261 | - public function admin_styles_global ( $hook ) { |
|
261 | + public function admin_styles_global($hook) { |
|
262 | 262 | global $post_type; |
263 | 263 | |
264 | - $allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) ); |
|
265 | - $allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) ); |
|
266 | - $allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order' ) ); |
|
264 | + $allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question')); |
|
265 | + $allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php')); |
|
266 | + $allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order')); |
|
267 | 267 | |
268 | 268 | // Global Styles for icons and menu items |
269 | - wp_register_style( Sensei()->token . '-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' ); |
|
270 | - wp_enqueue_style( Sensei()->token . '-global' ); |
|
269 | + wp_register_style(Sensei()->token.'-global', Sensei()->plugin_url.'assets/css/global.css', '', Sensei()->version, 'screen'); |
|
270 | + wp_enqueue_style(Sensei()->token.'-global'); |
|
271 | 271 | |
272 | 272 | // Select 2 styles |
273 | - wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
273 | + wp_enqueue_style('select2', Sensei()->plugin_url.'assets/css/select2/select2.css', '', Sensei()->version, 'screen'); |
|
274 | 274 | |
275 | 275 | // Test for Write Panel Pages |
276 | - if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) { |
|
276 | + if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) { |
|
277 | 277 | |
278 | - wp_register_style( Sensei()->token . '-admin-custom', Sensei()->plugin_url . 'assets/css/admin-custom.css', '', Sensei()->version, 'screen' ); |
|
279 | - wp_enqueue_style( Sensei()->token . '-admin-custom' ); |
|
278 | + wp_register_style(Sensei()->token.'-admin-custom', Sensei()->plugin_url.'assets/css/admin-custom.css', '', Sensei()->version, 'screen'); |
|
279 | + wp_enqueue_style(Sensei()->token.'-admin-custom'); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | * @since 1.8.2 |
292 | 292 | * @access public |
293 | 293 | */ |
294 | - public function register_scripts( $hook ){ |
|
294 | + public function register_scripts($hook) { |
|
295 | 295 | |
296 | 296 | $screen = get_current_screen(); |
297 | 297 | |
298 | 298 | // Allow developers to load non-minified versions of scripts |
299 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
299 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
300 | 300 | |
301 | 301 | // Select2 script used to enhance all select boxes |
302 | - wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
302 | + wp_register_script('select2', Sensei()->plugin_url.'/assets/js/select2/select2'.$suffix.'.js', array('jquery'), Sensei()->version); |
|
303 | 303 | |
304 | 304 | // load edit module scripts |
305 | - if( 'edit-module' == $screen->id ){ |
|
305 | + if ('edit-module' == $screen->id) { |
|
306 | 306 | |
307 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
307 | + wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery.min.js', array('jquery', 'sensei-chosen'), Sensei()->version, true); |
|
308 | 308 | |
309 | 309 | } |
310 | 310 | |
@@ -322,19 +322,19 @@ discard block |
||
322 | 322 | <div id="message" class="updated sensei-message sensei-connect"> |
323 | 323 | |
324 | 324 | <p> |
325 | - <?php _e( '<strong>Welcome to Sensei</strong> – You\'re almost ready to create some courses!', 'woothemes-sensei' ); ?> |
|
325 | + <?php _e('<strong>Welcome to Sensei</strong> – You\'re almost ready to create some courses!', 'woothemes-sensei'); ?> |
|
326 | 326 | </p> |
327 | 327 | |
328 | 328 | <p class="submit"> |
329 | 329 | |
330 | - <a href="<?php echo esc_url( add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings') ) ); ?>" |
|
330 | + <a href="<?php echo esc_url(add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>" |
|
331 | 331 | class="button-primary"> |
332 | 332 | |
333 | - <?php _e( 'Install Sensei Pages', 'woothemes-sensei' ); ?> |
|
333 | + <?php _e('Install Sensei Pages', 'woothemes-sensei'); ?> |
|
334 | 334 | |
335 | 335 | </a> |
336 | 336 | |
337 | - <a class="skip button" href="<?php echo esc_url( add_query_arg( 'skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings' ) ) ); ?>"> |
|
337 | + <a class="skip button" href="<?php echo esc_url(add_query_arg('skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>"> |
|
338 | 338 | |
339 | 339 | <?php _e('Skip setup', 'woothemes-sensei'); ?> |
340 | 340 | |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | <div id="message" class="updated sensei-message sensei-connect"> |
358 | 358 | |
359 | 359 | <p> |
360 | - <?php _e( '<strong>Sensei has been installed</strong> – You\'re ready to start creating courses!', 'woothemes-sensei' ); ?> |
|
360 | + <?php _e('<strong>Sensei has been installed</strong> – You\'re ready to start creating courses!', 'woothemes-sensei'); ?> |
|
361 | 361 | </p> |
362 | 362 | |
363 | 363 | <p class="submit"> |
364 | - <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woothemes-sensei' ); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/"> |
|
364 | + <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e('Settings', 'woothemes-sensei'); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/"> |
|
365 | 365 | <?php _e('Documentation', 'woothemes-sensei'); ?> |
366 | 366 | </a> |
367 | 367 | </p> |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | public function language_pack_install_notice() { |
395 | 395 | ?> |
396 | 396 | <div id="message" class="updated sensei-message sensei-connect"> |
397 | - <p><?php _e( '<strong>Sensei in your language</strong> – There is a translation available for your language.', 'woothemes-sensei' ); ?><p> |
|
397 | + <p><?php _e('<strong>Sensei in your language</strong> – There is a translation available for your language.', 'woothemes-sensei'); ?><p> |
|
398 | 398 | |
399 | 399 | <p class="submit"> |
400 | - <a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_install_uri() ); ?>" class="button-primary"><?php _e( 'Install', 'woothemes-sensei' ); ?></a> |
|
401 | - <a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_dismiss_uri() ) ?>" class="docs button"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?></a> |
|
400 | + <a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_install_uri()); ?>" class="button-primary"><?php _e('Install', 'woothemes-sensei'); ?></a> |
|
401 | + <a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_dismiss_uri()) ?>" class="docs button"><?php _e('Hide this notice', 'woothemes-sensei'); ?></a> |
|
402 | 402 | </p> |
403 | 403 | </div> |
404 | 404 | <?php |
@@ -414,20 +414,20 @@ discard block |
||
414 | 414 | function admin_notices_styles() { |
415 | 415 | |
416 | 416 | // Installed notices |
417 | - if ( 1 == get_option( 'sensei_installed' ) ) { |
|
417 | + if (1 == get_option('sensei_installed')) { |
|
418 | 418 | |
419 | - wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
419 | + wp_enqueue_style('sensei-activation', plugins_url('/assets/css/activation.css', dirname(__FILE__)), '', Sensei()->version); |
|
420 | 420 | |
421 | - if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
422 | - add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
423 | - } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
424 | - add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
421 | + if (get_option('skip_install_sensei_pages') != 1 && Sensei()->get_page_id('course') < 1 && ! isset($_GET['install_sensei_pages']) && ! isset($_GET['skip_install_sensei_pages'])) { |
|
422 | + add_action('admin_notices', array($this, 'admin_install_notice')); |
|
423 | + } elseif ( ! isset($_GET['page']) || $_GET['page'] != 'woothemes-sensei-settings') { |
|
424 | + add_action('admin_notices', array($this, 'admin_installed_notice')); |
|
425 | 425 | } // End If Statement |
426 | 426 | |
427 | 427 | } // End If Statement |
428 | 428 | |
429 | - if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
430 | - add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
429 | + if (Sensei_Language_Pack_Manager::has_language_pack_available()) { |
|
430 | + add_action('admin_notices', array($this, 'language_pack_install_notice')); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | } // End admin_notices_styles() |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | * @param object $post Current post |
439 | 439 | * @return array Modified actions |
440 | 440 | */ |
441 | - public function duplicate_action_link( $actions, $post ) { |
|
442 | - switch( $post->post_type ) { |
|
441 | + public function duplicate_action_link($actions, $post) { |
|
442 | + switch ($post->post_type) { |
|
443 | 443 | case 'lesson': |
444 | - $confirm = __( 'This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei' ); |
|
445 | - $actions['duplicate'] = "<a onclick='return confirm(\"" . $confirm . "\");' href='" . $this->get_duplicate_link( $post->ID ) . "' title='" . esc_attr(__( 'Duplicate this lesson', 'woothemes-sensei' ) ) . "'>" . __('Duplicate', 'woothemes-sensei' ) . "</a>"; |
|
444 | + $confirm = __('This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei'); |
|
445 | + $actions['duplicate'] = "<a onclick='return confirm(\"".$confirm."\");' href='".$this->get_duplicate_link($post->ID)."' title='".esc_attr(__('Duplicate this lesson', 'woothemes-sensei'))."'>".__('Duplicate', 'woothemes-sensei')."</a>"; |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | case 'course': |
449 | - $confirm = __( 'This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei' ); |
|
450 | - $actions['duplicate'] = '<a href="' . $this->get_duplicate_link( $post->ID ) . '" title="' . esc_attr(__( 'Duplicate this course', 'woothemes-sensei' ) ) . '">' . __('Duplicate', 'woothemes-sensei' ) . '</a>'; |
|
451 | - $actions['duplicate_with_lessons'] = '<a onclick="return confirm(\'' . $confirm . '\');" href="' . $this->get_duplicate_link( $post->ID, true ) . '" title="' . esc_attr(__( 'Duplicate this course with its lessons', 'woothemes-sensei' ) ) . '">' . __('Duplicate (with lessons)', 'woothemes-sensei' ) . '</a>'; |
|
449 | + $confirm = __('This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei'); |
|
450 | + $actions['duplicate'] = '<a href="'.$this->get_duplicate_link($post->ID).'" title="'.esc_attr(__('Duplicate this course', 'woothemes-sensei')).'">'.__('Duplicate', 'woothemes-sensei').'</a>'; |
|
451 | + $actions['duplicate_with_lessons'] = '<a onclick="return confirm(\''.$confirm.'\');" href="'.$this->get_duplicate_link($post->ID, true).'" title="'.esc_attr(__('Duplicate this course with its lessons', 'woothemes-sensei')).'">'.__('Duplicate (with lessons)', 'woothemes-sensei').'</a>'; |
|
452 | 452 | break; |
453 | 453 | } |
454 | 454 | |
@@ -461,17 +461,17 @@ discard block |
||
461 | 461 | * @param boolean $with_lessons Include lessons or not |
462 | 462 | * @return string Duplication link |
463 | 463 | */ |
464 | - private function get_duplicate_link( $post_id = 0, $with_lessons = false ) { |
|
464 | + private function get_duplicate_link($post_id = 0, $with_lessons = false) { |
|
465 | 465 | |
466 | - $post = get_post( $post_id ); |
|
466 | + $post = get_post($post_id); |
|
467 | 467 | |
468 | - $action = 'duplicate_' . $post->post_type; |
|
468 | + $action = 'duplicate_'.$post->post_type; |
|
469 | 469 | |
470 | - if( 'course' == $post->post_type && $with_lessons ) { |
|
470 | + if ('course' == $post->post_type && $with_lessons) { |
|
471 | 471 | $action .= '_with_lessons'; |
472 | 472 | } |
473 | 473 | |
474 | - return apply_filters( $action . '_link', admin_url( 'admin.php?action=' . $action . '&post=' . $post_id ), $post_id ); |
|
474 | + return apply_filters($action.'_link', admin_url('admin.php?action='.$action.'&post='.$post_id), $post_id); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @return void |
480 | 480 | */ |
481 | 481 | public function duplicate_lesson_action() { |
482 | - $this->duplicate_content( 'lesson' ); |
|
482 | + $this->duplicate_content('lesson'); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @return void |
488 | 488 | */ |
489 | 489 | public function duplicate_course_action() { |
490 | - $this->duplicate_content( 'course' ); |
|
490 | + $this->duplicate_content('course'); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @return void |
496 | 496 | */ |
497 | 497 | public function duplicate_course_with_lessons_action() { |
498 | - $this->duplicate_content( 'course', true ); |
|
498 | + $this->duplicate_content('course', true); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -504,34 +504,34 @@ discard block |
||
504 | 504 | * @param boolean $with_lessons Include lessons or not |
505 | 505 | * @return void |
506 | 506 | */ |
507 | - private function duplicate_content( $post_type = 'lesson', $with_lessons = false ) { |
|
508 | - if ( ! isset( $_GET['post'] ) ) { |
|
509 | - wp_die( sprintf( __( 'Please supply a %1$s ID.', 'woothemes-sensei' ) ), $post_type ); |
|
507 | + private function duplicate_content($post_type = 'lesson', $with_lessons = false) { |
|
508 | + if ( ! isset($_GET['post'])) { |
|
509 | + wp_die(sprintf(__('Please supply a %1$s ID.', 'woothemes-sensei')), $post_type); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | $post_id = $_GET['post']; |
513 | - $post = get_post( $post_id ); |
|
513 | + $post = get_post($post_id); |
|
514 | 514 | |
515 | - if( ! is_wp_error( $post ) ) { |
|
515 | + if ( ! is_wp_error($post)) { |
|
516 | 516 | |
517 | - $new_post = $this->duplicate_post( $post ); |
|
517 | + $new_post = $this->duplicate_post($post); |
|
518 | 518 | |
519 | - if( $new_post && ! is_wp_error( $new_post ) ) { |
|
519 | + if ($new_post && ! is_wp_error($new_post)) { |
|
520 | 520 | |
521 | - if( 'lesson' == $new_post->post_type ) { |
|
522 | - $this->duplicate_lesson_quizzes( $post_id, $new_post->ID ); |
|
521 | + if ('lesson' == $new_post->post_type) { |
|
522 | + $this->duplicate_lesson_quizzes($post_id, $new_post->ID); |
|
523 | 523 | } |
524 | 524 | |
525 | - if( 'course' == $new_post->post_type && $with_lessons ) { |
|
526 | - $this->duplicate_course_lessons( $post_id, $new_post->ID ); |
|
525 | + if ('course' == $new_post->post_type && $with_lessons) { |
|
526 | + $this->duplicate_course_lessons($post_id, $new_post->ID); |
|
527 | 527 | } |
528 | 528 | |
529 | - $redirect_url = admin_url( 'post.php?post=' . $new_post->ID . '&action=edit' ); |
|
529 | + $redirect_url = admin_url('post.php?post='.$new_post->ID.'&action=edit'); |
|
530 | 530 | } else { |
531 | - $redirect_url = admin_url( 'edit.php?post_type=' . $post->post_type . '&message=duplicate_failed' ); |
|
531 | + $redirect_url = admin_url('edit.php?post_type='.$post->post_type.'&message=duplicate_failed'); |
|
532 | 532 | } |
533 | 533 | |
534 | - wp_safe_redirect( esc_url_raw( $redirect_url ) ); |
|
534 | + wp_safe_redirect(esc_url_raw($redirect_url)); |
|
535 | 535 | exit; |
536 | 536 | } |
537 | 537 | } |
@@ -542,19 +542,19 @@ discard block |
||
542 | 542 | * @param integer $new_lesson_id ID of duplicate lesson |
543 | 543 | * @return void |
544 | 544 | */ |
545 | - private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) { |
|
545 | + private function duplicate_lesson_quizzes($old_lesson_id, $new_lesson_id) { |
|
546 | 546 | |
547 | - $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
548 | - $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
547 | + $old_quiz_id = Sensei()->lesson->lesson_quizzes($old_lesson_id); |
|
548 | + $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions($old_quiz_id); |
|
549 | 549 | |
550 | 550 | // duplicate the generic wp post information |
551 | - $new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' ); |
|
551 | + $new_quiz = $this->duplicate_post(get_post($old_quiz_id), ''); |
|
552 | 552 | |
553 | 553 | //update the new lesson data |
554 | - add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
554 | + add_post_meta($new_lesson_id, '_lesson_quiz', $new_quiz->ID); |
|
555 | 555 | |
556 | 556 | //update the new quiz data |
557 | - add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
557 | + add_post_meta($new_quiz->ID, '_quiz_lesson', $new_lesson_id); |
|
558 | 558 | wp_update_post( |
559 | 559 | array( |
560 | 560 | 'ID' => $new_quiz->ID, |
@@ -562,15 +562,15 @@ discard block |
||
562 | 562 | ) |
563 | 563 | ); |
564 | 564 | |
565 | - foreach( $old_quiz_questions as $question ) { |
|
565 | + foreach ($old_quiz_questions as $question) { |
|
566 | 566 | |
567 | 567 | // copy the question order over to the new quiz |
568 | - $old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true ); |
|
569 | - $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
570 | - add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
568 | + $old_question_order = get_post_meta($question->ID, '_quiz_question_order'.$old_quiz_id, true); |
|
569 | + $new_question_order = str_ireplace($old_quiz_id, $new_quiz->ID, $old_question_order); |
|
570 | + add_post_meta($question->ID, '_quiz_question_order'.$new_quiz->ID, $new_question_order); |
|
571 | 571 | |
572 | 572 | // Add question to quiz |
573 | - add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false ); |
|
573 | + add_post_meta($question->ID, '_quiz_id', $new_quiz->ID, false); |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @param integer $new_course_id ID of duplicated course |
582 | 582 | * @return void |
583 | 583 | */ |
584 | - private function duplicate_course_lessons( $old_course_id, $new_course_id ) { |
|
584 | + private function duplicate_course_lessons($old_course_id, $new_course_id) { |
|
585 | 585 | $lesson_args = array( |
586 | 586 | 'post_type' => 'lesson', |
587 | 587 | 'posts_per_page' => -1, |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | 'meta_value' => $old_course_id, |
590 | 590 | 'suppress_filters' => 0 |
591 | 591 | ); |
592 | - $lessons = get_posts( $lesson_args ); |
|
592 | + $lessons = get_posts($lesson_args); |
|
593 | 593 | |
594 | - foreach( $lessons as $lesson ) { |
|
595 | - $new_lesson = $this->duplicate_post( $lesson, '', true ); |
|
596 | - add_post_meta( $new_lesson->ID, '_lesson_course', $new_course_id ); |
|
594 | + foreach ($lessons as $lesson) { |
|
595 | + $new_lesson = $this->duplicate_post($lesson, '', true); |
|
596 | + add_post_meta($new_lesson->ID, '_lesson_course', $new_course_id); |
|
597 | 597 | |
598 | - $this->duplicate_lesson_quizzes( $lesson->ID, $new_lesson->ID ); |
|
598 | + $this->duplicate_lesson_quizzes($lesson->ID, $new_lesson->ID); |
|
599 | 599 | } |
600 | 600 | } |
601 | 601 | |
@@ -606,24 +606,24 @@ discard block |
||
606 | 606 | * @param boolean $ignore_course Ignore lesson course when dulicating |
607 | 607 | * @return object Duplicate post object |
608 | 608 | */ |
609 | - private function duplicate_post( $post, $suffix = ' (Duplicate)', $ignore_course = false ) { |
|
609 | + private function duplicate_post($post, $suffix = ' (Duplicate)', $ignore_course = false) { |
|
610 | 610 | |
611 | 611 | $new_post = array(); |
612 | 612 | |
613 | - foreach( $post as $k => $v ) { |
|
614 | - if( ! in_array( $k, array( 'ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count' ) ) ) { |
|
615 | - $new_post[ $k ] = $v; |
|
613 | + foreach ($post as $k => $v) { |
|
614 | + if ( ! in_array($k, array('ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count'))) { |
|
615 | + $new_post[$k] = $v; |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
619 | - $new_post['post_title'] .= __( $suffix, 'woothemes-sensei' ); |
|
619 | + $new_post['post_title'] .= __($suffix, 'woothemes-sensei'); |
|
620 | 620 | |
621 | - $new_post['post_date'] = current_time( 'mysql' ); |
|
622 | - $new_post['post_date_gmt'] = get_gmt_from_date( $new_post['post_date'] ); |
|
621 | + $new_post['post_date'] = current_time('mysql'); |
|
622 | + $new_post['post_date_gmt'] = get_gmt_from_date($new_post['post_date']); |
|
623 | 623 | $new_post['post_modified'] = $new_post['post_date']; |
624 | 624 | $new_post['post_modified_gmt'] = $new_post['post_date_gmt']; |
625 | 625 | |
626 | - switch( $post->post_type ) { |
|
626 | + switch ($post->post_type) { |
|
627 | 627 | case 'course': $new_post['post_status'] = 'draft'; break; |
628 | 628 | case 'lesson': $new_post['post_status'] = 'draft'; break; |
629 | 629 | case 'quiz': $new_post['post_status'] = 'publish'; break; |
@@ -631,45 +631,45 @@ discard block |
||
631 | 631 | } |
632 | 632 | |
633 | 633 | // As per wp_update_post() we need to escape the data from the db. |
634 | - $new_post = wp_slash( $new_post ); |
|
634 | + $new_post = wp_slash($new_post); |
|
635 | 635 | |
636 | - $new_post_id = wp_insert_post( $new_post ); |
|
636 | + $new_post_id = wp_insert_post($new_post); |
|
637 | 637 | |
638 | - if( ! is_wp_error( $new_post_id ) ) { |
|
638 | + if ( ! is_wp_error($new_post_id)) { |
|
639 | 639 | |
640 | - $post_meta = get_post_custom( $post->ID ); |
|
641 | - if( $post_meta && count( $post_meta ) > 0 ) { |
|
640 | + $post_meta = get_post_custom($post->ID); |
|
641 | + if ($post_meta && count($post_meta) > 0) { |
|
642 | 642 | |
643 | - $ignore_meta = array( '_quiz_lesson', '_quiz_id', '_lesson_quiz' ); |
|
643 | + $ignore_meta = array('_quiz_lesson', '_quiz_id', '_lesson_quiz'); |
|
644 | 644 | |
645 | - if( $ignore_course ) { |
|
645 | + if ($ignore_course) { |
|
646 | 646 | $ignore_meta[] = '_lesson_course'; |
647 | 647 | } |
648 | 648 | |
649 | - foreach( $post_meta as $key => $meta ) { |
|
650 | - foreach( $meta as $value ) { |
|
651 | - $value = maybe_unserialize( $value ); |
|
652 | - if( ! in_array( $key, $ignore_meta ) ) { |
|
653 | - add_post_meta( $new_post_id, $key, $value ); |
|
649 | + foreach ($post_meta as $key => $meta) { |
|
650 | + foreach ($meta as $value) { |
|
651 | + $value = maybe_unserialize($value); |
|
652 | + if ( ! in_array($key, $ignore_meta)) { |
|
653 | + add_post_meta($new_post_id, $key, $value); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | - add_post_meta( $new_post_id, '_duplicate', $post->ID ); |
|
659 | + add_post_meta($new_post_id, '_duplicate', $post->ID); |
|
660 | 660 | |
661 | - $taxonomies = get_object_taxonomies( $post->post_type, 'objects' ); |
|
661 | + $taxonomies = get_object_taxonomies($post->post_type, 'objects'); |
|
662 | 662 | |
663 | - foreach ( $taxonomies as $slug => $tax ) { |
|
664 | - $terms = get_the_terms( $post->ID, $slug ); |
|
665 | - if( isset( $terms ) && is_array( $terms ) && 0 < count( $terms ) ) { |
|
666 | - foreach( $terms as $term ) { |
|
667 | - wp_set_object_terms( $new_post_id, $term->term_id, $slug, true ); |
|
663 | + foreach ($taxonomies as $slug => $tax) { |
|
664 | + $terms = get_the_terms($post->ID, $slug); |
|
665 | + if (isset($terms) && is_array($terms) && 0 < count($terms)) { |
|
666 | + foreach ($terms as $term) { |
|
667 | + wp_set_object_terms($new_post_id, $term->term_id, $slug, true); |
|
668 | 668 | } |
669 | 669 | } |
670 | 670 | } |
671 | 671 | |
672 | - $new_post = get_post( $new_post_id ); |
|
672 | + $new_post = get_post($new_post_id); |
|
673 | 673 | |
674 | 674 | return $new_post; |
675 | 675 | } |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | public function lesson_filter_options() { |
685 | 685 | global $typenow; |
686 | 686 | |
687 | - if( is_admin() && 'lesson' == $typenow ) { |
|
687 | + if (is_admin() && 'lesson' == $typenow) { |
|
688 | 688 | |
689 | 689 | $args = array( |
690 | 690 | 'post_type' => 'course', |
@@ -694,16 +694,16 @@ discard block |
||
694 | 694 | 'orderby' => 'menu_order date', |
695 | 695 | 'order' => 'ASC', |
696 | 696 | ); |
697 | - $courses = get_posts( $args ); |
|
697 | + $courses = get_posts($args); |
|
698 | 698 | |
699 | - $selected = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : ''; |
|
699 | + $selected = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : ''; |
|
700 | 700 | $course_options = ''; |
701 | - foreach( $courses as $course ) { |
|
702 | - $course_options .= '<option value="' . esc_attr( $course->ID ) . '" ' . selected( $selected, $course->ID, false ) . '>' . get_the_title( $course->ID ) . '</option>'; |
|
701 | + foreach ($courses as $course) { |
|
702 | + $course_options .= '<option value="'.esc_attr($course->ID).'" '.selected($selected, $course->ID, false).'>'.get_the_title($course->ID).'</option>'; |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | $output = '<select name="lesson_course" id="dropdown_lesson_course">'; |
706 | - $output .= '<option value="">'.__( 'Show all courses', 'woothemes-sensei' ).'</option>'; |
|
706 | + $output .= '<option value="">'.__('Show all courses', 'woothemes-sensei').'</option>'; |
|
707 | 707 | $output .= $course_options; |
708 | 708 | $output .= '</select>'; |
709 | 709 | |
@@ -716,13 +716,13 @@ discard block |
||
716 | 716 | * @param array $request Current request |
717 | 717 | * @return array Modified request |
718 | 718 | */ |
719 | - public function lesson_filter_actions( $request ) { |
|
719 | + public function lesson_filter_actions($request) { |
|
720 | 720 | global $typenow; |
721 | 721 | |
722 | - if( is_admin() && 'lesson' == $typenow ) { |
|
723 | - $lesson_course = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : ''; |
|
722 | + if (is_admin() && 'lesson' == $typenow) { |
|
723 | + $lesson_course = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : ''; |
|
724 | 724 | |
725 | - if( $lesson_course ) { |
|
725 | + if ($lesson_course) { |
|
726 | 726 | $request['meta_key'] = '_lesson_course'; |
727 | 727 | $request['meta_value'] = $lesson_course; |
728 | 728 | $request['meta_compare'] = '='; |
@@ -737,27 +737,27 @@ discard block |
||
737 | 737 | * @param array $items Existing items |
738 | 738 | * @return array Updated items |
739 | 739 | */ |
740 | - public function glance_items( $items = array() ) { |
|
740 | + public function glance_items($items = array()) { |
|
741 | 741 | |
742 | - $types = array( 'course', 'lesson', 'question' ); |
|
742 | + $types = array('course', 'lesson', 'question'); |
|
743 | 743 | |
744 | - foreach( $types as $type ) { |
|
745 | - if( ! post_type_exists( $type ) ) continue; |
|
744 | + foreach ($types as $type) { |
|
745 | + if ( ! post_type_exists($type)) continue; |
|
746 | 746 | |
747 | - $num_posts = wp_count_posts( $type ); |
|
747 | + $num_posts = wp_count_posts($type); |
|
748 | 748 | |
749 | - if( $num_posts ) { |
|
749 | + if ($num_posts) { |
|
750 | 750 | |
751 | - $published = intval( $num_posts->publish ); |
|
752 | - $post_type = get_post_type_object( $type ); |
|
751 | + $published = intval($num_posts->publish); |
|
752 | + $post_type = get_post_type_object($type); |
|
753 | 753 | |
754 | - $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'woothemes-sensei' ); |
|
755 | - $text = sprintf( $text, number_format_i18n( $published ) ); |
|
754 | + $text = _n('%s '.$post_type->labels->singular_name, '%s '.$post_type->labels->name, $published, 'woothemes-sensei'); |
|
755 | + $text = sprintf($text, number_format_i18n($published)); |
|
756 | 756 | |
757 | - if ( current_user_can( $post_type->cap->edit_posts ) ) { |
|
758 | - $items[] = sprintf( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text ) . "\n"; |
|
757 | + if (current_user_can($post_type->cap->edit_posts)) { |
|
758 | + $items[] = sprintf('<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text)."\n"; |
|
759 | 759 | } else { |
760 | - $items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n"; |
|
760 | + $items[] = sprintf('<span class="%1$s-count">%2$s</span>', $type, $text)."\n"; |
|
761 | 761 | } |
762 | 762 | } |
763 | 763 | } |
@@ -771,13 +771,13 @@ discard block |
||
771 | 771 | * @param object $post Post object |
772 | 772 | * @return void |
773 | 773 | */ |
774 | - public function delete_content( $post_id, $post ) { |
|
774 | + public function delete_content($post_id, $post) { |
|
775 | 775 | |
776 | 776 | $type = $post->post_type; |
777 | 777 | |
778 | - if( in_array( $type, array( 'lesson', 'course' ) ) ) { |
|
778 | + if (in_array($type, array('lesson', 'course'))) { |
|
779 | 779 | |
780 | - $meta_key = '_' . $type . '_prerequisite'; |
|
780 | + $meta_key = '_'.$type.'_prerequisite'; |
|
781 | 781 | |
782 | 782 | $args = array( |
783 | 783 | 'post_type' => $type, |
@@ -787,10 +787,10 @@ discard block |
||
787 | 787 | 'meta_value' => $post_id |
788 | 788 | ); |
789 | 789 | |
790 | - $posts = get_posts( $args ); |
|
790 | + $posts = get_posts($args); |
|
791 | 791 | |
792 | - foreach( $posts as $post ) { |
|
793 | - delete_post_meta( $post->ID, $meta_key ); |
|
792 | + foreach ($posts as $post) { |
|
793 | + delete_post_meta($post->ID, $meta_key); |
|
794 | 794 | } |
795 | 795 | } |
796 | 796 | } |
@@ -800,181 +800,181 @@ discard block |
||
800 | 800 | * @param integer $user_id User ID |
801 | 801 | * @return void |
802 | 802 | */ |
803 | - public function delete_user_activity( $user_id = 0 ) { |
|
804 | - if( $user_id ) { |
|
805 | - Sensei_Utils::delete_all_user_activity( $user_id ); |
|
803 | + public function delete_user_activity($user_id = 0) { |
|
804 | + if ($user_id) { |
|
805 | + Sensei_Utils::delete_all_user_activity($user_id); |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
809 | - public function render_settings( $settings = array(), $post_id = 0, $group_id = '' ) { |
|
809 | + public function render_settings($settings = array(), $post_id = 0, $group_id = '') { |
|
810 | 810 | |
811 | 811 | $html = ''; |
812 | 812 | |
813 | - if( 0 == count( $settings ) ) return $html; |
|
813 | + if (0 == count($settings)) return $html; |
|
814 | 814 | |
815 | - $html .= '<div class="sensei-options-panel">' . "\n"; |
|
815 | + $html .= '<div class="sensei-options-panel">'."\n"; |
|
816 | 816 | |
817 | - $html .= '<div class="options_group" id="' . esc_attr( $group_id ) . '">' . "\n"; |
|
817 | + $html .= '<div class="options_group" id="'.esc_attr($group_id).'">'."\n"; |
|
818 | 818 | |
819 | - foreach( $settings as $field ) { |
|
819 | + foreach ($settings as $field) { |
|
820 | 820 | |
821 | 821 | $data = ''; |
822 | 822 | |
823 | - if( $post_id ) { |
|
824 | - $data = get_post_meta( $post_id, '_' . $field['id'], true ); |
|
825 | - if( ! $data && isset( $field['default'] ) ) { |
|
823 | + if ($post_id) { |
|
824 | + $data = get_post_meta($post_id, '_'.$field['id'], true); |
|
825 | + if ( ! $data && isset($field['default'])) { |
|
826 | 826 | $data = $field['default']; |
827 | 827 | } |
828 | 828 | } else { |
829 | - $option = get_option( $field['id'] ); |
|
830 | - if( isset( $field['default'] ) ) { |
|
829 | + $option = get_option($field['id']); |
|
830 | + if (isset($field['default'])) { |
|
831 | 831 | $data = $field['default']; |
832 | - if( $option ) { |
|
832 | + if ($option) { |
|
833 | 833 | $data = $option; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | 838 | $disabled = ''; |
839 | - if( isset( $field['disabled'] ) && $field['disabled'] ) { |
|
840 | - $disabled = disabled( $field['disabled'], true, false ); |
|
839 | + if (isset($field['disabled']) && $field['disabled']) { |
|
840 | + $disabled = disabled($field['disabled'], true, false); |
|
841 | 841 | } |
842 | 842 | |
843 | - if( 'hidden' != $field['type'] ) { |
|
843 | + if ('hidden' != $field['type']) { |
|
844 | 844 | |
845 | 845 | $class_tail = ''; |
846 | 846 | |
847 | - if( isset( $field['class'] ) ) { |
|
847 | + if (isset($field['class'])) { |
|
848 | 848 | $class_tail .= $field['class']; |
849 | 849 | } |
850 | 850 | |
851 | - if( isset( $field['disabled'] ) && $field['disabled'] ) { |
|
851 | + if (isset($field['disabled']) && $field['disabled']) { |
|
852 | 852 | $class_tail .= ' disabled'; |
853 | 853 | } |
854 | 854 | |
855 | - $html .= '<p class="form-field ' . esc_attr( $field['id'] ) . ' ' . esc_attr( $class_tail ) . '">' . "\n"; |
|
855 | + $html .= '<p class="form-field '.esc_attr($field['id']).' '.esc_attr($class_tail).'">'."\n"; |
|
856 | 856 | } |
857 | 857 | |
858 | - if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) { |
|
859 | - $html .= '<label for="' . esc_attr( $field['id'] ) . '">' . "\n"; |
|
858 | + if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) { |
|
859 | + $html .= '<label for="'.esc_attr($field['id']).'">'."\n"; |
|
860 | 860 | } |
861 | 861 | |
862 | - if( $field['label'] ) { |
|
863 | - $html .= '<span class="label">' . esc_html( $field['label'] ) . '</span>'; |
|
862 | + if ($field['label']) { |
|
863 | + $html .= '<span class="label">'.esc_html($field['label']).'</span>'; |
|
864 | 864 | } |
865 | 865 | |
866 | - switch( $field['type'] ) { |
|
866 | + switch ($field['type']) { |
|
867 | 867 | case 'text': |
868 | 868 | case 'password': |
869 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $disabled . ' />' . "\n"; |
|
869 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$disabled.' />'."\n"; |
|
870 | 870 | break; |
871 | 871 | |
872 | 872 | case 'number': |
873 | 873 | |
874 | 874 | $min = ''; |
875 | - if( isset( $field['min'] ) ) { |
|
876 | - $min = 'min="' . esc_attr( $field['min'] ) . '"'; |
|
875 | + if (isset($field['min'])) { |
|
876 | + $min = 'min="'.esc_attr($field['min']).'"'; |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | $max = ''; |
880 | - if( isset( $field['max'] ) ) { |
|
881 | - $max = 'max="' . esc_attr( $field['max'] ) . '"'; |
|
880 | + if (isset($field['max'])) { |
|
881 | + $max = 'max="'.esc_attr($field['max']).'"'; |
|
882 | 882 | } |
883 | 883 | |
884 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $min . ' ' . $max . ' class="small-text" ' . $disabled . ' />' . "\n"; |
|
884 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$min.' '.$max.' class="small-text" '.$disabled.' />'."\n"; |
|
885 | 885 | break; |
886 | 886 | |
887 | 887 | case 'textarea': |
888 | - $html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . $disabled . '>' . $data . '</textarea><br/>'. "\n"; |
|
888 | + $html .= '<textarea id="'.esc_attr($field['id']).'" rows="5" cols="50" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" '.$disabled.'>'.$data.'</textarea><br/>'."\n"; |
|
889 | 889 | break; |
890 | 890 | |
891 | 891 | case 'checkbox': |
892 | 892 | //backwards compatibility |
893 | - if( empty( $data ) || 'on' == $data ){ |
|
893 | + if (empty($data) || 'on' == $data) { |
|
894 | 894 | $checked_value = 'on'; |
895 | - }elseif( 'yes' == $data ) { |
|
895 | + }elseif ('yes' == $data) { |
|
896 | 896 | |
897 | 897 | $checked_value = 'yes'; |
898 | 898 | |
899 | - }elseif( 'auto' == $data ) { |
|
899 | + }elseif ('auto' == $data) { |
|
900 | 900 | |
901 | 901 | $checked_value = 'auto'; |
902 | 902 | |
903 | 903 | } else { |
904 | 904 | $checked_value = 1; |
905 | - $data = intval( $data ); |
|
905 | + $data = intval($data); |
|
906 | 906 | } |
907 | - $checked = checked( $checked_value, $data, false ); |
|
908 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n"; |
|
907 | + $checked = checked($checked_value, $data, false); |
|
908 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" '.$checked.' '.$disabled.'/>'."\n"; |
|
909 | 909 | break; |
910 | 910 | |
911 | 911 | case 'checkbox_multi': |
912 | - foreach( $field['options'] as $k => $v ) { |
|
912 | + foreach ($field['options'] as $k => $v) { |
|
913 | 913 | $checked = false; |
914 | - if( in_array( $k, $data ) ) { |
|
914 | + if (in_array($k, $data)) { |
|
915 | 915 | $checked = true; |
916 | 916 | } |
917 | - $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n"; |
|
917 | + $html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="checkbox" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'[]" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n"; |
|
918 | 918 | } |
919 | 919 | break; |
920 | 920 | |
921 | 921 | case 'radio': |
922 | - foreach( $field['options'] as $k => $v ) { |
|
922 | + foreach ($field['options'] as $k => $v) { |
|
923 | 923 | $checked = false; |
924 | - if( $k == $data ) { |
|
924 | + if ($k == $data) { |
|
925 | 925 | $checked = true; |
926 | 926 | } |
927 | - $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n"; |
|
927 | + $html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="radio" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n"; |
|
928 | 928 | } |
929 | 929 | break; |
930 | 930 | |
931 | 931 | case 'select': |
932 | - $html .= '<select name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" ' . $disabled . '>' . "\n"; |
|
933 | - foreach( $field['options'] as $k => $v ) { |
|
932 | + $html .= '<select name="'.esc_attr($field['id']).'" id="'.esc_attr($field['id']).'" '.$disabled.'>'."\n"; |
|
933 | + foreach ($field['options'] as $k => $v) { |
|
934 | 934 | $selected = false; |
935 | - if( $k == $data ) { |
|
935 | + if ($k == $data) { |
|
936 | 936 | $selected = true; |
937 | 937 | } |
938 | - $html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>' . "\n"; |
|
938 | + $html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'">'.$v.'</option>'."\n"; |
|
939 | 939 | } |
940 | - $html .= '</select><br/>' . "\n"; |
|
940 | + $html .= '</select><br/>'."\n"; |
|
941 | 941 | break; |
942 | 942 | |
943 | 943 | case 'select_multi': |
944 | - $html .= '<select name="' . esc_attr( $field['id'] ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple" ' . $disabled . '>' . "\n"; |
|
945 | - foreach( $field['options'] as $k => $v ) { |
|
944 | + $html .= '<select name="'.esc_attr($field['id']).'[]" id="'.esc_attr($field['id']).'" multiple="multiple" '.$disabled.'>'."\n"; |
|
945 | + foreach ($field['options'] as $k => $v) { |
|
946 | 946 | $selected = false; |
947 | - if( in_array( $k, $data ) ) { |
|
947 | + if (in_array($k, $data)) { |
|
948 | 948 | $selected = true; |
949 | 949 | } |
950 | - $html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '" />' . $v . '</option>' . "\n"; |
|
950 | + $html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'" />'.$v.'</option>'."\n"; |
|
951 | 951 | } |
952 | 952 | $html .= '</select> . "\n"'; |
953 | 953 | break; |
954 | 954 | |
955 | 955 | case 'hidden': |
956 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" value="' . $data . '" ' . $disabled . '/>' . "\n"; |
|
956 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" value="'.$data.'" '.$disabled.'/>'."\n"; |
|
957 | 957 | break; |
958 | 958 | |
959 | 959 | } |
960 | 960 | |
961 | - if( $field['description'] ) { |
|
962 | - $html .= ' <span class="description">' . esc_html( $field['description'] ) . '</span>' . "\n"; |
|
961 | + if ($field['description']) { |
|
962 | + $html .= ' <span class="description">'.esc_html($field['description']).'</span>'."\n"; |
|
963 | 963 | } |
964 | 964 | |
965 | - if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) { |
|
966 | - $html .= '</label>' . "\n"; |
|
965 | + if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) { |
|
966 | + $html .= '</label>'."\n"; |
|
967 | 967 | } |
968 | 968 | |
969 | - if( 'hidden' != $field['type'] ) { |
|
970 | - $html .= '</p>' . "\n"; |
|
969 | + if ('hidden' != $field['type']) { |
|
970 | + $html .= '</p>'."\n"; |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | } |
974 | 974 | |
975 | - $html .= '</div>' . "\n"; |
|
975 | + $html .= '</div>'."\n"; |
|
976 | 976 | |
977 | - $html .= '</div>' . "\n"; |
|
977 | + $html .= '</div>'."\n"; |
|
978 | 978 | |
979 | 979 | return $html; |
980 | 980 | } |
@@ -985,61 +985,61 @@ discard block |
||
985 | 985 | */ |
986 | 986 | public function course_order_screen() { |
987 | 987 | |
988 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
989 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version ); |
|
988 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
989 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version); |
|
990 | 990 | |
991 | 991 | ?><div id="course-order" class="wrap course-order"> |
992 | - <h2><?php _e( 'Order Courses', 'woothemes-sensei' ); ?></h2><?php |
|
992 | + <h2><?php _e('Order Courses', 'woothemes-sensei'); ?></h2><?php |
|
993 | 993 | |
994 | 994 | $html = ''; |
995 | 995 | |
996 | - if( isset( $_POST['course-order'] ) && 0 < strlen( $_POST['course-order'] ) ) { |
|
997 | - $ordered = $this->save_course_order( esc_attr( $_POST['course-order'] ) ); |
|
996 | + if (isset($_POST['course-order']) && 0 < strlen($_POST['course-order'])) { |
|
997 | + $ordered = $this->save_course_order(esc_attr($_POST['course-order'])); |
|
998 | 998 | |
999 | - if( $ordered ) { |
|
1000 | - $html .= '<div class="updated fade">' . "\n"; |
|
1001 | - $html .= '<p>' . __( 'The course order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
1002 | - $html .= '</div>' . "\n"; |
|
999 | + if ($ordered) { |
|
1000 | + $html .= '<div class="updated fade">'."\n"; |
|
1001 | + $html .= '<p>'.__('The course order has been saved.', 'woothemes-sensei').'</p>'."\n"; |
|
1002 | + $html .= '</div>'."\n"; |
|
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | $courses = Sensei()->course->get_all_courses(); |
1007 | 1007 | |
1008 | - if( 0 < count( $courses ) ) { |
|
1008 | + if (0 < count($courses)) { |
|
1009 | 1009 | |
1010 | 1010 | // order the courses as set by the users |
1011 | 1011 | $all_course_ids = array(); |
1012 | - foreach( $courses as $course ){ |
|
1012 | + foreach ($courses as $course) { |
|
1013 | 1013 | |
1014 | - $all_course_ids[] = (string)$course->ID; |
|
1014 | + $all_course_ids[] = (string) $course->ID; |
|
1015 | 1015 | |
1016 | 1016 | } |
1017 | 1017 | $order_string = $this->get_course_order(); |
1018 | 1018 | |
1019 | - if( !empty( $order_string ) ){ |
|
1020 | - $ordered_course_ids = explode(',' , $order_string ); |
|
1021 | - $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1019 | + if ( ! empty($order_string)) { |
|
1020 | + $ordered_course_ids = explode(',', $order_string); |
|
1021 | + $all_course_ids = array_unique(array_merge($ordered_course_ids, $all_course_ids)); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | |
1025 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
1026 | - $html .= '<ul class="sortable-course-list">' . "\n"; |
|
1025 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
1026 | + $html .= '<ul class="sortable-course-list">'."\n"; |
|
1027 | 1027 | $count = 0; |
1028 | - foreach ( $all_course_ids as $course_id ) { |
|
1029 | - $course = get_post( $course_id ); |
|
1028 | + foreach ($all_course_ids as $course_id) { |
|
1029 | + $course = get_post($course_id); |
|
1030 | 1030 | $count++; |
1031 | 1031 | $class = 'course'; |
1032 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1033 | - if ( $count == count( $course ) ) { $class .= ' last'; } |
|
1034 | - if ( $count % 2 != 0 ) { |
|
1032 | + if ($count == 1) { $class .= ' first'; } |
|
1033 | + if ($count == count($course)) { $class .= ' last'; } |
|
1034 | + if ($count % 2 != 0) { |
|
1035 | 1035 | $class .= ' alternate'; |
1036 | 1036 | } |
1037 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $course->ID ) . '" style="width: 100%;"> ' . $course->post_title . '</span></li>' . "\n"; |
|
1037 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($course->ID).'" style="width: 100%;"> '.$course->post_title.'</span></li>'."\n"; |
|
1038 | 1038 | } |
1039 | - $html .= '</ul>' . "\n"; |
|
1039 | + $html .= '</ul>'."\n"; |
|
1040 | 1040 | |
1041 | - $html .= '<input type="hidden" name="course-order" value="' . esc_attr( $order_string ) . '" />' . "\n"; |
|
1042 | - $html .= '<input type="submit" class="button-primary" value="' . __( 'Save course order', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1041 | + $html .= '<input type="hidden" name="course-order" value="'.esc_attr($order_string).'" />'."\n"; |
|
1042 | + $html .= '<input type="submit" class="button-primary" value="'.__('Save course order', 'woothemes-sensei').'" />'."\n"; |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | echo $html; |
@@ -1048,25 +1048,25 @@ discard block |
||
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | public function get_course_order() { |
1051 | - return get_option( 'sensei_course_order', '' ); |
|
1051 | + return get_option('sensei_course_order', ''); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | - public function save_course_order( $order_string = '' ) { |
|
1055 | - $order = explode( ',', $order_string ); |
|
1054 | + public function save_course_order($order_string = '') { |
|
1055 | + $order = explode(',', $order_string); |
|
1056 | 1056 | |
1057 | - update_option( 'sensei_course_order', $order_string ); |
|
1057 | + update_option('sensei_course_order', $order_string); |
|
1058 | 1058 | |
1059 | 1059 | $i = 1; |
1060 | - foreach( $order as $course_id ) { |
|
1060 | + foreach ($order as $course_id) { |
|
1061 | 1061 | |
1062 | - if( $course_id ) { |
|
1062 | + if ($course_id) { |
|
1063 | 1063 | |
1064 | 1064 | $update_args = array( |
1065 | 1065 | 'ID' => $course_id, |
1066 | 1066 | 'menu_order' => $i, |
1067 | 1067 | ); |
1068 | 1068 | |
1069 | - wp_update_post( $update_args ); |
|
1069 | + wp_update_post($update_args); |
|
1070 | 1070 | |
1071 | 1071 | ++$i; |
1072 | 1072 | } |
@@ -1081,22 +1081,22 @@ discard block |
||
1081 | 1081 | */ |
1082 | 1082 | public function lesson_order_screen() { |
1083 | 1083 | |
1084 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1085 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version ); |
|
1084 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
1085 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version); |
|
1086 | 1086 | |
1087 | 1087 | ?><div id="lesson-order" class="wrap lesson-order"> |
1088 | - <h2><?php _e( 'Order Lessons', 'woothemes-sensei' ); ?></h2><?php |
|
1088 | + <h2><?php _e('Order Lessons', 'woothemes-sensei'); ?></h2><?php |
|
1089 | 1089 | |
1090 | 1090 | $html = ''; |
1091 | 1091 | |
1092 | - if( isset( $_POST['lesson-order'] ) ) { |
|
1092 | + if (isset($_POST['lesson-order'])) { |
|
1093 | 1093 | |
1094 | - $ordered = $this->save_lesson_order( esc_attr( $_POST['lesson-order'] ), esc_attr( $_POST['course_id'] ) ); |
|
1094 | + $ordered = $this->save_lesson_order(esc_attr($_POST['lesson-order']), esc_attr($_POST['course_id'])); |
|
1095 | 1095 | |
1096 | - if( $ordered ) { |
|
1097 | - $html .= '<div class="updated fade">' . "\n"; |
|
1098 | - $html .= '<p>' . __( 'The lesson order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
1099 | - $html .= '</div>' . "\n"; |
|
1096 | + if ($ordered) { |
|
1097 | + $html .= '<div class="updated fade">'."\n"; |
|
1098 | + $html .= '<p>'.__('The lesson order has been saved.', 'woothemes-sensei').'</p>'."\n"; |
|
1099 | + $html .= '</div>'."\n"; |
|
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1107,43 +1107,43 @@ discard block |
||
1107 | 1107 | 'orderby' => 'name', |
1108 | 1108 | 'order' => 'ASC', |
1109 | 1109 | ); |
1110 | - $courses = get_posts( $args ); |
|
1110 | + $courses = get_posts($args); |
|
1111 | 1111 | |
1112 | - $html .= '<form action="' . admin_url( 'edit.php' ) . '" method="get">' . "\n"; |
|
1113 | - $html .= '<input type="hidden" name="post_type" value="lesson" />' . "\n"; |
|
1114 | - $html .= '<input type="hidden" name="page" value="lesson-order" />' . "\n"; |
|
1115 | - $html .= '<select id="lesson-order-course" name="course_id">' . "\n"; |
|
1116 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>' . "\n"; |
|
1112 | + $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n"; |
|
1113 | + $html .= '<input type="hidden" name="post_type" value="lesson" />'."\n"; |
|
1114 | + $html .= '<input type="hidden" name="page" value="lesson-order" />'."\n"; |
|
1115 | + $html .= '<select id="lesson-order-course" name="course_id">'."\n"; |
|
1116 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n"; |
|
1117 | 1117 | |
1118 | - foreach( $courses as $course ) { |
|
1118 | + foreach ($courses as $course) { |
|
1119 | 1119 | $course_id = ''; |
1120 | - if( isset( $_GET['course_id'] ) ) { |
|
1121 | - $course_id = intval( $_GET['course_id'] ); |
|
1120 | + if (isset($_GET['course_id'])) { |
|
1121 | + $course_id = intval($_GET['course_id']); |
|
1122 | 1122 | } |
1123 | - $html .= '<option value="' . esc_attr( intval( $course->ID ) ) . '" ' . selected( $course->ID, $course_id, false ) .'>' . get_the_title( $course->ID ) . '</option>' . "\n"; |
|
1123 | + $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n"; |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | - $html .= '</select>' . "\n"; |
|
1127 | - $html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="' . __( 'Select', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1128 | - $html .= '</form>' . "\n"; |
|
1126 | + $html .= '</select>'."\n"; |
|
1127 | + $html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n"; |
|
1128 | + $html .= '</form>'."\n"; |
|
1129 | 1129 | |
1130 | - $html .= '<script type="text/javascript">' . "\n"; |
|
1131 | - $html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});' . "\n"; |
|
1132 | - $html .= '</script>' . "\n"; |
|
1130 | + $html .= '<script type="text/javascript">'."\n"; |
|
1131 | + $html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});'."\n"; |
|
1132 | + $html .= '</script>'."\n"; |
|
1133 | 1133 | |
1134 | - if( isset( $_GET['course_id'] ) ) { |
|
1135 | - $course_id = intval( $_GET['course_id'] ); |
|
1136 | - if( $course_id > 0 ) { |
|
1134 | + if (isset($_GET['course_id'])) { |
|
1135 | + $course_id = intval($_GET['course_id']); |
|
1136 | + if ($course_id > 0) { |
|
1137 | 1137 | |
1138 | - $order_string = $this->get_lesson_order( $course_id ); |
|
1138 | + $order_string = $this->get_lesson_order($course_id); |
|
1139 | 1139 | |
1140 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
1140 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
1141 | 1141 | |
1142 | 1142 | $displayed_lessons = array(); |
1143 | 1143 | |
1144 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1144 | + $modules = Sensei()->modules->get_course_modules(intval($course_id)); |
|
1145 | 1145 | |
1146 | - foreach( $modules as $module ) { |
|
1146 | + foreach ($modules as $module) { |
|
1147 | 1147 | |
1148 | 1148 | $args = array( |
1149 | 1149 | 'post_type' => 'lesson', |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | 'meta_query' => array( |
1153 | 1153 | array( |
1154 | 1154 | 'key' => '_lesson_course', |
1155 | - 'value' => intval( $course_id ), |
|
1155 | + 'value' => intval($course_id), |
|
1156 | 1156 | 'compare' => '=' |
1157 | 1157 | ) |
1158 | 1158 | ), |
@@ -1160,66 +1160,66 @@ discard block |
||
1160 | 1160 | array( |
1161 | 1161 | 'taxonomy' => Sensei()->modules->taxonomy, |
1162 | 1162 | 'field' => 'id', |
1163 | - 'terms' => intval( $module->term_id ) |
|
1163 | + 'terms' => intval($module->term_id) |
|
1164 | 1164 | ) |
1165 | 1165 | ), |
1166 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
1166 | + 'meta_key' => '_order_module_'.$module->term_id, |
|
1167 | 1167 | 'orderby' => 'meta_value_num date', |
1168 | 1168 | 'order' => 'ASC', |
1169 | 1169 | 'suppress_filters' => 0 |
1170 | 1170 | ); |
1171 | 1171 | |
1172 | - $lessons = get_posts( $args ); |
|
1172 | + $lessons = get_posts($args); |
|
1173 | 1173 | |
1174 | - if( count( $lessons ) > 0 ) { |
|
1175 | - $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1176 | - $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1174 | + if (count($lessons) > 0) { |
|
1175 | + $html .= '<h3>'.$module->name.'</h3>'."\n"; |
|
1176 | + $html .= '<ul class="sortable-lesson-list" data-module_id="'.$module->term_id.'">'."\n"; |
|
1177 | 1177 | |
1178 | 1178 | $count = 0; |
1179 | - foreach( $lessons as $lesson ) { |
|
1179 | + foreach ($lessons as $lesson) { |
|
1180 | 1180 | $count++; |
1181 | 1181 | $class = 'lesson'; |
1182 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1183 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1184 | - if ( $count % 2 != 0 ) { |
|
1182 | + if ($count == 1) { $class .= ' first'; } |
|
1183 | + if ($count == count($lesson)) { $class .= ' last'; } |
|
1184 | + if ($count % 2 != 0) { |
|
1185 | 1185 | $class .= ' alternate'; |
1186 | 1186 | } |
1187 | 1187 | |
1188 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1188 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n"; |
|
1189 | 1189 | |
1190 | 1190 | $displayed_lessons[] = $lesson->ID; |
1191 | 1191 | } |
1192 | 1192 | |
1193 | - $html .= '</ul>' . "\n"; |
|
1193 | + $html .= '</ul>'."\n"; |
|
1194 | 1194 | |
1195 | - $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1195 | + $html .= '<input type="hidden" name="lesson-order-module-'.$module->term_id.'" value="" />'."\n"; |
|
1196 | 1196 | } |
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | |
1200 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1200 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1201 | 1201 | |
1202 | - if( 0 < count( $lessons ) ) { |
|
1202 | + if (0 < count($lessons)) { |
|
1203 | 1203 | |
1204 | 1204 | //get module term ids, will be used to exclude lessons |
1205 | 1205 | $module_items_ids = array(); |
1206 | - if( ! empty( $modules ) ) { |
|
1206 | + if ( ! empty($modules)) { |
|
1207 | 1207 | foreach ($modules as $module) { |
1208 | 1208 | $module_items_ids[] = $module->term_id; |
1209 | 1209 | } |
1210 | 1210 | } |
1211 | 1211 | |
1212 | - if( 0 < count( $displayed_lessons ) ) { |
|
1213 | - $html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n"; |
|
1212 | + if (0 < count($displayed_lessons)) { |
|
1213 | + $html .= '<h3>'.__('Other Lessons', 'woothemes-sensei').'</h3>'."\n"; |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | - $html .= '<ul class="sortable-lesson-list" data-module_id="0">' . "\n"; |
|
1216 | + $html .= '<ul class="sortable-lesson-list" data-module_id="0">'."\n"; |
|
1217 | 1217 | $count = 0; |
1218 | - foreach ( $lessons as $lesson ) { |
|
1218 | + foreach ($lessons as $lesson) { |
|
1219 | 1219 | |
1220 | 1220 | // if lesson belongs to one fo the course modules then exclude it here |
1221 | 1221 | // as it is listed above |
1222 | - if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1222 | + if (has_term($module_items_ids, 'module', $lesson->ID)) { |
|
1223 | 1223 | |
1224 | 1224 | continue; |
1225 | 1225 | |
@@ -1227,28 +1227,28 @@ discard block |
||
1227 | 1227 | |
1228 | 1228 | $count++; |
1229 | 1229 | $class = 'lesson'; |
1230 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1231 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1232 | - if ( $count % 2 != 0 ) { |
|
1230 | + if ($count == 1) { $class .= ' first'; } |
|
1231 | + if ($count == count($lesson)) { $class .= ' last'; } |
|
1232 | + if ($count % 2 != 0) { |
|
1233 | 1233 | |
1234 | 1234 | $class .= ' alternate'; |
1235 | 1235 | |
1236 | 1236 | } |
1237 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1237 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n"; |
|
1238 | 1238 | |
1239 | 1239 | $displayed_lessons[] = $lesson->ID; |
1240 | 1240 | } |
1241 | - $html .= '</ul>' . "\n"; |
|
1241 | + $html .= '</ul>'."\n"; |
|
1242 | 1242 | } else { |
1243 | - if( 0 == count( $displayed_lessons ) ) { |
|
1244 | - $html .= '<p><em>' . __( 'There are no lessons in this course.', 'woothemes-sensei' ) . '</em></p>'; |
|
1243 | + if (0 == count($displayed_lessons)) { |
|
1244 | + $html .= '<p><em>'.__('There are no lessons in this course.', 'woothemes-sensei').'</em></p>'; |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - if( 0 < count( $displayed_lessons ) ) { |
|
1249 | - $html .= '<input type="hidden" name="lesson-order" value="' . esc_attr( $order_string ) . '" />' . "\n"; |
|
1250 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
1251 | - $html .= '<input type="submit" class="button-primary" value="' . __( 'Save lesson order', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1248 | + if (0 < count($displayed_lessons)) { |
|
1249 | + $html .= '<input type="hidden" name="lesson-order" value="'.esc_attr($order_string).'" />'."\n"; |
|
1250 | + $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n"; |
|
1251 | + $html .= '<input type="submit" class="button-primary" value="'.__('Save lesson order', 'woothemes-sensei').'" />'."\n"; |
|
1252 | 1252 | } |
1253 | 1253 | } |
1254 | 1254 | } |
@@ -1258,27 +1258,27 @@ discard block |
||
1258 | 1258 | ?></div><?php |
1259 | 1259 | } |
1260 | 1260 | |
1261 | - public function get_lesson_order( $course_id = 0 ) { |
|
1262 | - $order_string = get_post_meta( $course_id, '_lesson_order', true ); |
|
1261 | + public function get_lesson_order($course_id = 0) { |
|
1262 | + $order_string = get_post_meta($course_id, '_lesson_order', true); |
|
1263 | 1263 | return $order_string; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | - public function save_lesson_order( $order_string = '', $course_id = 0 ) { |
|
1266 | + public function save_lesson_order($order_string = '', $course_id = 0) { |
|
1267 | 1267 | |
1268 | - if( $course_id ) { |
|
1268 | + if ($course_id) { |
|
1269 | 1269 | |
1270 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1270 | + $modules = Sensei()->modules->get_course_modules(intval($course_id)); |
|
1271 | 1271 | |
1272 | - foreach( $modules as $module ) { |
|
1272 | + foreach ($modules as $module) { |
|
1273 | 1273 | |
1274 | - $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ]; |
|
1274 | + $module_order_string = $_POST['lesson-order-module-'.$module->term_id]; |
|
1275 | 1275 | |
1276 | - if( $module_order_string ) { |
|
1277 | - $order = explode( ',', $module_order_string ); |
|
1276 | + if ($module_order_string) { |
|
1277 | + $order = explode(',', $module_order_string); |
|
1278 | 1278 | $i = 1; |
1279 | - foreach( $order as $lesson_id ) { |
|
1280 | - if( $lesson_id ) { |
|
1281 | - update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1279 | + foreach ($order as $lesson_id) { |
|
1280 | + if ($lesson_id) { |
|
1281 | + update_post_meta($lesson_id, '_order_module_'.$module->term_id, $i); |
|
1282 | 1282 | ++$i; |
1283 | 1283 | } |
1284 | 1284 | } |
@@ -1286,15 +1286,15 @@ discard block |
||
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | |
1289 | - if( $order_string ) { |
|
1290 | - update_post_meta( $course_id, '_lesson_order', $order_string ); |
|
1289 | + if ($order_string) { |
|
1290 | + update_post_meta($course_id, '_lesson_order', $order_string); |
|
1291 | 1291 | |
1292 | - $order = explode( ',', $order_string ); |
|
1292 | + $order = explode(',', $order_string); |
|
1293 | 1293 | |
1294 | 1294 | $i = 1; |
1295 | - foreach( $order as $lesson_id ) { |
|
1296 | - if( $lesson_id ) { |
|
1297 | - update_post_meta( $lesson_id, '_order_' . $course_id, $i ); |
|
1295 | + foreach ($order as $lesson_id) { |
|
1296 | + if ($lesson_id) { |
|
1297 | + update_post_meta($lesson_id, '_order_'.$course_id, $i); |
|
1298 | 1298 | ++$i; |
1299 | 1299 | } |
1300 | 1300 | } |
@@ -1309,54 +1309,54 @@ discard block |
||
1309 | 1309 | function sensei_add_custom_menu_items() { |
1310 | 1310 | global $pagenow; |
1311 | 1311 | |
1312 | - if( 'nav-menus.php' == $pagenow ) { |
|
1313 | - add_meta_box( 'add-sensei-links', 'Sensei', array( $this, 'wp_nav_menu_item_sensei_links_meta_box' ), 'nav-menus', 'side', 'low' ); |
|
1312 | + if ('nav-menus.php' == $pagenow) { |
|
1313 | + add_meta_box('add-sensei-links', 'Sensei', array($this, 'wp_nav_menu_item_sensei_links_meta_box'), 'nav-menus', 'side', 'low'); |
|
1314 | 1314 | } |
1315 | 1315 | } |
1316 | 1316 | |
1317 | - function wp_nav_menu_item_sensei_links_meta_box( $object ) { |
|
1317 | + function wp_nav_menu_item_sensei_links_meta_box($object) { |
|
1318 | 1318 | global $nav_menu_selected_id; |
1319 | 1319 | |
1320 | 1320 | $menu_items = array( |
1321 | - '#senseicourses' => __( 'Courses', 'woothemes-sensei' ), |
|
1322 | - '#senseilessons' => __( 'Lessons', 'woothemes-sensei' ), |
|
1323 | - '#senseimycourses' => __( 'My Courses', 'woothemes-sensei' ), |
|
1324 | - '#senseilearnerprofile' => __( 'My Profile', 'woothemes-sensei' ), |
|
1325 | - '#senseimymessages' => __( 'My Messages', 'woothemes-sensei' ), |
|
1326 | - '#senseiloginlogout' => __( 'Login', 'woothemes-sensei' ) . '|' . __( 'Logout', 'woothemes-sensei' ) |
|
1321 | + '#senseicourses' => __('Courses', 'woothemes-sensei'), |
|
1322 | + '#senseilessons' => __('Lessons', 'woothemes-sensei'), |
|
1323 | + '#senseimycourses' => __('My Courses', 'woothemes-sensei'), |
|
1324 | + '#senseilearnerprofile' => __('My Profile', 'woothemes-sensei'), |
|
1325 | + '#senseimymessages' => __('My Messages', 'woothemes-sensei'), |
|
1326 | + '#senseiloginlogout' => __('Login', 'woothemes-sensei').'|'.__('Logout', 'woothemes-sensei') |
|
1327 | 1327 | ); |
1328 | 1328 | |
1329 | 1329 | $menu_items_obj = array(); |
1330 | - foreach ( $menu_items as $value => $title ) { |
|
1330 | + foreach ($menu_items as $value => $title) { |
|
1331 | 1331 | $menu_items_obj[$title] = new stdClass; |
1332 | - $menu_items_obj[$title]->object_id = esc_attr( $value ); |
|
1333 | - $menu_items_obj[$title]->title = esc_attr( $title ); |
|
1334 | - $menu_items_obj[$title]->url = esc_attr( $value ); |
|
1335 | - $menu_items_obj[$title]->description = 'description'; |
|
1332 | + $menu_items_obj[$title]->object_id = esc_attr($value); |
|
1333 | + $menu_items_obj[$title]->title = esc_attr($title); |
|
1334 | + $menu_items_obj[$title]->url = esc_attr($value); |
|
1335 | + $menu_items_obj[$title]->description = 'description'; |
|
1336 | 1336 | $menu_items_obj[$title]->db_id = 0; |
1337 | 1337 | $menu_items_obj[$title]->object = 'sensei'; |
1338 | - $menu_items_obj[$title]->menu_item_parent = 0; |
|
1339 | - $menu_items_obj[$title]->type = 'custom'; |
|
1338 | + $menu_items_obj[$title]->menu_item_parent = 0; |
|
1339 | + $menu_items_obj[$title]->type = 'custom'; |
|
1340 | 1340 | $menu_items_obj[$title]->target = ''; |
1341 | - $menu_items_obj[$title]->attr_title = ''; |
|
1342 | - $menu_items_obj[$title]->classes = array(); |
|
1343 | - $menu_items_obj[$title]->xfn = ''; |
|
1341 | + $menu_items_obj[$title]->attr_title = ''; |
|
1342 | + $menu_items_obj[$title]->classes = array(); |
|
1343 | + $menu_items_obj[$title]->xfn = ''; |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | - $walker = new Walker_Nav_Menu_Checklist( array() ); |
|
1346 | + $walker = new Walker_Nav_Menu_Checklist(array()); |
|
1347 | 1347 | ?> |
1348 | 1348 | |
1349 | 1349 | <div id="sensei-links" class="senseidiv taxonomydiv"> |
1350 | 1350 | <div id="tabs-panel-sensei-links-all" class="tabs-panel tabs-panel-view-all tabs-panel-active"> |
1351 | 1351 | |
1352 | 1352 | <ul id="sensei-linkschecklist" class="list:sensei-links categorychecklist form-no-clear"> |
1353 | - <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items_obj ), 0, (object)array( 'walker' => $walker ) ); ?> |
|
1353 | + <?php echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $menu_items_obj), 0, (object) array('walker' => $walker)); ?> |
|
1354 | 1354 | </ul> |
1355 | 1355 | |
1356 | 1356 | </div> |
1357 | 1357 | <p class="button-controls"> |
1358 | 1358 | <span class="add-to-menu"> |
1359 | - <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'woothemes-sensei' ); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" /> |
|
1359 | + <input type="submit"<?php disabled($nav_menu_selected_id, 0); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu', 'woothemes-sensei'); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" /> |
|
1360 | 1360 | <span class="spinner"></span> |
1361 | 1361 | </span> |
1362 | 1362 | </p> |
@@ -1372,17 +1372,17 @@ discard block |
||
1372 | 1372 | */ |
1373 | 1373 | public function theme_compatibility_notices() { |
1374 | 1374 | |
1375 | - if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1376 | - switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1377 | - case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break; |
|
1378 | - case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break; |
|
1375 | + if (isset($_GET['sensei_hide_notice'])) { |
|
1376 | + switch (esc_attr($_GET['sensei_hide_notice'])) { |
|
1377 | + case 'menu_settings': add_user_meta(get_current_user_id(), 'sensei_hide_menu_settings_notice', true); break; |
|
1378 | + case 'theme_check': add_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); break; |
|
1379 | 1379 | } |
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | // white list templates that are already support by default and do not show notice for them |
1383 | - $template = get_option( 'template' ); |
|
1383 | + $template = get_option('template'); |
|
1384 | 1384 | |
1385 | - $white_list = array( 'twentyeleven', |
|
1385 | + $white_list = array('twentyeleven', |
|
1386 | 1386 | 'twentytwelve', |
1387 | 1387 | 'twentyfourteen', |
1388 | 1388 | 'twentyfifteen', |
@@ -1390,43 +1390,43 @@ discard block |
||
1390 | 1390 | 'storefront', |
1391 | 1391 | ); |
1392 | 1392 | |
1393 | - if ( in_array( $template, $white_list ) ) { |
|
1393 | + if (in_array($template, $white_list)) { |
|
1394 | 1394 | |
1395 | 1395 | return; |
1396 | 1396 | |
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | // don't show the notice if the user chose to hide it |
1400 | - $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1401 | - if( $hide_theme_check_notice ) { |
|
1400 | + $hide_theme_check_notice = get_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); |
|
1401 | + if ($hide_theme_check_notice) { |
|
1402 | 1402 | |
1403 | 1403 | return; |
1404 | 1404 | |
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | // show the notice for themes not supporting sensei |
1408 | - if ( ! current_theme_supports( 'sensei' ) ) { |
|
1408 | + if ( ! current_theme_supports('sensei')) { |
|
1409 | 1409 | ?> |
1410 | 1410 | |
1411 | 1411 | <div id="message" class="error sensei-message sensei-connect"> |
1412 | 1412 | <p> |
1413 | 1413 | <strong> |
1414 | 1414 | |
1415 | - <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei' ); ?> |
|
1415 | + <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei'); ?> |
|
1416 | 1416 | |
1417 | 1417 | </strong> – |
1418 | 1418 | |
1419 | - <?php _e( 'if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei' ); ?> |
|
1419 | + <?php _e('if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei'); ?> |
|
1420 | 1420 | |
1421 | - <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php _e( 'Sensei theme', 'woothemes-sensei' ) ?> </a> |
|
1421 | + <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php _e('Sensei theme', 'woothemes-sensei') ?> </a> |
|
1422 | 1422 | |
1423 | 1423 | :) |
1424 | 1424 | |
1425 | 1425 | </p> |
1426 | 1426 | <p class="submit"> |
1427 | - <a href="<?php echo esc_url( apply_filters( 'sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary"> |
|
1427 | + <a href="<?php echo esc_url(apply_filters('sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility')); ?>" class="button-primary"> |
|
1428 | 1428 | |
1429 | - <?php _e( 'Theme Integration Guide', 'woothemes-sensei' ); ?></a> <a class="skip button" href="<?php echo esc_url( add_query_arg( 'sensei_hide_notice', 'theme_check' ) ); ?>"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?> |
|
1429 | + <?php _e('Theme Integration Guide', 'woothemes-sensei'); ?></a> <a class="skip button" href="<?php echo esc_url(add_query_arg('sensei_hide_notice', 'theme_check')); ?>"><?php _e('Hide this notice', 'woothemes-sensei'); ?> |
|
1430 | 1430 | |
1431 | 1431 | </a> |
1432 | 1432 | </p> |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | wp_get_current_user(); |
1445 | 1445 | $user_id = $current_user->ID; |
1446 | 1446 | |
1447 | - delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' ); |
|
1447 | + delete_user_meta($user_id, 'sensei_hide_theme_check_notice'); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1454,8 +1454,8 @@ discard block |
||
1454 | 1454 | * @param bool $prevent_access |
1455 | 1455 | * @return bool |
1456 | 1456 | */ |
1457 | - public function admin_access( $prevent_access ) { |
|
1458 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
1457 | + public function admin_access($prevent_access) { |
|
1458 | + if (current_user_can('manage_sensei_grades')) { |
|
1459 | 1459 | return false; |
1460 | 1460 | } |
1461 | 1461 | |
@@ -1470,12 +1470,12 @@ discard block |
||
1470 | 1470 | * |
1471 | 1471 | * @since 1.8.7 |
1472 | 1472 | */ |
1473 | - public static function install_pages(){ |
|
1473 | + public static function install_pages() { |
|
1474 | 1474 | |
1475 | 1475 | // only fire on the settings page |
1476 | - if( ! isset( $_GET['page'] ) |
|
1476 | + if ( ! isset($_GET['page']) |
|
1477 | 1477 | || 'woothemes-sensei-settings' != $_GET['page'] |
1478 | - || 1 == get_option('skip_install_sensei_pages') ){ |
|
1478 | + || 1 == get_option('skip_install_sensei_pages')) { |
|
1479 | 1479 | |
1480 | 1480 | return; |
1481 | 1481 | |
@@ -1505,13 +1505,13 @@ discard block |
||
1505 | 1505 | if ($install_complete) { |
1506 | 1506 | |
1507 | 1507 | // Flush rules after install |
1508 | - flush_rewrite_rules( true ); |
|
1508 | + flush_rewrite_rules(true); |
|
1509 | 1509 | |
1510 | 1510 | // Set installed option |
1511 | 1511 | update_option('sensei_installed', 0); |
1512 | 1512 | |
1513 | - $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1514 | - wp_redirect( $complete_url ); |
|
1513 | + $complete_url = add_query_arg('sensei_install_complete', 'true', $settings_url); |
|
1514 | + wp_redirect($complete_url); |
|
1515 | 1515 | |
1516 | 1516 | } |
1517 | 1517 | |
@@ -1524,4 +1524,4 @@ discard block |
||
1524 | 1524 | * for backward compatibility |
1525 | 1525 | * @since 1.9.0 |
1526 | 1526 | */ |
1527 | -class WooThemes_Sensei_Admin extends Sensei_Admin{ } |
|
1527 | +class WooThemes_Sensei_Admin extends Sensei_Admin { } |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | /** |
4 | 6 | * The Template for displaying the my course page data. |
5 | 7 | * |
@@ -14,19 +14,19 @@ |
||
14 | 14 | |
15 | 15 | <?php |
16 | 16 | |
17 | - /** |
|
18 | - * Get the question data with the current quiz id |
|
19 | - * All data is loaded in this array to keep the template clean. |
|
20 | - */ |
|
21 | - $question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() ); |
|
17 | + /** |
|
18 | + * Get the question data with the current quiz id |
|
19 | + * All data is loaded in this array to keep the template clean. |
|
20 | + */ |
|
21 | + $question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() ); |
|
22 | 22 | |
23 | 23 | ?> |
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - Sensei_Utils::sensei_text_editor( $question_data[ 'user_answer_entry' ] , |
|
28 | - 'textquestion' . $question_data[ 'ID' ] , |
|
29 | - 'sensei_question[' . $question_data[ 'ID' ] . ']' ); |
|
27 | + Sensei_Utils::sensei_text_editor( $question_data[ 'user_answer_entry' ] , |
|
28 | + 'textquestion' . $question_data[ 'ID' ] , |
|
29 | + 'sensei_question[' . $question_data[ 'ID' ] . ']' ); |
|
30 | 30 | |
31 | 31 | ?> |
32 | 32 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | /** |
4 | 4 | * The Template for displaying Multi Line Questions. |
5 | 5 | * |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | * Get the question data with the current quiz id |
19 | 19 | * All data is loaded in this array to keep the template clean. |
20 | 20 | */ |
21 | - $question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() ); |
|
21 | + $question_data = WooThemes_Sensei_Question::get_template_data(sensei_get_the_question_id(), get_the_ID()); |
|
22 | 22 | |
23 | 23 | ?> |
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - Sensei_Utils::sensei_text_editor( $question_data[ 'user_answer_entry' ] , |
|
28 | - 'textquestion' . $question_data[ 'ID' ] , |
|
29 | - 'sensei_question[' . $question_data[ 'ID' ] . ']' ); |
|
27 | + Sensei_Utils::sensei_text_editor($question_data['user_answer_entry'], |
|
28 | + 'textquestion'.$question_data['ID'], |
|
29 | + 'sensei_question['.$question_data['ID'].']'); |
|
30 | 30 | |
31 | 31 | ?> |
32 | 32 |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | /** |
4 | 6 | * The Template for displaying the my course page data. |
5 | 7 | * |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | <?php if ( is_user_logged_in() ): ?> |
18 | 18 | |
19 | 19 | <?php |
20 | - /** |
|
21 | - * Fires inside course-results/lessons.php after the |
|
22 | - * is uer logged check, just above the lessons header. |
|
23 | - * @since 1.4.0 |
|
24 | - */ |
|
25 | - do_action( 'sensei_course_results_before_lessons', $course->ID ); |
|
26 | - ?> |
|
20 | + /** |
|
21 | + * Fires inside course-results/lessons.php after the |
|
22 | + * is uer logged check, just above the lessons header. |
|
23 | + * @since 1.4.0 |
|
24 | + */ |
|
25 | + do_action( 'sensei_course_results_before_lessons', $course->ID ); |
|
26 | + ?> |
|
27 | 27 | |
28 | 28 | <header> |
29 | 29 | |
@@ -36,33 +36,33 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | $displayed_lessons = array(); |
39 | - $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) ); |
|
39 | + $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) ); |
|
40 | 40 | |
41 | - // List modules with lessons |
|
42 | - foreach( $modules as $module ) { |
|
41 | + // List modules with lessons |
|
42 | + foreach( $modules as $module ) { |
|
43 | 43 | |
44 | - $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id ); |
|
45 | - $lessons = $lessons_query->get_posts(); |
|
44 | + $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id ); |
|
45 | + $lessons = $lessons_query->get_posts(); |
|
46 | 46 | |
47 | - if( count( $lessons ) > 0 ) { ?> |
|
47 | + if( count( $lessons ) > 0 ) { ?> |
|
48 | 48 | |
49 | 49 | <h3> <?php echo $module->name; ?></h3> |
50 | 50 | |
51 | 51 | <?php |
52 | - $count = 0; |
|
53 | - foreach( $lessons as $lesson ) { |
|
54 | - |
|
55 | - $lesson_grade = 'n/a'; |
|
56 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
57 | - if ( $has_questions ) { |
|
58 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() ); |
|
59 | - // Get user quiz grade |
|
60 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
61 | - if ( $lesson_grade ) { |
|
62 | - $lesson_grade .= '%'; |
|
63 | - } |
|
64 | - } |
|
65 | - ?> |
|
52 | + $count = 0; |
|
53 | + foreach( $lessons as $lesson ) { |
|
54 | + |
|
55 | + $lesson_grade = 'n/a'; |
|
56 | + $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
57 | + if ( $has_questions ) { |
|
58 | + $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() ); |
|
59 | + // Get user quiz grade |
|
60 | + $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
61 | + if ( $lesson_grade ) { |
|
62 | + $lesson_grade .= '%'; |
|
63 | + } |
|
64 | + } |
|
65 | + ?> |
|
66 | 66 | <h2> |
67 | 67 | |
68 | 68 | <a href="<?php esc_url_raw( get_permalink( $lesson->ID ) ); ?>" |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | |
81 | 81 | <?php |
82 | 82 | |
83 | - }// end for each |
|
83 | + }// end for each |
|
84 | 84 | |
85 | - }// end if count lesson |
|
85 | + }// end if count lesson |
|
86 | 86 | |
87 | - } // end for each module |
|
88 | - ?> |
|
87 | + } // end for each module |
|
88 | + ?> |
|
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - $lessons = Sensei()->modules->get_none_module_lessons( $course->ID ); |
|
93 | - if( 0 < count( $lessons ) ): ?> |
|
92 | + $lessons = Sensei()->modules->get_none_module_lessons( $course->ID ); |
|
93 | + if( 0 < count( $lessons ) ): ?> |
|
94 | 94 | |
95 | 95 | <h3> |
96 | 96 | |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | <?php foreach ( $lessons as $lesson ): ?> |
102 | 102 | |
103 | 103 | <?php |
104 | - $lesson_grade = 'n/a'; |
|
105 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
106 | - if ( $has_questions ) { |
|
107 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id()); |
|
108 | - // Get user quiz grade |
|
109 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
110 | - if ( $lesson_grade ) { |
|
111 | - $lesson_grade .= '%'; |
|
112 | - } |
|
113 | - } |
|
114 | - ?> |
|
104 | + $lesson_grade = 'n/a'; |
|
105 | + $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
106 | + if ( $has_questions ) { |
|
107 | + $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id()); |
|
108 | + // Get user quiz grade |
|
109 | + $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
110 | + if ( $lesson_grade ) { |
|
111 | + $lesson_grade .= '%'; |
|
112 | + } |
|
113 | + } |
|
114 | + ?> |
|
115 | 115 | |
116 | 116 | <h2> |
117 | 117 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | |
138 | 138 | <?php |
139 | 139 | |
140 | - $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() ); |
|
141 | - echo $course_user_grade . '%'; |
|
140 | + $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() ); |
|
141 | + echo $course_user_grade . '%'; |
|
142 | 142 | |
143 | - ?> |
|
143 | + ?> |
|
144 | 144 | |
145 | 145 | </span> |
146 | 146 | |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | </article> |
150 | 150 | |
151 | 151 | <?php |
152 | - /** |
|
153 | - * Fires inside course-results/lessons.php after the |
|
154 | - * is uer logged check, at the bottom of all lessons. |
|
155 | - * |
|
156 | - * @since 1.4.0 |
|
157 | - */ |
|
152 | + /** |
|
153 | + * Fires inside course-results/lessons.php after the |
|
154 | + * is uer logged check, at the bottom of all lessons. |
|
155 | + * |
|
156 | + * @since 1.4.0 |
|
157 | + */ |
|
158 | 158 | do_action( 'sensei_course_results_after_lessons', $course->ID ); |
159 | - ?> |
|
159 | + ?> |
|
160 | 160 | |
161 | 161 | <?php endif; //user logged in ?> |
162 | 162 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | /** |
4 | 4 | * The Template for displaying all course lessons on the course results page. |
5 | 5 | * |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | global $course; |
15 | 15 | ?> |
16 | 16 | |
17 | -<?php if ( is_user_logged_in() ): ?> |
|
17 | +<?php if (is_user_logged_in()): ?> |
|
18 | 18 | |
19 | 19 | <?php |
20 | 20 | /** |
@@ -22,53 +22,53 @@ discard block |
||
22 | 22 | * is uer logged check, just above the lessons header. |
23 | 23 | * @since 1.4.0 |
24 | 24 | */ |
25 | - do_action( 'sensei_course_results_before_lessons', $course->ID ); |
|
25 | + do_action('sensei_course_results_before_lessons', $course->ID); |
|
26 | 26 | ?> |
27 | 27 | |
28 | 28 | <header> |
29 | 29 | |
30 | - <h2> <?php _e( 'Lessons', 'woothemes-sensei' ); ?> </h2> |
|
30 | + <h2> <?php _e('Lessons', 'woothemes-sensei'); ?> </h2> |
|
31 | 31 | |
32 | 32 | </header> |
33 | 33 | |
34 | - <article class="<?php esc_attr_e( join( ' ', get_post_class( array( 'course', 'post' ), $course->ID ) ) ); ?> "> |
|
34 | + <article class="<?php esc_attr_e(join(' ', get_post_class(array('course', 'post'), $course->ID))); ?> "> |
|
35 | 35 | |
36 | 36 | <?php |
37 | 37 | |
38 | 38 | $displayed_lessons = array(); |
39 | - $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) ); |
|
39 | + $modules = Sensei()->modules->get_course_modules(intval($course->ID)); |
|
40 | 40 | |
41 | 41 | // List modules with lessons |
42 | - foreach( $modules as $module ) { |
|
42 | + foreach ($modules as $module) { |
|
43 | 43 | |
44 | - $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id ); |
|
44 | + $lessons_query = Sensei()->modules->get_lessons_query($course->ID, $module->term_id); |
|
45 | 45 | $lessons = $lessons_query->get_posts(); |
46 | 46 | |
47 | - if( count( $lessons ) > 0 ) { ?> |
|
47 | + if (count($lessons) > 0) { ?> |
|
48 | 48 | |
49 | 49 | <h3> <?php echo $module->name; ?></h3> |
50 | 50 | |
51 | 51 | <?php |
52 | 52 | $count = 0; |
53 | - foreach( $lessons as $lesson ) { |
|
53 | + foreach ($lessons as $lesson) { |
|
54 | 54 | |
55 | 55 | $lesson_grade = 'n/a'; |
56 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
57 | - if ( $has_questions ) { |
|
58 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() ); |
|
56 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
57 | + if ($has_questions) { |
|
58 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, get_current_user_id()); |
|
59 | 59 | // Get user quiz grade |
60 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
61 | - if ( $lesson_grade ) { |
|
60 | + $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
61 | + if ($lesson_grade) { |
|
62 | 62 | $lesson_grade .= '%'; |
63 | 63 | } |
64 | 64 | } |
65 | 65 | ?> |
66 | 66 | <h2> |
67 | 67 | |
68 | - <a href="<?php esc_url_raw( get_permalink( $lesson->ID ) ); ?>" |
|
69 | - title="<?php esc_attr_e( sprintf( __( 'Start %s', 'woothemes-sensei' ), $lesson->post_title ) ); ?>"> |
|
68 | + <a href="<?php esc_url_raw(get_permalink($lesson->ID)); ?>" |
|
69 | + title="<?php esc_attr_e(sprintf(__('Start %s', 'woothemes-sensei'), $lesson->post_title)); ?>"> |
|
70 | 70 | |
71 | - <?php esc_html_e( $lesson->post_title ); ?> |
|
71 | + <?php esc_html_e($lesson->post_title); ?> |
|
72 | 72 | |
73 | 73 | </a> |
74 | 74 | |
@@ -89,25 +89,25 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - $lessons = Sensei()->modules->get_none_module_lessons( $course->ID ); |
|
93 | - if( 0 < count( $lessons ) ): ?> |
|
92 | + $lessons = Sensei()->modules->get_none_module_lessons($course->ID); |
|
93 | + if (0 < count($lessons)): ?> |
|
94 | 94 | |
95 | 95 | <h3> |
96 | 96 | |
97 | - <?php _e( 'Other Lessons', 'woothemes-sensei' ); ?> |
|
97 | + <?php _e('Other Lessons', 'woothemes-sensei'); ?> |
|
98 | 98 | |
99 | 99 | </h3> |
100 | 100 | |
101 | - <?php foreach ( $lessons as $lesson ): ?> |
|
101 | + <?php foreach ($lessons as $lesson): ?> |
|
102 | 102 | |
103 | 103 | <?php |
104 | 104 | $lesson_grade = 'n/a'; |
105 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
106 | - if ( $has_questions ) { |
|
107 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id()); |
|
105 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
106 | + if ($has_questions) { |
|
107 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, get_current_user_id()); |
|
108 | 108 | // Get user quiz grade |
109 | - $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
110 | - if ( $lesson_grade ) { |
|
109 | + $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
110 | + if ($lesson_grade) { |
|
111 | 111 | $lesson_grade .= '%'; |
112 | 112 | } |
113 | 113 | } |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | |
116 | 116 | <h2> |
117 | 117 | |
118 | - <a href="<?php esc_url_raw( get_permalink( $lesson->ID ) ) ?>" title="<?php esc_attr_e( sprintf( __( 'Start %s', 'woothemes-sensei' ), $lesson->post_title ) ) ?>" > |
|
118 | + <a href="<?php esc_url_raw(get_permalink($lesson->ID)) ?>" title="<?php esc_attr_e(sprintf(__('Start %s', 'woothemes-sensei'), $lesson->post_title)) ?>" > |
|
119 | 119 | |
120 | - <?php esc_html_e( sprintf( __( '%s', 'woothemes-sensei' ), $lesson->post_title ) ); ?> |
|
120 | + <?php esc_html_e(sprintf(__('%s', 'woothemes-sensei'), $lesson->post_title)); ?> |
|
121 | 121 | |
122 | 122 | </a> |
123 | 123 | |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | |
133 | 133 | <h2 class="total-grade"> |
134 | 134 | |
135 | - <?php _e( 'Total Grade', 'woothemes-sensei' ); ?> |
|
135 | + <?php _e('Total Grade', 'woothemes-sensei'); ?> |
|
136 | 136 | <span class="lesson-grade"> |
137 | 137 | |
138 | 138 | <?php |
139 | 139 | |
140 | - $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() ); |
|
141 | - echo $course_user_grade . '%'; |
|
140 | + $course_user_grade = Sensei_Utils::sensei_course_user_grade($course->ID, get_current_user_id()); |
|
141 | + echo $course_user_grade.'%'; |
|
142 | 142 | |
143 | 143 | ?> |
144 | 144 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @since 1.4.0 |
157 | 157 | */ |
158 | - do_action( 'sensei_course_results_after_lessons', $course->ID ); |
|
158 | + do_action('sensei_course_results_after_lessons', $course->ID); |
|
159 | 159 | ?> |
160 | 160 | |
161 | 161 | <?php endif; //user logged in ?> |
162 | 162 | \ No newline at end of file |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// security check, don't load file outside WP |
|
3 | 6 | /** |
4 | 7 | * Sensei Autoloader Class |
5 | 8 | * |
@@ -817,7 +817,7 @@ |
||
817 | 817 | * @param int $user_id |
818 | 818 | * @param int $product_id |
819 | 819 | * |
820 | - * @return bool |
|
820 | + * @return boolean|null |
|
821 | 821 | */ |
822 | 822 | public static function has_customer_bought_product ( $user_id, $product_id ){ |
823 | 823 |
@@ -12,735 +12,735 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | Class Sensei_WC{ |
15 | - /** |
|
16 | - * Load the files needed for the woocommerce integration. |
|
17 | - * |
|
18 | - * @since 1.9.0 |
|
19 | - */ |
|
20 | - public static function load_woocommerce_integration_hooks(){ |
|
15 | + /** |
|
16 | + * Load the files needed for the woocommerce integration. |
|
17 | + * |
|
18 | + * @since 1.9.0 |
|
19 | + */ |
|
20 | + public static function load_woocommerce_integration_hooks(){ |
|
21 | 21 | |
22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
23 | 23 | |
24 | - } |
|
25 | - /** |
|
26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
27 | - * |
|
28 | - * @since 1.9.0 |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public static function is_woocommerce_active(){ |
|
24 | + } |
|
25 | + /** |
|
26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
27 | + * |
|
28 | + * @since 1.9.0 |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public static function is_woocommerce_active(){ |
|
32 | 32 | |
33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
35 | 35 | |
36 | - } // end is_woocommerce_active |
|
36 | + } // end is_woocommerce_active |
|
37 | 37 | |
38 | - /** |
|
39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
40 | - * |
|
41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
43 | - * |
|
44 | - * @since 1.9.0 |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function is_woocommerce_present(){ |
|
38 | + /** |
|
39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
40 | + * |
|
41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
43 | + * |
|
44 | + * @since 1.9.0 |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function is_woocommerce_present(){ |
|
49 | 49 | |
50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
51 | 51 | |
52 | - if ( is_multisite() ){ |
|
52 | + if ( is_multisite() ){ |
|
53 | 53 | |
54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
59 | 59 | |
60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
61 | 61 | |
62 | - }// end is_woocommerce_present |
|
62 | + }// end is_woocommerce_present |
|
63 | 63 | |
64 | - /** |
|
65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
66 | - * |
|
67 | - * If multiple exist we will return the latest order. |
|
68 | - * |
|
69 | - * @param $user_id |
|
70 | - * @param $course_id |
|
71 | - * @return array $user_course_orders |
|
72 | - */ |
|
73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
64 | + /** |
|
65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
66 | + * |
|
67 | + * If multiple exist we will return the latest order. |
|
68 | + * |
|
69 | + * @param $user_id |
|
70 | + * @param $course_id |
|
71 | + * @return array $user_course_orders |
|
72 | + */ |
|
73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
74 | 74 | |
75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
76 | 76 | |
77 | - $orders_query = new WP_Query( array( |
|
78 | - 'post_type' => 'shop_order', |
|
79 | - 'posts_per_page' => -1, |
|
80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
81 | - 'meta_key'=> '_customer_user', |
|
82 | - 'meta_value'=> $user_id, |
|
83 | - ) ); |
|
77 | + $orders_query = new WP_Query( array( |
|
78 | + 'post_type' => 'shop_order', |
|
79 | + 'posts_per_page' => -1, |
|
80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
81 | + 'meta_key'=> '_customer_user', |
|
82 | + 'meta_value'=> $user_id, |
|
83 | + ) ); |
|
84 | 84 | |
85 | - if( $orders_query->post_count == 0 ){ |
|
85 | + if( $orders_query->post_count == 0 ){ |
|
86 | 86 | |
87 | - return false; |
|
87 | + return false; |
|
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - foreach( $orders_query->get_posts() as $order ){ |
|
91 | + foreach( $orders_query->get_posts() as $order ){ |
|
92 | 92 | |
93 | - $order = new WC_Order( $order->ID ); |
|
94 | - $items = $order->get_items(); |
|
93 | + $order = new WC_Order( $order->ID ); |
|
94 | + $items = $order->get_items(); |
|
95 | 95 | |
96 | - $user_orders = array(); |
|
96 | + $user_orders = array(); |
|
97 | 97 | |
98 | - foreach( $items as $item ){ |
|
98 | + foreach( $items as $item ){ |
|
99 | 99 | |
100 | - // if the product id on the order and the one given to this function |
|
101 | - // this order has been placed by the given user on the given course. |
|
102 | - $product = wc_get_product( $item['product_id'] ); |
|
100 | + // if the product id on the order and the one given to this function |
|
101 | + // this order has been placed by the given user on the given course. |
|
102 | + $product = wc_get_product( $item['product_id'] ); |
|
103 | 103 | |
104 | - if ( $product->is_type( 'variable' )) { |
|
104 | + if ( $product->is_type( 'variable' )) { |
|
105 | 105 | |
106 | - $item_product_id = $item['variation_id']; |
|
106 | + $item_product_id = $item['variation_id']; |
|
107 | 107 | |
108 | - } else { |
|
108 | + } else { |
|
109 | 109 | |
110 | - $item_product_id = $item['product_id']; |
|
110 | + $item_product_id = $item['product_id']; |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - if( $course_product_id == $item_product_id ){ |
|
114 | + if( $course_product_id == $item_product_id ){ |
|
115 | 115 | |
116 | - return $order->id; |
|
116 | + return $order->id; |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - }//end for each order item |
|
121 | + }//end for each order item |
|
122 | 122 | |
123 | - } // end for each order |
|
123 | + } // end for each order |
|
124 | 124 | |
125 | - // if we reach this place we found no order |
|
126 | - return false; |
|
125 | + // if we reach this place we found no order |
|
126 | + return false; |
|
127 | 127 | |
128 | - } // end get_learner_course_active_order_ids |
|
128 | + } // end get_learner_course_active_order_ids |
|
129 | 129 | |
130 | - /** |
|
131 | - * Output WooCommerce specific course filters |
|
132 | - * Removing the paged argument |
|
133 | - * |
|
134 | - * @since 1.9.0 |
|
135 | - * @param $filter_links |
|
136 | - * @return mixed |
|
137 | - */ |
|
138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
130 | + /** |
|
131 | + * Output WooCommerce specific course filters |
|
132 | + * Removing the paged argument |
|
133 | + * |
|
134 | + * @since 1.9.0 |
|
135 | + * @param $filter_links |
|
136 | + * @return mixed |
|
137 | + */ |
|
138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
139 | 139 | |
140 | - $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
140 | + $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
141 | 141 | |
142 | - $free_courses = self::get_free_courses(); |
|
143 | - $paid_courses = self::get_paid_courses(); |
|
142 | + $free_courses = self::get_free_courses(); |
|
143 | + $paid_courses = self::get_paid_courses(); |
|
144 | 144 | |
145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
146 | - // do not show any WooCommerce filters if all courses are |
|
147 | - // free or if all courses are paid |
|
148 | - return $filter_links; |
|
145 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
146 | + // do not show any WooCommerce filters if all courses are |
|
147 | + // free or if all courses are paid |
|
148 | + return $filter_links; |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - $filter_links[] = array( 'id'=>'paid' , |
|
153 | - 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
154 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
155 | - ); |
|
152 | + $filter_links[] = array( 'id'=>'paid' , |
|
153 | + 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
|
154 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
155 | + ); |
|
156 | 156 | |
157 | - $filter_links[] = array( 'id'=>'free', |
|
158 | - 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
160 | - ); |
|
157 | + $filter_links[] = array( 'id'=>'free', |
|
158 | + 'url'=>add_query_arg('course_filter', 'free', $course_url), |
|
159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
160 | + ); |
|
161 | 161 | |
162 | - return $filter_links; |
|
162 | + return $filter_links; |
|
163 | 163 | |
164 | - }// end add_course_archive_wc_filter_links |
|
164 | + }// end add_course_archive_wc_filter_links |
|
165 | 165 | |
166 | - /** |
|
167 | - * Apply the free filter the the course query |
|
168 | - * getting all course with no products or products with zero price |
|
169 | - * |
|
170 | - * hooked into pre_get_posts |
|
171 | - * |
|
172 | - * @since 1.9.0 |
|
173 | - * @param WP_Query $query |
|
174 | - * @return WP_Query $query |
|
175 | - */ |
|
176 | - public static function course_archive_wc_filter_free( $query ){ |
|
166 | + /** |
|
167 | + * Apply the free filter the the course query |
|
168 | + * getting all course with no products or products with zero price |
|
169 | + * |
|
170 | + * hooked into pre_get_posts |
|
171 | + * |
|
172 | + * @since 1.9.0 |
|
173 | + * @param WP_Query $query |
|
174 | + * @return WP_Query $query |
|
175 | + */ |
|
176 | + public static function course_archive_wc_filter_free( $query ){ |
|
177 | 177 | |
178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
180 | 180 | |
181 | - // setup the course meta query |
|
182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
181 | + // setup the course meta query |
|
182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
183 | 183 | |
184 | - // manipulate the query to return free courses |
|
185 | - $query->set('meta_query', $meta_query ); |
|
184 | + // manipulate the query to return free courses |
|
185 | + $query->set('meta_query', $meta_query ); |
|
186 | 186 | |
187 | - // don't show any paid courses |
|
188 | - $courses = self::get_paid_courses(); |
|
189 | - $ids = array(); |
|
190 | - foreach( $courses as $course ){ |
|
191 | - $ids[] = $course->ID; |
|
192 | - } |
|
193 | - $query->set( 'post__not_in', $ids ); |
|
187 | + // don't show any paid courses |
|
188 | + $courses = self::get_paid_courses(); |
|
189 | + $ids = array(); |
|
190 | + foreach( $courses as $course ){ |
|
191 | + $ids[] = $course->ID; |
|
192 | + } |
|
193 | + $query->set( 'post__not_in', $ids ); |
|
194 | 194 | |
195 | - }// end if course_filter |
|
195 | + }// end if course_filter |
|
196 | 196 | |
197 | - return $query; |
|
197 | + return $query; |
|
198 | 198 | |
199 | - }// course_archive_wc_filter_free |
|
199 | + }// course_archive_wc_filter_free |
|
200 | 200 | |
201 | - /** |
|
202 | - * Apply the paid filter to the course query on the courses page |
|
203 | - * will include all course with a product attached with a price |
|
204 | - * more than 0 |
|
205 | - * |
|
206 | - * hooked into pre_get_posts |
|
207 | - * |
|
208 | - * @since 1.9.0 |
|
209 | - * @param WP_Query $query |
|
210 | - * @return WP_Query $query |
|
211 | - */ |
|
212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
201 | + /** |
|
202 | + * Apply the paid filter to the course query on the courses page |
|
203 | + * will include all course with a product attached with a price |
|
204 | + * more than 0 |
|
205 | + * |
|
206 | + * hooked into pre_get_posts |
|
207 | + * |
|
208 | + * @since 1.9.0 |
|
209 | + * @param WP_Query $query |
|
210 | + * @return WP_Query $query |
|
211 | + */ |
|
212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
213 | 213 | |
214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
216 | 216 | |
217 | - // setup the course meta query |
|
218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
217 | + // setup the course meta query |
|
218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
219 | 219 | |
220 | - // manipulate the query to return free courses |
|
221 | - $query->set('meta_query', $meta_query ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - return $query; |
|
226 | - |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Load the WooCommerce single product actions above |
|
231 | - * single courses if woocommerce is active allowing purchase |
|
232 | - * information and actions to be hooked from WooCommerce. |
|
233 | - */ |
|
234 | - public static function do_single_course_wc_single_product_action(){ |
|
235 | - |
|
236 | - /** |
|
237 | - * this hooks is documented within the WooCommerce plugin. |
|
238 | - */ |
|
239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
240 | - |
|
241 | - do_action( 'woocommerce_before_single_product' ); |
|
242 | - |
|
243 | - } // End If Statement |
|
244 | - |
|
245 | - }// end do_single_course_wc_single_product_action |
|
246 | - |
|
247 | - /** |
|
248 | - * Hooking into the single lesson page to alter the |
|
249 | - * user access permissions based on if they have purchased the |
|
250 | - * course the lesson belongs to. |
|
251 | - * |
|
252 | - * This function will only return false or the passed in user_access value. |
|
253 | - * It doesn't return true in order to avoid altering other options. |
|
254 | - * |
|
255 | - * @since 1.9.0 |
|
256 | - * |
|
257 | - * @param $can_user_view_lesson |
|
258 | - * @param $lesson_id |
|
259 | - * @param $user_id |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
263 | - |
|
264 | - // check if the course has a valid product attached to it |
|
265 | - // which the user should have purchased if they want to access |
|
266 | - // the current lesson |
|
267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
270 | - if( isset ($product) && is_object($product) ){ |
|
271 | - |
|
272 | - // valid product found |
|
273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
274 | - |
|
275 | - // product has a successful order so this user may access the content |
|
276 | - // this function may only return false or the default |
|
277 | - // returning true may override other negatives which we don't want |
|
278 | - if( ! $order_id ){ |
|
279 | - |
|
280 | - return false; |
|
281 | - |
|
282 | - } |
|
283 | - |
|
284 | - } |
|
285 | - |
|
286 | - // return the passed in value |
|
287 | - return $can_user_view_lesson; |
|
288 | - |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Add course link to order thank you and details pages. |
|
293 | - * |
|
294 | - * @since 1.4.5 |
|
295 | - * @access public |
|
296 | - * |
|
297 | - * @return void |
|
298 | - */ |
|
299 | - public static function course_link_from_order( ) { |
|
300 | - |
|
301 | - if( ! is_order_received_page() ){ |
|
302 | - return; |
|
303 | - } |
|
304 | - |
|
305 | - $order_id = get_query_var( 'order-received' ); |
|
220 | + // manipulate the query to return free courses |
|
221 | + $query->set('meta_query', $meta_query ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + return $query; |
|
226 | + |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Load the WooCommerce single product actions above |
|
231 | + * single courses if woocommerce is active allowing purchase |
|
232 | + * information and actions to be hooked from WooCommerce. |
|
233 | + */ |
|
234 | + public static function do_single_course_wc_single_product_action(){ |
|
235 | + |
|
236 | + /** |
|
237 | + * this hooks is documented within the WooCommerce plugin. |
|
238 | + */ |
|
239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
240 | + |
|
241 | + do_action( 'woocommerce_before_single_product' ); |
|
242 | + |
|
243 | + } // End If Statement |
|
244 | + |
|
245 | + }// end do_single_course_wc_single_product_action |
|
246 | + |
|
247 | + /** |
|
248 | + * Hooking into the single lesson page to alter the |
|
249 | + * user access permissions based on if they have purchased the |
|
250 | + * course the lesson belongs to. |
|
251 | + * |
|
252 | + * This function will only return false or the passed in user_access value. |
|
253 | + * It doesn't return true in order to avoid altering other options. |
|
254 | + * |
|
255 | + * @since 1.9.0 |
|
256 | + * |
|
257 | + * @param $can_user_view_lesson |
|
258 | + * @param $lesson_id |
|
259 | + * @param $user_id |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
263 | + |
|
264 | + // check if the course has a valid product attached to it |
|
265 | + // which the user should have purchased if they want to access |
|
266 | + // the current lesson |
|
267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
270 | + if( isset ($product) && is_object($product) ){ |
|
271 | + |
|
272 | + // valid product found |
|
273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
274 | + |
|
275 | + // product has a successful order so this user may access the content |
|
276 | + // this function may only return false or the default |
|
277 | + // returning true may override other negatives which we don't want |
|
278 | + if( ! $order_id ){ |
|
279 | + |
|
280 | + return false; |
|
281 | + |
|
282 | + } |
|
283 | + |
|
284 | + } |
|
285 | + |
|
286 | + // return the passed in value |
|
287 | + return $can_user_view_lesson; |
|
288 | + |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Add course link to order thank you and details pages. |
|
293 | + * |
|
294 | + * @since 1.4.5 |
|
295 | + * @access public |
|
296 | + * |
|
297 | + * @return void |
|
298 | + */ |
|
299 | + public static function course_link_from_order( ) { |
|
300 | + |
|
301 | + if( ! is_order_received_page() ){ |
|
302 | + return; |
|
303 | + } |
|
304 | + |
|
305 | + $order_id = get_query_var( 'order-received' ); |
|
306 | 306 | $order = new WC_Order( $order_id ); |
307 | 307 | |
308 | 308 | // exit early if not wc-completed or wc-processing |
309 | 309 | if( 'wc-completed' != $order->post_status |
310 | - && 'wc-processing' != $order->post_status ) { |
|
311 | - return; |
|
312 | - } |
|
310 | + && 'wc-processing' != $order->post_status ) { |
|
311 | + return; |
|
312 | + } |
|
313 | 313 | |
314 | - $course_links = array(); // store the for links for courses purchased |
|
314 | + $course_links = array(); // store the for links for courses purchased |
|
315 | 315 | foreach ( $order->get_items() as $item ) { |
316 | 316 | |
317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
318 | 318 | |
319 | - // If item has variation_id then its a variation of the product |
|
320 | - $item_id = $item['variation_id']; |
|
319 | + // If item has variation_id then its a variation of the product |
|
320 | + $item_id = $item['variation_id']; |
|
321 | 321 | |
322 | - } else { |
|
322 | + } else { |
|
323 | 323 | |
324 | - //If not its real product set its id to item_id |
|
325 | - $item_id = $item['product_id']; |
|
324 | + //If not its real product set its id to item_id |
|
325 | + $item_id = $item['product_id']; |
|
326 | 326 | |
327 | - } // End If Statement |
|
327 | + } // End If Statement |
|
328 | 328 | |
329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
330 | 330 | |
331 | - if( $user_id ) { |
|
331 | + if( $user_id ) { |
|
332 | 332 | |
333 | - // Get all courses for product |
|
334 | - $args = Sensei_Course::get_default_query_args(); |
|
335 | - $args['meta_query'] = array( array( |
|
336 | - 'key' => '_course_woocommerce_product', |
|
337 | - 'value' => $item_id |
|
338 | - ) ); |
|
339 | - $args['orderby'] = 'menu_order date'; |
|
340 | - $args['order'] = 'ASC'; |
|
333 | + // Get all courses for product |
|
334 | + $args = Sensei_Course::get_default_query_args(); |
|
335 | + $args['meta_query'] = array( array( |
|
336 | + 'key' => '_course_woocommerce_product', |
|
337 | + 'value' => $item_id |
|
338 | + ) ); |
|
339 | + $args['orderby'] = 'menu_order date'; |
|
340 | + $args['order'] = 'ASC'; |
|
341 | 341 | |
342 | - // loop through courses |
|
343 | - $courses = get_posts( $args ); |
|
344 | - if( $courses && count( $courses ) > 0 ) { |
|
342 | + // loop through courses |
|
343 | + $courses = get_posts( $args ); |
|
344 | + if( $courses && count( $courses ) > 0 ) { |
|
345 | 345 | |
346 | - foreach( $courses as $course ) { |
|
346 | + foreach( $courses as $course ) { |
|
347 | 347 | |
348 | - $title = $course->post_title; |
|
349 | - $permalink = get_permalink( $course->ID ); |
|
350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
348 | + $title = $course->post_title; |
|
349 | + $permalink = get_permalink( $course->ID ); |
|
350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
351 | 351 | |
352 | - } // end for each |
|
352 | + } // end for each |
|
353 | 353 | |
354 | - // close the message div |
|
354 | + // close the message div |
|
355 | 355 | |
356 | - }// end if $courses check |
|
357 | - } |
|
358 | - }// end loop through orders |
|
356 | + }// end if $courses check |
|
357 | + } |
|
358 | + }// end loop through orders |
|
359 | 359 | |
360 | - // add the courses to the WooCommerce notice |
|
361 | - if( ! empty( $course_links) ){ |
|
360 | + // add the courses to the WooCommerce notice |
|
361 | + if( ! empty( $course_links) ){ |
|
362 | 362 | |
363 | - $courses_html = _nx( |
|
364 | - 'You have purchased the following course:', |
|
365 | - 'You have purchased the following courses:', |
|
366 | - count( $course_links ), |
|
367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
368 | - ); |
|
363 | + $courses_html = _nx( |
|
364 | + 'You have purchased the following course:', |
|
365 | + 'You have purchased the following courses:', |
|
366 | + count( $course_links ), |
|
367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
368 | + ); |
|
369 | 369 | |
370 | - foreach( $course_links as $link ){ |
|
370 | + foreach( $course_links as $link ){ |
|
371 | 371 | |
372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
373 | 373 | |
374 | - } |
|
374 | + } |
|
375 | 375 | |
376 | - $courses_html .= ' </ul>'; |
|
376 | + $courses_html .= ' </ul>'; |
|
377 | 377 | |
378 | - wc_add_notice( $courses_html, 'success' ); |
|
379 | - } |
|
378 | + wc_add_notice( $courses_html, 'success' ); |
|
379 | + } |
|
380 | 380 | |
381 | 381 | } // end course_link_order_form |
382 | 382 | |
383 | - /** |
|
384 | - * Show the message that a user should complete |
|
385 | - * their purchase if the course is in the cart |
|
386 | - * |
|
387 | - * This should be used within the course loop or single course page |
|
388 | - * |
|
389 | - * @since 1.9.0 |
|
390 | - */ |
|
391 | - public static function course_in_cart_message(){ |
|
383 | + /** |
|
384 | + * Show the message that a user should complete |
|
385 | + * their purchase if the course is in the cart |
|
386 | + * |
|
387 | + * This should be used within the course loop or single course page |
|
388 | + * |
|
389 | + * @since 1.9.0 |
|
390 | + */ |
|
391 | + public static function course_in_cart_message(){ |
|
392 | 392 | |
393 | - global $post; |
|
393 | + global $post; |
|
394 | 394 | |
395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
396 | 396 | |
397 | 397 | <div class="sensei-message info">' |
398 | 398 | <?php |
399 | 399 | |
400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
403 | 403 | |
404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
404 | + sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
405 | 405 | |
406 | - ?> |
|
406 | + ?> |
|
407 | 407 | </div> |
408 | 408 | <?php } |
409 | 409 | |
410 | - } // End sensei_woocommerce_in_cart_message() |
|
410 | + } // End sensei_woocommerce_in_cart_message() |
|
411 | 411 | |
412 | - /** |
|
413 | - * Checks the cart to see if a course is in the cart. |
|
414 | - * |
|
415 | - * @param $course_id |
|
416 | - * @return bool |
|
417 | - */ |
|
418 | - public static function is_course_in_cart( $course_id ){ |
|
419 | - |
|
420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
422 | - |
|
423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
424 | - |
|
425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
426 | - |
|
427 | - return true; |
|
428 | - |
|
429 | - } |
|
430 | - |
|
431 | - } |
|
432 | - |
|
433 | - return false; |
|
434 | - |
|
435 | - }// is_course_in_cart |
|
436 | - |
|
437 | - /** |
|
438 | - * Check the cart to see if the product is in the cart |
|
439 | - * |
|
440 | - * @param $product_id |
|
441 | - * @return bool |
|
442 | - */ |
|
443 | - public static function is_product_in_cart( $product_id ){ |
|
444 | - |
|
445 | - if ( 0 < $product_id ) { |
|
446 | - |
|
447 | - $product = wc_get_product( $product_id ); |
|
448 | - |
|
449 | - $parent_id = ''; |
|
450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
451 | - $wc_product_id = $product->parent->id; |
|
452 | - } |
|
453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
454 | - |
|
455 | - $cart_product = $values['data']; |
|
456 | - if( $product_id == $cart_product->id ) { |
|
457 | - |
|
458 | - return true; |
|
459 | - |
|
460 | - } |
|
461 | - |
|
462 | - } |
|
463 | - } // End If Statement |
|
464 | - |
|
465 | - return false; |
|
466 | - |
|
467 | - } // end is_product_in_car |
|
468 | - |
|
469 | - /** |
|
470 | - * Get all free WooCommerce products |
|
471 | - * |
|
472 | - * @since 1.9.0 |
|
473 | - * |
|
474 | - * @return array $free_products{ |
|
475 | - * @type int $wp_post_id |
|
476 | - * } |
|
477 | - */ |
|
478 | - public static function get_free_product_ids(){ |
|
479 | - |
|
480 | - return get_posts( array( |
|
481 | - 'post_type' => 'product', |
|
482 | - 'posts_per_page' => '1000', |
|
483 | - 'fields' => 'ids', |
|
484 | - 'meta_query'=> array( |
|
485 | - 'relation' => 'OR', |
|
486 | - array( |
|
487 | - 'key'=> '_regular_price', |
|
488 | - 'value' => 0, |
|
489 | - ), |
|
490 | - array( |
|
491 | - 'key'=> '_sale_price', |
|
492 | - 'value' => 0, |
|
493 | - ), |
|
494 | - ), |
|
495 | - )); |
|
496 | - |
|
497 | - }// end get free product query |
|
498 | - |
|
499 | - /** |
|
500 | - * The metat query for courses that are free |
|
501 | - * |
|
502 | - * @since 1.9.0 |
|
503 | - * @return array $wp_meta_query_param |
|
504 | - */ |
|
505 | - public static function get_free_courses_meta_query_args(){ |
|
506 | - |
|
507 | - return array( |
|
508 | - 'relation' => 'OR', |
|
509 | - array( |
|
510 | - 'key' => '_course_woocommerce_product', |
|
511 | - 'value' => '-', |
|
512 | - 'compare' => '=', |
|
513 | - ), |
|
514 | - array( |
|
515 | - 'key' => '_course_woocommerce_product', |
|
516 | - 'value' => self::get_free_product_ids(), |
|
517 | - 'compare' => 'IN', |
|
518 | - ), |
|
519 | - ); |
|
520 | - |
|
521 | - }// get_free_courses_meta_query |
|
522 | - |
|
523 | - /** |
|
524 | - * The metat query for courses that are free |
|
525 | - * |
|
526 | - * @since 1.9.0 |
|
527 | - * @return array $wp_query_meta_query_args_param |
|
528 | - */ |
|
529 | - public static function get_paid_courses_meta_query_args(){ |
|
530 | - |
|
531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
532 | - |
|
533 | - return array( |
|
534 | - array( |
|
535 | - 'key' => '_course_woocommerce_product', |
|
536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
537 | - // query |
|
538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
539 | - 'compare' => 'IN', |
|
540 | - ), |
|
541 | - ); |
|
542 | - |
|
543 | - }// get_free_courses_meta_query |
|
544 | - |
|
545 | - /** |
|
546 | - * The WordPress Query args |
|
547 | - * for paid products on sale |
|
548 | - * |
|
549 | - * @since 1.9.0 |
|
550 | - * @return array $product_query_args |
|
551 | - */ |
|
552 | - public static function get_paid_products_on_sale_query_args(){ |
|
553 | - |
|
554 | - $args = array( |
|
555 | - 'post_type' => 'product', |
|
556 | - 'posts_per_page' => 1000, |
|
557 | - 'orderby' => 'date', |
|
558 | - 'order' => 'DESC', |
|
559 | - 'suppress_filters' => 0 |
|
560 | - ); |
|
561 | - |
|
562 | - $args[ 'fields' ] = 'ids'; |
|
563 | - |
|
564 | - $args[ 'meta_query' ] = array( |
|
565 | - 'relation' => 'AND', |
|
566 | - array( |
|
567 | - 'key'=> '_regular_price', |
|
568 | - 'compare' => '>', |
|
569 | - 'value' => 0, |
|
570 | - ), |
|
571 | - array( |
|
572 | - 'key'=> '_sale_price', |
|
573 | - 'compare' => '>', |
|
574 | - 'value' => 0, |
|
575 | - ), |
|
576 | - ); |
|
577 | - |
|
578 | - return $args; |
|
579 | - |
|
580 | - } // get_paid_products_on_sale_query_args |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Return the WordPress query args for |
|
585 | - * products not on sale but that is not a free |
|
586 | - * |
|
587 | - * @since 1.9.0 |
|
588 | - * |
|
589 | - * @return array |
|
590 | - */ |
|
591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
592 | - |
|
593 | - $args = array( |
|
594 | - 'post_type' => 'product', |
|
595 | - 'posts_per_page' => 1000, |
|
596 | - 'orderby' => 'date', |
|
597 | - 'order' => 'DESC', |
|
598 | - 'suppress_filters' => 0 |
|
599 | - ); |
|
600 | - |
|
601 | - $args[ 'fields' ] = 'ids'; |
|
602 | - $args[ 'meta_query' ] = array( |
|
603 | - 'relation' => 'AND', |
|
604 | - array( |
|
605 | - 'key'=> '_regular_price', |
|
606 | - 'compare' => '>', |
|
607 | - 'value' => 0, |
|
608 | - ), |
|
609 | - array( |
|
610 | - 'key'=> '_sale_price', |
|
611 | - 'compare' => '=', |
|
612 | - 'value' => '', |
|
613 | - ), |
|
614 | - ); |
|
615 | - |
|
616 | - return $args; |
|
617 | - |
|
618 | - |
|
619 | - } // get_paid_courses_meta_query |
|
620 | - |
|
621 | - /** |
|
622 | - * Get all WooCommerce non-free product id's |
|
623 | - * |
|
624 | - * @since 1.9.0 |
|
625 | - * |
|
626 | - * @return array $woocommerce_paid_product_ids |
|
627 | - */ |
|
628 | - public static function get_paid_product_ids(){ |
|
629 | - |
|
630 | - // get all the paid WooCommerce products that has regular |
|
631 | - // and sale price greater than 0 |
|
632 | - // will be used later to check for course with the id as meta |
|
633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
634 | - |
|
635 | - // get all the paid WooCommerce products that has regular price |
|
636 | - // greater than 0 without a sale price |
|
637 | - // will be used later to check for course with the id as meta |
|
638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
639 | - |
|
640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
641 | - // sale but regular price greater than zero |
|
642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
643 | - |
|
644 | - // if |
|
645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
646 | - return array( ); |
|
647 | - } |
|
648 | - return $woocommerce_paid_product_ids; |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Get all free courses. |
|
654 | - * |
|
655 | - * This course that have a WC product attached |
|
656 | - * that has a price or sale price of zero and |
|
657 | - * other courses with no WooCommerce products |
|
658 | - * attached. |
|
659 | - * |
|
660 | - * @since 1.9.0 |
|
661 | - * |
|
662 | - * @return array |
|
663 | - */ |
|
664 | - public static function get_free_courses(){ |
|
665 | - |
|
666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
668 | - |
|
669 | - // don't show any paid courses |
|
670 | - $courses = self::get_paid_courses(); |
|
671 | - $ids = array(); |
|
672 | - foreach( $courses as $course ){ |
|
673 | - $ids[] = $course->ID; |
|
674 | - } |
|
675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
676 | - |
|
677 | - return get_posts( $free_course_query_args ); |
|
678 | - |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Return all products that are not free |
|
683 | - * |
|
684 | - * @since 1.9.0 |
|
685 | - * @return array |
|
686 | - */ |
|
687 | - public static function get_paid_courses(){ |
|
688 | - |
|
689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
690 | - |
|
691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
692 | - |
|
693 | - return get_posts( $paid_course_query_args ); |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Show the WooCommerce add to cart button for the current course |
|
698 | - * |
|
699 | - * The function will only show the button if |
|
700 | - * 1- the user can buy the course |
|
701 | - * 2- if they have completed their pre-requisite |
|
702 | - * 3- if the course has a valid product attached |
|
703 | - * |
|
704 | - * @since 1.9.0 |
|
705 | - * @param int $course_id |
|
706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
707 | - */ |
|
708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
709 | - |
|
710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
711 | - return ''; |
|
712 | - } |
|
713 | - |
|
714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
715 | - |
|
716 | - // Check if customer purchased the product |
|
717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | - || empty( $wc_post_id ) ) { |
|
719 | - |
|
720 | - return ''; |
|
721 | - |
|
722 | - } |
|
723 | - |
|
724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
725 | - // Get the product |
|
726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
727 | - |
|
728 | - // do not show the button for invalid products, non purchasable products, out |
|
729 | - // of stock product or if course is already in cart |
|
730 | - if ( ! isset ( $product ) |
|
731 | - || ! is_object( $product ) |
|
732 | - || ! $product->is_purchasable() |
|
733 | - || ! $product->is_in_stock() |
|
734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
735 | - |
|
736 | - return ''; |
|
737 | - |
|
738 | - } |
|
739 | - |
|
740 | - // |
|
741 | - // button output: |
|
742 | - // |
|
743 | - ?> |
|
412 | + /** |
|
413 | + * Checks the cart to see if a course is in the cart. |
|
414 | + * |
|
415 | + * @param $course_id |
|
416 | + * @return bool |
|
417 | + */ |
|
418 | + public static function is_course_in_cart( $course_id ){ |
|
419 | + |
|
420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
422 | + |
|
423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
424 | + |
|
425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
426 | + |
|
427 | + return true; |
|
428 | + |
|
429 | + } |
|
430 | + |
|
431 | + } |
|
432 | + |
|
433 | + return false; |
|
434 | + |
|
435 | + }// is_course_in_cart |
|
436 | + |
|
437 | + /** |
|
438 | + * Check the cart to see if the product is in the cart |
|
439 | + * |
|
440 | + * @param $product_id |
|
441 | + * @return bool |
|
442 | + */ |
|
443 | + public static function is_product_in_cart( $product_id ){ |
|
444 | + |
|
445 | + if ( 0 < $product_id ) { |
|
446 | + |
|
447 | + $product = wc_get_product( $product_id ); |
|
448 | + |
|
449 | + $parent_id = ''; |
|
450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
451 | + $wc_product_id = $product->parent->id; |
|
452 | + } |
|
453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
454 | + |
|
455 | + $cart_product = $values['data']; |
|
456 | + if( $product_id == $cart_product->id ) { |
|
457 | + |
|
458 | + return true; |
|
459 | + |
|
460 | + } |
|
461 | + |
|
462 | + } |
|
463 | + } // End If Statement |
|
464 | + |
|
465 | + return false; |
|
466 | + |
|
467 | + } // end is_product_in_car |
|
468 | + |
|
469 | + /** |
|
470 | + * Get all free WooCommerce products |
|
471 | + * |
|
472 | + * @since 1.9.0 |
|
473 | + * |
|
474 | + * @return array $free_products{ |
|
475 | + * @type int $wp_post_id |
|
476 | + * } |
|
477 | + */ |
|
478 | + public static function get_free_product_ids(){ |
|
479 | + |
|
480 | + return get_posts( array( |
|
481 | + 'post_type' => 'product', |
|
482 | + 'posts_per_page' => '1000', |
|
483 | + 'fields' => 'ids', |
|
484 | + 'meta_query'=> array( |
|
485 | + 'relation' => 'OR', |
|
486 | + array( |
|
487 | + 'key'=> '_regular_price', |
|
488 | + 'value' => 0, |
|
489 | + ), |
|
490 | + array( |
|
491 | + 'key'=> '_sale_price', |
|
492 | + 'value' => 0, |
|
493 | + ), |
|
494 | + ), |
|
495 | + )); |
|
496 | + |
|
497 | + }// end get free product query |
|
498 | + |
|
499 | + /** |
|
500 | + * The metat query for courses that are free |
|
501 | + * |
|
502 | + * @since 1.9.0 |
|
503 | + * @return array $wp_meta_query_param |
|
504 | + */ |
|
505 | + public static function get_free_courses_meta_query_args(){ |
|
506 | + |
|
507 | + return array( |
|
508 | + 'relation' => 'OR', |
|
509 | + array( |
|
510 | + 'key' => '_course_woocommerce_product', |
|
511 | + 'value' => '-', |
|
512 | + 'compare' => '=', |
|
513 | + ), |
|
514 | + array( |
|
515 | + 'key' => '_course_woocommerce_product', |
|
516 | + 'value' => self::get_free_product_ids(), |
|
517 | + 'compare' => 'IN', |
|
518 | + ), |
|
519 | + ); |
|
520 | + |
|
521 | + }// get_free_courses_meta_query |
|
522 | + |
|
523 | + /** |
|
524 | + * The metat query for courses that are free |
|
525 | + * |
|
526 | + * @since 1.9.0 |
|
527 | + * @return array $wp_query_meta_query_args_param |
|
528 | + */ |
|
529 | + public static function get_paid_courses_meta_query_args(){ |
|
530 | + |
|
531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
532 | + |
|
533 | + return array( |
|
534 | + array( |
|
535 | + 'key' => '_course_woocommerce_product', |
|
536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
537 | + // query |
|
538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
539 | + 'compare' => 'IN', |
|
540 | + ), |
|
541 | + ); |
|
542 | + |
|
543 | + }// get_free_courses_meta_query |
|
544 | + |
|
545 | + /** |
|
546 | + * The WordPress Query args |
|
547 | + * for paid products on sale |
|
548 | + * |
|
549 | + * @since 1.9.0 |
|
550 | + * @return array $product_query_args |
|
551 | + */ |
|
552 | + public static function get_paid_products_on_sale_query_args(){ |
|
553 | + |
|
554 | + $args = array( |
|
555 | + 'post_type' => 'product', |
|
556 | + 'posts_per_page' => 1000, |
|
557 | + 'orderby' => 'date', |
|
558 | + 'order' => 'DESC', |
|
559 | + 'suppress_filters' => 0 |
|
560 | + ); |
|
561 | + |
|
562 | + $args[ 'fields' ] = 'ids'; |
|
563 | + |
|
564 | + $args[ 'meta_query' ] = array( |
|
565 | + 'relation' => 'AND', |
|
566 | + array( |
|
567 | + 'key'=> '_regular_price', |
|
568 | + 'compare' => '>', |
|
569 | + 'value' => 0, |
|
570 | + ), |
|
571 | + array( |
|
572 | + 'key'=> '_sale_price', |
|
573 | + 'compare' => '>', |
|
574 | + 'value' => 0, |
|
575 | + ), |
|
576 | + ); |
|
577 | + |
|
578 | + return $args; |
|
579 | + |
|
580 | + } // get_paid_products_on_sale_query_args |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Return the WordPress query args for |
|
585 | + * products not on sale but that is not a free |
|
586 | + * |
|
587 | + * @since 1.9.0 |
|
588 | + * |
|
589 | + * @return array |
|
590 | + */ |
|
591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
592 | + |
|
593 | + $args = array( |
|
594 | + 'post_type' => 'product', |
|
595 | + 'posts_per_page' => 1000, |
|
596 | + 'orderby' => 'date', |
|
597 | + 'order' => 'DESC', |
|
598 | + 'suppress_filters' => 0 |
|
599 | + ); |
|
600 | + |
|
601 | + $args[ 'fields' ] = 'ids'; |
|
602 | + $args[ 'meta_query' ] = array( |
|
603 | + 'relation' => 'AND', |
|
604 | + array( |
|
605 | + 'key'=> '_regular_price', |
|
606 | + 'compare' => '>', |
|
607 | + 'value' => 0, |
|
608 | + ), |
|
609 | + array( |
|
610 | + 'key'=> '_sale_price', |
|
611 | + 'compare' => '=', |
|
612 | + 'value' => '', |
|
613 | + ), |
|
614 | + ); |
|
615 | + |
|
616 | + return $args; |
|
617 | + |
|
618 | + |
|
619 | + } // get_paid_courses_meta_query |
|
620 | + |
|
621 | + /** |
|
622 | + * Get all WooCommerce non-free product id's |
|
623 | + * |
|
624 | + * @since 1.9.0 |
|
625 | + * |
|
626 | + * @return array $woocommerce_paid_product_ids |
|
627 | + */ |
|
628 | + public static function get_paid_product_ids(){ |
|
629 | + |
|
630 | + // get all the paid WooCommerce products that has regular |
|
631 | + // and sale price greater than 0 |
|
632 | + // will be used later to check for course with the id as meta |
|
633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
634 | + |
|
635 | + // get all the paid WooCommerce products that has regular price |
|
636 | + // greater than 0 without a sale price |
|
637 | + // will be used later to check for course with the id as meta |
|
638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
639 | + |
|
640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
641 | + // sale but regular price greater than zero |
|
642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
643 | + |
|
644 | + // if |
|
645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
646 | + return array( ); |
|
647 | + } |
|
648 | + return $woocommerce_paid_product_ids; |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Get all free courses. |
|
654 | + * |
|
655 | + * This course that have a WC product attached |
|
656 | + * that has a price or sale price of zero and |
|
657 | + * other courses with no WooCommerce products |
|
658 | + * attached. |
|
659 | + * |
|
660 | + * @since 1.9.0 |
|
661 | + * |
|
662 | + * @return array |
|
663 | + */ |
|
664 | + public static function get_free_courses(){ |
|
665 | + |
|
666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
668 | + |
|
669 | + // don't show any paid courses |
|
670 | + $courses = self::get_paid_courses(); |
|
671 | + $ids = array(); |
|
672 | + foreach( $courses as $course ){ |
|
673 | + $ids[] = $course->ID; |
|
674 | + } |
|
675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
676 | + |
|
677 | + return get_posts( $free_course_query_args ); |
|
678 | + |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Return all products that are not free |
|
683 | + * |
|
684 | + * @since 1.9.0 |
|
685 | + * @return array |
|
686 | + */ |
|
687 | + public static function get_paid_courses(){ |
|
688 | + |
|
689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
690 | + |
|
691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
692 | + |
|
693 | + return get_posts( $paid_course_query_args ); |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Show the WooCommerce add to cart button for the current course |
|
698 | + * |
|
699 | + * The function will only show the button if |
|
700 | + * 1- the user can buy the course |
|
701 | + * 2- if they have completed their pre-requisite |
|
702 | + * 3- if the course has a valid product attached |
|
703 | + * |
|
704 | + * @since 1.9.0 |
|
705 | + * @param int $course_id |
|
706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
707 | + */ |
|
708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
709 | + |
|
710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
711 | + return ''; |
|
712 | + } |
|
713 | + |
|
714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
715 | + |
|
716 | + // Check if customer purchased the product |
|
717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | + || empty( $wc_post_id ) ) { |
|
719 | + |
|
720 | + return ''; |
|
721 | + |
|
722 | + } |
|
723 | + |
|
724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
725 | + // Get the product |
|
726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
727 | + |
|
728 | + // do not show the button for invalid products, non purchasable products, out |
|
729 | + // of stock product or if course is already in cart |
|
730 | + if ( ! isset ( $product ) |
|
731 | + || ! is_object( $product ) |
|
732 | + || ! $product->is_purchasable() |
|
733 | + || ! $product->is_in_stock() |
|
734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
735 | + |
|
736 | + return ''; |
|
737 | + |
|
738 | + } |
|
739 | + |
|
740 | + // |
|
741 | + // button output: |
|
742 | + // |
|
743 | + ?> |
|
744 | 744 | |
745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
773 | 773 | </form> |
774 | 774 | |
775 | 775 | <?php |
776 | - } // end the_add_to_cart_button_html |
|
776 | + } // end the_add_to_cart_button_html |
|
777 | 777 | |
778 | - /** |
|
779 | - * Alter the no permissions message on the single course page |
|
780 | - * Changes the message to a WooCommerce specific message. |
|
781 | - * |
|
782 | - * @since 1.9.0 |
|
783 | - * |
|
784 | - * @param $message |
|
785 | - * @param $post_id |
|
786 | - * |
|
787 | - * @return string $message |
|
788 | - */ |
|
789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
778 | + /** |
|
779 | + * Alter the no permissions message on the single course page |
|
780 | + * Changes the message to a WooCommerce specific message. |
|
781 | + * |
|
782 | + * @since 1.9.0 |
|
783 | + * |
|
784 | + * @param $message |
|
785 | + * @param $post_id |
|
786 | + * |
|
787 | + * @return string $message |
|
788 | + */ |
|
789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
790 | 790 | |
791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
792 | - return $message; |
|
793 | - } |
|
791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
792 | + return $message; |
|
793 | + } |
|
794 | 794 | |
795 | - $product_id = self::get_course_product_id( $post_id ); |
|
795 | + $product_id = self::get_course_product_id( $post_id ); |
|
796 | 796 | |
797 | - if( ! $product_id |
|
798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
797 | + if( ! $product_id |
|
798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
799 | 799 | |
800 | - return $message; |
|
800 | + return $message; |
|
801 | 801 | |
802 | - } |
|
802 | + } |
|
803 | 803 | |
804 | - ob_start(); |
|
805 | - self::the_course_no_permissions_message( $post_id ); |
|
806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
804 | + ob_start(); |
|
805 | + self::the_course_no_permissions_message( $post_id ); |
|
806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
807 | 807 | |
808 | - return $woocommerce_course_no_permissions_message ; |
|
808 | + return $woocommerce_course_no_permissions_message ; |
|
809 | 809 | |
810 | - } |
|
811 | - /** |
|
812 | - * Show the no permissions message when a user is logged in |
|
813 | - * and have not yet purchased the current course |
|
814 | - * |
|
815 | - * @since 1.9.0 |
|
816 | - */ |
|
817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
810 | + } |
|
811 | + /** |
|
812 | + * Show the no permissions message when a user is logged in |
|
813 | + * and have not yet purchased the current course |
|
814 | + * |
|
815 | + * @since 1.9.0 |
|
816 | + */ |
|
817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
818 | 818 | |
819 | - // login link |
|
820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
819 | + // login link |
|
820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
822 | 822 | |
823 | - ?> |
|
823 | + ?> |
|
824 | 824 | |
825 | 825 | <span class="add-to-cart-login"> |
826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,110 +828,110 @@ discard block |
||
828 | 828 | |
829 | 829 | <?php } |
830 | 830 | |
831 | - /** |
|
832 | - * Checks if a user has bought a product item. |
|
833 | - * |
|
834 | - * @since 1.9.0 |
|
835 | - * |
|
836 | - * @param int $user_id |
|
837 | - * @param int $product_id |
|
838 | - * |
|
839 | - * @return bool |
|
840 | - */ |
|
841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
831 | + /** |
|
832 | + * Checks if a user has bought a product item. |
|
833 | + * |
|
834 | + * @since 1.9.0 |
|
835 | + * |
|
836 | + * @param int $user_id |
|
837 | + * @param int $product_id |
|
838 | + * |
|
839 | + * @return bool |
|
840 | + */ |
|
841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
842 | 842 | |
843 | - $orders = get_posts( array( |
|
844 | - 'posts_per_page' => -1, |
|
845 | - 'meta_key' => '_customer_user', |
|
846 | - 'meta_value' => intval( $user_id ), |
|
847 | - 'post_type' => 'shop_order', |
|
848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
849 | - ) ); |
|
843 | + $orders = get_posts( array( |
|
844 | + 'posts_per_page' => -1, |
|
845 | + 'meta_key' => '_customer_user', |
|
846 | + 'meta_value' => intval( $user_id ), |
|
847 | + 'post_type' => 'shop_order', |
|
848 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
849 | + ) ); |
|
850 | 850 | |
851 | - foreach ( $orders as $order_id ) { |
|
851 | + foreach ( $orders as $order_id ) { |
|
852 | 852 | |
853 | - $order = new WC_Order( $order_id->ID ); |
|
853 | + $order = new WC_Order( $order_id->ID ); |
|
854 | 854 | |
855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
855 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
856 | 856 | |
857 | - continue; |
|
858 | - } |
|
857 | + continue; |
|
858 | + } |
|
859 | 859 | |
860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
860 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
861 | 861 | |
862 | - continue; |
|
862 | + continue; |
|
863 | 863 | |
864 | - } |
|
864 | + } |
|
865 | 865 | |
866 | - foreach( $order->get_items() as $item ) { |
|
866 | + foreach( $order->get_items() as $item ) { |
|
867 | 867 | |
868 | - // Check if user has bought product |
|
869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
868 | + // Check if user has bought product |
|
869 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
870 | 870 | |
871 | - // Check if user has an active subscription for product |
|
872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
874 | - if( $sub_key ) { |
|
875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
876 | - if( $sub && isset( $sub['status'] ) ) { |
|
877 | - if( 'active' == $sub['status'] ) { |
|
878 | - return true; |
|
879 | - } else { |
|
880 | - return false; |
|
881 | - } |
|
882 | - } |
|
883 | - } |
|
884 | - } |
|
871 | + // Check if user has an active subscription for product |
|
872 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
874 | + if( $sub_key ) { |
|
875 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
876 | + if( $sub && isset( $sub['status'] ) ) { |
|
877 | + if( 'active' == $sub['status'] ) { |
|
878 | + return true; |
|
879 | + } else { |
|
880 | + return false; |
|
881 | + } |
|
882 | + } |
|
883 | + } |
|
884 | + } |
|
885 | 885 | |
886 | - // Customer has bought product |
|
887 | - return true; |
|
888 | - } // End If Statement |
|
886 | + // Customer has bought product |
|
887 | + return true; |
|
888 | + } // End If Statement |
|
889 | 889 | |
890 | - } // End For each item |
|
890 | + } // End For each item |
|
891 | 891 | |
892 | - } // End For each order |
|
892 | + } // End For each order |
|
893 | 893 | |
894 | - } // end has customer bought product |
|
894 | + } // end has customer bought product |
|
895 | 895 | |
896 | - /** |
|
897 | - * Return the product id for the given course |
|
898 | - * |
|
899 | - * @since 1.9.0 |
|
900 | - * |
|
901 | - * @param int $course_id |
|
902 | - * |
|
903 | - * @return string $woocommerce_product_id or false if none exist |
|
904 | - * |
|
905 | - */ |
|
906 | - public static function get_course_product_id( $course_id ){ |
|
896 | + /** |
|
897 | + * Return the product id for the given course |
|
898 | + * |
|
899 | + * @since 1.9.0 |
|
900 | + * |
|
901 | + * @param int $course_id |
|
902 | + * |
|
903 | + * @return string $woocommerce_product_id or false if none exist |
|
904 | + * |
|
905 | + */ |
|
906 | + public static function get_course_product_id( $course_id ){ |
|
907 | 907 | |
908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
908 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
909 | 909 | |
910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
911 | - return false; |
|
912 | - } |
|
910 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
911 | + return false; |
|
912 | + } |
|
913 | 913 | |
914 | - return $product_id; |
|
914 | + return $product_id; |
|
915 | 915 | |
916 | - } |
|
916 | + } |
|
917 | 917 | |
918 | - /** |
|
919 | - * Alter the body classes adding WooCommerce to the body |
|
920 | - * |
|
921 | - * @param array $classes |
|
922 | - * @return array |
|
923 | - */ |
|
924 | - public static function add_woocommerce_body_class( $classes ){ |
|
918 | + /** |
|
919 | + * Alter the body classes adding WooCommerce to the body |
|
920 | + * |
|
921 | + * @param array $classes |
|
922 | + * @return array |
|
923 | + */ |
|
924 | + public static function add_woocommerce_body_class( $classes ){ |
|
925 | 925 | |
926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
926 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
927 | 927 | |
928 | - $classes[] ='woocommerce'; |
|
928 | + $classes[] ='woocommerce'; |
|
929 | 929 | |
930 | - } |
|
930 | + } |
|
931 | 931 | |
932 | 932 | |
933 | - return $classes; |
|
933 | + return $classes; |
|
934 | 934 | |
935 | - } |
|
935 | + } |
|
936 | 936 | |
937 | 937 | }// end Sensei_WC |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei WooCommerce class |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | * @since 1.9.0 |
12 | 12 | */ |
13 | 13 | |
14 | -Class Sensei_WC{ |
|
14 | +Class Sensei_WC { |
|
15 | 15 | /** |
16 | 16 | * Load the files needed for the woocommerce integration. |
17 | 17 | * |
18 | 18 | * @since 1.9.0 |
19 | 19 | */ |
20 | - public static function load_woocommerce_integration_hooks(){ |
|
20 | + public static function load_woocommerce_integration_hooks() { |
|
21 | 21 | |
22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
22 | + require_once(__DIR__.'/hooks/woocommerce.php'); |
|
23 | 23 | |
24 | 24 | } |
25 | 25 | /** |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * @since 1.9.0 |
29 | 29 | * @return bool |
30 | 30 | */ |
31 | - public static function is_woocommerce_active(){ |
|
31 | + public static function is_woocommerce_active() { |
|
32 | 32 | |
33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
33 | + $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | 34 | return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
35 | 35 | |
36 | 36 | } // end is_woocommerce_active |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public static function is_woocommerce_present(){ |
|
48 | + public static function is_woocommerce_present() { |
|
49 | 49 | |
50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
50 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
51 | 51 | |
52 | - if ( is_multisite() ){ |
|
52 | + if (is_multisite()) { |
|
53 | 53 | |
54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
54 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
55 | 55 | |
56 | 56 | } |
57 | 57 | |
58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
58 | + $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins); |
|
59 | 59 | |
60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
60 | + return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated; |
|
61 | 61 | |
62 | 62 | }// end is_woocommerce_present |
63 | 63 | |
@@ -70,48 +70,48 @@ discard block |
||
70 | 70 | * @param $course_id |
71 | 71 | * @return array $user_course_orders |
72 | 72 | */ |
73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
73 | + public static function get_learner_course_active_order_id($user_id, $course_id) { |
|
74 | 74 | |
75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
75 | + $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
76 | 76 | |
77 | - $orders_query = new WP_Query( array( |
|
77 | + $orders_query = new WP_Query(array( |
|
78 | 78 | 'post_type' => 'shop_order', |
79 | 79 | 'posts_per_page' => -1, |
80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
80 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
81 | 81 | 'meta_key'=> '_customer_user', |
82 | 82 | 'meta_value'=> $user_id, |
83 | - ) ); |
|
83 | + )); |
|
84 | 84 | |
85 | - if( $orders_query->post_count == 0 ){ |
|
85 | + if ($orders_query->post_count == 0) { |
|
86 | 86 | |
87 | 87 | return false; |
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - foreach( $orders_query->get_posts() as $order ){ |
|
91 | + foreach ($orders_query->get_posts() as $order) { |
|
92 | 92 | |
93 | - $order = new WC_Order( $order->ID ); |
|
93 | + $order = new WC_Order($order->ID); |
|
94 | 94 | $items = $order->get_items(); |
95 | 95 | |
96 | - $user_orders = array(); |
|
96 | + $user_orders = array(); |
|
97 | 97 | |
98 | - foreach( $items as $item ){ |
|
98 | + foreach ($items as $item) { |
|
99 | 99 | |
100 | 100 | // if the product id on the order and the one given to this function |
101 | 101 | // this order has been placed by the given user on the given course. |
102 | - $product = wc_get_product( $item['product_id'] ); |
|
102 | + $product = wc_get_product($item['product_id']); |
|
103 | 103 | |
104 | - if ( $product->is_type( 'variable' )) { |
|
104 | + if ($product->is_type('variable')) { |
|
105 | 105 | |
106 | 106 | $item_product_id = $item['variation_id']; |
107 | 107 | |
108 | 108 | } else { |
109 | 109 | |
110 | - $item_product_id = $item['product_id']; |
|
110 | + $item_product_id = $item['product_id']; |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
114 | - if( $course_product_id == $item_product_id ){ |
|
114 | + if ($course_product_id == $item_product_id) { |
|
115 | 115 | |
116 | 116 | return $order->id; |
117 | 117 | |
@@ -135,28 +135,28 @@ discard block |
||
135 | 135 | * @param $filter_links |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
138 | + public static function add_course_archive_wc_filter_links($filter_links) { |
|
139 | 139 | |
140 | - $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() ); |
|
140 | + $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url()); |
|
141 | 141 | |
142 | 142 | $free_courses = self::get_free_courses(); |
143 | 143 | $paid_courses = self::get_paid_courses(); |
144 | 144 | |
145 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
145 | + if (empty($free_courses) || empty($paid_courses)) { |
|
146 | 146 | // do not show any WooCommerce filters if all courses are |
147 | 147 | // free or if all courses are paid |
148 | 148 | return $filter_links; |
149 | 149 | |
150 | 150 | } |
151 | 151 | |
152 | - $filter_links[] = array( 'id'=>'paid' , |
|
152 | + $filter_links[] = array('id'=>'paid', |
|
153 | 153 | 'url'=> add_query_arg('course_filter', 'paid', $course_url), |
154 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
154 | + 'title'=>__('Paid', 'woothemes-sensei') |
|
155 | 155 | ); |
156 | 156 | |
157 | - $filter_links[] = array( 'id'=>'free', |
|
157 | + $filter_links[] = array('id'=>'free', |
|
158 | 158 | 'url'=>add_query_arg('course_filter', 'free', $course_url), |
159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
159 | + 'title'=>__('Free', 'woothemes-sensei') |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | return $filter_links; |
@@ -173,24 +173,24 @@ discard block |
||
173 | 173 | * @param WP_Query $query |
174 | 174 | * @return WP_Query $query |
175 | 175 | */ |
176 | - public static function course_archive_wc_filter_free( $query ){ |
|
176 | + public static function course_archive_wc_filter_free($query) { |
|
177 | 177 | |
178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
178 | + if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter'] |
|
179 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
180 | 180 | |
181 | 181 | // setup the course meta query |
182 | 182 | $meta_query = self::get_free_courses_meta_query_args(); |
183 | 183 | |
184 | 184 | // manipulate the query to return free courses |
185 | - $query->set('meta_query', $meta_query ); |
|
185 | + $query->set('meta_query', $meta_query); |
|
186 | 186 | |
187 | 187 | // don't show any paid courses |
188 | 188 | $courses = self::get_paid_courses(); |
189 | 189 | $ids = array(); |
190 | - foreach( $courses as $course ){ |
|
190 | + foreach ($courses as $course) { |
|
191 | 191 | $ids[] = $course->ID; |
192 | 192 | } |
193 | - $query->set( 'post__not_in', $ids ); |
|
193 | + $query->set('post__not_in', $ids); |
|
194 | 194 | |
195 | 195 | }// end if course_filter |
196 | 196 | |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | * @param WP_Query $query |
210 | 210 | * @return WP_Query $query |
211 | 211 | */ |
212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
212 | + public static function course_archive_wc_filter_paid($query) { |
|
213 | 213 | |
214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
214 | + if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter'] |
|
215 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
216 | 216 | |
217 | 217 | // setup the course meta query |
218 | 218 | $meta_query = self::get_paid_courses_meta_query_args(); |
219 | 219 | |
220 | 220 | // manipulate the query to return free courses |
221 | - $query->set('meta_query', $meta_query ); |
|
221 | + $query->set('meta_query', $meta_query); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | * single courses if woocommerce is active allowing purchase |
232 | 232 | * information and actions to be hooked from WooCommerce. |
233 | 233 | */ |
234 | - public static function do_single_course_wc_single_product_action(){ |
|
234 | + public static function do_single_course_wc_single_product_action() { |
|
235 | 235 | |
236 | 236 | /** |
237 | 237 | * this hooks is documented within the WooCommerce plugin. |
238 | 238 | */ |
239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
239 | + if (Sensei_WC::is_woocommerce_active()) { |
|
240 | 240 | |
241 | - do_action( 'woocommerce_before_single_product' ); |
|
241 | + do_action('woocommerce_before_single_product'); |
|
242 | 242 | |
243 | 243 | } // End If Statement |
244 | 244 | |
@@ -259,23 +259,23 @@ discard block |
||
259 | 259 | * @param $user_id |
260 | 260 | * @return bool |
261 | 261 | */ |
262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
262 | + public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) { |
|
263 | 263 | |
264 | 264 | // check if the course has a valid product attached to it |
265 | 265 | // which the user should have purchased if they want to access |
266 | 266 | // the current lesson |
267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
267 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
268 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
269 | 269 | $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
270 | - if( isset ($product) && is_object($product) ){ |
|
270 | + if (isset ($product) && is_object($product)) { |
|
271 | 271 | |
272 | 272 | // valid product found |
273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
273 | + $order_id = self::get_learner_course_active_order_id($user_id, $course_id); |
|
274 | 274 | |
275 | 275 | // product has a successful order so this user may access the content |
276 | 276 | // this function may only return false or the default |
277 | 277 | // returning true may override other negatives which we don't want |
278 | - if( ! $order_id ){ |
|
278 | + if ( ! $order_id) { |
|
279 | 279 | |
280 | 280 | return false; |
281 | 281 | |
@@ -298,23 +298,23 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public static function course_link_from_order( ) { |
300 | 300 | |
301 | - if( ! is_order_received_page() ){ |
|
301 | + if ( ! is_order_received_page()) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $order_id = get_query_var( 'order-received' ); |
|
306 | - $order = new WC_Order( $order_id ); |
|
305 | + $order_id = get_query_var('order-received'); |
|
306 | + $order = new WC_Order($order_id); |
|
307 | 307 | |
308 | 308 | // exit early if not wc-completed or wc-processing |
309 | - if( 'wc-completed' != $order->post_status |
|
310 | - && 'wc-processing' != $order->post_status ) { |
|
309 | + if ('wc-completed' != $order->post_status |
|
310 | + && 'wc-processing' != $order->post_status) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | 313 | |
314 | 314 | $course_links = array(); // store the for links for courses purchased |
315 | - foreach ( $order->get_items() as $item ) { |
|
315 | + foreach ($order->get_items() as $item) { |
|
316 | 316 | |
317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
317 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
318 | 318 | |
319 | 319 | // If item has variation_id then its a variation of the product |
320 | 320 | $item_id = $item['variation_id']; |
@@ -326,28 +326,28 @@ discard block |
||
326 | 326 | |
327 | 327 | } // End If Statement |
328 | 328 | |
329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
329 | + $user_id = get_post_meta($order->id, '_customer_user', true); |
|
330 | 330 | |
331 | - if( $user_id ) { |
|
331 | + if ($user_id) { |
|
332 | 332 | |
333 | 333 | // Get all courses for product |
334 | 334 | $args = Sensei_Course::get_default_query_args(); |
335 | - $args['meta_query'] = array( array( |
|
335 | + $args['meta_query'] = array(array( |
|
336 | 336 | 'key' => '_course_woocommerce_product', |
337 | 337 | 'value' => $item_id |
338 | - ) ); |
|
338 | + )); |
|
339 | 339 | $args['orderby'] = 'menu_order date'; |
340 | 340 | $args['order'] = 'ASC'; |
341 | 341 | |
342 | 342 | // loop through courses |
343 | - $courses = get_posts( $args ); |
|
344 | - if( $courses && count( $courses ) > 0 ) { |
|
343 | + $courses = get_posts($args); |
|
344 | + if ($courses && count($courses) > 0) { |
|
345 | 345 | |
346 | - foreach( $courses as $course ) { |
|
346 | + foreach ($courses as $course) { |
|
347 | 347 | |
348 | 348 | $title = $course->post_title; |
349 | - $permalink = get_permalink( $course->ID ); |
|
350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
349 | + $permalink = get_permalink($course->ID); |
|
350 | + $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> '; |
|
351 | 351 | |
352 | 352 | } // end for each |
353 | 353 | |
@@ -358,24 +358,24 @@ discard block |
||
358 | 358 | }// end loop through orders |
359 | 359 | |
360 | 360 | // add the courses to the WooCommerce notice |
361 | - if( ! empty( $course_links) ){ |
|
361 | + if ( ! empty($course_links)) { |
|
362 | 362 | |
363 | 363 | $courses_html = _nx( |
364 | 364 | 'You have purchased the following course:', |
365 | 365 | 'You have purchased the following courses:', |
366 | - count( $course_links ), |
|
366 | + count($course_links), |
|
367 | 367 | 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
368 | 368 | ); |
369 | 369 | |
370 | - foreach( $course_links as $link ){ |
|
370 | + foreach ($course_links as $link) { |
|
371 | 371 | |
372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
372 | + $courses_html .= '<li>'.$link.'</li>'; |
|
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | 376 | $courses_html .= ' </ul>'; |
377 | 377 | |
378 | - wc_add_notice( $courses_html, 'success' ); |
|
378 | + wc_add_notice($courses_html, 'success'); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | } // end course_link_order_form |
@@ -388,20 +388,20 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @since 1.9.0 |
390 | 390 | */ |
391 | - public static function course_in_cart_message(){ |
|
391 | + public static function course_in_cart_message() { |
|
392 | 392 | |
393 | 393 | global $post; |
394 | 394 | |
395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
395 | + if (self::is_course_in_cart($post->ID)) { ?> |
|
396 | 396 | |
397 | 397 | <div class="sensei-message info">' |
398 | 398 | <?php |
399 | 399 | |
400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
400 | + $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url() |
|
401 | + . '" title="'.__('complete purchase', 'woothemes-sensei').'">' |
|
402 | + . __('complete the purchase', 'woothemes-sensei').'</a>'; |
|
403 | 403 | |
404 | - sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
404 | + sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link); |
|
405 | 405 | |
406 | 406 | ?> |
407 | 407 | </div> |
@@ -415,14 +415,14 @@ discard block |
||
415 | 415 | * @param $course_id |
416 | 416 | * @return bool |
417 | 417 | */ |
418 | - public static function is_course_in_cart( $course_id ){ |
|
418 | + public static function is_course_in_cart($course_id) { |
|
419 | 419 | |
420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
420 | + $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true)); |
|
421 | + $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
422 | 422 | |
423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
423 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
424 | 424 | |
425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
425 | + if (self::is_product_in_cart($wc_post_id)) { |
|
426 | 426 | |
427 | 427 | return true; |
428 | 428 | |
@@ -440,20 +440,20 @@ discard block |
||
440 | 440 | * @param $product_id |
441 | 441 | * @return bool |
442 | 442 | */ |
443 | - public static function is_product_in_cart( $product_id ){ |
|
443 | + public static function is_product_in_cart($product_id) { |
|
444 | 444 | |
445 | - if ( 0 < $product_id ) { |
|
445 | + if (0 < $product_id) { |
|
446 | 446 | |
447 | - $product = wc_get_product( $product_id ); |
|
447 | + $product = wc_get_product($product_id); |
|
448 | 448 | |
449 | 449 | $parent_id = ''; |
450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
450 | + if (isset($product->variation_id) && 0 < intval($product->variation_id)) { |
|
451 | 451 | $wc_product_id = $product->parent->id; |
452 | 452 | } |
453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
453 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
454 | 454 | |
455 | 455 | $cart_product = $values['data']; |
456 | - if( $product_id == $cart_product->id ) { |
|
456 | + if ($product_id == $cart_product->id) { |
|
457 | 457 | |
458 | 458 | return true; |
459 | 459 | |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | * @type int $wp_post_id |
476 | 476 | * } |
477 | 477 | */ |
478 | - public static function get_free_product_ids(){ |
|
478 | + public static function get_free_product_ids() { |
|
479 | 479 | |
480 | - return get_posts( array( |
|
480 | + return get_posts(array( |
|
481 | 481 | 'post_type' => 'product', |
482 | 482 | 'posts_per_page' => '1000', |
483 | 483 | 'fields' => 'ids', |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @since 1.9.0 |
503 | 503 | * @return array $wp_meta_query_param |
504 | 504 | */ |
505 | - public static function get_free_courses_meta_query_args(){ |
|
505 | + public static function get_free_courses_meta_query_args() { |
|
506 | 506 | |
507 | 507 | return array( |
508 | 508 | 'relation' => 'OR', |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @since 1.9.0 |
527 | 527 | * @return array $wp_query_meta_query_args_param |
528 | 528 | */ |
529 | - public static function get_paid_courses_meta_query_args(){ |
|
529 | + public static function get_paid_courses_meta_query_args() { |
|
530 | 530 | |
531 | 531 | $paid_product_ids = self::get_paid_product_ids(); |
532 | 532 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | 'key' => '_course_woocommerce_product', |
536 | 536 | // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
537 | 537 | // query |
538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
538 | + 'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids, |
|
539 | 539 | 'compare' => 'IN', |
540 | 540 | ), |
541 | 541 | ); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @since 1.9.0 |
550 | 550 | * @return array $product_query_args |
551 | 551 | */ |
552 | - public static function get_paid_products_on_sale_query_args(){ |
|
552 | + public static function get_paid_products_on_sale_query_args() { |
|
553 | 553 | |
554 | 554 | $args = array( |
555 | 555 | 'post_type' => 'product', |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | 'suppress_filters' => 0 |
560 | 560 | ); |
561 | 561 | |
562 | - $args[ 'fields' ] = 'ids'; |
|
562 | + $args['fields'] = 'ids'; |
|
563 | 563 | |
564 | - $args[ 'meta_query' ] = array( |
|
564 | + $args['meta_query'] = array( |
|
565 | 565 | 'relation' => 'AND', |
566 | 566 | array( |
567 | 567 | 'key'=> '_regular_price', |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return array |
590 | 590 | */ |
591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
591 | + public static function get_paid_products_not_on_sale_query_args() { |
|
592 | 592 | |
593 | 593 | $args = array( |
594 | 594 | 'post_type' => 'product', |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | 'suppress_filters' => 0 |
599 | 599 | ); |
600 | 600 | |
601 | - $args[ 'fields' ] = 'ids'; |
|
602 | - $args[ 'meta_query' ] = array( |
|
601 | + $args['fields'] = 'ids'; |
|
602 | + $args['meta_query'] = array( |
|
603 | 603 | 'relation' => 'AND', |
604 | 604 | array( |
605 | 605 | 'key'=> '_regular_price', |
@@ -625,24 +625,24 @@ discard block |
||
625 | 625 | * |
626 | 626 | * @return array $woocommerce_paid_product_ids |
627 | 627 | */ |
628 | - public static function get_paid_product_ids(){ |
|
628 | + public static function get_paid_product_ids() { |
|
629 | 629 | |
630 | 630 | // get all the paid WooCommerce products that has regular |
631 | 631 | // and sale price greater than 0 |
632 | 632 | // will be used later to check for course with the id as meta |
633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
633 | + $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args()); |
|
634 | 634 | |
635 | 635 | // get all the paid WooCommerce products that has regular price |
636 | 636 | // greater than 0 without a sale price |
637 | 637 | // will be used later to check for course with the id as meta |
638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
638 | + $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args()); |
|
639 | 639 | |
640 | 640 | // combine products ID's with regular and sale price grater than zero and those without |
641 | 641 | // sale but regular price greater than zero |
642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
642 | + $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale); |
|
643 | 643 | |
644 | 644 | // if |
645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
645 | + if (empty($woocommerce_paid_product_ids)) { |
|
646 | 646 | return array( ); |
647 | 647 | } |
648 | 648 | return $woocommerce_paid_product_ids; |
@@ -661,20 +661,20 @@ discard block |
||
661 | 661 | * |
662 | 662 | * @return array |
663 | 663 | */ |
664 | - public static function get_free_courses(){ |
|
664 | + public static function get_free_courses() { |
|
665 | 665 | |
666 | 666 | $free_course_query_args = Sensei_Course::get_default_query_args(); |
667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
667 | + $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args(); |
|
668 | 668 | |
669 | 669 | // don't show any paid courses |
670 | 670 | $courses = self::get_paid_courses(); |
671 | 671 | $ids = array(); |
672 | - foreach( $courses as $course ){ |
|
672 | + foreach ($courses as $course) { |
|
673 | 673 | $ids[] = $course->ID; |
674 | 674 | } |
675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
675 | + $free_course_query_args['post__not_in'] = $ids; |
|
676 | 676 | |
677 | - return get_posts( $free_course_query_args ); |
|
677 | + return get_posts($free_course_query_args); |
|
678 | 678 | |
679 | 679 | } |
680 | 680 | |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | * @since 1.9.0 |
685 | 685 | * @return array |
686 | 686 | */ |
687 | - public static function get_paid_courses(){ |
|
687 | + public static function get_paid_courses() { |
|
688 | 688 | |
689 | 689 | $paid_course_query_args = Sensei_Course::get_default_query_args(); |
690 | 690 | |
691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
691 | + $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args(); |
|
692 | 692 | |
693 | - return get_posts( $paid_course_query_args ); |
|
693 | + return get_posts($paid_course_query_args); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -705,17 +705,17 @@ discard block |
||
705 | 705 | * @param int $course_id |
706 | 706 | * @return string $html markup for the button or nothing if user not allowed to buy |
707 | 707 | */ |
708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
708 | + public static function the_add_to_cart_button_html($course_id) { |
|
709 | 709 | |
710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
710 | + if ( ! Sensei_Course::is_prerequisite_complete($course_id)) { |
|
711 | 711 | return ''; |
712 | 712 | } |
713 | 713 | |
714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
714 | + $wc_post_id = self::get_course_product_id($course_id); |
|
715 | 715 | |
716 | 716 | // Check if customer purchased the product |
717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | - || empty( $wc_post_id ) ) { |
|
717 | + if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) |
|
718 | + || empty($wc_post_id)) { |
|
719 | 719 | |
720 | 720 | return ''; |
721 | 721 | |
@@ -723,15 +723,15 @@ discard block |
||
723 | 723 | |
724 | 724 | // based on simple.php in WC templates/single-product/add-to-cart/ |
725 | 725 | // Get the product |
726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
726 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
727 | 727 | |
728 | 728 | // do not show the button for invalid products, non purchasable products, out |
729 | 729 | // of stock product or if course is already in cart |
730 | - if ( ! isset ( $product ) |
|
731 | - || ! is_object( $product ) |
|
730 | + if ( ! isset ($product) |
|
731 | + || ! is_object($product) |
|
732 | 732 | || ! $product->is_purchasable() |
733 | 733 | || ! $product->is_in_stock() |
734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
734 | + || self::is_course_in_cart($wc_post_id)) { |
|
735 | 735 | |
736 | 736 | return ''; |
737 | 737 | |
@@ -742,23 +742,23 @@ discard block |
||
742 | 742 | // |
743 | 743 | ?> |
744 | 744 | |
745 | - <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
|
745 | + <form action="<?php echo esc_url($product->add_to_cart_url()); ?>" |
|
746 | 746 | class="cart" |
747 | 747 | method="post" |
748 | 748 | enctype="multipart/form-data"> |
749 | 749 | |
750 | - <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" /> |
|
750 | + <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" /> |
|
751 | 751 | |
752 | 752 | <input type="hidden" name="quantity" value="1" /> |
753 | 753 | |
754 | - <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?> |
|
754 | + <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> |
|
755 | 755 | |
756 | 756 | <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" /> |
757 | - <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?> |
|
757 | + <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> |
|
758 | 758 | |
759 | - <?php foreach( $product->variation_data as $att => $val ) { ?> |
|
759 | + <?php foreach ($product->variation_data as $att => $val) { ?> |
|
760 | 760 | |
761 | - <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" /> |
|
761 | + <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" /> |
|
762 | 762 | |
763 | 763 | <?php } ?> |
764 | 764 | |
@@ -786,26 +786,26 @@ discard block |
||
786 | 786 | * |
787 | 787 | * @return string $message |
788 | 788 | */ |
789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
789 | + public static function alter_no_permissions_message($message, $post_id) { |
|
790 | 790 | |
791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
791 | + if (empty($post_id) || 'course' != get_post_type($post_id)) { |
|
792 | 792 | return $message; |
793 | 793 | } |
794 | 794 | |
795 | - $product_id = self::get_course_product_id( $post_id ); |
|
795 | + $product_id = self::get_course_product_id($post_id); |
|
796 | 796 | |
797 | - if( ! $product_id |
|
798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
797 | + if ( ! $product_id |
|
798 | + || self::has_customer_bought_product(get_current_user_id(), $product_id)) { |
|
799 | 799 | |
800 | 800 | return $message; |
801 | 801 | |
802 | 802 | } |
803 | 803 | |
804 | 804 | ob_start(); |
805 | - self::the_course_no_permissions_message( $post_id ); |
|
805 | + self::the_course_no_permissions_message($post_id); |
|
806 | 806 | $woocommerce_course_no_permissions_message = ob_get_clean(); |
807 | 807 | |
808 | - return $woocommerce_course_no_permissions_message ; |
|
808 | + return $woocommerce_course_no_permissions_message; |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | /** |
@@ -814,16 +814,16 @@ discard block |
||
814 | 814 | * |
815 | 815 | * @since 1.9.0 |
816 | 816 | */ |
817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
817 | + public static function the_course_no_permissions_message($course_id) { |
|
818 | 818 | |
819 | 819 | // login link |
820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
820 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
821 | + $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>'; |
|
822 | 822 | |
823 | 823 | ?> |
824 | 824 | |
825 | 825 | <span class="add-to-cart-login"> |
826 | - <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
|
826 | + <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?> |
|
827 | 827 | </span> |
828 | 828 | |
829 | 829 | <?php } |
@@ -838,43 +838,43 @@ discard block |
||
838 | 838 | * |
839 | 839 | * @return bool |
840 | 840 | */ |
841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
841 | + public static function has_customer_bought_product($user_id, $product_id) { |
|
842 | 842 | |
843 | - $orders = get_posts( array( |
|
843 | + $orders = get_posts(array( |
|
844 | 844 | 'posts_per_page' => -1, |
845 | 845 | 'meta_key' => '_customer_user', |
846 | - 'meta_value' => intval( $user_id ), |
|
846 | + 'meta_value' => intval($user_id), |
|
847 | 847 | 'post_type' => 'shop_order', |
848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
849 | - ) ); |
|
848 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
849 | + )); |
|
850 | 850 | |
851 | - foreach ( $orders as $order_id ) { |
|
851 | + foreach ($orders as $order_id) { |
|
852 | 852 | |
853 | - $order = new WC_Order( $order_id->ID ); |
|
853 | + $order = new WC_Order($order_id->ID); |
|
854 | 854 | |
855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
855 | + if ($order->post_status != 'wc-completed' && $order->post_status != 'wc-processing') { |
|
856 | 856 | |
857 | 857 | continue; |
858 | 858 | } |
859 | 859 | |
860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
860 | + if ( ! (0 < sizeof($order->get_items()))) { |
|
861 | 861 | |
862 | 862 | continue; |
863 | 863 | |
864 | 864 | } |
865 | 865 | |
866 | - foreach( $order->get_items() as $item ) { |
|
866 | + foreach ($order->get_items() as $item) { |
|
867 | 867 | |
868 | 868 | // Check if user has bought product |
869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
869 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
870 | 870 | |
871 | 871 | // Check if user has an active subscription for product |
872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
874 | - if( $sub_key ) { |
|
875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
876 | - if( $sub && isset( $sub['status'] ) ) { |
|
877 | - if( 'active' == $sub['status'] ) { |
|
872 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id); |
|
874 | + if ($sub_key) { |
|
875 | + $sub = WC_Subscriptions_Manager::get_subscription($sub_key); |
|
876 | + if ($sub && isset($sub['status'])) { |
|
877 | + if ('active' == $sub['status']) { |
|
878 | 878 | return true; |
879 | 879 | } else { |
880 | 880 | return false; |
@@ -903,11 +903,11 @@ discard block |
||
903 | 903 | * @return string $woocommerce_product_id or false if none exist |
904 | 904 | * |
905 | 905 | */ |
906 | - public static function get_course_product_id( $course_id ){ |
|
906 | + public static function get_course_product_id($course_id) { |
|
907 | 907 | |
908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
908 | + $product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
909 | 909 | |
910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
910 | + if (empty($product_id) || 'product' != get_post_type($product_id)) { |
|
911 | 911 | return false; |
912 | 912 | } |
913 | 913 | |
@@ -921,11 +921,11 @@ discard block |
||
921 | 921 | * @param array $classes |
922 | 922 | * @return array |
923 | 923 | */ |
924 | - public static function add_woocommerce_body_class( $classes ){ |
|
924 | + public static function add_woocommerce_body_class($classes) { |
|
925 | 925 | |
926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
926 | + if ( ! in_array('woocommerce', $classes)) { |
|
927 | 927 | |
928 | - $classes[] ='woocommerce'; |
|
928 | + $classes[] = 'woocommerce'; |
|
929 | 929 | |
930 | 930 | } |
931 | 931 |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Post Types Class |
@@ -146,7 +149,7 @@ discard block |
||
146 | 149 | |
147 | 150 | return get_page_uri( $settings_course_page->ID ); |
148 | 151 | |
149 | - }else{ |
|
152 | + } else{ |
|
150 | 153 | |
151 | 154 | return 'courses'; |
152 | 155 |
@@ -14,138 +14,138 @@ |
||
14 | 14 | */ |
15 | 15 | class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface { |
16 | 16 | |
17 | - /** |
|
18 | - * @var WP_Query to help setup the query needed by the render method. |
|
19 | - */ |
|
20 | - protected $query; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var string number of items to show on the current page |
|
24 | - * Default: all. |
|
25 | - */ |
|
26 | - protected $number; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string ordery by course field |
|
30 | - * Default: date |
|
31 | - */ |
|
32 | - protected $orderby; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string ASC or DESC |
|
36 | - * Default: 'DESC' |
|
37 | - */ |
|
38 | - protected $order; |
|
39 | - |
|
40 | - /** |
|
41 | - * Setup the shortcode object |
|
42 | - * |
|
43 | - * @since 1.9.0 |
|
44 | - * @param array $attributes |
|
45 | - * @param string $content |
|
46 | - * @param string $shortcode the shortcode that was called for this instance |
|
47 | - */ |
|
48 | - public function __construct( $attributes, $content, $shortcode ){ |
|
49 | - |
|
50 | - if( !is_user_logged_in() ) { |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - // set up all argument need for constructing the course query |
|
55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
56 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
57 | - |
|
58 | - // set the default for menu_order to be ASC |
|
59 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
60 | - |
|
61 | - $this->order = 'ASC'; |
|
62 | - |
|
63 | - }else{ |
|
64 | - |
|
65 | - // for everything else use the value passed or the default DESC |
|
66 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - // setup the course query that will be used when rendering |
|
71 | - $this->setup_course_query(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Sets up the object course query |
|
76 | - * that will be used int he render method. |
|
77 | - * |
|
78 | - * @since 1.9.0 |
|
79 | - */ |
|
80 | - protected function setup_course_query(){ |
|
81 | - |
|
82 | - // course query parameters to be used for all courses |
|
83 | - $query_args = array( |
|
84 | - 'post_type' => 'course', |
|
85 | - 'post_status' => 'publish', |
|
86 | - // the number specified by the user will be used later in this function |
|
87 | - 'posts_per_page' => 1000, |
|
88 | - 'orderby' => $this->orderby, |
|
89 | - 'order' => $this->order |
|
90 | - ); |
|
91 | - |
|
92 | - // get all the courses that has a product attached |
|
93 | - $all_courses_query = new WP_Query( $query_args ); |
|
94 | - |
|
95 | - $paid_courses_not_taken = array(); |
|
96 | - // look through all course and find the purchasable ones that user has not purchased |
|
97 | - foreach( $all_courses_query->posts as $course ){ |
|
98 | - |
|
99 | - // only keep the courses with a product including only courses that the user not taking |
|
100 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
101 | - if( is_numeric( $course_product_id ) |
|
102 | - && |
|
103 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
104 | - ){ |
|
105 | - |
|
106 | - $paid_courses_not_taken[] = $course->ID; |
|
107 | - |
|
108 | - } |
|
109 | - |
|
110 | - } // end foreach |
|
111 | - |
|
112 | - |
|
113 | - // setup the course query again and only use the course the user has not purchased. |
|
114 | - // this query will be loaded into the global WP_Query in the render function. |
|
115 | - $query_args['post__in'] = $paid_courses_not_taken; |
|
116 | - $query_args['posts_per_page'] = $this->number; |
|
117 | - $this->query = new WP_Query( $query_args ); |
|
118 | - |
|
119 | - }// end setup _course_query |
|
17 | + /** |
|
18 | + * @var WP_Query to help setup the query needed by the render method. |
|
19 | + */ |
|
20 | + protected $query; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var string number of items to show on the current page |
|
24 | + * Default: all. |
|
25 | + */ |
|
26 | + protected $number; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string ordery by course field |
|
30 | + * Default: date |
|
31 | + */ |
|
32 | + protected $orderby; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string ASC or DESC |
|
36 | + * Default: 'DESC' |
|
37 | + */ |
|
38 | + protected $order; |
|
39 | + |
|
40 | + /** |
|
41 | + * Setup the shortcode object |
|
42 | + * |
|
43 | + * @since 1.9.0 |
|
44 | + * @param array $attributes |
|
45 | + * @param string $content |
|
46 | + * @param string $shortcode the shortcode that was called for this instance |
|
47 | + */ |
|
48 | + public function __construct( $attributes, $content, $shortcode ){ |
|
49 | + |
|
50 | + if( !is_user_logged_in() ) { |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + // set up all argument need for constructing the course query |
|
55 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
56 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
57 | + |
|
58 | + // set the default for menu_order to be ASC |
|
59 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
60 | + |
|
61 | + $this->order = 'ASC'; |
|
62 | + |
|
63 | + }else{ |
|
64 | + |
|
65 | + // for everything else use the value passed or the default DESC |
|
66 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + // setup the course query that will be used when rendering |
|
71 | + $this->setup_course_query(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Sets up the object course query |
|
76 | + * that will be used int he render method. |
|
77 | + * |
|
78 | + * @since 1.9.0 |
|
79 | + */ |
|
80 | + protected function setup_course_query(){ |
|
81 | + |
|
82 | + // course query parameters to be used for all courses |
|
83 | + $query_args = array( |
|
84 | + 'post_type' => 'course', |
|
85 | + 'post_status' => 'publish', |
|
86 | + // the number specified by the user will be used later in this function |
|
87 | + 'posts_per_page' => 1000, |
|
88 | + 'orderby' => $this->orderby, |
|
89 | + 'order' => $this->order |
|
90 | + ); |
|
91 | + |
|
92 | + // get all the courses that has a product attached |
|
93 | + $all_courses_query = new WP_Query( $query_args ); |
|
94 | + |
|
95 | + $paid_courses_not_taken = array(); |
|
96 | + // look through all course and find the purchasable ones that user has not purchased |
|
97 | + foreach( $all_courses_query->posts as $course ){ |
|
98 | + |
|
99 | + // only keep the courses with a product including only courses that the user not taking |
|
100 | + $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
101 | + if( is_numeric( $course_product_id ) |
|
102 | + && |
|
103 | + ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
104 | + ){ |
|
105 | + |
|
106 | + $paid_courses_not_taken[] = $course->ID; |
|
107 | + |
|
108 | + } |
|
109 | + |
|
110 | + } // end foreach |
|
111 | + |
|
112 | + |
|
113 | + // setup the course query again and only use the course the user has not purchased. |
|
114 | + // this query will be loaded into the global WP_Query in the render function. |
|
115 | + $query_args['post__in'] = $paid_courses_not_taken; |
|
116 | + $query_args['posts_per_page'] = $this->number; |
|
117 | + $this->query = new WP_Query( $query_args ); |
|
118 | + |
|
119 | + }// end setup _course_query |
|
120 | 120 | |
121 | - /** |
|
122 | - * Rendering the shortcode this class is responsible for. |
|
123 | - * |
|
124 | - * @return string $content |
|
125 | - */ |
|
126 | - public function render(){ |
|
121 | + /** |
|
122 | + * Rendering the shortcode this class is responsible for. |
|
123 | + * |
|
124 | + * @return string $content |
|
125 | + */ |
|
126 | + public function render(){ |
|
127 | 127 | |
128 | - global $wp_query; |
|
128 | + global $wp_query; |
|
129 | 129 | |
130 | - if( ! is_user_logged_in() ) { |
|
131 | - return ''; |
|
132 | - } |
|
130 | + if( ! is_user_logged_in() ) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | 133 | |
134 | - // keep a reference to old query |
|
135 | - $current_global_query = $wp_query; |
|
134 | + // keep a reference to old query |
|
135 | + $current_global_query = $wp_query; |
|
136 | 136 | |
137 | - // assign the query setup in $this-> setup_course_query |
|
138 | - $wp_query = $this->query; |
|
137 | + // assign the query setup in $this-> setup_course_query |
|
138 | + $wp_query = $this->query; |
|
139 | 139 | |
140 | - ob_start(); |
|
141 | - Sensei_Templates::get_template('loop-course.php'); |
|
142 | - $shortcode_output = ob_get_clean(); |
|
140 | + ob_start(); |
|
141 | + Sensei_Templates::get_template('loop-course.php'); |
|
142 | + $shortcode_output = ob_get_clean(); |
|
143 | 143 | |
144 | - //restore old query |
|
145 | - $wp_query = $current_global_query; |
|
144 | + //restore old query |
|
145 | + $wp_query = $current_global_query; |
|
146 | 146 | |
147 | - return $shortcode_output; |
|
147 | + return $shortcode_output; |
|
148 | 148 | |
149 | - }// end render |
|
149 | + }// end render |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Renders the [sensei_unpurchased_courses] shortcode when a user is logged in. If the user is not logged in |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | * @param string $content |
46 | 46 | * @param string $shortcode the shortcode that was called for this instance |
47 | 47 | */ |
48 | - public function __construct( $attributes, $content, $shortcode ){ |
|
48 | + public function __construct($attributes, $content, $shortcode) { |
|
49 | 49 | |
50 | - if( !is_user_logged_in() ) { |
|
50 | + if ( ! is_user_logged_in()) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | // set up all argument need for constructing the course query |
55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
56 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
55 | + $this->number = isset($attributes['number']) ? $attributes['number'] : '10'; |
|
56 | + $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title'; |
|
57 | 57 | |
58 | 58 | // set the default for menu_order to be ASC |
59 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
59 | + if ('menu_order' == $this->orderby && ! isset($attributes['order'])) { |
|
60 | 60 | |
61 | - $this->order = 'ASC'; |
|
61 | + $this->order = 'ASC'; |
|
62 | 62 | |
63 | - }else{ |
|
63 | + } else { |
|
64 | 64 | |
65 | 65 | // for everything else use the value passed or the default DESC |
66 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
66 | + $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC'; |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @since 1.9.0 |
79 | 79 | */ |
80 | - protected function setup_course_query(){ |
|
80 | + protected function setup_course_query() { |
|
81 | 81 | |
82 | 82 | // course query parameters to be used for all courses |
83 | 83 | $query_args = array( |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | ); |
91 | 91 | |
92 | 92 | // get all the courses that has a product attached |
93 | - $all_courses_query = new WP_Query( $query_args ); |
|
93 | + $all_courses_query = new WP_Query($query_args); |
|
94 | 94 | |
95 | 95 | $paid_courses_not_taken = array(); |
96 | 96 | // look through all course and find the purchasable ones that user has not purchased |
97 | - foreach( $all_courses_query->posts as $course ){ |
|
97 | + foreach ($all_courses_query->posts as $course) { |
|
98 | 98 | |
99 | 99 | // only keep the courses with a product including only courses that the user not taking |
100 | - $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true ); |
|
101 | - if( is_numeric( $course_product_id ) |
|
100 | + $course_product_id = get_post_meta($course->ID, '_course_woocommerce_product', true); |
|
101 | + if (is_numeric($course_product_id) |
|
102 | 102 | && |
103 | - ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id() ) |
|
104 | - ){ |
|
103 | + ! Sensei_Utils::user_started_course($course->ID, get_current_user_id()) |
|
104 | + ) { |
|
105 | 105 | |
106 | 106 | $paid_courses_not_taken[] = $course->ID; |
107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | // this query will be loaded into the global WP_Query in the render function. |
115 | 115 | $query_args['post__in'] = $paid_courses_not_taken; |
116 | 116 | $query_args['posts_per_page'] = $this->number; |
117 | - $this->query = new WP_Query( $query_args ); |
|
117 | + $this->query = new WP_Query($query_args); |
|
118 | 118 | |
119 | 119 | }// end setup _course_query |
120 | 120 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return string $content |
125 | 125 | */ |
126 | - public function render(){ |
|
126 | + public function render() { |
|
127 | 127 | |
128 | 128 | global $wp_query; |
129 | 129 | |
130 | - if( ! is_user_logged_in() ) { |
|
130 | + if ( ! is_user_logged_in()) { |
|
131 | 131 | return ''; |
132 | 132 | } |
133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | ob_start(); |
141 | 141 | Sensei_Templates::get_template('loop-course.php'); |
142 | - $shortcode_output = ob_get_clean(); |
|
142 | + $shortcode_output = ob_get_clean(); |
|
143 | 143 | |
144 | 144 | //restore old query |
145 | 145 | $wp_query = $current_global_query; |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Completed_Course' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_Learner_Completed_Course')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Learner Completed Course |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | */ |
31 | 31 | function __construct() { |
32 | 32 | $this->template = 'learner-completed-course'; |
33 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
34 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a course', 'woothemes-sensei' ), $this->template ); |
|
33 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
34 | + $this->heading = apply_filters('sensei_email_heading', __('You have completed a course', 'woothemes-sensei'), $this->template); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -40,32 +40,32 @@ discard block |
||
40 | 40 | * @access public |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - function trigger( $user_id = 0, $course_id = 0 ) { |
|
43 | + function trigger($user_id = 0, $course_id = 0) { |
|
44 | 44 | global $sensei_email_data; |
45 | 45 | |
46 | 46 | // Get learner user object |
47 | - $this->user = new WP_User( $user_id ); |
|
47 | + $this->user = new WP_User($user_id); |
|
48 | 48 | |
49 | 49 | // Get passed status |
50 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
51 | - if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $user_id ) ) { |
|
52 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
50 | + $passed = __('passed', 'woothemes-sensei'); |
|
51 | + if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $user_id)) { |
|
52 | + $passed = __('failed', 'woothemes-sensei'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // Construct data array |
56 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
56 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
57 | 57 | 'template' => $this->template, |
58 | 58 | 'heading' => $this->heading, |
59 | 59 | 'user_id' => $user_id, |
60 | 60 | 'course_id' => $course_id, |
61 | 61 | 'passed' => $passed, |
62 | - ), $this->template ); |
|
62 | + ), $this->template); |
|
63 | 63 | |
64 | 64 | // Set recipient (learner) |
65 | - $this->recipient = stripslashes( $this->user->user_email ); |
|
65 | + $this->recipient = stripslashes($this->user->user_email); |
|
66 | 66 | |
67 | 67 | // Send mail |
68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
68 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Course' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_Teacher_Completed_Course')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Teacher Completed Course |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function __construct() { |
33 | 33 | $this->template = 'teacher-completed-course'; |
34 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
35 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a course', 'woothemes-sensei' ), $this->template ); |
|
34 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your student has completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
35 | + $this->heading = apply_filters('sensei_email_heading', __('Your student has completed a course', 'woothemes-sensei'), $this->template); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | * @access public |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - function trigger( $learner_id = 0, $course_id = 0 ) { |
|
44 | + function trigger($learner_id = 0, $course_id = 0) { |
|
45 | 45 | global $sensei_email_data; |
46 | 46 | |
47 | 47 | // Get learner user object |
48 | - $this->learner = new WP_User( $learner_id ); |
|
48 | + $this->learner = new WP_User($learner_id); |
|
49 | 49 | |
50 | 50 | // Get teacher ID and user object |
51 | - $teacher_id = get_post_field( 'post_author', $course_id, 'raw' ); |
|
52 | - $this->teacher = new WP_User( $teacher_id ); |
|
51 | + $teacher_id = get_post_field('post_author', $course_id, 'raw'); |
|
52 | + $this->teacher = new WP_User($teacher_id); |
|
53 | 53 | |
54 | 54 | // Get passed status |
55 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
56 | - if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $learner_id ) ) { |
|
57 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
55 | + $passed = __('passed', 'woothemes-sensei'); |
|
56 | + if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $learner_id)) { |
|
57 | + $passed = __('failed', 'woothemes-sensei'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Construct data array |
61 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
61 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
62 | 62 | 'template' => $this->template, |
63 | 63 | 'heading' => $this->heading, |
64 | 64 | 'teacher_id' => $teacher_id, |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | 'learner_name' => $this->learner->display_name, |
67 | 67 | 'course_id' => $course_id, |
68 | 68 | 'passed' => $passed, |
69 | - ), $this->template ); |
|
69 | + ), $this->template); |
|
70 | 70 | |
71 | 71 | // Set recipient (learner) |
72 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
72 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
73 | 73 | |
74 | 74 | // Send mail |
75 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
75 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | * |
19 | 19 | ***************************/ |
20 | 20 | //This hook allow us to change the template WordPress loads for a given page/post_type @since 1.9.0 |
21 | -add_filter( 'template_include', array ( 'Sensei_Templates', 'template_loader' ), 10, 1 ); |
|
21 | +add_filter('template_include', array('Sensei_Templates', 'template_loader'), 10, 1); |
|
22 | 22 | |
23 | 23 | //This hook adds the sensei pagination to the pagination hook |
24 | -add_action( 'sensei_pagination', array( 'Sensei_Frontend', 'load_content_pagination' ), 30 ); |
|
24 | +add_action('sensei_pagination', array('Sensei_Frontend', 'load_content_pagination'), 30); |
|
25 | 25 | |
26 | 26 | |
27 | 27 | /*************************** |
@@ -32,16 +32,16 @@ discard block |
||
32 | 32 | * |
33 | 33 | ***************************/ |
34 | 34 | // deprecate the archive content hook @since 1.9.0 |
35 | -add_action( 'sensei_archive_before_course_loop', array ( 'Sensei_Templates', 'deprecated_archive_course_content_hook' ), 10, 1 ); |
|
35 | +add_action('sensei_archive_before_course_loop', array('Sensei_Templates', 'deprecated_archive_course_content_hook'), 10, 1); |
|
36 | 36 | |
37 | 37 | // Course archive title hook @since 1.9.0 |
38 | -add_action('sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 ); |
|
38 | +add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'archive_header'), 10, 0); |
|
39 | 39 | |
40 | 40 | // add the course image above the content |
41 | -add_action('sensei_course_content_inside_before', array( Sensei()->course, 'course_image' ) ,10, 1 ); |
|
41 | +add_action('sensei_course_content_inside_before', array(Sensei()->course, 'course_image'), 10, 1); |
|
42 | 42 | |
43 | 43 | // add course content title to the courses on the archive page |
44 | -add_action('sensei_course_content_inside_before', array( 'Sensei_Templates', 'the_title' ) ,5, 1 ); |
|
44 | +add_action('sensei_course_content_inside_before', array('Sensei_Templates', 'the_title'), 5, 1); |
|
45 | 45 | |
46 | 46 | /*************************** |
47 | 47 | * |
@@ -53,28 +53,28 @@ discard block |
||
53 | 53 | // @1.9.0 |
54 | 54 | // add deprecated action hooks for backwards compatibility sake |
55 | 55 | // hooks on single course page: sensei_course_image , sensei_course_single_title, sensei_course_single_meta |
56 | -add_action('sensei_single_course_content_inside_before', array( 'Sensei_Templates', 'deprecated_single_course_inside_before_hooks' ), 80); |
|
56 | +add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecated_single_course_inside_before_hooks'), 80); |
|
57 | 57 | |
58 | 58 | // @1.9.0 |
59 | 59 | // hook the single course title on the single course page |
60 | -add_action( 'sensei_single_course_content_inside_before',array( 'Sensei_Course', 'the_title'), 10 ); |
|
60 | +add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_title'), 10); |
|
61 | 61 | |
62 | 62 | // @1.9.0 |
63 | 63 | //Add legacy hooks deprecated in 1.9.0 |
64 | -add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Templates','deprecate_course_single_meta_hooks'), 10 ); |
|
64 | +add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecate_course_single_meta_hooks'), 10); |
|
65 | 65 | |
66 | 66 | // @1.9.0 |
67 | 67 | // Filter the content and replace it with the excerpt if the user doesn't have full access |
68 | -add_filter( 'the_content', array('Sensei_Course', 'single_course_content' ) ); |
|
68 | +add_filter('the_content', array('Sensei_Course', 'single_course_content')); |
|
69 | 69 | |
70 | 70 | // @1.9.0 |
71 | 71 | // Deprecate lessons specific single course hooks |
72 | -add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_course_single_lessons_hook' ) ); |
|
72 | +add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_course_single_lessons_hook')); |
|
73 | 73 | |
74 | 74 | // @1.9.0 |
75 | 75 | // Deprecate single main content hooks |
76 | -add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') ); |
|
77 | -add_action( 'sensei_single_message_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') ); |
|
76 | +add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook')); |
|
77 | +add_action('sensei_single_message_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook')); |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Deprecate all the post type single titile hooks in favor of before content and after content hooks |
@@ -82,62 +82,62 @@ discard block |
||
82 | 82 | * @deprecate 1.9.0 |
83 | 83 | * @1.9.0 |
84 | 84 | */ |
85 | -add_action('sensei_single_message_content_inside_before', array( 'Sensei_Templates', 'deprecate_all_post_type_single_title_hooks' ) ); |
|
85 | +add_action('sensei_single_message_content_inside_before', array('Sensei_Templates', 'deprecate_all_post_type_single_title_hooks')); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Deprecate hooks into the single course modules |
89 | 89 | * @deprecated since 1.9.0 |
90 | 90 | */ |
91 | -add_action('sensei_single_course_modules_before', array('Sensei_Templates','deprecate_module_before_hook' ) ); |
|
92 | -add_action('sensei_single_course_modules_after', array('Sensei_Templates','deprecate_module_after_hook' ) ); |
|
91 | +add_action('sensei_single_course_modules_before', array('Sensei_Templates', 'deprecate_module_before_hook')); |
|
92 | +add_action('sensei_single_course_modules_after', array('Sensei_Templates', 'deprecate_module_after_hook')); |
|
93 | 93 | |
94 | 94 | // @since 1.9.0 |
95 | 95 | // add the single course lessons title |
96 | -add_action( 'sensei_single_course_content_inside_after' , array( 'Sensei_Course','the_course_lessons_title'), 9 ); |
|
96 | +add_action('sensei_single_course_content_inside_after', array('Sensei_Course', 'the_course_lessons_title'), 9); |
|
97 | 97 | |
98 | 98 | // @since 1.9.0 |
99 | 99 | // hooks in the course lessons query and remove it at the end |
100 | 100 | // also loading the course lessons template in the middle |
101 | -add_action( 'sensei_single_course_lessons_before', array('Sensei_Course','load_single_course_lessons_query' ) ); |
|
102 | -add_action( 'sensei_single_course_content_inside_after', 'course_single_lessons', 10 ); |
|
103 | -add_action( 'sensei_single_course_lessons_after', array( 'Sensei_Utils','restore_wp_query' )); |
|
101 | +add_action('sensei_single_course_lessons_before', array('Sensei_Course', 'load_single_course_lessons_query')); |
|
102 | +add_action('sensei_single_course_content_inside_after', 'course_single_lessons', 10); |
|
103 | +add_action('sensei_single_course_lessons_after', array('Sensei_Utils', 'restore_wp_query')); |
|
104 | 104 | |
105 | 105 | // @since 1.9.0 |
106 | 106 | // add post classes to the lessons on the single course page |
107 | -add_filter( 'post_class', array( 'Sensei_Lesson', 'single_course_lessons_classes' ) ); |
|
107 | +add_filter('post_class', array('Sensei_Lesson', 'single_course_lessons_classes')); |
|
108 | 108 | |
109 | 109 | // @since 1.9.0 |
110 | 110 | // lesson meta information on the single course page |
111 | -add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_meta') , 5); |
|
111 | +add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_meta'), 5); |
|
112 | 112 | |
113 | 113 | //@since 1.9.0 |
114 | 114 | // lesson image |
115 | -add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_thumbnail') , 8); |
|
115 | +add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_thumbnail'), 8); |
|
116 | 116 | |
117 | 117 | //@since 1.9.0 |
118 | 118 | // lesson custom excerpts |
119 | -add_filter( 'get_the_excerpt', array( 'Sensei_Lesson', 'alter_the_lesson_excerpt' ) ); |
|
119 | +add_filter('get_the_excerpt', array('Sensei_Lesson', 'alter_the_lesson_excerpt')); |
|
120 | 120 | |
121 | 121 | // @since 1.9.0 |
122 | 122 | // run a deprecated hook for backwards compatibility sake |
123 | -add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content' ) ); |
|
123 | +add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content')); |
|
124 | 124 | |
125 | 125 | // @since 1.9.0 |
126 | 126 | // hook in the module loop intialization functionality |
127 | -add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'setup_single_course_module_loop' ) ); |
|
127 | +add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'setup_single_course_module_loop')); |
|
128 | 128 | |
129 | 129 | // @since 1.9.0 |
130 | 130 | // hook in the module loop destructor functionality |
131 | -add_action( 'sensei_single_course_modules_after', array( 'Sensei_Core_Modules', 'teardown_single_course_module_loop' ) ); |
|
131 | +add_action('sensei_single_course_modules_after', array('Sensei_Core_Modules', 'teardown_single_course_module_loop')); |
|
132 | 132 | |
133 | 133 | // @since 1.9.0 |
134 | 134 | // hook in the possible full content override to show instead of excerpt |
135 | -add_filter('get_the_excerpt', array( 'Sensei_Course', 'full_content_excerpt_override' ) ); |
|
135 | +add_filter('get_the_excerpt', array('Sensei_Course', 'full_content_excerpt_override')); |
|
136 | 136 | |
137 | 137 | //@since 1.9.0 |
138 | 138 | //Course meta |
139 | -add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course', 'the_course_enrolment_actions' ), 30 ); |
|
140 | -add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course' , 'the_course_video' ), 40 ); |
|
139 | +add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_enrolment_actions'), 30); |
|
140 | +add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_video'), 40); |
|
141 | 141 | |
142 | 142 | /*************************** |
143 | 143 | * |
@@ -148,54 +148,54 @@ discard block |
||
148 | 148 | ***************************/ |
149 | 149 | //@since 1.9.0 |
150 | 150 | // deprecate hooks no longer needed |
151 | -add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook' ) ); |
|
152 | -add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook' ) ); |
|
151 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook')); |
|
152 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook')); |
|
153 | 153 | |
154 | 154 | //@since 1.9.0 |
155 | 155 | // Single quiz title |
156 | -add_filter( 'the_title', array( 'Sensei_Quiz' , 'single_quiz_title' ), 20 , 2 ); // append Quiz |
|
157 | -add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_title' ), 20 ); //output single quiz |
|
156 | +add_filter('the_title', array('Sensei_Quiz', 'single_quiz_title'), 20, 2); // append Quiz |
|
157 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_title'), 20); //output single quiz |
|
158 | 158 | |
159 | 159 | // since 1.9.0 |
160 | 160 | // initialize the quiz questions loop |
161 | -add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'start_quiz_questions_loop') ); |
|
161 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'start_quiz_questions_loop')); |
|
162 | 162 | |
163 | 163 | // since 1.9.0 |
164 | 164 | // hook in the quiz user message |
165 | -add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_user_status_message' ), 40 ); |
|
165 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_user_status_message'), 40); |
|
166 | 166 | |
167 | 167 | //@since 1.9.0 |
168 | 168 | // hook in the question title, description and quesiton media |
169 | -add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_title' ), 10 ); |
|
170 | -add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_description' ), 20 ); |
|
171 | -add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_media' ), 30 ); |
|
172 | -add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_hidden_fields' ), 40 ); |
|
169 | +add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_title'), 10); |
|
170 | +add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_description'), 20); |
|
171 | +add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_media'), 30); |
|
172 | +add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_hidden_fields'), 40); |
|
173 | 173 | |
174 | 174 | //@since 1.9.0 |
175 | 175 | // hook in incorrect / correct message above questions if the quiz has been graded |
176 | -add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question', 'the_answer_result_indication' ), 50 ); |
|
176 | +add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_answer_result_indication'), 50); |
|
177 | 177 | |
178 | 178 | //@since 1.9.0 |
179 | 179 | // add answer grading feedback at the bottom of the question |
180 | -add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Question', 'answer_feedback_notes' ) ); |
|
180 | +add_action('sensei_quiz_question_inside_after', array('Sensei_Question', 'answer_feedback_notes')); |
|
181 | 181 | |
182 | 182 | //@since 1.9.0 |
183 | 183 | // add extra question data for different quesiton types when get_question_template_data_is_called. |
184 | -add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','multiple_choice_load_question_data'), 10, 3); |
|
185 | -add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','gap_fill_load_question_data'), 10, 3); |
|
186 | -add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','file_upload_load_question_data'), 10, 3); |
|
184 | +add_filter('sensei_get_question_template_data', array('Sensei_Question', 'multiple_choice_load_question_data'), 10, 3); |
|
185 | +add_filter('sensei_get_question_template_data', array('Sensei_Question', 'gap_fill_load_question_data'), 10, 3); |
|
186 | +add_filter('sensei_get_question_template_data', array('Sensei_Question', 'file_upload_load_question_data'), 10, 3); |
|
187 | 187 | |
188 | 188 | //@since 1.9.0 |
189 | 189 | // deprecate the quiz button action |
190 | -add_action( 'sensei_single_quiz_questions_after', array( 'Sensei_Quiz', 'action_buttons' ), 10, 0 ); |
|
190 | +add_action('sensei_single_quiz_questions_after', array('Sensei_Quiz', 'action_buttons'), 10, 0); |
|
191 | 191 | |
192 | 192 | //@since 1.9.0 |
193 | 193 | // deprecate the sensei_complete_quiz hook |
194 | -add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_complete_quiz_action' )); |
|
194 | +add_action('sensei_single_quiz_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_complete_quiz_action')); |
|
195 | 195 | |
196 | 196 | //@since 1.9.0 |
197 | 197 | // deprecate the sensei_quiz_question_type hook |
198 | -add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_quiz_question_type_action' )); |
|
198 | +add_action('sensei_quiz_question_inside_after', array('Sensei_Templates', 'deprecate_sensei_quiz_question_type_action')); |
|
199 | 199 | |
200 | 200 | /*************************** |
201 | 201 | * |
@@ -206,63 +206,63 @@ discard block |
||
206 | 206 | ***************************/ |
207 | 207 | //@since 1.9.0 |
208 | 208 | // deprecate the main content hook on the single lesson page |
209 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_lesson_single_main_content_hook' ), 20); |
|
209 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_single_main_content_hook'), 20); |
|
210 | 210 | |
211 | 211 | //@since 1.9.0 |
212 | 212 | // hook in the lesson image on the single lesson |
213 | -add_action( 'sensei_single_lesson_content_inside_before', array( Sensei()->lesson, 'lesson_image' ), 10 ); |
|
213 | +add_action('sensei_single_lesson_content_inside_before', array(Sensei()->lesson, 'lesson_image'), 10); |
|
214 | 214 | |
215 | 215 | //@since 1.9.0 |
216 | 216 | // hook in the lesson image on the single lesson deprecated hook function |
217 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates','deprecate_lesson_image_hook' ), 10 ); |
|
217 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_image_hook'), 10); |
|
218 | 218 | |
219 | 219 | //@since 1.9.0 |
220 | 220 | // hook in the lesson single title deprecated function |
221 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_title' ), 15 ); |
|
221 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_lesson_single_title'), 15); |
|
222 | 222 | |
223 | 223 | // @since 1.9.0 |
224 | 224 | // hook in the sensei lesson user notices |
225 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_not_taking_course_message' ), 15 ); |
|
225 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_not_taking_course_message'), 15); |
|
226 | 226 | |
227 | 227 | // @since 1.9.0 |
228 | 228 | // attach the lesson title |
229 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'the_title' ), 15 ); |
|
229 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'the_title'), 15); |
|
230 | 230 | |
231 | 231 | //@since 1.9.0 |
232 | 232 | // hook in the lesson image on the single lesson |
233 | -add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_lesson_quiz_status_message' ), 20 ); |
|
233 | +add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_lesson_quiz_status_message'), 20); |
|
234 | 234 | |
235 | 235 | // @since 1.9.0 |
236 | 236 | // add the single lesson meta |
237 | -add_action( 'sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10 ); |
|
237 | +add_action('sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10); |
|
238 | 238 | |
239 | 239 | // @since 1.9.0 |
240 | 240 | // deprecate the sensei_lesson_single_meta hook |
241 | -add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook' ), 15 ); |
|
241 | +add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook'), 15); |
|
242 | 242 | |
243 | 243 | // @since 1.9.0 |
244 | 244 | // deprecate the sensei_lesson_course_signup hook |
245 | -add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_lesson_course_signup_hook' ), 20 ); |
|
245 | +add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_course_signup_hook'), 20); |
|
246 | 246 | |
247 | 247 | // @since 1.9.0 |
248 | 248 | // hook in the lesson prerequisite completion message |
249 | -add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Lesson', 'prerequisite_complete_message' ), 20 ); |
|
249 | +add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'prerequisite_complete_message'), 20); |
|
250 | 250 | |
251 | 251 | // @since 1.9.0 |
252 | 252 | // hook the single lesson course_signup_link |
253 | -add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Lesson', 'course_signup_link' ), 30 ); |
|
253 | +add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'course_signup_link'), 30); |
|
254 | 254 | |
255 | 255 | // @since 1.9.0 |
256 | 256 | // hook the deprecate breadcrumbs and comments hooks |
257 | -add_action( 'sensei_after_main_content', array( 'Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5 ); |
|
257 | +add_action('sensei_after_main_content', array('Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5); |
|
258 | 258 | |
259 | 259 | // @since 1.9.0 |
260 | 260 | // Add the quiz specific buttons and notices to the lesson |
261 | -add_action( 'sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action' )); |
|
261 | +add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action')); |
|
262 | 262 | |
263 | 263 | // @since 1.9.0 |
264 | 264 | // hook in the comments on the single lessons page |
265 | -add_action( 'sensei_pagination', array( 'Sensei_Lesson', 'output_comments' ), 90 ); |
|
265 | +add_action('sensei_pagination', array('Sensei_Lesson', 'output_comments'), 90); |
|
266 | 266 | |
267 | 267 | /********************** |
268 | 268 | * |
@@ -272,9 +272,9 @@ discard block |
||
272 | 272 | * |
273 | 273 | ************************/ |
274 | 274 | |
275 | -add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_title' ), 20 ); |
|
275 | +add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_title'), 20); |
|
276 | 276 | |
277 | -add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_message_sent_by_title' ), 40 ); |
|
277 | +add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_message_sent_by_title'), 40); |
|
278 | 278 | |
279 | 279 | /************************* |
280 | 280 | * |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | |
287 | 287 | // deprecate the sensei_lesson_archive_header hook |
288 | 288 | // @deprecated since 1.9.0 |
289 | -add_action( 'sensei_loop_lesson_inside_before', array( 'Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook' ), 20 ); |
|
289 | +add_action('sensei_loop_lesson_inside_before', array('Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook'), 20); |
|
290 | 290 | |
291 | 291 | // @1.9.0 |
292 | 292 | //The archive title header on the lesson archive loop |
293 | -add_action( 'sensei_loop_lesson_inside_before', array( Sensei()->lesson, 'the_archive_header' ), 20 ); |
|
293 | +add_action('sensei_loop_lesson_inside_before', array(Sensei()->lesson, 'the_archive_header'), 20); |
|
294 | 294 | |
295 | 295 | // @since 1.9.0 |
296 | 296 | //Output the lesson header on the content-lesson.php which runs inside the lessons loop |
297 | -add_action( 'sensei_content_lesson_inside_before', array( 'Sensei_Lesson', 'the_lesson_meta' ), 20 ); |
|
297 | +add_action('sensei_content_lesson_inside_before', array('Sensei_Lesson', 'the_lesson_meta'), 20); |
|
298 | 298 | |
299 | 299 | /************************** |
300 | 300 | * |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | **************************/ |
306 | 306 | // @since 1.9.0 |
307 | 307 | // deprecate the learner profile content hook as the markup code is added in the template directly. |
308 | -add_action('sensei_learner_profile_content_before', array( 'Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook' ) ); |
|
308 | +add_action('sensei_learner_profile_content_before', array('Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook')); |
|
309 | 309 | |
310 | 310 | // @since 1.9.0 |
311 | 311 | // do the sensei complete course action on the learner profiles page. |
312 | -add_action('sensei_learner_profile_content_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) ); |
|
312 | +add_action('sensei_learner_profile_content_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook')); |
|
313 | 313 | |
314 | 314 | // @since 1.9.0 |
315 | 315 | // fire the frontend messages hook before the profile content |
316 | -add_action('sensei_learner_profile_inside_content_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) ); |
|
316 | +add_action('sensei_learner_profile_inside_content_before', array('Sensei_Templates', 'fire_frontend_messages_hook')); |
|
317 | 317 | |
318 | 318 | |
319 | 319 | /********************************** |
@@ -326,23 +326,23 @@ discard block |
||
326 | 326 | |
327 | 327 | // @since 1.9.0 |
328 | 328 | // fire the deprecated hook function within the course-result.php file |
329 | -add_action( 'sensei_course_results_content_before', array('Sensei_Course_Results','deprecate_sensei_course_results_content_hook') ); |
|
329 | +add_action('sensei_course_results_content_before', array('Sensei_Course_Results', 'deprecate_sensei_course_results_content_hook')); |
|
330 | 330 | |
331 | 331 | // @since 1.9.0 |
332 | 332 | // fire the sensei message hooke inside the course-result.php file |
333 | -add_action( 'sensei_course_results_content_inside_before', array('Sensei_Course_Results','fire_sensei_message_hook') ); |
|
333 | +add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_sensei_message_hook')); |
|
334 | 334 | |
335 | 335 | // @since 1.9.0 |
336 | 336 | // load the course information on the course results page |
337 | -add_action( 'sensei_course_results_content_inside_after', array( Sensei()->course_results,'course_info') ); |
|
337 | +add_action('sensei_course_results_content_inside_after', array(Sensei()->course_results, 'course_info')); |
|
338 | 338 | |
339 | 339 | // @since 1.9.0 |
340 | 340 | // deprecate the course results top hook in favour of a new hook |
341 | -add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'deprecate_course_results_top_hook') ); |
|
341 | +add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'deprecate_course_results_top_hook')); |
|
342 | 342 | |
343 | 343 | // @since 1.9.0 |
344 | 344 | // Fire the course image hook within the course results page |
345 | -add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'fire_course_image_hook') ); |
|
345 | +add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_course_image_hook')); |
|
346 | 346 | |
347 | 347 | |
348 | 348 | /********************************** |
@@ -354,19 +354,19 @@ discard block |
||
354 | 354 | ********************************/ |
355 | 355 | // @since 1.9.0 |
356 | 356 | // fire the sensei complete course action on the my courses template |
357 | -add_action( 'sensei_my_courses_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) ); |
|
357 | +add_action('sensei_my_courses_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook')); |
|
358 | 358 | |
359 | 359 | // @since 1.9.0 |
360 | 360 | // fire the sensei frontend messages hook before the my-courses content |
361 | -add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) ); |
|
361 | +add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'fire_frontend_messages_hook')); |
|
362 | 362 | |
363 | 363 | // @since 1.9.0 |
364 | 364 | // deprecate the sensei_before_user_course_content hook |
365 | -add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook' ) ); |
|
365 | +add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook')); |
|
366 | 366 | |
367 | 367 | // @since 1.9.0 |
368 | 368 | // deprecate the sensei_after_user_course_content hook |
369 | -add_action('sensei_my_courses_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook' ) ); |
|
369 | +add_action('sensei_my_courses_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook')); |
|
370 | 370 | |
371 | 371 | /********************************** |
372 | 372 | * |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | // @since 1.9.0 |
379 | 379 | // deprecate the sensei_login_form hok which was use to load the login form. |
380 | 380 | // This now loads independent of the my-courses template which helps keep templates free from logic |
381 | -add_action( 'sensei_login_form_before', array( 'Sensei_Templates', 'deprecate_sensei_login_form_hook' ) ); |
|
381 | +add_action('sensei_login_form_before', array('Sensei_Templates', 'deprecate_sensei_login_form_hook')); |
|
382 | 382 | |
383 | 383 | /********************************** |
384 | 384 | * |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | ********************************/ |
390 | 390 | // @since 1.9.0 |
391 | 391 | // Deprecate the archive messages hooks no longer supported |
392 | -add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Templates', 'deprecated_archive_message_hooks' ) ); |
|
392 | +add_action('sensei_archive_before_message_loop', array('Sensei_Templates', 'deprecated_archive_message_hooks')); |
|
393 | 393 | |
394 | 394 | // @since 1.9.0 |
395 | 395 | // Deprecate the archive messages hooks no longer supported |
396 | -add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Messages', 'the_archive_header' ) ); |
|
396 | +add_action('sensei_archive_before_message_loop', array('Sensei_Messages', 'the_archive_header')); |
|
397 | 397 | |
398 | 398 | // @since 1.9.0 |
399 | 399 | // output the message title and the message sensei |
400 | -add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_title' ), 10, 1 ); |
|
401 | -add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_sender' ), 20 , 1 ); |
|
400 | +add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_title'), 10, 1); |
|
401 | +add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_sender'), 20, 1); |
|
402 | 402 | |
403 | 403 | /********************************** |
404 | 404 | * |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * |
408 | 408 | * |
409 | 409 | **********************************/ |
410 | -add_action( 'sensei_loop_course_before', array( 'Sensei_Course', 'course_category_title' ), 70 , 1 ); |
|
410 | +add_action('sensei_loop_course_before', array('Sensei_Course', 'course_category_title'), 70, 1); |
|
411 | 411 | |
412 | 412 | /********************************** |
413 | 413 | * |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | **********************************/ |
419 | 419 | //@since 1.9.0 |
420 | 420 | //add a title to the teacher archive page when viewn siteurl/author/{teacher-username} |
421 | -add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'archive_title' ) ); |
|
421 | +add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'archive_title')); |
|
422 | 422 | |
423 | 423 | //@since 1.9.0 |
424 | 424 | // remove course meta from the teacher page until it can be refactored to allow only removing the |
425 | 425 | // teacher name and not all lessons |
426 | -add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'remove_course_meta_on_teacher_archive' ) ); |
|
426 | +add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'remove_course_meta_on_teacher_archive')); |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Utilities Class |
@@ -181,8 +184,7 @@ discard block |
||
181 | 184 | // ...use a filter to switch the encoding back |
182 | 185 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
183 | 186 | } |
184 | - } |
|
185 | - else { |
|
187 | + } else { |
|
186 | 188 | $args['status'] = 'any'; // 'log' == 'sensei_user_answer' |
187 | 189 | } |
188 | 190 | |
@@ -307,8 +309,12 @@ discard block |
||
307 | 309 | } |
308 | 310 | |
309 | 311 | foreach( $activities as $activity ) { |
310 | - if( '' == $activity->comment_type ) continue; |
|
311 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
312 | + if( '' == $activity->comment_type ) { |
|
313 | + continue; |
|
314 | + } |
|
315 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
316 | + continue; |
|
317 | + } |
|
312 | 318 | $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
313 | 319 | wp_cache_flush(); |
314 | 320 | } |
@@ -360,11 +366,13 @@ discard block |
||
360 | 366 | $emails[] = $user->user_email; |
361 | 367 | } |
362 | 368 | |
363 | - if ( is_email( $customer_email ) ) |
|
364 | - $emails[] = $customer_email; |
|
369 | + if ( is_email( $customer_email ) ) { |
|
370 | + $emails[] = $customer_email; |
|
371 | + } |
|
365 | 372 | |
366 | - if ( sizeof( $emails ) == 0 ) |
|
367 | - return false; |
|
373 | + if ( sizeof( $emails ) == 0 ) { |
|
374 | + return false; |
|
375 | + } |
|
368 | 376 | |
369 | 377 | return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
370 | 378 | |
@@ -379,7 +387,9 @@ discard block |
||
379 | 387 | */ |
380 | 388 | public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
381 | 389 | |
382 | - if( ! $input_name ) $input_name = $editor_id; |
|
390 | + if( ! $input_name ) { |
|
391 | + $input_name = $editor_id; |
|
392 | + } |
|
383 | 393 | |
384 | 394 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
385 | 395 | |
@@ -689,8 +699,7 @@ discard block |
||
689 | 699 | if ( $has_questions ) { |
690 | 700 | $status = 'passed'; // Force a pass |
691 | 701 | $metadata['grade'] = 0; |
692 | - } |
|
693 | - else { |
|
702 | + } else { |
|
694 | 703 | $status = 'complete'; |
695 | 704 | } |
696 | 705 | } |
@@ -738,7 +747,9 @@ discard block |
||
738 | 747 | public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
739 | 748 | |
740 | 749 | |
741 | - if( ! $lesson_id ) return false; |
|
750 | + if( ! $lesson_id ) { |
|
751 | + return false; |
|
752 | + } |
|
742 | 753 | |
743 | 754 | if( intval( $user_id ) == 0 ) { |
744 | 755 | $user_id = get_current_user_id(); |
@@ -776,7 +787,9 @@ discard block |
||
776 | 787 | public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
777 | 788 | |
778 | 789 | |
779 | - if( ! $course_id ) return false; |
|
790 | + if( ! $course_id ) { |
|
791 | + return false; |
|
792 | + } |
|
780 | 793 | |
781 | 794 | if( intval( $user_id ) == 0 ) { |
782 | 795 | $user_id = get_current_user_id(); |
@@ -844,8 +857,7 @@ discard block |
||
844 | 857 | if( $question ) { |
845 | 858 | if ( is_object( $question ) ) { |
846 | 859 | $user_answer_id = $question->comment_ID; |
847 | - } |
|
848 | - else { |
|
860 | + } else { |
|
849 | 861 | if( intval( $user_id ) == 0 ) { |
850 | 862 | $user_id = get_current_user_id(); |
851 | 863 | } |
@@ -872,8 +884,7 @@ discard block |
||
872 | 884 | if( $question ) { |
873 | 885 | if ( is_object( $question ) ) { |
874 | 886 | $user_answer_id = $question->comment_ID; |
875 | - } |
|
876 | - else { |
|
887 | + } else { |
|
877 | 888 | if( intval( $user_id ) == 0 ) { |
878 | 889 | $user_id = get_current_user_id(); |
879 | 890 | } |
@@ -938,8 +949,7 @@ discard block |
||
938 | 949 | if ( !empty($notes) ) { |
939 | 950 | $user_lesson_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
940 | 951 | $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
941 | - } |
|
942 | - else { |
|
952 | + } else { |
|
943 | 953 | $activity_logged = true; |
944 | 954 | } |
945 | 955 | } |
@@ -1451,8 +1461,7 @@ discard block |
||
1451 | 1461 | $lessons_completed++; |
1452 | 1462 | break; |
1453 | 1463 | } |
1454 | - } |
|
1455 | - else { |
|
1464 | + } else { |
|
1456 | 1465 | switch ( $lesson_status->comment_approved ) { |
1457 | 1466 | case 'complete': // Lesson has no quiz/questions |
1458 | 1467 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
@@ -1500,11 +1509,9 @@ discard block |
||
1500 | 1509 | if( $course ) { |
1501 | 1510 | if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
1502 | 1511 | $user_course_status = $course->comment_approved; |
1503 | - } |
|
1504 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
1512 | + } elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
1505 | 1513 | $user_course_status = $course; |
1506 | - } |
|
1507 | - else { |
|
1514 | + } else { |
|
1508 | 1515 | if( ! $user_id ) { |
1509 | 1516 | $user_id = get_current_user_id(); |
1510 | 1517 | } |
@@ -1564,11 +1571,9 @@ discard block |
||
1564 | 1571 | if ( is_object( $lesson ) ) { |
1565 | 1572 | $user_lesson_status = $lesson->comment_approved; |
1566 | 1573 | $lesson_id = $lesson->comment_post_ID; |
1567 | - } |
|
1568 | - elseif ( ! is_numeric( $lesson ) ) { |
|
1574 | + } elseif ( ! is_numeric( $lesson ) ) { |
|
1569 | 1575 | $user_lesson_status = $lesson; |
1570 | - } |
|
1571 | - else { |
|
1576 | + } else { |
|
1572 | 1577 | if( ! $user_id ) { |
1573 | 1578 | $user_id = get_current_user_id(); |
1574 | 1579 | } |
@@ -1581,8 +1586,7 @@ discard block |
||
1581 | 1586 | |
1582 | 1587 | if ( $_user_lesson_status ) { |
1583 | 1588 | $user_lesson_status = $_user_lesson_status->comment_approved; |
1584 | - } |
|
1585 | - else { |
|
1589 | + } else { |
|
1586 | 1590 | return false; // No status means not complete |
1587 | 1591 | } |
1588 | 1592 | $lesson_id = $lesson; |
@@ -1683,7 +1687,9 @@ discard block |
||
1683 | 1687 | |
1684 | 1688 | public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
1685 | 1689 | |
1686 | - if( ! $quiz_id ) return false; |
|
1690 | + if( ! $quiz_id ) { |
|
1691 | + return false; |
|
1692 | + } |
|
1687 | 1693 | |
1688 | 1694 | if( ! $user_id ) { |
1689 | 1695 | $user_id = get_current_user_id(); |
@@ -1921,7 +1927,7 @@ discard block |
||
1921 | 1927 | $start_function = 'user_start_'.$post_type; |
1922 | 1928 | $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
1923 | 1929 | |
1924 | - }else{ |
|
1930 | + } else{ |
|
1925 | 1931 | |
1926 | 1932 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
1927 | 1933 | |
@@ -2138,7 +2144,7 @@ discard block |
||
2138 | 2144 | |
2139 | 2145 | return round( $val, $precision, $mode ); |
2140 | 2146 | |
2141 | - }else{ |
|
2147 | + } else{ |
|
2142 | 2148 | |
2143 | 2149 | return round( $val, $precision ); |
2144 | 2150 |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param string $customer_email |
346 | 346 | * @param int $user_id |
347 | 347 | * @param int $product_id |
348 | - * @return bool |
|
348 | + * @return boolean|null |
|
349 | 349 | */ |
350 | 350 | public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
351 | 351 | |
@@ -464,6 +464,9 @@ discard block |
||
464 | 464 | |
465 | 465 | } // End sensei_save_quiz_answers() |
466 | 466 | |
467 | + /** |
|
468 | + * @return string |
|
469 | + */ |
|
467 | 470 | public static function upload_file( $file = array() ) { |
468 | 471 | |
469 | 472 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
@@ -636,7 +639,7 @@ discard block |
||
636 | 639 | * @param integer $lesson_id |
637 | 640 | * @param bool $complete |
638 | 641 | * |
639 | - * @return mixed boolean or comment_ID |
|
642 | + * @return boolean|string boolean or comment_ID |
|
640 | 643 | */ |
641 | 644 | public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
642 | 645 | |
@@ -655,7 +658,7 @@ discard block |
||
655 | 658 | * @param int| string $user_id default 0 |
656 | 659 | * @param bool $complete default false |
657 | 660 | * |
658 | - * @return mixed boolean or comment_ID |
|
661 | + * @return boolean|string boolean or comment_ID |
|
659 | 662 | */ |
660 | 663 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
661 | 664 | |
@@ -834,7 +837,7 @@ discard block |
||
834 | 837 | /** |
835 | 838 | * Returns the user_grade for a specific question and user, or sensei_user_answer entry |
836 | 839 | * |
837 | - * @param mixed $question |
|
840 | + * @param integer $question |
|
838 | 841 | * @param int $user_id |
839 | 842 | * @return string |
840 | 843 | */ |
@@ -862,7 +865,7 @@ discard block |
||
862 | 865 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
863 | 866 | * |
864 | 867 | * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
865 | - * @param mixed $question |
|
868 | + * @param integer $question |
|
866 | 869 | * @param int $user_id |
867 | 870 | * @return string |
868 | 871 | */ |
@@ -975,7 +978,7 @@ discard block |
||
975 | 978 | * sort_array_by_key sorts array by key |
976 | 979 | * @since 1.3.0 |
977 | 980 | * @param array $array by ref |
978 | - * @param $key string column name in array |
|
981 | + * @param string $key string column name in array |
|
979 | 982 | * @return void |
980 | 983 | */ |
981 | 984 | public static function sort_array_by_key( $array, $key ) { |
@@ -1022,7 +1025,7 @@ discard block |
||
1022 | 1025 | /** |
1023 | 1026 | * Get pass mark for course |
1024 | 1027 | * @param integer $course_id ID of course |
1025 | - * @return integer Pass mark for course |
|
1028 | + * @return double Pass mark for course |
|
1026 | 1029 | */ |
1027 | 1030 | public static function sensei_course_pass_grade( $course_id = 0 ) { |
1028 | 1031 | |
@@ -1063,7 +1066,7 @@ discard block |
||
1063 | 1066 | * Get user total grade for course |
1064 | 1067 | * @param integer $course_id ID of course |
1065 | 1068 | * @param integer $user_id ID of user |
1066 | - * @return integer User's total grade |
|
1069 | + * @return double User's total grade |
|
1067 | 1070 | */ |
1068 | 1071 | public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
1069 | 1072 | |
@@ -1323,7 +1326,7 @@ discard block |
||
1323 | 1326 | * @since 1.4.8 |
1324 | 1327 | * @param integer $user_id User ID |
1325 | 1328 | * @param integer $course_id Course ID |
1326 | - * @return mixed boolean or comment_ID |
|
1329 | + * @return string|boolean boolean or comment_ID |
|
1327 | 1330 | */ |
1328 | 1331 | public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
1329 | 1332 | |
@@ -1359,7 +1362,7 @@ discard block |
||
1359 | 1362 | * @since 1.7.0 |
1360 | 1363 | * @param int $course_id |
1361 | 1364 | * @param int $user_id |
1362 | - * @return mixed false or comment_ID |
|
1365 | + * @return false|string false or comment_ID |
|
1363 | 1366 | */ |
1364 | 1367 | public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
1365 | 1368 | |
@@ -1386,7 +1389,7 @@ discard block |
||
1386 | 1389 | * @since 1.7.0 |
1387 | 1390 | * @param integer $course_id Course ID |
1388 | 1391 | * @param integer $user_id User ID |
1389 | - * @return int |
|
1392 | + * @return boolean |
|
1390 | 1393 | */ |
1391 | 1394 | public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
1392 | 1395 | global $wp_version; |
@@ -1535,7 +1538,7 @@ discard block |
||
1535 | 1538 | * @since 1.7.0 |
1536 | 1539 | * @param int $lesson_id |
1537 | 1540 | * @param int $user_id |
1538 | - * @return mixed false or comment_ID |
|
1541 | + * @return string|false false or comment_ID |
|
1539 | 1542 | */ |
1540 | 1543 | public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
1541 | 1544 | |
@@ -1562,7 +1565,7 @@ discard block |
||
1562 | 1565 | * Check if a user has completed a lesson or not |
1563 | 1566 | * |
1564 | 1567 | * @uses Sensei() |
1565 | - * @param mixed $lesson lesson_id or sensei_lesson_status entry |
|
1568 | + * @param integer $lesson lesson_id or sensei_lesson_status entry |
|
1566 | 1569 | * @param int $user_id |
1567 | 1570 | * @return boolean |
1568 | 1571 | */ |
@@ -1660,7 +1663,7 @@ discard block |
||
1660 | 1663 | * @since 1.7.0 |
1661 | 1664 | * @param int $lesson_id |
1662 | 1665 | * @param int $user_id |
1663 | - * @return object | bool |
|
1666 | + * @return integer | bool |
|
1664 | 1667 | */ |
1665 | 1668 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
1666 | 1669 | |
@@ -1719,11 +1722,11 @@ discard block |
||
1719 | 1722 | * @since 1.7.0 |
1720 | 1723 | * |
1721 | 1724 | * @param int|string $user_id |
1722 | - * @param int|string $lesson_id |
|
1725 | + * @param integer $lesson_id |
|
1723 | 1726 | * @param string $status |
1724 | 1727 | * @param array $metadata |
1725 | 1728 | * |
1726 | - * @return mixed false or comment_ID |
|
1729 | + * @return boolean false or comment_ID |
|
1727 | 1730 | */ |
1728 | 1731 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
1729 | 1732 | $comment_id = false; |
@@ -1761,7 +1764,7 @@ discard block |
||
1761 | 1764 | * @param int $course_id |
1762 | 1765 | * @param string $status |
1763 | 1766 | * @param array $metadata |
1764 | - * @return mixed false or comment_ID |
|
1767 | + * @return boolean false or comment_ID |
|
1765 | 1768 | */ |
1766 | 1769 | public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
1767 | 1770 | $comment_id = false; |
@@ -1951,7 +1954,7 @@ discard block |
||
1951 | 1954 | * |
1952 | 1955 | * @since 1.7.4 |
1953 | 1956 | * |
1954 | - * @param $data_key |
|
1957 | + * @param string $data_key |
|
1955 | 1958 | * @param $post_id |
1956 | 1959 | * @param int $user_id |
1957 | 1960 | * |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Check if WooCommerce is present. |
29 | - * |
|
30 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
29 | + * |
|
30 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
31 | 31 | * @access public |
32 | 32 | * @since 1.0.2 |
33 | 33 | * @static |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public static function sensei_is_woocommerce_present () { |
37 | 37 | |
38 | - return Sensei_WC::is_woocommerce_present(); |
|
38 | + return Sensei_WC::is_woocommerce_present(); |
|
39 | 39 | |
40 | 40 | } // End sensei_is_woocommerce_present() |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Check if WooCommerce is active. |
44 | - * |
|
45 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
44 | + * |
|
45 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
46 | 46 | * @access public |
47 | 47 | * @since 1.0.2 |
48 | 48 | * @static |
@@ -187,15 +187,15 @@ discard block |
||
187 | 187 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
188 | 188 | } |
189 | 189 | |
190 | - //Get the comments |
|
191 | - /** |
|
192 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
193 | - * |
|
194 | - * It runs while getting the comments for the given request. |
|
195 | - * |
|
196 | - * @param int|array $comments |
|
197 | - */ |
|
198 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
190 | + //Get the comments |
|
191 | + /** |
|
192 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
193 | + * |
|
194 | + * It runs while getting the comments for the given request. |
|
195 | + * |
|
196 | + * @param int|array $comments |
|
197 | + */ |
|
198 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
199 | 199 | |
200 | 200 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
201 | 201 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -280,18 +280,18 @@ discard block |
||
280 | 280 | return $dataset_changes; |
281 | 281 | } // End sensei_delete_activities() |
282 | 282 | |
283 | - /** |
|
284 | - * Delete all activity for specified user |
|
285 | - * @access public |
|
283 | + /** |
|
284 | + * Delete all activity for specified user |
|
285 | + * @access public |
|
286 | 286 | * @since 1.5.0 |
287 | - * @param integer $user_id User ID |
|
288 | - * @return boolean |
|
289 | - */ |
|
290 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
287 | + * @param integer $user_id User ID |
|
288 | + * @return boolean |
|
289 | + */ |
|
290 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
291 | 291 | |
292 | - $dataset_changes = false; |
|
292 | + $dataset_changes = false; |
|
293 | 293 | |
294 | - if( $user_id ) { |
|
294 | + if( $user_id ) { |
|
295 | 295 | |
296 | 296 | $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
297 | 297 | |
@@ -336,35 +336,35 @@ discard block |
||
336 | 336 | return $activity_value; |
337 | 337 | } // End sensei_get_activity_value() |
338 | 338 | |
339 | - /** |
|
340 | - * Checks if a user (by email) has bought an item. |
|
341 | - * |
|
342 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
343 | - * @access public |
|
344 | - * @since 1.0.0 |
|
345 | - * @param string $customer_email |
|
346 | - * @param int $user_id |
|
347 | - * @param int $product_id |
|
348 | - * @return bool |
|
349 | - */ |
|
350 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
339 | + /** |
|
340 | + * Checks if a user (by email) has bought an item. |
|
341 | + * |
|
342 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
343 | + * @access public |
|
344 | + * @since 1.0.0 |
|
345 | + * @param string $customer_email |
|
346 | + * @param int $user_id |
|
347 | + * @param int $product_id |
|
348 | + * @return bool |
|
349 | + */ |
|
350 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
351 | 351 | |
352 | - $emails = array(); |
|
352 | + $emails = array(); |
|
353 | 353 | |
354 | - if ( $user_id ) { |
|
355 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
356 | - $emails[] = $user->user_email; |
|
357 | - } |
|
354 | + if ( $user_id ) { |
|
355 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
356 | + $emails[] = $user->user_email; |
|
357 | + } |
|
358 | 358 | |
359 | - if ( is_email( $customer_email ) ) |
|
360 | - $emails[] = $customer_email; |
|
359 | + if ( is_email( $customer_email ) ) |
|
360 | + $emails[] = $customer_email; |
|
361 | 361 | |
362 | - if ( sizeof( $emails ) == 0 ) |
|
363 | - return false; |
|
362 | + if ( sizeof( $emails ) == 0 ) |
|
363 | + return false; |
|
364 | 364 | |
365 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
365 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
366 | 366 | |
367 | - } // End sensei_customer_bought_product() |
|
367 | + } // End sensei_customer_bought_product() |
|
368 | 368 | |
369 | 369 | /** |
370 | 370 | * Load the WordPress rich text editor |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | /** |
401 | 401 | * Save quiz answers submitted by users |
402 | 402 | * @param array $submitted User's quiz answers |
403 | - * @param int $user_id |
|
403 | + * @param int $user_id |
|
404 | 404 | * @return boolean Whether the answers were saved or not |
405 | 405 | */ |
406 | 406 | public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
@@ -468,72 +468,72 @@ discard block |
||
468 | 468 | |
469 | 469 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
470 | 470 | |
471 | - /** |
|
472 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
473 | - * |
|
474 | - * This filter was mainly added for Unit Testing purposes. |
|
475 | - * |
|
476 | - * @since 1.7.4 |
|
477 | - * |
|
478 | - * @param array $file_upload_args { |
|
479 | - * array of current values |
|
480 | - * |
|
481 | - * @type string test_form set to false by default |
|
482 | - * } |
|
483 | - */ |
|
484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
485 | - |
|
486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
487 | - |
|
488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
489 | - return false; |
|
490 | - } else { |
|
471 | + /** |
|
472 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
473 | + * |
|
474 | + * This filter was mainly added for Unit Testing purposes. |
|
475 | + * |
|
476 | + * @since 1.7.4 |
|
477 | + * |
|
478 | + * @param array $file_upload_args { |
|
479 | + * array of current values |
|
480 | + * |
|
481 | + * @type string test_form set to false by default |
|
482 | + * } |
|
483 | + */ |
|
484 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
485 | + |
|
486 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
487 | + |
|
488 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
489 | + return false; |
|
490 | + } else { |
|
491 | 491 | |
492 | - $filename = $file_return['file']; |
|
492 | + $filename = $file_return['file']; |
|
493 | 493 | |
494 | - $attachment = array( |
|
495 | - 'post_mime_type' => $file_return['type'], |
|
496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
497 | - 'post_content' => '', |
|
498 | - 'post_status' => 'inherit', |
|
499 | - 'guid' => $file_return['url'] |
|
500 | - ); |
|
494 | + $attachment = array( |
|
495 | + 'post_mime_type' => $file_return['type'], |
|
496 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
497 | + 'post_content' => '', |
|
498 | + 'post_status' => 'inherit', |
|
499 | + 'guid' => $file_return['url'] |
|
500 | + ); |
|
501 | 501 | |
502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
502 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
503 | 503 | |
504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
504 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
507 | 507 | |
508 | - if( 0 < intval( $attachment_id ) ) { |
|
509 | - return $attachment_id; |
|
510 | - } |
|
511 | - } |
|
508 | + if( 0 < intval( $attachment_id ) ) { |
|
509 | + return $attachment_id; |
|
510 | + } |
|
511 | + } |
|
512 | 512 | |
513 | - return false; |
|
513 | + return false; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
517 | 517 | * Grade quiz automatically |
518 | - * |
|
519 | - * This function grades each question automatically if the are auto gradable. |
|
520 | - * It store all question grades. |
|
521 | - * |
|
522 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
523 | - * |
|
518 | + * |
|
519 | + * This function grades each question automatically if the are auto gradable. |
|
520 | + * It store all question grades. |
|
521 | + * |
|
522 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
523 | + * |
|
524 | 524 | * @param integer $quiz_id ID of quiz |
525 | 525 | * @param array $submitted questions id ans answers { |
526 | - * @type int $question_id |
|
527 | - * @type mixed $answer |
|
528 | - * } |
|
526 | + * @type int $question_id |
|
527 | + * @type mixed $answer |
|
528 | + * } |
|
529 | 529 | * @param integer $total_questions Total questions in quiz (not used) |
530 | - * @param string $quiz_grade_type Optional defaults to auto |
|
531 | - * |
|
530 | + * @param string $quiz_grade_type Optional defaults to auto |
|
531 | + * |
|
532 | 532 | * @return int $quiz_grade total sum of all question grades |
533 | 533 | */ |
534 | 534 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
535 | 535 | |
536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
536 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
537 | 537 | |
538 | 538 | } // End sensei_grade_quiz_auto() |
539 | 539 | |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @param integer $quiz_id ID of quiz |
543 | 543 | * @param integer $grade Grade received |
544 | 544 | * @param integer $user_id ID of user being graded |
545 | - * @param string $quiz_grade_type default 'auto' |
|
545 | + * @param string $quiz_grade_type default 'auto' |
|
546 | 546 | * @return boolean |
547 | 547 | */ |
548 | 548 | public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
@@ -566,21 +566,21 @@ discard block |
||
566 | 566 | |
567 | 567 | /** |
568 | 568 | * Grade question automatically |
569 | - * |
|
570 | - * This function checks the question typ and then grades it accordingly. |
|
571 | - * |
|
572 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
573 | - * |
|
569 | + * |
|
570 | + * This function checks the question typ and then grades it accordingly. |
|
571 | + * |
|
572 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
573 | + * |
|
574 | 574 | * @param integer $question_id |
575 | - * @param string $question_type of the standard Sensei question types |
|
575 | + * @param string $question_type of the standard Sensei question types |
|
576 | 576 | * @param string $answer |
577 | - * @param int $user_id |
|
578 | - * |
|
577 | + * @param int $user_id |
|
578 | + * |
|
579 | 579 | * @return int $question_grade |
580 | 580 | */ |
581 | 581 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
582 | 582 | |
583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
583 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
584 | 584 | |
585 | 585 | } // end sensei_grade_question_auto |
586 | 586 | |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * Grade question |
589 | 589 | * @param integer $question_id ID of question |
590 | 590 | * @param integer $grade Grade received |
591 | - * @param int $user_id |
|
591 | + * @param int $user_id |
|
592 | 592 | * @return boolean |
593 | 593 | */ |
594 | 594 | public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
@@ -627,35 +627,35 @@ discard block |
||
627 | 627 | } |
628 | 628 | |
629 | 629 | |
630 | - /** |
|
631 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
632 | - * |
|
633 | - * @since 1.7.4 |
|
634 | - * |
|
635 | - * @param integer $user_id |
|
636 | - * @param integer $lesson_id |
|
637 | - * @param bool $complete |
|
638 | - * |
|
639 | - * @return mixed boolean or comment_ID |
|
640 | - */ |
|
641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
630 | + /** |
|
631 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
632 | + * |
|
633 | + * @since 1.7.4 |
|
634 | + * |
|
635 | + * @param integer $user_id |
|
636 | + * @param integer $lesson_id |
|
637 | + * @param bool $complete |
|
638 | + * |
|
639 | + * @return mixed boolean or comment_ID |
|
640 | + */ |
|
641 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
642 | 642 | |
643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
643 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
644 | 644 | |
645 | - }// end user_start_lesson() |
|
645 | + }// end user_start_lesson() |
|
646 | 646 | |
647 | 647 | /** |
648 | 648 | * Mark a lesson as started for user |
649 | - * |
|
650 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
651 | - * |
|
652 | - * @since 1.6.0 |
|
653 | - * |
|
649 | + * |
|
650 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
651 | + * |
|
652 | + * @since 1.6.0 |
|
653 | + * |
|
654 | 654 | * @param integer $lesson_id ID of lesson |
655 | 655 | * @param int| string $user_id default 0 |
656 | - * @param bool $complete default false |
|
657 | - * |
|
658 | - * @return mixed boolean or comment_ID |
|
656 | + * @param bool $complete default false |
|
657 | + * |
|
658 | + * @return mixed boolean or comment_ID |
|
659 | 659 | */ |
660 | 660 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
661 | 661 | |
@@ -701,21 +701,21 @@ discard block |
||
701 | 701 | $metadata['start'] = current_time('mysql'); |
702 | 702 | $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
703 | 703 | |
704 | - } else { |
|
704 | + } else { |
|
705 | 705 | |
706 | - // if users is already taking the lesson and the status changes to complete update it |
|
707 | - $current_user_activity = get_comment($activity_logged); |
|
708 | - if( $status=='complete' && |
|
709 | - $status != $current_user_activity->comment_approved ){ |
|
706 | + // if users is already taking the lesson and the status changes to complete update it |
|
707 | + $current_user_activity = get_comment($activity_logged); |
|
708 | + if( $status=='complete' && |
|
709 | + $status != $current_user_activity->comment_approved ){ |
|
710 | 710 | |
711 | - $comment = array(); |
|
712 | - $comment['comment_ID'] = $activity_logged; |
|
713 | - $comment['comment_approved'] = $status; |
|
714 | - wp_update_comment( $comment ); |
|
711 | + $comment = array(); |
|
712 | + $comment['comment_ID'] = $activity_logged; |
|
713 | + $comment['comment_approved'] = $status; |
|
714 | + wp_update_comment( $comment ); |
|
715 | 715 | |
716 | - } |
|
716 | + } |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | if ( $complete ) { |
721 | 721 | // Run this *after* the lesson status has been created/updated |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | /** |
862 | 862 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
863 | 863 | * |
864 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
864 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
865 | 865 | * @param mixed $question |
866 | 866 | * @param int $user_id |
867 | 867 | * @return string |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * Add answer notes to question |
922 | 922 | * @param integer $question_id ID of question |
923 | 923 | * @param integer $user_id ID of user |
924 | - * @param string $notes |
|
924 | + * @param string $notes |
|
925 | 925 | * @return boolean |
926 | 926 | */ |
927 | 927 | public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
@@ -979,17 +979,17 @@ discard block |
||
979 | 979 | * @return void |
980 | 980 | */ |
981 | 981 | public static function sort_array_by_key( $array, $key ) { |
982 | - $sorter = array(); |
|
983 | - $ret = array(); |
|
984 | - reset( $array ); |
|
985 | - foreach ( $array as $ii => $va ) { |
|
986 | - $sorter[$ii] = $va[$key]; |
|
987 | - } // End For Loop |
|
988 | - asort( $sorter ); |
|
989 | - foreach ( $sorter as $ii => $va ) { |
|
990 | - $ret[$ii] = $array[$ii]; |
|
991 | - } // End For Loop |
|
992 | - $array = $ret; |
|
982 | + $sorter = array(); |
|
983 | + $ret = array(); |
|
984 | + reset( $array ); |
|
985 | + foreach ( $array as $ii => $va ) { |
|
986 | + $sorter[$ii] = $va[$key]; |
|
987 | + } // End For Loop |
|
988 | + asort( $sorter ); |
|
989 | + foreach ( $sorter as $ii => $va ) { |
|
990 | + $ret[$ii] = $array[$ii]; |
|
991 | + } // End For Loop |
|
992 | + $array = $ret; |
|
993 | 993 | } // End sort_array_by_key() |
994 | 994 | |
995 | 995 | /** |
@@ -1002,21 +1002,21 @@ discard block |
||
1002 | 1002 | $questions_array = array(); |
1003 | 1003 | if ( 0 < $quiz_id ) { |
1004 | 1004 | $question_args = array( 'post_type' => 'question', |
1005 | - 'posts_per_page' => -1, |
|
1006 | - 'orderby' => 'ID', |
|
1007 | - 'order' => 'ASC', |
|
1008 | - 'meta_query' => array( |
|
1005 | + 'posts_per_page' => -1, |
|
1006 | + 'orderby' => 'ID', |
|
1007 | + 'order' => 'ASC', |
|
1008 | + 'meta_query' => array( |
|
1009 | 1009 | array( |
1010 | 1010 | 'key' => '_quiz_id', |
1011 | 1011 | 'value' => $quiz_id, |
1012 | 1012 | ) |
1013 | 1013 | ), |
1014 | - 'post_status' => 'any', |
|
1015 | - 'suppress_filters' => 0 |
|
1016 | - ); |
|
1017 | - $questions_array = get_posts( $question_args ); |
|
1018 | - } // End If Statement |
|
1019 | - return $questions_array; |
|
1014 | + 'post_status' => 'any', |
|
1015 | + 'suppress_filters' => 0 |
|
1016 | + ); |
|
1017 | + $questions_array = get_posts( $question_args ); |
|
1018 | + } // End If Statement |
|
1019 | + return $questions_array; |
|
1020 | 1020 | } // End lesson_quiz_questions() |
1021 | 1021 | |
1022 | 1022 | /** |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | * Set the status message displayed to the user for a quiz |
1175 | 1175 | * @param integer $lesson_id ID of quiz lesson |
1176 | 1176 | * @param integer $user_id ID of user |
1177 | - * @param bool $is_lesson |
|
1177 | + * @param bool $is_lesson |
|
1178 | 1178 | * @return array Status code and message |
1179 | 1179 | */ |
1180 | 1180 | public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
@@ -1257,20 +1257,20 @@ discard block |
||
1257 | 1257 | } |
1258 | 1258 | } |
1259 | 1259 | |
1260 | - // add next lesson button |
|
1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1260 | + // add next lesson button |
|
1261 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1263 | 1263 | |
1264 | - // Output HTML |
|
1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1268 | - .'</a>'; |
|
1264 | + // Output HTML |
|
1265 | + if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1268 | + .'</a>'; |
|
1269 | 1269 | |
1270 | - } |
|
1270 | + } |
|
1271 | 1271 | |
1272 | 1272 | } |
1273 | - // Lesson/Quiz not complete |
|
1273 | + // Lesson/Quiz not complete |
|
1274 | 1274 | else { |
1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
1276 | 1276 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1310,7 +1310,7 @@ discard block |
||
1310 | 1310 | $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
1311 | 1311 | |
1312 | 1312 | if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1314 | 1314 | $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
1315 | 1315 | } |
1316 | 1316 | |
@@ -1368,9 +1368,9 @@ discard block |
||
1368 | 1368 | $user_id = get_current_user_id(); |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if( ! $user_id > 0 ){ |
|
1372 | - return false; |
|
1373 | - } |
|
1371 | + if( ! $user_id > 0 ){ |
|
1372 | + return false; |
|
1373 | + } |
|
1374 | 1374 | |
1375 | 1375 | $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
1376 | 1376 | if( $user_course_status_id ) { |
@@ -1494,7 +1494,7 @@ discard block |
||
1494 | 1494 | * Check if a user has completed a course or not |
1495 | 1495 | * |
1496 | 1496 | * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry |
1497 | - * |
|
1497 | + * |
|
1498 | 1498 | * @param int $user_id |
1499 | 1499 | * @return boolean |
1500 | 1500 | */ |
@@ -1512,14 +1512,14 @@ discard block |
||
1512 | 1512 | $user_id = get_current_user_id(); |
1513 | 1513 | } |
1514 | 1514 | |
1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | - $course = $course->ID; |
|
1517 | - } |
|
1515 | + if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | + $course = $course->ID; |
|
1517 | + } |
|
1518 | 1518 | |
1519 | 1519 | $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
1520 | 1520 | if( isset( $user_course_status->comment_approved ) ){ |
1521 | - $user_course_status = $user_course_status->comment_approved; |
|
1522 | - } |
|
1521 | + $user_course_status = $user_course_status->comment_approved; |
|
1522 | + } |
|
1523 | 1523 | |
1524 | 1524 | } |
1525 | 1525 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1544,11 +1544,11 @@ discard block |
||
1544 | 1544 | $user_id = get_current_user_id(); |
1545 | 1545 | } |
1546 | 1546 | |
1547 | - $activity_args = array( |
|
1548 | - 'post_id' => $lesson_id, |
|
1549 | - 'user_id' => $user_id, |
|
1550 | - 'type' => 'sensei_lesson_status', |
|
1551 | - 'field' => 'comment_ID' ); |
|
1547 | + $activity_args = array( |
|
1548 | + 'post_id' => $lesson_id, |
|
1549 | + 'user_id' => $user_id, |
|
1550 | + 'type' => 'sensei_lesson_status', |
|
1551 | + 'field' => 'comment_ID' ); |
|
1552 | 1552 | |
1553 | 1553 | $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
1554 | 1554 | if( $user_lesson_status_id ) { |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | /** |
1562 | 1562 | * Check if a user has completed a lesson or not |
1563 | 1563 | * |
1564 | - * @uses Sensei() |
|
1564 | + * @uses Sensei() |
|
1565 | 1565 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
1566 | 1566 | * @param int $user_id |
1567 | 1567 | * @return boolean |
@@ -1582,10 +1582,10 @@ discard block |
||
1582 | 1582 | $user_id = get_current_user_id(); |
1583 | 1583 | } |
1584 | 1584 | |
1585 | - // the user is not logged in |
|
1586 | - if( ! $user_id > 0 ){ |
|
1587 | - return false; |
|
1588 | - } |
|
1585 | + // the user is not logged in |
|
1586 | + if( ! $user_id > 0 ){ |
|
1587 | + return false; |
|
1588 | + } |
|
1589 | 1589 | $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
1590 | 1590 | |
1591 | 1591 | if ( $_user_lesson_status ) { |
@@ -1664,9 +1664,9 @@ discard block |
||
1664 | 1664 | */ |
1665 | 1665 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
1666 | 1666 | |
1667 | - if( ! $user_id ) { |
|
1668 | - $user_id = get_current_user_id(); |
|
1669 | - } |
|
1667 | + if( ! $user_id ) { |
|
1668 | + $user_id = get_current_user_id(); |
|
1669 | + } |
|
1670 | 1670 | |
1671 | 1671 | if( $lesson_id > 0 && $user_id > 0 ) { |
1672 | 1672 | |
@@ -1717,12 +1717,12 @@ discard block |
||
1717 | 1717 | * Sets the status for the lesson |
1718 | 1718 | * |
1719 | 1719 | * @since 1.7.0 |
1720 | - * |
|
1720 | + * |
|
1721 | 1721 | * @param int|string $user_id |
1722 | 1722 | * @param int|string $lesson_id |
1723 | 1723 | * @param string $status |
1724 | 1724 | * @param array $metadata |
1725 | - * |
|
1725 | + * |
|
1726 | 1726 | * @return mixed false or comment_ID |
1727 | 1727 | */ |
1728 | 1728 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
1838 | 1838 | /** |
1839 | 1839 | * Adjust the comment query to be faster on the database, used by Analysis admin |
1840 | 1840 | * @since 1.7.0 |
1841 | - * @param array $pieces |
|
1841 | + * @param array $pieces |
|
1842 | 1842 | * @return array $pieces |
1843 | 1843 | */ |
1844 | 1844 | public static function comment_total_sum_meta_value_filter( $pieces ) { |
@@ -1873,360 +1873,360 @@ discard block |
||
1873 | 1873 | return $pieces; |
1874 | 1874 | } |
1875 | 1875 | |
1876 | - /** |
|
1877 | - * |
|
1878 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
1879 | - * @since 1.7.4 |
|
1880 | - * |
|
1881 | - * @param string $data_key maximum 39 characters allowed |
|
1882 | - * @param int $post_id |
|
1883 | - * @param mixed $value |
|
1884 | - * @param int $user_id |
|
1885 | - * |
|
1886 | - * @return bool $success |
|
1887 | - */ |
|
1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1889 | - |
|
1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1891 | - |
|
1892 | - }// end add_user_data |
|
1893 | - |
|
1894 | - /** |
|
1895 | - * add user specific data to the passed in sensei post type id |
|
1896 | - * |
|
1897 | - * This function saves comment meta on the users current status. If no status is available |
|
1898 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
1899 | - * |
|
1900 | - * @since 1.7.4 |
|
1901 | - * |
|
1902 | - * @param string $data_key maximum 39 characters allowed |
|
1903 | - * @param int $post_id |
|
1904 | - * @param mixed $value |
|
1905 | - * @param int $user_id |
|
1906 | - * |
|
1907 | - * @return bool $success |
|
1908 | - */ |
|
1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1910 | - |
|
1911 | - if( ! ( $user_id > 0 ) ){ |
|
1912 | - $user_id = get_current_user_id(); |
|
1913 | - } |
|
1914 | - |
|
1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | - $post_type = get_post_type( $post_id ); |
|
1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | - || !get_userdata( $user_id ) |
|
1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
1921 | - |
|
1922 | - return false; |
|
1923 | - } |
|
1924 | - |
|
1925 | - // check if there and existing Sensei status on this post type if not create it |
|
1926 | - // and get the activity ID |
|
1927 | - $status_function = 'user_'.$post_type.'_status'; |
|
1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1930 | - |
|
1931 | - $start_function = 'user_start_'.$post_type; |
|
1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1933 | - |
|
1934 | - }else{ |
|
1935 | - |
|
1936 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1937 | - |
|
1938 | - } |
|
1939 | - |
|
1940 | - // store the data |
|
1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1942 | - |
|
1943 | - return $success; |
|
1944 | - |
|
1945 | - }//update_user_data |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * Get the user data stored on the passed in post type |
|
1949 | - * |
|
1950 | - * This function gets the comment meta on the lesson or course status |
|
1951 | - * |
|
1952 | - * @since 1.7.4 |
|
1953 | - * |
|
1954 | - * @param $data_key |
|
1955 | - * @param $post_id |
|
1956 | - * @param int $user_id |
|
1957 | - * |
|
1958 | - * @return mixed $user_data_value |
|
1959 | - */ |
|
1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1961 | - |
|
1962 | - $user_data_value = true; |
|
1963 | - |
|
1964 | - if( ! ( $user_id > 0 ) ){ |
|
1965 | - $user_id = get_current_user_id(); |
|
1966 | - } |
|
1967 | - |
|
1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | - $post_type = get_post_type( $post_id ); |
|
1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | - || ! get_userdata( $user_id ) |
|
1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1974 | - |
|
1975 | - return false; |
|
1976 | - } |
|
1977 | - |
|
1978 | - // check if there and existing Sensei status on this post type if not create it |
|
1979 | - // and get the activity ID |
|
1980 | - $status_function = 'user_'.$post_type.'_status'; |
|
1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1983 | - return false; |
|
1984 | - } |
|
1985 | - |
|
1986 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1988 | - |
|
1989 | - return $user_data_value; |
|
1990 | - |
|
1991 | - }// end get_user_data |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
1995 | - * |
|
1996 | - * @param int $data_key |
|
1997 | - * @param int $post_id |
|
1998 | - * @param int $user_id |
|
1999 | - * |
|
2000 | - * @return bool $deleted |
|
2001 | - */ |
|
2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2003 | - $deleted = true; |
|
1876 | + /** |
|
1877 | + * |
|
1878 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
1879 | + * @since 1.7.4 |
|
1880 | + * |
|
1881 | + * @param string $data_key maximum 39 characters allowed |
|
1882 | + * @param int $post_id |
|
1883 | + * @param mixed $value |
|
1884 | + * @param int $user_id |
|
1885 | + * |
|
1886 | + * @return bool $success |
|
1887 | + */ |
|
1888 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1889 | + |
|
1890 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1891 | + |
|
1892 | + }// end add_user_data |
|
1893 | + |
|
1894 | + /** |
|
1895 | + * add user specific data to the passed in sensei post type id |
|
1896 | + * |
|
1897 | + * This function saves comment meta on the users current status. If no status is available |
|
1898 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
1899 | + * |
|
1900 | + * @since 1.7.4 |
|
1901 | + * |
|
1902 | + * @param string $data_key maximum 39 characters allowed |
|
1903 | + * @param int $post_id |
|
1904 | + * @param mixed $value |
|
1905 | + * @param int $user_id |
|
1906 | + * |
|
1907 | + * @return bool $success |
|
1908 | + */ |
|
1909 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1910 | + |
|
1911 | + if( ! ( $user_id > 0 ) ){ |
|
1912 | + $user_id = get_current_user_id(); |
|
1913 | + } |
|
1914 | + |
|
1915 | + $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | + $post_type = get_post_type( $post_id ); |
|
1917 | + if( empty( $post_id ) || empty( $data_key ) |
|
1918 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | + || !get_userdata( $user_id ) |
|
1920 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
1921 | + |
|
1922 | + return false; |
|
1923 | + } |
|
1924 | + |
|
1925 | + // check if there and existing Sensei status on this post type if not create it |
|
1926 | + // and get the activity ID |
|
1927 | + $status_function = 'user_'.$post_type.'_status'; |
|
1928 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1930 | + |
|
1931 | + $start_function = 'user_start_'.$post_type; |
|
1932 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1933 | + |
|
1934 | + }else{ |
|
1935 | + |
|
1936 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1937 | + |
|
1938 | + } |
|
1939 | + |
|
1940 | + // store the data |
|
1941 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1942 | + |
|
1943 | + return $success; |
|
1944 | + |
|
1945 | + }//update_user_data |
|
1946 | + |
|
1947 | + /** |
|
1948 | + * Get the user data stored on the passed in post type |
|
1949 | + * |
|
1950 | + * This function gets the comment meta on the lesson or course status |
|
1951 | + * |
|
1952 | + * @since 1.7.4 |
|
1953 | + * |
|
1954 | + * @param $data_key |
|
1955 | + * @param $post_id |
|
1956 | + * @param int $user_id |
|
1957 | + * |
|
1958 | + * @return mixed $user_data_value |
|
1959 | + */ |
|
1960 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1961 | + |
|
1962 | + $user_data_value = true; |
|
1963 | + |
|
1964 | + if( ! ( $user_id > 0 ) ){ |
|
1965 | + $user_id = get_current_user_id(); |
|
1966 | + } |
|
1967 | + |
|
1968 | + $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | + $post_type = get_post_type( $post_id ); |
|
1970 | + if( empty( $post_id ) || empty( $data_key ) |
|
1971 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | + || ! get_userdata( $user_id ) |
|
1973 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
2004 | 1974 | |
2005 | - if( ! ( $user_id > 0 ) ){ |
|
2006 | - $user_id = get_current_user_id(); |
|
2007 | - } |
|
1975 | + return false; |
|
1976 | + } |
|
2008 | 1977 | |
2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | - $post_type = get_post_type( $post_id ); |
|
2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | - || ! get_userdata( $user_id ) |
|
2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1978 | + // check if there and existing Sensei status on this post type if not create it |
|
1979 | + // and get the activity ID |
|
1980 | + $status_function = 'user_'.$post_type.'_status'; |
|
1981 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1983 | + return false; |
|
1984 | + } |
|
2015 | 1985 | |
2016 | - return false; |
|
2017 | - } |
|
1986 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1987 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1988 | + |
|
1989 | + return $user_data_value; |
|
1990 | + |
|
1991 | + }// end get_user_data |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
1995 | + * |
|
1996 | + * @param int $data_key |
|
1997 | + * @param int $post_id |
|
1998 | + * @param int $user_id |
|
1999 | + * |
|
2000 | + * @return bool $deleted |
|
2001 | + */ |
|
2002 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2003 | + $deleted = true; |
|
2004 | + |
|
2005 | + if( ! ( $user_id > 0 ) ){ |
|
2006 | + $user_id = get_current_user_id(); |
|
2007 | + } |
|
2008 | + |
|
2009 | + $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | + $post_type = get_post_type( $post_id ); |
|
2011 | + if( empty( $post_id ) || empty( $data_key ) |
|
2012 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | + || ! get_userdata( $user_id ) |
|
2014 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
2015 | + |
|
2016 | + return false; |
|
2017 | + } |
|
2018 | 2018 | |
2019 | - // check if there and existing Sensei status on this post type if not create it |
|
2020 | - // and get the activity ID |
|
2021 | - $status_function = 'user_'.$post_type.'_status'; |
|
2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2024 | - return false; |
|
2025 | - } |
|
2019 | + // check if there and existing Sensei status on this post type if not create it |
|
2020 | + // and get the activity ID |
|
2021 | + $status_function = 'user_'.$post_type.'_status'; |
|
2022 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2024 | + return false; |
|
2025 | + } |
|
2026 | 2026 | |
2027 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2027 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
2028 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2029 | 2029 | |
2030 | - return $deleted; |
|
2030 | + return $deleted; |
|
2031 | 2031 | |
2032 | - }// end delete_user_data |
|
2032 | + }// end delete_user_data |
|
2033 | 2033 | |
2034 | 2034 | |
2035 | - /** |
|
2036 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
2037 | - * |
|
2038 | - * @since 1.8.0 |
|
2039 | - * |
|
2040 | - * @param string $selected_value |
|
2041 | - * @param $options{ |
|
2042 | - * @type string $value the value saved in the database |
|
2043 | - * @type string $option what the user will see in the list of items |
|
2044 | - * } |
|
2045 | - * @param array $attributes{ |
|
2046 | - * @type string $attribute type such name or id etc. |
|
2047 | - * @type string $value |
|
2048 | - * } |
|
2049 | - * @param bool $enable_none_option |
|
2050 | - * |
|
2051 | - * @return string $drop_down_element |
|
2052 | - */ |
|
2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2035 | + /** |
|
2036 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
2037 | + * |
|
2038 | + * @since 1.8.0 |
|
2039 | + * |
|
2040 | + * @param string $selected_value |
|
2041 | + * @param $options{ |
|
2042 | + * @type string $value the value saved in the database |
|
2043 | + * @type string $option what the user will see in the list of items |
|
2044 | + * } |
|
2045 | + * @param array $attributes{ |
|
2046 | + * @type string $attribute type such name or id etc. |
|
2047 | + * @type string $value |
|
2048 | + * } |
|
2049 | + * @param bool $enable_none_option |
|
2050 | + * |
|
2051 | + * @return string $drop_down_element |
|
2052 | + */ |
|
2053 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2054 | 2054 | |
2055 | - $drop_down_element = ''; |
|
2055 | + $drop_down_element = ''; |
|
2056 | 2056 | |
2057 | - // setup the basic attributes |
|
2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2057 | + // setup the basic attributes |
|
2058 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2059 | 2059 | |
2060 | - $attributes['name'] = 'sensei-options'; |
|
2060 | + $attributes['name'] = 'sensei-options'; |
|
2061 | 2061 | |
2062 | - } |
|
2062 | + } |
|
2063 | 2063 | |
2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2064 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2065 | 2065 | |
2066 | - $attributes['id'] = 'sensei-options'; |
|
2066 | + $attributes['id'] = 'sensei-options'; |
|
2067 | 2067 | |
2068 | - } |
|
2068 | + } |
|
2069 | 2069 | |
2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2070 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2071 | 2071 | |
2072 | - $attributes['class'] ='chosen_select widefat'; |
|
2072 | + $attributes['class'] ='chosen_select widefat'; |
|
2073 | 2073 | |
2074 | - } |
|
2074 | + } |
|
2075 | 2075 | |
2076 | - // create element attributes |
|
2077 | - $combined_attributes = ''; |
|
2078 | - foreach( $attributes as $attribute => $value ){ |
|
2076 | + // create element attributes |
|
2077 | + $combined_attributes = ''; |
|
2078 | + foreach( $attributes as $attribute => $value ){ |
|
2079 | 2079 | |
2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2080 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2081 | 2081 | |
2082 | - }// end for each |
|
2082 | + }// end for each |
|
2083 | 2083 | |
2084 | 2084 | |
2085 | - // create the select element |
|
2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2085 | + // create the select element |
|
2086 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2087 | 2087 | |
2088 | - // show the none option if the client requested |
|
2089 | - if( $enable_none_option ) { |
|
2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2091 | - } |
|
2088 | + // show the none option if the client requested |
|
2089 | + if( $enable_none_option ) { |
|
2090 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2091 | + } |
|
2092 | 2092 | |
2093 | - if ( count( $options ) > 0 ) { |
|
2093 | + if ( count( $options ) > 0 ) { |
|
2094 | 2094 | |
2095 | - foreach ($options as $value => $option ){ |
|
2095 | + foreach ($options as $value => $option ){ |
|
2096 | 2096 | |
2097 | - $element = ''; |
|
2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2097 | + $element = ''; |
|
2098 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2101 | 2101 | |
2102 | - // add the element to the select html |
|
2103 | - $drop_down_element.= $element; |
|
2104 | - } // End For Loop |
|
2102 | + // add the element to the select html |
|
2103 | + $drop_down_element.= $element; |
|
2104 | + } // End For Loop |
|
2105 | 2105 | |
2106 | - } // End If Statement |
|
2106 | + } // End If Statement |
|
2107 | 2107 | |
2108 | - $drop_down_element .= '</select>' . "\n"; |
|
2108 | + $drop_down_element .= '</select>' . "\n"; |
|
2109 | 2109 | |
2110 | - return $drop_down_element; |
|
2110 | + return $drop_down_element; |
|
2111 | 2111 | |
2112 | - }// generate_drop_down |
|
2112 | + }// generate_drop_down |
|
2113 | 2113 | |
2114 | - /** |
|
2115 | - * Wrapper for the default php round() function. |
|
2116 | - * This allows us to give more control to a user on how they can round Sensei |
|
2117 | - * decimals passed through this function. |
|
2118 | - * |
|
2119 | - * @since 1.8.5 |
|
2120 | - * |
|
2121 | - * @param double $val |
|
2122 | - * @param int $precision |
|
2123 | - * @param $mode |
|
2124 | - * @param string $context |
|
2125 | - * |
|
2126 | - * @return double $val |
|
2127 | - */ |
|
2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2114 | + /** |
|
2115 | + * Wrapper for the default php round() function. |
|
2116 | + * This allows us to give more control to a user on how they can round Sensei |
|
2117 | + * decimals passed through this function. |
|
2118 | + * |
|
2119 | + * @since 1.8.5 |
|
2120 | + * |
|
2121 | + * @param double $val |
|
2122 | + * @param int $precision |
|
2123 | + * @param $mode |
|
2124 | + * @param string $context |
|
2125 | + * |
|
2126 | + * @return double $val |
|
2127 | + */ |
|
2128 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2129 | 2129 | |
2130 | - /**å |
|
2130 | + /**å |
|
2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
2132 | 2132 | * the precision given will be passed into the php round function |
2133 | 2133 | * @since 1.8.5 |
2134 | 2134 | */ |
2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2136 | - |
|
2137 | - /** |
|
2138 | - * Change the mode for the Sensei_Utils::round function. |
|
2139 | - * the mode given will be passed into the php round function |
|
2140 | - * |
|
2141 | - * This applies only to PHP version 5.3.0 and greater |
|
2142 | - * |
|
2143 | - * @since 1.8.5 |
|
2144 | - */ |
|
2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2135 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2136 | + |
|
2137 | + /** |
|
2138 | + * Change the mode for the Sensei_Utils::round function. |
|
2139 | + * the mode given will be passed into the php round function |
|
2140 | + * |
|
2141 | + * This applies only to PHP version 5.3.0 and greater |
|
2142 | + * |
|
2143 | + * @since 1.8.5 |
|
2144 | + */ |
|
2145 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2146 | 2146 | |
2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2147 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2148 | 2148 | |
2149 | - return round( $val, $precision, $mode ); |
|
2149 | + return round( $val, $precision, $mode ); |
|
2150 | 2150 | |
2151 | - }else{ |
|
2151 | + }else{ |
|
2152 | 2152 | |
2153 | - return round( $val, $precision ); |
|
2153 | + return round( $val, $precision ); |
|
2154 | 2154 | |
2155 | - } |
|
2155 | + } |
|
2156 | 2156 | |
2157 | - } |
|
2157 | + } |
|
2158 | 2158 | |
2159 | - /** |
|
2160 | - * Returns the current url with all the query vars |
|
2161 | - * |
|
2162 | - * @since 1.9.0 |
|
2163 | - * @return string $url |
|
2164 | - */ |
|
2165 | - public static function get_current_url(){ |
|
2159 | + /** |
|
2160 | + * Returns the current url with all the query vars |
|
2161 | + * |
|
2162 | + * @since 1.9.0 |
|
2163 | + * @return string $url |
|
2164 | + */ |
|
2165 | + public static function get_current_url(){ |
|
2166 | 2166 | |
2167 | - global $wp; |
|
2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | - if ( isset( $_GET ) ) { |
|
2167 | + global $wp; |
|
2168 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | + if ( isset( $_GET ) ) { |
|
2170 | 2170 | |
2171 | - foreach ($_GET as $param => $val ) { |
|
2171 | + foreach ($_GET as $param => $val ) { |
|
2172 | 2172 | |
2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
2173 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
2174 | 2174 | |
2175 | - } |
|
2176 | - } |
|
2175 | + } |
|
2176 | + } |
|
2177 | 2177 | |
2178 | - return $current_url; |
|
2179 | - } |
|
2178 | + return $current_url; |
|
2179 | + } |
|
2180 | 2180 | |
2181 | - /** |
|
2182 | - * Restore the global WP_Query |
|
2183 | - * |
|
2184 | - * @since 1.9.0 |
|
2185 | - */ |
|
2186 | - public static function restore_wp_query() { |
|
2181 | + /** |
|
2182 | + * Restore the global WP_Query |
|
2183 | + * |
|
2184 | + * @since 1.9.0 |
|
2185 | + */ |
|
2186 | + public static function restore_wp_query() { |
|
2187 | 2187 | |
2188 | - wp_reset_query(); |
|
2188 | + wp_reset_query(); |
|
2189 | 2189 | |
2190 | - } |
|
2190 | + } |
|
2191 | 2191 | |
2192 | - /** |
|
2193 | - * Merge two arrays in a zip like fashion. |
|
2194 | - * If one array is longer than the other the elements will be apended |
|
2195 | - * to the end of the resulting array. |
|
2196 | - * |
|
2197 | - * @since 1.9.0 |
|
2198 | - * |
|
2199 | - * @param array $array_a |
|
2200 | - * @param array $array_b |
|
2201 | - * @return array $merged_array |
|
2202 | - */ |
|
2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
2192 | + /** |
|
2193 | + * Merge two arrays in a zip like fashion. |
|
2194 | + * If one array is longer than the other the elements will be apended |
|
2195 | + * to the end of the resulting array. |
|
2196 | + * |
|
2197 | + * @since 1.9.0 |
|
2198 | + * |
|
2199 | + * @param array $array_a |
|
2200 | + * @param array $array_b |
|
2201 | + * @return array $merged_array |
|
2202 | + */ |
|
2203 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
2204 | 2204 | |
2205 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
2206 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
2207 | - } |
|
2205 | + if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
2206 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
2207 | + } |
|
2208 | 2208 | |
2209 | - $merged_array = array(); |
|
2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
2209 | + $merged_array = array(); |
|
2210 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
2211 | 2211 | |
2212 | - // Zip arrays |
|
2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
2212 | + // Zip arrays |
|
2213 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
2214 | 2214 | |
2215 | - // if has an element at current index push a on top |
|
2216 | - if( isset( $array_a[ $i ] ) ){ |
|
2217 | - $merged_array[] = $array_a[ $i ] ; |
|
2218 | - } |
|
2215 | + // if has an element at current index push a on top |
|
2216 | + if( isset( $array_a[ $i ] ) ){ |
|
2217 | + $merged_array[] = $array_a[ $i ] ; |
|
2218 | + } |
|
2219 | 2219 | |
2220 | - // next if $array_b has an element at current index push a on top of the element |
|
2221 | - // from a if there was one, if not the element before that. |
|
2222 | - if( isset( $array_b[ $i ] ) ){ |
|
2223 | - $merged_array[] = $array_b[ $i ] ; |
|
2224 | - } |
|
2220 | + // next if $array_b has an element at current index push a on top of the element |
|
2221 | + // from a if there was one, if not the element before that. |
|
2222 | + if( isset( $array_b[ $i ] ) ){ |
|
2223 | + $merged_array[] = $array_b[ $i ] ; |
|
2224 | + } |
|
2225 | 2225 | |
2226 | - } |
|
2226 | + } |
|
2227 | 2227 | |
2228 | - return $merged_array; |
|
2229 | - } |
|
2228 | + return $merged_array; |
|
2229 | + } |
|
2230 | 2230 | |
2231 | 2231 | } // End Class |
2232 | 2232 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Utilities Class |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | * @since 1.0.0 |
20 | 20 | * @return string The URL to the placeholder thumbnail image. |
21 | 21 | */ |
22 | - public static function get_placeholder_image () { |
|
22 | + public static function get_placeholder_image() { |
|
23 | 23 | |
24 | - return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) ); |
|
24 | + return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png')); |
|
25 | 25 | } // End get_placeholder_image() |
26 | 26 | |
27 | 27 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @static |
34 | 34 | * @return bool |
35 | 35 | */ |
36 | - public static function sensei_is_woocommerce_present () { |
|
36 | + public static function sensei_is_woocommerce_present() { |
|
37 | 37 | |
38 | 38 | return Sensei_WC::is_woocommerce_present(); |
39 | 39 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @static |
49 | 49 | * @return boolean |
50 | 50 | */ |
51 | - public static function sensei_is_woocommerce_activated () { |
|
51 | + public static function sensei_is_woocommerce_activated() { |
|
52 | 52 | |
53 | 53 | return Sensei_WC::is_woocommerce_active(); |
54 | 54 | |
@@ -61,70 +61,70 @@ discard block |
||
61 | 61 | * @param array $args (default: array()) |
62 | 62 | * @return bool | int |
63 | 63 | */ |
64 | - public static function sensei_log_activity ( $args = array() ) { |
|
64 | + public static function sensei_log_activity($args = array()) { |
|
65 | 65 | global $wpdb; |
66 | 66 | |
67 | 67 | // Args, minimum data required for WP |
68 | 68 | $data = array( |
69 | - 'comment_post_ID' => intval( $args['post_id'] ), |
|
69 | + 'comment_post_ID' => intval($args['post_id']), |
|
70 | 70 | 'comment_author' => '', // Not needed |
71 | 71 | 'comment_author_email' => '', // Not needed |
72 | 72 | 'comment_author_url' => '', // Not needed |
73 | - 'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '', |
|
74 | - 'comment_type' => esc_attr( $args['type'] ), |
|
75 | - 'user_id' => intval( $args['user_id'] ), |
|
76 | - 'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer' |
|
73 | + 'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '', |
|
74 | + 'comment_type' => esc_attr($args['type']), |
|
75 | + 'user_id' => intval($args['user_id']), |
|
76 | + 'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer' |
|
77 | 77 | ); |
78 | 78 | // Allow extra data |
79 | - if ( !empty($args['username']) ) { |
|
80 | - $data['comment_author'] = sanitize_user( $args['username'] ); |
|
79 | + if ( ! empty($args['username'])) { |
|
80 | + $data['comment_author'] = sanitize_user($args['username']); |
|
81 | 81 | } |
82 | - if ( !empty($args['user_email']) ) { |
|
83 | - $data['comment_author_email'] = sanitize_email( $args['user_email'] ); |
|
82 | + if ( ! empty($args['user_email'])) { |
|
83 | + $data['comment_author_email'] = sanitize_email($args['user_email']); |
|
84 | 84 | } |
85 | - if ( !empty($args['user_url']) ) { |
|
86 | - $data['comment_author_url'] = esc_url( $args['user_url'] ); |
|
85 | + if ( ! empty($args['user_url'])) { |
|
86 | + $data['comment_author_url'] = esc_url($args['user_url']); |
|
87 | 87 | } |
88 | - if ( !empty($args['parent']) ) { |
|
88 | + if ( ! empty($args['parent'])) { |
|
89 | 89 | $data['comment_parent'] = $args['parent']; |
90 | 90 | } |
91 | 91 | // Sanity check |
92 | - if ( empty($args['user_id']) ) { |
|
93 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
92 | + if (empty($args['user_id'])) { |
|
93 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - do_action( 'sensei_log_activity_before', $args, $data ); |
|
97 | + do_action('sensei_log_activity_before', $args, $data); |
|
98 | 98 | |
99 | 99 | $flush_cache = false; |
100 | 100 | |
101 | 101 | // Custom Logic |
102 | 102 | // Check if comment exists first |
103 | - $comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) ); |
|
104 | - if ( ! $comment_id ) { |
|
103 | + $comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'])); |
|
104 | + if ( ! $comment_id) { |
|
105 | 105 | // Add the comment |
106 | - $comment_id = wp_insert_comment( $data ); |
|
106 | + $comment_id = wp_insert_comment($data); |
|
107 | 107 | |
108 | 108 | $flush_cache = true; |
109 | - } elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) { |
|
109 | + } elseif (isset($args['action']) && 'update' == $args['action']) { |
|
110 | 110 | // Update the comment if an update was requested |
111 | 111 | $data['comment_ID'] = $comment_id; |
112 | 112 | // By default update the timestamp of the comment |
113 | - if ( empty($args['keep_time']) ) { |
|
113 | + if (empty($args['keep_time'])) { |
|
114 | 114 | $data['comment_date'] = current_time('mysql'); |
115 | 115 | } |
116 | - wp_update_comment( $data ); |
|
116 | + wp_update_comment($data); |
|
117 | 117 | $flush_cache = true; |
118 | 118 | } // End If Statement |
119 | 119 | |
120 | 120 | // Manually Flush the Cache |
121 | - if ( $flush_cache ) { |
|
121 | + if ($flush_cache) { |
|
122 | 122 | wp_cache_flush(); |
123 | 123 | } |
124 | 124 | |
125 | - do_action( 'sensei_log_activity_after', $args, $data, $comment_id ); |
|
125 | + do_action('sensei_log_activity_after', $args, $data, $comment_id); |
|
126 | 126 | |
127 | - if ( 0 < $comment_id ) { |
|
127 | + if (0 < $comment_id) { |
|
128 | 128 | // Return the ID so that it can be used for meta data storage |
129 | 129 | return $comment_id; |
130 | 130 | } else { |
@@ -141,41 +141,41 @@ discard block |
||
141 | 141 | * @param bool $return_comments (default: false) |
142 | 142 | * @return mixed | int |
143 | 143 | */ |
144 | - public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) { |
|
144 | + public static function sensei_check_for_activity($args = array(), $return_comments = false) { |
|
145 | 145 | |
146 | 146 | global $wp_version; |
147 | - if ( !$return_comments ) { |
|
147 | + if ( ! $return_comments) { |
|
148 | 148 | $args['count'] = true; |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Are we only retrieving a single entry, or not care about the order... |
152 | - if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){ |
|
152 | + if (isset($args['count']) || isset($args['post_id'])) { |
|
153 | 153 | |
154 | 154 | // ...then we don't need to ask the db to order the results, this overrides WP default behaviour |
155 | - if ( version_compare( $wp_version, '4.1', '>=' ) ) { |
|
155 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
156 | 156 | $args['order'] = false; |
157 | 157 | $args['orderby'] = false; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | 161 | // A user ID of 0 is in valid, so shortcut this |
162 | - if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) { |
|
163 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
162 | + if (isset($args['user_id']) && 0 == intval($args['user_id'])) { |
|
163 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | // Check for legacy code |
167 | - if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) { |
|
168 | - _deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) ); |
|
167 | + if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) { |
|
168 | + _deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'])); |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | // Are we checking for specific comment_approved statuses? |
172 | - if ( isset($args['status']) ) { |
|
172 | + if (isset($args['status'])) { |
|
173 | 173 | // Temporarily store as a custom status if requesting an array... |
174 | - if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
174 | + if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
175 | 175 | // Encode now, decode later |
176 | - $args['status'] = implode( ",", $args['status'] ); |
|
176 | + $args['status'] = implode(",", $args['status']); |
|
177 | 177 | // ...use a filter to switch the encoding back |
178 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
178 | + add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | else { |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | // Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 ' |
186 | - if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
187 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
186 | + if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
187 | + add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | //Get the comments |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @param int|array $comments |
197 | 197 | */ |
198 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
198 | + $comments = apply_filters('sensei_check_for_activity', get_comments($args)); |
|
199 | 199 | |
200 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
201 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
200 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
201 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
202 | 202 | // Return comments |
203 | - if ( $return_comments ) { |
|
203 | + if ($return_comments) { |
|
204 | 204 | // Could check for array of 1 and just return the 1 item? |
205 | - if ( is_array($comments) && 1 == count($comments) ) { |
|
205 | + if (is_array($comments) && 1 == count($comments)) { |
|
206 | 206 | $comments = array_shift($comments); |
207 | 207 | } |
208 | 208 | |
@@ -220,31 +220,31 @@ discard block |
||
220 | 220 | * @param array $args (default: array()) |
221 | 221 | * @return array |
222 | 222 | */ |
223 | - public static function sensei_activity_ids ( $args = array() ) { |
|
223 | + public static function sensei_activity_ids($args = array()) { |
|
224 | 224 | |
225 | 225 | |
226 | - $comments = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
226 | + $comments = Sensei_Utils::sensei_check_for_activity($args, true); |
|
227 | 227 | // Need to always use an array, even with only 1 item |
228 | - if ( !is_array($comments) ) { |
|
229 | - $comments = array( $comments ); |
|
228 | + if ( ! is_array($comments)) { |
|
229 | + $comments = array($comments); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | $post_ids = array(); |
233 | 233 | // Count comments |
234 | - if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) { |
|
235 | - foreach ( $comments as $key => $value ) { |
|
234 | + if (is_array($comments) && (0 < intval(count($comments)))) { |
|
235 | + foreach ($comments as $key => $value) { |
|
236 | 236 | // Add matches to id array |
237 | - if ( isset( $args['field'] ) && 'comment' == $args['field'] ) { |
|
238 | - array_push( $post_ids, $value->comment_ID ); |
|
239 | - } elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) { |
|
240 | - array_push( $post_ids, $value->user_id ); |
|
237 | + if (isset($args['field']) && 'comment' == $args['field']) { |
|
238 | + array_push($post_ids, $value->comment_ID); |
|
239 | + } elseif (isset($args['field']) && 'user_id' == $args['field']) { |
|
240 | + array_push($post_ids, $value->user_id); |
|
241 | 241 | } else { |
242 | - array_push( $post_ids, $value->comment_post_ID ); |
|
242 | + array_push($post_ids, $value->comment_post_ID); |
|
243 | 243 | } // End If Statement |
244 | 244 | } // End For Loop |
245 | 245 | // Reset array indexes |
246 | - $post_ids = array_unique( $post_ids ); |
|
247 | - $post_ids = array_values( $post_ids ); |
|
246 | + $post_ids = array_unique($post_ids); |
|
247 | + $post_ids = array_values($post_ids); |
|
248 | 248 | } // End If Statement |
249 | 249 | |
250 | 250 | return $post_ids; |
@@ -258,20 +258,20 @@ discard block |
||
258 | 258 | * @param array $args (default: array()) |
259 | 259 | * @return boolean |
260 | 260 | */ |
261 | - public static function sensei_delete_activities ( $args = array() ) { |
|
261 | + public static function sensei_delete_activities($args = array()) { |
|
262 | 262 | |
263 | 263 | $dataset_changes = false; |
264 | 264 | |
265 | 265 | // If activity exists remove activity from log |
266 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true ); |
|
267 | - if( $comments ) { |
|
266 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true); |
|
267 | + if ($comments) { |
|
268 | 268 | // Need to always return an array, even with only 1 item |
269 | - if ( !is_array( $comments ) ) { |
|
270 | - $comments = array( $comments ); |
|
269 | + if ( ! is_array($comments)) { |
|
270 | + $comments = array($comments); |
|
271 | 271 | } |
272 | - foreach ( $comments as $key => $value ) { |
|
273 | - if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { |
|
274 | - $dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true ); |
|
272 | + foreach ($comments as $key => $value) { |
|
273 | + if (isset($value->comment_ID) && 0 < $value->comment_ID) { |
|
274 | + $dataset_changes = wp_delete_comment(intval($value->comment_ID), true); |
|
275 | 275 | } // End If Statement |
276 | 276 | } // End For Loop |
277 | 277 | // Manually flush the cache |
@@ -287,25 +287,25 @@ discard block |
||
287 | 287 | * @param integer $user_id User ID |
288 | 288 | * @return boolean |
289 | 289 | */ |
290 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
290 | + public static function delete_all_user_activity($user_id = 0) { |
|
291 | 291 | |
292 | 292 | $dataset_changes = false; |
293 | 293 | |
294 | - if( $user_id ) { |
|
294 | + if ($user_id) { |
|
295 | 295 | |
296 | - $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
|
296 | + $activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true); |
|
297 | 297 | |
298 | - if( $activities ) { |
|
298 | + if ($activities) { |
|
299 | 299 | |
300 | 300 | // Need to always return an array, even with only 1 item |
301 | - if ( ! is_array( $activities ) ) { |
|
302 | - $activities = array( $activities ); |
|
301 | + if ( ! is_array($activities)) { |
|
302 | + $activities = array($activities); |
|
303 | 303 | } |
304 | 304 | |
305 | - foreach( $activities as $activity ) { |
|
306 | - if( '' == $activity->comment_type ) continue; |
|
307 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
308 | - $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
305 | + foreach ($activities as $activity) { |
|
306 | + if ('' == $activity->comment_type) continue; |
|
307 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
308 | + $dataset_changes = wp_delete_comment(intval($activity->comment_ID), true); |
|
309 | 309 | wp_cache_flush(); |
310 | 310 | } |
311 | 311 | } |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | * @param array $args (default: array()) |
323 | 323 | * @return string |
324 | 324 | */ |
325 | - public static function sensei_get_activity_value ( $args = array() ) { |
|
325 | + public static function sensei_get_activity_value($args = array()) { |
|
326 | 326 | |
327 | 327 | |
328 | 328 | $activity_value = false; |
329 | - if ( !empty($args['field']) ) { |
|
330 | - $comment = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
329 | + if ( ! empty($args['field'])) { |
|
330 | + $comment = Sensei_Utils::sensei_check_for_activity($args, true); |
|
331 | 331 | |
332 | - if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
332 | + if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
333 | 333 | $activity_value = $comment->{$args['field']}; |
334 | 334 | } // End If Statement |
335 | 335 | } |
@@ -347,22 +347,22 @@ discard block |
||
347 | 347 | * @param int $product_id |
348 | 348 | * @return bool |
349 | 349 | */ |
350 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
350 | + public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) { |
|
351 | 351 | |
352 | 352 | $emails = array(); |
353 | 353 | |
354 | - if ( $user_id ) { |
|
355 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
354 | + if ($user_id) { |
|
355 | + $user = get_user_by('id', intval($user_id)); |
|
356 | 356 | $emails[] = $user->user_email; |
357 | 357 | } |
358 | 358 | |
359 | - if ( is_email( $customer_email ) ) |
|
359 | + if (is_email($customer_email)) |
|
360 | 360 | $emails[] = $customer_email; |
361 | 361 | |
362 | - if ( sizeof( $emails ) == 0 ) |
|
362 | + if (sizeof($emails) == 0) |
|
363 | 363 | return false; |
364 | 364 | |
365 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
365 | + return Sensei_WC::has_customer_bought_product($user_id, $product_id); |
|
366 | 366 | |
367 | 367 | } // End sensei_customer_bought_product() |
368 | 368 | |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | * @param string $input_name Name for textarea form element |
374 | 374 | * @return void |
375 | 375 | */ |
376 | - public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
|
376 | + public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') { |
|
377 | 377 | |
378 | - if( ! $input_name ) $input_name = $editor_id; |
|
378 | + if ( ! $input_name) $input_name = $editor_id; |
|
379 | 379 | |
380 | 380 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
381 | 381 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | 'quicktags' => false |
394 | 394 | ); |
395 | 395 | |
396 | - wp_editor( $content, $editor_id, $settings ); |
|
396 | + wp_editor($content, $editor_id, $settings); |
|
397 | 397 | |
398 | 398 | } // End sensei_text_editor() |
399 | 399 | |
@@ -403,56 +403,56 @@ discard block |
||
403 | 403 | * @param int $user_id |
404 | 404 | * @return boolean Whether the answers were saved or not |
405 | 405 | */ |
406 | - public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
|
407 | - if( intval( $user_id ) == 0 ) { |
|
406 | + public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) { |
|
407 | + if (intval($user_id) == 0) { |
|
408 | 408 | $user_id = get_current_user_id(); |
409 | 409 | } |
410 | 410 | |
411 | 411 | $answers_saved = false; |
412 | 412 | |
413 | - if( $submitted && intval( $user_id ) > 0 ) { |
|
413 | + if ($submitted && intval($user_id) > 0) { |
|
414 | 414 | |
415 | - foreach( $submitted as $question_id => $answer ) { |
|
415 | + foreach ($submitted as $question_id => $answer) { |
|
416 | 416 | |
417 | 417 | // Get question type |
418 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
418 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
419 | 419 | |
420 | 420 | // Sanitise answer |
421 | - if( 0 == get_magic_quotes_gpc() ) { |
|
422 | - $answer = wp_unslash( $answer ); |
|
421 | + if (0 == get_magic_quotes_gpc()) { |
|
422 | + $answer = wp_unslash($answer); |
|
423 | 423 | } |
424 | - switch( $question_type ) { |
|
425 | - case 'multi-line': $answer = nl2br( $answer ); break; |
|
424 | + switch ($question_type) { |
|
425 | + case 'multi-line': $answer = nl2br($answer); break; |
|
426 | 426 | case 'single-line': break; |
427 | 427 | case 'gap-fill': break; |
428 | - default: $answer = maybe_serialize( $answer ); break; |
|
428 | + default: $answer = maybe_serialize($answer); break; |
|
429 | 429 | } |
430 | 430 | $args = array( |
431 | 431 | 'post_id' => $question_id, |
432 | - 'data' => base64_encode( $answer ), |
|
432 | + 'data' => base64_encode($answer), |
|
433 | 433 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
434 | 434 | 'user_id' => $user_id, |
435 | 435 | 'action' => 'update' |
436 | 436 | ); |
437 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
437 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | // Handle file upload questions |
441 | - if( isset( $_FILES ) ) { |
|
442 | - foreach( $_FILES as $field => $file ) { |
|
443 | - if( strpos( $field, 'file_upload_' ) !== false ) { |
|
444 | - $question_id = str_replace( 'file_upload_', '', $field ); |
|
445 | - if( $file && $question_id ) { |
|
446 | - $attachment_id = self::upload_file( $file ); |
|
447 | - if( $attachment_id ) { |
|
441 | + if (isset($_FILES)) { |
|
442 | + foreach ($_FILES as $field => $file) { |
|
443 | + if (strpos($field, 'file_upload_') !== false) { |
|
444 | + $question_id = str_replace('file_upload_', '', $field); |
|
445 | + if ($file && $question_id) { |
|
446 | + $attachment_id = self::upload_file($file); |
|
447 | + if ($attachment_id) { |
|
448 | 448 | $args = array( |
449 | 449 | 'post_id' => $question_id, |
450 | - 'data' => base64_encode( $attachment_id ), |
|
450 | + 'data' => base64_encode($attachment_id), |
|
451 | 451 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
452 | 452 | 'user_id' => $user_id, |
453 | 453 | 'action' => 'update' |
454 | 454 | ); |
455 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
455 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | |
465 | 465 | } // End sensei_save_quiz_answers() |
466 | 466 | |
467 | - public static function upload_file( $file = array() ) { |
|
467 | + public static function upload_file($file = array()) { |
|
468 | 468 | |
469 | - require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
|
469 | + require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
470 | 470 | |
471 | 471 | /** |
472 | 472 | * Filter the data array for the Sensei wp_handle_upload function call |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | * @type string test_form set to false by default |
482 | 482 | * } |
483 | 483 | */ |
484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
484 | + $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false)); |
|
485 | 485 | |
486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
486 | + $file_return = wp_handle_upload($file, $file_upload_args); |
|
487 | 487 | |
488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
488 | + if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { |
|
489 | 489 | return false; |
490 | 490 | } else { |
491 | 491 | |
@@ -493,19 +493,19 @@ discard block |
||
493 | 493 | |
494 | 494 | $attachment = array( |
495 | 495 | 'post_mime_type' => $file_return['type'], |
496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
496 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
497 | 497 | 'post_content' => '', |
498 | 498 | 'post_status' => 'inherit', |
499 | 499 | 'guid' => $file_return['url'] |
500 | 500 | ); |
501 | 501 | |
502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
502 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
503 | 503 | |
504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
504 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
505 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
506 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
507 | 507 | |
508 | - if( 0 < intval( $attachment_id ) ) { |
|
508 | + if (0 < intval($attachment_id)) { |
|
509 | 509 | return $attachment_id; |
510 | 510 | } |
511 | 511 | } |
@@ -531,9 +531,9 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return int $quiz_grade total sum of all question grades |
533 | 533 | */ |
534 | - public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
534 | + public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
535 | 535 | |
536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
536 | + return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); |
|
537 | 537 | |
538 | 538 | } // End sensei_grade_quiz_auto() |
539 | 539 | |
@@ -545,20 +545,20 @@ discard block |
||
545 | 545 | * @param string $quiz_grade_type default 'auto' |
546 | 546 | * @return boolean |
547 | 547 | */ |
548 | - public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
|
549 | - if( intval( $user_id ) == 0 ) { |
|
548 | + public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') { |
|
549 | + if (intval($user_id) == 0) { |
|
550 | 550 | $user_id = get_current_user_id(); |
551 | 551 | } |
552 | 552 | |
553 | 553 | $activity_logged = false; |
554 | - if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) { |
|
555 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
556 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
557 | - $activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade ); |
|
554 | + if (intval($quiz_id) > 0 && intval($user_id) > 0) { |
|
555 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
556 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
557 | + $activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade); |
|
558 | 558 | |
559 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
559 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
560 | 560 | |
561 | - do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type ); |
|
561 | + do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $activity_logged; |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | * |
579 | 579 | * @return int $question_grade |
580 | 580 | */ |
581 | - public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
581 | + public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
582 | 582 | |
583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
583 | + return WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
584 | 584 | |
585 | 585 | } // end sensei_grade_question_auto |
586 | 586 | |
@@ -591,20 +591,20 @@ discard block |
||
591 | 591 | * @param int $user_id |
592 | 592 | * @return boolean |
593 | 593 | */ |
594 | - public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
|
595 | - if( intval( $user_id ) == 0 ) { |
|
594 | + public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) { |
|
595 | + if (intval($user_id) == 0) { |
|
596 | 596 | $user_id = get_current_user_id(); |
597 | 597 | } |
598 | 598 | |
599 | 599 | $activity_logged = false; |
600 | - if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) { |
|
600 | + if (intval($question_id) > 0 && intval($user_id) > 0) { |
|
601 | 601 | |
602 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
603 | - $activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade ); |
|
602 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
603 | + $activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade); |
|
604 | 604 | |
605 | - $answer_notes = get_post_meta( $question_id, '_answer_feedback', true ); |
|
606 | - if ( !empty($answer_notes) ) { |
|
607 | - update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) ); |
|
605 | + $answer_notes = get_post_meta($question_id, '_answer_feedback', true); |
|
606 | + if ( ! empty($answer_notes)) { |
|
607 | + update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes)); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | } |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | return $activity_logged; |
613 | 613 | } |
614 | 614 | |
615 | - public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) { |
|
616 | - if( intval( $user_id ) == 0 ) { |
|
615 | + public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) { |
|
616 | + if (intval($user_id) == 0) { |
|
617 | 617 | $user_id = get_current_user_id(); |
618 | 618 | } |
619 | 619 | |
620 | 620 | $activity_logged = false; |
621 | - if( intval( $question_id ) > 0 ) { |
|
622 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
623 | - $activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' ); |
|
621 | + if (intval($question_id) > 0) { |
|
622 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
623 | + $activity_logged = delete_comment_meta($user_answer_id, 'user_grade'); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | return $activity_logged; |
@@ -638,9 +638,9 @@ discard block |
||
638 | 638 | * |
639 | 639 | * @return mixed boolean or comment_ID |
640 | 640 | */ |
641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
641 | + public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) { |
|
642 | 642 | |
643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
643 | + return self::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
644 | 644 | |
645 | 645 | }// end user_start_lesson() |
646 | 646 | |
@@ -657,22 +657,22 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @return mixed boolean or comment_ID |
659 | 659 | */ |
660 | - public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
|
660 | + public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) { |
|
661 | 661 | |
662 | 662 | |
663 | - if( intval( $user_id ) == 0 ) { |
|
663 | + if (intval($user_id) == 0) { |
|
664 | 664 | $user_id = get_current_user_id(); |
665 | 665 | } |
666 | 666 | |
667 | 667 | $activity_logged = false; |
668 | 668 | |
669 | - if( intval( $lesson_id ) > 0 ) { |
|
669 | + if (intval($lesson_id) > 0) { |
|
670 | 670 | |
671 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
672 | - if( $course_id ) { |
|
673 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
674 | - if( ! $is_user_taking_course ) { |
|
675 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
671 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
672 | + if ($course_id) { |
|
673 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
674 | + if ( ! $is_user_taking_course) { |
|
675 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
@@ -680,12 +680,12 @@ discard block |
||
680 | 680 | $status = 'in-progress'; |
681 | 681 | |
682 | 682 | // Note: When this action runs the lesson status may not yet exist |
683 | - do_action( 'sensei_user_lesson_start', $user_id, $lesson_id ); |
|
683 | + do_action('sensei_user_lesson_start', $user_id, $lesson_id); |
|
684 | 684 | |
685 | - if( $complete ) { |
|
685 | + if ($complete) { |
|
686 | 686 | |
687 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
688 | - if ( $has_questions ) { |
|
687 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
688 | + if ($has_questions) { |
|
689 | 689 | $status = 'passed'; // Force a pass |
690 | 690 | $metadata['grade'] = 0; |
691 | 691 | } |
@@ -695,31 +695,31 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // Check if user is already taking the lesson |
698 | - $activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id ); |
|
699 | - if( ! $activity_logged ) { |
|
698 | + $activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id); |
|
699 | + if ( ! $activity_logged) { |
|
700 | 700 | |
701 | 701 | $metadata['start'] = current_time('mysql'); |
702 | - $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
|
702 | + $activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata); |
|
703 | 703 | |
704 | 704 | } else { |
705 | 705 | |
706 | 706 | // if users is already taking the lesson and the status changes to complete update it |
707 | 707 | $current_user_activity = get_comment($activity_logged); |
708 | - if( $status=='complete' && |
|
709 | - $status != $current_user_activity->comment_approved ){ |
|
708 | + if ($status == 'complete' && |
|
709 | + $status != $current_user_activity->comment_approved) { |
|
710 | 710 | |
711 | 711 | $comment = array(); |
712 | 712 | $comment['comment_ID'] = $activity_logged; |
713 | 713 | $comment['comment_approved'] = $status; |
714 | - wp_update_comment( $comment ); |
|
714 | + wp_update_comment($comment); |
|
715 | 715 | |
716 | 716 | } |
717 | 717 | |
718 | 718 | } |
719 | 719 | |
720 | - if ( $complete ) { |
|
720 | + if ($complete) { |
|
721 | 721 | // Run this *after* the lesson status has been created/updated |
722 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
722 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | } |
@@ -734,20 +734,20 @@ discard block |
||
734 | 734 | * @param int $user_id |
735 | 735 | * @return boolean |
736 | 736 | */ |
737 | - public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
|
737 | + public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) { |
|
738 | 738 | |
739 | 739 | |
740 | - if( ! $lesson_id ) return false; |
|
740 | + if ( ! $lesson_id) return false; |
|
741 | 741 | |
742 | - if( intval( $user_id ) == 0 ) { |
|
742 | + if (intval($user_id) == 0) { |
|
743 | 743 | $user_id = get_current_user_id(); |
744 | 744 | } |
745 | 745 | |
746 | 746 | // Process quiz |
747 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
747 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
748 | 748 | |
749 | 749 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
750 | - Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id ); |
|
750 | + Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id); |
|
751 | 751 | |
752 | 752 | // Delete lesson status |
753 | 753 | $args = array( |
@@ -756,10 +756,10 @@ discard block |
||
756 | 756 | 'user_id' => $user_id, |
757 | 757 | ); |
758 | 758 | // This auto deletes the corresponding meta data, such as the quiz grade, and questions asked |
759 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
759 | + Sensei_Utils::sensei_delete_activities($args); |
|
760 | 760 | |
761 | - if( ! $from_course ) { |
|
762 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
761 | + if ( ! $from_course) { |
|
762 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | return true; |
@@ -772,19 +772,19 @@ discard block |
||
772 | 772 | * @param int $user_id |
773 | 773 | * @return boolean |
774 | 774 | */ |
775 | - public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
|
775 | + public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) { |
|
776 | 776 | |
777 | 777 | |
778 | - if( ! $course_id ) return false; |
|
778 | + if ( ! $course_id) return false; |
|
779 | 779 | |
780 | - if( intval( $user_id ) == 0 ) { |
|
780 | + if (intval($user_id) == 0) { |
|
781 | 781 | $user_id = get_current_user_id(); |
782 | 782 | } |
783 | 783 | |
784 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
784 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
785 | 785 | |
786 | - foreach( $lesson_ids as $lesson_id ) { |
|
787 | - Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true ); |
|
786 | + foreach ($lesson_ids as $lesson_id) { |
|
787 | + Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | // Delete course status |
@@ -794,36 +794,36 @@ discard block |
||
794 | 794 | 'user_id' => $user_id, |
795 | 795 | ); |
796 | 796 | |
797 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
797 | + Sensei_Utils::sensei_delete_activities($args); |
|
798 | 798 | |
799 | - do_action( 'sensei_user_course_reset', $user_id, $course_id ); |
|
799 | + do_action('sensei_user_course_reset', $user_id, $course_id); |
|
800 | 800 | |
801 | 801 | return true; |
802 | 802 | } |
803 | 803 | |
804 | - public static function sensei_get_quiz_questions( $quiz_id = 0 ) { |
|
804 | + public static function sensei_get_quiz_questions($quiz_id = 0) { |
|
805 | 805 | |
806 | 806 | |
807 | 807 | $questions = array(); |
808 | 808 | |
809 | - if( intval( $quiz_id ) > 0 ) { |
|
810 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
811 | - $questions = Sensei_Utils::array_sort_reorder( $questions ); |
|
809 | + if (intval($quiz_id) > 0) { |
|
810 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
811 | + $questions = Sensei_Utils::array_sort_reorder($questions); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | return $questions; |
815 | 815 | } |
816 | 816 | |
817 | - public static function sensei_get_quiz_total( $quiz_id = 0 ) { |
|
817 | + public static function sensei_get_quiz_total($quiz_id = 0) { |
|
818 | 818 | |
819 | 819 | |
820 | 820 | $quiz_total = 0; |
821 | 821 | |
822 | - if( $quiz_id > 0 ) { |
|
823 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
822 | + if ($quiz_id > 0) { |
|
823 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
824 | 824 | $question_grade = 0; |
825 | - foreach( $questions as $question ) { |
|
826 | - $question_grade = Sensei()->question->get_question_grade( $question->ID ); |
|
825 | + foreach ($questions as $question) { |
|
826 | + $question_grade = Sensei()->question->get_question_grade($question->ID); |
|
827 | 827 | $quiz_total += $question_grade; |
828 | 828 | } |
829 | 829 | } |
@@ -838,20 +838,20 @@ discard block |
||
838 | 838 | * @param int $user_id |
839 | 839 | * @return string |
840 | 840 | */ |
841 | - public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) { |
|
841 | + public static function sensei_get_user_question_grade($question = 0, $user_id = 0) { |
|
842 | 842 | $question_grade = false; |
843 | - if( $question ) { |
|
844 | - if ( is_object( $question ) ) { |
|
843 | + if ($question) { |
|
844 | + if (is_object($question)) { |
|
845 | 845 | $user_answer_id = $question->comment_ID; |
846 | 846 | } |
847 | 847 | else { |
848 | - if( intval( $user_id ) == 0 ) { |
|
848 | + if (intval($user_id) == 0) { |
|
849 | 849 | $user_id = get_current_user_id(); |
850 | 850 | } |
851 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
851 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
852 | 852 | } |
853 | - if ( $user_answer_id ) { |
|
854 | - $question_grade = get_comment_meta( $user_answer_id, 'user_grade', true ); |
|
853 | + if ($user_answer_id) { |
|
854 | + $question_grade = get_comment_meta($user_answer_id, 'user_grade', true); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
@@ -866,52 +866,52 @@ discard block |
||
866 | 866 | * @param int $user_id |
867 | 867 | * @return string |
868 | 868 | */ |
869 | - public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) { |
|
869 | + public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) { |
|
870 | 870 | $answer_notes = false; |
871 | - if( $question ) { |
|
872 | - if ( is_object( $question ) ) { |
|
871 | + if ($question) { |
|
872 | + if (is_object($question)) { |
|
873 | 873 | $user_answer_id = $question->comment_ID; |
874 | 874 | } |
875 | 875 | else { |
876 | - if( intval( $user_id ) == 0 ) { |
|
876 | + if (intval($user_id) == 0) { |
|
877 | 877 | $user_id = get_current_user_id(); |
878 | 878 | } |
879 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
879 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
880 | 880 | } |
881 | - if ( $user_answer_id ) { |
|
882 | - $answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) ); |
|
881 | + if ($user_answer_id) { |
|
882 | + $answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true)); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | return $answer_notes; |
887 | 887 | } |
888 | 888 | |
889 | - public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) { |
|
890 | - if( intval( $user_id ) == 0 ) { |
|
889 | + public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) { |
|
890 | + if (intval($user_id) == 0) { |
|
891 | 891 | $user_id = get_current_user_id(); |
892 | 892 | } |
893 | 893 | |
894 | 894 | $delete_answers = false; |
895 | - if( intval( $quiz_id ) > 0 ) { |
|
896 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
897 | - foreach( $questions as $question ) { |
|
898 | - $delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) ); |
|
895 | + if (intval($quiz_id) > 0) { |
|
896 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
897 | + foreach ($questions as $question) { |
|
898 | + $delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer')); |
|
899 | 899 | } |
900 | 900 | } |
901 | 901 | |
902 | 902 | return $delete_answers; |
903 | 903 | } |
904 | 904 | |
905 | - public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) { |
|
906 | - if( intval( $user_id ) == 0 ) { |
|
905 | + public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) { |
|
906 | + if (intval($user_id) == 0) { |
|
907 | 907 | $user_id = get_current_user_id(); |
908 | 908 | } |
909 | 909 | |
910 | 910 | $delete_grade = false; |
911 | - if( intval( $quiz_id ) > 0 ) { |
|
912 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
913 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
914 | - $delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' ); |
|
911 | + if (intval($quiz_id) > 0) { |
|
912 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
913 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
914 | + $delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade'); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | return $delete_grade; |
@@ -924,20 +924,20 @@ discard block |
||
924 | 924 | * @param string $notes |
925 | 925 | * @return boolean |
926 | 926 | */ |
927 | - public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
|
928 | - if( intval( $user_id ) == 0 ) { |
|
927 | + public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') { |
|
928 | + if (intval($user_id) == 0) { |
|
929 | 929 | $user_id = get_current_user_id(); |
930 | 930 | } |
931 | 931 | |
932 | 932 | $activity_logged = false; |
933 | 933 | |
934 | - if( intval( $question_id ) > 0 ) { |
|
935 | - $notes = base64_encode( $notes ); |
|
934 | + if (intval($question_id) > 0) { |
|
935 | + $notes = base64_encode($notes); |
|
936 | 936 | |
937 | 937 | // Don't store empty values, no point |
938 | - if ( !empty($notes) ) { |
|
939 | - $user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
940 | - $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
|
938 | + if ( ! empty($notes)) { |
|
939 | + $user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
940 | + $activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes); |
|
941 | 941 | } |
942 | 942 | else { |
943 | 943 | $activity_logged = true; |
@@ -953,16 +953,16 @@ discard block |
||
953 | 953 | * @param array $return_array data to be ordered |
954 | 954 | * @return array $return_array ordered data |
955 | 955 | */ |
956 | - public static function array_sort_reorder( $return_array ) { |
|
957 | - if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) { |
|
956 | + public static function array_sort_reorder($return_array) { |
|
957 | + if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) { |
|
958 | 958 | $sort_key = ''; |
959 | 959 | // if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) { |
960 | 960 | // $sort_key = esc_html( $_GET['orderby'] ); |
961 | 961 | // } // End If Statement |
962 | - if ( '' != $sort_key ) { |
|
963 | - Sensei_Utils::sort_array_by_key($return_array,$sort_key); |
|
964 | - if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) { |
|
965 | - $return_array = array_reverse( $return_array, true ); |
|
962 | + if ('' != $sort_key) { |
|
963 | + Sensei_Utils::sort_array_by_key($return_array, $sort_key); |
|
964 | + if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) { |
|
965 | + $return_array = array_reverse($return_array, true); |
|
966 | 966 | } // End If Statement |
967 | 967 | } // End If Statement |
968 | 968 | return $return_array; |
@@ -978,15 +978,15 @@ discard block |
||
978 | 978 | * @param $key string column name in array |
979 | 979 | * @return void |
980 | 980 | */ |
981 | - public static function sort_array_by_key( $array, $key ) { |
|
981 | + public static function sort_array_by_key($array, $key) { |
|
982 | 982 | $sorter = array(); |
983 | 983 | $ret = array(); |
984 | - reset( $array ); |
|
985 | - foreach ( $array as $ii => $va ) { |
|
984 | + reset($array); |
|
985 | + foreach ($array as $ii => $va) { |
|
986 | 986 | $sorter[$ii] = $va[$key]; |
987 | 987 | } // End For Loop |
988 | - asort( $sorter ); |
|
989 | - foreach ( $sorter as $ii => $va ) { |
|
988 | + asort($sorter); |
|
989 | + foreach ($sorter as $ii => $va) { |
|
990 | 990 | $ret[$ii] = $array[$ii]; |
991 | 991 | } // End For Loop |
992 | 992 | $array = $ret; |
@@ -998,10 +998,10 @@ discard block |
||
998 | 998 | * @param integer $quiz_id |
999 | 999 | * @return array of quiz questions |
1000 | 1000 | */ |
1001 | - public static function lesson_quiz_questions( $quiz_id = 0 ) { |
|
1001 | + public static function lesson_quiz_questions($quiz_id = 0) { |
|
1002 | 1002 | $questions_array = array(); |
1003 | - if ( 0 < $quiz_id ) { |
|
1004 | - $question_args = array( 'post_type' => 'question', |
|
1003 | + if (0 < $quiz_id) { |
|
1004 | + $question_args = array('post_type' => 'question', |
|
1005 | 1005 | 'posts_per_page' => -1, |
1006 | 1006 | 'orderby' => 'ID', |
1007 | 1007 | 'order' => 'ASC', |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | 'post_status' => 'any', |
1015 | 1015 | 'suppress_filters' => 0 |
1016 | 1016 | ); |
1017 | - $questions_array = get_posts( $question_args ); |
|
1017 | + $questions_array = get_posts($question_args); |
|
1018 | 1018 | } // End If Statement |
1019 | 1019 | return $questions_array; |
1020 | 1020 | } // End lesson_quiz_questions() |
@@ -1024,25 +1024,25 @@ discard block |
||
1024 | 1024 | * @param integer $course_id ID of course |
1025 | 1025 | * @return integer Pass mark for course |
1026 | 1026 | */ |
1027 | - public static function sensei_course_pass_grade( $course_id = 0 ) { |
|
1027 | + public static function sensei_course_pass_grade($course_id = 0) { |
|
1028 | 1028 | |
1029 | 1029 | |
1030 | 1030 | $course_passmark = 0; |
1031 | 1031 | |
1032 | - if( $course_id > 0 ) { |
|
1033 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1032 | + if ($course_id > 0) { |
|
1033 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1034 | 1034 | $lesson_count = 0; |
1035 | 1035 | $total_passmark = 0; |
1036 | - foreach( $lessons as $lesson ) { |
|
1036 | + foreach ($lessons as $lesson) { |
|
1037 | 1037 | |
1038 | 1038 | // Get Quiz ID |
1039 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
1039 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
1040 | 1040 | |
1041 | 1041 | // Check for a pass being required |
1042 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
1043 | - if ( $pass_required ) { |
|
1042 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
1043 | + if ($pass_required) { |
|
1044 | 1044 | // Get quiz passmark |
1045 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
1045 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
1046 | 1046 | |
1047 | 1047 | // Add up total passmark |
1048 | 1048 | $total_passmark += $quiz_passmark; |
@@ -1051,12 +1051,12 @@ discard block |
||
1051 | 1051 | } |
1052 | 1052 | } |
1053 | 1053 | // Might be a case of no required lessons |
1054 | - if ( $lesson_count ) { |
|
1055 | - $course_passmark = ( $total_passmark / $lesson_count ); |
|
1054 | + if ($lesson_count) { |
|
1055 | + $course_passmark = ($total_passmark / $lesson_count); |
|
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - return Sensei_Utils::round( $course_passmark ); |
|
1059 | + return Sensei_Utils::round($course_passmark); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | /** |
@@ -1065,27 +1065,27 @@ discard block |
||
1065 | 1065 | * @param integer $user_id ID of user |
1066 | 1066 | * @return integer User's total grade |
1067 | 1067 | */ |
1068 | - public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
|
1068 | + public static function sensei_course_user_grade($course_id = 0, $user_id = 0) { |
|
1069 | 1069 | |
1070 | 1070 | |
1071 | - if( intval( $user_id ) == 0 ) { |
|
1071 | + if (intval($user_id) == 0) { |
|
1072 | 1072 | $user_id = get_current_user_id(); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $total_grade = 0; |
1076 | 1076 | |
1077 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1078 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1077 | + if ($course_id > 0 && $user_id > 0) { |
|
1078 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1079 | 1079 | $lesson_count = 0; |
1080 | 1080 | $total_grade = 0; |
1081 | - foreach( $lessons as $lesson ) { |
|
1081 | + foreach ($lessons as $lesson) { |
|
1082 | 1082 | |
1083 | 1083 | // Check for lesson having questions, thus a quiz, thus having a grade |
1084 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
1085 | - if ( $has_questions ) { |
|
1086 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id ); |
|
1084 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
1085 | + if ($has_questions) { |
|
1086 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id); |
|
1087 | 1087 | // Get user quiz grade |
1088 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1088 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1089 | 1089 | |
1090 | 1090 | // Add up total grade |
1091 | 1091 | $total_grade += $quiz_grade; |
@@ -1095,13 +1095,13 @@ discard block |
||
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | // Might be a case of no lessons with quizzes |
1098 | - if ( $lesson_count ) { |
|
1099 | - $total_grade = ( $total_grade / $lesson_count ); |
|
1098 | + if ($lesson_count) { |
|
1099 | + $total_grade = ($total_grade / $lesson_count); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | } |
1103 | 1103 | |
1104 | - return Sensei_Utils::round( $total_grade ); |
|
1104 | + return Sensei_Utils::round($total_grade); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | /** |
@@ -1110,18 +1110,18 @@ discard block |
||
1110 | 1110 | * @param integer $user_id ID of user |
1111 | 1111 | * @return boolean |
1112 | 1112 | */ |
1113 | - public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) { |
|
1114 | - if( intval( $user_id ) == 0 ) { |
|
1113 | + public static function sensei_user_passed_course($course_id = 0, $user_id = 0) { |
|
1114 | + if (intval($user_id) == 0) { |
|
1115 | 1115 | $user_id = get_current_user_id(); |
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | $pass = false; |
1119 | 1119 | |
1120 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1121 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); |
|
1122 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); |
|
1120 | + if ($course_id > 0 && $user_id > 0) { |
|
1121 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); |
|
1122 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); |
|
1123 | 1123 | |
1124 | - if( $user_grade >= $passmark ) { |
|
1124 | + if ($user_grade >= $passmark) { |
|
1125 | 1125 | $pass = true; |
1126 | 1126 | } |
1127 | 1127 | } |
@@ -1136,38 +1136,38 @@ discard block |
||
1136 | 1136 | * @param integer $user_id ID of user |
1137 | 1137 | * @return array Status code and message |
1138 | 1138 | */ |
1139 | - public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) { |
|
1140 | - if( intval( $user_id ) == 0 ) { |
|
1139 | + public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) { |
|
1140 | + if (intval($user_id) == 0) { |
|
1141 | 1141 | $user_id = get_current_user_id(); |
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | $status = 'not_started'; |
1145 | 1145 | $box_class = 'info'; |
1146 | - $message = __( 'You have not started this course yet.', 'woothemes-sensei' ); |
|
1146 | + $message = __('You have not started this course yet.', 'woothemes-sensei'); |
|
1147 | 1147 | |
1148 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1148 | + if ($course_id > 0 && $user_id > 0) { |
|
1149 | 1149 | |
1150 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1150 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1151 | 1151 | |
1152 | - if( $started_course ) { |
|
1153 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()! |
|
1154 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()! |
|
1155 | - if( $user_grade >= $passmark ) { |
|
1152 | + if ($started_course) { |
|
1153 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()! |
|
1154 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()! |
|
1155 | + if ($user_grade >= $passmark) { |
|
1156 | 1156 | $status = 'passed'; |
1157 | 1157 | $box_class = 'tick'; |
1158 | - $message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade ); |
|
1158 | + $message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade); |
|
1159 | 1159 | } else { |
1160 | 1160 | $status = 'failed'; |
1161 | 1161 | $box_class = 'alert'; |
1162 | - $message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade ); |
|
1162 | + $message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade); |
|
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - $message = apply_filters( 'sensei_user_course_status_' . $status, $message ); |
|
1168 | + $message = apply_filters('sensei_user_course_status_'.$status, $message); |
|
1169 | 1169 | |
1170 | - return array( 'status' => $status, 'box_class' => $box_class, 'message' => $message ); |
|
1170 | + return array('status' => $status, 'box_class' => $box_class, 'message' => $message); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | /** |
@@ -1177,94 +1177,94 @@ discard block |
||
1177 | 1177 | * @param bool $is_lesson |
1178 | 1178 | * @return array Status code and message |
1179 | 1179 | */ |
1180 | - public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
|
1180 | + public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) { |
|
1181 | 1181 | global $current_user; |
1182 | - if( intval( $user_id ) == 0 ) { |
|
1182 | + if (intval($user_id) == 0) { |
|
1183 | 1183 | $user_id = $current_user->ID; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | $status = 'not_started'; |
1187 | 1187 | $box_class = 'info'; |
1188 | - $message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' ); |
|
1188 | + $message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei'); |
|
1189 | 1189 | $extra = ''; |
1190 | 1190 | |
1191 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
1191 | + if ($lesson_id > 0 && $user_id > 0) { |
|
1192 | 1192 | |
1193 | 1193 | // Prerequisite lesson |
1194 | - $prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1194 | + $prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
1195 | 1195 | |
1196 | 1196 | // Course ID |
1197 | - $course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
1197 | + $course_id = absint(get_post_meta($lesson_id, '_lesson_course', true)); |
|
1198 | 1198 | |
1199 | 1199 | // Has user started course |
1200 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1200 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1201 | 1201 | |
1202 | 1202 | // Has user completed lesson |
1203 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1204 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
1203 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
1204 | + $lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
1205 | 1205 | |
1206 | 1206 | // Quiz ID |
1207 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1207 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1208 | 1208 | |
1209 | 1209 | // Quiz grade |
1210 | 1210 | $quiz_grade = 0; |
1211 | - if ( $user_lesson_status ) { |
|
1212 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1211 | + if ($user_lesson_status) { |
|
1212 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // Quiz passmark |
1216 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
1216 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
1217 | 1217 | $quiz_passmark_float = (float) $quiz_passmark; |
1218 | 1218 | |
1219 | 1219 | // Pass required |
1220 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
1220 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
1221 | 1221 | |
1222 | 1222 | // Quiz questions |
1223 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1223 | + $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
1224 | 1224 | |
1225 | - if ( ! $started_course ) { |
|
1225 | + if ( ! $started_course) { |
|
1226 | 1226 | |
1227 | 1227 | $status = 'not_started_course'; |
1228 | 1228 | $box_class = 'info'; |
1229 | - $message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' ); |
|
1229 | + $message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>'); |
|
1230 | 1230 | |
1231 | - } elseif ( ! is_user_logged_in() ) { |
|
1231 | + } elseif ( ! is_user_logged_in()) { |
|
1232 | 1232 | |
1233 | 1233 | $status = 'login_required'; |
1234 | 1234 | $box_class = 'info'; |
1235 | - $message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' ); |
|
1235 | + $message = __('You must be logged in to take this quiz', 'woothemes-sensei'); |
|
1236 | 1236 | |
1237 | 1237 | } |
1238 | 1238 | // Lesson/Quiz is marked as complete thus passing any quiz restrictions |
1239 | - elseif ( $lesson_complete ) { |
|
1239 | + elseif ($lesson_complete) { |
|
1240 | 1240 | |
1241 | 1241 | $status = 'passed'; |
1242 | 1242 | $box_class = 'tick'; |
1243 | 1243 | // Lesson status will be "complete" (has no Quiz) |
1244 | - if ( ! $has_quiz_questions ) { |
|
1245 | - $message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) ); |
|
1244 | + if ( ! $has_quiz_questions) { |
|
1245 | + $message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei')); |
|
1246 | 1246 | } |
1247 | 1247 | // Lesson status will be "graded" (no passmark required so might have failed all the questions) |
1248 | - elseif ( empty( $quiz_grade ) ) { |
|
1249 | - $message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) ); |
|
1248 | + elseif (empty($quiz_grade)) { |
|
1249 | + $message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei')); |
|
1250 | 1250 | } |
1251 | 1251 | // Lesson status will be "passed" (passmark reached) |
1252 | - elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) { |
|
1253 | - if( $is_lesson ) { |
|
1254 | - $message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
1252 | + elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) { |
|
1253 | + if ($is_lesson) { |
|
1254 | + $message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
1255 | 1255 | } else { |
1256 | - $message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
1256 | + $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
1257 | 1257 | } |
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | // add next lesson button |
1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1261 | + $nav_id_array = sensei_get_prev_next_lessons($lesson_id); |
|
1262 | + $next_lesson_id = absint($nav_id_array['next_lesson']); |
|
1263 | 1263 | |
1264 | 1264 | // Output HTML |
1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1265 | + if ((0 < $next_lesson_id)) { |
|
1266 | + $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id)) |
|
1267 | + . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei') |
|
1268 | 1268 | .'</a>'; |
1269 | 1269 | |
1270 | 1270 | } |
@@ -1273,33 +1273,33 @@ discard block |
||
1273 | 1273 | // Lesson/Quiz not complete |
1274 | 1274 | else { |
1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
1276 | - if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
|
1276 | + if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) { |
|
1277 | 1277 | $status = 'complete'; |
1278 | 1278 | $box_class = 'info'; |
1279 | - if( $is_lesson ) { |
|
1280 | - $message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' ); |
|
1279 | + if ($is_lesson) { |
|
1280 | + $message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>'); |
|
1281 | 1281 | } else { |
1282 | - $message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1282 | + $message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1283 | 1283 | } |
1284 | 1284 | } |
1285 | 1285 | // Lesson status must be "failed" |
1286 | - elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) { |
|
1286 | + elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) { |
|
1287 | 1287 | $status = 'failed'; |
1288 | 1288 | $box_class = 'alert'; |
1289 | - if( $is_lesson ) { |
|
1290 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
1289 | + if ($is_lesson) { |
|
1290 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
1291 | 1291 | } else { |
1292 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
1292 | + $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
1293 | 1293 | } |
1294 | 1294 | } |
1295 | 1295 | // Lesson/Quiz requires a pass |
1296 | - elseif( $pass_required ) { |
|
1296 | + elseif ($pass_required) { |
|
1297 | 1297 | $status = 'not_started'; |
1298 | 1298 | $box_class = 'info'; |
1299 | - if( $is_lesson ) { |
|
1300 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1299 | + if ($is_lesson) { |
|
1300 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1301 | 1301 | } else { |
1302 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1302 | + $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1303 | 1303 | } |
1304 | 1304 | } |
1305 | 1305 | } |
@@ -1307,15 +1307,15 @@ discard block |
||
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | // Legacy filter |
1310 | - $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
|
1310 | + $message = apply_filters('sensei_user_quiz_status_'.$status, $message); |
|
1311 | 1311 | |
1312 | - if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
|
1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1314 | - $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
|
1312 | + if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) { |
|
1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1314 | + $extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>'; |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | // Filter of all messages |
1318 | - return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson ); |
|
1318 | + return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | /** |
@@ -1325,14 +1325,14 @@ discard block |
||
1325 | 1325 | * @param integer $course_id Course ID |
1326 | 1326 | * @return mixed boolean or comment_ID |
1327 | 1327 | */ |
1328 | - public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
|
1328 | + public static function user_start_course($user_id = 0, $course_id = 0) { |
|
1329 | 1329 | |
1330 | 1330 | $activity_logged = false; |
1331 | 1331 | |
1332 | - if( $user_id && $course_id ) { |
|
1332 | + if ($user_id && $course_id) { |
|
1333 | 1333 | // Check if user is already on the Course |
1334 | - $activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1335 | - if ( ! $activity_logged ) { |
|
1334 | + $activity_logged = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1335 | + if ( ! $activity_logged) { |
|
1336 | 1336 | |
1337 | 1337 | // Add user to course |
1338 | 1338 | $course_metadata = array( |
@@ -1341,11 +1341,11 @@ discard block |
||
1341 | 1341 | 'complete' => 0, |
1342 | 1342 | ); |
1343 | 1343 | |
1344 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata ); |
|
1344 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata); |
|
1345 | 1345 | |
1346 | 1346 | // Allow further actions |
1347 | - if ( $activity_logged ) { |
|
1348 | - do_action( 'sensei_user_course_start', $user_id, $course_id ); |
|
1347 | + if ($activity_logged) { |
|
1348 | + do_action('sensei_user_course_start', $user_id, $course_id); |
|
1349 | 1349 | } |
1350 | 1350 | } |
1351 | 1351 | } |
@@ -1361,19 +1361,19 @@ discard block |
||
1361 | 1361 | * @param int $user_id |
1362 | 1362 | * @return mixed false or comment_ID |
1363 | 1363 | */ |
1364 | - public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
|
1364 | + public static function user_started_course($course_id = 0, $user_id = 0) { |
|
1365 | 1365 | |
1366 | - if( $course_id ) { |
|
1367 | - if( ! $user_id ) { |
|
1366 | + if ($course_id) { |
|
1367 | + if ( ! $user_id) { |
|
1368 | 1368 | $user_id = get_current_user_id(); |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if( ! $user_id > 0 ){ |
|
1371 | + if ( ! $user_id > 0) { |
|
1372 | 1372 | return false; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
|
1376 | - if( $user_course_status_id ) { |
|
1375 | + $user_course_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID')); |
|
1376 | + if ($user_course_status_id) { |
|
1377 | 1377 | return $user_course_status_id; |
1378 | 1378 | } |
1379 | 1379 | } |
@@ -1388,17 +1388,17 @@ discard block |
||
1388 | 1388 | * @param integer $user_id User ID |
1389 | 1389 | * @return int |
1390 | 1390 | */ |
1391 | - public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
|
1391 | + public static function user_complete_course($course_id = 0, $user_id = 0) { |
|
1392 | 1392 | global $wp_version; |
1393 | 1393 | |
1394 | - if( $course_id ) { |
|
1395 | - if( ! $user_id ) { |
|
1394 | + if ($course_id) { |
|
1395 | + if ( ! $user_id) { |
|
1396 | 1396 | $user_id = get_current_user_id(); |
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | $course_status = 'in-progress'; |
1400 | 1400 | $course_metadata = array(); |
1401 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
1401 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
1402 | 1402 | $lessons_completed = $total_lessons = 0; |
1403 | 1403 | $lesson_status_args = array( |
1404 | 1404 | 'user_id' => $user_id, |
@@ -1407,8 +1407,8 @@ discard block |
||
1407 | 1407 | ); |
1408 | 1408 | |
1409 | 1409 | // Grab all of this Courses' lessons, looping through each... |
1410 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
1411 | - $total_lessons = count( $lesson_ids ); |
|
1410 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
1411 | + $total_lessons = count($lesson_ids); |
|
1412 | 1412 | // ...if course completion not set to 'passed', and all lessons are complete or graded, |
1413 | 1413 | // ......then all lessons are 'passed' |
1414 | 1414 | // ...else if course completion is set to 'passed', check if each lesson has questions... |
@@ -1421,29 +1421,29 @@ discard block |
||
1421 | 1421 | // The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson() |
1422 | 1422 | $all_lesson_statuses = array(); |
1423 | 1423 | // In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs |
1424 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1424 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1425 | 1425 | $lesson_status_args['post__in'] = $lesson_ids; |
1426 | - $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
1426 | + $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
1427 | 1427 | // Need to always return an array, even with only 1 item |
1428 | - if ( !is_array($all_lesson_statuses) ) { |
|
1429 | - $all_lesson_statuses = array( $all_lesson_statuses ); |
|
1428 | + if ( ! is_array($all_lesson_statuses)) { |
|
1429 | + $all_lesson_statuses = array($all_lesson_statuses); |
|
1430 | 1430 | } |
1431 | 1431 | } |
1432 | 1432 | // ...otherwise check each one |
1433 | 1433 | else { |
1434 | - foreach( $lesson_ids as $lesson_id ) { |
|
1434 | + foreach ($lesson_ids as $lesson_id) { |
|
1435 | 1435 | $lesson_status_args['post_id'] = $lesson_id; |
1436 | - $each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
1436 | + $each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
1437 | 1437 | // Check for valid return before using |
1438 | - if ( !empty($each_lesson_status->comment_approved) ) { |
|
1438 | + if ( ! empty($each_lesson_status->comment_approved)) { |
|
1439 | 1439 | $all_lesson_statuses[] = $each_lesson_status; |
1440 | 1440 | } |
1441 | 1441 | } |
1442 | 1442 | } |
1443 | - foreach( $all_lesson_statuses as $lesson_status ) { |
|
1443 | + foreach ($all_lesson_statuses as $lesson_status) { |
|
1444 | 1444 | // If lessons are complete without needing quizzes to be passed |
1445 | - if ( 'passed' != $course_completion ) { |
|
1446 | - switch ( $lesson_status->comment_approved ) { |
|
1445 | + if ('passed' != $course_completion) { |
|
1446 | + switch ($lesson_status->comment_approved) { |
|
1447 | 1447 | // A user cannot 'complete' a course if a lesson... |
1448 | 1448 | case 'in-progress': // ...is still in progress |
1449 | 1449 | case 'ungraded': // ...hasn't yet been graded |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | } |
1456 | 1456 | } |
1457 | 1457 | else { |
1458 | - switch ( $lesson_status->comment_approved ) { |
|
1458 | + switch ($lesson_status->comment_approved) { |
|
1459 | 1459 | case 'complete': // Lesson has no quiz/questions |
1460 | 1460 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
1461 | 1461 | case 'passed': // Lesson has quiz and the user passed |
@@ -1469,20 +1469,20 @@ discard block |
||
1469 | 1469 | } |
1470 | 1470 | } |
1471 | 1471 | } // Each lesson |
1472 | - if ( $lessons_completed == $total_lessons ) { |
|
1472 | + if ($lessons_completed == $total_lessons) { |
|
1473 | 1473 | $course_status = 'complete'; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | // Update meta data on how many lessons have been completed |
1477 | 1477 | $course_metadata['complete'] = $lessons_completed; |
1478 | 1478 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
1479 | - $course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
1479 | + $course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
1480 | 1480 | |
1481 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata ); |
|
1481 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata); |
|
1482 | 1482 | |
1483 | 1483 | // Allow further actions |
1484 | - if ( 'complete' == $course_status ) { |
|
1485 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
1484 | + if ('complete' == $course_status) { |
|
1485 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
1486 | 1486 | } |
1487 | 1487 | return $activity_logged; |
1488 | 1488 | } |
@@ -1498,31 +1498,31 @@ discard block |
||
1498 | 1498 | * @param int $user_id |
1499 | 1499 | * @return boolean |
1500 | 1500 | */ |
1501 | - public static function user_completed_course( $course , $user_id = 0 ) { |
|
1501 | + public static function user_completed_course($course, $user_id = 0) { |
|
1502 | 1502 | |
1503 | - if( $course ) { |
|
1504 | - if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
|
1503 | + if ($course) { |
|
1504 | + if (is_object($course) && is_a($course, 'WP_Comment')) { |
|
1505 | 1505 | $user_course_status = $course->comment_approved; |
1506 | 1506 | } |
1507 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
1507 | + elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) { |
|
1508 | 1508 | $user_course_status = $course; |
1509 | 1509 | } |
1510 | 1510 | else { |
1511 | - if( ! $user_id ) { |
|
1511 | + if ( ! $user_id) { |
|
1512 | 1512 | $user_id = get_current_user_id(); |
1513 | 1513 | } |
1514 | 1514 | |
1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | - $course = $course->ID; |
|
1515 | + if (is_a($course, 'WP_Post')) { |
|
1516 | + $course = $course->ID; |
|
1517 | 1517 | } |
1518 | 1518 | |
1519 | - $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
|
1520 | - if( isset( $user_course_status->comment_approved ) ){ |
|
1519 | + $user_course_status = Sensei_Utils::user_course_status($course, $user_id); |
|
1520 | + if (isset($user_course_status->comment_approved)) { |
|
1521 | 1521 | $user_course_status = $user_course_status->comment_approved; |
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | } |
1525 | - if( $user_course_status && 'complete' == $user_course_status ) { |
|
1525 | + if ($user_course_status && 'complete' == $user_course_status) { |
|
1526 | 1526 | return true; |
1527 | 1527 | } |
1528 | 1528 | } |
@@ -1537,10 +1537,10 @@ discard block |
||
1537 | 1537 | * @param int $user_id |
1538 | 1538 | * @return mixed false or comment_ID |
1539 | 1539 | */ |
1540 | - public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
|
1540 | + public static function user_started_lesson($lesson_id = 0, $user_id = 0) { |
|
1541 | 1541 | |
1542 | - if( $lesson_id ) { |
|
1543 | - if( ! $user_id ) { |
|
1542 | + if ($lesson_id) { |
|
1543 | + if ( ! $user_id) { |
|
1544 | 1544 | $user_id = get_current_user_id(); |
1545 | 1545 | } |
1546 | 1546 | |
@@ -1550,8 +1550,8 @@ discard block |
||
1550 | 1550 | 'type' => 'sensei_lesson_status', |
1551 | 1551 | 'field' => 'comment_ID' ); |
1552 | 1552 | |
1553 | - $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
|
1554 | - if( $user_lesson_status_id ) { |
|
1553 | + $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args); |
|
1554 | + if ($user_lesson_status_id) { |
|
1555 | 1555 | return $user_lesson_status_id; |
1556 | 1556 | } |
1557 | 1557 | } |
@@ -1566,29 +1566,29 @@ discard block |
||
1566 | 1566 | * @param int $user_id |
1567 | 1567 | * @return boolean |
1568 | 1568 | */ |
1569 | - public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) { |
|
1569 | + public static function user_completed_lesson($lesson = 0, $user_id = 0) { |
|
1570 | 1570 | |
1571 | - if( $lesson ) { |
|
1571 | + if ($lesson) { |
|
1572 | 1572 | $lesson_id = 0; |
1573 | - if ( is_object( $lesson ) ) { |
|
1573 | + if (is_object($lesson)) { |
|
1574 | 1574 | $user_lesson_status = $lesson->comment_approved; |
1575 | 1575 | $lesson_id = $lesson->comment_post_ID; |
1576 | 1576 | } |
1577 | - elseif ( ! is_numeric( $lesson ) ) { |
|
1577 | + elseif ( ! is_numeric($lesson)) { |
|
1578 | 1578 | $user_lesson_status = $lesson; |
1579 | 1579 | } |
1580 | 1580 | else { |
1581 | - if( ! $user_id ) { |
|
1581 | + if ( ! $user_id) { |
|
1582 | 1582 | $user_id = get_current_user_id(); |
1583 | 1583 | } |
1584 | 1584 | |
1585 | 1585 | // the user is not logged in |
1586 | - if( ! $user_id > 0 ){ |
|
1586 | + if ( ! $user_id > 0) { |
|
1587 | 1587 | return false; |
1588 | 1588 | } |
1589 | - $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
|
1589 | + $_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id); |
|
1590 | 1590 | |
1591 | - if ( $_user_lesson_status ) { |
|
1591 | + if ($_user_lesson_status) { |
|
1592 | 1592 | $user_lesson_status = $_user_lesson_status->comment_approved; |
1593 | 1593 | } |
1594 | 1594 | else { |
@@ -1596,12 +1596,12 @@ discard block |
||
1596 | 1596 | } |
1597 | 1597 | $lesson_id = $lesson; |
1598 | 1598 | } |
1599 | - if ( 'in-progress' != $user_lesson_status ) { |
|
1599 | + if ('in-progress' != $user_lesson_status) { |
|
1600 | 1600 | // Check for Passed or Completed Setting |
1601 | 1601 | // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting |
1602 | 1602 | // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
1603 | 1603 | // if ( 'passed' == $course_completion ) { |
1604 | - switch( $user_lesson_status ) { |
|
1604 | + switch ($user_lesson_status) { |
|
1605 | 1605 | case 'complete': |
1606 | 1606 | case 'graded': |
1607 | 1607 | case 'passed': |
@@ -1610,13 +1610,13 @@ discard block |
||
1610 | 1610 | |
1611 | 1611 | case 'failed': |
1612 | 1612 | // This may be 'completed' depending on... |
1613 | - if ( $lesson_id ) { |
|
1613 | + if ($lesson_id) { |
|
1614 | 1614 | // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson |
1615 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1616 | - if ( $lesson_quiz_id ) { |
|
1615 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1616 | + if ($lesson_quiz_id) { |
|
1617 | 1617 | // ...the quiz pass setting |
1618 | - $pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true ); |
|
1619 | - if ( empty($pass_required) ) { |
|
1618 | + $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); |
|
1619 | + if (empty($pass_required)) { |
|
1620 | 1620 | // We just require the user to have done the quiz, not to have passed |
1621 | 1621 | return true; |
1622 | 1622 | } |
@@ -1639,15 +1639,15 @@ discard block |
||
1639 | 1639 | * @param int $user_id |
1640 | 1640 | * @return object |
1641 | 1641 | */ |
1642 | - public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
|
1642 | + public static function user_course_status($course_id = 0, $user_id = 0) { |
|
1643 | 1643 | |
1644 | 1644 | |
1645 | - if( $course_id ) { |
|
1646 | - if( ! $user_id ) { |
|
1645 | + if ($course_id) { |
|
1646 | + if ( ! $user_id) { |
|
1647 | 1647 | $user_id = get_current_user_id(); |
1648 | 1648 | } |
1649 | 1649 | |
1650 | - $user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true ); |
|
1650 | + $user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true); |
|
1651 | 1651 | return $user_course_status; |
1652 | 1652 | } |
1653 | 1653 | |
@@ -1662,27 +1662,27 @@ discard block |
||
1662 | 1662 | * @param int $user_id |
1663 | 1663 | * @return object | bool |
1664 | 1664 | */ |
1665 | - public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
|
1665 | + public static function user_lesson_status($lesson_id = 0, $user_id = 0) { |
|
1666 | 1666 | |
1667 | - if( ! $user_id ) { |
|
1667 | + if ( ! $user_id) { |
|
1668 | 1668 | $user_id = get_current_user_id(); |
1669 | 1669 | } |
1670 | 1670 | |
1671 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
1671 | + if ($lesson_id > 0 && $user_id > 0) { |
|
1672 | 1672 | |
1673 | - $user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true ); |
|
1673 | + $user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true); |
|
1674 | 1674 | return $user_lesson_status; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | return false; |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - public static function is_preview_lesson( $lesson_id ) { |
|
1680 | + public static function is_preview_lesson($lesson_id) { |
|
1681 | 1681 | $is_preview = false; |
1682 | 1682 | |
1683 | - if( 'lesson' == get_post_type( $lesson_id ) ) { |
|
1684 | - $lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true ); |
|
1685 | - if ( isset( $lesson_preview ) && '' != $lesson_preview ) { |
|
1683 | + if ('lesson' == get_post_type($lesson_id)) { |
|
1684 | + $lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true); |
|
1685 | + if (isset($lesson_preview) && '' != $lesson_preview) { |
|
1686 | 1686 | $is_preview = true; |
1687 | 1687 | } |
1688 | 1688 | } |
@@ -1690,22 +1690,22 @@ discard block |
||
1690 | 1690 | return $is_preview; |
1691 | 1691 | } |
1692 | 1692 | |
1693 | - public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
|
1693 | + public static function user_passed_quiz($quiz_id = 0, $user_id = 0) { |
|
1694 | 1694 | |
1695 | - if( ! $quiz_id ) return false; |
|
1695 | + if ( ! $quiz_id) return false; |
|
1696 | 1696 | |
1697 | - if( ! $user_id ) { |
|
1697 | + if ( ! $user_id) { |
|
1698 | 1698 | $user_id = get_current_user_id(); |
1699 | 1699 | } |
1700 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
1700 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
1701 | 1701 | |
1702 | 1702 | // Quiz Grade |
1703 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1704 | - $quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
1703 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
1704 | + $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
1705 | 1705 | |
1706 | 1706 | // Check if Grade is greater than or equal to pass percentage |
1707 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
1708 | - if ( $quiz_passmark <= intval( $quiz_grade ) ) { |
|
1707 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
1708 | + if ($quiz_passmark <= intval($quiz_grade)) { |
|
1709 | 1709 | return true; |
1710 | 1710 | } |
1711 | 1711 | |
@@ -1725,9 +1725,9 @@ discard block |
||
1725 | 1725 | * |
1726 | 1726 | * @return mixed false or comment_ID |
1727 | 1727 | */ |
1728 | - public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
|
1728 | + public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) { |
|
1729 | 1729 | $comment_id = false; |
1730 | - if ( !empty($status) ) { |
|
1730 | + if ( ! empty($status)) { |
|
1731 | 1731 | $args = array( |
1732 | 1732 | 'user_id' => $user_id, |
1733 | 1733 | 'post_id' => $lesson_id, |
@@ -1736,18 +1736,18 @@ discard block |
||
1736 | 1736 | 'action' => 'update', // Update the existing status... |
1737 | 1737 | 'keep_time' => true, // ...but don't change the existing timestamp |
1738 | 1738 | ); |
1739 | - if( 'in-progress' == $status ) { |
|
1740 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
1739 | + if ('in-progress' == $status) { |
|
1740 | + unset($args['keep_time']); // Keep updating what's happened |
|
1741 | 1741 | } |
1742 | 1742 | |
1743 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
1744 | - if ( $comment_id && !empty($metadata) ) { |
|
1745 | - foreach( $metadata as $key => $value ) { |
|
1746 | - update_comment_meta( $comment_id, $key, $value ); |
|
1743 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
1744 | + if ($comment_id && ! empty($metadata)) { |
|
1745 | + foreach ($metadata as $key => $value) { |
|
1746 | + update_comment_meta($comment_id, $key, $value); |
|
1747 | 1747 | } |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id ); |
|
1750 | + do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id); |
|
1751 | 1751 | } |
1752 | 1752 | return $comment_id; |
1753 | 1753 | } |
@@ -1763,9 +1763,9 @@ discard block |
||
1763 | 1763 | * @param array $metadata |
1764 | 1764 | * @return mixed false or comment_ID |
1765 | 1765 | */ |
1766 | - public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
|
1766 | + public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) { |
|
1767 | 1767 | $comment_id = false; |
1768 | - if ( !empty($status) ) { |
|
1768 | + if ( ! empty($status)) { |
|
1769 | 1769 | $args = array( |
1770 | 1770 | 'user_id' => $user_id, |
1771 | 1771 | 'post_id' => $course_id, |
@@ -1774,17 +1774,17 @@ discard block |
||
1774 | 1774 | 'action' => 'update', // Update the existing status... |
1775 | 1775 | 'keep_time' => true, // ...but don't change the existing timestamp |
1776 | 1776 | ); |
1777 | - if( 'in-progress' == $status ) { |
|
1778 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
1777 | + if ('in-progress' == $status) { |
|
1778 | + unset($args['keep_time']); // Keep updating what's happened |
|
1779 | 1779 | } |
1780 | 1780 | |
1781 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
1782 | - if ( $comment_id && !empty($metadata) ) { |
|
1783 | - foreach( $metadata as $key => $value ) { |
|
1784 | - update_comment_meta( $comment_id, $key, $value ); |
|
1781 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
1782 | + if ($comment_id && ! empty($metadata)) { |
|
1783 | + foreach ($metadata as $key => $value) { |
|
1784 | + update_comment_meta($comment_id, $key, $value); |
|
1785 | 1785 | } |
1786 | 1786 | } |
1787 | - do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id ); |
|
1787 | + do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id); |
|
1788 | 1788 | } |
1789 | 1789 | return $comment_id; |
1790 | 1790 | } |
@@ -1796,9 +1796,9 @@ discard block |
||
1796 | 1796 | * @param array $pieces (default: array()) |
1797 | 1797 | * @return array |
1798 | 1798 | */ |
1799 | - public static function single_comment_filter( $pieces ) { |
|
1800 | - unset( $pieces['orderby'] ); |
|
1801 | - unset( $pieces['order'] ); |
|
1799 | + public static function single_comment_filter($pieces) { |
|
1800 | + unset($pieces['orderby']); |
|
1801 | + unset($pieces['order']); |
|
1802 | 1802 | |
1803 | 1803 | return $pieces; |
1804 | 1804 | } |
@@ -1810,9 +1810,9 @@ discard block |
||
1810 | 1810 | * @param array $pieces (default: array()) |
1811 | 1811 | * @return array |
1812 | 1812 | */ |
1813 | - public static function comment_any_status_filter( $pieces ) { |
|
1813 | + public static function comment_any_status_filter($pieces) { |
|
1814 | 1814 | |
1815 | - $pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] ); |
|
1815 | + $pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']); |
|
1816 | 1816 | |
1817 | 1817 | return $pieces; |
1818 | 1818 | } |
@@ -1824,12 +1824,12 @@ discard block |
||
1824 | 1824 | * @param array $pieces (default: array()) |
1825 | 1825 | * @return array |
1826 | 1826 | */ |
1827 | - public static function comment_multiple_status_filter( $pieces ) { |
|
1827 | + public static function comment_multiple_status_filter($pieces) { |
|
1828 | 1828 | |
1829 | - preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder ); |
|
1830 | - if ( !empty($placeholder[1]) ) { |
|
1831 | - $statuses = explode( ',', $placeholder[1] ); |
|
1832 | - $pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] ); |
|
1829 | + preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder); |
|
1830 | + if ( ! empty($placeholder[1])) { |
|
1831 | + $statuses = explode(',', $placeholder[1]); |
|
1832 | + $pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']); |
|
1833 | 1833 | } |
1834 | 1834 | |
1835 | 1835 | return $pieces; |
@@ -1841,12 +1841,12 @@ discard block |
||
1841 | 1841 | * @param array $pieces |
1842 | 1842 | * @return array $pieces |
1843 | 1843 | */ |
1844 | - public static function comment_total_sum_meta_value_filter( $pieces ) { |
|
1844 | + public static function comment_total_sum_meta_value_filter($pieces) { |
|
1845 | 1845 | global $wpdb, $wp_version; |
1846 | 1846 | |
1847 | 1847 | $pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum "; |
1848 | - unset( $pieces['groupby'] ); |
|
1849 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1848 | + unset($pieces['groupby']); |
|
1849 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1850 | 1850 | $args['order'] = false; |
1851 | 1851 | $args['orderby'] = false; |
1852 | 1852 | } |
@@ -1861,12 +1861,12 @@ discard block |
||
1861 | 1861 | * @param array $pieces (default: array()) |
1862 | 1862 | * @return array |
1863 | 1863 | */ |
1864 | - public static function get_posts_count_only_filter( $pieces ) { |
|
1864 | + public static function get_posts_count_only_filter($pieces) { |
|
1865 | 1865 | global $wp_version; |
1866 | 1866 | |
1867 | 1867 | $pieces['fields'] = " COUNT(*) AS total "; |
1868 | - unset( $pieces['groupby'] ); |
|
1869 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1868 | + unset($pieces['groupby']); |
|
1869 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1870 | 1870 | $args['order'] = false; |
1871 | 1871 | $args['orderby'] = false; |
1872 | 1872 | } |
@@ -1885,9 +1885,9 @@ discard block |
||
1885 | 1885 | * |
1886 | 1886 | * @return bool $success |
1887 | 1887 | */ |
1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1888 | + public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
1889 | 1889 | |
1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1890 | + return self::update_user_data($data_key, $post_id, $value, $user_id); |
|
1891 | 1891 | |
1892 | 1892 | }// end add_user_data |
1893 | 1893 | |
@@ -1906,18 +1906,18 @@ discard block |
||
1906 | 1906 | * |
1907 | 1907 | * @return bool $success |
1908 | 1908 | */ |
1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1909 | + public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
1910 | 1910 | |
1911 | - if( ! ( $user_id > 0 ) ){ |
|
1911 | + if ( ! ($user_id > 0)) { |
|
1912 | 1912 | $user_id = get_current_user_id(); |
1913 | 1913 | } |
1914 | 1914 | |
1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | - $post_type = get_post_type( $post_id ); |
|
1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | - || !get_userdata( $user_id ) |
|
1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
1915 | + $supported_post_types = array('course', 'lesson'); |
|
1916 | + $post_type = get_post_type($post_id); |
|
1917 | + if (empty($post_id) || empty($data_key) |
|
1918 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
1919 | + || ! get_userdata($user_id) |
|
1920 | + || ! in_array($post_type, $supported_post_types)) { |
|
1921 | 1921 | |
1922 | 1922 | return false; |
1923 | 1923 | } |
@@ -1925,20 +1925,20 @@ discard block |
||
1925 | 1925 | // check if there and existing Sensei status on this post type if not create it |
1926 | 1926 | // and get the activity ID |
1927 | 1927 | $status_function = 'user_'.$post_type.'_status'; |
1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1928 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
1929 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
1930 | 1930 | |
1931 | 1931 | $start_function = 'user_start_'.$post_type; |
1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1932 | + $sensei_user_activity_id = self::$start_function($user_id, $post_id); |
|
1933 | 1933 | |
1934 | - }else{ |
|
1934 | + } else { |
|
1935 | 1935 | |
1936 | 1936 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
1937 | 1937 | |
1938 | 1938 | } |
1939 | 1939 | |
1940 | 1940 | // store the data |
1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1941 | + $success = update_comment_meta($sensei_user_activity_id, $data_key, $value); |
|
1942 | 1942 | |
1943 | 1943 | return $success; |
1944 | 1944 | |
@@ -1957,20 +1957,20 @@ discard block |
||
1957 | 1957 | * |
1958 | 1958 | * @return mixed $user_data_value |
1959 | 1959 | */ |
1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1960 | + public static function get_user_data($data_key, $post_id, $user_id = 0) { |
|
1961 | 1961 | |
1962 | 1962 | $user_data_value = true; |
1963 | 1963 | |
1964 | - if( ! ( $user_id > 0 ) ){ |
|
1964 | + if ( ! ($user_id > 0)) { |
|
1965 | 1965 | $user_id = get_current_user_id(); |
1966 | 1966 | } |
1967 | 1967 | |
1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | - $post_type = get_post_type( $post_id ); |
|
1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | - || ! get_userdata( $user_id ) |
|
1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1968 | + $supported_post_types = array('course', 'lesson'); |
|
1969 | + $post_type = get_post_type($post_id); |
|
1970 | + if (empty($post_id) || empty($data_key) |
|
1971 | + || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
1972 | + || ! get_userdata($user_id) |
|
1973 | + || ! in_array($post_type, $supported_post_types)) { |
|
1974 | 1974 | |
1975 | 1975 | return false; |
1976 | 1976 | } |
@@ -1978,13 +1978,13 @@ discard block |
||
1978 | 1978 | // check if there and existing Sensei status on this post type if not create it |
1979 | 1979 | // and get the activity ID |
1980 | 1980 | $status_function = 'user_'.$post_type.'_status'; |
1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1981 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
1982 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
1983 | 1983 | return false; |
1984 | 1984 | } |
1985 | 1985 | |
1986 | 1986 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1987 | + $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true); |
|
1988 | 1988 | |
1989 | 1989 | return $user_data_value; |
1990 | 1990 | |
@@ -1999,19 +1999,19 @@ discard block |
||
1999 | 1999 | * |
2000 | 2000 | * @return bool $deleted |
2001 | 2001 | */ |
2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2002 | + public static function delete_user_data($data_key, $post_id, $user_id) { |
|
2003 | 2003 | $deleted = true; |
2004 | 2004 | |
2005 | - if( ! ( $user_id > 0 ) ){ |
|
2005 | + if ( ! ($user_id > 0)) { |
|
2006 | 2006 | $user_id = get_current_user_id(); |
2007 | 2007 | } |
2008 | 2008 | |
2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | - $post_type = get_post_type( $post_id ); |
|
2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | - || ! get_userdata( $user_id ) |
|
2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
2009 | + $supported_post_types = array('course', 'lesson'); |
|
2010 | + $post_type = get_post_type($post_id); |
|
2011 | + if (empty($post_id) || empty($data_key) |
|
2012 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
2013 | + || ! get_userdata($user_id) |
|
2014 | + || ! in_array($post_type, $supported_post_types)) { |
|
2015 | 2015 | |
2016 | 2016 | return false; |
2017 | 2017 | } |
@@ -2019,13 +2019,13 @@ discard block |
||
2019 | 2019 | // check if there and existing Sensei status on this post type if not create it |
2020 | 2020 | // and get the activity ID |
2021 | 2021 | $status_function = 'user_'.$post_type.'_status'; |
2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2022 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
2023 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
2024 | 2024 | return false; |
2025 | 2025 | } |
2026 | 2026 | |
2027 | 2027 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2028 | + $deleted = delete_comment_meta($sensei_user_activity_id, $data_key); |
|
2029 | 2029 | |
2030 | 2030 | return $deleted; |
2031 | 2031 | |
@@ -2050,62 +2050,62 @@ discard block |
||
2050 | 2050 | * |
2051 | 2051 | * @return string $drop_down_element |
2052 | 2052 | */ |
2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2053 | + public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) { |
|
2054 | 2054 | |
2055 | 2055 | $drop_down_element = ''; |
2056 | 2056 | |
2057 | 2057 | // setup the basic attributes |
2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2058 | + if ( ! isset($attributes['name']) || empty($attributes['name'])) { |
|
2059 | 2059 | |
2060 | 2060 | $attributes['name'] = 'sensei-options'; |
2061 | 2061 | |
2062 | 2062 | } |
2063 | 2063 | |
2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2064 | + if ( ! isset($attributes['id']) || empty($attributes['id'])) { |
|
2065 | 2065 | |
2066 | 2066 | $attributes['id'] = 'sensei-options'; |
2067 | 2067 | |
2068 | 2068 | } |
2069 | 2069 | |
2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2070 | + if ( ! isset($attributes['class']) || empty($attributes['class'])) { |
|
2071 | 2071 | |
2072 | - $attributes['class'] ='chosen_select widefat'; |
|
2072 | + $attributes['class'] = 'chosen_select widefat'; |
|
2073 | 2073 | |
2074 | 2074 | } |
2075 | 2075 | |
2076 | 2076 | // create element attributes |
2077 | 2077 | $combined_attributes = ''; |
2078 | - foreach( $attributes as $attribute => $value ){ |
|
2078 | + foreach ($attributes as $attribute => $value) { |
|
2079 | 2079 | |
2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2080 | + $combined_attributes .= $attribute.'="'.$value.'"'.' '; |
|
2081 | 2081 | |
2082 | 2082 | }// end for each |
2083 | 2083 | |
2084 | 2084 | |
2085 | 2085 | // create the select element |
2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2086 | + $drop_down_element .= '<select '.$combined_attributes.' >'."\n"; |
|
2087 | 2087 | |
2088 | 2088 | // show the none option if the client requested |
2089 | - if( $enable_none_option ) { |
|
2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2089 | + if ($enable_none_option) { |
|
2090 | + $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
2091 | 2091 | } |
2092 | 2092 | |
2093 | - if ( count( $options ) > 0 ) { |
|
2093 | + if (count($options) > 0) { |
|
2094 | 2094 | |
2095 | - foreach ($options as $value => $option ){ |
|
2095 | + foreach ($options as $value => $option) { |
|
2096 | 2096 | |
2097 | 2097 | $element = ''; |
2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2098 | + $element .= '<option value="'.esc_attr($value).'"'; |
|
2099 | + $element .= selected($value, $selected_value, false).'>'; |
|
2100 | + $element .= esc_html($option).'</option>'."\n"; |
|
2101 | 2101 | |
2102 | 2102 | // add the element to the select html |
2103 | - $drop_down_element.= $element; |
|
2103 | + $drop_down_element .= $element; |
|
2104 | 2104 | } // End For Loop |
2105 | 2105 | |
2106 | 2106 | } // End If Statement |
2107 | 2107 | |
2108 | - $drop_down_element .= '</select>' . "\n"; |
|
2108 | + $drop_down_element .= '</select>'."\n"; |
|
2109 | 2109 | |
2110 | 2110 | return $drop_down_element; |
2111 | 2111 | |
@@ -2125,14 +2125,14 @@ discard block |
||
2125 | 2125 | * |
2126 | 2126 | * @return double $val |
2127 | 2127 | */ |
2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2128 | + public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') { |
|
2129 | 2129 | |
2130 | 2130 | /**å |
2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
2132 | 2132 | * the precision given will be passed into the php round function |
2133 | 2133 | * @since 1.8.5 |
2134 | 2134 | */ |
2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2135 | + $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode); |
|
2136 | 2136 | |
2137 | 2137 | /** |
2138 | 2138 | * Change the mode for the Sensei_Utils::round function. |
@@ -2142,15 +2142,15 @@ discard block |
||
2142 | 2142 | * |
2143 | 2143 | * @since 1.8.5 |
2144 | 2144 | */ |
2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2145 | + $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision); |
|
2146 | 2146 | |
2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2147 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
2148 | 2148 | |
2149 | - return round( $val, $precision, $mode ); |
|
2149 | + return round($val, $precision, $mode); |
|
2150 | 2150 | |
2151 | - }else{ |
|
2151 | + } else { |
|
2152 | 2152 | |
2153 | - return round( $val, $precision ); |
|
2153 | + return round($val, $precision); |
|
2154 | 2154 | |
2155 | 2155 | } |
2156 | 2156 | |
@@ -2162,15 +2162,15 @@ discard block |
||
2162 | 2162 | * @since 1.9.0 |
2163 | 2163 | * @return string $url |
2164 | 2164 | */ |
2165 | - public static function get_current_url(){ |
|
2165 | + public static function get_current_url() { |
|
2166 | 2166 | |
2167 | 2167 | global $wp; |
2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | - if ( isset( $_GET ) ) { |
|
2168 | + $current_url = trailingslashit(home_url($wp->request)); |
|
2169 | + if (isset($_GET)) { |
|
2170 | 2170 | |
2171 | - foreach ($_GET as $param => $val ) { |
|
2171 | + foreach ($_GET as $param => $val) { |
|
2172 | 2172 | |
2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
2173 | + $current_url = add_query_arg($param, $val, $current_url); |
|
2174 | 2174 | |
2175 | 2175 | } |
2176 | 2176 | } |
@@ -2200,27 +2200,27 @@ discard block |
||
2200 | 2200 | * @param array $array_b |
2201 | 2201 | * @return array $merged_array |
2202 | 2202 | */ |
2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
2203 | + public static function array_zip_merge($array_a, $array_b) { |
|
2204 | 2204 | |
2205 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
2205 | + if ( ! isset($array_a[0]) || ! isset($array_b[0])) { |
|
2206 | 2206 | trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
2207 | 2207 | } |
2208 | 2208 | |
2209 | 2209 | $merged_array = array(); |
2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
2210 | + $total_elements = count($array_a) + count($array_b); |
|
2211 | 2211 | |
2212 | 2212 | // Zip arrays |
2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
2213 | + for ($i = 0; $i < $total_elements; $i++) { |
|
2214 | 2214 | |
2215 | 2215 | // if has an element at current index push a on top |
2216 | - if( isset( $array_a[ $i ] ) ){ |
|
2217 | - $merged_array[] = $array_a[ $i ] ; |
|
2216 | + if (isset($array_a[$i])) { |
|
2217 | + $merged_array[] = $array_a[$i]; |
|
2218 | 2218 | } |
2219 | 2219 | |
2220 | 2220 | // next if $array_b has an element at current index push a on top of the element |
2221 | 2221 | // from a if there was one, if not the element before that. |
2222 | - if( isset( $array_b[ $i ] ) ){ |
|
2223 | - $merged_array[] = $array_b[ $i ] ; |
|
2222 | + if (isset($array_b[$i])) { |
|
2223 | + $merged_array[] = $array_b[$i]; |
|
2224 | 2224 | } |
2225 | 2225 | |
2226 | 2226 | } |
@@ -2235,4 +2235,4 @@ discard block |
||
2235 | 2235 | * for backward compatibility |
2236 | 2236 | * @since 1.9.0 |
2237 | 2237 | */ |
2238 | -class WooThemes_Sensei_Utils extends Sensei_Utils{} |
|
2239 | 2238 | \ No newline at end of file |
2239 | +class WooThemes_Sensei_Utils extends Sensei_Utils {} |
|
2240 | 2240 | \ No newline at end of file |