@@ -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 Frontend Class |
@@ -20,78 +20,78 @@ discard block |
||
| 20 | 20 | * Constructor. |
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | - public function __construct () { |
|
| 23 | + public function __construct() { |
|
| 24 | 24 | |
| 25 | 25 | // Template output actions |
| 26 | - add_action( 'sensei_before_main_content', array( $this, 'sensei_output_content_wrapper' ), 10 ); |
|
| 27 | - add_action( 'sensei_after_main_content', array( $this, 'sensei_output_content_wrapper_end' ), 10 ); |
|
| 28 | - add_action( 'sensei_lesson_archive_lesson_title', array( $this, 'sensei_lesson_archive_lesson_title' ), 10 ); |
|
| 26 | + add_action('sensei_before_main_content', array($this, 'sensei_output_content_wrapper'), 10); |
|
| 27 | + add_action('sensei_after_main_content', array($this, 'sensei_output_content_wrapper_end'), 10); |
|
| 28 | + add_action('sensei_lesson_archive_lesson_title', array($this, 'sensei_lesson_archive_lesson_title'), 10); |
|
| 29 | 29 | |
| 30 | 30 | // 1.2.1 |
| 31 | - add_action( 'wp_head', array( $this, 'sensei_complete_lesson' ), 10 ); |
|
| 32 | - add_action( 'wp_head', array( $this, 'sensei_complete_course' ), 10 ); |
|
| 33 | - add_action( 'sensei_frontend_messages', array( $this, 'sensei_frontend_messages' ) ); |
|
| 34 | - add_action( 'sensei_lesson_video', array( $this, 'sensei_lesson_video' ), 10, 1 ); |
|
| 35 | - add_action( 'sensei_complete_lesson_button', array( $this, 'sensei_complete_lesson_button' ) ); |
|
| 36 | - add_action( 'sensei_reset_lesson_button', array( $this, 'sensei_reset_lesson_button' ) ); |
|
| 31 | + add_action('wp_head', array($this, 'sensei_complete_lesson'), 10); |
|
| 32 | + add_action('wp_head', array($this, 'sensei_complete_course'), 10); |
|
| 33 | + add_action('sensei_frontend_messages', array($this, 'sensei_frontend_messages')); |
|
| 34 | + add_action('sensei_lesson_video', array($this, 'sensei_lesson_video'), 10, 1); |
|
| 35 | + add_action('sensei_complete_lesson_button', array($this, 'sensei_complete_lesson_button')); |
|
| 36 | + add_action('sensei_reset_lesson_button', array($this, 'sensei_reset_lesson_button')); |
|
| 37 | 37 | |
| 38 | - add_action( 'sensei_course_archive_meta', array( $this, 'sensei_course_archive_meta' ) ); |
|
| 38 | + add_action('sensei_course_archive_meta', array($this, 'sensei_course_archive_meta')); |
|
| 39 | 39 | |
| 40 | - add_action( 'sensei_lesson_tag_main_content', array( $this, 'sensei_lesson_archive_main_content' ), 10 ); |
|
| 41 | - add_action( 'sensei_no_permissions_main_content', array( $this, 'sensei_no_permissions_main_content' ), 10 ); |
|
| 40 | + add_action('sensei_lesson_tag_main_content', array($this, 'sensei_lesson_archive_main_content'), 10); |
|
| 41 | + add_action('sensei_no_permissions_main_content', array($this, 'sensei_no_permissions_main_content'), 10); |
|
| 42 | 42 | |
| 43 | - add_action( 'sensei_lesson_meta', array( $this, 'sensei_lesson_meta' ), 10 ); |
|
| 44 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'sensei_course_start' ), 10 ); |
|
| 43 | + add_action('sensei_lesson_meta', array($this, 'sensei_lesson_meta'), 10); |
|
| 44 | + add_action('sensei_single_course_content_inside_before', array($this, 'sensei_course_start'), 10); |
|
| 45 | 45 | |
| 46 | 46 | // add_filter( 'get_comments_number', array( $this, 'sensei_lesson_comment_count' ), 1 ); |
| 47 | - add_filter( 'the_title', array( $this, 'sensei_lesson_preview_title' ), 10, 2 ); |
|
| 47 | + add_filter('the_title', array($this, 'sensei_lesson_preview_title'), 10, 2); |
|
| 48 | 48 | |
| 49 | 49 | //1.6.2 |
| 50 | - add_filter( 'wp_login_failed', array( $this, 'sensei_login_fail_redirect' ), 10 ); |
|
| 51 | - add_filter( 'init', array( $this, 'sensei_handle_login_request' ), 10 ); |
|
| 50 | + add_filter('wp_login_failed', array($this, 'sensei_login_fail_redirect'), 10); |
|
| 51 | + add_filter('init', array($this, 'sensei_handle_login_request'), 10); |
|
| 52 | 52 | //1.6.3 |
| 53 | - add_action( 'init', array( $this, 'sensei_process_registration' ), 2 ); |
|
| 53 | + add_action('init', array($this, 'sensei_process_registration'), 2); |
|
| 54 | 54 | //1.7.0 |
| 55 | - add_action( 'sensei_pagination', array( $this, 'sensei_breadcrumb' ), 80, 1 ); |
|
| 55 | + add_action('sensei_pagination', array($this, 'sensei_breadcrumb'), 80, 1); |
|
| 56 | 56 | |
| 57 | 57 | // Fix pagination for course archive pages when filtering by course type |
| 58 | - add_filter( 'pre_get_posts', array( $this, 'sensei_course_archive_pagination' ) ); |
|
| 58 | + add_filter('pre_get_posts', array($this, 'sensei_course_archive_pagination')); |
|
| 59 | 59 | |
| 60 | 60 | // Scripts and Styles |
| 61 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 62 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 61 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 62 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
| 63 | 63 | |
| 64 | 64 | // Custom Menu Item filters |
| 65 | - add_filter( 'wp_setup_nav_menu_item', array( $this, 'sensei_setup_nav_menu_item' ) ); |
|
| 66 | - add_filter( 'wp_nav_menu_objects', array( $this, 'sensei_wp_nav_menu_objects' ) ); |
|
| 65 | + add_filter('wp_setup_nav_menu_item', array($this, 'sensei_setup_nav_menu_item')); |
|
| 66 | + add_filter('wp_nav_menu_objects', array($this, 'sensei_wp_nav_menu_objects')); |
|
| 67 | 67 | // Search Results filters |
| 68 | - add_filter( 'post_class', array( $this, 'sensei_search_results_classes' ), 10 ); |
|
| 68 | + add_filter('post_class', array($this, 'sensei_search_results_classes'), 10); |
|
| 69 | 69 | // Only show course & lesson excerpts in search results |
| 70 | - add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) ); |
|
| 70 | + add_filter('the_content', array($this, 'sensei_search_results_excerpt')); |
|
| 71 | 71 | |
| 72 | 72 | //Use WooCommerce filter to show admin bar to Teachers. |
| 73 | - add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
| 73 | + add_action('init', array($this, 'sensei_show_admin_bar')); |
|
| 74 | 74 | |
| 75 | 75 | // Remove course from active courses if an order is cancelled or refunded |
| 76 | - add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 77 | - add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 78 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 79 | - add_action( 'woocommerce_order_status_processing_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 80 | - add_action( 'woocommerce_order_status_completed_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 81 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 76 | + add_action('woocommerce_order_status_processing_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 77 | + add_action('woocommerce_order_status_completed_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 78 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 79 | + add_action('woocommerce_order_status_processing_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 80 | + add_action('woocommerce_order_status_completed_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 81 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 82 | 82 | |
| 83 | 83 | // Make sure correct courses are marked as active for users |
| 84 | - add_action( 'sensei_before_my_courses', array( $this, 'activate_purchased_courses' ), 10, 1 ); |
|
| 85 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'activate_purchased_single_course' ), 10 ); |
|
| 84 | + add_action('sensei_before_my_courses', array($this, 'activate_purchased_courses'), 10, 1); |
|
| 85 | + add_action('sensei_single_course_content_inside_before', array($this, 'activate_purchased_single_course'), 10); |
|
| 86 | 86 | |
| 87 | 87 | // Lesson tags |
| 88 | - add_action( 'sensei_lesson_meta_extra', array( $this, 'lesson_tags_display' ), 10, 1 ); |
|
| 89 | - add_action( 'pre_get_posts', array( $this, 'lesson_tag_archive_filter' ), 10, 1 ); |
|
| 90 | - add_filter( 'sensei_lessons_archive_text', array( $this, 'lesson_tag_archive_header' ) ); |
|
| 91 | - add_action( 'sensei_loop_lesson_inside_before', array( $this, 'lesson_tag_archive_description' ), 11 ); |
|
| 88 | + add_action('sensei_lesson_meta_extra', array($this, 'lesson_tags_display'), 10, 1); |
|
| 89 | + add_action('pre_get_posts', array($this, 'lesson_tag_archive_filter'), 10, 1); |
|
| 90 | + add_filter('sensei_lessons_archive_text', array($this, 'lesson_tag_archive_header')); |
|
| 91 | + add_action('sensei_loop_lesson_inside_before', array($this, 'lesson_tag_archive_description'), 11); |
|
| 92 | 92 | |
| 93 | 93 | // Hide Sensei activity comments from lesson and course pages |
| 94 | - add_filter( 'wp_list_comments_args', array( $this, 'hide_sensei_activity' ) ); |
|
| 94 | + add_filter('wp_list_comments_args', array($this, 'hide_sensei_activity')); |
|
| 95 | 95 | } // End __construct() |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | * @since 1.7.3 |
| 102 | 102 | * @return array|mixed |
| 103 | 103 | */ |
| 104 | - public function __get( $key ) { |
|
| 104 | + public function __get($key) { |
|
| 105 | 105 | |
| 106 | - if ( 'lesson' == $key || 'course' == $key ) { |
|
| 107 | - if ( WP_DEBUG ) { |
|
| 108 | - trigger_error( sprintf( 'Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3' ) ); |
|
| 106 | + if ('lesson' == $key || 'course' == $key) { |
|
| 107 | + if (WP_DEBUG) { |
|
| 108 | + trigger_error(sprintf('Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3')); |
|
| 109 | 109 | } |
| 110 | 110 | return Sensei()->$key; |
| 111 | 111 | } |
@@ -118,32 +118,32 @@ discard block |
||
| 118 | 118 | * @since 1.0.0 |
| 119 | 119 | * @return void |
| 120 | 120 | */ |
| 121 | - public function enqueue_scripts () { |
|
| 121 | + public function enqueue_scripts() { |
|
| 122 | 122 | |
| 123 | 123 | $disable_js = false; |
| 124 | - if ( isset( Sensei()->settings->settings[ 'js_disable' ] ) ) { |
|
| 125 | - $disable_js = Sensei()->settings->settings[ 'js_disable' ]; |
|
| 124 | + if (isset(Sensei()->settings->settings['js_disable'])) { |
|
| 125 | + $disable_js = Sensei()->settings->settings['js_disable']; |
|
| 126 | 126 | } // End If Statement |
| 127 | - if ( ! $disable_js ) { |
|
| 127 | + if ( ! $disable_js) { |
|
| 128 | 128 | |
| 129 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 129 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 130 | 130 | |
| 131 | 131 | // My Courses tabs script |
| 132 | - wp_register_script( Sensei()->token . '-user-dashboard', esc_url( Sensei()->plugin_url . 'assets/js/user-dashboard' . $suffix . '.js' ), array( 'jquery-ui-tabs' ), Sensei()->version, true ); |
|
| 133 | - wp_enqueue_script( Sensei()->token . '-user-dashboard' ); |
|
| 132 | + wp_register_script(Sensei()->token.'-user-dashboard', esc_url(Sensei()->plugin_url.'assets/js/user-dashboard'.$suffix.'.js'), array('jquery-ui-tabs'), Sensei()->version, true); |
|
| 133 | + wp_enqueue_script(Sensei()->token.'-user-dashboard'); |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | // Course Archive javascript |
| 137 | - if( is_post_type_archive( 'course' ) ){ |
|
| 137 | + if (is_post_type_archive('course')) { |
|
| 138 | 138 | |
| 139 | - wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
| 140 | - wp_enqueue_script( 'sensei-course-archive-js' ); |
|
| 139 | + wp_register_script('sensei-course-archive-js', esc_url(Sensei()->plugin_url.'assets/js/frontend/course-archive'.$suffix.'.js'), array('jquery'), '1', true); |
|
| 140 | + wp_enqueue_script('sensei-course-archive-js'); |
|
| 141 | 141 | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | 145 | // Allow additional scripts to be loaded |
| 146 | - do_action( 'sensei_additional_scripts' ); |
|
| 146 | + do_action('sensei_additional_scripts'); |
|
| 147 | 147 | |
| 148 | 148 | } // End If Statement |
| 149 | 149 | |
@@ -154,23 +154,23 @@ discard block |
||
| 154 | 154 | * @since 1.0.0 |
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | - public function enqueue_styles () { |
|
| 157 | + public function enqueue_styles() { |
|
| 158 | 158 | |
| 159 | 159 | $disable_styles = false; |
| 160 | - if ( isset( Sensei()->settings->settings[ 'styles_disable' ] ) ) { |
|
| 161 | - $disable_styles = Sensei()->settings->settings[ 'styles_disable' ]; |
|
| 160 | + if (isset(Sensei()->settings->settings['styles_disable'])) { |
|
| 161 | + $disable_styles = Sensei()->settings->settings['styles_disable']; |
|
| 162 | 162 | } // End If Statement |
| 163 | 163 | |
| 164 | 164 | // Add filter for theme overrides |
| 165 | - $disable_styles = apply_filters( 'sensei_disable_styles', $disable_styles ); |
|
| 165 | + $disable_styles = apply_filters('sensei_disable_styles', $disable_styles); |
|
| 166 | 166 | |
| 167 | - if ( ! $disable_styles ) { |
|
| 167 | + if ( ! $disable_styles) { |
|
| 168 | 168 | |
| 169 | - wp_register_style( Sensei()->token . '-frontend', Sensei()->plugin_url . 'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen' ); |
|
| 170 | - wp_enqueue_style( Sensei()->token . '-frontend' ); |
|
| 169 | + wp_register_style(Sensei()->token.'-frontend', Sensei()->plugin_url.'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen'); |
|
| 170 | + wp_enqueue_style(Sensei()->token.'-frontend'); |
|
| 171 | 171 | |
| 172 | 172 | // Allow additional stylesheets to be loaded |
| 173 | - do_action( 'sensei_additional_styles' ); |
|
| 173 | + do_action('sensei_additional_styles'); |
|
| 174 | 174 | |
| 175 | 175 | } // End If Statement |
| 176 | 176 | |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | * @param string $name (default: '') |
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | - function sensei_get_template_part( $slug, $name = '' ) { |
|
| 189 | + function sensei_get_template_part($slug, $name = '') { |
|
| 190 | 190 | |
| 191 | - _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
| 192 | - Sensei_Templates::get_part( $slug, $name ); |
|
| 191 | + _deprecated_function('class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part'); |
|
| 192 | + Sensei_Templates::get_part($slug, $name); |
|
| 193 | 193 | |
| 194 | 194 | } // End sensei_get_template_part() |
| 195 | 195 | |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | * @param string $default_path (default: '') |
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | - function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 207 | + function sensei_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 208 | 208 | |
| 209 | - _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
| 210 | - Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
| 209 | + _deprecated_function('sensei_get_template', '1.9.0', 'Sensei_Templates::get_template'); |
|
| 210 | + Sensei_Templates::get_template($template_name, $args, $template_path, $default_path); |
|
| 211 | 211 | |
| 212 | 212 | } // End sensei_get_template() |
| 213 | 213 | |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | * @param string $default_path (default: '') |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 224 | + function sensei_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 225 | 225 | |
| 226 | - _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
| 227 | - Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
| 226 | + _deprecated_function('sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template'); |
|
| 227 | + Sensei_Templates::locate_template($template_name, $template_path, $default_path); |
|
| 228 | 228 | |
| 229 | 229 | } // End sensei_locate_template() |
| 230 | 230 | |
@@ -238,20 +238,20 @@ discard block |
||
| 238 | 238 | function sensei_output_content_wrapper() { |
| 239 | 239 | |
| 240 | 240 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 241 | - $backwards_compatible_wrapper_location = array( |
|
| 242 | - Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
| 241 | + $backwards_compatible_wrapper_location = array( |
|
| 242 | + Sensei()->template_url.'wrappers/wrapper-start.php', |
|
| 243 | 243 | 'wrappers/wrapper-start.php' |
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - $template = locate_template( $backwards_compatible_wrapper_location ); |
|
| 247 | - if( !empty( $template ) ){ |
|
| 246 | + $template = locate_template($backwards_compatible_wrapper_location); |
|
| 247 | + if ( ! empty($template)) { |
|
| 248 | 248 | |
| 249 | - Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
| 249 | + Sensei_Templates::get_template('wrappers/wrapper-start.php'); |
|
| 250 | 250 | return; |
| 251 | 251 | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - Sensei_Templates::get_template( 'globals/wrapper-start.php' ); |
|
| 254 | + Sensei_Templates::get_template('globals/wrapper-start.php'); |
|
| 255 | 255 | |
| 256 | 256 | } // End sensei_output_content_wrapper() |
| 257 | 257 | |
@@ -265,21 +265,21 @@ discard block |
||
| 265 | 265 | function sensei_output_content_wrapper_end() { |
| 266 | 266 | |
| 267 | 267 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 268 | - $backwards_compatible_wrapper_location = array( |
|
| 269 | - Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
| 268 | + $backwards_compatible_wrapper_location = array( |
|
| 269 | + Sensei()->template_url.'wrappers/wrapper-end.php', |
|
| 270 | 270 | 'wrappers/wrapper-end.php' |
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | - $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
| 274 | - if( !empty( $backwards_compatible_template ) ){ |
|
| 273 | + $backwards_compatible_template = locate_template($backwards_compatible_wrapper_location); |
|
| 274 | + if ( ! empty($backwards_compatible_template)) { |
|
| 275 | 275 | |
| 276 | - Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
| 276 | + Sensei_Templates::get_template('wrappers/wrapper-end.php'); |
|
| 277 | 277 | return; |
| 278 | 278 | |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
| 282 | - Sensei_Templates::get_template( 'globals/wrapper-end.php' ); |
|
| 282 | + Sensei_Templates::get_template('globals/wrapper-end.php'); |
|
| 283 | 283 | |
| 284 | 284 | } // End sensei_output_content_wrapper_end() |
| 285 | 285 | |
@@ -292,57 +292,57 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | public static function load_content_pagination() { |
| 294 | 294 | |
| 295 | - if( is_singular('course') ) { |
|
| 295 | + if (is_singular('course')) { |
|
| 296 | 296 | |
| 297 | 297 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 298 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
| 299 | - if( !empty( $template ) ){ |
|
| 298 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-posts.php')); |
|
| 299 | + if ( ! empty($template)) { |
|
| 300 | 300 | |
| 301 | - Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
| 301 | + Sensei_Templates::get_template('wrappers/pagination-posts.php'); |
|
| 302 | 302 | return; |
| 303 | 303 | |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - Sensei_Templates::get_template( 'globals/pagination-posts.php' ); |
|
| 306 | + Sensei_Templates::get_template('globals/pagination-posts.php'); |
|
| 307 | 307 | |
| 308 | - } elseif( is_singular('lesson') ) { |
|
| 308 | + } elseif (is_singular('lesson')) { |
|
| 309 | 309 | |
| 310 | 310 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 311 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
| 312 | - if( !empty( $template ) ){ |
|
| 311 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-lesson.php')); |
|
| 312 | + if ( ! empty($template)) { |
|
| 313 | 313 | |
| 314 | - Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
| 314 | + Sensei_Templates::get_template('wrappers/pagination-lesson.php'); |
|
| 315 | 315 | return; |
| 316 | 316 | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - Sensei_Templates::get_template( 'globals/pagination-lesson.php' ); |
|
| 319 | + Sensei_Templates::get_template('globals/pagination-lesson.php'); |
|
| 320 | 320 | |
| 321 | - } elseif( is_singular('quiz') ) { |
|
| 321 | + } elseif (is_singular('quiz')) { |
|
| 322 | 322 | |
| 323 | 323 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 324 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
| 325 | - if( !empty( $template ) ){ |
|
| 324 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-quiz.php')); |
|
| 325 | + if ( ! empty($template)) { |
|
| 326 | 326 | |
| 327 | - Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
| 327 | + Sensei_Templates::get_template('wrappers/pagination-quiz.php'); |
|
| 328 | 328 | return; |
| 329 | 329 | |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - Sensei_Templates::get_template( 'globals/pagination-quiz.php' ); |
|
| 332 | + Sensei_Templates::get_template('globals/pagination-quiz.php'); |
|
| 333 | 333 | |
| 334 | 334 | } else { |
| 335 | 335 | |
| 336 | 336 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 337 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
| 338 | - if( !empty( $template ) ){ |
|
| 337 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination.php')); |
|
| 338 | + if ( ! empty($template)) { |
|
| 339 | 339 | |
| 340 | - Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
| 340 | + Sensei_Templates::get_template('wrappers/pagination.php'); |
|
| 341 | 341 | return; |
| 342 | 342 | |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - Sensei_Templates::get_template( 'globals/pagination.php' ); |
|
| 345 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 346 | 346 | |
| 347 | 347 | } // End If Statement |
| 348 | 348 | |
@@ -368,21 +368,21 @@ discard block |
||
| 368 | 368 | * @param object $item |
| 369 | 369 | * @return object $item |
| 370 | 370 | */ |
| 371 | - public function sensei_setup_nav_menu_item( $item ) { |
|
| 371 | + public function sensei_setup_nav_menu_item($item) { |
|
| 372 | 372 | global $pagenow, $wp_rewrite; |
| 373 | 373 | |
| 374 | - if( 'nav-menus.php' != $pagenow && !defined('DOING_AJAX') && isset( $item->url ) && 'custom' == $item->type ) { |
|
| 374 | + if ('nav-menus.php' != $pagenow && ! defined('DOING_AJAX') && isset($item->url) && 'custom' == $item->type) { |
|
| 375 | 375 | |
| 376 | 376 | // Set up Sensei menu links |
| 377 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 378 | - $my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 377 | + $course_page_id = intval(Sensei()->settings->settings['course_page']); |
|
| 378 | + $my_account_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
| 379 | 379 | |
| 380 | 380 | $course_page_url = Sensei_Course::get_courses_page_url(); |
| 381 | - $lesson_archive_url = get_post_type_archive_link( 'lesson' ); |
|
| 382 | - $my_courses_url = get_permalink( $my_account_page_id ); |
|
| 383 | - $my_messages_url = get_post_type_archive_link( 'sensei_message' ); |
|
| 381 | + $lesson_archive_url = get_post_type_archive_link('lesson'); |
|
| 382 | + $my_courses_url = get_permalink($my_account_page_id); |
|
| 383 | + $my_messages_url = get_post_type_archive_link('sensei_message'); |
|
| 384 | 384 | |
| 385 | - switch ( $item->url ) { |
|
| 385 | + switch ($item->url) { |
|
| 386 | 386 | case '#senseicourses': |
| 387 | 387 | $item->url = $course_page_url; |
| 388 | 388 | break; |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $item->url = $my_messages_url; |
| 400 | 400 | // if no archive link exist for sensei_message |
| 401 | 401 | // set it back to the place holder |
| 402 | - if( ! $item->url ){ |
|
| 402 | + if ( ! $item->url) { |
|
| 403 | 403 | |
| 404 | 404 | $item->url = '#senseimymessages'; |
| 405 | 405 | |
@@ -407,21 +407,21 @@ discard block |
||
| 407 | 407 | break; |
| 408 | 408 | |
| 409 | 409 | case '#senseilearnerprofile': |
| 410 | - $item->url = esc_url( Sensei()->learner_profiles->get_permalink() ); |
|
| 410 | + $item->url = esc_url(Sensei()->learner_profiles->get_permalink()); |
|
| 411 | 411 | break; |
| 412 | 412 | |
| 413 | 413 | case '#senseiloginlogout': |
| 414 | - $logout_url = wp_logout_url( home_url() ); |
|
| 414 | + $logout_url = wp_logout_url(home_url()); |
|
| 415 | 415 | // Login link links to the My Courses page, to avoid the WP dashboard. |
| 416 | 416 | $login_url = $my_courses_url; |
| 417 | 417 | |
| 418 | - $item->url = ( is_user_logged_in() ? $logout_url : $login_url ); |
|
| 418 | + $item->url = (is_user_logged_in() ? $logout_url : $login_url); |
|
| 419 | 419 | |
| 420 | 420 | // determine the menu title login or logout |
| 421 | - if ( is_user_logged_in() ) { |
|
| 422 | - $menu_title = __( 'Logout' ,'woothemes-sensei'); |
|
| 421 | + if (is_user_logged_in()) { |
|
| 422 | + $menu_title = __('Logout', 'woothemes-sensei'); |
|
| 423 | 423 | } else { |
| 424 | - $menu_title = __( 'Login' ,'woothemes-sensei'); |
|
| 424 | + $menu_title = __('Login', 'woothemes-sensei'); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * |
| 432 | 432 | * @param $menu_title |
| 433 | 433 | */ |
| 434 | - $item->title = apply_filters( 'sensei_login_logout_menu_title', $menu_title ); |
|
| 434 | + $item->title = apply_filters('sensei_login_logout_menu_title', $menu_title); |
|
| 435 | 435 | |
| 436 | 436 | break; |
| 437 | 437 | |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | break; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); |
|
| 443 | - $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current ); |
|
| 444 | - $item_url = untrailingslashit( $item->url ); |
|
| 445 | - $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) ); |
|
| 442 | + $_root_relative_current = untrailingslashit($_SERVER['REQUEST_URI']); |
|
| 443 | + $current_url = set_url_scheme('http://'.$_SERVER['HTTP_HOST'].$_root_relative_current); |
|
| 444 | + $item_url = untrailingslashit($item->url); |
|
| 445 | + $_indexless_current = untrailingslashit(preg_replace('/'.preg_quote($wp_rewrite->index, '/').'$/', '', $current_url)); |
|
| 446 | 446 | // Highlight current menu item |
| 447 | - if ( $item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { |
|
| 447 | + if ($item_url && in_array($item_url, array($current_url, $_indexless_current, $_root_relative_current))) { |
|
| 448 | 448 | $item->classes[] = 'current-menu-item current_page_item'; |
| 449 | 449 | } |
| 450 | 450 | |
@@ -463,26 +463,26 @@ discard block |
||
| 463 | 463 | * @param object $sorted_menu_items |
| 464 | 464 | * @return object $sorted_menu_items |
| 465 | 465 | */ |
| 466 | - public function sensei_wp_nav_menu_objects( $sorted_menu_items ) { |
|
| 466 | + public function sensei_wp_nav_menu_objects($sorted_menu_items) { |
|
| 467 | 467 | |
| 468 | - foreach( $sorted_menu_items as $k=>$item ) { |
|
| 468 | + foreach ($sorted_menu_items as $k=>$item) { |
|
| 469 | 469 | |
| 470 | 470 | // Remove the My Messages link for logged out users or if Private Messages are disabled |
| 471 | - if( ! get_post_type_archive_link( 'sensei_message' ) |
|
| 472 | - && '#senseimymessages' == $item->url ) { |
|
| 471 | + if ( ! get_post_type_archive_link('sensei_message') |
|
| 472 | + && '#senseimymessages' == $item->url) { |
|
| 473 | 473 | |
| 474 | - if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) { |
|
| 474 | + if ( ! is_user_logged_in() || (isset(Sensei()->settings->settings['messages_disable']) && Sensei()->settings->settings['messages_disable'])) { |
|
| 475 | 475 | |
| 476 | - unset( $sorted_menu_items[$k] ); |
|
| 476 | + unset($sorted_menu_items[$k]); |
|
| 477 | 477 | |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | // Remove the My Profile link for logged out users. |
| 481 | - if( Sensei()->learner_profiles->get_permalink() == $item->url ) { |
|
| 481 | + if (Sensei()->learner_profiles->get_permalink() == $item->url) { |
|
| 482 | 482 | |
| 483 | - if ( !is_user_logged_in() || ! ( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] ) && Sensei()->settings->settings[ 'learner_profile_enable' ] ) ) { |
|
| 483 | + if ( ! is_user_logged_in() || ! (isset(Sensei()->settings->settings['learner_profile_enable']) && Sensei()->settings->settings['learner_profile_enable'])) { |
|
| 484 | 484 | |
| 485 | - unset( $sorted_menu_items[$k] ); |
|
| 485 | + unset($sorted_menu_items[$k]); |
|
| 486 | 486 | |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | function sensei_search_results_classes($classes) { |
| 495 | 495 | global $post; |
| 496 | 496 | // Handle Search Classes for Courses, Lessons, and WC Products |
| 497 | - if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
| 497 | + if (isset($post->post_type) && (('course' == $post->post_type) || ('lesson' == $post->post_type) || ('product' == $post->post_type))) { |
|
| 498 | 498 | $classes[] = 'post'; |
| 499 | 499 | } // End If Statement |
| 500 | 500 | return $classes; |
@@ -522,16 +522,16 @@ discard block |
||
| 522 | 522 | * @param bool|false $return |
| 523 | 523 | * @return string|void |
| 524 | 524 | */ |
| 525 | - function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) { |
|
| 525 | + function sensei_course_image($course_id, $width = '100', $height = '100', $return = false) { |
|
| 526 | 526 | |
| 527 | - if ( ! $return ) { |
|
| 527 | + if ( ! $return) { |
|
| 528 | 528 | |
| 529 | - echo Sensei()->course->course_image( $course_id, $width, $height ); |
|
| 529 | + echo Sensei()->course->course_image($course_id, $width, $height); |
|
| 530 | 530 | return ''; |
| 531 | 531 | |
| 532 | 532 | } // End If Statement |
| 533 | 533 | |
| 534 | - return Sensei()->course->course_image( $course_id, $width, $height ); |
|
| 534 | + return Sensei()->course->course_image($course_id, $width, $height); |
|
| 535 | 535 | |
| 536 | 536 | } // End sensei_course_image() |
| 537 | 537 | |
@@ -546,15 +546,15 @@ discard block |
||
| 546 | 546 | * @param bool|false $widget |
| 547 | 547 | * @return string |
| 548 | 548 | */ |
| 549 | - function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) { |
|
| 549 | + function sensei_lesson_image($lesson_id, $width = '100', $height = '100', $return = false, $widget = false) { |
|
| 550 | 550 | |
| 551 | - if( ! $return ){ |
|
| 551 | + if ( ! $return) { |
|
| 552 | 552 | |
| 553 | - echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
| 553 | + echo Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget); |
|
| 554 | 554 | return ''; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
| 557 | + return Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget); |
|
| 558 | 558 | |
| 559 | 559 | } // End sensei_lesson_image() |
| 560 | 560 | |
@@ -562,20 +562,20 @@ discard block |
||
| 562 | 562 | * @since 1.0.0 |
| 563 | 563 | * @param WP_Query $query |
| 564 | 564 | */ |
| 565 | - function sensei_course_archive_pagination( $query ) { |
|
| 565 | + function sensei_course_archive_pagination($query) { |
|
| 566 | 566 | |
| 567 | - if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) { |
|
| 567 | + if ( ! is_admin() && $query->is_main_query() && isset($_GET['action']) && in_array($_GET['action'], array('newcourses', 'featuredcourses', 'freecourses', 'paidcourses'))) { |
|
| 568 | 568 | |
| 569 | 569 | $amount = 0; |
| 570 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 571 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 570 | + if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { |
|
| 571 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - if( $amount ) { |
|
| 575 | - $query->set( 'posts_per_page', $amount ); |
|
| 574 | + if ($amount) { |
|
| 575 | + $query->set('posts_per_page', $amount); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $query->set( 'orderby', 'menu_order date' ); |
|
| 578 | + $query->set('orderby', 'menu_order date'); |
|
| 579 | 579 | |
| 580 | 580 | } |
| 581 | 581 | } |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | function sensei_course_archive_header( ) { |
| 592 | 592 | |
| 593 | 593 | trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
| 594 | - WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
| 594 | + WooThemes_Sensei_Course::archive_header('', '<header class="archive-header"><h1>', '</h1></header>'); |
|
| 595 | 595 | |
| 596 | 596 | } // sensei_course_archive_header() |
| 597 | 597 | |
@@ -604,15 +604,15 @@ discard block |
||
| 604 | 604 | * @return void |
| 605 | 605 | */ |
| 606 | 606 | public function sensei_lesson_archive_header( ) { |
| 607 | - _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
| 607 | + _deprecated_function('WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header'); |
|
| 608 | 608 | Sensei()->lesson->the_archive_header(); |
| 609 | 609 | } // sensei_course_archive_header() |
| 610 | 610 | |
| 611 | 611 | /** |
| 612 | 612 | * @deprecated since 1.9.0 |
| 613 | 613 | */ |
| 614 | - public function sensei_message_archive_header( ){ |
|
| 615 | - _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
| 614 | + public function sensei_message_archive_header( ) { |
|
| 615 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_header', 'Please use: Sense'); |
|
| 616 | 616 | Sensei_Messages::the_archive_header(); |
| 617 | 617 | } // sensei_message_archive_header() |
| 618 | 618 | |
@@ -622,15 +622,15 @@ discard block |
||
| 622 | 622 | * @param WP_Post $post_item |
| 623 | 623 | * @return void |
| 624 | 624 | */ |
| 625 | - function sensei_course_archive_course_title( $post_item ) { |
|
| 626 | - if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) { |
|
| 627 | - $post_id = absint( $post_item->ID ); |
|
| 625 | + function sensei_course_archive_course_title($post_item) { |
|
| 626 | + if (isset($post_item->ID) && (0 < $post_item->ID)) { |
|
| 627 | + $post_id = absint($post_item->ID); |
|
| 628 | 628 | $post_title = $post_item->post_title; |
| 629 | 629 | } else { |
| 630 | 630 | $post_id = get_the_ID(); |
| 631 | 631 | $post_title = get_the_title(); |
| 632 | 632 | } // End If Statement |
| 633 | - ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 633 | + ?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 634 | 634 | } // End sensei_course_archive_course_title() |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | public function sensei_lesson_archive_lesson_title() { |
| 642 | 642 | $post_id = get_the_ID(); |
| 643 | 643 | $post_title = get_the_title(); |
| 644 | - ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 644 | + ?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 645 | 645 | } // End sensei_lesson_archive_lesson_title() |
| 646 | 646 | |
| 647 | 647 | /** |
@@ -650,40 +650,40 @@ discard block |
||
| 650 | 650 | * @param integer $id course, lesson or quiz id |
| 651 | 651 | * @return void |
| 652 | 652 | */ |
| 653 | - public function sensei_breadcrumb( $id = 0 ) { |
|
| 653 | + public function sensei_breadcrumb($id = 0) { |
|
| 654 | 654 | |
| 655 | 655 | // Only output on lesson, quiz and taxonomy (module) pages |
| 656 | - if( ! ( is_tax( 'module' ) || is_singular( 'lesson' ) || is_singular( 'quiz' ) ) ) return; |
|
| 656 | + if ( ! (is_tax('module') || is_singular('lesson') || is_singular('quiz'))) return; |
|
| 657 | 657 | |
| 658 | - if( empty( $id ) ){ |
|
| 658 | + if (empty($id)) { |
|
| 659 | 659 | |
| 660 | 660 | $id = get_the_ID(); |
| 661 | 661 | |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - $sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' ); |
|
| 665 | - $separator = apply_filters( 'sensei_breadcrumb_separator', '>' ); |
|
| 664 | + $sensei_breadcrumb_prefix = __('Back to: ', 'woothemes-sensei'); |
|
| 665 | + $separator = apply_filters('sensei_breadcrumb_separator', '>'); |
|
| 666 | 666 | |
| 667 | - $html = '<section class="sensei-breadcrumb">' . $sensei_breadcrumb_prefix; |
|
| 667 | + $html = '<section class="sensei-breadcrumb">'.$sensei_breadcrumb_prefix; |
|
| 668 | 668 | // Lesson |
| 669 | - if ( is_singular( 'lesson' ) && 0 < intval( $id ) ) { |
|
| 670 | - $course_id = intval( get_post_meta( $id, '_lesson_course', true ) ); |
|
| 671 | - if( ! $course_id ) { |
|
| 669 | + if (is_singular('lesson') && 0 < intval($id)) { |
|
| 670 | + $course_id = intval(get_post_meta($id, '_lesson_course', true)); |
|
| 671 | + if ( ! $course_id) { |
|
| 672 | 672 | return; |
| 673 | 673 | } |
| 674 | - $html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>'; |
|
| 674 | + $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>'; |
|
| 675 | 675 | } // End If Statement |
| 676 | 676 | // Quiz |
| 677 | - if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) { |
|
| 678 | - $lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) ); |
|
| 679 | - if( ! $lesson_id ) { |
|
| 677 | + if (is_singular('quiz') && 0 < intval($id)) { |
|
| 678 | + $lesson_id = intval(get_post_meta($id, '_quiz_lesson', true)); |
|
| 679 | + if ( ! $lesson_id) { |
|
| 680 | 680 | return; |
| 681 | 681 | } |
| 682 | - $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>'; |
|
| 682 | + $html .= '<a href="'.esc_url(get_permalink($lesson_id)).'" title="'.__('Back to the lesson', 'woothemes-sensei').'">'.get_the_title($lesson_id).'</a>'; |
|
| 683 | 683 | } // End If Statement |
| 684 | 684 | |
| 685 | 685 | // Allow other plugins to filter html |
| 686 | - $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
| 686 | + $html = apply_filters('sensei_breadcrumb_output', $html, $separator); |
|
| 687 | 687 | $html .= '</section>'; |
| 688 | 688 | |
| 689 | 689 | echo $html; |
@@ -695,25 +695,25 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | public function sensei_lesson_course_signup_link( ) { |
| 697 | 697 | |
| 698 | - _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
| 698 | + _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link'); |
|
| 699 | 699 | WooThemes_Sensei_Lesson::course_signup_link(); |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - public function lesson_tags_display( $lesson_id = 0 ) { |
|
| 703 | - if( $lesson_id ) { |
|
| 704 | - $tags = wp_get_post_terms( $lesson_id, 'lesson-tag' ); |
|
| 705 | - if( $tags && count( $tags ) > 0 ) { |
|
| 702 | + public function lesson_tags_display($lesson_id = 0) { |
|
| 703 | + if ($lesson_id) { |
|
| 704 | + $tags = wp_get_post_terms($lesson_id, 'lesson-tag'); |
|
| 705 | + if ($tags && count($tags) > 0) { |
|
| 706 | 706 | $tag_list = ''; |
| 707 | - foreach( $tags as $tag ) { |
|
| 708 | - $tag_link = get_term_link( $tag, 'lesson-tag' ); |
|
| 709 | - if( ! is_wp_error( $tag_link ) ) { |
|
| 710 | - if( $tag_list ) { $tag_list .= ', '; } |
|
| 711 | - $tag_list .= '<a href="' . $tag_link . '">' . $tag->name . '</a>'; |
|
| 707 | + foreach ($tags as $tag) { |
|
| 708 | + $tag_link = get_term_link($tag, 'lesson-tag'); |
|
| 709 | + if ( ! is_wp_error($tag_link)) { |
|
| 710 | + if ($tag_list) { $tag_list .= ', '; } |
|
| 711 | + $tag_list .= '<a href="'.$tag_link.'">'.$tag->name.'</a>'; |
|
| 712 | 712 | } |
| 713 | 713 | } |
| 714 | - if( $tag_list ) { |
|
| 714 | + if ($tag_list) { |
|
| 715 | 715 | ?><section class="lesson-tags"> |
| 716 | - <?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?> |
|
| 716 | + <?php printf(__('Lesson tags: %1$s', 'woothemes-sensei'), $tag_list); ?> |
|
| 717 | 717 | </section><?php |
| 718 | 718 | } |
| 719 | 719 | } |
@@ -723,51 +723,51 @@ discard block |
||
| 723 | 723 | /** |
| 724 | 724 | * @param WP_Query $query |
| 725 | 725 | */ |
| 726 | - public function lesson_tag_archive_filter( $query ) { |
|
| 727 | - if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
| 726 | + public function lesson_tag_archive_filter($query) { |
|
| 727 | + if (is_tax('lesson-tag') && $query->is_main_query()) { |
|
| 728 | 728 | // Limit to lessons only |
| 729 | - $query->set( 'post_type', 'lesson' ); |
|
| 729 | + $query->set('post_type', 'lesson'); |
|
| 730 | 730 | |
| 731 | 731 | // Set order of lessons |
| 732 | - $query->set( 'orderby', 'menu_order' ); |
|
| 733 | - $query->set( 'order', 'ASC' ); |
|
| 732 | + $query->set('orderby', 'menu_order'); |
|
| 733 | + $query->set('order', 'ASC'); |
|
| 734 | 734 | |
| 735 | 735 | } |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - public function lesson_tag_archive_header( $title ) { |
|
| 739 | - if( is_tax( 'lesson-tag' ) ) { |
|
| 740 | - $title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) ); |
|
| 738 | + public function lesson_tag_archive_header($title) { |
|
| 739 | + if (is_tax('lesson-tag')) { |
|
| 740 | + $title = sprintf(__('Lesson tag: %1$s', 'woothemes-sensei'), apply_filters('sensei_lesson_tag_archive_title', get_queried_object()->name)); |
|
| 741 | 741 | } |
| 742 | 742 | return $title; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | public function lesson_tag_archive_description() { |
| 746 | - if( is_tax( 'lesson-tag' ) ) { |
|
| 746 | + if (is_tax('lesson-tag')) { |
|
| 747 | 747 | $tag = get_queried_object(); |
| 748 | - echo '<p class="archive-description lesson-description">' . apply_filters( 'sensei_lesson_tag_archive_description', nl2br( $tag->description ), $tag->term_id ) . '</p>'; |
|
| 748 | + echo '<p class="archive-description lesson-description">'.apply_filters('sensei_lesson_tag_archive_description', nl2br($tag->description), $tag->term_id).'</p>'; |
|
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | public function sensei_complete_lesson() { |
| 753 | - global $post, $current_user; |
|
| 753 | + global $post, $current_user; |
|
| 754 | 754 | // Handle Quiz Completion |
| 755 | - if ( isset( $_POST['quiz_action'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_lesson_noonce' ], 'woothemes_sensei_complete_lesson_noonce' ) ) { |
|
| 755 | + if (isset($_POST['quiz_action']) && wp_verify_nonce($_POST['woothemes_sensei_complete_lesson_noonce'], 'woothemes_sensei_complete_lesson_noonce')) { |
|
| 756 | 756 | |
| 757 | - $sanitized_submit = esc_html( $_POST['quiz_action'] ); |
|
| 757 | + $sanitized_submit = esc_html($_POST['quiz_action']); |
|
| 758 | 758 | |
| 759 | 759 | switch ($sanitized_submit) { |
| 760 | 760 | case 'lesson-complete': |
| 761 | 761 | |
| 762 | - Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true ); |
|
| 762 | + Sensei_Utils::sensei_start_lesson($post->ID, $current_user->ID, $complete = true); |
|
| 763 | 763 | |
| 764 | 764 | break; |
| 765 | 765 | |
| 766 | 766 | case 'lesson-reset': |
| 767 | 767 | |
| 768 | - Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID ); |
|
| 768 | + Sensei_Utils::sensei_remove_user_from_lesson($post->ID, $current_user->ID); |
|
| 769 | 769 | |
| 770 | - $this->messages = '<div class="sensei-message note">' . __( 'Lesson Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 770 | + $this->messages = '<div class="sensei-message note">'.__('Lesson Reset Successfully.', 'woothemes-sensei').'</div>'; |
|
| 771 | 771 | break; |
| 772 | 772 | |
| 773 | 773 | default: |
@@ -781,14 +781,14 @@ discard block |
||
| 781 | 781 | } // End sensei_complete_lesson() |
| 782 | 782 | |
| 783 | 783 | public function sensei_complete_course() { |
| 784 | - global $post, $current_user, $wp_query; |
|
| 785 | - if ( isset( $_POST['course_complete'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_course_noonce' ], 'woothemes_sensei_complete_course_noonce' ) ) { |
|
| 784 | + global $post, $current_user, $wp_query; |
|
| 785 | + if (isset($_POST['course_complete']) && wp_verify_nonce($_POST['woothemes_sensei_complete_course_noonce'], 'woothemes_sensei_complete_course_noonce')) { |
|
| 786 | 786 | |
| 787 | - $sanitized_submit = esc_html( $_POST['course_complete'] ); |
|
| 788 | - $sanitized_course_id = absint( esc_html( $_POST['course_complete_id'] ) ); |
|
| 787 | + $sanitized_submit = esc_html($_POST['course_complete']); |
|
| 788 | + $sanitized_course_id = absint(esc_html($_POST['course_complete_id'])); |
|
| 789 | 789 | // Handle submit data |
| 790 | 790 | switch ($sanitized_submit) { |
| 791 | - case __( 'Mark as Complete', 'woothemes-sensei' ): |
|
| 791 | + case __('Mark as Complete', 'woothemes-sensei'): |
|
| 792 | 792 | |
| 793 | 793 | // Add user to course |
| 794 | 794 | $course_metadata = array( |
@@ -796,15 +796,15 @@ discard block |
||
| 796 | 796 | 'percent' => 0, // No completed lessons yet |
| 797 | 797 | 'complete' => 0, |
| 798 | 798 | ); |
| 799 | - $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata ); |
|
| 799 | + $activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata); |
|
| 800 | 800 | |
| 801 | - if ( $activity_logged ) { |
|
| 801 | + if ($activity_logged) { |
|
| 802 | 802 | // Get all course lessons |
| 803 | - $course_lesson_ids = Sensei()->course->course_lessons( $sanitized_course_id, 'any', 'ids' ); |
|
| 803 | + $course_lesson_ids = Sensei()->course->course_lessons($sanitized_course_id, 'any', 'ids'); |
|
| 804 | 804 | // Mark all quiz user meta lessons as complete |
| 805 | - foreach ( $course_lesson_ids as $lesson_item_id ){ |
|
| 805 | + foreach ($course_lesson_ids as $lesson_item_id) { |
|
| 806 | 806 | // Mark lesson as complete |
| 807 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_item_id, $current_user->ID, $complete = true ); |
|
| 807 | + $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_item_id, $current_user->ID, $complete = true); |
|
| 808 | 808 | } // End For Loop |
| 809 | 809 | |
| 810 | 810 | // Update with final stats |
@@ -812,22 +812,22 @@ discard block |
||
| 812 | 812 | 'percent' => 100, |
| 813 | 813 | 'complete' => count($course_lesson_ids), |
| 814 | 814 | ); |
| 815 | - $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'complete', $course_metadata ); |
|
| 815 | + $activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'complete', $course_metadata); |
|
| 816 | 816 | |
| 817 | - do_action( 'sensei_user_course_end', $current_user->ID, $sanitized_course_id ); |
|
| 817 | + do_action('sensei_user_course_end', $current_user->ID, $sanitized_course_id); |
|
| 818 | 818 | |
| 819 | 819 | // Success message |
| 820 | - $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s marked as complete.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>'; |
|
| 820 | + $this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s marked as complete.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>'; |
|
| 821 | 821 | } // End If Statement |
| 822 | 822 | |
| 823 | 823 | break; |
| 824 | 824 | |
| 825 | - case __( 'Delete Course', 'woothemes-sensei' ): |
|
| 825 | + case __('Delete Course', 'woothemes-sensei'): |
|
| 826 | 826 | |
| 827 | - Sensei_Utils::sensei_remove_user_from_course( $sanitized_course_id, $current_user->ID ); |
|
| 827 | + Sensei_Utils::sensei_remove_user_from_course($sanitized_course_id, $current_user->ID); |
|
| 828 | 828 | |
| 829 | 829 | // Success message |
| 830 | - $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s deleted.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>'; |
|
| 830 | + $this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s deleted.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>'; |
|
| 831 | 831 | break; |
| 832 | 832 | |
| 833 | 833 | default: |
@@ -843,25 +843,25 @@ discard block |
||
| 843 | 843 | * @param int $lesson_id |
| 844 | 844 | * @return array |
| 845 | 845 | */ |
| 846 | - public function sensei_get_user_quiz_answers( $lesson_id = 0 ) { |
|
| 846 | + public function sensei_get_user_quiz_answers($lesson_id = 0) { |
|
| 847 | 847 | global $current_user; |
| 848 | 848 | |
| 849 | 849 | $user_answers = array(); |
| 850 | 850 | |
| 851 | - if ( 0 < intval( $lesson_id ) ) { |
|
| 852 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $lesson_id ); |
|
| 853 | - foreach( $lesson_quiz_questions as $question ) { |
|
| 854 | - $answer = maybe_unserialize( base64_decode( Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content' ) ) ) ); |
|
| 855 | - $user_answers[ $question->ID ] = $answer; |
|
| 851 | + if (0 < intval($lesson_id)) { |
|
| 852 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($lesson_id); |
|
| 853 | + foreach ($lesson_quiz_questions as $question) { |
|
| 854 | + $answer = maybe_unserialize(base64_decode(Sensei_Utils::sensei_get_activity_value(array('post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content')))); |
|
| 855 | + $user_answers[$question->ID] = $answer; |
|
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | return $user_answers; |
| 860 | 860 | } // End sensei_get_user_quiz_answers() |
| 861 | 861 | |
| 862 | - public function sensei_has_user_completed_lesson( $post_id = 0, $user_id = 0 ) { |
|
| 863 | - _deprecated_function( __FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()" ); |
|
| 864 | - return Sensei_Utils::user_completed_lesson( $post_id, $user_id ); |
|
| 862 | + public function sensei_has_user_completed_lesson($post_id = 0, $user_id = 0) { |
|
| 863 | + _deprecated_function(__FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()"); |
|
| 864 | + return Sensei_Utils::user_completed_lesson($post_id, $user_id); |
|
| 865 | 865 | } // End sensei_has_user_completed_lesson() |
| 866 | 866 | |
| 867 | 867 | /** |
@@ -871,14 +871,14 @@ discard block |
||
| 871 | 871 | Sensei()->notices->print_notices(); |
| 872 | 872 | } // End sensei_frontend_messages() |
| 873 | 873 | |
| 874 | - public function sensei_lesson_video( $post_id = 0 ) { |
|
| 875 | - if ( 0 < intval( $post_id ) ) { |
|
| 876 | - $lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true ); |
|
| 877 | - if ( 'http' == substr( $lesson_video_embed, 0, 4) ) { |
|
| 874 | + public function sensei_lesson_video($post_id = 0) { |
|
| 875 | + if (0 < intval($post_id)) { |
|
| 876 | + $lesson_video_embed = get_post_meta($post_id, '_lesson_video_embed', true); |
|
| 877 | + if ('http' == substr($lesson_video_embed, 0, 4)) { |
|
| 878 | 878 | // V2 - make width and height a setting for video embed |
| 879 | - $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
| 879 | + $lesson_video_embed = wp_oembed_get(esc_url($lesson_video_embed)/*, array( 'width' => 100 , 'height' => 100)*/); |
|
| 880 | 880 | } // End If Statement |
| 881 | - if ( '' != $lesson_video_embed ) { |
|
| 881 | + if ('' != $lesson_video_embed) { |
|
| 882 | 882 | ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
| 883 | 883 | } // End If Statement |
| 884 | 884 | } // End If Statement |
@@ -890,19 +890,19 @@ discard block |
||
| 890 | 890 | $quiz_id = 0; |
| 891 | 891 | |
| 892 | 892 | // Lesson quizzes |
| 893 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID ); |
|
| 893 | + $quiz_id = Sensei()->lesson->lesson_quizzes($post->ID); |
|
| 894 | 894 | $pass_required = true; |
| 895 | - if( $quiz_id ) { |
|
| 895 | + if ($quiz_id) { |
|
| 896 | 896 | // Get quiz pass setting |
| 897 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 897 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 898 | 898 | } |
| 899 | - if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) { |
|
| 899 | + if ( ! $quiz_id || ($quiz_id && ! $pass_required)) { |
|
| 900 | 900 | ?> |
| 901 | - <form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
|
| 901 | + <form class="lesson_button_form" method="POST" action="<?php echo esc_url(get_permalink()); ?>"> |
|
| 902 | 902 | <input type="hidden" |
| 903 | 903 | name="woothemes_sensei_complete_lesson_noonce" |
| 904 | 904 | id="woothemes_sensei_complete_lesson_noonce" |
| 905 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" |
|
| 905 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>" |
|
| 906 | 906 | /> |
| 907 | 907 | |
| 908 | 908 | <input type="hidden" name="quiz_action" value="lesson-complete" /> |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | <input type="submit" |
| 911 | 911 | name="quiz_complete" |
| 912 | 912 | class="quiz-submit complete" |
| 913 | - value="<?php _e( 'Complete Lesson', 'woothemes-sensei' ); ?>"/> |
|
| 913 | + value="<?php _e('Complete Lesson', 'woothemes-sensei'); ?>"/> |
|
| 914 | 914 | |
| 915 | 915 | </form> |
| 916 | 916 | <?php |
@@ -923,25 +923,25 @@ discard block |
||
| 923 | 923 | $quiz_id = 0; |
| 924 | 924 | |
| 925 | 925 | // Lesson quizzes |
| 926 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID ); |
|
| 926 | + $quiz_id = Sensei()->lesson->lesson_quizzes($post->ID); |
|
| 927 | 927 | $reset_allowed = true; |
| 928 | - if( $quiz_id ) { |
|
| 928 | + if ($quiz_id) { |
|
| 929 | 929 | // Get quiz pass setting |
| 930 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 930 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 931 | 931 | } |
| 932 | - if ( ! $quiz_id || !empty($reset_allowed) ) { |
|
| 932 | + if ( ! $quiz_id || ! empty($reset_allowed)) { |
|
| 933 | 933 | ?> |
| 934 | - <form method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
|
| 934 | + <form method="POST" action="<?php echo esc_url(get_permalink()); ?>"> |
|
| 935 | 935 | |
| 936 | 936 | <input |
| 937 | 937 | type="hidden" |
| 938 | - name="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>" |
|
| 939 | - id="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>" |
|
| 940 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" /> |
|
| 938 | + name="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>" |
|
| 939 | + id="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>" |
|
| 940 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>" /> |
|
| 941 | 941 | |
| 942 | 942 | <input type="hidden" name="quiz_action" value="lesson-reset" /> |
| 943 | 943 | |
| 944 | - <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e( 'Reset Lesson', 'woothemes-sensei' ); ?>"/> |
|
| 944 | + <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e('Reset Lesson', 'woothemes-sensei'); ?>"/> |
|
| 945 | 945 | |
| 946 | 946 | </form> |
| 947 | 947 | <?php |
@@ -964,23 +964,23 @@ discard block |
||
| 964 | 964 | $post_title = get_the_title(); |
| 965 | 965 | $author_display_name = get_the_author(); |
| 966 | 966 | $author_id = get_the_author_meta('ID'); |
| 967 | - $category_output = get_the_term_list( $post_id, 'course-category', '', ', ', '' ); |
|
| 968 | - $free_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $post_id ) ); |
|
| 967 | + $category_output = get_the_term_list($post_id, 'course-category', '', ', ', ''); |
|
| 968 | + $free_lesson_count = intval(Sensei()->course->course_lesson_preview_count($post_id)); |
|
| 969 | 969 | ?><section class="entry"> |
| 970 | 970 | <p class="sensei-course-meta"> |
| 971 | - <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> |
|
| 972 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span> |
|
| 971 | + <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> |
|
| 972 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span> |
|
| 973 | 973 | <?php } // End If Statement ?> |
| 974 | - <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?></span> |
|
| 975 | - <?php if ( '' != $category_output ) { ?> |
|
| 976 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
| 974 | + <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).' '.__('Lessons', 'woothemes-sensei'); ?></span> |
|
| 975 | + <?php if ('' != $category_output) { ?> |
|
| 976 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
| 977 | 977 | <?php } // End If Statement ?> |
| 978 | - <?php sensei_simple_course_price( $post_id ); ?> |
|
| 978 | + <?php sensei_simple_course_price($post_id); ?> |
|
| 979 | 979 | </p> |
| 980 | 980 | <p class="course-excerpt"><?php the_excerpt(); ?></p> |
| 981 | - <?php if ( 0 < $free_lesson_count ) { |
|
| 982 | - $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
| 983 | - <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p> |
|
| 981 | + <?php if (0 < $free_lesson_count) { |
|
| 982 | + $free_lessons = sprintf(__('You can access %d of this course\'s lessons for free', 'woothemes-sensei'), $free_lesson_count); ?> |
|
| 983 | + <p class="sensei-free-lessons"><a href="<?php echo get_permalink($post_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?></a> - <?php echo $free_lessons; ?></p> |
|
| 984 | 984 | <?php } ?> |
| 985 | 985 | </section><?php |
| 986 | 986 | } // End sensei_course_archive_meta() |
@@ -1003,33 +1003,33 @@ discard block |
||
| 1003 | 1003 | * @deprecated since 1.9.0 |
| 1004 | 1004 | */ |
| 1005 | 1005 | public function sensei_message_archive_main_content() { |
| 1006 | - _deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' ); |
|
| 1006 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed'); |
|
| 1007 | 1007 | } // End sensei_lesson_archive_main_content() |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
| 1010 | 1010 | * @deprecated since 1.9.0 |
| 1011 | 1011 | */ |
| 1012 | 1012 | public function sensei_no_permissions_main_content() { |
| 1013 | - _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
| 1013 | + _deprecated_function('Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed'); |
|
| 1014 | 1014 | } // End sensei_no_permissions_main_content() |
| 1015 | 1015 | |
| 1016 | 1016 | public function sensei_course_category_main_content() { |
| 1017 | 1017 | global $post; |
| 1018 | - if ( have_posts() ) { ?> |
|
| 1018 | + if (have_posts()) { ?> |
|
| 1019 | 1019 | |
| 1020 | 1020 | <section id="main-course" class="course-container"> |
| 1021 | 1021 | |
| 1022 | - <?php do_action( 'sensei_course_archive_header' ); ?> |
|
| 1022 | + <?php do_action('sensei_course_archive_header'); ?> |
|
| 1023 | 1023 | |
| 1024 | - <?php while ( have_posts() ) { the_post(); ?> |
|
| 1024 | + <?php while (have_posts()) { the_post(); ?> |
|
| 1025 | 1025 | |
| 1026 | - <article class="<?php echo join( ' ', get_post_class( array( 'course', 'post' ), get_the_ID() ) ); ?>"> |
|
| 1026 | + <article class="<?php echo join(' ', get_post_class(array('course', 'post'), get_the_ID())); ?>"> |
|
| 1027 | 1027 | |
| 1028 | - <?php sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', get_the_ID() ); ?> |
|
| 1028 | + <?php sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_single_course_content_inside_before', get_the_ID()); ?> |
|
| 1029 | 1029 | |
| 1030 | - <?php sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before', $post ); ?> |
|
| 1030 | + <?php sensei_do_deprecated_action('sensei_course_archive_course_title', '1.9.0', 'sensei_course_content_inside_before', $post); ?> |
|
| 1031 | 1031 | |
| 1032 | - <?php do_action( 'sensei_course_archive_meta' ); ?> |
|
| 1032 | + <?php do_action('sensei_course_archive_meta'); ?> |
|
| 1033 | 1033 | |
| 1034 | 1034 | </article> |
| 1035 | 1035 | |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | |
| 1042 | 1042 | <p> |
| 1043 | 1043 | |
| 1044 | - <?php _e( 'No courses found that match your selection.', 'woothemes-sensei' ); ?> |
|
| 1044 | + <?php _e('No courses found that match your selection.', 'woothemes-sensei'); ?> |
|
| 1045 | 1045 | |
| 1046 | 1046 | </p> |
| 1047 | 1047 | |
@@ -1058,12 +1058,12 @@ discard block |
||
| 1058 | 1058 | <div class="col-1"> |
| 1059 | 1059 | <?php |
| 1060 | 1060 | // output the actual form markup |
| 1061 | - Sensei_Templates::get_template( 'user/login-form.php'); |
|
| 1061 | + Sensei_Templates::get_template('user/login-form.php'); |
|
| 1062 | 1062 | ?> |
| 1063 | 1063 | </div> |
| 1064 | 1064 | |
| 1065 | 1065 | <?php |
| 1066 | - if ( get_option('users_can_register') ) { |
|
| 1066 | + if (get_option('users_can_register')) { |
|
| 1067 | 1067 | |
| 1068 | 1068 | // get current url |
| 1069 | 1069 | $action_url = get_permalink(); |
@@ -1071,38 +1071,38 @@ discard block |
||
| 1071 | 1071 | ?> |
| 1072 | 1072 | |
| 1073 | 1073 | <div class="col-2"> |
| 1074 | - <h2><?php _e( 'Register', 'woothemes-sensei' ); ?></h2> |
|
| 1074 | + <h2><?php _e('Register', 'woothemes-sensei'); ?></h2> |
|
| 1075 | 1075 | |
| 1076 | - <form method="post" class="register" action="<?php echo esc_url( $action_url ); ?>" > |
|
| 1076 | + <form method="post" class="register" action="<?php echo esc_url($action_url); ?>" > |
|
| 1077 | 1077 | |
| 1078 | - <?php do_action( 'sensei_register_form_start' ); ?> |
|
| 1078 | + <?php do_action('sensei_register_form_start'); ?> |
|
| 1079 | 1079 | |
| 1080 | 1080 | <p class="form-row form-row-wide"> |
| 1081 | - <label for="sensei_reg_username"><?php _e( 'Username', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1082 | - <input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty( $_POST['sensei_reg_username'] ) ) esc_attr_e( $_POST['sensei_reg_username'] ); ?>" /> |
|
| 1081 | + <label for="sensei_reg_username"><?php _e('Username', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1082 | + <input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty($_POST['sensei_reg_username'])) esc_attr_e($_POST['sensei_reg_username']); ?>" /> |
|
| 1083 | 1083 | </p> |
| 1084 | 1084 | |
| 1085 | 1085 | <p class="form-row form-row-wide"> |
| 1086 | - <label for="sensei_reg_email"><?php _e( 'Email address', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1087 | - <input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty( $_POST['sensei_reg_email'] ) ) esc_attr_e( $_POST['sensei_reg_email'] ); ?>" /> |
|
| 1086 | + <label for="sensei_reg_email"><?php _e('Email address', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1087 | + <input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty($_POST['sensei_reg_email'])) esc_attr_e($_POST['sensei_reg_email']); ?>" /> |
|
| 1088 | 1088 | </p> |
| 1089 | 1089 | |
| 1090 | 1090 | <p class="form-row form-row-wide"> |
| 1091 | - <label for="sensei_reg_password"><?php _e( 'Password', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1092 | - <input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty( $_POST['sensei_reg_password'] ) ) esc_attr_e( $_POST['sensei_reg_password'] ); ?>" /> |
|
| 1091 | + <label for="sensei_reg_password"><?php _e('Password', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1092 | + <input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty($_POST['sensei_reg_password'])) esc_attr_e($_POST['sensei_reg_password']); ?>" /> |
|
| 1093 | 1093 | </p> |
| 1094 | 1094 | |
| 1095 | 1095 | <!-- Spam Trap --> |
| 1096 | - <div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woothemes-sensei' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> |
|
| 1096 | + <div style="left:-999em; position:absolute;"><label for="trap"><?php _e('Anti-spam', 'woothemes-sensei'); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> |
|
| 1097 | 1097 | |
| 1098 | - <?php do_action( 'sensei_register_form_fields' ); ?> |
|
| 1099 | - <?php do_action( 'register_form' ); ?> |
|
| 1098 | + <?php do_action('sensei_register_form_fields'); ?> |
|
| 1099 | + <?php do_action('register_form'); ?> |
|
| 1100 | 1100 | |
| 1101 | 1101 | <p class="form-row"> |
| 1102 | - <input type="submit" class="button" name="register" value="<?php _e( 'Register', 'woothemes-sensei' ); ?>" /> |
|
| 1102 | + <input type="submit" class="button" name="register" value="<?php _e('Register', 'woothemes-sensei'); ?>" /> |
|
| 1103 | 1103 | </p> |
| 1104 | 1104 | |
| 1105 | - <?php do_action( 'sensei_register_form_end' ); ?> |
|
| 1105 | + <?php do_action('sensei_register_form_end'); ?> |
|
| 1106 | 1106 | |
| 1107 | 1107 | </form> |
| 1108 | 1108 | </div> |
@@ -1115,17 +1115,17 @@ discard block |
||
| 1115 | 1115 | <?php |
| 1116 | 1116 | } // End sensei_login_form() |
| 1117 | 1117 | |
| 1118 | - public function sensei_lesson_meta( $post_id = 0 ) { |
|
| 1118 | + public function sensei_lesson_meta($post_id = 0) { |
|
| 1119 | 1119 | global $post; |
| 1120 | - if ( 0 < intval( $post_id ) ) { |
|
| 1121 | - $lesson_course_id = absint( get_post_meta( $post_id, '_lesson_course', true ) ); |
|
| 1120 | + if (0 < intval($post_id)) { |
|
| 1121 | + $lesson_course_id = absint(get_post_meta($post_id, '_lesson_course', true)); |
|
| 1122 | 1122 | ?><section class="entry"> |
| 1123 | 1123 | <p class="sensei-course-meta"> |
| 1124 | - <?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?> |
|
| 1125 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span> |
|
| 1124 | + <?php if (isset(Sensei()->settings->settings['lesson_author']) && (Sensei()->settings->settings['lesson_author'])) { ?> |
|
| 1125 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span> |
|
| 1126 | 1126 | <?php } ?> |
| 1127 | - <?php if ( 0 < intval( $lesson_course_id ) ) { ?> |
|
| 1128 | - <span class="lesson-course"><?php echo ' ' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . __( 'View course', 'woothemes-sensei' ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span> |
|
| 1127 | + <?php if (0 < intval($lesson_course_id)) { ?> |
|
| 1128 | + <span class="lesson-course"><?php echo ' '.sprintf(__('Part of: %s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($lesson_course_id)).'" title="'.__('View course', 'woothemes-sensei').'"><em>'.get_the_title($lesson_course_id).'</em></a>'); ?></span> |
|
| 1129 | 1129 | <?php } ?> |
| 1130 | 1130 | </p> |
| 1131 | 1131 | <p class="lesson-excerpt"><?php the_excerpt( ); ?></p> |
@@ -1133,36 +1133,36 @@ discard block |
||
| 1133 | 1133 | } // End If Statement |
| 1134 | 1134 | } // sensei_lesson_meta() |
| 1135 | 1135 | |
| 1136 | - public function sensei_lesson_preview_title_text( $course_id ) { |
|
| 1136 | + public function sensei_lesson_preview_title_text($course_id) { |
|
| 1137 | 1137 | |
| 1138 | - $preview_text = __( ' (Preview)', 'woothemes-sensei' ); |
|
| 1138 | + $preview_text = __(' (Preview)', 'woothemes-sensei'); |
|
| 1139 | 1139 | |
| 1140 | 1140 | //if this is a paid course |
| 1141 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1142 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 1143 | - if ( 0 < $wc_post_id ) { |
|
| 1144 | - $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
| 1141 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1142 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 1143 | + if (0 < $wc_post_id) { |
|
| 1144 | + $preview_text = __(' (Free Preview)', 'woothemes-sensei'); |
|
| 1145 | 1145 | } // End If Statement |
| 1146 | 1146 | } |
| 1147 | 1147 | return $preview_text; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - public function sensei_lesson_preview_title( $title = '', $id = 0 ) { |
|
| 1150 | + public function sensei_lesson_preview_title($title = '', $id = 0) { |
|
| 1151 | 1151 | global $post, $current_user; |
| 1152 | 1152 | |
| 1153 | 1153 | // Limit to lessons and check if lesson ID matches filtered post ID |
| 1154 | 1154 | // @see https://github.com/woothemes/sensei/issues/574 |
| 1155 | - if( isset( $post->ID ) && $id == $post->ID && 'lesson' == get_post_type( $post ) ) { |
|
| 1155 | + if (isset($post->ID) && $id == $post->ID && 'lesson' == get_post_type($post)) { |
|
| 1156 | 1156 | |
| 1157 | 1157 | // Limit to main query only |
| 1158 | - if( is_main_query() ) { |
|
| 1158 | + if (is_main_query()) { |
|
| 1159 | 1159 | |
| 1160 | 1160 | // Get the course ID |
| 1161 | - $course_id = get_post_meta( $post->ID, '_lesson_course', true ); |
|
| 1161 | + $course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
| 1162 | 1162 | |
| 1163 | 1163 | // Check if the user is taking the course |
| 1164 | - if( is_singular( 'lesson' ) && Sensei_Utils::is_preview_lesson( $post->ID ) && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID ) && $post->ID == $id ) { |
|
| 1165 | - $title .= ' ' . $this->sensei_lesson_preview_title_text( $course_id ); |
|
| 1164 | + if (is_singular('lesson') && Sensei_Utils::is_preview_lesson($post->ID) && ! Sensei_Utils::user_started_course($course_id, $current_user->ID) && $post->ID == $id) { |
|
| 1165 | + $title .= ' '.$this->sensei_lesson_preview_title_text($course_id); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | } |
| 1168 | 1168 | } |
@@ -1173,23 +1173,23 @@ discard block |
||
| 1173 | 1173 | global $post, $current_user; |
| 1174 | 1174 | |
| 1175 | 1175 | // Check if the user is taking the course |
| 1176 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 1176 | + $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID); |
|
| 1177 | 1177 | // Handle user starting the course |
| 1178 | - if ( isset( $_POST['course_start'] ) |
|
| 1179 | - && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
| 1180 | - && !$is_user_taking_course ) { |
|
| 1178 | + if (isset($_POST['course_start']) |
|
| 1179 | + && wp_verify_nonce($_POST['woothemes_sensei_start_course_noonce'], 'woothemes_sensei_start_course_noonce') |
|
| 1180 | + && ! $is_user_taking_course) { |
|
| 1181 | 1181 | |
| 1182 | 1182 | // Start the course |
| 1183 | - $activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID ); |
|
| 1183 | + $activity_logged = Sensei_Utils::user_start_course($current_user->ID, $post->ID); |
|
| 1184 | 1184 | $this->data = new stdClass(); |
| 1185 | 1185 | $this->data->is_user_taking_course = false; |
| 1186 | - if ( $activity_logged ) { |
|
| 1186 | + if ($activity_logged) { |
|
| 1187 | 1187 | $this->data->is_user_taking_course = true; |
| 1188 | 1188 | |
| 1189 | 1189 | // Refresh page to avoid re-posting |
| 1190 | 1190 | ?> |
| 1191 | 1191 | |
| 1192 | - <script type="text/javascript"> window.location = '<?php echo get_permalink( $post->ID ); ?>'; </script> |
|
| 1192 | + <script type="text/javascript"> window.location = '<?php echo get_permalink($post->ID); ?>'; </script> |
|
| 1193 | 1193 | |
| 1194 | 1194 | <?php |
| 1195 | 1195 | } // End If Statement |
@@ -1200,15 +1200,15 @@ discard block |
||
| 1200 | 1200 | * @deprecated since 1.9.0 |
| 1201 | 1201 | */ |
| 1202 | 1202 | public function sensei_course_meta() { |
| 1203 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
| 1204 | - Sensei()->course->the_course_meta( get_post() ); |
|
| 1203 | + _deprecated_function('Sensei_Frontend::sensei_course_meta', '1.9.0', 'Sensei_Course::the_course_meta()'); |
|
| 1204 | + Sensei()->course->the_course_meta(get_post()); |
|
| 1205 | 1205 | } // End sensei_course_meta() |
| 1206 | 1206 | |
| 1207 | 1207 | /** |
| 1208 | 1208 | * @deprecated since 1.9.0 |
| 1209 | 1209 | */ |
| 1210 | 1210 | public function sensei_course_meta_video() { |
| 1211 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
| 1211 | + _deprecated_function('Sensei_Frontend::sensei_course_meta_video', '1.9.0', 'Sensei_Course::the_course_video()'); |
|
| 1212 | 1212 | Sensei_Course::the_course_video(); |
| 1213 | 1213 | } // End sensei_course_meta_video() |
| 1214 | 1214 | |
@@ -1223,12 +1223,12 @@ discard block |
||
| 1223 | 1223 | public function sensei_woocommerce_in_cart_message() { |
| 1224 | 1224 | global $post, $woocommerce; |
| 1225 | 1225 | |
| 1226 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 1227 | - $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
| 1228 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 1226 | + $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true)); |
|
| 1227 | + $user_course_status_id = Sensei_Utils::user_started_course($post->ID, get_current_user_id()); |
|
| 1228 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
| 1229 | 1229 | |
| 1230 | - if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) { |
|
| 1231 | - echo '<div class="sensei-message info">' . sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei') . '</div>', '<a class="cart-complete" href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __('complete the purchase', 'woothemes-sensei') . '">' . __('complete the purchase', 'woothemes-sensei') . '</a>' ); |
|
| 1230 | + if (Sensei_WC::is_product_in_cart($wc_post_id)) { |
|
| 1231 | + echo '<div class="sensei-message info">'.sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei').'</div>', '<a class="cart-complete" href="'.$woocommerce->cart->get_checkout_url().'" title="'.__('complete the purchase', 'woothemes-sensei').'">'.__('complete the purchase', 'woothemes-sensei').'</a>'); |
|
| 1232 | 1232 | } // End If Statement |
| 1233 | 1233 | |
| 1234 | 1234 | } // End If Statement |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | } // End sensei_woocommerce_in_cart_message() |
| 1237 | 1237 | |
| 1238 | 1238 | // Deprecated |
| 1239 | - public function sensei_lesson_comment_count( $count ) { |
|
| 1239 | + public function sensei_lesson_comment_count($count) { |
|
| 1240 | 1240 | return $count; |
| 1241 | 1241 | } // End sensei_lesson_comment_count() |
| 1242 | 1242 | |
@@ -1245,11 +1245,11 @@ discard block |
||
| 1245 | 1245 | * @param string $content Original content |
| 1246 | 1246 | * @return string Modified content |
| 1247 | 1247 | */ |
| 1248 | - public function sensei_search_results_excerpt( $content ) { |
|
| 1248 | + public function sensei_search_results_excerpt($content) { |
|
| 1249 | 1249 | global $post; |
| 1250 | 1250 | |
| 1251 | - if( is_search() && in_array( $post->post_type, array( 'course', 'lesson' ) ) ) { |
|
| 1252 | - $content = '<p class="course-excerpt">' . the_excerpt( ) . '</p>'; |
|
| 1251 | + if (is_search() && in_array($post->post_type, array('course', 'lesson'))) { |
|
| 1252 | + $content = '<p class="course-excerpt">'.the_excerpt( ).'</p>'; |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | return $content; |
@@ -1260,11 +1260,11 @@ discard block |
||
| 1260 | 1260 | * @param integer $order_id ID of order |
| 1261 | 1261 | * @return void |
| 1262 | 1262 | */ |
| 1263 | - public function remove_active_course( $order_id ) { |
|
| 1264 | - $order = new WC_Order( $order_id ); |
|
| 1263 | + public function remove_active_course($order_id) { |
|
| 1264 | + $order = new WC_Order($order_id); |
|
| 1265 | 1265 | |
| 1266 | - foreach ( $order->get_items() as $item ) { |
|
| 1267 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1266 | + foreach ($order->get_items() as $item) { |
|
| 1267 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1268 | 1268 | // If item has variation_id then its a variation of the product |
| 1269 | 1269 | $item_id = $item['variation_id']; |
| 1270 | 1270 | } else { |
@@ -1272,11 +1272,11 @@ discard block |
||
| 1272 | 1272 | $item_id = $item['product_id']; |
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | - if ( $item_id > 0 ) { |
|
| 1275 | + if ($item_id > 0) { |
|
| 1276 | 1276 | |
| 1277 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1277 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1278 | 1278 | |
| 1279 | - if( $user_id ) { |
|
| 1279 | + if ($user_id) { |
|
| 1280 | 1280 | |
| 1281 | 1281 | // Get all courses for product |
| 1282 | 1282 | $args = array( |
@@ -1292,13 +1292,13 @@ discard block |
||
| 1292 | 1292 | 'order' => 'ASC', |
| 1293 | 1293 | 'fields' => 'ids', |
| 1294 | 1294 | ); |
| 1295 | - $course_ids = get_posts( $args ); |
|
| 1295 | + $course_ids = get_posts($args); |
|
| 1296 | 1296 | |
| 1297 | - if( $course_ids && count( $course_ids ) > 0 ) { |
|
| 1298 | - foreach( $course_ids as $course_id ) { |
|
| 1297 | + if ($course_ids && count($course_ids) > 0) { |
|
| 1298 | + foreach ($course_ids as $course_id) { |
|
| 1299 | 1299 | |
| 1300 | 1300 | // Remove all course user meta |
| 1301 | - Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 1301 | + Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 1302 | 1302 | |
| 1303 | 1303 | } // End For Loop |
| 1304 | 1304 | } // End If Statement |
@@ -1314,16 +1314,16 @@ discard block |
||
| 1314 | 1314 | * @param integer $user_id User ID |
| 1315 | 1315 | * @return void |
| 1316 | 1316 | */ |
| 1317 | - public function activate_purchased_courses( $user_id = 0 ) { |
|
| 1317 | + public function activate_purchased_courses($user_id = 0) { |
|
| 1318 | 1318 | |
| 1319 | - if( $user_id ) { |
|
| 1319 | + if ($user_id) { |
|
| 1320 | 1320 | |
| 1321 | - if( Sensei_WC::is_woocommerce_active() ) { |
|
| 1321 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1322 | 1322 | |
| 1323 | 1323 | // Get all user's orders |
| 1324 | 1324 | $order_args = array( |
| 1325 | 1325 | 'post_type' => 'shop_order', |
| 1326 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 1326 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 1327 | 1327 | 'posts_per_page' => -1, |
| 1328 | 1328 | 'meta_query' => array( |
| 1329 | 1329 | array( |
@@ -1333,25 +1333,25 @@ discard block |
||
| 1333 | 1333 | ), |
| 1334 | 1334 | ); |
| 1335 | 1335 | |
| 1336 | - $orders = get_posts( $order_args ); |
|
| 1336 | + $orders = get_posts($order_args); |
|
| 1337 | 1337 | |
| 1338 | 1338 | $product_ids = array(); |
| 1339 | 1339 | $order_ids = array(); |
| 1340 | 1340 | |
| 1341 | - foreach( $orders as $post_id ) { |
|
| 1341 | + foreach ($orders as $post_id) { |
|
| 1342 | 1342 | |
| 1343 | 1343 | // Only process each order once |
| 1344 | - $processed = get_post_meta( $post_id, 'sensei_products_processed', true ); |
|
| 1344 | + $processed = get_post_meta($post_id, 'sensei_products_processed', true); |
|
| 1345 | 1345 | |
| 1346 | - if( $processed && $processed == 'processed' ) { |
|
| 1346 | + if ($processed && $processed == 'processed') { |
|
| 1347 | 1347 | continue; |
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | 1350 | // Get course product IDs from order |
| 1351 | - $order = new WC_Order( $post_id ); |
|
| 1351 | + $order = new WC_Order($post_id); |
|
| 1352 | 1352 | |
| 1353 | 1353 | $items = $order->get_items(); |
| 1354 | - foreach( $items as $item ) { |
|
| 1354 | + foreach ($items as $item) { |
|
| 1355 | 1355 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
| 1356 | 1356 | $item_id = $item['variation_id']; |
| 1357 | 1357 | $product_type = 'variation'; |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | $order_ids[] = $post_id; |
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | - if( count( $product_ids ) > 0 ) { |
|
| 1368 | + if (count($product_ids) > 0) { |
|
| 1369 | 1369 | |
| 1370 | 1370 | // Get all courses from user's orders |
| 1371 | 1371 | $course_args = array( |
@@ -1382,31 +1382,31 @@ discard block |
||
| 1382 | 1382 | 'order' => 'ASC', |
| 1383 | 1383 | 'fields' => 'ids', |
| 1384 | 1384 | ); |
| 1385 | - $course_ids = get_posts( $course_args ); |
|
| 1385 | + $course_ids = get_posts($course_args); |
|
| 1386 | 1386 | |
| 1387 | - foreach( $course_ids as $course_id ) { |
|
| 1387 | + foreach ($course_ids as $course_id) { |
|
| 1388 | 1388 | |
| 1389 | - $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id ); |
|
| 1389 | + $user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id); |
|
| 1390 | 1390 | |
| 1391 | 1391 | // Ignore course if already completed |
| 1392 | - if( Sensei_Utils::user_completed_course( $user_course_status ) ) { |
|
| 1392 | + if (Sensei_Utils::user_completed_course($user_course_status)) { |
|
| 1393 | 1393 | continue; |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | 1396 | // Ignore course if already started |
| 1397 | - if( $user_course_status ) { |
|
| 1397 | + if ($user_course_status) { |
|
| 1398 | 1398 | continue; |
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | // Mark course as started by user |
| 1402 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1402 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | - if( count( $order_ids ) > 0 ) { |
|
| 1407 | - foreach( $order_ids as $order_id ) { |
|
| 1406 | + if (count($order_ids) > 0) { |
|
| 1407 | + foreach ($order_ids as $order_id) { |
|
| 1408 | 1408 | // Mark order as processed |
| 1409 | - update_post_meta( $order_id, 'sensei_products_processed', 'processed' ); |
|
| 1409 | + update_post_meta($order_id, 'sensei_products_processed', 'processed'); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | } |
| 1412 | 1412 | } |
@@ -1420,28 +1420,28 @@ discard block |
||
| 1420 | 1420 | public function activate_purchased_single_course() { |
| 1421 | 1421 | global $post, $current_user; |
| 1422 | 1422 | |
| 1423 | - if( Sensei_WC::is_woocommerce_active() ) { |
|
| 1423 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1424 | 1424 | |
| 1425 | - if( ! is_user_logged_in() ) return; |
|
| 1426 | - if( ! isset( $post->ID ) ) return; |
|
| 1425 | + if ( ! is_user_logged_in()) return; |
|
| 1426 | + if ( ! isset($post->ID)) return; |
|
| 1427 | 1427 | |
| 1428 | 1428 | $user_id = $current_user->ID; |
| 1429 | 1429 | $course_id = $post->ID; |
| 1430 | - $course_product_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 1431 | - if( ! $course_product_id ) { |
|
| 1430 | + $course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 1431 | + if ( ! $course_product_id) { |
|
| 1432 | 1432 | return; |
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | - $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id ); |
|
| 1435 | + $user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id); |
|
| 1436 | 1436 | |
| 1437 | 1437 | // Ignore course if already completed |
| 1438 | - if( Sensei_Utils::user_completed_course( $user_course_status ) ) { |
|
| 1438 | + if (Sensei_Utils::user_completed_course($user_course_status)) { |
|
| 1439 | 1439 | |
| 1440 | 1440 | return; |
| 1441 | 1441 | } |
| 1442 | 1442 | |
| 1443 | 1443 | // Ignore course if already started |
| 1444 | - if( $user_course_status ) { |
|
| 1444 | + if ($user_course_status) { |
|
| 1445 | 1445 | return; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
@@ -1449,7 +1449,7 @@ discard block |
||
| 1449 | 1449 | $order_args = array( |
| 1450 | 1450 | 'post_type' => 'shop_order', |
| 1451 | 1451 | 'posts_per_page' => -1, |
| 1452 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 1452 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 1453 | 1453 | 'meta_query' => array( |
| 1454 | 1454 | array( |
| 1455 | 1455 | 'key' => '_customer_user', |
@@ -1458,28 +1458,28 @@ discard block |
||
| 1458 | 1458 | ), |
| 1459 | 1459 | 'fields' => 'ids', |
| 1460 | 1460 | ); |
| 1461 | - $orders = get_posts( $order_args ); |
|
| 1461 | + $orders = get_posts($order_args); |
|
| 1462 | 1462 | |
| 1463 | - foreach( $orders as $order_post_id ) { |
|
| 1463 | + foreach ($orders as $order_post_id) { |
|
| 1464 | 1464 | |
| 1465 | 1465 | // Get course product IDs from order |
| 1466 | - $order = new WC_Order( $order_post_id ); |
|
| 1466 | + $order = new WC_Order($order_post_id); |
|
| 1467 | 1467 | |
| 1468 | 1468 | $items = $order->get_items(); |
| 1469 | - foreach( $items as $item ) { |
|
| 1469 | + foreach ($items as $item) { |
|
| 1470 | 1470 | |
| 1471 | - $product = wc_get_product( $item['product_id'] ); |
|
| 1471 | + $product = wc_get_product($item['product_id']); |
|
| 1472 | 1472 | |
| 1473 | 1473 | // handle product bundles |
| 1474 | - if( is_object( $product ) && $product->is_type('bundle') ){ |
|
| 1474 | + if (is_object($product) && $product->is_type('bundle')) { |
|
| 1475 | 1475 | |
| 1476 | - $bundled_product = new WC_Product_Bundle( $product->id ); |
|
| 1476 | + $bundled_product = new WC_Product_Bundle($product->id); |
|
| 1477 | 1477 | $bundled_items = $bundled_product->get_bundled_items(); |
| 1478 | 1478 | |
| 1479 | - foreach( $bundled_items as $bundled_item ){ |
|
| 1479 | + foreach ($bundled_items as $bundled_item) { |
|
| 1480 | 1480 | |
| 1481 | - if( $bundled_item->product_id == $course_product_id ) { |
|
| 1482 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1481 | + if ($bundled_item->product_id == $course_product_id) { |
|
| 1482 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1483 | 1483 | return; |
| 1484 | 1484 | } |
| 1485 | 1485 | |
@@ -1488,8 +1488,8 @@ discard block |
||
| 1488 | 1488 | } else { |
| 1489 | 1489 | |
| 1490 | 1490 | // handle regular products |
| 1491 | - if( $item['product_id'] == $course_product_id ) { |
|
| 1492 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1491 | + if ($item['product_id'] == $course_product_id) { |
|
| 1492 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1493 | 1493 | return; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
@@ -1505,9 +1505,9 @@ discard block |
||
| 1505 | 1505 | * @param array $args Default arguments |
| 1506 | 1506 | * @return array Modified arguments |
| 1507 | 1507 | */ |
| 1508 | - public function hide_sensei_activity( $args = array() ) { |
|
| 1508 | + public function hide_sensei_activity($args = array()) { |
|
| 1509 | 1509 | |
| 1510 | - if( is_singular( 'lesson' ) || is_singular( 'course' ) ) { |
|
| 1510 | + if (is_singular('lesson') || is_singular('course')) { |
|
| 1511 | 1511 | $args['type'] = 'comment'; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
@@ -1524,9 +1524,9 @@ discard block |
||
| 1524 | 1524 | |
| 1525 | 1525 | //if not posted from the sensei login form let |
| 1526 | 1526 | // WordPress or any other party handle the failed request |
| 1527 | - if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
| 1527 | + if ( ! isset($_REQUEST['form']) || 'sensei-login' != $_REQUEST['form']) { |
|
| 1528 | 1528 | |
| 1529 | - return ; |
|
| 1529 | + return; |
|
| 1530 | 1530 | |
| 1531 | 1531 | } |
| 1532 | 1532 | |
@@ -1534,9 +1534,9 @@ discard block |
||
| 1534 | 1534 | $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
| 1535 | 1535 | |
| 1536 | 1536 | // if there's a valid referrer, and it's not the default log-in screen |
| 1537 | - if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
| 1537 | + if ( ! empty($referrer) && ! strstr($referrer, 'wp-login') && ! strstr($referrer, 'wp-admin')) { |
|
| 1538 | 1538 | // let's append some information (login=failed) to the URL for the theme to use |
| 1539 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1539 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1540 | 1540 | exit; |
| 1541 | 1541 | } |
| 1542 | 1542 | }// End sensei_login_fail_redirect_to_front_end_login |
@@ -1549,10 +1549,10 @@ discard block |
||
| 1549 | 1549 | function sensei_handle_login_request( ) { |
| 1550 | 1550 | |
| 1551 | 1551 | // Check that it is a sensei login request and if it has a valid nonce |
| 1552 | - if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
| 1552 | + if (isset($_REQUEST['form']) && 'sensei-login' == $_REQUEST['form']) { |
|
| 1553 | 1553 | |
| 1554 | 1554 | // Validate the login request nonce |
| 1555 | - if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
| 1555 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'sensei-login')) { |
|
| 1556 | 1556 | return; |
| 1557 | 1557 | } |
| 1558 | 1558 | |
@@ -1560,47 +1560,47 @@ discard block |
||
| 1560 | 1560 | $referrer = $_REQUEST['_wp_http_referer']; |
| 1561 | 1561 | //$redirect = $_REQUEST['_sensei_redirect']; |
| 1562 | 1562 | |
| 1563 | - if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
| 1564 | - && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
| 1563 | + if ((isset($_REQUEST['log']) && ! empty($_REQUEST['log'])) |
|
| 1564 | + && (isset($_REQUEST['pwd']) && ! empty($_REQUEST['pwd']))) { |
|
| 1565 | 1565 | |
| 1566 | 1566 | // when the user has entered a password or username do the sensei login |
| 1567 | 1567 | $creds = array(); |
| 1568 | 1568 | |
| 1569 | 1569 | // check if the requests login is an email address |
| 1570 | - if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
| 1570 | + if (is_email(trim($_REQUEST['log']))) { |
|
| 1571 | 1571 | // query wordpress for the users details |
| 1572 | - $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
| 1572 | + $user = get_user_by('email', sanitize_email($_REQUEST['log'])); |
|
| 1573 | 1573 | |
| 1574 | 1574 | // validate the user object |
| 1575 | - if( !$user ){ |
|
| 1575 | + if ( ! $user) { |
|
| 1576 | 1576 | |
| 1577 | 1577 | // the email doesnt exist |
| 1578 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1578 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1579 | 1579 | exit; |
| 1580 | 1580 | |
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | //assigne the username to the creds array for further processing |
| 1584 | - $creds['user_login'] = $user->user_login ; |
|
| 1584 | + $creds['user_login'] = $user->user_login; |
|
| 1585 | 1585 | |
| 1586 | - }else{ |
|
| 1586 | + } else { |
|
| 1587 | 1587 | |
| 1588 | 1588 | // process this as a default username login |
| 1589 | - $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
| 1589 | + $creds['user_login'] = sanitize_text_field($_REQUEST['log']); |
|
| 1590 | 1590 | |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | // get setup the rest of the creds array |
| 1594 | - $creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] ); |
|
| 1595 | - $creds['remember'] = isset( $_REQUEST['rememberme'] ) ? true : false ; |
|
| 1594 | + $creds['user_password'] = sanitize_text_field($_REQUEST['pwd']); |
|
| 1595 | + $creds['remember'] = isset($_REQUEST['rememberme']) ? true : false; |
|
| 1596 | 1596 | |
| 1597 | 1597 | //attempt logging in with the given details |
| 1598 | - $user = wp_signon( $creds, false ); |
|
| 1598 | + $user = wp_signon($creds, false); |
|
| 1599 | 1599 | |
| 1600 | - if ( is_wp_error($user) ){ // on login failure |
|
| 1601 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1600 | + if (is_wp_error($user)) { // on login failure |
|
| 1601 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1602 | 1602 | exit; |
| 1603 | - }else{ // on login success |
|
| 1603 | + } else { // on login success |
|
| 1604 | 1604 | |
| 1605 | 1605 | /** |
| 1606 | 1606 | * change the redirect url programatically |
@@ -1610,21 +1610,21 @@ discard block |
||
| 1610 | 1610 | * @param string $referrer the page where the current url wheresensei login form was posted from |
| 1611 | 1611 | */ |
| 1612 | 1612 | |
| 1613 | - $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) ); |
|
| 1613 | + $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg('login', $referrer)); |
|
| 1614 | 1614 | |
| 1615 | - wp_redirect( esc_url_raw( $success_redirect_url ) ); |
|
| 1615 | + wp_redirect(esc_url_raw($success_redirect_url)); |
|
| 1616 | 1616 | exit; |
| 1617 | 1617 | |
| 1618 | 1618 | } // end is_wp_error($user) |
| 1619 | 1619 | |
| 1620 | - }else{ // if username or password is empty |
|
| 1620 | + } else { // if username or password is empty |
|
| 1621 | 1621 | |
| 1622 | - wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
| 1622 | + wp_redirect(esc_url_raw(add_query_arg('login', 'emptyfields', $referrer))); |
|
| 1623 | 1623 | exit; |
| 1624 | 1624 | |
| 1625 | 1625 | } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
| 1626 | 1626 | |
| 1627 | - }elseif( ( isset( $_GET['login'] ) ) ) { |
|
| 1627 | + }elseif ((isset($_GET['login']))) { |
|
| 1628 | 1628 | // else if this request is a redircect from a previously faile login request |
| 1629 | 1629 | $this->login_message_process(); |
| 1630 | 1630 | |
@@ -1643,87 +1643,87 @@ discard block |
||
| 1643 | 1643 | * @return void redirect |
| 1644 | 1644 | * |
| 1645 | 1645 | */ |
| 1646 | - public function sensei_process_registration(){ |
|
| 1646 | + public function sensei_process_registration() { |
|
| 1647 | 1647 | global $current_user; |
| 1648 | 1648 | // check the for the sensei specific registration requests |
| 1649 | - if( !isset( $_POST['sensei_reg_username'] ) && ! isset( $_POST['sensei_reg_email'] ) && !isset( $_POST['sensei_reg_password'] )){ |
|
| 1649 | + if ( ! isset($_POST['sensei_reg_username']) && ! isset($_POST['sensei_reg_email']) && ! isset($_POST['sensei_reg_password'])) { |
|
| 1650 | 1650 | // exit if this is not a sensei registration request |
| 1651 | - return ; |
|
| 1651 | + return; |
|
| 1652 | 1652 | } |
| 1653 | 1653 | // check for spam throw cheating huh |
| 1654 | - if( isset( $_POST['email_2'] ) && '' !== $_POST['email_2'] ){ |
|
| 1654 | + if (isset($_POST['email_2']) && '' !== $_POST['email_2']) { |
|
| 1655 | 1655 | $message = 'Error: The spam field should be empty'; |
| 1656 | - Sensei()->notices->add_notice( $message, 'alert'); |
|
| 1656 | + Sensei()->notices->add_notice($message, 'alert'); |
|
| 1657 | 1657 | return; |
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | // retreive form variables |
| 1661 | - $new_user_name = sanitize_user( $_POST['sensei_reg_username'] ); |
|
| 1662 | - $new_user_email = $_POST['sensei_reg_email']; |
|
| 1663 | - $new_user_password = $_POST['sensei_reg_password']; |
|
| 1661 | + $new_user_name = sanitize_user($_POST['sensei_reg_username']); |
|
| 1662 | + $new_user_email = $_POST['sensei_reg_email']; |
|
| 1663 | + $new_user_password = $_POST['sensei_reg_password']; |
|
| 1664 | 1664 | |
| 1665 | 1665 | // Check the username |
| 1666 | 1666 | $username_error_notice = ''; |
| 1667 | - if ( $new_user_name == '' ) { |
|
| 1668 | - $username_error_notice = __( '<strong>ERROR</strong>: Please enter a username.' ); |
|
| 1669 | - } elseif ( ! validate_username( $new_user_name ) ) { |
|
| 1670 | - $username_error_notice = __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ); |
|
| 1671 | - } elseif ( username_exists( $new_user_name ) ) { |
|
| 1672 | - $username_error_notice = __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ); |
|
| 1667 | + if ($new_user_name == '') { |
|
| 1668 | + $username_error_notice = __('<strong>ERROR</strong>: Please enter a username.'); |
|
| 1669 | + } elseif ( ! validate_username($new_user_name)) { |
|
| 1670 | + $username_error_notice = __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'); |
|
| 1671 | + } elseif (username_exists($new_user_name)) { |
|
| 1672 | + $username_error_notice = __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'); |
|
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | // exit on username error |
| 1676 | - if( '' !== $username_error_notice ){ |
|
| 1677 | - Sensei()->notices->add_notice( $username_error_notice , 'alert'); |
|
| 1676 | + if ('' !== $username_error_notice) { |
|
| 1677 | + Sensei()->notices->add_notice($username_error_notice, 'alert'); |
|
| 1678 | 1678 | return; |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | 1681 | // Check the e-mail address |
| 1682 | 1682 | $email_error_notice = ''; |
| 1683 | - if ( $new_user_email == '' ) { |
|
| 1684 | - $email_error_notice = __( '<strong>ERROR</strong>: Please type your e-mail address.' ); |
|
| 1685 | - } elseif ( ! is_email( $new_user_email ) ) { |
|
| 1686 | - $email_error_notice = __( '<strong>ERROR</strong>: The email address isn’t correct.' ); |
|
| 1687 | - } elseif ( email_exists( $new_user_email ) ) { |
|
| 1688 | - $email_error_notice = __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ); |
|
| 1683 | + if ($new_user_email == '') { |
|
| 1684 | + $email_error_notice = __('<strong>ERROR</strong>: Please type your e-mail address.'); |
|
| 1685 | + } elseif ( ! is_email($new_user_email)) { |
|
| 1686 | + $email_error_notice = __('<strong>ERROR</strong>: The email address isn’t correct.'); |
|
| 1687 | + } elseif (email_exists($new_user_email)) { |
|
| 1688 | + $email_error_notice = __('<strong>ERROR</strong>: This email is already registered, please choose another one.'); |
|
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | // exit on email address error |
| 1692 | - if( '' !== $email_error_notice ){ |
|
| 1693 | - Sensei()->notices->add_notice( $email_error_notice , 'alert'); |
|
| 1692 | + if ('' !== $email_error_notice) { |
|
| 1693 | + Sensei()->notices->add_notice($email_error_notice, 'alert'); |
|
| 1694 | 1694 | return; |
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | //check user password |
| 1698 | 1698 | |
| 1699 | 1699 | // exit on email address error |
| 1700 | - if( empty( $new_user_password ) ){ |
|
| 1701 | - Sensei()->notices->add_notice( __( '<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.' ) , 'alert'); |
|
| 1700 | + if (empty($new_user_password)) { |
|
| 1701 | + Sensei()->notices->add_notice(__('<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.'), 'alert'); |
|
| 1702 | 1702 | return; |
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | // register user |
| 1706 | - $user_id = wp_create_user( $new_user_name, $new_user_password, $new_user_email ); |
|
| 1707 | - if ( ! $user_id || is_wp_error( $user_id ) ) { |
|
| 1708 | - Sensei()->notices->add_notice( sprintf( __( '<strong>ERROR</strong>: Couldn\'t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ), 'alert'); |
|
| 1706 | + $user_id = wp_create_user($new_user_name, $new_user_password, $new_user_email); |
|
| 1707 | + if ( ! $user_id || is_wp_error($user_id)) { |
|
| 1708 | + Sensei()->notices->add_notice(sprintf(__('<strong>ERROR</strong>: Couldn\'t register you… please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')), 'alert'); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | // notify the user |
| 1712 | - wp_new_user_notification( $user_id, $new_user_password ); |
|
| 1712 | + wp_new_user_notification($user_id, $new_user_password); |
|
| 1713 | 1713 | |
| 1714 | 1714 | // set global current user aka log the user in |
| 1715 | - $current_user = get_user_by( 'id', $user_id ); |
|
| 1716 | - wp_set_auth_cookie( $user_id, true ); |
|
| 1715 | + $current_user = get_user_by('id', $user_id); |
|
| 1716 | + wp_set_auth_cookie($user_id, true); |
|
| 1717 | 1717 | |
| 1718 | 1718 | // Redirect |
| 1719 | 1719 | global $wp; |
| 1720 | - if ( wp_get_referer() ) { |
|
| 1721 | - $redirect = esc_url( wp_get_referer() ); |
|
| 1720 | + if (wp_get_referer()) { |
|
| 1721 | + $redirect = esc_url(wp_get_referer()); |
|
| 1722 | 1722 | } else { |
| 1723 | - $redirect = esc_url( home_url( $wp->request ) ); |
|
| 1723 | + $redirect = esc_url(home_url($wp->request)); |
|
| 1724 | 1724 | } |
| 1725 | 1725 | |
| 1726 | - wp_redirect( apply_filters( 'sensei_registration_redirect', $redirect ) ); |
|
| 1726 | + wp_redirect(apply_filters('sensei_registration_redirect', $redirect)); |
|
| 1727 | 1727 | exit; |
| 1728 | 1728 | |
| 1729 | 1729 | } // end sensei_process_registration)() |
@@ -1734,23 +1734,23 @@ discard block |
||
| 1734 | 1734 | * @return void redirect |
| 1735 | 1735 | * @since 1.7.0 |
| 1736 | 1736 | */ |
| 1737 | - public function login_message_process(){ |
|
| 1737 | + public function login_message_process() { |
|
| 1738 | 1738 | |
| 1739 | 1739 | // setup the message variables |
| 1740 | 1740 | $message = ''; |
| 1741 | 1741 | |
| 1742 | 1742 | //only output message if the url contains login=failed and login=emptyfields |
| 1743 | 1743 | |
| 1744 | - if( $_GET['login'] == 'failed' ){ |
|
| 1744 | + if ($_GET['login'] == 'failed') { |
|
| 1745 | 1745 | |
| 1746 | - $message = __('Incorrect login details', 'woothemes-sensei' ); |
|
| 1746 | + $message = __('Incorrect login details', 'woothemes-sensei'); |
|
| 1747 | 1747 | |
| 1748 | - }elseif( $_GET['login'] == 'emptyfields' ){ |
|
| 1748 | + }elseif ($_GET['login'] == 'emptyfields') { |
|
| 1749 | 1749 | |
| 1750 | - $message= __('Please enter your username and password', 'woothemes-sensei' ); |
|
| 1750 | + $message = __('Please enter your username and password', 'woothemes-sensei'); |
|
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | - Sensei()->notices->add_notice( $message, 'alert'); |
|
| 1753 | + Sensei()->notices->add_notice($message, 'alert'); |
|
| 1754 | 1754 | |
| 1755 | 1755 | }// end login_message_process |
| 1756 | 1756 | |
@@ -1762,11 +1762,11 @@ discard block |
||
| 1762 | 1762 | * @return void redirect |
| 1763 | 1763 | * |
| 1764 | 1764 | */ |
| 1765 | - public function sensei_show_admin_bar () { |
|
| 1765 | + public function sensei_show_admin_bar() { |
|
| 1766 | 1766 | |
| 1767 | 1767 | if (current_user_can('edit_courses')) { |
| 1768 | 1768 | |
| 1769 | - add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
| 1769 | + add_filter('woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
| 1770 | 1770 | |
| 1771 | 1771 | } |
| 1772 | 1772 | |
@@ -1779,4 +1779,4 @@ discard block |
||
| 1779 | 1779 | * @ignore only for backward compatibility |
| 1780 | 1780 | * @since 1.9.0 |
| 1781 | 1781 | */ |
| 1782 | -class WooThemes_Sensei_Frontend extends Sensei_Frontend{} |
|
| 1782 | +class WooThemes_Sensei_Frontend extends Sensei_Frontend {} |
|
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @since 1.0.0 |
| 21 | 21 | */ |
| 22 | 22 | public function __construct () { |
| 23 | - $this->token = 'question'; |
|
| 23 | + $this->token = 'question'; |
|
| 24 | 24 | $this->question_types = $this->question_types(); |
| 25 | 25 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
| 26 | 26 | if ( is_admin() ) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | if( isset( $post->ID ) ) { |
| 119 | 119 | |
| 120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 120 | + $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 121 | 121 | |
| 122 | 122 | if( $question_type ) { |
| 123 | 123 | $type = $this->question_types[ $question_type ]; |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | public function save_question( $post_id = 0 ) { |
| 238 | 238 | |
| 239 | 239 | if( ! isset( $_POST['post_type'] |
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 240 | + ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | - //setup the data for saving |
|
| 246 | + //setup the data for saving |
|
| 247 | 247 | $data = $_POST ; |
| 248 | - $data['quiz_id'] = 0; |
|
| 248 | + $data['quiz_id'] = 0; |
|
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | 251 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -339,34 +339,34 @@ discard block |
||
| 339 | 339 | return $request; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Get the type of question by id |
|
| 344 | - * |
|
| 345 | - * This function uses the post terms to determine which question type |
|
| 346 | - * the passed question id belongs to. |
|
| 347 | - * |
|
| 348 | - * @since 1.7.4 |
|
| 349 | - * |
|
| 350 | - * @param int $question_id |
|
| 351 | - * |
|
| 352 | - * @return string $question_type | bool |
|
| 353 | - */ |
|
| 354 | - public function get_question_type( $question_id ){ |
|
| 355 | - |
|
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $question_type = 'multiple-choice'; |
|
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 364 | - $question_type = $type->slug; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $question_type; |
|
| 368 | - |
|
| 369 | - }// end get_question_type |
|
| 342 | + /** |
|
| 343 | + * Get the type of question by id |
|
| 344 | + * |
|
| 345 | + * This function uses the post terms to determine which question type |
|
| 346 | + * the passed question id belongs to. |
|
| 347 | + * |
|
| 348 | + * @since 1.7.4 |
|
| 349 | + * |
|
| 350 | + * @param int $question_id |
|
| 351 | + * |
|
| 352 | + * @return string $question_type | bool |
|
| 353 | + */ |
|
| 354 | + public function get_question_type( $question_id ){ |
|
| 355 | + |
|
| 356 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | + || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $question_type = 'multiple-choice'; |
|
| 362 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | + foreach( $question_types as $type ) { |
|
| 364 | + $question_type = $type->slug; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $question_type; |
|
| 368 | + |
|
| 369 | + }// end get_question_type |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Given a question ID, return the grade that can be achieved. |
@@ -398,317 +398,317 @@ discard block |
||
| 398 | 398 | } // end get_question_grade |
| 399 | 399 | |
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * This function simply loads the question type template |
|
| 403 | - * |
|
| 404 | - * @since 1.9.0 |
|
| 405 | - * @param $question_type |
|
| 406 | - */ |
|
| 407 | - public static function load_question_template( $question_type ){ |
|
| 408 | - |
|
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Echo the sensei question title. |
|
| 414 | - * |
|
| 415 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | - * |
|
| 417 | - * @since 1.9.0 |
|
| 418 | - * @param $question_id |
|
| 419 | - */ |
|
| 420 | - public static function the_question_title( $question_id ){ |
|
| 421 | - |
|
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 423 | - |
|
| 424 | - }// end the_question_title |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Generate the question title with it's grade. |
|
| 428 | - * |
|
| 429 | - * @since 1.9.0 |
|
| 430 | - * |
|
| 431 | - * @param $question_id |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Filter the sensei question title |
|
| 438 | - * |
|
| 439 | - * @since 1.3.0 |
|
| 440 | - * @param $question_title |
|
| 441 | - */ |
|
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | - */ |
|
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | - |
|
| 449 | - $title_html = '<span class="question question-title">'; |
|
| 450 | - $title_html .= $title; |
|
| 451 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | - $title_html .='</span>'; |
|
| 453 | - |
|
| 454 | - return $title_html; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Tech the question description |
|
| 459 | - * |
|
| 460 | - * @param $question_id |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 464 | - |
|
| 465 | - $question = get_post( $question_id ); |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Already documented within WordPress Core |
|
| 469 | - */ |
|
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | - |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Output the question description |
|
| 476 | - * |
|
| 477 | - * @since 1.9.0 |
|
| 478 | - * @param $question_id |
|
| 479 | - */ |
|
| 480 | - public static function the_question_description( $question_id ){ |
|
| 481 | - |
|
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 483 | - |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Get the questions media markup |
|
| 488 | - * |
|
| 489 | - * @since 1.9.0 |
|
| 490 | - * @param $question_id |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 494 | - |
|
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 496 | - $question_media_link = ''; |
|
| 497 | - if( 0 < intval( $question_media ) ) { |
|
| 498 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | - if( $mimetype ) { |
|
| 500 | - $mimetype_array = explode( '/', $mimetype); |
|
| 501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 502 | - $question_media_type = $mimetype_array[0]; |
|
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 505 | - $question_media_title = $attachment->post_title; |
|
| 506 | - $question_media_description = $attachment->post_content; |
|
| 507 | - switch( $question_media_type ) { |
|
| 508 | - case 'image': |
|
| 509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 512 | - break; |
|
| 513 | - |
|
| 514 | - case 'audio': |
|
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | - break; |
|
| 517 | - |
|
| 518 | - case 'video': |
|
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | - break; |
|
| 521 | - |
|
| 522 | - default: |
|
| 523 | - $question_media_filename = basename( $question_media_url ); |
|
| 524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $output = ''; |
|
| 532 | - if( $question_media_link ) { |
|
| 533 | - |
|
| 534 | - $output .= '<div class="question_media_display">'; |
|
| 535 | - $output .= $question_media_link; |
|
| 536 | - $output .= '<dl>'; |
|
| 537 | - |
|
| 538 | - if( $question_media_title ) { |
|
| 539 | - |
|
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 541 | - |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if( $question_media_description ) { |
|
| 545 | - |
|
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | - |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $output .= '</dl>'; |
|
| 551 | - $output .= '</div>'; |
|
| 401 | + /** |
|
| 402 | + * This function simply loads the question type template |
|
| 403 | + * |
|
| 404 | + * @since 1.9.0 |
|
| 405 | + * @param $question_type |
|
| 406 | + */ |
|
| 407 | + public static function load_question_template( $question_type ){ |
|
| 408 | + |
|
| 409 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Echo the sensei question title. |
|
| 414 | + * |
|
| 415 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | + * |
|
| 417 | + * @since 1.9.0 |
|
| 418 | + * @param $question_id |
|
| 419 | + */ |
|
| 420 | + public static function the_question_title( $question_id ){ |
|
| 421 | + |
|
| 422 | + echo self::get_the_question_title( $question_id ); |
|
| 423 | + |
|
| 424 | + }// end the_question_title |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Generate the question title with it's grade. |
|
| 428 | + * |
|
| 429 | + * @since 1.9.0 |
|
| 430 | + * |
|
| 431 | + * @param $question_id |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + public static function get_the_question_title( $question_id ){ |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Filter the sensei question title |
|
| 438 | + * |
|
| 439 | + * @since 1.3.0 |
|
| 440 | + * @param $question_title |
|
| 441 | + */ |
|
| 442 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | + */ |
|
| 447 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | + |
|
| 449 | + $title_html = '<span class="question question-title">'; |
|
| 450 | + $title_html .= $title; |
|
| 451 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | + $title_html .='</span>'; |
|
| 453 | + |
|
| 454 | + return $title_html; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Tech the question description |
|
| 459 | + * |
|
| 460 | + * @param $question_id |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public static function get_the_question_description( $question_id ){ |
|
| 464 | + |
|
| 465 | + $question = get_post( $question_id ); |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Already documented within WordPress Core |
|
| 469 | + */ |
|
| 470 | + return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | + |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Output the question description |
|
| 476 | + * |
|
| 477 | + * @since 1.9.0 |
|
| 478 | + * @param $question_id |
|
| 479 | + */ |
|
| 480 | + public static function the_question_description( $question_id ){ |
|
| 481 | + |
|
| 482 | + echo self::get_the_question_description( $question_id ); |
|
| 483 | + |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Get the questions media markup |
|
| 488 | + * |
|
| 489 | + * @since 1.9.0 |
|
| 490 | + * @param $question_id |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + public static function get_the_question_media( $question_id ){ |
|
| 494 | + |
|
| 495 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 496 | + $question_media_link = ''; |
|
| 497 | + if( 0 < intval( $question_media ) ) { |
|
| 498 | + $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | + if( $mimetype ) { |
|
| 500 | + $mimetype_array = explode( '/', $mimetype); |
|
| 501 | + if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 502 | + $question_media_type = $mimetype_array[0]; |
|
| 503 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | + $attachment = get_post( $question_media ); |
|
| 505 | + $question_media_title = $attachment->post_title; |
|
| 506 | + $question_media_description = $attachment->post_content; |
|
| 507 | + switch( $question_media_type ) { |
|
| 508 | + case 'image': |
|
| 509 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 512 | + break; |
|
| 513 | + |
|
| 514 | + case 'audio': |
|
| 515 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | + break; |
|
| 517 | + |
|
| 518 | + case 'video': |
|
| 519 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | + break; |
|
| 521 | + |
|
| 522 | + default: |
|
| 523 | + $question_media_filename = basename( $question_media_url ); |
|
| 524 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $output = ''; |
|
| 532 | + if( $question_media_link ) { |
|
| 552 | 533 | |
| 534 | + $output .= '<div class="question_media_display">'; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | + $output .= '<dl>'; |
|
| 553 | 537 | |
| 554 | - } |
|
| 555 | - |
|
| 556 | - return $output; |
|
| 557 | - |
|
| 558 | - } // end get_the_question_media |
|
| 559 | - |
|
| 538 | + if( $question_media_title ) { |
|
| 560 | 539 | |
| 561 | - /** |
|
| 562 | - * Output the question media |
|
| 563 | - * |
|
| 564 | - * @since 1.9.0 |
|
| 565 | - * @param string $question_id |
|
| 566 | - */ |
|
| 567 | - public static function the_question_media( $question_id ){ |
|
| 540 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 568 | 541 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 542 | + } |
|
| 570 | 543 | |
| 571 | - } |
|
| 544 | + if( $question_media_description ) { |
|
| 572 | 545 | |
| 573 | - /** |
|
| 574 | - * Output a special field for the question needed for question submission. |
|
| 575 | - * |
|
| 576 | - * @since 1.9.0 |
|
| 577 | - * |
|
| 578 | - * @param $question_id |
|
| 579 | - */ |
|
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | - ?> |
|
| 546 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | + |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + $output .= '</dl>'; |
|
| 551 | + $output .= '</div>'; |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return $output; |
|
| 557 | + |
|
| 558 | + } // end get_the_question_media |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Output the question media |
|
| 563 | + * |
|
| 564 | + * @since 1.9.0 |
|
| 565 | + * @param string $question_id |
|
| 566 | + */ |
|
| 567 | + public static function the_question_media( $question_id ){ |
|
| 568 | + |
|
| 569 | + echo self::get_the_question_media( $question_id ); |
|
| 570 | + |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Output a special field for the question needed for question submission. |
|
| 575 | + * |
|
| 576 | + * @since 1.9.0 |
|
| 577 | + * |
|
| 578 | + * @param $question_id |
|
| 579 | + */ |
|
| 580 | + public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | + ?> |
|
| 582 | 582 | |
| 583 | 583 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
| 584 | 584 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | - } |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - /** |
|
| 590 | - * This function can only be run withing the single quiz question loop |
|
| 591 | - * |
|
| 592 | - * @since 1.9.0 |
|
| 593 | - * @param $question_id |
|
| 594 | - */ |
|
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 589 | + /** |
|
| 590 | + * This function can only be run withing the single quiz question loop |
|
| 591 | + * |
|
| 592 | + * @since 1.9.0 |
|
| 593 | + * @param $question_id |
|
| 594 | + */ |
|
| 595 | + public static function answer_feedback_notes( $question_id ){ |
|
| 596 | 596 | |
| 597 | - //IDS |
|
| 598 | - $quiz_id = get_the_ID(); |
|
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 597 | + //IDS |
|
| 598 | + $quiz_id = get_the_ID(); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 600 | 600 | |
| 601 | - // Data to check before showing feedback |
|
| 602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 601 | + // Data to check before showing feedback |
|
| 602 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 608 | 608 | |
| 609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 609 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | + || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 612 | 612 | |
| 613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 614 | 614 | |
| 615 | - if( $answer_notes ) { ?> |
|
| 615 | + if( $answer_notes ) { ?> |
|
| 616 | 616 | |
| 617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
| 618 | 618 | |
| 619 | 619 | <?php |
| 620 | 620 | |
| 621 | - /** |
|
| 622 | - * Filter the answer feedback |
|
| 623 | - * Since 1.9.0 |
|
| 624 | - * |
|
| 625 | - * @param string $answer_notes |
|
| 626 | - * @param string $question_id |
|
| 627 | - * @param string $lesson_id |
|
| 628 | - */ |
|
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 621 | + /** |
|
| 622 | + * Filter the answer feedback |
|
| 623 | + * Since 1.9.0 |
|
| 624 | + * |
|
| 625 | + * @param string $answer_notes |
|
| 626 | + * @param string $question_id |
|
| 627 | + * @param string $lesson_id |
|
| 628 | + */ |
|
| 629 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 630 | 630 | |
| 631 | - ?> |
|
| 631 | + ?> |
|
| 632 | 632 | |
| 633 | 633 | </div> |
| 634 | 634 | |
| 635 | 635 | <?php } |
| 636 | 636 | |
| 637 | - }// end if we can show answer feedback |
|
| 637 | + }// end if we can show answer feedback |
|
| 638 | 638 | |
| 639 | - }// end answer_feedback_notes |
|
| 639 | + }// end answer_feedback_notes |
|
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | - * |
|
| 644 | - * |
|
| 645 | - * @since 1.9.0 |
|
| 646 | - * @param string $question_id |
|
| 647 | - */ |
|
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 641 | + /** |
|
| 642 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | + * |
|
| 644 | + * |
|
| 645 | + * @since 1.9.0 |
|
| 646 | + * @param string $question_id |
|
| 647 | + */ |
|
| 648 | + public static function the_answer_result_indication( $question_id ){ |
|
| 649 | 649 | |
| 650 | - global $post, $current_user, $sensei_question_loop; |
|
| 650 | + global $post, $current_user, $sensei_question_loop; |
|
| 651 | 651 | |
| 652 | - // Post Data |
|
| 653 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | - $question_item = $sensei_question_loop['current_question']; |
|
| 652 | + // Post Data |
|
| 653 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | + $question_item = $sensei_question_loop['current_question']; |
|
| 656 | 656 | |
| 657 | - // Setup variable needed to determine if the message should show and what it should show |
|
| 658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 657 | + // Setup variable needed to determine if the message should show and what it should show |
|
| 658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 662 | 662 | |
| 663 | - // retrieve the question total grade |
|
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 663 | + // retrieve the question total grade |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 665 | 665 | |
| 666 | - // retrieve grade the user achieved |
|
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 666 | + // retrieve grade the user achieved |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 668 | 668 | |
| 669 | - // Question ID |
|
| 670 | - $question_id = $question_item->ID; |
|
| 669 | + // Question ID |
|
| 670 | + $question_id = $question_item->ID; |
|
| 671 | 671 | |
| 672 | - // conditions to check |
|
| 673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 672 | + // conditions to check |
|
| 673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 678 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 677 | + if ( $completed_with_valid_grade |
|
| 678 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 680 | 680 | |
| 681 | - $user_correct = false; |
|
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | - $answer_message_class = 'user_wrong'; |
|
| 684 | - // For zero grade mark as 'correct' but add no classes |
|
| 685 | - if ( 0 == $question_grade ) { |
|
| 681 | + $user_correct = false; |
|
| 682 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | + $answer_message_class = 'user_wrong'; |
|
| 684 | + // For zero grade mark as 'correct' but add no classes |
|
| 685 | + if ( 0 == $question_grade ) { |
|
| 686 | 686 | |
| 687 | - $user_correct = true; |
|
| 688 | - $answer_message = ''; |
|
| 689 | - $answer_message_class = ''; |
|
| 687 | + $user_correct = true; |
|
| 688 | + $answer_message = ''; |
|
| 689 | + $answer_message_class = ''; |
|
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if( $user_question_grade > 0 ) { |
|
| 692 | 692 | |
| 693 | - $user_correct = true; |
|
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | - $answer_message_class = 'user_right'; |
|
| 693 | + $user_correct = true; |
|
| 694 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | + $answer_message_class = 'user_right'; |
|
| 696 | 696 | |
| 697 | - } |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 699 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 700 | + if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 701 | 701 | |
| 702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 702 | + $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 703 | 703 | |
| 704 | - } |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - // answer feedback |
|
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 709 | - $answer_message_class .= ' has_notes'; |
|
| 710 | - } |
|
| 711 | - ?> |
|
| 706 | + // answer feedback |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | + if( $answer_notes ) { |
|
| 709 | + $answer_message_class .= ' has_notes'; |
|
| 710 | + } |
|
| 711 | + ?> |
|
| 712 | 712 | |
| 713 | 713 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
| 714 | 714 | |
@@ -718,387 +718,387 @@ discard block |
||
| 718 | 718 | |
| 719 | 719 | <?php |
| 720 | 720 | |
| 721 | - } // end if user can see all the goodies |
|
| 722 | - |
|
| 723 | - }// end the_answer_result_indication |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Generate the question template data and return it as an array. |
|
| 727 | - * |
|
| 728 | - * @since 1.9.0 |
|
| 729 | - * |
|
| 730 | - * @param string $question_id |
|
| 731 | - * @param $quiz_id |
|
| 732 | - * @return array $question_data |
|
| 733 | - */ |
|
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 735 | - |
|
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 737 | - |
|
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | - //backwards compatibility |
|
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 741 | - $reset_allowed = 1; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // Check again that the lesson is complete |
|
| 745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 746 | - $user_lesson_complete = false; |
|
| 747 | - if ( $user_lesson_end ) { |
|
| 748 | - $user_lesson_complete = true; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - //setup the question data |
|
| 752 | - $data[ 'ID' ] = $question_id; |
|
| 753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Filter the question template data. This filter fires in |
|
| 770 | - * the get_template_data function |
|
| 771 | - * |
|
| 772 | - * @hooked self::boolean_load_question_data |
|
| 773 | - * |
|
| 774 | - * @since 1.9.0 |
|
| 775 | - * |
|
| 776 | - * @param array $data |
|
| 777 | - * @param string $question_id |
|
| 778 | - * @param string $quiz_id |
|
| 779 | - */ |
|
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 721 | + } // end if user can see all the goodies |
|
| 781 | 722 | |
| 782 | - } |
|
| 723 | + }// end the_answer_result_indication |
|
| 783 | 724 | |
| 784 | - /** |
|
| 785 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | - * filter. |
|
| 787 | - * |
|
| 788 | - * @since 1.9.0 |
|
| 789 | - * |
|
| 790 | - * @param $question_data |
|
| 791 | - * @param $question_id |
|
| 792 | - * @param $quiz_id |
|
| 793 | - * |
|
| 794 | - * @return array() |
|
| 795 | - */ |
|
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 725 | + /** |
|
| 726 | + * Generate the question template data and return it as an array. |
|
| 727 | + * |
|
| 728 | + * @since 1.9.0 |
|
| 729 | + * |
|
| 730 | + * @param string $question_id |
|
| 731 | + * @param $quiz_id |
|
| 732 | + * @return array $question_data |
|
| 733 | + */ |
|
| 734 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
| 797 | 735 | |
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 798 | 737 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 738 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | + //backwards compatibility |
|
| 740 | + if( 'on' == $reset_allowed ) { |
|
| 741 | + $reset_allowed = 1; |
|
| 742 | + } |
|
| 800 | 743 | |
| 801 | - // Get uploaded file |
|
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | - $answer_media_url = $answer_media_filename = ''; |
|
| 744 | + // Check again that the lesson is complete |
|
| 745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 746 | + $user_lesson_complete = false; |
|
| 747 | + if ( $user_lesson_end ) { |
|
| 748 | + $user_lesson_complete = true; |
|
| 749 | + } |
|
| 804 | 750 | |
| 751 | + //setup the question data |
|
| 752 | + $data[ 'ID' ] = $question_id; |
|
| 753 | + $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | + $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | + $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | + $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Filter the question template data. This filter fires in |
|
| 770 | + * the get_template_data function |
|
| 771 | + * |
|
| 772 | + * @hooked self::boolean_load_question_data |
|
| 773 | + * |
|
| 774 | + * @since 1.9.0 |
|
| 775 | + * |
|
| 776 | + * @param array $data |
|
| 777 | + * @param string $question_id |
|
| 778 | + * @param string $quiz_id |
|
| 779 | + */ |
|
| 780 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 805 | 781 | |
| 806 | - $question_helptext = ''; |
|
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 782 | + } |
|
| 808 | 783 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 784 | + /** |
|
| 785 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | + * filter. |
|
| 787 | + * |
|
| 788 | + * @since 1.9.0 |
|
| 789 | + * |
|
| 790 | + * @param $question_data |
|
| 791 | + * @param $question_id |
|
| 792 | + * @param $quiz_id |
|
| 793 | + * |
|
| 794 | + * @return array() |
|
| 795 | + */ |
|
| 796 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 810 | 797 | |
| 811 | - } |
|
| 812 | 798 | |
| 799 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 813 | 800 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 801 | + // Get uploaded file |
|
| 802 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | + $answer_media_url = $answer_media_filename = ''; |
|
| 815 | 804 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 818 | 805 | |
| 819 | - } |
|
| 806 | + $question_helptext = ''; |
|
| 807 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 820 | 808 | |
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 821 | 810 | |
| 822 | - // Get max upload file size, formatted for display |
|
| 823 | - // Code copied from wp-admin/includes/media.php:1515 |
|
| 824 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 827 | - $upload_size_unit /= 1024; |
|
| 828 | - } |
|
| 829 | - if ( $u < 0 ) { |
|
| 811 | + } |
|
| 830 | 812 | |
| 831 | - $upload_size_unit = 0; |
|
| 832 | - $u = 0; |
|
| 833 | 813 | |
| 834 | - } else { |
|
| 814 | + if( 0 < intval( $attachment_id ) ) { |
|
| 835 | 815 | |
| 836 | - $upload_size_unit = (int) $upload_size_unit; |
|
| 816 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | + $answer_media_filename = basename( $answer_media_url ); |
|
| 837 | 818 | |
| 838 | - } |
|
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 819 | + } |
|
| 840 | 820 | |
| 841 | - // Assemble all the data needed by the file upload template |
|
| 842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 845 | 821 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 822 | + // Get max upload file size, formatted for display |
|
| 823 | + // Code copied from wp-admin/includes/media.php:1515 |
|
| 824 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 825 | + $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 827 | + $upload_size_unit /= 1024; |
|
| 828 | + } |
|
| 829 | + if ( $u < 0 ) { |
|
| 847 | 830 | |
| 848 | - }// end if is file upload type |
|
| 831 | + $upload_size_unit = 0; |
|
| 832 | + $u = 0; |
|
| 849 | 833 | |
| 850 | - return $question_data; |
|
| 834 | + } else { |
|
| 851 | 835 | |
| 852 | - }// end file_upload_load_question_data |
|
| 836 | + $upload_size_unit = (int) $upload_size_unit; |
|
| 853 | 837 | |
| 854 | - /** |
|
| 855 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | - * filter. |
|
| 857 | - * |
|
| 858 | - * @since 1.9.0 |
|
| 859 | - * |
|
| 860 | - * @param $question_data |
|
| 861 | - * @param $question_id |
|
| 862 | - * @param $quiz_id |
|
| 863 | - * |
|
| 864 | - * @return array() |
|
| 865 | - */ |
|
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 838 | + } |
|
| 839 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 867 | 840 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 841 | + // Assemble all the data needed by the file upload template |
|
| 842 | + $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | + $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 869 | 845 | |
| 846 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 870 | 847 | |
| 871 | - $answer_type = 'radio'; |
|
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 848 | + }// end if is file upload type |
|
| 873 | 849 | |
| 874 | - $answer_type = 'checkbox'; |
|
| 850 | + return $question_data; |
|
| 875 | 851 | |
| 876 | - } |
|
| 852 | + }// end file_upload_load_question_data |
|
| 877 | 853 | |
| 878 | - // Merge right and wrong answers |
|
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 854 | + /** |
|
| 855 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | + * filter. |
|
| 857 | + * |
|
| 858 | + * @since 1.9.0 |
|
| 859 | + * |
|
| 860 | + * @param $question_data |
|
| 861 | + * @param $question_id |
|
| 862 | + * @param $quiz_id |
|
| 863 | + * |
|
| 864 | + * @return array() |
|
| 865 | + */ |
|
| 866 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 880 | 867 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 868 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 882 | 869 | |
| 883 | - } else { |
|
| 884 | 870 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 871 | + $answer_type = 'radio'; |
|
| 872 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 887 | 873 | |
| 888 | - } |
|
| 874 | + $answer_type = 'checkbox'; |
|
| 889 | 875 | |
| 890 | - // Setup answer options array. |
|
| 891 | - $question_answers_options = array(); |
|
| 892 | - $count = 0; |
|
| 876 | + } |
|
| 893 | 877 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 878 | + // Merge right and wrong answers |
|
| 879 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 895 | 880 | |
| 896 | - $count++; |
|
| 897 | - $question_option = array(); |
|
| 881 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 898 | 882 | |
| 899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 883 | + } else { |
|
| 902 | 884 | |
| 903 | - $user_correct = false; |
|
| 885 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 904 | 887 | |
| 888 | + } |
|
| 905 | 889 | |
| 906 | - // For zero grade mark as 'correct' but add no classes |
|
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 890 | + // Setup answer options array. |
|
| 891 | + $question_answers_options = array(); |
|
| 892 | + $count = 0; |
|
| 908 | 893 | |
| 909 | - $user_correct = true; |
|
| 894 | + foreach( $merged_options as $answer ) { |
|
| 910 | 895 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 896 | + $count++; |
|
| 897 | + $question_option = array(); |
|
| 912 | 898 | |
| 913 | - $user_correct = true; |
|
| 899 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | + || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 914 | 902 | |
| 915 | - } |
|
| 903 | + $user_correct = false; |
|
| 916 | 904 | |
| 917 | - } |
|
| 918 | 905 | |
| 919 | - // setup the option specific classes |
|
| 920 | - $answer_class = ''; |
|
| 921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 906 | + // For zero grade mark as 'correct' but add no classes |
|
| 907 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 923 | 908 | |
| 924 | - $answer_class .= ' right_answer'; |
|
| 909 | + $user_correct = true; |
|
| 925 | 910 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 911 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 927 | 912 | |
| 928 | - $answer_class .= ' right_answer'; |
|
| 913 | + $user_correct = true; |
|
| 929 | 914 | |
| 930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 915 | + } |
|
| 932 | 916 | |
| 933 | - $answer_class = 'user_wrong'; |
|
| 934 | - if( $user_correct ) { |
|
| 917 | + } |
|
| 935 | 918 | |
| 936 | - $answer_class = 'user_right'; |
|
| 919 | + // setup the option specific classes |
|
| 920 | + $answer_class = ''; |
|
| 921 | + if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | + if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 937 | 923 | |
| 938 | - } |
|
| 924 | + $answer_class .= ' right_answer'; |
|
| 939 | 925 | |
| 940 | - } |
|
| 926 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 941 | 927 | |
| 942 | - } |
|
| 928 | + $answer_class .= ' right_answer'; |
|
| 943 | 929 | |
| 944 | - // determine if the current option must be checked |
|
| 945 | - $checked = ''; |
|
| 946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 930 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 948 | 932 | |
| 949 | - $checked = 'checked="checked"'; |
|
| 933 | + $answer_class = 'user_wrong'; |
|
| 934 | + if( $user_correct ) { |
|
| 950 | 935 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 936 | + $answer_class = 'user_right'; |
|
| 952 | 937 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 938 | + } |
|
| 954 | 939 | |
| 955 | - } |
|
| 940 | + } |
|
| 956 | 941 | |
| 957 | - } // End If Statement |
|
| 942 | + } |
|
| 958 | 943 | |
| 959 | - //Load the answer option data |
|
| 960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | - $question_option[ 'answer' ] = $answer; |
|
| 962 | - $question_option[ 'option_class'] = $answer_class; |
|
| 963 | - $question_option[ 'checked'] = $checked; |
|
| 964 | - $question_option[ 'count' ] = $count; |
|
| 965 | - $question_option[ 'type' ] = $answer_type; |
|
| 944 | + // determine if the current option must be checked |
|
| 945 | + $checked = ''; |
|
| 946 | + if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | + if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 966 | 948 | |
| 967 | - // add the speci fic option to the list of options for this question |
|
| 968 | - $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
| 949 | + $checked = 'checked="checked"'; |
|
| 969 | 950 | |
| 970 | - } // end for each option |
|
| 951 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 971 | 952 | |
| 953 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 972 | 954 | |
| 973 | - // Shuffle the array depending on the settings |
|
| 974 | - $answer_options_sorted = array(); |
|
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 955 | + } |
|
| 977 | 956 | |
| 978 | - $answer_options_sorted = $question_answers_options; |
|
| 979 | - shuffle( $answer_options_sorted ); |
|
| 957 | + } // End If Statement |
|
| 980 | 958 | |
| 981 | - } else { |
|
| 959 | + //Load the answer option data |
|
| 960 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | + $question_option[ 'answer' ] = $answer; |
|
| 962 | + $question_option[ 'option_class'] = $answer_class; |
|
| 963 | + $question_option[ 'checked'] = $checked; |
|
| 964 | + $question_option[ 'count' ] = $count; |
|
| 965 | + $question_option[ 'type' ] = $answer_type; |
|
| 982 | 966 | |
| 983 | - $answer_order = array(); |
|
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 967 | + // add the speci fic option to the list of options for this question |
|
| 968 | + $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
| 986 | 969 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 970 | + } // end for each option |
|
| 989 | 971 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 991 | 972 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 973 | + // Shuffle the array depending on the settings |
|
| 974 | + $answer_options_sorted = array(); |
|
| 975 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | + if( $random_order && $random_order == 'yes' ) { |
|
| 993 | 977 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 978 | + $answer_options_sorted = $question_answers_options; |
|
| 979 | + shuffle( $answer_options_sorted ); |
|
| 996 | 980 | |
| 997 | - } |
|
| 981 | + } else { |
|
| 998 | 982 | |
| 999 | - } |
|
| 983 | + $answer_order = array(); |
|
| 984 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | + if( $answer_order_string ) { |
|
| 1000 | 986 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 987 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | + if( count( $answer_order ) > 0 ) { |
|
| 1003 | 989 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 990 | + foreach( $answer_order as $answer_id ) { |
|
| 1005 | 991 | |
| 1006 | - } |
|
| 1007 | - } |
|
| 992 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 1008 | 993 | |
| 1009 | - }else{ |
|
| 994 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | + unset( $question_answers_options[ $answer_id ] ); |
|
| 1010 | 996 | |
| 1011 | - $answer_options_sorted = $question_answers_options; |
|
| 997 | + } |
|
| 1012 | 998 | |
| 1013 | - } |
|
| 999 | + } |
|
| 1014 | 1000 | |
| 1015 | - }else{ |
|
| 1001 | + if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | + foreach( $question_answers_options as $id => $answer ) { |
|
| 1016 | 1003 | |
| 1017 | - $answer_options_sorted = $question_answers_options; |
|
| 1004 | + $answer_options_sorted[ $id ] = $answer; |
|
| 1018 | 1005 | |
| 1019 | - } // end if $answer_order_string |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1020 | 1008 | |
| 1021 | - } // end if random order |
|
| 1009 | + }else{ |
|
| 1022 | 1010 | |
| 1011 | + $answer_options_sorted = $question_answers_options; |
|
| 1023 | 1012 | |
| 1024 | - // assemble and setup the data for the templates data array |
|
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1013 | + } |
|
| 1026 | 1014 | |
| 1027 | - } |
|
| 1015 | + }else{ |
|
| 1028 | 1016 | |
| 1029 | - return $question_data; |
|
| 1017 | + $answer_options_sorted = $question_answers_options; |
|
| 1030 | 1018 | |
| 1031 | - }// end multiple_choice_load_question_data |
|
| 1019 | + } // end if $answer_order_string |
|
| 1032 | 1020 | |
| 1033 | - /** |
|
| 1034 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | - * filter. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * |
|
| 1039 | - * @param $question_data |
|
| 1040 | - * @param $question_id |
|
| 1041 | - * @param $quiz_id |
|
| 1042 | - * |
|
| 1043 | - * @return array() |
|
| 1044 | - */ |
|
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1021 | + } // end if random order |
|
| 1046 | 1022 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1048 | 1023 | |
| 1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1024 | + // assemble and setup the data for the templates data array |
|
| 1025 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1053 | 1026 | |
| 1054 | - } |
|
| 1027 | + } |
|
| 1055 | 1028 | |
| 1056 | - return $question_data; |
|
| 1029 | + return $question_data; |
|
| 1057 | 1030 | |
| 1058 | - }// end gap_fill_load_question_data |
|
| 1031 | + }// end multiple_choice_load_question_data |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | + * filter. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * |
|
| 1039 | + * @param $question_data |
|
| 1040 | + * @param $question_id |
|
| 1041 | + * @param $quiz_id |
|
| 1042 | + * |
|
| 1043 | + * @return array() |
|
| 1044 | + */ |
|
| 1045 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1046 | + |
|
| 1047 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1048 | + |
|
| 1049 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1053 | + |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $question_data; |
|
| 1057 | + |
|
| 1058 | + }// end gap_fill_load_question_data |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - /** |
|
| 1062 | - * Get the correct answer for a question |
|
| 1063 | - * |
|
| 1064 | - * @param $question_id |
|
| 1065 | - * @return string $correct_answer or empty |
|
| 1066 | - */ |
|
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1061 | + /** |
|
| 1062 | + * Get the correct answer for a question |
|
| 1063 | + * |
|
| 1064 | + * @param $question_id |
|
| 1065 | + * @return string $correct_answer or empty |
|
| 1066 | + */ |
|
| 1067 | + public static function get_correct_answer( $question_id ){ |
|
| 1068 | 1068 | |
| 1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1072 | - $grade_type = 'manual-grade'; |
|
| 1069 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | + $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1072 | + $grade_type = 'manual-grade'; |
|
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean'== $type ) { |
|
| 1075 | 1075 | |
| 1076 | - $right_answer = ucfirst($right_answer); |
|
| 1076 | + $right_answer = ucfirst($right_answer); |
|
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif( 'multiple-choice' == $type ) { |
|
| 1079 | 1079 | |
| 1080 | - $right_answer = (array) $right_answer; |
|
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1080 | + $right_answer = (array) $right_answer; |
|
| 1081 | + $right_answer = implode( ', ', $right_answer ); |
|
| 1082 | 1082 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1083 | + }elseif( 'gap-fill' == $type ) { |
|
| 1084 | 1084 | |
| 1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1085 | + $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | + if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | + if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | + if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1089 | 1089 | |
| 1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1090 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1091 | 1091 | |
| 1092 | - }else{ |
|
| 1092 | + }else{ |
|
| 1093 | 1093 | |
| 1094 | - // for non auto gradable question types no answer should be returned. |
|
| 1095 | - $right_answer = ''; |
|
| 1094 | + // for non auto gradable question types no answer should be returned. |
|
| 1095 | + $right_answer = ''; |
|
| 1096 | 1096 | |
| 1097 | - } |
|
| 1097 | + } |
|
| 1098 | 1098 | |
| 1099 | - return $right_answer; |
|
| 1099 | + return $right_answer; |
|
| 1100 | 1100 | |
| 1101 | - } // get_correct_answer |
|
| 1101 | + } // get_correct_answer |
|
| 1102 | 1102 | |
| 1103 | 1103 | } // End Class |
| 1104 | 1104 | |
@@ -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 Question Class |
@@ -19,35 +19,35 @@ discard block |
||
| 19 | 19 | * Constructor. |
| 20 | 20 | * @since 1.0.0 |
| 21 | 21 | */ |
| 22 | - public function __construct () { |
|
| 22 | + public function __construct() { |
|
| 23 | 23 | $this->token = 'question'; |
| 24 | 24 | $this->question_types = $this->question_types(); |
| 25 | - $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
|
| 26 | - if ( is_admin() ) { |
|
| 25 | + $this->meta_fields = array('question_right_answer', 'question_wrong_answers'); |
|
| 26 | + if (is_admin()) { |
|
| 27 | 27 | // Custom Write Panel Columns |
| 28 | - add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
|
| 29 | - add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 ); |
|
| 30 | - add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 ); |
|
| 28 | + add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1); |
|
| 29 | + add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2); |
|
| 30 | + add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2); |
|
| 31 | 31 | |
| 32 | 32 | // Quesitno list table filters |
| 33 | - add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) ); |
|
| 34 | - add_filter( 'request', array( $this, 'filter_actions' ) ); |
|
| 33 | + add_action('restrict_manage_posts', array($this, 'filter_options')); |
|
| 34 | + add_filter('request', array($this, 'filter_actions')); |
|
| 35 | 35 | |
| 36 | - add_action( 'save_post', array( $this, 'save_question' ), 10, 1 ); |
|
| 36 | + add_action('save_post', array($this, 'save_question'), 10, 1); |
|
| 37 | 37 | } // End If Statement |
| 38 | 38 | } // End __construct() |
| 39 | 39 | |
| 40 | 40 | public function question_types() { |
| 41 | 41 | $types = array( |
| 42 | - 'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ), |
|
| 43 | - 'boolean' => __( 'True/False', 'woothemes-sensei' ), |
|
| 44 | - 'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ), |
|
| 45 | - 'single-line' => __( 'Single Line', 'woothemes-sensei' ), |
|
| 46 | - 'multi-line' => __( 'Multi Line', 'woothemes-sensei' ), |
|
| 47 | - 'file-upload' => __( 'File Upload', 'woothemes-sensei' ), |
|
| 42 | + 'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'), |
|
| 43 | + 'boolean' => __('True/False', 'woothemes-sensei'), |
|
| 44 | + 'gap-fill' => __('Gap Fill', 'woothemes-sensei'), |
|
| 45 | + 'single-line' => __('Single Line', 'woothemes-sensei'), |
|
| 46 | + 'multi-line' => __('Multi Line', 'woothemes-sensei'), |
|
| 47 | + 'file-upload' => __('File Upload', 'woothemes-sensei'), |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - return apply_filters( 'sensei_question_types', $types ); |
|
| 50 | + return apply_filters('sensei_question_types', $types); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @param array $defaults |
| 58 | 58 | * @return array $new_columns |
| 59 | 59 | */ |
| 60 | - public function add_column_headings ( $defaults ) { |
|
| 60 | + public function add_column_headings($defaults) { |
|
| 61 | 61 | $new_columns['cb'] = '<input type="checkbox" />'; |
| 62 | - $new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' ); |
|
| 63 | - $new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' ); |
|
| 64 | - $new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' ); |
|
| 65 | - if ( isset( $defaults['date'] ) ) { |
|
| 62 | + $new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei'); |
|
| 63 | + $new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei'); |
|
| 64 | + $new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei'); |
|
| 65 | + if (isset($defaults['date'])) { |
|
| 66 | 66 | $new_columns['date'] = $defaults['date']; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,27 +77,27 @@ discard block |
||
| 77 | 77 | * @param int $id |
| 78 | 78 | * @return void |
| 79 | 79 | */ |
| 80 | - public function add_column_data ( $column_name, $id ) { |
|
| 80 | + public function add_column_data($column_name, $id) { |
|
| 81 | 81 | global $wpdb, $post; |
| 82 | 82 | |
| 83 | - switch ( $column_name ) { |
|
| 83 | + switch ($column_name) { |
|
| 84 | 84 | |
| 85 | 85 | case 'id': |
| 86 | 86 | echo $id; |
| 87 | 87 | break; |
| 88 | 88 | |
| 89 | 89 | case 'question-type': |
| 90 | - $question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) ); |
|
| 90 | + $question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', '')); |
|
| 91 | 91 | $output = '—'; |
| 92 | - if( isset( $this->question_types[ $question_type ] ) ) { |
|
| 93 | - $output = $this->question_types[ $question_type ]; |
|
| 92 | + if (isset($this->question_types[$question_type])) { |
|
| 93 | + $output = $this->question_types[$question_type]; |
|
| 94 | 94 | } |
| 95 | 95 | echo $output; |
| 96 | 96 | break; |
| 97 | 97 | |
| 98 | 98 | case 'question-category': |
| 99 | - $output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) ); |
|
| 100 | - if( ! $output ) { |
|
| 99 | + $output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', '')); |
|
| 100 | + if ( ! $output) { |
|
| 101 | 101 | $output = '—'; |
| 102 | 102 | } |
| 103 | 103 | echo $output; |
@@ -110,49 +110,49 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | } // End add_column_data() |
| 112 | 112 | |
| 113 | - public function question_edit_panel_metabox( $post_type, $post ) { |
|
| 114 | - if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) { |
|
| 113 | + public function question_edit_panel_metabox($post_type, $post) { |
|
| 114 | + if (in_array($post_type, array('question', 'multiple_question'))) { |
|
| 115 | 115 | |
| 116 | - $metabox_title = __( 'Question', 'woothemes-sensei' ); |
|
| 116 | + $metabox_title = __('Question', 'woothemes-sensei'); |
|
| 117 | 117 | |
| 118 | - if( isset( $post->ID ) ) { |
|
| 118 | + if (isset($post->ID)) { |
|
| 119 | 119 | |
| 120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 120 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 121 | 121 | |
| 122 | - if( $question_type ) { |
|
| 123 | - $type = $this->question_types[ $question_type ]; |
|
| 124 | - if( $type ) { |
|
| 122 | + if ($question_type) { |
|
| 123 | + $type = $this->question_types[$question_type]; |
|
| 124 | + if ($type) { |
|
| 125 | 125 | $metabox_title = $type; |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | - add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' ); |
|
| 130 | - add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' ); |
|
| 131 | - add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' ); |
|
| 129 | + add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high'); |
|
| 130 | + add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default'); |
|
| 131 | + add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | public function question_edit_panel() { |
| 136 | 136 | global $post, $pagenow; |
| 137 | 137 | |
| 138 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) ); |
|
| 139 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) ); |
|
| 138 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts')); |
|
| 139 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles')); |
|
| 140 | 140 | |
| 141 | 141 | $html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">'; |
| 142 | 142 | |
| 143 | - if( 'post-new.php' == $pagenow ) { |
|
| 143 | + if ('post-new.php' == $pagenow) { |
|
| 144 | 144 | |
| 145 | 145 | $html .= '<div id="add-question-actions">'; |
| 146 | - $html .= Sensei()->lesson->quiz_panel_add( 'question' ); |
|
| 146 | + $html .= Sensei()->lesson->quiz_panel_add('question'); |
|
| 147 | 147 | $html .= '</div>'; |
| 148 | 148 | |
| 149 | 149 | } else { |
| 150 | 150 | $question_id = $post->ID; |
| 151 | 151 | |
| 152 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 152 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 153 | 153 | |
| 154 | 154 | $html .= '<div id="add-question-metadata"><table class="widefat">'; |
| 155 | - $html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' ); |
|
| 155 | + $html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question'); |
|
| 156 | 156 | $html .= '</table></div>'; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | public function question_lessons_panel() { |
| 165 | 165 | global $post; |
| 166 | 166 | |
| 167 | - $no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' ); |
|
| 167 | + $no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>'); |
|
| 168 | 168 | |
| 169 | - if( ! isset( $post->ID ) ) { |
|
| 169 | + if ( ! isset($post->ID)) { |
|
| 170 | 170 | echo $no_lessons; |
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // This retrieves those quizzes the question is directly connected to. |
| 175 | - $quizzes = get_post_meta( $post->ID, '_quiz_id', false ); |
|
| 175 | + $quizzes = get_post_meta($post->ID, '_quiz_id', false); |
|
| 176 | 176 | |
| 177 | 177 | // Collate all 'multiple_question' quizzes the question is part of. |
| 178 | - $categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) ); |
|
| 179 | - if ( ! empty( $categories_of_question ) ) { |
|
| 180 | - foreach ( $categories_of_question as $term_id ) { |
|
| 178 | + $categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids')); |
|
| 179 | + if ( ! empty($categories_of_question)) { |
|
| 180 | + foreach ($categories_of_question as $term_id) { |
|
| 181 | 181 | $qargs = array( |
| 182 | 182 | 'fields' => 'ids', |
| 183 | 183 | 'post_type' => 'multiple_question', |
@@ -191,41 +191,41 @@ discard block |
||
| 191 | 191 | 'post_status' => 'any', |
| 192 | 192 | 'suppress_filters' => 0, |
| 193 | 193 | ); |
| 194 | - $cat_question_ids = get_posts( $qargs ); |
|
| 195 | - foreach( $cat_question_ids as $cat_question_id ) { |
|
| 196 | - $cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false ); |
|
| 197 | - $quizzes = array_merge( $quizzes, $cat_quizzes ); |
|
| 194 | + $cat_question_ids = get_posts($qargs); |
|
| 195 | + foreach ($cat_question_ids as $cat_question_id) { |
|
| 196 | + $cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false); |
|
| 197 | + $quizzes = array_merge($quizzes, $cat_quizzes); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - $quizzes = array_unique( array_filter( $quizzes ) ); |
|
| 200 | + $quizzes = array_unique(array_filter($quizzes)); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if( 0 == count( $quizzes ) ) { |
|
| 203 | + if (0 == count($quizzes)) { |
|
| 204 | 204 | echo $no_lessons; |
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $lessons = false; |
| 209 | 209 | |
| 210 | - foreach( $quizzes as $quiz ) { |
|
| 210 | + foreach ($quizzes as $quiz) { |
|
| 211 | 211 | |
| 212 | - $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
|
| 212 | + $lesson_id = get_post_meta($quiz, '_quiz_lesson', true); |
|
| 213 | 213 | |
| 214 | - if( ! $lesson_id ) continue; |
|
| 214 | + if ( ! $lesson_id) continue; |
|
| 215 | 215 | |
| 216 | - $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
|
| 217 | - $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
|
| 216 | + $lessons[$lesson_id]['title'] = get_the_title($lesson_id); |
|
| 217 | + $lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if( ! $lessons ) { |
|
| 220 | + if ( ! $lessons) { |
|
| 221 | 221 | echo $no_lessons; |
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $html = '<ul>'; |
| 226 | 226 | |
| 227 | - foreach( $lessons as $id => $lesson ) { |
|
| 228 | - $html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>'; |
|
| 227 | + foreach ($lessons as $id => $lesson) { |
|
| 228 | + $html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>'; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $html .= '</ul>'; |
@@ -234,30 +234,30 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - public function save_question( $post_id = 0 ) { |
|
| 237 | + public function save_question($post_id = 0) { |
|
| 238 | 238 | |
| 239 | - if( ! isset( $_POST['post_type'] |
|
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 239 | + if ( ! isset($_POST['post_type'] |
|
| 240 | + ) || 'question' != $_POST['post_type']) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | //setup the data for saving |
| 247 | - $data = $_POST ; |
|
| 247 | + $data = $_POST; |
|
| 248 | 248 | $data['quiz_id'] = 0; |
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | - if ( ! wp_is_post_revision( $post_id ) ){ |
|
| 251 | + if ( ! wp_is_post_revision($post_id)) { |
|
| 252 | 252 | |
| 253 | 253 | // Unhook function to prevent infinite loops |
| 254 | - remove_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 254 | + remove_action('save_post', array($this, 'save_question')); |
|
| 255 | 255 | |
| 256 | 256 | // Update question data |
| 257 | - $question_id = Sensei()->lesson->lesson_save_question( $data, 'question' ); |
|
| 257 | + $question_id = Sensei()->lesson->lesson_save_question($data, 'question'); |
|
| 258 | 258 | |
| 259 | 259 | // Re-hook same function |
| 260 | - add_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 260 | + add_action('save_post', array($this, 'save_question')); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | return; |
@@ -270,15 +270,15 @@ discard block |
||
| 270 | 270 | public function filter_options() { |
| 271 | 271 | global $typenow; |
| 272 | 272 | |
| 273 | - if( is_admin() && 'question' == $typenow ) { |
|
| 273 | + if (is_admin() && 'question' == $typenow) { |
|
| 274 | 274 | |
| 275 | 275 | $output = ''; |
| 276 | 276 | |
| 277 | 277 | // Question type |
| 278 | - $selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 279 | - $type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>'; |
|
| 280 | - foreach( $this->question_types as $label => $type ) { |
|
| 281 | - $type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>'; |
|
| 278 | + $selected = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 279 | + $type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>'; |
|
| 280 | + foreach ($this->question_types as $label => $type) { |
|
| 281 | + $type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>'; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $output .= '<select name="question_type" id="dropdown_question_type">'; |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | $output .= '</select>'; |
| 287 | 287 | |
| 288 | 288 | // Question category |
| 289 | - $cats = get_terms( 'question-category', array( 'hide_empty' => false ) ); |
|
| 290 | - if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { |
|
| 291 | - $selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 292 | - $cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>'; |
|
| 293 | - foreach( $cats as $cat ) { |
|
| 294 | - $cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>'; |
|
| 289 | + $cats = get_terms('question-category', array('hide_empty' => false)); |
|
| 290 | + if ( ! empty($cats) && ! is_wp_error($cats)) { |
|
| 291 | + $selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 292 | + $cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>'; |
|
| 293 | + foreach ($cats as $cat) { |
|
| 294 | + $cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $output .= '<select name="question_cat" id="dropdown_question_cat">'; |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | * @param array $request Current request |
| 309 | 309 | * @return array Modified request |
| 310 | 310 | */ |
| 311 | - public function filter_actions( $request ) { |
|
| 311 | + public function filter_actions($request) { |
|
| 312 | 312 | global $typenow; |
| 313 | 313 | |
| 314 | - if( is_admin() && 'question' == $typenow ) { |
|
| 314 | + if (is_admin() && 'question' == $typenow) { |
|
| 315 | 315 | |
| 316 | 316 | // Question type |
| 317 | - $question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 318 | - if( $question_type ) { |
|
| 317 | + $question_type = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 318 | + if ($question_type) { |
|
| 319 | 319 | $type_query = array( |
| 320 | 320 | 'taxonomy' => 'question-type', |
| 321 | 321 | 'terms' => $question_type, |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Question category |
| 328 | - $question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 329 | - if( $question_cat ) { |
|
| 328 | + $question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 329 | + if ($question_cat) { |
|
| 330 | 330 | $cat_query = array( |
| 331 | 331 | 'taxonomy' => 'question-category', |
| 332 | 332 | 'terms' => $question_cat, |
@@ -351,16 +351,16 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return string $question_type | bool |
| 353 | 353 | */ |
| 354 | - public function get_question_type( $question_id ){ |
|
| 354 | + public function get_question_type($question_id) { |
|
| 355 | 355 | |
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 356 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 357 | + || 'question' != get_post_type($question_id)) { |
|
| 358 | 358 | return false; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | $question_type = 'multiple-choice'; |
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 362 | + $question_types = wp_get_post_terms($question_id, 'question-type'); |
|
| 363 | + foreach ($question_types as $type) { |
|
| 364 | 364 | $question_type = $type->slug; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -377,21 +377,21 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return int $question_grade | bool |
| 379 | 379 | */ |
| 380 | - public function get_question_grade( $question_id ) { |
|
| 380 | + public function get_question_grade($question_id) { |
|
| 381 | 381 | |
| 382 | - if ( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 383 | - || 'question' != get_post_type( $question_id ) ) { |
|
| 382 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 383 | + || 'question' != get_post_type($question_id)) { |
|
| 384 | 384 | return false; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $question_grade_raw = get_post_meta( $question_id, '_question_grade', true ); |
|
| 387 | + $question_grade_raw = get_post_meta($question_id, '_question_grade', true); |
|
| 388 | 388 | // If not set then default to 1... |
| 389 | - if ( false === $question_grade_raw || $question_grade_raw == '' ) { |
|
| 389 | + if (false === $question_grade_raw || $question_grade_raw == '') { |
|
| 390 | 390 | $question_grade = 1; |
| 391 | 391 | } |
| 392 | 392 | // ...but allow a grade of 0 for non-marked questions |
| 393 | 393 | else { |
| 394 | - $question_grade = intval( $question_grade_raw ); |
|
| 394 | + $question_grade = intval($question_grade_raw); |
|
| 395 | 395 | } |
| 396 | 396 | return $question_grade; |
| 397 | 397 | |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * @since 1.9.0 |
| 405 | 405 | * @param $question_type |
| 406 | 406 | */ |
| 407 | - public static function load_question_template( $question_type ){ |
|
| 407 | + public static function load_question_template($question_type) { |
|
| 408 | 408 | |
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 409 | + Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php'); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * @since 1.9.0 |
| 418 | 418 | * @param $question_id |
| 419 | 419 | */ |
| 420 | - public static function the_question_title( $question_id ){ |
|
| 420 | + public static function the_question_title($question_id) { |
|
| 421 | 421 | |
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 422 | + echo self::get_the_question_title($question_id); |
|
| 423 | 423 | |
| 424 | 424 | }// end the_question_title |
| 425 | 425 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @param $question_id |
| 432 | 432 | * @return string |
| 433 | 433 | */ |
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 434 | + public static function get_the_question_title($question_id) { |
|
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | 437 | * Filter the sensei question title |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @since 1.3.0 |
| 440 | 440 | * @param $question_title |
| 441 | 441 | */ |
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 442 | + $title = apply_filters('sensei_question_title', get_the_title($question_id)); |
|
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * hook document in class-woothemes-sensei-message.php the_title() |
| 446 | 446 | */ |
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 447 | + $title = apply_filters('sensei_single_title', $title, 'question'); |
|
| 448 | 448 | |
| 449 | 449 | $title_html = '<span class="question question-title">'; |
| 450 | 450 | $title_html .= $title; |
| 451 | 451 | $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
| 452 | - $title_html .='</span>'; |
|
| 452 | + $title_html .= '</span>'; |
|
| 453 | 453 | |
| 454 | 454 | return $title_html; |
| 455 | 455 | } |
@@ -460,14 +460,14 @@ discard block |
||
| 460 | 460 | * @param $question_id |
| 461 | 461 | * @return string |
| 462 | 462 | */ |
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 463 | + public static function get_the_question_description($question_id) { |
|
| 464 | 464 | |
| 465 | - $question = get_post( $question_id ); |
|
| 465 | + $question = get_post($question_id); |
|
| 466 | 466 | |
| 467 | 467 | /** |
| 468 | 468 | * Already documented within WordPress Core |
| 469 | 469 | */ |
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 470 | + return apply_filters('the_content', $question->post_content); |
|
| 471 | 471 | |
| 472 | 472 | } |
| 473 | 473 | |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | * @since 1.9.0 |
| 478 | 478 | * @param $question_id |
| 479 | 479 | */ |
| 480 | - public static function the_question_description( $question_id ){ |
|
| 480 | + public static function the_question_description($question_id) { |
|
| 481 | 481 | |
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 482 | + echo self::get_the_question_description($question_id); |
|
| 483 | 483 | |
| 484 | 484 | } |
| 485 | 485 | |
@@ -490,38 +490,38 @@ discard block |
||
| 490 | 490 | * @param $question_id |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 493 | + public static function get_the_question_media($question_id) { |
|
| 494 | 494 | |
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 495 | + $question_media = get_post_meta($question_id, '_question_media', true); |
|
| 496 | 496 | $question_media_link = ''; |
| 497 | - if( 0 < intval( $question_media ) ) { |
|
| 498 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | - if( $mimetype ) { |
|
| 500 | - $mimetype_array = explode( '/', $mimetype); |
|
| 501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 497 | + if (0 < intval($question_media)) { |
|
| 498 | + $mimetype = get_post_mime_type($question_media); |
|
| 499 | + if ($mimetype) { |
|
| 500 | + $mimetype_array = explode('/', $mimetype); |
|
| 501 | + if (isset($mimetype_array[0]) && $mimetype_array[0]) { |
|
| 502 | 502 | $question_media_type = $mimetype_array[0]; |
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 503 | + $question_media_url = wp_get_attachment_url($question_media); |
|
| 504 | + $attachment = get_post($question_media); |
|
| 505 | 505 | $question_media_title = $attachment->post_title; |
| 506 | 506 | $question_media_description = $attachment->post_content; |
| 507 | - switch( $question_media_type ) { |
|
| 507 | + switch ($question_media_type) { |
|
| 508 | 508 | case 'image': |
| 509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 509 | + $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id); |
|
| 510 | + $attachment_src = wp_get_attachment_image_src($question_media, $image_size); |
|
| 511 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>'; |
|
| 512 | 512 | break; |
| 513 | 513 | |
| 514 | 514 | case 'audio': |
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 515 | + $question_media_link = wp_audio_shortcode(array('src' => $question_media_url)); |
|
| 516 | 516 | break; |
| 517 | 517 | |
| 518 | 518 | case 'video': |
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 519 | + $question_media_link = wp_video_shortcode(array('src' => $question_media_url)); |
|
| 520 | 520 | break; |
| 521 | 521 | |
| 522 | 522 | default: |
| 523 | - $question_media_filename = basename( $question_media_url ); |
|
| 524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 523 | + $question_media_filename = basename($question_media_url); |
|
| 524 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>'; |
|
| 525 | 525 | break; |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -529,21 +529,21 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | $output = ''; |
| 532 | - if( $question_media_link ) { |
|
| 532 | + if ($question_media_link) { |
|
| 533 | 533 | |
| 534 | 534 | $output .= '<div class="question_media_display">'; |
| 535 | - $output .= $question_media_link; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | 536 | $output .= '<dl>'; |
| 537 | 537 | |
| 538 | - if( $question_media_title ) { |
|
| 538 | + if ($question_media_title) { |
|
| 539 | 539 | |
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 540 | + $output .= '<dt>'.$question_media_title.'</dt>'; |
|
| 541 | 541 | |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if( $question_media_description ) { |
|
| 544 | + if ($question_media_description) { |
|
| 545 | 545 | |
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 546 | + $output .= '<dd>'.$question_media_description.'</dd>'; |
|
| 547 | 547 | |
| 548 | 548 | } |
| 549 | 549 | |
@@ -564,9 +564,9 @@ discard block |
||
| 564 | 564 | * @since 1.9.0 |
| 565 | 565 | * @param string $question_id |
| 566 | 566 | */ |
| 567 | - public static function the_question_media( $question_id ){ |
|
| 567 | + public static function the_question_media($question_id) { |
|
| 568 | 568 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 569 | + echo self::get_the_question_media($question_id); |
|
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @param $question_id |
| 579 | 579 | */ |
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 580 | + public static function the_question_hidden_fields($question_id) { |
|
| 581 | 581 | ?> |
| 582 | 582 | |
| 583 | - <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
|
| 584 | - <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
| 583 | + <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" /> |
|
| 584 | + <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" /> |
|
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | 587 | } |
@@ -592,27 +592,27 @@ discard block |
||
| 592 | 592 | * @since 1.9.0 |
| 593 | 593 | * @param $question_id |
| 594 | 594 | */ |
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 595 | + public static function answer_feedback_notes($question_id) { |
|
| 596 | 596 | |
| 597 | 597 | //IDS |
| 598 | 598 | $quiz_id = get_the_ID(); |
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 600 | 600 | |
| 601 | 601 | // Data to check before showing feedback |
| 602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 602 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id()); |
|
| 603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 604 | + $not_empty_user_quiz_grade = ! empty($user_quiz_grade); |
|
| 605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 606 | + $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id); |
|
| 607 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 608 | 608 | |
| 609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 609 | + if (($lesson_completed && $not_empty_user_quiz_grade) |
|
| 610 | + || ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type) |
|
| 611 | + || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) { |
|
| 612 | 612 | |
| 613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id()); |
|
| 614 | 614 | |
| 615 | - if( $answer_notes ) { ?> |
|
| 615 | + if ($answer_notes) { ?> |
|
| 616 | 616 | |
| 617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
| 618 | 618 | |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param string $question_id |
| 627 | 627 | * @param string $lesson_id |
| 628 | 628 | */ |
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 629 | + echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id); |
|
| 630 | 630 | |
| 631 | 631 | ?> |
| 632 | 632 | |
@@ -645,72 +645,72 @@ discard block |
||
| 645 | 645 | * @since 1.9.0 |
| 646 | 646 | * @param string $question_id |
| 647 | 647 | */ |
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 648 | + public static function the_answer_result_indication($question_id) { |
|
| 649 | 649 | |
| 650 | - global $post, $current_user, $sensei_question_loop; |
|
| 650 | + global $post, $current_user, $sensei_question_loop; |
|
| 651 | 651 | |
| 652 | 652 | // Post Data |
| 653 | 653 | $quiz_id = $sensei_question_loop['quiz_id']; |
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 655 | 655 | $question_item = $sensei_question_loop['current_question']; |
| 656 | 656 | |
| 657 | 657 | // Setup variable needed to determine if the message should show and what it should show |
| 658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 659 | + $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id()); |
|
| 660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 661 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 662 | 662 | |
| 663 | 663 | // retrieve the question total grade |
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
| 665 | 665 | |
| 666 | 666 | // retrieve grade the user achieved |
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 668 | 668 | |
| 669 | 669 | // Question ID |
| 670 | 670 | $question_id = $question_item->ID; |
| 671 | 671 | |
| 672 | 672 | // conditions to check |
| 673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != ''; |
|
| 674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed; |
|
| 675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != ''; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 677 | + if ($completed_with_valid_grade |
|
| 678 | 678 | || $completed_with_valid_grade_and_reset_not_allowed |
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed) { |
|
| 680 | 680 | |
| 681 | 681 | $user_correct = false; |
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 682 | + $answer_message = __('Incorrect', 'woothemes-sensei'); |
|
| 683 | 683 | $answer_message_class = 'user_wrong'; |
| 684 | 684 | // For zero grade mark as 'correct' but add no classes |
| 685 | - if ( 0 == $question_grade ) { |
|
| 685 | + if (0 == $question_grade) { |
|
| 686 | 686 | |
| 687 | 687 | $user_correct = true; |
| 688 | 688 | $answer_message = ''; |
| 689 | 689 | $answer_message_class = ''; |
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if ($user_question_grade > 0) { |
|
| 692 | 692 | |
| 693 | 693 | $user_correct = true; |
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 694 | + $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade); |
|
| 695 | 695 | $answer_message_class = 'user_right'; |
| 696 | 696 | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // attach the correct answer if the question is auto gradable and user got it wrong |
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 700 | + if ( ! $reset_quiz_allowed && ! $user_correct) { |
|
| 701 | 701 | |
| 702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 702 | + $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID); |
|
| 703 | 703 | |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // answer feedback |
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID); |
|
| 708 | + if ($answer_notes) { |
|
| 709 | 709 | $answer_message_class .= ' has_notes'; |
| 710 | 710 | } |
| 711 | 711 | ?> |
| 712 | 712 | |
| 713 | - <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
|
| 713 | + <div class="answer_message <?php esc_attr_e($answer_message_class); ?>"> |
|
| 714 | 714 | |
| 715 | 715 | <span><?php echo $answer_message; ?></span> |
| 716 | 716 | |
@@ -731,39 +731,39 @@ discard block |
||
| 731 | 731 | * @param $quiz_id |
| 732 | 732 | * @return array $question_data |
| 733 | 733 | */ |
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 734 | + public static function get_template_data($question_id, $quiz_id) { |
|
| 735 | 735 | |
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 737 | 737 | |
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 738 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 739 | 739 | //backwards compatibility |
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 740 | + if ('on' == $reset_allowed) { |
|
| 741 | 741 | $reset_allowed = 1; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // Check again that the lesson is complete |
| 745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id()); |
|
| 746 | 746 | $user_lesson_complete = false; |
| 747 | - if ( $user_lesson_end ) { |
|
| 747 | + if ($user_lesson_end) { |
|
| 748 | 748 | $user_lesson_complete = true; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | //setup the question data |
| 752 | - $data[ 'ID' ] = $question_id; |
|
| 753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 752 | + $data['ID'] = $question_id; |
|
| 753 | + $data['title'] = get_the_title($question_id); |
|
| 754 | + $data['content'] = get_post($question_id)->post_content; |
|
| 755 | + $data['quiz_id'] = $quiz_id; |
|
| 756 | + $data['lesson_id'] = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 757 | + $data['type'] = Sensei()->question->get_question_type($question_id); |
|
| 758 | + $data['question_grade'] = Sensei()->question->get_question_grade($question_id); |
|
| 759 | + $data['user_question_grade'] = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 760 | + $data['question_right_answer'] = get_post_meta($question_id, '_question_right_answer', true); |
|
| 761 | + $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true); |
|
| 762 | + $data['user_answer_entry'] = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id()); |
|
| 763 | + $data['lesson_completed'] = Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( )); |
|
| 764 | + $data['quiz_grade_type'] = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 765 | + $data['reset_quiz_allowed'] = $reset_allowed; |
|
| 766 | + $data['lesson_complete'] = $user_lesson_complete; |
|
| 767 | 767 | |
| 768 | 768 | /** |
| 769 | 769 | * Filter the question template data. This filter fires in |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * @param string $question_id |
| 778 | 778 | * @param string $quiz_id |
| 779 | 779 | */ |
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 780 | + return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id); |
|
| 781 | 781 | |
| 782 | 782 | } |
| 783 | 783 | |
@@ -793,28 +793,28 @@ discard block |
||
| 793 | 793 | * |
| 794 | 794 | * @return array() |
| 795 | 795 | */ |
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 796 | + public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 797 | 797 | |
| 798 | 798 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 799 | + if ('file-upload' == Sensei()->question->get_question_type($question_id)) { |
|
| 800 | 800 | |
| 801 | 801 | // Get uploaded file |
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 802 | + $attachment_id = $question_data['user_answer_entry']; |
|
| 803 | 803 | $answer_media_url = $answer_media_filename = ''; |
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | $question_helptext = ''; |
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 807 | + if (isset($question_data['question_wrong_answers'][0])) { |
|
| 808 | 808 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 810 | 810 | |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 814 | + if (0 < intval($attachment_id)) { |
|
| 815 | 815 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 816 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
| 817 | + $answer_media_filename = basename($answer_media_url); |
|
| 818 | 818 | |
| 819 | 819 | } |
| 820 | 820 | |
@@ -822,11 +822,11 @@ discard block |
||
| 822 | 822 | // Get max upload file size, formatted for display |
| 823 | 823 | // Code copied from wp-admin/includes/media.php:1515 |
| 824 | 824 | $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
| 825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 825 | + $sizes = array('KB', 'MB', 'GB'); |
|
| 826 | + for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) { |
|
| 827 | 827 | $upload_size_unit /= 1024; |
| 828 | 828 | } |
| 829 | - if ( $u < 0 ) { |
|
| 829 | + if ($u < 0) { |
|
| 830 | 830 | |
| 831 | 831 | $upload_size_unit = 0; |
| 832 | 832 | $u = 0; |
@@ -836,14 +836,14 @@ discard block |
||
| 836 | 836 | $upload_size_unit = (int) $upload_size_unit; |
| 837 | 837 | |
| 838 | 838 | } |
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 839 | + $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u])); |
|
| 840 | 840 | |
| 841 | 841 | // Assemble all the data needed by the file upload template |
| 842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 842 | + $question_data['answer_media_url'] = $answer_media_url; |
|
| 843 | + $question_data['answer_media_filename'] = $answer_media_filename; |
|
| 844 | + $question_data['max_upload_size'] = $max_upload_size; |
|
| 845 | 845 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 846 | + $question_data['question_helptext'] = $question_helptext; |
|
| 847 | 847 | |
| 848 | 848 | }// end if is file upload type |
| 849 | 849 | |
@@ -863,27 +863,27 @@ discard block |
||
| 863 | 863 | * |
| 864 | 864 | * @return array() |
| 865 | 865 | */ |
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 866 | + public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 867 | 867 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 868 | + if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) { |
|
| 869 | 869 | |
| 870 | 870 | |
| 871 | 871 | $answer_type = 'radio'; |
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 872 | + if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) { |
|
| 873 | 873 | |
| 874 | 874 | $answer_type = 'checkbox'; |
| 875 | 875 | |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | // Merge right and wrong answers |
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 879 | + if (is_array($question_data['question_right_answer'])) { |
|
| 880 | 880 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 881 | + $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 882 | 882 | |
| 883 | - } else { |
|
| 883 | + } else { |
|
| 884 | 884 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 885 | + array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 886 | + $merged_options = $question_data['question_wrong_answers']; |
|
| 887 | 887 | |
| 888 | 888 | } |
| 889 | 889 | |
@@ -891,24 +891,24 @@ discard block |
||
| 891 | 891 | $question_answers_options = array(); |
| 892 | 892 | $count = 0; |
| 893 | 893 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 894 | + foreach ($merged_options as $answer) { |
|
| 895 | 895 | |
| 896 | 896 | $count++; |
| 897 | 897 | $question_option = array(); |
| 898 | 898 | |
| 899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 899 | + if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '') |
|
| 900 | + || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '') |
|
| 901 | + || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) { |
|
| 902 | 902 | |
| 903 | 903 | $user_correct = false; |
| 904 | 904 | |
| 905 | 905 | |
| 906 | 906 | // For zero grade mark as 'correct' but add no classes |
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 907 | + if (0 == $question_data['question_grade']) { |
|
| 908 | 908 | |
| 909 | 909 | $user_correct = true; |
| 910 | 910 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 911 | + } else if ($question_data['user_question_grade'] > 0) { |
|
| 912 | 912 | |
| 913 | 913 | $user_correct = true; |
| 914 | 914 | |
@@ -918,20 +918,20 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | // setup the option specific classes |
| 920 | 920 | $answer_class = ''; |
| 921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 921 | + if (isset($user_correct) && 0 < $question_data['question_grade']) { |
|
| 922 | + if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) { |
|
| 923 | 923 | |
| 924 | 924 | $answer_class .= ' right_answer'; |
| 925 | 925 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 926 | + } elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) { |
|
| 927 | 927 | |
| 928 | 928 | $answer_class .= ' right_answer'; |
| 929 | 929 | |
| 930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 930 | + } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) |
|
| 931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) { |
|
| 932 | 932 | |
| 933 | 933 | $answer_class = 'user_wrong'; |
| 934 | - if( $user_correct ) { |
|
| 934 | + if ($user_correct) { |
|
| 935 | 935 | |
| 936 | 936 | $answer_class = 'user_right'; |
| 937 | 937 | |
@@ -943,76 +943,76 @@ discard block |
||
| 943 | 943 | |
| 944 | 944 | // determine if the current option must be checked |
| 945 | 945 | $checked = ''; |
| 946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 946 | + if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) { |
|
| 947 | + if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) { |
|
| 948 | 948 | |
| 949 | 949 | $checked = 'checked="checked"'; |
| 950 | 950 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 951 | + } elseif ( ! is_array($question_data['user_answer_entry'])) { |
|
| 952 | 952 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 953 | + $checked = checked($answer, $question_data['user_answer_entry'], false); |
|
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | } // End If Statement |
| 958 | 958 | |
| 959 | 959 | //Load the answer option data |
| 960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | - $question_option[ 'answer' ] = $answer; |
|
| 962 | - $question_option[ 'option_class'] = $answer_class; |
|
| 963 | - $question_option[ 'checked'] = $checked; |
|
| 964 | - $question_option[ 'count' ] = $count; |
|
| 965 | - $question_option[ 'type' ] = $answer_type; |
|
| 960 | + $question_option['ID'] = Sensei()->lesson->get_answer_id($answer); |
|
| 961 | + $question_option['answer'] = $answer; |
|
| 962 | + $question_option['option_class'] = $answer_class; |
|
| 963 | + $question_option['checked'] = $checked; |
|
| 964 | + $question_option['count'] = $count; |
|
| 965 | + $question_option['type'] = $answer_type; |
|
| 966 | 966 | |
| 967 | 967 | // add the speci fic option to the list of options for this question |
| 968 | - $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
| 968 | + $question_answers_options[$question_option['ID']] = $question_option; |
|
| 969 | 969 | |
| 970 | 970 | } // end for each option |
| 971 | 971 | |
| 972 | 972 | |
| 973 | 973 | // Shuffle the array depending on the settings |
| 974 | 974 | $answer_options_sorted = array(); |
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 975 | + $random_order = get_post_meta($question_data['ID'], '_random_order', true); |
|
| 976 | + if ($random_order && $random_order == 'yes') { |
|
| 977 | 977 | |
| 978 | 978 | $answer_options_sorted = $question_answers_options; |
| 979 | - shuffle( $answer_options_sorted ); |
|
| 979 | + shuffle($answer_options_sorted); |
|
| 980 | 980 | |
| 981 | 981 | } else { |
| 982 | 982 | |
| 983 | 983 | $answer_order = array(); |
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 984 | + $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true); |
|
| 985 | + if ($answer_order_string) { |
|
| 986 | 986 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 987 | + $answer_order = array_filter(explode(',', $answer_order_string)); |
|
| 988 | + if (count($answer_order) > 0) { |
|
| 989 | 989 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 990 | + foreach ($answer_order as $answer_id) { |
|
| 991 | 991 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 992 | + if (isset($question_answers_options[$answer_id])) { |
|
| 993 | 993 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 994 | + $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id]; |
|
| 995 | + unset($question_answers_options[$answer_id]); |
|
| 996 | 996 | |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 1001 | + if (count($question_answers_options) > 0) { |
|
| 1002 | + foreach ($question_answers_options as $id => $answer) { |
|
| 1003 | 1003 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 1004 | + $answer_options_sorted[$id] = $answer; |
|
| 1005 | 1005 | |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - }else{ |
|
| 1009 | + } else { |
|
| 1010 | 1010 | |
| 1011 | 1011 | $answer_options_sorted = $question_answers_options; |
| 1012 | 1012 | |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - }else{ |
|
| 1015 | + } else { |
|
| 1016 | 1016 | |
| 1017 | 1017 | $answer_options_sorted = $question_answers_options; |
| 1018 | 1018 | |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | |
| 1023 | 1023 | |
| 1024 | 1024 | // assemble and setup the data for the templates data array |
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1025 | + $question_data['answer_options'] = $answer_options_sorted; |
|
| 1026 | 1026 | |
| 1027 | 1027 | } |
| 1028 | 1028 | |
@@ -1042,14 +1042,14 @@ discard block |
||
| 1042 | 1042 | * |
| 1043 | 1043 | * @return array() |
| 1044 | 1044 | */ |
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1045 | + public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 1046 | 1046 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1047 | + if ('gap-fill' == Sensei()->question->get_question_type($question_id)) { |
|
| 1048 | 1048 | |
| 1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1049 | + $gapfill_array = explode('||', $question_data['question_right_answer']); |
|
| 1050 | + $question_data['gapfill_pre'] = isset($gapfill_array[0]) ? $gapfill_array[0] : ''; |
|
| 1051 | + $question_data['gapfill_gap'] = isset($gapfill_array[1]) ? $gapfill_array[1] : ''; |
|
| 1052 | + $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : ''; |
|
| 1053 | 1053 | |
| 1054 | 1054 | } |
| 1055 | 1055 | |
@@ -1064,32 +1064,32 @@ discard block |
||
| 1064 | 1064 | * @param $question_id |
| 1065 | 1065 | * @return string $correct_answer or empty |
| 1066 | 1066 | */ |
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1067 | + public static function get_correct_answer($question_id) { |
|
| 1068 | 1068 | |
| 1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1069 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 1070 | + $type = Sensei()->question->get_question_type($question_id); |
|
| 1071 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 1072 | 1072 | $grade_type = 'manual-grade'; |
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean' == $type) { |
|
| 1075 | 1075 | |
| 1076 | 1076 | $right_answer = ucfirst($right_answer); |
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif ('multiple-choice' == $type) { |
|
| 1079 | 1079 | |
| 1080 | 1080 | $right_answer = (array) $right_answer; |
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1081 | + $right_answer = implode(', ', $right_answer); |
|
| 1082 | 1082 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1083 | + }elseif ('gap-fill' == $type) { |
|
| 1084 | 1084 | |
| 1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1085 | + $right_answer_array = explode('||', $right_answer); |
|
| 1086 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1089 | 1089 | |
| 1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1090 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
| 1091 | 1091 | |
| 1092 | - }else{ |
|
| 1092 | + } else { |
|
| 1093 | 1093 | |
| 1094 | 1094 | // for non auto gradable question types no answer should be returned. |
| 1095 | 1095 | $right_answer = ''; |
@@ -1107,4 +1107,4 @@ discard block |
||
| 1107 | 1107 | * @ignore only for backward compatibility |
| 1108 | 1108 | * @since 1.9.0 |
| 1109 | 1109 | */ |
| 1110 | -class WooThemes_Sensei_Question extends Sensei_Question{} |
|
| 1110 | +class WooThemes_Sensei_Question extends Sensei_Question {} |
|