@@ -299,7 +299,7 @@ |
||
| 299 | 299 | * @param integer $sender_id ID of sender |
| 300 | 300 | * @param integer $receiver_id ID of receiver |
| 301 | 301 | * @param string $message Message content |
| 302 | - * @param string $post_id ID of post related to message |
|
| 302 | + * @param integer $post_id ID of post related to message |
|
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure |
| 304 | 304 | */ |
| 305 | 305 | private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | // Monitor when new reply is posted |
| 37 | 37 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
| 38 | 38 | |
| 39 | - // Block WordPress from sending comment update emails for the messages post type |
|
| 40 | - add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 39 | + // Block WordPress from sending comment update emails for the messages post type |
|
| 40 | + add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 41 | 41 | |
| 42 | - // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 43 | - add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 42 | + // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 43 | + add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts |
| 46 | 46 | add_action( 'save_post', array( $this, 'save_message' ) ); |
@@ -48,20 +48,20 @@ discard block |
||
| 48 | 48 | // Add message links to courses & lessons |
| 49 | 49 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
| 50 | 50 | |
| 51 | - // add message link to lesson |
|
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 51 | + // add message link to lesson |
|
| 52 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 53 | 53 | |
| 54 | - // add message link to lesson |
|
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 54 | + // add message link to lesson |
|
| 55 | + add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 56 | 56 | |
| 57 | 57 | // Hide messages and replies from users who do not have access |
| 58 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 59 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 60 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 61 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 62 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 63 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 64 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 58 | + add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 59 | + add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 60 | + add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 61 | + add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 62 | + add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 63 | + add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 64 | + add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 65 | 65 | } // End __construct() |
| 66 | 66 | |
| 67 | 67 | public function add_menu_item() { |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | public function send_message_link( $post_id = 0, $user_id = 0 ) { |
| 163 | 163 | global $post; |
| 164 | 164 | |
| 165 | - // only show the link for the allowed post types: |
|
| 166 | - $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 165 | + // only show the link for the allowed post types: |
|
| 166 | + $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 167 | 167 | if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
| 168 | 168 | |
| 169 | 169 | return; |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | } elseif( 'course' == $post->post_type ) { |
| 187 | 187 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 188 | 188 | }else{ |
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 190 | - } |
|
| 189 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
| 193 | 193 | } |
@@ -212,19 +212,19 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | if( ! isset( $post->ID ) ) return $html; |
| 214 | 214 | |
| 215 | - //confirm private message |
|
| 216 | - $confirmation = ''; |
|
| 217 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 215 | + //confirm private message |
|
| 216 | + $confirmation = ''; |
|
| 217 | + if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 218 | 218 | |
| 219 | - $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 219 | + $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 220 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
| 225 | - $html .= '<p>'; |
|
| 226 | - $html .= $confirmation; |
|
| 227 | - $html .= '</p>'; |
|
| 225 | + $html .= '<p>'; |
|
| 226 | + $html .= $confirmation; |
|
| 227 | + $html .= '</p>'; |
|
| 228 | 228 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; |
| 229 | 229 | $html .= '<p class="form-row form-row-wide">'; |
| 230 | 230 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | public function message_reply_received( $comment_id = 0 ) { |
| 256 | 256 | |
| 257 | 257 | // Get comment object |
| 258 | - $comment = get_comment( $comment_id ); |
|
| 258 | + $comment = get_comment( $comment_id ); |
|
| 259 | 259 | |
| 260 | 260 | if( is_null( $comment ) ) return; |
| 261 | 261 | |
@@ -270,87 +270,87 @@ discard block |
||
| 270 | 270 | do_action( 'sensei_private_message_reply', $comment, $message ); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * This function stops WordPress from sending the default comment update emails. |
|
| 275 | - * |
|
| 276 | - * This function is hooked into comment_notification_recipients. It will simply return |
|
| 277 | - * an empty array if the current passed in comment is on a message post type. |
|
| 278 | - * |
|
| 279 | - * @param array $emails |
|
| 280 | - * @param int $comment_id |
|
| 281 | - * @return array; |
|
| 282 | - */ |
|
| 283 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 273 | + /** |
|
| 274 | + * This function stops WordPress from sending the default comment update emails. |
|
| 275 | + * |
|
| 276 | + * This function is hooked into comment_notification_recipients. It will simply return |
|
| 277 | + * an empty array if the current passed in comment is on a message post type. |
|
| 278 | + * |
|
| 279 | + * @param array $emails |
|
| 280 | + * @param int $comment_id |
|
| 281 | + * @return array; |
|
| 282 | + */ |
|
| 283 | + public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 284 | 284 | |
| 285 | - $comment = get_comment( $comment_id ); |
|
| 286 | - if( isset( $comment->comment_post_ID ) && |
|
| 287 | - 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 285 | + $comment = get_comment( $comment_id ); |
|
| 286 | + if( isset( $comment->comment_post_ID ) && |
|
| 287 | + 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 288 | 288 | |
| 289 | - // empty the emails array to ensure no emails are sent for this comment |
|
| 290 | - $emails = array(); |
|
| 289 | + // empty the emails array to ensure no emails are sent for this comment |
|
| 290 | + $emails = array(); |
|
| 291 | 291 | |
| 292 | - } |
|
| 293 | - return $emails; |
|
| 292 | + } |
|
| 293 | + return $emails; |
|
| 294 | 294 | |
| 295 | - }// end stop_wp_comment_emails |
|
| 295 | + }// end stop_wp_comment_emails |
|
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | - * Save new message post |
|
| 299 | - * @param integer $sender_id ID of sender |
|
| 300 | - * @param integer $receiver_id ID of receiver |
|
| 301 | - * @param string $message Message content |
|
| 302 | - * @param string $post_id ID of post related to message |
|
| 303 | - * @return mixed Message ID on success, boolean false on failure |
|
| 304 | - */ |
|
| 305 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 298 | + * Save new message post |
|
| 299 | + * @param integer $sender_id ID of sender |
|
| 300 | + * @param integer $receiver_id ID of receiver |
|
| 301 | + * @param string $message Message content |
|
| 302 | + * @param string $post_id ID of post related to message |
|
| 303 | + * @return mixed Message ID on success, boolean false on failure |
|
| 304 | + */ |
|
| 305 | + private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 306 | 306 | |
| 307 | - $message_id = false; |
|
| 307 | + $message_id = false; |
|
| 308 | 308 | |
| 309 | - if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 309 | + if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 310 | 310 | |
| 311 | - $title = wp_trim_words( $message, 8, '...' ); |
|
| 311 | + $title = wp_trim_words( $message, 8, '...' ); |
|
| 312 | 312 | |
| 313 | - // Set up post data for message |
|
| 314 | - $message_data = array( |
|
| 315 | - 'post_type' => $this->post_type, |
|
| 316 | - 'post_title' => esc_html( $title ), |
|
| 317 | - 'post_content' => esc_html( $message ), |
|
| 318 | - 'post_status' => 'publish', |
|
| 319 | - 'ping_status' => 'closed', |
|
| 320 | - 'comment_status' => 'open', |
|
| 321 | - 'post_excerpt' => '', |
|
| 322 | - 'post_author' => intval( $sender_id ) |
|
| 323 | - ); |
|
| 313 | + // Set up post data for message |
|
| 314 | + $message_data = array( |
|
| 315 | + 'post_type' => $this->post_type, |
|
| 316 | + 'post_title' => esc_html( $title ), |
|
| 317 | + 'post_content' => esc_html( $message ), |
|
| 318 | + 'post_status' => 'publish', |
|
| 319 | + 'ping_status' => 'closed', |
|
| 320 | + 'comment_status' => 'open', |
|
| 321 | + 'post_excerpt' => '', |
|
| 322 | + 'post_author' => intval( $sender_id ) |
|
| 323 | + ); |
|
| 324 | 324 | |
| 325 | - // Insert post |
|
| 326 | - $message_id = wp_insert_post( $message_data ); |
|
| 325 | + // Insert post |
|
| 326 | + $message_id = wp_insert_post( $message_data ); |
|
| 327 | 327 | |
| 328 | - if( ! is_wp_error( $message_id ) ) { |
|
| 328 | + if( ! is_wp_error( $message_id ) ) { |
|
| 329 | 329 | |
| 330 | - // Add sender to message meta |
|
| 331 | - $sender = get_userdata( $sender_id ); |
|
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 330 | + // Add sender to message meta |
|
| 331 | + $sender = get_userdata( $sender_id ); |
|
| 332 | + add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 333 | 333 | |
| 334 | - // Add receiver to message meta |
|
| 335 | - $receiver = get_userdata( $receiver_id ); |
|
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 334 | + // Add receiver to message meta |
|
| 335 | + $receiver = get_userdata( $receiver_id ); |
|
| 336 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 337 | 337 | |
| 338 | - // Add lesson/course ID to message meta |
|
| 339 | - $post = get_post( $post_id ); |
|
| 340 | - add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 341 | - add_post_meta( $message_id, '_post', $post->ID ); |
|
| 338 | + // Add lesson/course ID to message meta |
|
| 339 | + $post = get_post( $post_id ); |
|
| 340 | + add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 341 | + add_post_meta( $message_id, '_post', $post->ID ); |
|
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 343 | + do_action( 'sensei_new_private_message', $message_id ); |
|
| 344 | 344 | |
| 345 | - } else { |
|
| 345 | + } else { |
|
| 346 | 346 | |
| 347 | - $message_id = false; |
|
| 347 | + $message_id = false; |
|
| 348 | 348 | |
| 349 | - } |
|
| 350 | - } |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - return $message_id; |
|
| 353 | - } |
|
| 352 | + return $message_id; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * Check if user has access to view this message |
@@ -389,56 +389,56 @@ discard block |
||
| 389 | 389 | remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - /** |
|
| 393 | - * Function message_login() |
|
| 394 | - * |
|
| 395 | - * Only show /messages/* to logged in users, and |
|
| 396 | - * redirect logged out users to wp-login.php |
|
| 397 | - * |
|
| 398 | - * @since 1.9.0 |
|
| 399 | - * @param none |
|
| 400 | - * @return void |
|
| 401 | - */ |
|
| 392 | + /** |
|
| 393 | + * Function message_login() |
|
| 394 | + * |
|
| 395 | + * Only show /messages/* to logged in users, and |
|
| 396 | + * redirect logged out users to wp-login.php |
|
| 397 | + * |
|
| 398 | + * @since 1.9.0 |
|
| 399 | + * @param none |
|
| 400 | + * @return void |
|
| 401 | + */ |
|
| 402 | 402 | |
| 403 | - public function message_login () { |
|
| 403 | + public function message_login () { |
|
| 404 | 404 | |
| 405 | - if ( is_user_logged_in() ) { |
|
| 405 | + if ( is_user_logged_in() ) { |
|
| 406 | 406 | |
| 407 | - return; |
|
| 408 | - } |
|
| 407 | + return; |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - $settings = Sensei()->settings->get_settings(); |
|
| 411 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 412 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 410 | + $settings = Sensei()->settings->get_settings(); |
|
| 411 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 412 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 413 | 413 | |
| 414 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 414 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 415 | 415 | |
| 416 | - $my_courses_url = get_permalink($my_courses_page_id); |
|
| 416 | + $my_courses_url = get_permalink($my_courses_page_id); |
|
| 417 | 417 | |
| 418 | - } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - if ( is_single() && is_singular( $this->post_type ) |
|
| 421 | - || is_post_type_archive( $this->post_type ) ) { |
|
| 420 | + if ( is_single() && is_singular( $this->post_type ) |
|
| 421 | + || is_post_type_archive( $this->post_type ) ) { |
|
| 422 | 422 | |
| 423 | - if ( isset($my_courses_url) ) { |
|
| 423 | + if ( isset($my_courses_url) ) { |
|
| 424 | 424 | |
| 425 | - wp_redirect($my_courses_url, 303); |
|
| 426 | - exit; |
|
| 427 | - } |
|
| 425 | + wp_redirect($my_courses_url, 303); |
|
| 426 | + exit; |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - else { |
|
| 429 | + else { |
|
| 430 | 430 | |
| 431 | - wp_redirect(home_url('/wp-login.php'), 303); |
|
| 432 | - exit; |
|
| 433 | - } |
|
| 431 | + wp_redirect(home_url('/wp-login.php'), 303); |
|
| 432 | + exit; |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | - } |
|
| 436 | - } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | 437 | /** |
| 438 | - * Only show allowed messages in messages archive |
|
| 439 | - * @param array $query Original query |
|
| 440 | - * @return void |
|
| 441 | - */ |
|
| 438 | + * Only show allowed messages in messages archive |
|
| 439 | + * @param array $query Original query |
|
| 440 | + * @return void |
|
| 441 | + */ |
|
| 442 | 442 | public function message_list( $query ) { |
| 443 | 443 | global $current_user; |
| 444 | 444 | |
@@ -555,17 +555,17 @@ discard block |
||
| 555 | 555 | return $open; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - /** |
|
| 559 | - * Print outthe message was sent by $sender_username on the |
|
| 560 | - * |
|
| 561 | - * @since 1.9.0 |
|
| 562 | - */ |
|
| 563 | - public static function the_message_sent_by_title(){ |
|
| 558 | + /** |
|
| 559 | + * Print outthe message was sent by $sender_username on the |
|
| 560 | + * |
|
| 561 | + * @since 1.9.0 |
|
| 562 | + */ |
|
| 563 | + public static function the_message_sent_by_title(){ |
|
| 564 | 564 | |
| 565 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 566 | - if( $sender_username ) { |
|
| 565 | + $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 566 | + if( $sender_username ) { |
|
| 567 | 567 | |
| 568 | - $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 568 | + $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 569 | 569 | |
| 570 | 570 | <p class="message-meta"> |
| 571 | 571 | <small> |
@@ -577,41 +577,41 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | <?php } |
| 579 | 579 | |
| 580 | - } |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * sensei_single_title output for single page title |
|
| 584 | - * @since 1.1.0 |
|
| 585 | - * @return void |
|
| 586 | - * @deprecate |
|
| 587 | - */ |
|
| 588 | - public static function the_title() { |
|
| 582 | + /** |
|
| 583 | + * sensei_single_title output for single page title |
|
| 584 | + * @since 1.1.0 |
|
| 585 | + * @return void |
|
| 586 | + * @deprecate |
|
| 587 | + */ |
|
| 588 | + public static function the_title() { |
|
| 589 | 589 | |
| 590 | - global $post; |
|
| 590 | + global $post; |
|
| 591 | 591 | |
| 592 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 593 | - if( $content_post_id ) { |
|
| 594 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 595 | - } else { |
|
| 596 | - $title = get_the_title( $post->ID ); |
|
| 597 | - } |
|
| 592 | + $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 593 | + if( $content_post_id ) { |
|
| 594 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 595 | + } else { |
|
| 596 | + $title = get_the_title( $post->ID ); |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | - ?> |
|
| 599 | + ?> |
|
| 600 | 600 | <header> |
| 601 | 601 | |
| 602 | 602 | <h1> |
| 603 | 603 | |
| 604 | 604 | <?php |
| 605 | - /** |
|
| 606 | - * Filter Sensei single title |
|
| 607 | - * |
|
| 608 | - * @since 1.8.0 |
|
| 609 | - * @param string $title |
|
| 610 | - * @param string $template |
|
| 611 | - * @param string $post_type |
|
| 612 | - */ |
|
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 614 | - ?> |
|
| 605 | + /** |
|
| 606 | + * Filter Sensei single title |
|
| 607 | + * |
|
| 608 | + * @since 1.8.0 |
|
| 609 | + * @param string $title |
|
| 610 | + * @param string $template |
|
| 611 | + * @param string $post_type |
|
| 612 | + */ |
|
| 613 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 614 | + ?> |
|
| 615 | 615 | |
| 616 | 616 | </h1> |
| 617 | 617 | |
@@ -619,52 +619,52 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | <?php |
| 621 | 621 | |
| 622 | - } // End sensei_single_title() |
|
| 622 | + } // End sensei_single_title() |
|
| 623 | 623 | |
| 624 | - /** |
|
| 625 | - * Generates the my messages |
|
| 626 | - * archive header. |
|
| 627 | - * |
|
| 628 | - * @since 1.9.0 |
|
| 629 | - * |
|
| 630 | - * @return string |
|
| 631 | - */ |
|
| 632 | - public static function the_archive_header( ){ |
|
| 624 | + /** |
|
| 625 | + * Generates the my messages |
|
| 626 | + * archive header. |
|
| 627 | + * |
|
| 628 | + * @since 1.9.0 |
|
| 629 | + * |
|
| 630 | + * @return string |
|
| 631 | + */ |
|
| 632 | + public static function the_archive_header( ){ |
|
| 633 | 633 | |
| 634 | - $html = ''; |
|
| 635 | - $html .= '<header class="archive-header"><h1>'; |
|
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 637 | - $html .= '</h1></header>'; |
|
| 634 | + $html = ''; |
|
| 635 | + $html .= '<header class="archive-header"><h1>'; |
|
| 636 | + $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 637 | + $html .= '</h1></header>'; |
|
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Filter the sensei messages archive title. |
|
| 641 | - * @since 1.0.0 |
|
| 642 | - */ |
|
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 639 | + /** |
|
| 640 | + * Filter the sensei messages archive title. |
|
| 641 | + * @since 1.0.0 |
|
| 642 | + */ |
|
| 643 | + echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 644 | 644 | |
| 645 | - } // get_archive_header() |
|
| 645 | + } // get_archive_header() |
|
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Output the title for a message given the post_id. |
|
| 649 | - * |
|
| 650 | - * @since 1.9.0 |
|
| 651 | - * @param $post_id |
|
| 652 | - */ |
|
| 653 | - public static function the_message_title( $message_post_id ){ |
|
| 647 | + /** |
|
| 648 | + * Output the title for a message given the post_id. |
|
| 649 | + * |
|
| 650 | + * @since 1.9.0 |
|
| 651 | + * @param $post_id |
|
| 652 | + */ |
|
| 653 | + public static function the_message_title( $message_post_id ){ |
|
| 654 | 654 | |
| 655 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 655 | + $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 656 | 656 | |
| 657 | - if( $content_post_id ) { |
|
| 657 | + if( $content_post_id ) { |
|
| 658 | 658 | |
| 659 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 659 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 660 | 660 | |
| 661 | - } else { |
|
| 661 | + } else { |
|
| 662 | 662 | |
| 663 | - $title = get_the_title( $message_post_id ); |
|
| 663 | + $title = get_the_title( $message_post_id ); |
|
| 664 | 664 | |
| 665 | - } |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | - ?> |
|
| 667 | + ?> |
|
| 668 | 668 | <h2> |
| 669 | 669 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
| 670 | 670 | <?php echo $title; ?> |
@@ -673,21 +673,21 @@ discard block |
||
| 673 | 673 | </h2> |
| 674 | 674 | |
| 675 | 675 | <?php |
| 676 | - } //end the_message_header |
|
| 676 | + } //end the_message_header |
|
| 677 | 677 | |
| 678 | - /** |
|
| 679 | - * Output the message sender given the post id. |
|
| 680 | - * |
|
| 681 | - * @param $message_post_id |
|
| 682 | - */ |
|
| 683 | - public static function the_message_sender( $message_post_id ){ |
|
| 678 | + /** |
|
| 679 | + * Output the message sender given the post id. |
|
| 680 | + * |
|
| 681 | + * @param $message_post_id |
|
| 682 | + */ |
|
| 683 | + public static function the_message_sender( $message_post_id ){ |
|
| 684 | 684 | |
| 685 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 686 | - $sender = get_user_by( 'login', $sender_username ); |
|
| 685 | + $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 686 | + $sender = get_user_by( 'login', $sender_username ); |
|
| 687 | 687 | |
| 688 | - if( $sender_username && $sender instanceof WP_User ) { |
|
| 689 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 690 | - ?> |
|
| 688 | + if( $sender_username && $sender instanceof WP_User ) { |
|
| 689 | + $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 690 | + ?> |
|
| 691 | 691 | <p class="message-meta"> |
| 692 | 692 | <small> |
| 693 | 693 | <em> <?php echo $sender_display_name; ?> </em> |
@@ -695,18 +695,18 @@ discard block |
||
| 695 | 695 | </p> |
| 696 | 696 | |
| 697 | 697 | <?php |
| 698 | - } // end if |
|
| 699 | - |
|
| 700 | - } // end the_message_archive_sender |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Link to the users my messages page |
|
| 704 | - * |
|
| 705 | - * @since 1.9.0 |
|
| 706 | - */ |
|
| 707 | - public static function the_my_messages_link(){ |
|
| 708 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 709 | - ?> |
|
| 698 | + } // end if |
|
| 699 | + |
|
| 700 | + } // end the_message_archive_sender |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Link to the users my messages page |
|
| 704 | + * |
|
| 705 | + * @since 1.9.0 |
|
| 706 | + */ |
|
| 707 | + public static function the_my_messages_link(){ |
|
| 708 | + if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 709 | + ?> |
|
| 710 | 710 | <p class="my-messages-link-container"> |
| 711 | 711 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
| 712 | 712 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
@@ -714,8 +714,8 @@ discard block |
||
| 714 | 714 | </a> |
| 715 | 715 | </p> |
| 716 | 716 | <?php |
| 717 | - } |
|
| 718 | - } |
|
| 717 | + } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | } // End Class |
| 721 | 721 | |
@@ -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 Messages Class |
@@ -21,61 +21,61 @@ discard block |
||
| 21 | 21 | * Constructor. |
| 22 | 22 | * @since 1.6.0 |
| 23 | 23 | */ |
| 24 | - public function __construct () { |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | $this->post_type = 'sensei_message'; |
| 26 | - $this->meta_fields = array( 'sender', 'receiver' ); |
|
| 26 | + $this->meta_fields = array('sender', 'receiver'); |
|
| 27 | 27 | |
| 28 | 28 | // Add Messages page to admin menu |
| 29 | - add_action( 'admin_menu', array( $this, 'add_menu_item' ), 40 ); |
|
| 30 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10, 2 ); |
|
| 31 | - add_action( 'admin_menu', array( $this, 'remove_meta_box' ) ); |
|
| 29 | + add_action('admin_menu', array($this, 'add_menu_item'), 40); |
|
| 30 | + add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 2); |
|
| 31 | + add_action('admin_menu', array($this, 'remove_meta_box')); |
|
| 32 | 32 | |
| 33 | 33 | // Save new private message |
| 34 | - add_action( 'init', array( $this, 'save_new_message' ), 1 ); |
|
| 34 | + add_action('init', array($this, 'save_new_message'), 1); |
|
| 35 | 35 | |
| 36 | 36 | // Monitor when new reply is posted |
| 37 | - add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
|
| 37 | + add_action('comment_post', array($this, 'message_reply_received'), 10, 1); |
|
| 38 | 38 | |
| 39 | 39 | // Block WordPress from sending comment update emails for the messages post type |
| 40 | - add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 40 | + add_filter('comment_notification_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); |
|
| 41 | 41 | |
| 42 | 42 | // Block WordPress from sending comment moderator emails on the sensei messages post types |
| 43 | - add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 43 | + add_filter('comment_moderation_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); |
|
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts |
| 46 | - add_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 46 | + add_action('save_post', array($this, 'save_message')); |
|
| 47 | 47 | |
| 48 | 48 | // Add message links to courses & lessons |
| 49 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
|
| 49 | + add_action('sensei_single_course_content_inside_before', array($this, 'send_message_link'), 35); |
|
| 50 | 50 | |
| 51 | 51 | // add message link to lesson |
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 52 | + add_action('sensei_single_lesson_content_inside_before', array($this, 'send_message_link'), 30, 2); |
|
| 53 | 53 | |
| 54 | 54 | // add message link to lesson |
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 55 | + add_action('sensei_single_quiz_questions_before', array($this, 'send_message_link'), 10, 2); |
|
| 56 | 56 | |
| 57 | 57 | // Hide messages and replies from users who do not have access |
| 58 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 59 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 60 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 61 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 62 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 63 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 64 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 58 | + add_action('template_redirect', array($this, 'message_login'), 10, 1); |
|
| 59 | + add_action('pre_get_posts', array($this, 'message_list'), 10, 1); |
|
| 60 | + add_filter('the_title', array($this, 'message_title'), 10, 2); |
|
| 61 | + add_filter('the_content', array($this, 'message_content'), 10, 1); |
|
| 62 | + add_filter('comments_array', array($this, 'message_replies'), 100, 1); |
|
| 63 | + add_filter('get_comments_number', array($this, 'message_reply_count'), 100, 2); |
|
| 64 | + add_filter('comments_open', array($this, 'message_replies_open'), 100, 2); |
|
| 65 | 65 | } // End __construct() |
| 66 | 66 | |
| 67 | 67 | public function add_menu_item() { |
| 68 | 68 | |
| 69 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 70 | - add_submenu_page( 'sensei', __( 'Messages', 'woothemes-sensei'), __( 'Messages', 'woothemes-sensei') , 'edit_courses', 'edit.php?post_type=sensei_message' ); |
|
| 69 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 70 | + add_submenu_page('sensei', __('Messages', 'woothemes-sensei'), __('Messages', 'woothemes-sensei'), 'edit_courses', 'edit.php?post_type=sensei_message'); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public function add_meta_box( $post_type, $post ) { |
|
| 74 | + public function add_meta_box($post_type, $post) { |
|
| 75 | 75 | |
| 76 | - if( ! $post_type == $this->post_type ) return; |
|
| 76 | + if ( ! $post_type == $this->post_type) return; |
|
| 77 | 77 | |
| 78 | - add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); |
|
| 78 | + add_meta_box($this->post_type.'-data', __('Message Information', 'woothemes-sensei'), array($this, 'meta_box_content'), $this->post_type, 'normal', 'default'); |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -85,25 +85,25 @@ discard block |
||
| 85 | 85 | $settings = array( |
| 86 | 86 | array( |
| 87 | 87 | 'id' => 'sender', |
| 88 | - 'label' => __( 'Message sent by:', 'woothemes-sensei' ), |
|
| 89 | - 'description' => __( 'The username of the learner who sent this message.', 'woothemes-sensei' ), |
|
| 88 | + 'label' => __('Message sent by:', 'woothemes-sensei'), |
|
| 89 | + 'description' => __('The username of the learner who sent this message.', 'woothemes-sensei'), |
|
| 90 | 90 | 'type' => 'text', |
| 91 | 91 | 'default' => '', |
| 92 | - 'placeholder' => __( 'Learner username', 'woothemes-sensei' ), |
|
| 92 | + 'placeholder' => __('Learner username', 'woothemes-sensei'), |
|
| 93 | 93 | ), |
| 94 | 94 | array( |
| 95 | 95 | 'id' => 'receiver', |
| 96 | - 'label' => __( 'Message received by:', 'woothemes-sensei' ), |
|
| 97 | - 'description' => __( 'The username of the teacher who received this message.', 'woothemes-sensei' ), |
|
| 96 | + 'label' => __('Message received by:', 'woothemes-sensei'), |
|
| 97 | + 'description' => __('The username of the teacher who received this message.', 'woothemes-sensei'), |
|
| 98 | 98 | 'type' => 'text', |
| 99 | 99 | 'default' => '', |
| 100 | - 'placeholder' => __( 'Teacher username', 'woothemes-sensei' ), |
|
| 100 | + 'placeholder' => __('Teacher username', 'woothemes-sensei'), |
|
| 101 | 101 | ), |
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - $message_posttype = get_post_meta( $post->ID, '_posttype', true ); |
|
| 104 | + $message_posttype = get_post_meta($post->ID, '_posttype', true); |
|
| 105 | 105 | |
| 106 | - if( isset( $message_posttype ) && $message_posttype ) { |
|
| 106 | + if (isset($message_posttype) && $message_posttype) { |
|
| 107 | 107 | |
| 108 | 108 | $args = array( |
| 109 | 109 | 'post_type' => $message_posttype, |
@@ -113,58 +113,58 @@ discard block |
||
| 113 | 113 | 'post_status' => 'publish', |
| 114 | 114 | ); |
| 115 | 115 | |
| 116 | - $posts = get_posts( $args ); |
|
| 116 | + $posts = get_posts($args); |
|
| 117 | 117 | |
| 118 | - $post_options[0] = sprintf( __( 'Select %1$s', 'woothemes-sensei' ), $message_posttype ); |
|
| 119 | - foreach( $posts as $post_item ) { |
|
| 120 | - $post_options[ $post_item->ID ] = $post_item->post_title; |
|
| 118 | + $post_options[0] = sprintf(__('Select %1$s', 'woothemes-sensei'), $message_posttype); |
|
| 119 | + foreach ($posts as $post_item) { |
|
| 120 | + $post_options[$post_item->ID] = $post_item->post_title; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $settings[] = array( |
| 124 | 124 | 'id' => 'post', |
| 125 | - 'label' => sprintf( __( 'Message from %1$s:', 'woothemes-sensei' ), $message_posttype ), |
|
| 126 | - 'description' => sprintf( __( 'The %1$s to which this message relates.', 'woothemes-sensei' ), $message_posttype ), |
|
| 125 | + 'label' => sprintf(__('Message from %1$s:', 'woothemes-sensei'), $message_posttype), |
|
| 126 | + 'description' => sprintf(__('The %1$s to which this message relates.', 'woothemes-sensei'), $message_posttype), |
|
| 127 | 127 | 'type' => 'select', |
| 128 | 128 | 'default' => 0, |
| 129 | 129 | 'options' => $post_options, |
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $html = Sensei()->admin->render_settings( $settings, $post->ID, 'message-info' ); |
|
| 133 | + $html = Sensei()->admin->render_settings($settings, $post->ID, 'message-info'); |
|
| 134 | 134 | |
| 135 | 135 | echo $html; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function save_message( $post_id = 0 ) { |
|
| 138 | + public function save_message($post_id = 0) { |
|
| 139 | 139 | global $post; |
| 140 | 140 | |
| 141 | - if( $this->post_type != get_post_type() ) return; |
|
| 141 | + if ($this->post_type != get_post_type()) return; |
|
| 142 | 142 | |
| 143 | - if( isset( $_POST['sender'] ) && $_POST['sender'] ) { |
|
| 144 | - update_post_meta( $post_id, '_sender', $_POST['sender'] ); |
|
| 143 | + if (isset($_POST['sender']) && $_POST['sender']) { |
|
| 144 | + update_post_meta($post_id, '_sender', $_POST['sender']); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if( isset( $_POST['receiver'] ) && $_POST['receiver'] ) { |
|
| 148 | - update_post_meta( $post_id, '_receiver', $_POST['receiver'] ); |
|
| 147 | + if (isset($_POST['receiver']) && $_POST['receiver']) { |
|
| 148 | + update_post_meta($post_id, '_receiver', $_POST['receiver']); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if( isset( $_POST['post'] ) && $_POST['post'] ) { |
|
| 152 | - update_post_meta( $post_id, '_post', $_POST['post'] ); |
|
| 151 | + if (isset($_POST['post']) && $_POST['post']) { |
|
| 152 | + update_post_meta($post_id, '_post', $_POST['post']); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - remove_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 155 | + remove_action('save_post', array($this, 'save_message')); |
|
| 156 | 156 | |
| 157 | - wp_update_post( array( 'ID' => $post_id, 'comment_status' => 'open' ) ); |
|
| 157 | + wp_update_post(array('ID' => $post_id, 'comment_status' => 'open')); |
|
| 158 | 158 | |
| 159 | - add_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 159 | + add_action('save_post', array($this, 'save_message')); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public function send_message_link( $post_id = 0, $user_id = 0 ) { |
|
| 162 | + public function send_message_link($post_id = 0, $user_id = 0) { |
|
| 163 | 163 | global $post; |
| 164 | 164 | |
| 165 | 165 | // only show the link for the allowed post types: |
| 166 | 166 | $allowed_post_types = array('lesson', 'course', 'quiz'); |
| 167 | - if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
|
| 167 | + if ( ! in_array(get_post_type(), $allowed_post_types)) { |
|
| 168 | 168 | |
| 169 | 169 | return; |
| 170 | 170 | |
@@ -172,28 +172,28 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $html = ''; |
| 174 | 174 | |
| 175 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 175 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 176 | 176 | |
| 177 | - if( ! is_user_logged_in() ) return; |
|
| 177 | + if ( ! is_user_logged_in()) return; |
|
| 178 | 178 | |
| 179 | - if( isset( $_GET['contact'] ) ) { |
|
| 180 | - $html .= $this->teacher_contact_form( $post ); |
|
| 179 | + if (isset($_GET['contact'])) { |
|
| 180 | + $html .= $this->teacher_contact_form($post); |
|
| 181 | 181 | } else { |
| 182 | - $href = add_query_arg( array( 'contact' => $post->post_type ) ); |
|
| 183 | - |
|
| 184 | - if( 'lesson' == $post->post_type ) { |
|
| 185 | - $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); |
|
| 186 | - } elseif( 'course' == $post->post_type ) { |
|
| 187 | - $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
|
| 188 | - }else{ |
|
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 182 | + $href = add_query_arg(array('contact' => $post->post_type)); |
|
| 183 | + |
|
| 184 | + if ('lesson' == $post->post_type) { |
|
| 185 | + $contact_button_text = __('Contact Lesson Teacher', 'woothemes-sensei'); |
|
| 186 | + } elseif ('course' == $post->post_type) { |
|
| 187 | + $contact_button_text = __('Contact Course Teacher', 'woothemes-sensei'); |
|
| 188 | + } else { |
|
| 189 | + $contact_button_text = __('Contact Teacher', 'woothemes-sensei'); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
|
| 192 | + $html .= '<p><a class="button send-message-button" href="'.esc_url($href).'#private_message">'.$contact_button_text.'</a></p>'; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if( isset( $this->message_notice ) && isset( $this->message_notice['type'] ) && isset( $this->message_notice['notice'] ) ) { |
|
| 196 | - $html .= '<div class="sensei-message ' . $this->message_notice['type'] . '">' . $this->message_notice['notice'] . '</div>'; |
|
| 195 | + if (isset($this->message_notice) && isset($this->message_notice['type']) && isset($this->message_notice['notice'])) { |
|
| 196 | + $html .= '<div class="sensei-message '.$this->message_notice['type'].'">'.$this->message_notice['notice'].'</div>'; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | } |
@@ -201,40 +201,40 @@ discard block |
||
| 201 | 201 | echo $html; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - public function teacher_contact_form( $post ) { |
|
| 204 | + public function teacher_contact_form($post) { |
|
| 205 | 205 | |
| 206 | - if( ! is_user_logged_in() ) return; |
|
| 206 | + if ( ! is_user_logged_in()) return; |
|
| 207 | 207 | |
| 208 | 208 | global $current_user; |
| 209 | 209 | wp_get_current_user(); |
| 210 | 210 | |
| 211 | 211 | $html = ''; |
| 212 | 212 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; |
|
| 213 | + if ( ! isset($post->ID)) return $html; |
|
| 214 | 214 | |
| 215 | 215 | //confirm private message |
| 216 | 216 | $confirmation = ''; |
| 217 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 217 | + if (isset($_GET['send']) && 'complete' == $_GET['send']) { |
|
| 218 | 218 | |
| 219 | 219 | $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 220 | + $confirmation = '<div class="sensei-message tick">'.$confirmation_message.'</div>'; |
|
| 221 | 221 | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
|
| 224 | + $html .= '<h3 id="private_message">'.__('Send Private Message', 'woothemes-sensei').'</h3>'; |
|
| 225 | 225 | $html .= '<p>'; |
| 226 | - $html .= $confirmation; |
|
| 226 | + $html .= $confirmation; |
|
| 227 | 227 | $html .= '</p>'; |
| 228 | 228 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; |
| 229 | 229 | $html .= '<p class="form-row form-row-wide">'; |
| 230 | - $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
|
| 230 | + $html .= '<textarea name="contact_message" placeholder="'.__('Enter your private message.', 'woothemes-sensei').'"></textarea>'; |
|
| 231 | 231 | $html .= '</p>'; |
| 232 | 232 | $html .= '<p class="form-row">'; |
| 233 | - $html .= '<input type="hidden" name="post_id" value="' . $post->ID . '" />'; |
|
| 234 | - $html .= '<input type="hidden" name="sender_id" value="' . $current_user->ID . '" />'; |
|
| 235 | - $html .= '<input type="hidden" name="receiver_id" value="' . $post->post_author . '" />'; |
|
| 236 | - $html .= wp_nonce_field( 'message_teacher', 'sensei_message_teacher_nonce', true, false ); |
|
| 237 | - $html .= '<input type="submit" class="send_message" value="' . __( 'Send Message', 'woothemes-sensei' ) . '" />'; |
|
| 233 | + $html .= '<input type="hidden" name="post_id" value="'.$post->ID.'" />'; |
|
| 234 | + $html .= '<input type="hidden" name="sender_id" value="'.$current_user->ID.'" />'; |
|
| 235 | + $html .= '<input type="hidden" name="receiver_id" value="'.$post->post_author.'" />'; |
|
| 236 | + $html .= wp_nonce_field('message_teacher', 'sensei_message_teacher_nonce', true, false); |
|
| 237 | + $html .= '<input type="submit" class="send_message" value="'.__('Send Message', 'woothemes-sensei').'" />'; |
|
| 238 | 238 | $html .= '</p>'; |
| 239 | 239 | $html .= '<div class="fix"></div>'; |
| 240 | 240 | $html .= '</form>'; |
@@ -244,30 +244,30 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | public function save_new_message() { |
| 246 | 246 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; |
|
| 247 | + if ( ! isset($_POST['sensei_message_teacher_nonce'])) return; |
|
| 248 | 248 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; |
|
| 249 | + if ( ! wp_verify_nonce($_POST['sensei_message_teacher_nonce'], 'message_teacher')) return; |
|
| 250 | 250 | |
| 251 | - $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); |
|
| 251 | + $message_id = $this->save_new_message_post($_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id']); |
|
| 252 | 252 | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - public function message_reply_received( $comment_id = 0 ) { |
|
| 255 | + public function message_reply_received($comment_id = 0) { |
|
| 256 | 256 | |
| 257 | 257 | // Get comment object |
| 258 | - $comment = get_comment( $comment_id ); |
|
| 258 | + $comment = get_comment($comment_id); |
|
| 259 | 259 | |
| 260 | - if( is_null( $comment ) ) return; |
|
| 260 | + if (is_null($comment)) return; |
|
| 261 | 261 | |
| 262 | 262 | // Get message post object |
| 263 | - $message = get_post( $comment->comment_post_ID ); |
|
| 263 | + $message = get_post($comment->comment_post_ID); |
|
| 264 | 264 | |
| 265 | - if( $message->post_type != $this->post_type ) return; |
|
| 265 | + if ($message->post_type != $this->post_type) return; |
|
| 266 | 266 | |
| 267 | 267 | // Force comment to be approved |
| 268 | - wp_set_comment_status( $comment_id, 'approve' ); |
|
| 268 | + wp_set_comment_status($comment_id, 'approve'); |
|
| 269 | 269 | |
| 270 | - do_action( 'sensei_private_message_reply', $comment, $message ); |
|
| 270 | + do_action('sensei_private_message_reply', $comment, $message); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -280,11 +280,11 @@ discard block |
||
| 280 | 280 | * @param int $comment_id |
| 281 | 281 | * @return array; |
| 282 | 282 | */ |
| 283 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 283 | + public function stop_wp_comment_emails($emails, $comment_id) { |
|
| 284 | 284 | |
| 285 | - $comment = get_comment( $comment_id ); |
|
| 286 | - if( isset( $comment->comment_post_ID ) && |
|
| 287 | - 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 285 | + $comment = get_comment($comment_id); |
|
| 286 | + if (isset($comment->comment_post_ID) && |
|
| 287 | + 'sensei_message' == get_post_type($comment->comment_post_ID)) { |
|
| 288 | 288 | |
| 289 | 289 | // empty the emails array to ensure no emails are sent for this comment |
| 290 | 290 | $emails = array(); |
@@ -302,45 +302,45 @@ discard block |
||
| 302 | 302 | * @param string $post_id ID of post related to message |
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure |
| 304 | 304 | */ |
| 305 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 305 | + private function save_new_message_post($sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0) { |
|
| 306 | 306 | |
| 307 | 307 | $message_id = false; |
| 308 | 308 | |
| 309 | - if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 309 | + if ($sender_id && $receiver_id && $message && $post_id) { |
|
| 310 | 310 | |
| 311 | - $title = wp_trim_words( $message, 8, '...' ); |
|
| 311 | + $title = wp_trim_words($message, 8, '...'); |
|
| 312 | 312 | |
| 313 | 313 | // Set up post data for message |
| 314 | 314 | $message_data = array( |
| 315 | 315 | 'post_type' => $this->post_type, |
| 316 | - 'post_title' => esc_html( $title ), |
|
| 317 | - 'post_content' => esc_html( $message ), |
|
| 316 | + 'post_title' => esc_html($title), |
|
| 317 | + 'post_content' => esc_html($message), |
|
| 318 | 318 | 'post_status' => 'publish', |
| 319 | 319 | 'ping_status' => 'closed', |
| 320 | 320 | 'comment_status' => 'open', |
| 321 | 321 | 'post_excerpt' => '', |
| 322 | - 'post_author' => intval( $sender_id ) |
|
| 322 | + 'post_author' => intval($sender_id) |
|
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | 325 | // Insert post |
| 326 | - $message_id = wp_insert_post( $message_data ); |
|
| 326 | + $message_id = wp_insert_post($message_data); |
|
| 327 | 327 | |
| 328 | - if( ! is_wp_error( $message_id ) ) { |
|
| 328 | + if ( ! is_wp_error($message_id)) { |
|
| 329 | 329 | |
| 330 | 330 | // Add sender to message meta |
| 331 | - $sender = get_userdata( $sender_id ); |
|
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 331 | + $sender = get_userdata($sender_id); |
|
| 332 | + add_post_meta($message_id, '_sender', $sender->user_login); |
|
| 333 | 333 | |
| 334 | 334 | // Add receiver to message meta |
| 335 | - $receiver = get_userdata( $receiver_id ); |
|
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 335 | + $receiver = get_userdata($receiver_id); |
|
| 336 | + add_post_meta($message_id, '_receiver', $receiver->user_login); |
|
| 337 | 337 | |
| 338 | 338 | // Add lesson/course ID to message meta |
| 339 | - $post = get_post( $post_id ); |
|
| 340 | - add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 341 | - add_post_meta( $message_id, '_post', $post->ID ); |
|
| 339 | + $post = get_post($post_id); |
|
| 340 | + add_post_meta($message_id, '_posttype', $post->post_type); |
|
| 341 | + add_post_meta($message_id, '_post', $post->ID); |
|
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 343 | + do_action('sensei_new_private_message', $message_id); |
|
| 344 | 344 | |
| 345 | 345 | } else { |
| 346 | 346 | |
@@ -358,22 +358,22 @@ discard block |
||
| 358 | 358 | * @param integer $user_id ID of user |
| 359 | 359 | * @return boolean True if user has access to this message |
| 360 | 360 | */ |
| 361 | - private function view_message( $message_id, $user_id = 0) { |
|
| 361 | + private function view_message($message_id, $user_id = 0) { |
|
| 362 | 362 | |
| 363 | - if( ! is_user_logged_in() ) return false; |
|
| 363 | + if ( ! is_user_logged_in()) return false; |
|
| 364 | 364 | |
| 365 | - if( $user_id == 0 ) { |
|
| 365 | + if ($user_id == 0) { |
|
| 366 | 366 | global $current_user; |
| 367 | 367 | wp_get_current_user(); |
| 368 | 368 | $user_login = $current_user->user_login; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Get allowed users |
| 372 | - $receiver = get_post_meta( $message_id, '_receiver', true ); |
|
| 373 | - $sender = get_post_meta( $message_id, '_sender', true ); |
|
| 372 | + $receiver = get_post_meta($message_id, '_receiver', true); |
|
| 373 | + $sender = get_post_meta($message_id, '_sender', true); |
|
| 374 | 374 | |
| 375 | 375 | // Check if user is allowed to view the message |
| 376 | - if( in_array( $user_login, array( $receiver, $sender ) ) ) { |
|
| 376 | + if (in_array($user_login, array($receiver, $sender))) { |
|
| 377 | 377 | return true; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -400,27 +400,27 @@ discard block |
||
| 400 | 400 | * @return void |
| 401 | 401 | */ |
| 402 | 402 | |
| 403 | - public function message_login () { |
|
| 403 | + public function message_login() { |
|
| 404 | 404 | |
| 405 | - if ( is_user_logged_in() ) { |
|
| 405 | + if (is_user_logged_in()) { |
|
| 406 | 406 | |
| 407 | 407 | return; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $settings = Sensei()->settings->get_settings(); |
| 411 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 412 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 411 | + if (isset($settings['my_course_page']) |
|
| 412 | + && 0 < intval($settings['my_course_page'])) { |
|
| 413 | 413 | |
| 414 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 414 | + $my_courses_page_id = $settings['my_course_page']; |
|
| 415 | 415 | |
| 416 | 416 | $my_courses_url = get_permalink($my_courses_page_id); |
| 417 | 417 | |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if ( is_single() && is_singular( $this->post_type ) |
|
| 421 | - || is_post_type_archive( $this->post_type ) ) { |
|
| 420 | + if (is_single() && is_singular($this->post_type) |
|
| 421 | + || is_post_type_archive($this->post_type)) { |
|
| 422 | 422 | |
| 423 | - if ( isset($my_courses_url) ) { |
|
| 423 | + if (isset($my_courses_url)) { |
|
| 424 | 424 | |
| 425 | 425 | wp_redirect($my_courses_url, 303); |
| 426 | 426 | exit; |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | * @param array $query Original query |
| 440 | 440 | * @return void |
| 441 | 441 | */ |
| 442 | - public function message_list( $query ) { |
|
| 442 | + public function message_list($query) { |
|
| 443 | 443 | global $current_user; |
| 444 | 444 | |
| 445 | - if( is_admin() ) return; |
|
| 445 | + if (is_admin()) return; |
|
| 446 | 446 | |
| 447 | - if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { |
|
| 447 | + if (is_post_type_archive($this->post_type) && $query->is_main_query()) { |
|
| 448 | 448 | wp_get_current_user(); |
| 449 | 449 | $username = $current_user->user_login; |
| 450 | 450 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | 'compare' => '=' |
| 463 | 463 | ); |
| 464 | 464 | |
| 465 | - $query->set( 'meta_query', $meta_query ); |
|
| 465 | + $query->set('meta_query', $meta_query); |
|
| 466 | 466 | |
| 467 | 467 | return; |
| 468 | 468 | } |
@@ -474,11 +474,11 @@ discard block |
||
| 474 | 474 | * @param integer $post_id ID of post |
| 475 | 475 | * @return string Modified string if user does not have access to this message |
| 476 | 476 | */ |
| 477 | - public function message_title( $title = '', $post_id = null ) { |
|
| 477 | + public function message_title($title = '', $post_id = null) { |
|
| 478 | 478 | |
| 479 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() && get_post_type( $post_id ) == $this->post_type ) { |
|
| 480 | - if( ! is_user_logged_in() || ! $this->view_message( $post_id ) ) { |
|
| 481 | - $title = __( 'You are not allowed to view this message.', 'woothemes-sensei' ); |
|
| 479 | + if (is_single() && is_singular($this->post_type) && in_the_loop() && get_post_type($post_id) == $this->post_type) { |
|
| 480 | + if ( ! is_user_logged_in() || ! $this->view_message($post_id)) { |
|
| 481 | + $title = __('You are not allowed to view this message.', 'woothemes-sensei'); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
@@ -490,12 +490,12 @@ discard block |
||
| 490 | 490 | * @param string $content Original message content |
| 491 | 491 | * @return string Empty string if user does not have access to this message |
| 492 | 492 | */ |
| 493 | - public function message_content( $content ) { |
|
| 493 | + public function message_content($content) { |
|
| 494 | 494 | global $post; |
| 495 | 495 | |
| 496 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 497 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 498 | - $content = __( 'Please log in to view your messages.', 'woothemes-sensei' ); |
|
| 496 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 497 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 498 | + $content = __('Please log in to view your messages.', 'woothemes-sensei'); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | |
@@ -507,11 +507,11 @@ discard block |
||
| 507 | 507 | * @param array $comments Array of replies |
| 508 | 508 | * @return array Empty array if user does not have access to this message |
| 509 | 509 | */ |
| 510 | - public function message_replies( $comments ) { |
|
| 510 | + public function message_replies($comments) { |
|
| 511 | 511 | global $post; |
| 512 | 512 | |
| 513 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 514 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 513 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 514 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 515 | 515 | $comments = array(); |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -525,11 +525,11 @@ discard block |
||
| 525 | 525 | * @param integer $post_id ID of post |
| 526 | 526 | * @return integer 0 if user does not have access to this message |
| 527 | 527 | */ |
| 528 | - public function message_reply_count( $count, $post_id ) { |
|
| 528 | + public function message_reply_count($count, $post_id) { |
|
| 529 | 529 | global $post; |
| 530 | 530 | |
| 531 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 532 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 531 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 532 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 533 | 533 | $count = 0; |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -543,11 +543,11 @@ discard block |
||
| 543 | 543 | * @param integer $post_id ID of post |
| 544 | 544 | * @return boolean False if user does not have access to this message |
| 545 | 545 | */ |
| 546 | - public function message_replies_open( $open, $post_id ) { |
|
| 546 | + public function message_replies_open($open, $post_id) { |
|
| 547 | 547 | global $post; |
| 548 | 548 | |
| 549 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 550 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 549 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 550 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 551 | 551 | $open = false; |
| 552 | 552 | } |
| 553 | 553 | } |
@@ -560,17 +560,17 @@ discard block |
||
| 560 | 560 | * |
| 561 | 561 | * @since 1.9.0 |
| 562 | 562 | */ |
| 563 | - public static function the_message_sent_by_title(){ |
|
| 563 | + public static function the_message_sent_by_title() { |
|
| 564 | 564 | |
| 565 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 566 | - if( $sender_username ) { |
|
| 565 | + $sender_username = get_post_meta(get_the_ID(), '_sender', true); |
|
| 566 | + if ($sender_username) { |
|
| 567 | 567 | |
| 568 | - $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 568 | + $sender = get_user_by('login', $sender_username); ?> |
|
| 569 | 569 | |
| 570 | 570 | <p class="message-meta"> |
| 571 | 571 | <small> |
| 572 | 572 | <em> |
| 573 | - <?php printf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); ?> |
|
| 573 | + <?php printf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); ?> |
|
| 574 | 574 | </em> |
| 575 | 575 | </small> |
| 576 | 576 | </p> |
@@ -589,11 +589,11 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | global $post; |
| 591 | 591 | |
| 592 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 593 | - if( $content_post_id ) { |
|
| 594 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 592 | + $content_post_id = get_post_meta($post->ID, '_post', true); |
|
| 593 | + if ($content_post_id) { |
|
| 594 | + $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), '<a href="'.get_permalink($content_post_id).'">'.get_the_title($content_post_id).'</a>'); |
|
| 595 | 595 | } else { |
| 596 | - $title = get_the_title( $post->ID ); |
|
| 596 | + $title = get_the_title($post->ID); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | ?> |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @param string $template |
| 611 | 611 | * @param string $post_type |
| 612 | 612 | */ |
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 613 | + echo apply_filters('sensei_single_title', $title, $post->post_type); |
|
| 614 | 614 | ?> |
| 615 | 615 | |
| 616 | 616 | </h1> |
@@ -629,18 +629,18 @@ discard block |
||
| 629 | 629 | * |
| 630 | 630 | * @return string |
| 631 | 631 | */ |
| 632 | - public static function the_archive_header( ){ |
|
| 632 | + public static function the_archive_header( ) { |
|
| 633 | 633 | |
| 634 | 634 | $html = ''; |
| 635 | 635 | $html .= '<header class="archive-header"><h1>'; |
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 636 | + $html .= __('My Messages', 'woothemes-sensei'); |
|
| 637 | 637 | $html .= '</h1></header>'; |
| 638 | 638 | |
| 639 | 639 | /** |
| 640 | 640 | * Filter the sensei messages archive title. |
| 641 | 641 | * @since 1.0.0 |
| 642 | 642 | */ |
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 643 | + echo apply_filters('sensei_message_archive_title', $html); |
|
| 644 | 644 | |
| 645 | 645 | } // get_archive_header() |
| 646 | 646 | |
@@ -650,23 +650,23 @@ discard block |
||
| 650 | 650 | * @since 1.9.0 |
| 651 | 651 | * @param $post_id |
| 652 | 652 | */ |
| 653 | - public static function the_message_title( $message_post_id ){ |
|
| 653 | + public static function the_message_title($message_post_id) { |
|
| 654 | 654 | |
| 655 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 655 | + $content_post_id = get_post_meta($message_post_id, '_post', true); |
|
| 656 | 656 | |
| 657 | - if( $content_post_id ) { |
|
| 657 | + if ($content_post_id) { |
|
| 658 | 658 | |
| 659 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 659 | + $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), get_the_title($content_post_id)); |
|
| 660 | 660 | |
| 661 | 661 | } else { |
| 662 | 662 | |
| 663 | - $title = get_the_title( $message_post_id ); |
|
| 663 | + $title = get_the_title($message_post_id); |
|
| 664 | 664 | |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | ?> |
| 668 | 668 | <h2> |
| 669 | - <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
|
| 669 | + <a href="<?php esc_url(get_permalink($message_post_id)); ?>"> |
|
| 670 | 670 | <?php echo $title; ?> |
| 671 | 671 | </a> |
| 672 | 672 | |
@@ -680,13 +680,13 @@ discard block |
||
| 680 | 680 | * |
| 681 | 681 | * @param $message_post_id |
| 682 | 682 | */ |
| 683 | - public static function the_message_sender( $message_post_id ){ |
|
| 683 | + public static function the_message_sender($message_post_id) { |
|
| 684 | 684 | |
| 685 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 686 | - $sender = get_user_by( 'login', $sender_username ); |
|
| 685 | + $sender_username = get_post_meta($message_post_id, '_sender', true); |
|
| 686 | + $sender = get_user_by('login', $sender_username); |
|
| 687 | 687 | |
| 688 | - if( $sender_username && $sender instanceof WP_User ) { |
|
| 689 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 688 | + if ($sender_username && $sender instanceof WP_User) { |
|
| 689 | + $sender_display_name = sprintf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); |
|
| 690 | 690 | ?> |
| 691 | 691 | <p class="message-meta"> |
| 692 | 692 | <small> |
@@ -704,13 +704,13 @@ discard block |
||
| 704 | 704 | * |
| 705 | 705 | * @since 1.9.0 |
| 706 | 706 | */ |
| 707 | - public static function the_my_messages_link(){ |
|
| 708 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 707 | + public static function the_my_messages_link() { |
|
| 708 | + if ( ! Sensei()->settings->get('messages_disable')) { |
|
| 709 | 709 | ?> |
| 710 | 710 | <p class="my-messages-link-container"> |
| 711 | - <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
|
| 712 | - title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
|
| 713 | - <?php _e( 'My Messages', 'woothemes-sensei' ); ?> |
|
| 711 | + <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>" |
|
| 712 | + title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>"> |
|
| 713 | + <?php _e('My Messages', 'woothemes-sensei'); ?> |
|
| 714 | 714 | </a> |
| 715 | 715 | </p> |
| 716 | 716 | <?php |
@@ -724,4 +724,4 @@ discard block |
||
| 724 | 724 | * for backward compatibility |
| 725 | 725 | * @since 1.9.0 |
| 726 | 726 | */ |
| 727 | -class WooThemes_Sensei_Messages extends Sensei_Messages{} |
|
| 727 | +class WooThemes_Sensei_Messages extends Sensei_Messages {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Messages Class |
@@ -73,7 +76,9 @@ discard block |
||
| 73 | 76 | |
| 74 | 77 | public function add_meta_box( $post_type, $post ) { |
| 75 | 78 | |
| 76 | - if( ! $post_type == $this->post_type ) return; |
|
| 79 | + if( ! $post_type == $this->post_type ) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); |
| 79 | 84 | |
@@ -138,7 +143,9 @@ discard block |
||
| 138 | 143 | public function save_message( $post_id = 0 ) { |
| 139 | 144 | global $post; |
| 140 | 145 | |
| 141 | - if( $this->post_type != get_post_type() ) return; |
|
| 146 | + if( $this->post_type != get_post_type() ) { |
|
| 147 | + return; |
|
| 148 | + } |
|
| 142 | 149 | |
| 143 | 150 | if( isset( $_POST['sender'] ) && $_POST['sender'] ) { |
| 144 | 151 | update_post_meta( $post_id, '_sender', $_POST['sender'] ); |
@@ -174,7 +181,9 @@ discard block |
||
| 174 | 181 | |
| 175 | 182 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
| 176 | 183 | |
| 177 | - if( ! is_user_logged_in() ) return; |
|
| 184 | + if( ! is_user_logged_in() ) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | 188 | if( isset( $_GET['contact'] ) ) { |
| 180 | 189 | $html .= $this->teacher_contact_form( $post ); |
@@ -185,7 +194,7 @@ discard block |
||
| 185 | 194 | $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); |
| 186 | 195 | } elseif( 'course' == $post->post_type ) { |
| 187 | 196 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 188 | - }else{ |
|
| 197 | + } else{ |
|
| 189 | 198 | $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
| 190 | 199 | } |
| 191 | 200 | |
@@ -203,14 +212,18 @@ discard block |
||
| 203 | 212 | |
| 204 | 213 | public function teacher_contact_form( $post ) { |
| 205 | 214 | |
| 206 | - if( ! is_user_logged_in() ) return; |
|
| 215 | + if( ! is_user_logged_in() ) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 207 | 218 | |
| 208 | 219 | global $current_user; |
| 209 | 220 | wp_get_current_user(); |
| 210 | 221 | |
| 211 | 222 | $html = ''; |
| 212 | 223 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; |
|
| 224 | + if( ! isset( $post->ID ) ) { |
|
| 225 | + return $html; |
|
| 226 | + } |
|
| 214 | 227 | |
| 215 | 228 | //confirm private message |
| 216 | 229 | $confirmation = ''; |
@@ -244,9 +257,13 @@ discard block |
||
| 244 | 257 | |
| 245 | 258 | public function save_new_message() { |
| 246 | 259 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; |
|
| 260 | + if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 248 | 263 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; |
|
| 264 | + if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 250 | 267 | |
| 251 | 268 | $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); |
| 252 | 269 | |
@@ -257,12 +274,16 @@ discard block |
||
| 257 | 274 | // Get comment object |
| 258 | 275 | $comment = get_comment( $comment_id ); |
| 259 | 276 | |
| 260 | - if( is_null( $comment ) ) return; |
|
| 277 | + if( is_null( $comment ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 261 | 280 | |
| 262 | 281 | // Get message post object |
| 263 | 282 | $message = get_post( $comment->comment_post_ID ); |
| 264 | 283 | |
| 265 | - if( $message->post_type != $this->post_type ) return; |
|
| 284 | + if( $message->post_type != $this->post_type ) { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 266 | 287 | |
| 267 | 288 | // Force comment to be approved |
| 268 | 289 | wp_set_comment_status( $comment_id, 'approve' ); |
@@ -360,7 +381,9 @@ discard block |
||
| 360 | 381 | */ |
| 361 | 382 | private function view_message( $message_id, $user_id = 0) { |
| 362 | 383 | |
| 363 | - if( ! is_user_logged_in() ) return false; |
|
| 384 | + if( ! is_user_logged_in() ) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 364 | 387 | |
| 365 | 388 | if( $user_id == 0 ) { |
| 366 | 389 | global $current_user; |
@@ -424,9 +447,7 @@ discard block |
||
| 424 | 447 | |
| 425 | 448 | wp_redirect($my_courses_url, 303); |
| 426 | 449 | exit; |
| 427 | - } |
|
| 428 | - |
|
| 429 | - else { |
|
| 450 | + } else { |
|
| 430 | 451 | |
| 431 | 452 | wp_redirect(home_url('/wp-login.php'), 303); |
| 432 | 453 | exit; |
@@ -442,7 +463,9 @@ discard block |
||
| 442 | 463 | public function message_list( $query ) { |
| 443 | 464 | global $current_user; |
| 444 | 465 | |
| 445 | - if( is_admin() ) return; |
|
| 466 | + if( is_admin() ) { |
|
| 467 | + return; |
|
| 468 | + } |
|
| 446 | 469 | |
| 447 | 470 | if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { |
| 448 | 471 | wp_get_current_user(); |
@@ -1942,6 +1942,7 @@ |
||
| 1942 | 1942 | * Hooked into 'get_terms' |
| 1943 | 1943 | * |
| 1944 | 1944 | * @since 1.8.0 |
| 1945 | + * @param string[] $taxonomies |
|
| 1945 | 1946 | */ |
| 1946 | 1947 | public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
| 1947 | 1948 | { |
@@ -14,265 +14,265 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Core_Modules |
| 16 | 16 | { |
| 17 | - private $dir; |
|
| 18 | - private $file; |
|
| 19 | - private $assets_dir; |
|
| 20 | - private $assets_url; |
|
| 21 | - private $order_page_slug; |
|
| 22 | - public $taxonomy; |
|
| 23 | - |
|
| 24 | - public function __construct( $file ) |
|
| 25 | - { |
|
| 26 | - $this->file = $file; |
|
| 27 | - $this->dir = dirname($this->file); |
|
| 28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | - $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | - $this->taxonomy = 'module'; |
|
| 31 | - $this->order_page_slug = 'module-order'; |
|
| 32 | - |
|
| 33 | - // setup taxonomy |
|
| 34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | - |
|
| 36 | - // Manage lesson meta boxes for taxonomy |
|
| 37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | - |
|
| 39 | - // Save lesson meta box |
|
| 40 | - add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | - |
|
| 42 | - //Reset the none modules lessons transient |
|
| 43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | - |
|
| 45 | - // Frontend styling |
|
| 46 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | - |
|
| 48 | - // Admin styling |
|
| 49 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | - |
|
| 52 | - // Handle module completion record |
|
| 53 | - add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | - add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | - add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | - |
|
| 57 | - // Handle module ordering |
|
| 58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | - add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | - add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | - |
|
| 62 | - // Ensure modules always show under courses |
|
| 63 | - add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | - add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | - add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | - |
|
| 67 | - // Add course field to taxonomy |
|
| 68 | - add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | - add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | - add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | - add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | - add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | - |
|
| 74 | - // Manage module taxonomy archive page |
|
| 75 | - add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | - add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | - add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | - add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | - add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | - add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | - |
|
| 82 | - // add modules to the single course template |
|
| 83 | - add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | - |
|
| 85 | - //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | - add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | - |
|
| 88 | - // Set up display on single lesson page |
|
| 89 | - add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | - |
|
| 91 | - // Add 'Modules' columns to Analysis tables |
|
| 92 | - add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | - add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | - add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | - add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | - |
|
| 97 | - // Manage module taxonomy columns |
|
| 98 | - add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | - add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | - add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | - |
|
| 102 | - //store new modules created on the course edit screen |
|
| 103 | - add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | - |
|
| 105 | - // for non admin users, only show taxonomies that belong to them |
|
| 106 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | - add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | - |
|
| 109 | - // add the teacher name next to the module term in for admin users |
|
| 110 | - add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | - |
|
| 112 | - // remove the default modules metabox |
|
| 113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | - |
|
| 115 | - } // end constructor |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Alter a module term slug when a new taxonomy term is created |
|
| 119 | - * This will add the creators user name to the slug for uniqueness. |
|
| 120 | - * |
|
| 121 | - * @since 1.8.0 |
|
| 122 | - * |
|
| 123 | - * @param $term_id |
|
| 124 | - * @param $tt_id |
|
| 125 | - * @param $taxonomy |
|
| 126 | - * |
|
| 127 | - * @return void |
|
| 128 | - * @deprecated since 1.9.0 |
|
| 129 | - */ |
|
| 130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | - |
|
| 132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | - |
|
| 134 | - }// end add_module_term_group |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | - * |
|
| 139 | - * @since 1.8.0 |
|
| 140 | - * |
|
| 141 | - * @param string $post_type |
|
| 142 | - * @param WP_Post $post |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function modules_metaboxes( $post_type, $post ) |
|
| 147 | - { |
|
| 148 | - if ('lesson' == $post_type ) { |
|
| 149 | - |
|
| 150 | - // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | - |
|
| 153 | - // Add custom meta box to limit module selection to one per lesson |
|
| 154 | - add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if( 'course' == $post_type ){ |
|
| 158 | - // Course modules selection metabox |
|
| 159 | - add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Build content for custom module meta box |
|
| 165 | - * |
|
| 166 | - * @since 1.8.0 |
|
| 167 | - * @param object $post Current post object |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function lesson_module_metabox($post) |
|
| 171 | - { |
|
| 172 | - |
|
| 173 | - // Get lesson course |
|
| 174 | - $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | - |
|
| 176 | - $html = ''; |
|
| 177 | - |
|
| 178 | - // Only show module selection if this lesson is part of a course |
|
| 179 | - if ($lesson_course && $lesson_course > 0) { |
|
| 180 | - |
|
| 181 | - // Get existing lesson module |
|
| 182 | - $lesson_module = 0; |
|
| 183 | - $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | - foreach ($lesson_module_list as $single_module) { |
|
| 186 | - $lesson_module = $single_module->term_id; |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Get the available modules for this lesson's course |
|
| 192 | - $modules = $this->get_course_modules($lesson_course); |
|
| 193 | - |
|
| 194 | - // Build the HTML to output |
|
| 195 | - $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | - if (is_array($modules) && count($modules) > 0) { |
|
| 197 | - $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | - $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | - foreach ($modules as $module) { |
|
| 200 | - $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | - } |
|
| 202 | - $html .= '</select>' . "\n"; |
|
| 203 | - } else { |
|
| 204 | - $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | - } // End If Statement |
|
| 207 | - |
|
| 208 | - } else { |
|
| 209 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | - } // End If Statement |
|
| 211 | - |
|
| 212 | - // Output the HTML |
|
| 213 | - echo $html; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Save module to lesson |
|
| 218 | - * |
|
| 219 | - * @since 1.8.0 |
|
| 220 | - * @param integer $post_id ID of post |
|
| 221 | - * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | - */ |
|
| 223 | - public function save_lesson_module($post_id) |
|
| 224 | - { |
|
| 225 | - global $post; |
|
| 226 | - |
|
| 227 | - // Verify post type and nonce |
|
| 228 | - if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | - ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | - return $post_id; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Check if user has permissions to edit lessons |
|
| 234 | - $post_type = get_post_type_object($post->post_type); |
|
| 235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | - return $post_id; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check if user has permissions to edit this specific post |
|
| 240 | - if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | - return $post_id; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | - |
|
| 247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | - return true; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | - |
|
| 254 | - // Assign lesson to selected module |
|
| 255 | - wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | - |
|
| 257 | - // Set default order for lesson inside module |
|
| 258 | - if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | - update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Display course field on new module screen |
|
| 268 | - * |
|
| 269 | - * @since 1.8.0 |
|
| 270 | - * @param object $taxonomy Taxonomy object |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - public function add_module_fields($taxonomy) |
|
| 274 | - { |
|
| 275 | - ?> |
|
| 17 | + private $dir; |
|
| 18 | + private $file; |
|
| 19 | + private $assets_dir; |
|
| 20 | + private $assets_url; |
|
| 21 | + private $order_page_slug; |
|
| 22 | + public $taxonomy; |
|
| 23 | + |
|
| 24 | + public function __construct( $file ) |
|
| 25 | + { |
|
| 26 | + $this->file = $file; |
|
| 27 | + $this->dir = dirname($this->file); |
|
| 28 | + $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 29 | + $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
| 30 | + $this->taxonomy = 'module'; |
|
| 31 | + $this->order_page_slug = 'module-order'; |
|
| 32 | + |
|
| 33 | + // setup taxonomy |
|
| 34 | + add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 35 | + |
|
| 36 | + // Manage lesson meta boxes for taxonomy |
|
| 37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 38 | + |
|
| 39 | + // Save lesson meta box |
|
| 40 | + add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
| 41 | + |
|
| 42 | + //Reset the none modules lessons transient |
|
| 43 | + add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 44 | + |
|
| 45 | + // Frontend styling |
|
| 46 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 47 | + |
|
| 48 | + // Admin styling |
|
| 49 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
| 50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 51 | + |
|
| 52 | + // Handle module completion record |
|
| 53 | + add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
| 54 | + add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
| 55 | + add_action('wp', array($this, 'save_module_progress'), 10); |
|
| 56 | + |
|
| 57 | + // Handle module ordering |
|
| 58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 59 | + add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
| 60 | + add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
| 61 | + |
|
| 62 | + // Ensure modules always show under courses |
|
| 63 | + add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | + add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | + add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 66 | + |
|
| 67 | + // Add course field to taxonomy |
|
| 68 | + add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | + add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | + add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | + add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | + add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
| 73 | + |
|
| 74 | + // Manage module taxonomy archive page |
|
| 75 | + add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
| 76 | + add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
| 77 | + add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
| 78 | + add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
| 79 | + add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
| 80 | + add_filter('body_class', array($this, 'module_archive_body_class')); |
|
| 81 | + |
|
| 82 | + // add modules to the single course template |
|
| 83 | + add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 84 | + |
|
| 85 | + //Single Course modules actions. Add to single-course/course-modules.php |
|
| 86 | + add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 87 | + |
|
| 88 | + // Set up display on single lesson page |
|
| 89 | + add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
| 90 | + |
|
| 91 | + // Add 'Modules' columns to Analysis tables |
|
| 92 | + add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
| 93 | + add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
| 94 | + add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
| 95 | + add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
| 96 | + |
|
| 97 | + // Manage module taxonomy columns |
|
| 98 | + add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | + add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | + add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
| 101 | + |
|
| 102 | + //store new modules created on the course edit screen |
|
| 103 | + add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 104 | + |
|
| 105 | + // for non admin users, only show taxonomies that belong to them |
|
| 106 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | + add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 108 | + |
|
| 109 | + // add the teacher name next to the module term in for admin users |
|
| 110 | + add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 111 | + |
|
| 112 | + // remove the default modules metabox |
|
| 113 | + add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 114 | + |
|
| 115 | + } // end constructor |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Alter a module term slug when a new taxonomy term is created |
|
| 119 | + * This will add the creators user name to the slug for uniqueness. |
|
| 120 | + * |
|
| 121 | + * @since 1.8.0 |
|
| 122 | + * |
|
| 123 | + * @param $term_id |
|
| 124 | + * @param $tt_id |
|
| 125 | + * @param $taxonomy |
|
| 126 | + * |
|
| 127 | + * @return void |
|
| 128 | + * @deprecated since 1.9.0 |
|
| 129 | + */ |
|
| 130 | + public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 131 | + |
|
| 132 | + _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 133 | + |
|
| 134 | + }// end add_module_term_group |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Hook in all meta boxes related tot he modules taxonomy |
|
| 138 | + * |
|
| 139 | + * @since 1.8.0 |
|
| 140 | + * |
|
| 141 | + * @param string $post_type |
|
| 142 | + * @param WP_Post $post |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function modules_metaboxes( $post_type, $post ) |
|
| 147 | + { |
|
| 148 | + if ('lesson' == $post_type ) { |
|
| 149 | + |
|
| 150 | + // Remove default taxonomy meta box from Lesson edit screen |
|
| 151 | + remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 152 | + |
|
| 153 | + // Add custom meta box to limit module selection to one per lesson |
|
| 154 | + add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if( 'course' == $post_type ){ |
|
| 158 | + // Course modules selection metabox |
|
| 159 | + add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Build content for custom module meta box |
|
| 165 | + * |
|
| 166 | + * @since 1.8.0 |
|
| 167 | + * @param object $post Current post object |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function lesson_module_metabox($post) |
|
| 171 | + { |
|
| 172 | + |
|
| 173 | + // Get lesson course |
|
| 174 | + $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
| 175 | + |
|
| 176 | + $html = ''; |
|
| 177 | + |
|
| 178 | + // Only show module selection if this lesson is part of a course |
|
| 179 | + if ($lesson_course && $lesson_course > 0) { |
|
| 180 | + |
|
| 181 | + // Get existing lesson module |
|
| 182 | + $lesson_module = 0; |
|
| 183 | + $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
| 184 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 185 | + foreach ($lesson_module_list as $single_module) { |
|
| 186 | + $lesson_module = $single_module->term_id; |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Get the available modules for this lesson's course |
|
| 192 | + $modules = $this->get_course_modules($lesson_course); |
|
| 193 | + |
|
| 194 | + // Build the HTML to output |
|
| 195 | + $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 196 | + if (is_array($modules) && count($modules) > 0) { |
|
| 197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | + $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 199 | + foreach ($modules as $module) { |
|
| 200 | + $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 201 | + } |
|
| 202 | + $html .= '</select>' . "\n"; |
|
| 203 | + } else { |
|
| 204 | + $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 206 | + } // End If Statement |
|
| 207 | + |
|
| 208 | + } else { |
|
| 209 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 210 | + } // End If Statement |
|
| 211 | + |
|
| 212 | + // Output the HTML |
|
| 213 | + echo $html; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Save module to lesson |
|
| 218 | + * |
|
| 219 | + * @since 1.8.0 |
|
| 220 | + * @param integer $post_id ID of post |
|
| 221 | + * @return mixed Post ID on permissions failure, boolean true on success |
|
| 222 | + */ |
|
| 223 | + public function save_lesson_module($post_id) |
|
| 224 | + { |
|
| 225 | + global $post; |
|
| 226 | + |
|
| 227 | + // Verify post type and nonce |
|
| 228 | + if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | + ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 230 | + return $post_id; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Check if user has permissions to edit lessons |
|
| 234 | + $post_type = get_post_type_object($post->post_type); |
|
| 235 | + if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | + return $post_id; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check if user has permissions to edit this specific post |
|
| 240 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 241 | + return $post_id; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Cast module ID as an integer if selected, otherwise leave as empty string |
|
| 245 | + if ( isset( $_POST['lesson_module'] ) ) { |
|
| 246 | + |
|
| 247 | + if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 249 | + return true; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $module_id = intval( $_POST['lesson_module'] ); |
|
| 253 | + |
|
| 254 | + // Assign lesson to selected module |
|
| 255 | + wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
| 256 | + |
|
| 257 | + // Set default order for lesson inside module |
|
| 258 | + if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | + update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Display course field on new module screen |
|
| 268 | + * |
|
| 269 | + * @since 1.8.0 |
|
| 270 | + * @param object $taxonomy Taxonomy object |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + public function add_module_fields($taxonomy) |
|
| 274 | + { |
|
| 275 | + ?> |
|
| 276 | 276 | <div class="form-field"> |
| 277 | 277 | <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label> |
| 278 | 278 | <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses" |
@@ -281,44 +281,44 @@ discard block |
||
| 281 | 281 | class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span> |
| 282 | 282 | </div> |
| 283 | 283 | <?php |
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Display course field on module edit screen |
|
| 288 | - * |
|
| 289 | - * @since 1.8.0 |
|
| 290 | - * @param object $module Module term object |
|
| 291 | - * @return void |
|
| 292 | - */ |
|
| 293 | - public function edit_module_fields($module) |
|
| 294 | - { |
|
| 295 | - |
|
| 296 | - $module_id = $module->term_id; |
|
| 297 | - |
|
| 298 | - // Get module's existing courses |
|
| 299 | - $args = array( |
|
| 300 | - 'post_type' => 'course', |
|
| 301 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | - 'posts_per_page' => -1, |
|
| 303 | - 'tax_query' => array( |
|
| 304 | - array( |
|
| 305 | - 'taxonomy' => $this->taxonomy, |
|
| 306 | - 'field' => 'id', |
|
| 307 | - 'terms' => $module_id |
|
| 308 | - ) |
|
| 309 | - ) |
|
| 310 | - ); |
|
| 311 | - $courses = get_posts($args); |
|
| 312 | - |
|
| 313 | - //build the defaults array |
|
| 314 | - $module_courses = array(); |
|
| 315 | - if (isset($courses) && is_array($courses)) { |
|
| 316 | - foreach ($courses as $course) { |
|
| 317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - ?> |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Display course field on module edit screen |
|
| 288 | + * |
|
| 289 | + * @since 1.8.0 |
|
| 290 | + * @param object $module Module term object |
|
| 291 | + * @return void |
|
| 292 | + */ |
|
| 293 | + public function edit_module_fields($module) |
|
| 294 | + { |
|
| 295 | + |
|
| 296 | + $module_id = $module->term_id; |
|
| 297 | + |
|
| 298 | + // Get module's existing courses |
|
| 299 | + $args = array( |
|
| 300 | + 'post_type' => 'course', |
|
| 301 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 302 | + 'posts_per_page' => -1, |
|
| 303 | + 'tax_query' => array( |
|
| 304 | + array( |
|
| 305 | + 'taxonomy' => $this->taxonomy, |
|
| 306 | + 'field' => 'id', |
|
| 307 | + 'terms' => $module_id |
|
| 308 | + ) |
|
| 309 | + ) |
|
| 310 | + ); |
|
| 311 | + $courses = get_posts($args); |
|
| 312 | + |
|
| 313 | + //build the defaults array |
|
| 314 | + $module_courses = array(); |
|
| 315 | + if (isset($courses) && is_array($courses)) { |
|
| 316 | + foreach ($courses as $course) { |
|
| 317 | + $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + ?> |
|
| 322 | 322 | <tr class="form-field"> |
| 323 | 323 | <th scope="row" valign="top"><label |
| 324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
@@ -335,1399 +335,1399 @@ discard block |
||
| 335 | 335 | </td> |
| 336 | 336 | </tr> |
| 337 | 337 | <?php |
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Save module course on add/edit |
|
| 342 | - * |
|
| 343 | - * @since 1.8.0 |
|
| 344 | - * @param integer $module_id ID of module |
|
| 345 | - * @return void |
|
| 346 | - */ |
|
| 347 | - public function save_module_course($module_id) |
|
| 348 | - { |
|
| 349 | - |
|
| 350 | - // Get module's existing courses |
|
| 351 | - $args = array( |
|
| 352 | - 'post_type' => 'course', |
|
| 353 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | - 'posts_per_page' => -1, |
|
| 355 | - 'tax_query' => array( |
|
| 356 | - array( |
|
| 357 | - 'taxonomy' => $this->taxonomy, |
|
| 358 | - 'field' => 'id', |
|
| 359 | - 'terms' => $module_id |
|
| 360 | - ) |
|
| 361 | - ) |
|
| 362 | - ); |
|
| 363 | - $courses = get_posts($args); |
|
| 364 | - |
|
| 365 | - // Remove module from existing courses |
|
| 366 | - if (isset($courses) && is_array($courses)) { |
|
| 367 | - foreach ($courses as $course) { |
|
| 368 | - wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Add module to selected courses |
|
| 373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | - |
|
| 375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | - |
|
| 377 | - foreach ( $course_ids as $course_id ) { |
|
| 378 | - |
|
| 379 | - wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | - |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Ajax function to search for courses matching term |
|
| 387 | - * |
|
| 388 | - * @since 1.8.0 |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - public function search_courses_json() |
|
| 392 | - { |
|
| 393 | - |
|
| 394 | - // Security check |
|
| 395 | - check_ajax_referer('search-courses', 'security'); |
|
| 396 | - |
|
| 397 | - // Set content type |
|
| 398 | - header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | - |
|
| 400 | - // Get user input |
|
| 401 | - $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | - |
|
| 403 | - // Return nothing if term is empty |
|
| 404 | - if (empty($term)) |
|
| 405 | - die(); |
|
| 406 | - |
|
| 407 | - // Set a default if none is given |
|
| 408 | - $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | - |
|
| 410 | - // Set up array of results |
|
| 411 | - $found_courses = array('' => $default); |
|
| 412 | - |
|
| 413 | - // Fetch results |
|
| 414 | - $args = array( |
|
| 415 | - 'post_type' => 'course', |
|
| 416 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | - 'posts_per_page' => -1, |
|
| 418 | - 'orderby' => 'title', |
|
| 419 | - 's' => $term |
|
| 420 | - ); |
|
| 421 | - $courses = get_posts($args); |
|
| 422 | - |
|
| 423 | - // Add results to array |
|
| 424 | - if ($courses) { |
|
| 425 | - foreach ($courses as $course) { |
|
| 426 | - $found_courses[$course->ID] = $course->post_title; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // Encode and return results for processing & selection |
|
| 431 | - echo json_encode($found_courses); |
|
| 432 | - die(); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * display modules on single course pages |
|
| 437 | - * |
|
| 438 | - * @since 1.8.0 |
|
| 439 | - * @return void |
|
| 440 | - */ |
|
| 441 | - public function single_course_modules(){ |
|
| 442 | - |
|
| 443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | - // only show modules on the course that has modules |
|
| 445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | - |
|
| 447 | - $this->load_course_module_content_template(); |
|
| 448 | - |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - } // end single_course_modules |
|
| 452 | - |
|
| 453 | - public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | - { |
|
| 455 | - global $post, $current_user; |
|
| 456 | - |
|
| 457 | - $course_id = $post->ID; |
|
| 458 | - $title_text = ''; |
|
| 459 | - |
|
| 460 | - if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | - $is_user_taking_course = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | - if (!$is_user_taking_course) { |
|
| 463 | - if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | - $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | - // Remove brackets for display here |
|
| 466 | - $title_text = str_replace('(', '', $title_text); |
|
| 467 | - $title_text = str_replace(')', '', $title_text); |
|
| 468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | - } |
|
| 470 | - $title .= ' ' . $title_text; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return $title; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - public function module_breadcrumb_link($html, $separator) |
|
| 478 | - { |
|
| 479 | - global $post; |
|
| 480 | - // Lesson |
|
| 481 | - if (is_singular('lesson')) { |
|
| 482 | - if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | - $module = $this->get_lesson_module($post->ID); |
|
| 484 | - if( $module ) { |
|
| 485 | - $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - // Module |
|
| 490 | - if (is_tax($this->taxonomy)) { |
|
| 491 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | - $course_id = intval($_GET['course_id']); |
|
| 493 | - $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $html; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | - * |
|
| 502 | - * @since 1.8.0 |
|
| 503 | - * @param string $template Default template |
|
| 504 | - * @return string Modified template |
|
| 505 | - */ |
|
| 506 | - public function module_archive_template($template) { |
|
| 507 | - |
|
| 508 | - if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | - return $template; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $file = 'archive-lesson.php'; |
|
| 513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | - |
|
| 515 | - // locate the template file |
|
| 516 | - $template = locate_template($find); |
|
| 517 | - if (!$template) { |
|
| 518 | - |
|
| 519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | - |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - return $template; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Modify module taxonomy archive query |
|
| 529 | - * |
|
| 530 | - * @since 1.8.0 |
|
| 531 | - * @param object $query The query object passed by reference |
|
| 532 | - * @return void |
|
| 533 | - */ |
|
| 534 | - public function module_archive_filter($query) |
|
| 535 | - { |
|
| 536 | - if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - // Limit to lessons only |
|
| 540 | - $query->set('post_type', 'lesson'); |
|
| 541 | - |
|
| 542 | - // Set order of lessons |
|
| 543 | - if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | - $module_id = $query->queried_object_id; |
|
| 545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | - $query->set('orderby', 'meta_value_num date'); |
|
| 547 | - } else { |
|
| 548 | - $query->set('orderby', 'menu_order'); |
|
| 549 | - } |
|
| 550 | - $query->set('order', 'ASC'); |
|
| 551 | - |
|
| 552 | - // Limit to specific course if specified |
|
| 553 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | - $course_id = intval($_GET['course_id']); |
|
| 555 | - $meta_query[] = array( |
|
| 556 | - 'key' => '_lesson_course', |
|
| 557 | - 'value' => intval($course_id) |
|
| 558 | - ); |
|
| 559 | - $query->set('meta_query', $meta_query); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Modify archive page title |
|
| 567 | - * |
|
| 568 | - * @since 1.8.0 |
|
| 569 | - * @param string $title Default title |
|
| 570 | - * @return string Modified title |
|
| 571 | - */ |
|
| 572 | - public function module_archive_title($title) |
|
| 573 | - { |
|
| 574 | - if (is_tax($this->taxonomy)) { |
|
| 575 | - $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | - } |
|
| 577 | - return $title; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Display module description on taxonomy archive page |
|
| 582 | - * |
|
| 583 | - * @since 1.8.0 |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - public function module_archive_description() |
|
| 587 | - { |
|
| 588 | - if (is_tax($this->taxonomy)) { |
|
| 589 | - |
|
| 590 | - $module = get_queried_object(); |
|
| 591 | - |
|
| 592 | - $module_progress = false; |
|
| 593 | - if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | - global $current_user; |
|
| 595 | - wp_get_current_user(); |
|
| 596 | - $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if ($module_progress && $module_progress > 0) { |
|
| 600 | - $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | - $class = 'completed'; |
|
| 602 | - if ($module_progress < 100) { |
|
| 603 | - $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | - $class = 'in-progress'; |
|
| 605 | - } |
|
| 606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - public function module_archive_body_class($classes) |
|
| 614 | - { |
|
| 615 | - if (is_tax($this->taxonomy)) { |
|
| 616 | - $classes[] = 'module-archive'; |
|
| 617 | - } |
|
| 618 | - return $classes; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Display module navigation links on module taxonomy archive page |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * @return void |
|
| 626 | - */ |
|
| 627 | - public function module_navigation_links() |
|
| 628 | - { |
|
| 629 | - if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | - |
|
| 631 | - $queried_module = get_queried_object(); |
|
| 632 | - $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | - |
|
| 634 | - $prev_module = false; |
|
| 635 | - $next_module = false; |
|
| 636 | - $on_current = false; |
|
| 637 | - foreach ($course_modules as $module) { |
|
| 638 | - $this_module = $module; |
|
| 639 | - if ($on_current) { |
|
| 640 | - $next_module = $this_module; |
|
| 641 | - break; |
|
| 642 | - } |
|
| 643 | - if ($this_module == $queried_module) { |
|
| 644 | - $on_current = true; |
|
| 645 | - } else { |
|
| 646 | - $prev_module = $module; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - ?> |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Save module course on add/edit |
|
| 342 | + * |
|
| 343 | + * @since 1.8.0 |
|
| 344 | + * @param integer $module_id ID of module |
|
| 345 | + * @return void |
|
| 346 | + */ |
|
| 347 | + public function save_module_course($module_id) |
|
| 348 | + { |
|
| 349 | + |
|
| 350 | + // Get module's existing courses |
|
| 351 | + $args = array( |
|
| 352 | + 'post_type' => 'course', |
|
| 353 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 354 | + 'posts_per_page' => -1, |
|
| 355 | + 'tax_query' => array( |
|
| 356 | + array( |
|
| 357 | + 'taxonomy' => $this->taxonomy, |
|
| 358 | + 'field' => 'id', |
|
| 359 | + 'terms' => $module_id |
|
| 360 | + ) |
|
| 361 | + ) |
|
| 362 | + ); |
|
| 363 | + $courses = get_posts($args); |
|
| 364 | + |
|
| 365 | + // Remove module from existing courses |
|
| 366 | + if (isset($courses) && is_array($courses)) { |
|
| 367 | + foreach ($courses as $course) { |
|
| 368 | + wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Add module to selected courses |
|
| 373 | + if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 374 | + |
|
| 375 | + $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 376 | + |
|
| 377 | + foreach ( $course_ids as $course_id ) { |
|
| 378 | + |
|
| 379 | + wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
| 380 | + |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Ajax function to search for courses matching term |
|
| 387 | + * |
|
| 388 | + * @since 1.8.0 |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + public function search_courses_json() |
|
| 392 | + { |
|
| 393 | + |
|
| 394 | + // Security check |
|
| 395 | + check_ajax_referer('search-courses', 'security'); |
|
| 396 | + |
|
| 397 | + // Set content type |
|
| 398 | + header('Content-Type: application/json; charset=utf-8'); |
|
| 399 | + |
|
| 400 | + // Get user input |
|
| 401 | + $term = urldecode(stripslashes($_GET['term'])); |
|
| 402 | + |
|
| 403 | + // Return nothing if term is empty |
|
| 404 | + if (empty($term)) |
|
| 405 | + die(); |
|
| 406 | + |
|
| 407 | + // Set a default if none is given |
|
| 408 | + $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
| 409 | + |
|
| 410 | + // Set up array of results |
|
| 411 | + $found_courses = array('' => $default); |
|
| 412 | + |
|
| 413 | + // Fetch results |
|
| 414 | + $args = array( |
|
| 415 | + 'post_type' => 'course', |
|
| 416 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
| 417 | + 'posts_per_page' => -1, |
|
| 418 | + 'orderby' => 'title', |
|
| 419 | + 's' => $term |
|
| 420 | + ); |
|
| 421 | + $courses = get_posts($args); |
|
| 422 | + |
|
| 423 | + // Add results to array |
|
| 424 | + if ($courses) { |
|
| 425 | + foreach ($courses as $course) { |
|
| 426 | + $found_courses[$course->ID] = $course->post_title; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // Encode and return results for processing & selection |
|
| 431 | + echo json_encode($found_courses); |
|
| 432 | + die(); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * display modules on single course pages |
|
| 437 | + * |
|
| 438 | + * @since 1.8.0 |
|
| 439 | + * @return void |
|
| 440 | + */ |
|
| 441 | + public function single_course_modules(){ |
|
| 442 | + |
|
| 443 | + _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | + // only show modules on the course that has modules |
|
| 445 | + if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 446 | + |
|
| 447 | + $this->load_course_module_content_template(); |
|
| 448 | + |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + } // end single_course_modules |
|
| 452 | + |
|
| 453 | + public function sensei_course_preview_titles($title, $lesson_id) |
|
| 454 | + { |
|
| 455 | + global $post, $current_user; |
|
| 456 | + |
|
| 457 | + $course_id = $post->ID; |
|
| 458 | + $title_text = ''; |
|
| 459 | + |
|
| 460 | + if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
| 461 | + $is_user_taking_course = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
| 462 | + if (!$is_user_taking_course) { |
|
| 463 | + if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
| 464 | + $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
| 465 | + // Remove brackets for display here |
|
| 466 | + $title_text = str_replace('(', '', $title_text); |
|
| 467 | + $title_text = str_replace(')', '', $title_text); |
|
| 468 | + $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 469 | + } |
|
| 470 | + $title .= ' ' . $title_text; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return $title; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + public function module_breadcrumb_link($html, $separator) |
|
| 478 | + { |
|
| 479 | + global $post; |
|
| 480 | + // Lesson |
|
| 481 | + if (is_singular('lesson')) { |
|
| 482 | + if (has_term('', $this->taxonomy, $post->ID)) { |
|
| 483 | + $module = $this->get_lesson_module($post->ID); |
|
| 484 | + if( $module ) { |
|
| 485 | + $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + // Module |
|
| 490 | + if (is_tax($this->taxonomy)) { |
|
| 491 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 492 | + $course_id = intval($_GET['course_id']); |
|
| 493 | + $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $html; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Set lesson archive template to display on module taxonomy archive page |
|
| 501 | + * |
|
| 502 | + * @since 1.8.0 |
|
| 503 | + * @param string $template Default template |
|
| 504 | + * @return string Modified template |
|
| 505 | + */ |
|
| 506 | + public function module_archive_template($template) { |
|
| 507 | + |
|
| 508 | + if ( ! is_tax($this->taxonomy) ) { |
|
| 509 | + return $template; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $file = 'archive-lesson.php'; |
|
| 513 | + $find = array( $file, Sensei()->template_url . $file ); |
|
| 514 | + |
|
| 515 | + // locate the template file |
|
| 516 | + $template = locate_template($find); |
|
| 517 | + if (!$template) { |
|
| 518 | + |
|
| 519 | + $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 520 | + |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + return $template; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Modify module taxonomy archive query |
|
| 529 | + * |
|
| 530 | + * @since 1.8.0 |
|
| 531 | + * @param object $query The query object passed by reference |
|
| 532 | + * @return void |
|
| 533 | + */ |
|
| 534 | + public function module_archive_filter($query) |
|
| 535 | + { |
|
| 536 | + if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + // Limit to lessons only |
|
| 540 | + $query->set('post_type', 'lesson'); |
|
| 541 | + |
|
| 542 | + // Set order of lessons |
|
| 543 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 544 | + $module_id = $query->queried_object_id; |
|
| 545 | + $query->set('meta_key', '_order_module_' . $module_id); |
|
| 546 | + $query->set('orderby', 'meta_value_num date'); |
|
| 547 | + } else { |
|
| 548 | + $query->set('orderby', 'menu_order'); |
|
| 549 | + } |
|
| 550 | + $query->set('order', 'ASC'); |
|
| 551 | + |
|
| 552 | + // Limit to specific course if specified |
|
| 553 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 554 | + $course_id = intval($_GET['course_id']); |
|
| 555 | + $meta_query[] = array( |
|
| 556 | + 'key' => '_lesson_course', |
|
| 557 | + 'value' => intval($course_id) |
|
| 558 | + ); |
|
| 559 | + $query->set('meta_query', $meta_query); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Modify archive page title |
|
| 567 | + * |
|
| 568 | + * @since 1.8.0 |
|
| 569 | + * @param string $title Default title |
|
| 570 | + * @return string Modified title |
|
| 571 | + */ |
|
| 572 | + public function module_archive_title($title) |
|
| 573 | + { |
|
| 574 | + if (is_tax($this->taxonomy)) { |
|
| 575 | + $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
| 576 | + } |
|
| 577 | + return $title; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Display module description on taxonomy archive page |
|
| 582 | + * |
|
| 583 | + * @since 1.8.0 |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + public function module_archive_description() |
|
| 587 | + { |
|
| 588 | + if (is_tax($this->taxonomy)) { |
|
| 589 | + |
|
| 590 | + $module = get_queried_object(); |
|
| 591 | + |
|
| 592 | + $module_progress = false; |
|
| 593 | + if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
| 594 | + global $current_user; |
|
| 595 | + wp_get_current_user(); |
|
| 596 | + $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if ($module_progress && $module_progress > 0) { |
|
| 600 | + $status = __('Completed', 'woothemes-sensei'); |
|
| 601 | + $class = 'completed'; |
|
| 602 | + if ($module_progress < 100) { |
|
| 603 | + $status = __('In progress', 'woothemes-sensei'); |
|
| 604 | + $class = 'in-progress'; |
|
| 605 | + } |
|
| 606 | + echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + public function module_archive_body_class($classes) |
|
| 614 | + { |
|
| 615 | + if (is_tax($this->taxonomy)) { |
|
| 616 | + $classes[] = 'module-archive'; |
|
| 617 | + } |
|
| 618 | + return $classes; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Display module navigation links on module taxonomy archive page |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * @return void |
|
| 626 | + */ |
|
| 627 | + public function module_navigation_links() |
|
| 628 | + { |
|
| 629 | + if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
| 630 | + |
|
| 631 | + $queried_module = get_queried_object(); |
|
| 632 | + $course_modules = $this->get_course_modules($_GET['course_id']); |
|
| 633 | + |
|
| 634 | + $prev_module = false; |
|
| 635 | + $next_module = false; |
|
| 636 | + $on_current = false; |
|
| 637 | + foreach ($course_modules as $module) { |
|
| 638 | + $this_module = $module; |
|
| 639 | + if ($on_current) { |
|
| 640 | + $next_module = $this_module; |
|
| 641 | + break; |
|
| 642 | + } |
|
| 643 | + if ($this_module == $queried_module) { |
|
| 644 | + $on_current = true; |
|
| 645 | + } else { |
|
| 646 | + $prev_module = $module; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + ?> |
|
| 651 | 651 | <div id="post-entries" class="post-entries module-navigation fix"> |
| 652 | 652 | <?php if ($next_module) { |
| 653 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | - ?> |
|
| 653 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
| 654 | + ?> |
|
| 655 | 655 | <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>" |
| 656 | 656 | title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?> |
| 657 | 657 | <span class="meta-nav"></span></a></div> |
| 658 | 658 | <?php } ?> |
| 659 | 659 | <?php if ($prev_module) { |
| 660 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | - ?> |
|
| 660 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
| 661 | + ?> |
|
| 662 | 662 | <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>" |
| 663 | 663 | title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span |
| 664 | 664 | class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div> |
| 665 | 665 | <?php } ?> |
| 666 | 666 | </div> |
| 667 | 667 | <?php |
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | - * |
|
| 674 | - * @since 1.8.0 |
|
| 675 | - * @param string $status Status of the lesson for the user |
|
| 676 | - * @param integer $user_id ID of user |
|
| 677 | - * @param integer $lesson_id ID of lesson |
|
| 678 | - * @return void |
|
| 679 | - */ |
|
| 680 | - public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | - { |
|
| 682 | - $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Save lesson's module progress for a specific user |
|
| 687 | - * |
|
| 688 | - * @since 1.8.0 |
|
| 689 | - * @param integer $user_id ID of user |
|
| 690 | - * @param integer $lesson_id ID of lesson |
|
| 691 | - * @return void |
|
| 692 | - */ |
|
| 693 | - public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | - { |
|
| 695 | - $module = $this->get_lesson_module($lesson_id); |
|
| 696 | - $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | - if ($module && $course_id) { |
|
| 698 | - $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Save progress of module for user |
|
| 704 | - * |
|
| 705 | - * @since 1.8.0 |
|
| 706 | - * @return void |
|
| 707 | - */ |
|
| 708 | - public function save_module_progress() |
|
| 709 | - { |
|
| 710 | - if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | - global $current_user; |
|
| 712 | - wp_get_current_user(); |
|
| 713 | - $user_id = $current_user->ID; |
|
| 714 | - |
|
| 715 | - $module = get_queried_object(); |
|
| 716 | - |
|
| 717 | - $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Save module progess for user |
|
| 723 | - * |
|
| 724 | - * @since 1.8.0 |
|
| 725 | - * |
|
| 726 | - * @param integer $module_id ID of module |
|
| 727 | - * @param integer $course_id ID of course |
|
| 728 | - * @param integer $user_id ID of user |
|
| 729 | - * @return void |
|
| 730 | - */ |
|
| 731 | - public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | - { |
|
| 733 | - $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | - update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | - |
|
| 736 | - do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Get module progress for a user |
|
| 741 | - * |
|
| 742 | - * @since 1.8.0 |
|
| 743 | - * |
|
| 744 | - * @param integer $module_id ID of module |
|
| 745 | - * @param integer $course_id ID of course |
|
| 746 | - * @param integer $user_id ID of user |
|
| 747 | - * @return mixed Module progress percentage on success, false on failure |
|
| 748 | - */ |
|
| 749 | - public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | - { |
|
| 751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | - if ($module_progress) { |
|
| 753 | - return (float)$module_progress; |
|
| 754 | - } |
|
| 755 | - return false; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Calculate module progess for user |
|
| 760 | - * |
|
| 761 | - * @since 1.8.0 |
|
| 762 | - * |
|
| 763 | - * @param integer $user_id ID of user |
|
| 764 | - * @param integer $module_id ID of module |
|
| 765 | - * @param integer $course_id ID of course |
|
| 766 | - * @return integer Module progress percentage |
|
| 767 | - */ |
|
| 768 | - public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | - { |
|
| 770 | - |
|
| 771 | - $args = array( |
|
| 772 | - 'post_type' => 'lesson', |
|
| 773 | - 'post_status' => 'publish', |
|
| 774 | - 'posts_per_page' => -1, |
|
| 775 | - 'tax_query' => array( |
|
| 776 | - array( |
|
| 777 | - 'taxonomy' => $this->taxonomy, |
|
| 778 | - 'field' => 'id', |
|
| 779 | - 'terms' => $module_id |
|
| 780 | - ) |
|
| 781 | - ), |
|
| 782 | - 'meta_query' => array( |
|
| 783 | - array( |
|
| 784 | - 'key' => '_lesson_course', |
|
| 785 | - 'value' => $course_id |
|
| 786 | - ) |
|
| 787 | - ), |
|
| 788 | - 'fields' => 'ids' |
|
| 789 | - ); |
|
| 790 | - $lessons = get_posts($args); |
|
| 791 | - |
|
| 792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | - |
|
| 794 | - $completed = false; |
|
| 795 | - $lesson_count = 0; |
|
| 796 | - $completed_count = 0; |
|
| 797 | - foreach ($lessons as $lesson_id) { |
|
| 798 | - $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | - ++$lesson_count; |
|
| 800 | - if ($completed) { |
|
| 801 | - ++$completed_count; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | - |
|
| 806 | - return (float)$module_progress; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Register admin screen for ordering modules |
|
| 811 | - * |
|
| 812 | - * @since 1.8.0 |
|
| 813 | - * |
|
| 814 | - * @return void |
|
| 815 | - */ |
|
| 816 | - public function register_modules_admin_menu_items() |
|
| 817 | - { |
|
| 818 | - //add the modules link under the Course main menu |
|
| 819 | - add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | - |
|
| 821 | - // Regsiter new admin page for module ordering |
|
| 822 | - $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | - |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Display Module Order screen |
|
| 828 | - * |
|
| 829 | - * @since 1.8.0 |
|
| 830 | - * |
|
| 831 | - * @return void |
|
| 832 | - */ |
|
| 833 | - public function module_order_screen() |
|
| 834 | - { |
|
| 835 | - ?> |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
| 673 | + * |
|
| 674 | + * @since 1.8.0 |
|
| 675 | + * @param string $status Status of the lesson for the user |
|
| 676 | + * @param integer $user_id ID of user |
|
| 677 | + * @param integer $lesson_id ID of lesson |
|
| 678 | + * @return void |
|
| 679 | + */ |
|
| 680 | + public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
| 681 | + { |
|
| 682 | + $this->save_lesson_module_progress($user_id, $lesson_id); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Save lesson's module progress for a specific user |
|
| 687 | + * |
|
| 688 | + * @since 1.8.0 |
|
| 689 | + * @param integer $user_id ID of user |
|
| 690 | + * @param integer $lesson_id ID of lesson |
|
| 691 | + * @return void |
|
| 692 | + */ |
|
| 693 | + public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
| 694 | + { |
|
| 695 | + $module = $this->get_lesson_module($lesson_id); |
|
| 696 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 697 | + if ($module && $course_id) { |
|
| 698 | + $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Save progress of module for user |
|
| 704 | + * |
|
| 705 | + * @since 1.8.0 |
|
| 706 | + * @return void |
|
| 707 | + */ |
|
| 708 | + public function save_module_progress() |
|
| 709 | + { |
|
| 710 | + if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
| 711 | + global $current_user; |
|
| 712 | + wp_get_current_user(); |
|
| 713 | + $user_id = $current_user->ID; |
|
| 714 | + |
|
| 715 | + $module = get_queried_object(); |
|
| 716 | + |
|
| 717 | + $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Save module progess for user |
|
| 723 | + * |
|
| 724 | + * @since 1.8.0 |
|
| 725 | + * |
|
| 726 | + * @param integer $module_id ID of module |
|
| 727 | + * @param integer $course_id ID of course |
|
| 728 | + * @param integer $user_id ID of user |
|
| 729 | + * @return void |
|
| 730 | + */ |
|
| 731 | + public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 732 | + { |
|
| 733 | + $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
| 734 | + update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 735 | + |
|
| 736 | + do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Get module progress for a user |
|
| 741 | + * |
|
| 742 | + * @since 1.8.0 |
|
| 743 | + * |
|
| 744 | + * @param integer $module_id ID of module |
|
| 745 | + * @param integer $course_id ID of course |
|
| 746 | + * @param integer $user_id ID of user |
|
| 747 | + * @return mixed Module progress percentage on success, false on failure |
|
| 748 | + */ |
|
| 749 | + public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
| 750 | + { |
|
| 751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 752 | + if ($module_progress) { |
|
| 753 | + return (float)$module_progress; |
|
| 754 | + } |
|
| 755 | + return false; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Calculate module progess for user |
|
| 760 | + * |
|
| 761 | + * @since 1.8.0 |
|
| 762 | + * |
|
| 763 | + * @param integer $user_id ID of user |
|
| 764 | + * @param integer $module_id ID of module |
|
| 765 | + * @param integer $course_id ID of course |
|
| 766 | + * @return integer Module progress percentage |
|
| 767 | + */ |
|
| 768 | + public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
| 769 | + { |
|
| 770 | + |
|
| 771 | + $args = array( |
|
| 772 | + 'post_type' => 'lesson', |
|
| 773 | + 'post_status' => 'publish', |
|
| 774 | + 'posts_per_page' => -1, |
|
| 775 | + 'tax_query' => array( |
|
| 776 | + array( |
|
| 777 | + 'taxonomy' => $this->taxonomy, |
|
| 778 | + 'field' => 'id', |
|
| 779 | + 'terms' => $module_id |
|
| 780 | + ) |
|
| 781 | + ), |
|
| 782 | + 'meta_query' => array( |
|
| 783 | + array( |
|
| 784 | + 'key' => '_lesson_course', |
|
| 785 | + 'value' => $course_id |
|
| 786 | + ) |
|
| 787 | + ), |
|
| 788 | + 'fields' => 'ids' |
|
| 789 | + ); |
|
| 790 | + $lessons = get_posts($args); |
|
| 791 | + |
|
| 792 | + if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 793 | + |
|
| 794 | + $completed = false; |
|
| 795 | + $lesson_count = 0; |
|
| 796 | + $completed_count = 0; |
|
| 797 | + foreach ($lessons as $lesson_id) { |
|
| 798 | + $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
| 799 | + ++$lesson_count; |
|
| 800 | + if ($completed) { |
|
| 801 | + ++$completed_count; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $module_progress = ($completed_count / $lesson_count) * 100; |
|
| 805 | + |
|
| 806 | + return (float)$module_progress; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Register admin screen for ordering modules |
|
| 811 | + * |
|
| 812 | + * @since 1.8.0 |
|
| 813 | + * |
|
| 814 | + * @return void |
|
| 815 | + */ |
|
| 816 | + public function register_modules_admin_menu_items() |
|
| 817 | + { |
|
| 818 | + //add the modules link under the Course main menu |
|
| 819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 820 | + |
|
| 821 | + // Regsiter new admin page for module ordering |
|
| 822 | + $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
| 823 | + |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Display Module Order screen |
|
| 828 | + * |
|
| 829 | + * @since 1.8.0 |
|
| 830 | + * |
|
| 831 | + * @return void |
|
| 832 | + */ |
|
| 833 | + public function module_order_screen() |
|
| 834 | + { |
|
| 835 | + ?> |
|
| 836 | 836 | <div id="<?php echo esc_attr($this->order_page_slug); ?>" |
| 837 | 837 | class="wrap <?php echo esc_attr($this->order_page_slug); ?>"> |
| 838 | 838 | <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php |
| 839 | 839 | |
| 840 | - $html = ''; |
|
| 841 | - |
|
| 842 | - if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | - $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | - |
|
| 845 | - if ($ordered) { |
|
| 846 | - $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | - $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | - $html .= '</div>' . "\n"; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - $courses = Sensei()->course->get_all_courses(); |
|
| 853 | - |
|
| 854 | - $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | - $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | - $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | - $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | - $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | - |
|
| 860 | - foreach ($courses as $course) { |
|
| 861 | - if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | - $course_id = ''; |
|
| 863 | - if (isset($_GET['course_id'])) { |
|
| 864 | - $course_id = intval($_GET['course_id']); |
|
| 865 | - } |
|
| 866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - $html .= '</select>' . "\n"; |
|
| 871 | - $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | - $html .= '</form>' . "\n"; |
|
| 873 | - |
|
| 874 | - if (isset($_GET['course_id'])) { |
|
| 875 | - $course_id = intval($_GET['course_id']); |
|
| 876 | - if ($course_id > 0) { |
|
| 877 | - $modules = $this->get_course_modules($course_id); |
|
| 878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | - if ($modules) { |
|
| 880 | - |
|
| 881 | - $order = $this->get_course_module_order($course_id); |
|
| 882 | - |
|
| 883 | - $order_string=''; |
|
| 884 | - if ($order) { |
|
| 885 | - $order_string = implode(',', $order); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | - $count = 0; |
|
| 891 | - foreach ($modules as $module) { |
|
| 892 | - $count++; |
|
| 893 | - $class = $this->taxonomy; |
|
| 894 | - if ($count == 1) { |
|
| 895 | - $class .= ' first'; |
|
| 896 | - } |
|
| 897 | - if ($count == count($module)) { |
|
| 898 | - $class .= ' last'; |
|
| 899 | - } |
|
| 900 | - if ($count % 2 != 0) { |
|
| 901 | - $class .= ' alternate'; |
|
| 902 | - } |
|
| 903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | - } |
|
| 905 | - $html .= '</ul>' . "\n"; |
|
| 906 | - |
|
| 907 | - $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | - $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | - $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - echo $html; |
|
| 916 | - |
|
| 917 | - ?></div><?php |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Add 'Module order' column to courses list table |
|
| 922 | - * |
|
| 923 | - * @since 1.8.0 |
|
| 924 | - * |
|
| 925 | - * @param array $columns Existing columns |
|
| 926 | - * @return array Modifed columns |
|
| 927 | - */ |
|
| 928 | - public function course_columns($columns = array()) |
|
| 929 | - { |
|
| 930 | - $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | - return $columns; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Load content in 'Module order' column |
|
| 936 | - * |
|
| 937 | - * @since 1.8.0 |
|
| 938 | - * |
|
| 939 | - * @param string $column Current column name |
|
| 940 | - * @param integer $course_id ID of course |
|
| 941 | - * @return void |
|
| 942 | - */ |
|
| 943 | - public function course_column_content($column = '', $course_id = 0) |
|
| 944 | - { |
|
| 945 | - if ($column == 'module_order') { |
|
| 946 | - if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | - echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * Save module order for course |
|
| 954 | - * |
|
| 955 | - * @since 1.8.0 |
|
| 956 | - * |
|
| 957 | - * @param string $order_string Comma-separated string of module IDs |
|
| 958 | - * @param integer $course_id ID of course |
|
| 959 | - * @return boolean True on success, false on failure |
|
| 960 | - */ |
|
| 961 | - private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | - { |
|
| 963 | - if ($order_string && $course_id) { |
|
| 964 | - $order = explode(',', $order_string); |
|
| 965 | - update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | - return true; |
|
| 967 | - } |
|
| 968 | - return false; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Get module order for course |
|
| 973 | - * |
|
| 974 | - * @since 1.8.0 |
|
| 975 | - * |
|
| 976 | - * @param integer $course_id ID of course |
|
| 977 | - * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | - */ |
|
| 979 | - public function get_course_module_order($course_id = 0) |
|
| 980 | - { |
|
| 981 | - if ($course_id) { |
|
| 982 | - $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | - return $order; |
|
| 984 | - } |
|
| 985 | - return false; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Modify module taxonomy columns |
|
| 990 | - * |
|
| 991 | - * @since 1.8.0 |
|
| 992 | - * |
|
| 993 | - * @param array $columns Default columns |
|
| 994 | - * @return array Modified columns |
|
| 995 | - */ |
|
| 996 | - public function taxonomy_column_headings($columns) |
|
| 997 | - { |
|
| 998 | - |
|
| 999 | - unset($columns['posts']); |
|
| 1000 | - |
|
| 1001 | - $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | - |
|
| 1003 | - return $columns; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Manage content in custom module taxonomy columns |
|
| 1008 | - * |
|
| 1009 | - * @since 1.8.0 |
|
| 1010 | - * |
|
| 1011 | - * @param string $column_data Default data for column |
|
| 1012 | - * @param string $column_name Name of current column |
|
| 1013 | - * @param integer $term_id ID of current term |
|
| 1014 | - * @return string Modified column data |
|
| 1015 | - */ |
|
| 1016 | - public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | - { |
|
| 1018 | - |
|
| 1019 | - $args = array( |
|
| 1020 | - 'post_status' => 'publish', |
|
| 1021 | - 'posts_per_page' => -1, |
|
| 1022 | - 'tax_query' => array( |
|
| 1023 | - array( |
|
| 1024 | - 'taxonomy' => $this->taxonomy, |
|
| 1025 | - 'field' => 'id', |
|
| 1026 | - 'terms' => intval($term_id) |
|
| 1027 | - ) |
|
| 1028 | - ) |
|
| 1029 | - ); |
|
| 1030 | - |
|
| 1031 | - $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | - |
|
| 1033 | - switch ($column_name) { |
|
| 1034 | - |
|
| 1035 | - case 'lessons': |
|
| 1036 | - $args['post_type'] = 'lesson'; |
|
| 1037 | - $lessons = get_posts($args); |
|
| 1038 | - $total_lessons = count($lessons); |
|
| 1039 | - $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return $column_data; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | - * |
|
| 1049 | - * @since 1.8.0 |
|
| 1050 | - * |
|
| 1051 | - * @param array $columns Default columns |
|
| 1052 | - * @return array Modified columns |
|
| 1053 | - */ |
|
| 1054 | - public function analysis_overview_column_title($columns) |
|
| 1055 | - { |
|
| 1056 | - |
|
| 1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | - $new_columns = array(); |
|
| 1059 | - if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | - foreach ($columns as $column => $title) { |
|
| 1061 | - $new_columns[$column] = $title; |
|
| 1062 | - if ($column == 'title') { |
|
| 1063 | - $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - if (0 < count($new_columns)) { |
|
| 1069 | - return $new_columns; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $columns; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | - * |
|
| 1079 | - * @since 1.8.0 |
|
| 1080 | - * |
|
| 1081 | - * @param array $columns Table column data |
|
| 1082 | - * @param WP_Post $lesson |
|
| 1083 | - * @return array Updated column data |
|
| 1084 | - */ |
|
| 1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | - { |
|
| 1087 | - |
|
| 1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | - $lesson_module = ''; |
|
| 1090 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | - foreach ($lesson_module_list as $single_module) { |
|
| 1093 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | - break; |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - $columns['lesson_module'] = $lesson_module; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - return $columns; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Add 'Module' columns to Analysis Course table |
|
| 1106 | - * |
|
| 1107 | - * @since 1.8.0 |
|
| 1108 | - * |
|
| 1109 | - * @param array $columns Default columns |
|
| 1110 | - * @return array Modified columns |
|
| 1111 | - */ |
|
| 1112 | - public function analysis_course_column_title($columns) |
|
| 1113 | - { |
|
| 1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | - $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | - } |
|
| 1117 | - return $columns; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * Data for 'Module' column in Analysis Course table |
|
| 1122 | - * |
|
| 1123 | - * @since 1.8.0 |
|
| 1124 | - * |
|
| 1125 | - * @param array $columns Table column data |
|
| 1126 | - * @param WP_Post $lesson |
|
| 1127 | - * @return array Updated columns data |
|
| 1128 | - */ |
|
| 1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | - { |
|
| 1131 | - |
|
| 1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | - $lesson_module = ''; |
|
| 1134 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | - foreach ($lesson_module_list as $single_module) { |
|
| 1137 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | - break; |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $columns['lesson_module'] = $lesson_module; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - return $columns; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * Get module for lesson |
|
| 1150 | - * |
|
| 1151 | - * This function also checks if the module still |
|
| 1152 | - * exists on the course before returning it. Although |
|
| 1153 | - * the lesson has a module the same module must exist on the |
|
| 1154 | - * course for it to be valid. |
|
| 1155 | - * |
|
| 1156 | - * @since 1.8.0 |
|
| 1157 | - * |
|
| 1158 | - * @param integer $lesson_id ID of lesson |
|
| 1159 | - * @return object Module taxonomy term object |
|
| 1160 | - */ |
|
| 1161 | - public function get_lesson_module($lesson_id = 0) |
|
| 1162 | - { |
|
| 1163 | - $lesson_id = intval($lesson_id); |
|
| 1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | - return false; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - // get taxonomy terms on this lesson |
|
| 1169 | - $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | - |
|
| 1171 | - //check if error returned |
|
| 1172 | - if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | - return false; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - // get the last item in the array there should be only be 1 really. |
|
| 1177 | - // this method works for all php versions. |
|
| 1178 | - foreach( $modules as $module ){ |
|
| 1179 | - break; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | - return false; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | - $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | - if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | - |
|
| 1190 | - // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | - return false; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | - } |
|
| 1197 | - return $module; |
|
| 1198 | - |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Get ordered array of all modules in course |
|
| 1203 | - * |
|
| 1204 | - * @since 1.8.0 |
|
| 1205 | - * |
|
| 1206 | - * @param integer $course_id ID of course |
|
| 1207 | - * @return array Ordered array of module taxonomy term objects |
|
| 1208 | - */ |
|
| 1209 | - public function get_course_modules($course_id = 0) |
|
| 1210 | - { |
|
| 1211 | - $course_id = intval($course_id); |
|
| 1212 | - if (0 < $course_id) { |
|
| 1213 | - |
|
| 1214 | - // Get modules for course |
|
| 1215 | - $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | - |
|
| 1217 | - // Get custom module order for course |
|
| 1218 | - $order = $this->get_course_module_order($course_id); |
|
| 1219 | - |
|
| 1220 | - // Sort by custom order if custom order exists |
|
| 1221 | - if ($order) { |
|
| 1222 | - $ordered_modules = array(); |
|
| 1223 | - $unordered_modules = array(); |
|
| 1224 | - foreach ($modules as $module) { |
|
| 1225 | - $order_key = array_search($module->term_id, $order); |
|
| 1226 | - if ($order_key !== false) { |
|
| 1227 | - $ordered_modules[$order_key] = $module; |
|
| 1228 | - } else { |
|
| 1229 | - $unordered_modules[] = $module; |
|
| 1230 | - } |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // Order modules correctly |
|
| 1234 | - ksort($ordered_modules); |
|
| 1235 | - |
|
| 1236 | - // Append modules that have not yet been ordered |
|
| 1237 | - if (count($unordered_modules) > 0) { |
|
| 1238 | - $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - } else { |
|
| 1242 | - |
|
| 1243 | - $ordered_modules = $modules; |
|
| 1244 | - |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - return $ordered_modules; |
|
| 1248 | - |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - return false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Load frontend CSS |
|
| 1256 | - * |
|
| 1257 | - * @since 1.8.0 |
|
| 1258 | - * |
|
| 1259 | - * @return void |
|
| 1260 | - */ |
|
| 1261 | - public function enqueue_styles() |
|
| 1262 | - { |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Load admin Javascript |
|
| 1271 | - * |
|
| 1272 | - * @since 1.8.0 |
|
| 1273 | - * |
|
| 1274 | - * @return void |
|
| 1275 | - */ |
|
| 1276 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | - * |
|
| 1281 | - * @param array $white_listed_pages |
|
| 1282 | - */ |
|
| 1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | - 'edit-tags.php', |
|
| 1285 | - 'course_page_module-order', |
|
| 1286 | - 'post-new.php', |
|
| 1287 | - 'post.php' |
|
| 1288 | - ) ); |
|
| 1289 | - |
|
| 1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | - return; |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | - |
|
| 1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | - wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | - |
|
| 1300 | - // localized module data |
|
| 1301 | - $localize_modulesAdmin = array( |
|
| 1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | - ); |
|
| 1305 | - |
|
| 1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Load admin CSS |
|
| 1311 | - * |
|
| 1312 | - * @since 1.8.0 |
|
| 1313 | - * |
|
| 1314 | - * @return void |
|
| 1315 | - */ |
|
| 1316 | - public function admin_enqueue_styles() { |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | - |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * Show the title modules on the single course template. |
|
| 1326 | - * |
|
| 1327 | - * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | - * |
|
| 1329 | - * @since 1.8.0 |
|
| 1330 | - * @return void |
|
| 1331 | - */ |
|
| 1332 | - public function course_modules_title( ) { |
|
| 1333 | - |
|
| 1334 | - if( sensei_module_has_lessons() ){ |
|
| 1335 | - |
|
| 1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | - |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * Display the single course modules content this will only show |
|
| 1344 | - * if the course has modules. |
|
| 1345 | - * |
|
| 1346 | - * @since 1.8.0 |
|
| 1347 | - * @return void |
|
| 1348 | - */ |
|
| 1349 | - public function load_course_module_content_template(){ |
|
| 1350 | - |
|
| 1351 | - // load backwards compatible template name if it exists in the users theme |
|
| 1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | - if( $located_template ){ |
|
| 1354 | - |
|
| 1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | - return; |
|
| 1357 | - |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | - |
|
| 1362 | - } // end course_module_content |
|
| 1363 | - |
|
| 1364 | - /** |
|
| 1365 | - * Returns all lessons for the given module ID |
|
| 1366 | - * |
|
| 1367 | - * @since 1.8.0 |
|
| 1368 | - * |
|
| 1369 | - * @param $course_id |
|
| 1370 | - * @param $term_id |
|
| 1371 | - * @return array $lessons |
|
| 1372 | - */ |
|
| 1373 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | - |
|
| 1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 840 | + $html = ''; |
|
| 841 | + |
|
| 842 | + if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
| 843 | + $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
| 844 | + |
|
| 845 | + if ($ordered) { |
|
| 846 | + $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | + $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | + $html .= '</div>' . "\n"; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + $courses = Sensei()->course->get_all_courses(); |
|
| 853 | + |
|
| 854 | + $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | + $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | + $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | + $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | + $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 859 | + |
|
| 860 | + foreach ($courses as $course) { |
|
| 861 | + if (has_term('', $this->taxonomy, $course->ID)) { |
|
| 862 | + $course_id = ''; |
|
| 863 | + if (isset($_GET['course_id'])) { |
|
| 864 | + $course_id = intval($_GET['course_id']); |
|
| 865 | + } |
|
| 866 | + $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + $html .= '</select>' . "\n"; |
|
| 871 | + $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | + $html .= '</form>' . "\n"; |
|
| 873 | + |
|
| 874 | + if (isset($_GET['course_id'])) { |
|
| 875 | + $course_id = intval($_GET['course_id']); |
|
| 876 | + if ($course_id > 0) { |
|
| 877 | + $modules = $this->get_course_modules($course_id); |
|
| 878 | + $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 879 | + if ($modules) { |
|
| 880 | + |
|
| 881 | + $order = $this->get_course_module_order($course_id); |
|
| 882 | + |
|
| 883 | + $order_string=''; |
|
| 884 | + if ($order) { |
|
| 885 | + $order_string = implode(',', $order); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | + $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 890 | + $count = 0; |
|
| 891 | + foreach ($modules as $module) { |
|
| 892 | + $count++; |
|
| 893 | + $class = $this->taxonomy; |
|
| 894 | + if ($count == 1) { |
|
| 895 | + $class .= ' first'; |
|
| 896 | + } |
|
| 897 | + if ($count == count($module)) { |
|
| 898 | + $class .= ' last'; |
|
| 899 | + } |
|
| 900 | + if ($count % 2 != 0) { |
|
| 901 | + $class .= ' alternate'; |
|
| 902 | + } |
|
| 903 | + $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 904 | + } |
|
| 905 | + $html .= '</ul>' . "\n"; |
|
| 906 | + |
|
| 907 | + $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | + $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | + $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | + $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + echo $html; |
|
| 916 | + |
|
| 917 | + ?></div><?php |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Add 'Module order' column to courses list table |
|
| 922 | + * |
|
| 923 | + * @since 1.8.0 |
|
| 924 | + * |
|
| 925 | + * @param array $columns Existing columns |
|
| 926 | + * @return array Modifed columns |
|
| 927 | + */ |
|
| 928 | + public function course_columns($columns = array()) |
|
| 929 | + { |
|
| 930 | + $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
| 931 | + return $columns; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Load content in 'Module order' column |
|
| 936 | + * |
|
| 937 | + * @since 1.8.0 |
|
| 938 | + * |
|
| 939 | + * @param string $column Current column name |
|
| 940 | + * @param integer $course_id ID of course |
|
| 941 | + * @return void |
|
| 942 | + */ |
|
| 943 | + public function course_column_content($column = '', $course_id = 0) |
|
| 944 | + { |
|
| 945 | + if ($column == 'module_order') { |
|
| 946 | + if (has_term('', $this->taxonomy, $course_id)) { |
|
| 947 | + echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * Save module order for course |
|
| 954 | + * |
|
| 955 | + * @since 1.8.0 |
|
| 956 | + * |
|
| 957 | + * @param string $order_string Comma-separated string of module IDs |
|
| 958 | + * @param integer $course_id ID of course |
|
| 959 | + * @return boolean True on success, false on failure |
|
| 960 | + */ |
|
| 961 | + private function save_course_module_order($order_string = '', $course_id = 0) |
|
| 962 | + { |
|
| 963 | + if ($order_string && $course_id) { |
|
| 964 | + $order = explode(',', $order_string); |
|
| 965 | + update_post_meta(intval($course_id), '_module_order', $order); |
|
| 966 | + return true; |
|
| 967 | + } |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Get module order for course |
|
| 973 | + * |
|
| 974 | + * @since 1.8.0 |
|
| 975 | + * |
|
| 976 | + * @param integer $course_id ID of course |
|
| 977 | + * @return mixed Module order on success, false if no module order has been saved |
|
| 978 | + */ |
|
| 979 | + public function get_course_module_order($course_id = 0) |
|
| 980 | + { |
|
| 981 | + if ($course_id) { |
|
| 982 | + $order = get_post_meta(intval($course_id), '_module_order', true); |
|
| 983 | + return $order; |
|
| 984 | + } |
|
| 985 | + return false; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Modify module taxonomy columns |
|
| 990 | + * |
|
| 991 | + * @since 1.8.0 |
|
| 992 | + * |
|
| 993 | + * @param array $columns Default columns |
|
| 994 | + * @return array Modified columns |
|
| 995 | + */ |
|
| 996 | + public function taxonomy_column_headings($columns) |
|
| 997 | + { |
|
| 998 | + |
|
| 999 | + unset($columns['posts']); |
|
| 1000 | + |
|
| 1001 | + $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
| 1002 | + |
|
| 1003 | + return $columns; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Manage content in custom module taxonomy columns |
|
| 1008 | + * |
|
| 1009 | + * @since 1.8.0 |
|
| 1010 | + * |
|
| 1011 | + * @param string $column_data Default data for column |
|
| 1012 | + * @param string $column_name Name of current column |
|
| 1013 | + * @param integer $term_id ID of current term |
|
| 1014 | + * @return string Modified column data |
|
| 1015 | + */ |
|
| 1016 | + public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
| 1017 | + { |
|
| 1018 | + |
|
| 1019 | + $args = array( |
|
| 1020 | + 'post_status' => 'publish', |
|
| 1021 | + 'posts_per_page' => -1, |
|
| 1022 | + 'tax_query' => array( |
|
| 1023 | + array( |
|
| 1024 | + 'taxonomy' => $this->taxonomy, |
|
| 1025 | + 'field' => 'id', |
|
| 1026 | + 'terms' => intval($term_id) |
|
| 1027 | + ) |
|
| 1028 | + ) |
|
| 1029 | + ); |
|
| 1030 | + |
|
| 1031 | + $module = get_term($term_id, $this->taxonomy); |
|
| 1032 | + |
|
| 1033 | + switch ($column_name) { |
|
| 1034 | + |
|
| 1035 | + case 'lessons': |
|
| 1036 | + $args['post_type'] = 'lesson'; |
|
| 1037 | + $lessons = get_posts($args); |
|
| 1038 | + $total_lessons = count($lessons); |
|
| 1039 | + $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return $column_data; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * Add 'Module' columns to Analysis Lesson Overview table |
|
| 1048 | + * |
|
| 1049 | + * @since 1.8.0 |
|
| 1050 | + * |
|
| 1051 | + * @param array $columns Default columns |
|
| 1052 | + * @return array Modified columns |
|
| 1053 | + */ |
|
| 1054 | + public function analysis_overview_column_title($columns) |
|
| 1055 | + { |
|
| 1056 | + |
|
| 1057 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1058 | + $new_columns = array(); |
|
| 1059 | + if (is_array($columns) && 0 < count($columns)) { |
|
| 1060 | + foreach ($columns as $column => $title) { |
|
| 1061 | + $new_columns[$column] = $title; |
|
| 1062 | + if ($column == 'title') { |
|
| 1063 | + $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + if (0 < count($new_columns)) { |
|
| 1069 | + return $new_columns; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $columns; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Data for 'Module' column Analysis Lesson Overview table |
|
| 1078 | + * |
|
| 1079 | + * @since 1.8.0 |
|
| 1080 | + * |
|
| 1081 | + * @param array $columns Table column data |
|
| 1082 | + * @param WP_Post $lesson |
|
| 1083 | + * @return array Updated column data |
|
| 1084 | + */ |
|
| 1085 | + public function analysis_overview_column_data($columns, $lesson ) |
|
| 1086 | + { |
|
| 1087 | + |
|
| 1088 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1089 | + $lesson_module = ''; |
|
| 1090 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1091 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1092 | + foreach ($lesson_module_list as $single_module) { |
|
| 1093 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1094 | + break; |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + $columns['lesson_module'] = $lesson_module; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + return $columns; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Add 'Module' columns to Analysis Course table |
|
| 1106 | + * |
|
| 1107 | + * @since 1.8.0 |
|
| 1108 | + * |
|
| 1109 | + * @param array $columns Default columns |
|
| 1110 | + * @return array Modified columns |
|
| 1111 | + */ |
|
| 1112 | + public function analysis_course_column_title($columns) |
|
| 1113 | + { |
|
| 1114 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1115 | + $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
| 1116 | + } |
|
| 1117 | + return $columns; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * Data for 'Module' column in Analysis Course table |
|
| 1122 | + * |
|
| 1123 | + * @since 1.8.0 |
|
| 1124 | + * |
|
| 1125 | + * @param array $columns Table column data |
|
| 1126 | + * @param WP_Post $lesson |
|
| 1127 | + * @return array Updated columns data |
|
| 1128 | + */ |
|
| 1129 | + public function analysis_course_column_data($columns, $lesson ) |
|
| 1130 | + { |
|
| 1131 | + |
|
| 1132 | + if ( isset( $_GET['course_id'] ) ) { |
|
| 1133 | + $lesson_module = ''; |
|
| 1134 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
| 1135 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
| 1136 | + foreach ($lesson_module_list as $single_module) { |
|
| 1137 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1138 | + break; |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $columns['lesson_module'] = $lesson_module; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + return $columns; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * Get module for lesson |
|
| 1150 | + * |
|
| 1151 | + * This function also checks if the module still |
|
| 1152 | + * exists on the course before returning it. Although |
|
| 1153 | + * the lesson has a module the same module must exist on the |
|
| 1154 | + * course for it to be valid. |
|
| 1155 | + * |
|
| 1156 | + * @since 1.8.0 |
|
| 1157 | + * |
|
| 1158 | + * @param integer $lesson_id ID of lesson |
|
| 1159 | + * @return object Module taxonomy term object |
|
| 1160 | + */ |
|
| 1161 | + public function get_lesson_module($lesson_id = 0) |
|
| 1162 | + { |
|
| 1163 | + $lesson_id = intval($lesson_id); |
|
| 1164 | + if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1165 | + return false; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + // get taxonomy terms on this lesson |
|
| 1169 | + $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
| 1170 | + |
|
| 1171 | + //check if error returned |
|
| 1172 | + if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1173 | + return false; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + // get the last item in the array there should be only be 1 really. |
|
| 1177 | + // this method works for all php versions. |
|
| 1178 | + foreach( $modules as $module ){ |
|
| 1179 | + break; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
| 1183 | + return false; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + $module->url = get_term_link($module, $this->taxonomy); |
|
| 1187 | + $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
| 1188 | + if (isset($course_id) && 0 < $course_id) { |
|
| 1189 | + |
|
| 1190 | + // the course should contain the same module taxonomy term for this to be valid |
|
| 1191 | + if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1192 | + return false; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
| 1196 | + } |
|
| 1197 | + return $module; |
|
| 1198 | + |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Get ordered array of all modules in course |
|
| 1203 | + * |
|
| 1204 | + * @since 1.8.0 |
|
| 1205 | + * |
|
| 1206 | + * @param integer $course_id ID of course |
|
| 1207 | + * @return array Ordered array of module taxonomy term objects |
|
| 1208 | + */ |
|
| 1209 | + public function get_course_modules($course_id = 0) |
|
| 1210 | + { |
|
| 1211 | + $course_id = intval($course_id); |
|
| 1212 | + if (0 < $course_id) { |
|
| 1213 | + |
|
| 1214 | + // Get modules for course |
|
| 1215 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1216 | + |
|
| 1217 | + // Get custom module order for course |
|
| 1218 | + $order = $this->get_course_module_order($course_id); |
|
| 1219 | + |
|
| 1220 | + // Sort by custom order if custom order exists |
|
| 1221 | + if ($order) { |
|
| 1222 | + $ordered_modules = array(); |
|
| 1223 | + $unordered_modules = array(); |
|
| 1224 | + foreach ($modules as $module) { |
|
| 1225 | + $order_key = array_search($module->term_id, $order); |
|
| 1226 | + if ($order_key !== false) { |
|
| 1227 | + $ordered_modules[$order_key] = $module; |
|
| 1228 | + } else { |
|
| 1229 | + $unordered_modules[] = $module; |
|
| 1230 | + } |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // Order modules correctly |
|
| 1234 | + ksort($ordered_modules); |
|
| 1235 | + |
|
| 1236 | + // Append modules that have not yet been ordered |
|
| 1237 | + if (count($unordered_modules) > 0) { |
|
| 1238 | + $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + } else { |
|
| 1242 | + |
|
| 1243 | + $ordered_modules = $modules; |
|
| 1244 | + |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + return $ordered_modules; |
|
| 1248 | + |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + return false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Load frontend CSS |
|
| 1256 | + * |
|
| 1257 | + * @since 1.8.0 |
|
| 1258 | + * |
|
| 1259 | + * @return void |
|
| 1260 | + */ |
|
| 1261 | + public function enqueue_styles() |
|
| 1262 | + { |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Load admin Javascript |
|
| 1271 | + * |
|
| 1272 | + * @since 1.8.0 |
|
| 1273 | + * |
|
| 1274 | + * @return void |
|
| 1275 | + */ |
|
| 1276 | + public function admin_enqueue_scripts( $hook ) { |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Filter the page hooks where modules admin script can be loaded on. |
|
| 1280 | + * |
|
| 1281 | + * @param array $white_listed_pages |
|
| 1282 | + */ |
|
| 1283 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | + 'edit-tags.php', |
|
| 1285 | + 'course_page_module-order', |
|
| 1286 | + 'post-new.php', |
|
| 1287 | + 'post.php' |
|
| 1288 | + ) ); |
|
| 1289 | + |
|
| 1290 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1291 | + return; |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | + |
|
| 1296 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | + wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1299 | + |
|
| 1300 | + // localized module data |
|
| 1301 | + $localize_modulesAdmin = array( |
|
| 1302 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1304 | + ); |
|
| 1305 | + |
|
| 1306 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Load admin CSS |
|
| 1311 | + * |
|
| 1312 | + * @since 1.8.0 |
|
| 1313 | + * |
|
| 1314 | + * @return void |
|
| 1315 | + */ |
|
| 1316 | + public function admin_enqueue_styles() { |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1321 | + |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * Show the title modules on the single course template. |
|
| 1326 | + * |
|
| 1327 | + * Function is hooked into sensei_single_course_modules_before. |
|
| 1328 | + * |
|
| 1329 | + * @since 1.8.0 |
|
| 1330 | + * @return void |
|
| 1331 | + */ |
|
| 1332 | + public function course_modules_title( ) { |
|
| 1333 | + |
|
| 1334 | + if( sensei_module_has_lessons() ){ |
|
| 1335 | + |
|
| 1336 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1337 | + |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * Display the single course modules content this will only show |
|
| 1344 | + * if the course has modules. |
|
| 1345 | + * |
|
| 1346 | + * @since 1.8.0 |
|
| 1347 | + * @return void |
|
| 1348 | + */ |
|
| 1349 | + public function load_course_module_content_template(){ |
|
| 1350 | + |
|
| 1351 | + // load backwards compatible template name if it exists in the users theme |
|
| 1352 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | + if( $located_template ){ |
|
| 1354 | + |
|
| 1355 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1356 | + return; |
|
| 1357 | + |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1361 | + |
|
| 1362 | + } // end course_module_content |
|
| 1363 | + |
|
| 1364 | + /** |
|
| 1365 | + * Returns all lessons for the given module ID |
|
| 1366 | + * |
|
| 1367 | + * @since 1.8.0 |
|
| 1368 | + * |
|
| 1369 | + * @param $course_id |
|
| 1370 | + * @param $term_id |
|
| 1371 | + * @return array $lessons |
|
| 1372 | + */ |
|
| 1373 | + public function get_lessons( $course_id , $term_id ){ |
|
| 1374 | + |
|
| 1375 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1376 | 1376 | |
| 1377 | - if( isset( $lesson_query->posts ) ){ |
|
| 1377 | + if( isset( $lesson_query->posts ) ){ |
|
| 1378 | 1378 | |
| 1379 | - return $lesson_query->posts; |
|
| 1379 | + return $lesson_query->posts; |
|
| 1380 | 1380 | |
| 1381 | - }else{ |
|
| 1381 | + }else{ |
|
| 1382 | 1382 | |
| 1383 | - return array(); |
|
| 1383 | + return array(); |
|
| 1384 | 1384 | |
| 1385 | - } |
|
| 1385 | + } |
|
| 1386 | 1386 | |
| 1387 | - } // end get lessons |
|
| 1387 | + } // end get lessons |
|
| 1388 | 1388 | |
| 1389 | - /** |
|
| 1390 | - * Returns all lessons for the given module ID |
|
| 1391 | - * |
|
| 1392 | - * @since 1.8.0 |
|
| 1393 | - * |
|
| 1394 | - * @param $course_id |
|
| 1395 | - * @param $term_id |
|
| 1396 | - * @return WP_Query $lessons_query |
|
| 1397 | - */ |
|
| 1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | - |
|
| 1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | - |
|
| 1402 | - return array(); |
|
| 1403 | - |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - $args = array( |
|
| 1407 | - 'post_type' => 'lesson', |
|
| 1408 | - 'post_status' => 'publish', |
|
| 1409 | - 'posts_per_page' => -1, |
|
| 1410 | - 'meta_query' => array( |
|
| 1411 | - array( |
|
| 1412 | - 'key' => '_lesson_course', |
|
| 1413 | - 'value' => intval($course_id), |
|
| 1414 | - 'compare' => '=' |
|
| 1415 | - ) |
|
| 1416 | - ), |
|
| 1417 | - 'tax_query' => array( |
|
| 1418 | - array( |
|
| 1419 | - 'taxonomy' => 'module', |
|
| 1420 | - 'field' => 'id', |
|
| 1421 | - 'terms' => intval( $term_id ) |
|
| 1422 | - ) |
|
| 1423 | - ), |
|
| 1424 | - 'orderby' => 'menu_order', |
|
| 1425 | - 'order' => 'ASC', |
|
| 1426 | - 'suppress_filters' => 0 |
|
| 1427 | - ); |
|
| 1428 | - |
|
| 1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | - $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - $lessons_query = new WP_Query( $args ); |
|
| 1435 | - |
|
| 1436 | - return $lessons_query; |
|
| 1437 | - |
|
| 1438 | - } // end get lessons |
|
| 1439 | - |
|
| 1440 | - /** |
|
| 1441 | - * Find the lesson in the given course that doesn't belong |
|
| 1442 | - * to any of the courses modules |
|
| 1443 | - * |
|
| 1444 | - * |
|
| 1445 | - * @param $course_id |
|
| 1446 | - * |
|
| 1447 | - * @return array $non_module_lessons |
|
| 1448 | - */ |
|
| 1449 | - public function get_none_module_lessons( $course_id ){ |
|
| 1450 | - |
|
| 1451 | - $non_module_lessons = array(); |
|
| 1452 | - |
|
| 1453 | - //exit if there is no course id passed in |
|
| 1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | - |
|
| 1456 | - return $non_module_lessons; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - //save some time and check if we already have the saved |
|
| 1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | - |
|
| 1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | - |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // create terms array which must be excluded from other arrays |
|
| 1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | - |
|
| 1469 | - //exit if there are no module on this course |
|
| 1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | - |
|
| 1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | - |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - $terms = array(); |
|
| 1477 | - foreach( $course_modules as $module ){ |
|
| 1478 | - |
|
| 1479 | - array_push( $terms , $module->term_id ); |
|
| 1480 | - |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $args = array( |
|
| 1484 | - 'post_type' => 'lesson', |
|
| 1485 | - 'post_status' => 'publish', |
|
| 1486 | - 'posts_per_page' => -1, |
|
| 1487 | - 'meta_query' => array( |
|
| 1488 | - array( |
|
| 1489 | - 'key' => '_lesson_course', |
|
| 1490 | - 'value' => intval( $course_id ), |
|
| 1491 | - 'compare' => '=' |
|
| 1492 | - ) |
|
| 1493 | - ), |
|
| 1494 | - 'tax_query' => array( |
|
| 1495 | - array( |
|
| 1496 | - 'taxonomy' => 'module', |
|
| 1497 | - 'field' => 'id', |
|
| 1498 | - 'terms' => $terms, |
|
| 1499 | - 'operator' => 'NOT IN' |
|
| 1500 | - ) |
|
| 1501 | - ), |
|
| 1502 | - 'orderby' => 'menu_order', |
|
| 1503 | - 'order' => 'ASC', |
|
| 1504 | - 'suppress_filters' => 0 |
|
| 1505 | - ); |
|
| 1506 | - |
|
| 1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | - |
|
| 1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - return $non_module_lessons; |
|
| 1515 | - } // end get_none_module_lessons |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Register the modules taxonomy |
|
| 1519 | - * |
|
| 1520 | - * @since 1.8.0 |
|
| 1521 | - */ |
|
| 1522 | - public function setup_modules_taxonomy(){ |
|
| 1523 | - |
|
| 1524 | - $labels = array( |
|
| 1525 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | - ); |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | - * |
|
| 1541 | - * @since 1.8.0 |
|
| 1542 | - * @param string default 'modules' |
|
| 1543 | - */ |
|
| 1544 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | - |
|
| 1546 | - $args = array( |
|
| 1547 | - 'public' => true, |
|
| 1548 | - 'hierarchical' => true, |
|
| 1549 | - 'show_admin_column' => true, |
|
| 1550 | - 'capabilities' => array( |
|
| 1551 | - 'manage_terms' => 'manage_categories', |
|
| 1552 | - 'edit_terms' => 'edit_courses', |
|
| 1553 | - 'delete_terms' => 'manage_categories', |
|
| 1554 | - 'assign_terms' => 'edit_courses' |
|
| 1555 | - ), |
|
| 1556 | - 'show_in_nav_menus' => false, |
|
| 1557 | - 'show_in_quick_edit' => false, |
|
| 1558 | - 'show_ui' => true, |
|
| 1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | - 'labels' => $labels |
|
| 1561 | - ); |
|
| 1562 | - |
|
| 1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | - |
|
| 1565 | - }// end setup_modules_taxonomy |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | - * |
|
| 1570 | - * This function is hooked into the admin_menu |
|
| 1571 | - * |
|
| 1572 | - * @since 1.8.0 |
|
| 1573 | - * @return void |
|
| 1574 | - */ |
|
| 1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | - |
|
| 1577 | - global $typenow , $taxnow; |
|
| 1578 | - |
|
| 1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - }// end redirect to course taxonomy |
|
| 1584 | - |
|
| 1585 | - /** |
|
| 1586 | - * Completely remove the module menu item under lessons. |
|
| 1587 | - * |
|
| 1588 | - * This function is hooked into the admin_menu |
|
| 1589 | - * |
|
| 1590 | - * @since 1.8.0 |
|
| 1591 | - * @return void |
|
| 1592 | - */ |
|
| 1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | - global $submenu; |
|
| 1595 | - |
|
| 1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | - return; // exit |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | - |
|
| 1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | - } |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - }// end remove lesson module tax |
|
| 1609 | - |
|
| 1610 | - /** |
|
| 1611 | - * Completely remove the second modules under courses |
|
| 1612 | - * |
|
| 1613 | - * This function is hooked into the admin_menu |
|
| 1614 | - * |
|
| 1615 | - * @since 1.8.0 |
|
| 1616 | - * @return void |
|
| 1617 | - */ |
|
| 1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | - global $submenu; |
|
| 1620 | - |
|
| 1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | - return; // exit |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | - |
|
| 1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | - } |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - }// end remove courses module tax |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * Determine the author of a module term term by looking at |
|
| 1637 | - * the prefixed author id. This function will query the full term object. |
|
| 1638 | - * Will return the admin user author could not be determined. |
|
| 1639 | - * |
|
| 1640 | - * @since 1.8.0 |
|
| 1641 | - * |
|
| 1642 | - * @param string $term_name |
|
| 1643 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | - */ |
|
| 1645 | - public static function get_term_authors( $term_name ){ |
|
| 1646 | - |
|
| 1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | - |
|
| 1649 | - $owners = array(); |
|
| 1650 | - if( empty( $terms ) ){ |
|
| 1651 | - |
|
| 1652 | - return $owners; |
|
| 1389 | + /** |
|
| 1390 | + * Returns all lessons for the given module ID |
|
| 1391 | + * |
|
| 1392 | + * @since 1.8.0 |
|
| 1393 | + * |
|
| 1394 | + * @param $course_id |
|
| 1395 | + * @param $term_id |
|
| 1396 | + * @return WP_Query $lessons_query |
|
| 1397 | + */ |
|
| 1398 | + public function get_lessons_query( $course_id , $term_id ){ |
|
| 1399 | + |
|
| 1400 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1401 | + |
|
| 1402 | + return array(); |
|
| 1403 | + |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + $args = array( |
|
| 1407 | + 'post_type' => 'lesson', |
|
| 1408 | + 'post_status' => 'publish', |
|
| 1409 | + 'posts_per_page' => -1, |
|
| 1410 | + 'meta_query' => array( |
|
| 1411 | + array( |
|
| 1412 | + 'key' => '_lesson_course', |
|
| 1413 | + 'value' => intval($course_id), |
|
| 1414 | + 'compare' => '=' |
|
| 1415 | + ) |
|
| 1416 | + ), |
|
| 1417 | + 'tax_query' => array( |
|
| 1418 | + array( |
|
| 1419 | + 'taxonomy' => 'module', |
|
| 1420 | + 'field' => 'id', |
|
| 1421 | + 'terms' => intval( $term_id ) |
|
| 1422 | + ) |
|
| 1423 | + ), |
|
| 1424 | + 'orderby' => 'menu_order', |
|
| 1425 | + 'order' => 'ASC', |
|
| 1426 | + 'suppress_filters' => 0 |
|
| 1427 | + ); |
|
| 1428 | + |
|
| 1429 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1431 | + $args['orderby'] = 'meta_value_num date'; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + $lessons_query = new WP_Query( $args ); |
|
| 1435 | + |
|
| 1436 | + return $lessons_query; |
|
| 1437 | + |
|
| 1438 | + } // end get lessons |
|
| 1439 | + |
|
| 1440 | + /** |
|
| 1441 | + * Find the lesson in the given course that doesn't belong |
|
| 1442 | + * to any of the courses modules |
|
| 1443 | + * |
|
| 1444 | + * |
|
| 1445 | + * @param $course_id |
|
| 1446 | + * |
|
| 1447 | + * @return array $non_module_lessons |
|
| 1448 | + */ |
|
| 1449 | + public function get_none_module_lessons( $course_id ){ |
|
| 1450 | + |
|
| 1451 | + $non_module_lessons = array(); |
|
| 1452 | + |
|
| 1453 | + //exit if there is no course id passed in |
|
| 1454 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1455 | + |
|
| 1456 | + return $non_module_lessons; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + //save some time and check if we already have the saved |
|
| 1460 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1461 | + |
|
| 1462 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1463 | + |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // create terms array which must be excluded from other arrays |
|
| 1467 | + $course_modules = $this->get_course_modules( $course_id ); |
|
| 1468 | + |
|
| 1469 | + //exit if there are no module on this course |
|
| 1470 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1471 | + |
|
| 1472 | + return Sensei()->course->course_lessons( $course_id ); |
|
| 1473 | + |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + $terms = array(); |
|
| 1477 | + foreach( $course_modules as $module ){ |
|
| 1478 | + |
|
| 1479 | + array_push( $terms , $module->term_id ); |
|
| 1480 | + |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $args = array( |
|
| 1484 | + 'post_type' => 'lesson', |
|
| 1485 | + 'post_status' => 'publish', |
|
| 1486 | + 'posts_per_page' => -1, |
|
| 1487 | + 'meta_query' => array( |
|
| 1488 | + array( |
|
| 1489 | + 'key' => '_lesson_course', |
|
| 1490 | + 'value' => intval( $course_id ), |
|
| 1491 | + 'compare' => '=' |
|
| 1492 | + ) |
|
| 1493 | + ), |
|
| 1494 | + 'tax_query' => array( |
|
| 1495 | + array( |
|
| 1496 | + 'taxonomy' => 'module', |
|
| 1497 | + 'field' => 'id', |
|
| 1498 | + 'terms' => $terms, |
|
| 1499 | + 'operator' => 'NOT IN' |
|
| 1500 | + ) |
|
| 1501 | + ), |
|
| 1502 | + 'orderby' => 'menu_order', |
|
| 1503 | + 'order' => 'ASC', |
|
| 1504 | + 'suppress_filters' => 0 |
|
| 1505 | + ); |
|
| 1506 | + |
|
| 1507 | + $wp_lessons_query = new WP_Query( $args ); |
|
| 1508 | + |
|
| 1509 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1510 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1511 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + return $non_module_lessons; |
|
| 1515 | + } // end get_none_module_lessons |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Register the modules taxonomy |
|
| 1519 | + * |
|
| 1520 | + * @since 1.8.0 |
|
| 1521 | + */ |
|
| 1522 | + public function setup_modules_taxonomy(){ |
|
| 1523 | + |
|
| 1524 | + $labels = array( |
|
| 1525 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1526 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1527 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1528 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1529 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1530 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1531 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1532 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1533 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1534 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1535 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | + ); |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Filter to alter the Sensei Modules rewrite slug |
|
| 1540 | + * |
|
| 1541 | + * @since 1.8.0 |
|
| 1542 | + * @param string default 'modules' |
|
| 1543 | + */ |
|
| 1544 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1545 | + |
|
| 1546 | + $args = array( |
|
| 1547 | + 'public' => true, |
|
| 1548 | + 'hierarchical' => true, |
|
| 1549 | + 'show_admin_column' => true, |
|
| 1550 | + 'capabilities' => array( |
|
| 1551 | + 'manage_terms' => 'manage_categories', |
|
| 1552 | + 'edit_terms' => 'edit_courses', |
|
| 1553 | + 'delete_terms' => 'manage_categories', |
|
| 1554 | + 'assign_terms' => 'edit_courses' |
|
| 1555 | + ), |
|
| 1556 | + 'show_in_nav_menus' => false, |
|
| 1557 | + 'show_in_quick_edit' => false, |
|
| 1558 | + 'show_ui' => true, |
|
| 1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1560 | + 'labels' => $labels |
|
| 1561 | + ); |
|
| 1562 | + |
|
| 1563 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1564 | + |
|
| 1565 | + }// end setup_modules_taxonomy |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1569 | + * |
|
| 1570 | + * This function is hooked into the admin_menu |
|
| 1571 | + * |
|
| 1572 | + * @since 1.8.0 |
|
| 1573 | + * @return void |
|
| 1574 | + */ |
|
| 1575 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1576 | + |
|
| 1577 | + global $typenow , $taxnow; |
|
| 1578 | + |
|
| 1579 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + }// end redirect to course taxonomy |
|
| 1584 | + |
|
| 1585 | + /** |
|
| 1586 | + * Completely remove the module menu item under lessons. |
|
| 1587 | + * |
|
| 1588 | + * This function is hooked into the admin_menu |
|
| 1589 | + * |
|
| 1590 | + * @since 1.8.0 |
|
| 1591 | + * @return void |
|
| 1592 | + */ |
|
| 1593 | + public function remove_lessons_menu_model_taxonomy(){ |
|
| 1594 | + global $submenu; |
|
| 1595 | + |
|
| 1596 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1597 | + return; // exit |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1601 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1602 | + |
|
| 1603 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1605 | + } |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + }// end remove lesson module tax |
|
| 1609 | + |
|
| 1610 | + /** |
|
| 1611 | + * Completely remove the second modules under courses |
|
| 1612 | + * |
|
| 1613 | + * This function is hooked into the admin_menu |
|
| 1614 | + * |
|
| 1615 | + * @since 1.8.0 |
|
| 1616 | + * @return void |
|
| 1617 | + */ |
|
| 1618 | + public function remove_courses_menu_model_taxonomy(){ |
|
| 1619 | + global $submenu; |
|
| 1620 | + |
|
| 1621 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1622 | + return; // exit |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1626 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1627 | + |
|
| 1628 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1630 | + } |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + }// end remove courses module tax |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * Determine the author of a module term term by looking at |
|
| 1637 | + * the prefixed author id. This function will query the full term object. |
|
| 1638 | + * Will return the admin user author could not be determined. |
|
| 1639 | + * |
|
| 1640 | + * @since 1.8.0 |
|
| 1641 | + * |
|
| 1642 | + * @param string $term_name |
|
| 1643 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1644 | + */ |
|
| 1645 | + public static function get_term_authors( $term_name ){ |
|
| 1646 | + |
|
| 1647 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1648 | + |
|
| 1649 | + $owners = array(); |
|
| 1650 | + if( empty( $terms ) ){ |
|
| 1651 | + |
|
| 1652 | + return $owners; |
|
| 1653 | 1653 | |
| 1654 | - } |
|
| 1654 | + } |
|
| 1655 | 1655 | |
| 1656 | - // setup the admin user |
|
| 1656 | + // setup the admin user |
|
| 1657 | 1657 | |
| 1658 | 1658 | |
| 1659 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | - foreach( $terms as $term){ |
|
| 1661 | - if( $term->name == $term_name ){ |
|
| 1659 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1660 | + foreach( $terms as $term){ |
|
| 1661 | + if( $term->name == $term_name ){ |
|
| 1662 | 1662 | |
| 1663 | - // look for the author in the slug |
|
| 1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1663 | + // look for the author in the slug |
|
| 1664 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1665 | 1665 | |
| 1666 | - }// end if term name |
|
| 1666 | + }// end if term name |
|
| 1667 | 1667 | |
| 1668 | - } // end for each |
|
| 1668 | + } // end for each |
|
| 1669 | 1669 | |
| 1670 | - return $owners; |
|
| 1670 | + return $owners; |
|
| 1671 | 1671 | |
| 1672 | - }// end get_term_author |
|
| 1672 | + }// end get_term_author |
|
| 1673 | 1673 | |
| 1674 | - /** |
|
| 1675 | - * Looks at a term slug and figures out |
|
| 1676 | - * which author created the slug. The author was |
|
| 1677 | - * appended when the user saved the module term in the course edit |
|
| 1678 | - * screen. |
|
| 1679 | - * |
|
| 1680 | - * @since 1.8.0 |
|
| 1681 | - * |
|
| 1682 | - * @param $slug |
|
| 1683 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | - */ |
|
| 1685 | - public static function get_term_author( $slug='' ){ |
|
| 1674 | + /** |
|
| 1675 | + * Looks at a term slug and figures out |
|
| 1676 | + * which author created the slug. The author was |
|
| 1677 | + * appended when the user saved the module term in the course edit |
|
| 1678 | + * screen. |
|
| 1679 | + * |
|
| 1680 | + * @since 1.8.0 |
|
| 1681 | + * |
|
| 1682 | + * @param $slug |
|
| 1683 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1684 | + */ |
|
| 1685 | + public static function get_term_author( $slug='' ){ |
|
| 1686 | 1686 | |
| 1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1687 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1688 | 1688 | |
| 1689 | - if( empty( $slug ) ){ |
|
| 1689 | + if( empty( $slug ) ){ |
|
| 1690 | 1690 | |
| 1691 | - return $term_owner; |
|
| 1691 | + return $term_owner; |
|
| 1692 | 1692 | |
| 1693 | - } |
|
| 1693 | + } |
|
| 1694 | 1694 | |
| 1695 | - // look for the author in the slug |
|
| 1696 | - $slug_parts = explode( '-', $slug ); |
|
| 1695 | + // look for the author in the slug |
|
| 1696 | + $slug_parts = explode( '-', $slug ); |
|
| 1697 | 1697 | |
| 1698 | - if( count( $slug_parts ) > 1 ){ |
|
| 1698 | + if( count( $slug_parts ) > 1 ){ |
|
| 1699 | 1699 | |
| 1700 | - // get the user data |
|
| 1701 | - $possible_user_id = $slug_parts[0]; |
|
| 1702 | - $author = get_userdata( $possible_user_id ); |
|
| 1700 | + // get the user data |
|
| 1701 | + $possible_user_id = $slug_parts[0]; |
|
| 1702 | + $author = get_userdata( $possible_user_id ); |
|
| 1703 | 1703 | |
| 1704 | - // if the user doesnt exist for the first part of the slug |
|
| 1705 | - // then this slug was also created by admin |
|
| 1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1704 | + // if the user doesnt exist for the first part of the slug |
|
| 1705 | + // then this slug was also created by admin |
|
| 1706 | + if( is_a( $author, 'WP_User' ) ){ |
|
| 1707 | 1707 | |
| 1708 | - $term_owner = $author; |
|
| 1708 | + $term_owner = $author; |
|
| 1709 | 1709 | |
| 1710 | - } |
|
| 1711 | - } |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1712 | 1712 | |
| 1713 | - return $term_owner; |
|
| 1714 | - } |
|
| 1713 | + return $term_owner; |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - /** |
|
| 1717 | - * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | - * |
|
| 1719 | - * @since 1.8.0 |
|
| 1720 | - * |
|
| 1721 | - * @hooked into add_meta_box |
|
| 1722 | - * |
|
| 1723 | - * @param WP_Post $post Post object. |
|
| 1724 | - */ |
|
| 1725 | - public function course_module_metabox( $post ) { |
|
| 1716 | + /** |
|
| 1717 | + * Display the Sensei modules taxonomy terms metabox |
|
| 1718 | + * |
|
| 1719 | + * @since 1.8.0 |
|
| 1720 | + * |
|
| 1721 | + * @hooked into add_meta_box |
|
| 1722 | + * |
|
| 1723 | + * @param WP_Post $post Post object. |
|
| 1724 | + */ |
|
| 1725 | + public function course_module_metabox( $post ) { |
|
| 1726 | 1726 | |
| 1727 | - $tax_name = 'module'; |
|
| 1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1727 | + $tax_name = 'module'; |
|
| 1728 | + $taxonomy = get_taxonomy( 'module' ); |
|
| 1729 | 1729 | |
| 1730 | - ?> |
|
| 1730 | + ?> |
|
| 1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1742,9 +1742,9 @@ discard block |
||
| 1742 | 1742 | |
| 1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1744 | 1744 | <?php |
| 1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | - echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | - ?> |
|
| 1745 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1746 | + echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 1747 | + ?> |
|
| 1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1749 | 1749 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
| 1750 | 1750 | </ul> |
@@ -1754,9 +1754,9 @@ discard block |
||
| 1754 | 1754 | <h4> |
| 1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1756 | 1756 | <?php |
| 1757 | - /* translators: %s: add new taxonomy label */ |
|
| 1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | - ?> |
|
| 1757 | + /* translators: %s: add new taxonomy label */ |
|
| 1758 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1759 | + ?> |
|
| 1760 | 1760 | </a> |
| 1761 | 1761 | </h4> |
| 1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1771,331 +1771,331 @@ discard block |
||
| 1771 | 1771 | </div> |
| 1772 | 1772 | <?php |
| 1773 | 1773 | |
| 1774 | - } // end course_module_metabox |
|
| 1774 | + } // end course_module_metabox |
|
| 1775 | 1775 | |
| 1776 | 1776 | |
| 1777 | - /** |
|
| 1778 | - * Submits a new module term prefixed with the |
|
| 1779 | - * the current author id. |
|
| 1780 | - * |
|
| 1781 | - * @since 1.8.0 |
|
| 1782 | - */ |
|
| 1783 | - public static function add_new_module_term( ) { |
|
| 1777 | + /** |
|
| 1778 | + * Submits a new module term prefixed with the |
|
| 1779 | + * the current author id. |
|
| 1780 | + * |
|
| 1781 | + * @since 1.8.0 |
|
| 1782 | + */ |
|
| 1783 | + public static function add_new_module_term( ) { |
|
| 1784 | 1784 | |
| 1785 | 1785 | |
| 1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | - } |
|
| 1786 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - // get the term an create the new term storing infomration |
|
| 1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1790 | + // get the term an create the new term storing infomration |
|
| 1791 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1792 | 1792 | |
| 1793 | - if( current_user_can('manage_options' ) ) { |
|
| 1793 | + if( current_user_can('manage_options' ) ) { |
|
| 1794 | 1794 | |
| 1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1795 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1796 | 1796 | |
| 1797 | - } else { |
|
| 1797 | + } else { |
|
| 1798 | 1798 | |
| 1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1799 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1800 | 1800 | |
| 1801 | - } |
|
| 1801 | + } |
|
| 1802 | 1802 | |
| 1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1803 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1804 | 1804 | |
| 1805 | - // save the term |
|
| 1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1805 | + // save the term |
|
| 1806 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1807 | 1807 | |
| 1808 | - // send error for all errors except term exits |
|
| 1809 | - if( is_wp_error( $slug ) ){ |
|
| 1808 | + // send error for all errors except term exits |
|
| 1809 | + if( is_wp_error( $slug ) ){ |
|
| 1810 | 1810 | |
| 1811 | - // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | - $term_data = array(); |
|
| 1811 | + // prepare for possible term name and id to be passed down if term exists |
|
| 1812 | + $term_data = array(); |
|
| 1813 | 1813 | |
| 1814 | - // if term exists also send back the term name and id |
|
| 1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1814 | + // if term exists also send back the term name and id |
|
| 1815 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1816 | 1816 | |
| 1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | - $term_data['name'] = $term_name; |
|
| 1819 | - $term_data['id'] = $term->term_id; |
|
| 1817 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1818 | + $term_data['name'] = $term_name; |
|
| 1819 | + $term_data['id'] = $term->term_id; |
|
| 1820 | 1820 | |
| 1821 | - // set the object terms |
|
| 1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | - } |
|
| 1821 | + // set the object terms |
|
| 1822 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1823 | + } |
|
| 1824 | 1824 | |
| 1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1825 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1826 | 1826 | |
| 1827 | - } |
|
| 1827 | + } |
|
| 1828 | 1828 | |
| 1829 | - //make sure the new term is checked for this course |
|
| 1829 | + //make sure the new term is checked for this course |
|
| 1830 | 1830 | |
| 1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1831 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1832 | 1832 | |
| 1833 | - // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1833 | + // Handle request then generate response using WP_Ajax_Response |
|
| 1834 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1835 | 1835 | |
| 1836 | - } |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | - /** |
|
| 1839 | - * Limit the course module metabox |
|
| 1840 | - * term list to only those on courses belonging to current teacher. |
|
| 1841 | - * |
|
| 1842 | - * Hooked into 'get_terms' |
|
| 1843 | - * |
|
| 1844 | - * @since 1.8.0 |
|
| 1845 | - */ |
|
| 1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1838 | + /** |
|
| 1839 | + * Limit the course module metabox |
|
| 1840 | + * term list to only those on courses belonging to current teacher. |
|
| 1841 | + * |
|
| 1842 | + * Hooked into 'get_terms' |
|
| 1843 | + * |
|
| 1844 | + * @since 1.8.0 |
|
| 1845 | + */ |
|
| 1846 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1847 | 1847 | |
| 1848 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | - return $terms; |
|
| 1851 | - } |
|
| 1848 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1849 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1850 | + return $terms; |
|
| 1851 | + } |
|
| 1852 | 1852 | |
| 1853 | - // avoid infinite call loop |
|
| 1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1853 | + // avoid infinite call loop |
|
| 1854 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1855 | 1855 | |
| 1856 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | - // change only scrub the terms ids form the array keys |
|
| 1859 | - $terms = array_keys( $terms ); |
|
| 1860 | - } |
|
| 1856 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1857 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1858 | + // change only scrub the terms ids form the array keys |
|
| 1859 | + $terms = array_keys( $terms ); |
|
| 1860 | + } |
|
| 1861 | 1861 | |
| 1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1862 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1863 | 1863 | |
| 1864 | - // add filter again as removed above |
|
| 1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1864 | + // add filter again as removed above |
|
| 1865 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1866 | 1866 | |
| 1867 | - return $teachers_terms; |
|
| 1868 | - }// end filter_module_terms |
|
| 1867 | + return $teachers_terms; |
|
| 1868 | + }// end filter_module_terms |
|
| 1869 | 1869 | |
| 1870 | - /** |
|
| 1871 | - * For the selected items on a course module only return those |
|
| 1872 | - * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | - * |
|
| 1874 | - * hooked into get_object_terms |
|
| 1875 | - * |
|
| 1876 | - * @since 1.8.0 |
|
| 1877 | - */ |
|
| 1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1870 | + /** |
|
| 1871 | + * For the selected items on a course module only return those |
|
| 1872 | + * for the current user. This does not apply to admin and super admin users. |
|
| 1873 | + * |
|
| 1874 | + * hooked into get_object_terms |
|
| 1875 | + * |
|
| 1876 | + * @since 1.8.0 |
|
| 1877 | + */ |
|
| 1878 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1879 | 1879 | |
| 1880 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | - return $terms; |
|
| 1885 | - } |
|
| 1880 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1881 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1882 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1883 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1884 | + return $terms; |
|
| 1885 | + } |
|
| 1886 | 1886 | |
| 1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1887 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1888 | 1888 | |
| 1889 | - // if term objects were passed in send back objects |
|
| 1890 | - // if term id were passed in send that back |
|
| 1891 | - if( is_object( $terms[0] ) ){ |
|
| 1892 | - return $term_objects; |
|
| 1893 | - } |
|
| 1889 | + // if term objects were passed in send back objects |
|
| 1890 | + // if term id were passed in send that back |
|
| 1891 | + if( is_object( $terms[0] ) ){ |
|
| 1892 | + return $term_objects; |
|
| 1893 | + } |
|
| 1894 | 1894 | |
| 1895 | - $terms = array(); |
|
| 1896 | - foreach( $term_objects as $term_object ){ |
|
| 1897 | - $terms[] = $term_object->term_id; |
|
| 1898 | - } |
|
| 1895 | + $terms = array(); |
|
| 1896 | + foreach( $term_objects as $term_object ){ |
|
| 1897 | + $terms[] = $term_object->term_id; |
|
| 1898 | + } |
|
| 1899 | 1899 | |
| 1900 | - return $terms; |
|
| 1900 | + return $terms; |
|
| 1901 | 1901 | |
| 1902 | 1902 | |
| 1903 | - }// end filter_course_selected_terms |
|
| 1903 | + }// end filter_course_selected_terms |
|
| 1904 | 1904 | |
| 1905 | - /** |
|
| 1906 | - * Filter the given terms and only return the |
|
| 1907 | - * terms that belong to the given user id. |
|
| 1908 | - * |
|
| 1909 | - * @since 1.8.0 |
|
| 1910 | - * @param $terms |
|
| 1911 | - * @param $user_id |
|
| 1912 | - * @return array |
|
| 1913 | - */ |
|
| 1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1905 | + /** |
|
| 1906 | + * Filter the given terms and only return the |
|
| 1907 | + * terms that belong to the given user id. |
|
| 1908 | + * |
|
| 1909 | + * @since 1.8.0 |
|
| 1910 | + * @param $terms |
|
| 1911 | + * @param $user_id |
|
| 1912 | + * @return array |
|
| 1913 | + */ |
|
| 1914 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1915 | 1915 | |
| 1916 | - $users_terms = array(); |
|
| 1916 | + $users_terms = array(); |
|
| 1917 | 1917 | |
| 1918 | - foreach( $terms as $index => $term ){ |
|
| 1918 | + foreach( $terms as $index => $term ){ |
|
| 1919 | 1919 | |
| 1920 | - if( is_numeric( $term ) ){ |
|
| 1921 | - // the term id was given, get the term object |
|
| 1922 | - $term = get_term( $term, 'module' ); |
|
| 1923 | - } |
|
| 1920 | + if( is_numeric( $term ) ){ |
|
| 1921 | + // the term id was given, get the term object |
|
| 1922 | + $term = get_term( $term, 'module' ); |
|
| 1923 | + } |
|
| 1924 | 1924 | |
| 1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1925 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1926 | 1926 | |
| 1927 | - if ( $user_id == $author->ID ) { |
|
| 1928 | - // add the term to the teachers terms |
|
| 1929 | - $users_terms[] = $term; |
|
| 1930 | - } |
|
| 1927 | + if ( $user_id == $author->ID ) { |
|
| 1928 | + // add the term to the teachers terms |
|
| 1929 | + $users_terms[] = $term; |
|
| 1930 | + } |
|
| 1931 | 1931 | |
| 1932 | - } |
|
| 1932 | + } |
|
| 1933 | 1933 | |
| 1934 | - return $users_terms; |
|
| 1934 | + return $users_terms; |
|
| 1935 | 1935 | |
| 1936 | - } // end filter terms by owner |
|
| 1936 | + } // end filter terms by owner |
|
| 1937 | 1937 | |
| 1938 | - /** |
|
| 1939 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | - * This will not add name to terms belonging to admin user. |
|
| 1941 | - * |
|
| 1942 | - * Hooked into 'get_terms' |
|
| 1943 | - * |
|
| 1944 | - * @since 1.8.0 |
|
| 1945 | - */ |
|
| 1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | - { |
|
| 1938 | + /** |
|
| 1939 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1940 | + * This will not add name to terms belonging to admin user. |
|
| 1941 | + * |
|
| 1942 | + * Hooked into 'get_terms' |
|
| 1943 | + * |
|
| 1944 | + * @since 1.8.0 |
|
| 1945 | + */ |
|
| 1946 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1947 | + { |
|
| 1948 | 1948 | |
| 1949 | - // only for admin users ont he module taxonomy |
|
| 1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | - return $terms; |
|
| 1952 | - } |
|
| 1949 | + // only for admin users ont he module taxonomy |
|
| 1950 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1951 | + return $terms; |
|
| 1952 | + } |
|
| 1953 | 1953 | |
| 1954 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | - // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1954 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1955 | + // simply return this as wp doesn't need an array of stdObject Term |
|
| 1956 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1957 | 1957 | |
| 1958 | - return $terms; |
|
| 1958 | + return $terms; |
|
| 1959 | 1959 | |
| 1960 | - } |
|
| 1960 | + } |
|
| 1961 | 1961 | |
| 1962 | - // loop through and update all terms adding the author name |
|
| 1963 | - foreach( $terms as $index => $term ){ |
|
| 1962 | + // loop through and update all terms adding the author name |
|
| 1963 | + foreach( $terms as $index => $term ){ |
|
| 1964 | 1964 | |
| 1965 | - if( is_numeric( $term ) ){ |
|
| 1966 | - // the term id was given, get the term object |
|
| 1967 | - $term = get_term( $term, 'module' ); |
|
| 1968 | - } |
|
| 1965 | + if( is_numeric( $term ) ){ |
|
| 1966 | + // the term id was given, get the term object |
|
| 1967 | + $term = get_term( $term, 'module' ); |
|
| 1968 | + } |
|
| 1969 | 1969 | |
| 1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1970 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1971 | 1971 | |
| 1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | - } |
|
| 1972 | + if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1974 | + } |
|
| 1975 | 1975 | |
| 1976 | - // add the term to the teachers terms |
|
| 1977 | - $users_terms[] = $term; |
|
| 1976 | + // add the term to the teachers terms |
|
| 1977 | + $users_terms[] = $term; |
|
| 1978 | 1978 | |
| 1979 | - } |
|
| 1979 | + } |
|
| 1980 | 1980 | |
| 1981 | - return $users_terms; |
|
| 1982 | - } |
|
| 1981 | + return $users_terms; |
|
| 1982 | + } |
|
| 1983 | 1983 | |
| 1984 | - /** |
|
| 1985 | - * Remove modules metabox that come by default |
|
| 1986 | - * with the modules taxonomy. We are removing this as |
|
| 1987 | - * we have created our own custom meta box. |
|
| 1988 | - */ |
|
| 1989 | - public static function remove_default_modules_box() { |
|
| 1984 | + /** |
|
| 1985 | + * Remove modules metabox that come by default |
|
| 1986 | + * with the modules taxonomy. We are removing this as |
|
| 1987 | + * we have created our own custom meta box. |
|
| 1988 | + */ |
|
| 1989 | + public static function remove_default_modules_box() { |
|
| 1990 | 1990 | |
| 1991 | - remove_meta_box('modulediv', 'course', 'side'); |
|
| 1991 | + remove_meta_box('modulediv', 'course', 'side'); |
|
| 1992 | 1992 | |
| 1993 | - } |
|
| 1993 | + } |
|
| 1994 | 1994 | |
| 1995 | - /** |
|
| 1996 | - * When a course is save make sure to reset the transient set |
|
| 1997 | - * for it when determining the none module lessons. |
|
| 1998 | - * |
|
| 1999 | - * @sine 1.9.0 |
|
| 2000 | - * @param $post_id |
|
| 2001 | - */ |
|
| 2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 1995 | + /** |
|
| 1996 | + * When a course is save make sure to reset the transient set |
|
| 1997 | + * for it when determining the none module lessons. |
|
| 1998 | + * |
|
| 1999 | + * @sine 1.9.0 |
|
| 2000 | + * @param $post_id |
|
| 2001 | + */ |
|
| 2002 | + public static function reset_none_modules_transient ( $post_id ){ |
|
| 2003 | 2003 | |
| 2004 | - // this should only apply to course and lesson post types |
|
| 2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2004 | + // this should only apply to course and lesson post types |
|
| 2005 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2006 | 2006 | |
| 2007 | - $course_id = ''; |
|
| 2007 | + $course_id = ''; |
|
| 2008 | 2008 | |
| 2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2009 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2010 | 2010 | |
| 2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2011 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2012 | 2012 | |
| 2013 | - } |
|
| 2013 | + } |
|
| 2014 | 2014 | |
| 2015 | 2015 | |
| 2016 | - if( !empty( $course_id ) ){ |
|
| 2016 | + if( !empty( $course_id ) ){ |
|
| 2017 | 2017 | |
| 2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2018 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2019 | 2019 | |
| 2020 | - } |
|
| 2020 | + } |
|
| 2021 | 2021 | |
| 2022 | - } // end if is a course or a lesson |
|
| 2022 | + } // end if is a course or a lesson |
|
| 2023 | 2023 | |
| 2024 | - } // end reset_none_modules_transient |
|
| 2024 | + } // end reset_none_modules_transient |
|
| 2025 | 2025 | |
| 2026 | - /** |
|
| 2027 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | - * |
|
| 2029 | - * @since 1.9.0 |
|
| 2030 | - * @deprecated since 1.9.0 |
|
| 2031 | - * |
|
| 2032 | - */ |
|
| 2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2026 | + /** |
|
| 2027 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2028 | + * |
|
| 2029 | + * @since 1.9.0 |
|
| 2030 | + * @deprecated since 1.9.0 |
|
| 2031 | + * |
|
| 2032 | + */ |
|
| 2033 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2034 | 2034 | |
| 2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2035 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2036 | 2036 | |
| 2037 | - } |
|
| 2037 | + } |
|
| 2038 | 2038 | |
| 2039 | - /** |
|
| 2040 | - * Setup the single course module loop. |
|
| 2041 | - * |
|
| 2042 | - * Setup the global $sensei_modules_loop |
|
| 2043 | - * |
|
| 2044 | - * @since 1.9.0 |
|
| 2045 | - */ |
|
| 2046 | - public static function setup_single_course_module_loop(){ |
|
| 2039 | + /** |
|
| 2040 | + * Setup the single course module loop. |
|
| 2041 | + * |
|
| 2042 | + * Setup the global $sensei_modules_loop |
|
| 2043 | + * |
|
| 2044 | + * @since 1.9.0 |
|
| 2045 | + */ |
|
| 2046 | + public static function setup_single_course_module_loop(){ |
|
| 2047 | 2047 | |
| 2048 | - global $sensei_modules_loop, $post; |
|
| 2049 | - $course_id = $post->ID; |
|
| 2048 | + global $sensei_modules_loop, $post; |
|
| 2049 | + $course_id = $post->ID; |
|
| 2050 | 2050 | |
| 2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2051 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2052 | 2052 | |
| 2053 | - //initial setup |
|
| 2054 | - $sensei_modules_loop['total'] = 0; |
|
| 2055 | - $sensei_modules_loop['modules'] = array(); |
|
| 2056 | - $sensei_modules_loop['current'] = -1; |
|
| 2053 | + //initial setup |
|
| 2054 | + $sensei_modules_loop['total'] = 0; |
|
| 2055 | + $sensei_modules_loop['modules'] = array(); |
|
| 2056 | + $sensei_modules_loop['current'] = -1; |
|
| 2057 | 2057 | |
| 2058 | - // exit if this course doesn't have modules |
|
| 2059 | - if( !$modules || empty( $modules ) ){ |
|
| 2060 | - return; |
|
| 2061 | - } |
|
| 2058 | + // exit if this course doesn't have modules |
|
| 2059 | + if( !$modules || empty( $modules ) ){ |
|
| 2060 | + return; |
|
| 2061 | + } |
|
| 2062 | 2062 | |
| 2063 | 2063 | |
| 2064 | - $lessons_in_all_modules = array(); |
|
| 2065 | - foreach( $modules as $term ){ |
|
| 2064 | + $lessons_in_all_modules = array(); |
|
| 2065 | + foreach( $modules as $term ){ |
|
| 2066 | 2066 | |
| 2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2069 | 2069 | |
| 2070 | - } |
|
| 2070 | + } |
|
| 2071 | 2071 | |
| 2072 | 2072 | |
| 2073 | - //setup all of the modules loop variables |
|
| 2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | - $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | - $sensei_modules_loop['current'] = -1; |
|
| 2077 | - $sensei_modules_loop['course_id'] = $course_id; |
|
| 2073 | + //setup all of the modules loop variables |
|
| 2074 | + $sensei_modules_loop['total'] = count( $modules ); |
|
| 2075 | + $sensei_modules_loop['modules'] = $modules; |
|
| 2076 | + $sensei_modules_loop['current'] = -1; |
|
| 2077 | + $sensei_modules_loop['course_id'] = $course_id; |
|
| 2078 | 2078 | |
| 2079 | - }// end setup_single_course_module_loop |
|
| 2079 | + }// end setup_single_course_module_loop |
|
| 2080 | 2080 | |
| 2081 | - /** |
|
| 2082 | - * Tear down the course module loop. |
|
| 2083 | - * |
|
| 2084 | - * @since 1.9.0 |
|
| 2085 | - * |
|
| 2086 | - */ |
|
| 2087 | - public static function teardown_single_course_module_loop(){ |
|
| 2081 | + /** |
|
| 2082 | + * Tear down the course module loop. |
|
| 2083 | + * |
|
| 2084 | + * @since 1.9.0 |
|
| 2085 | + * |
|
| 2086 | + */ |
|
| 2087 | + public static function teardown_single_course_module_loop(){ |
|
| 2088 | 2088 | |
| 2089 | - global $sensei_modules_loop, $wp_query, $post; |
|
| 2089 | + global $sensei_modules_loop, $wp_query, $post; |
|
| 2090 | 2090 | |
| 2091 | - //reset all of the modules loop variables |
|
| 2092 | - $sensei_modules_loop['total'] = 0; |
|
| 2093 | - $sensei_modules_loop['modules'] = array(); |
|
| 2094 | - $sensei_modules_loop['current'] = -1; |
|
| 2091 | + //reset all of the modules loop variables |
|
| 2092 | + $sensei_modules_loop['total'] = 0; |
|
| 2093 | + $sensei_modules_loop['modules'] = array(); |
|
| 2094 | + $sensei_modules_loop['current'] = -1; |
|
| 2095 | 2095 | |
| 2096 | - // set the current course to be the global post again |
|
| 2097 | - wp_reset_query(); |
|
| 2098 | - $post = $wp_query->post; |
|
| 2099 | - }// end teardown_single_course_module_loop |
|
| 2096 | + // set the current course to be the global post again |
|
| 2097 | + wp_reset_query(); |
|
| 2098 | + $post = $wp_query->post; |
|
| 2099 | + }// end teardown_single_course_module_loop |
|
| 2100 | 2100 | |
| 2101 | 2101 | } // end modules class |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if ( ! defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Sensei Modules Class |
@@ -21,33 +21,33 @@ discard block |
||
| 21 | 21 | private $order_page_slug; |
| 22 | 22 | public $taxonomy; |
| 23 | 23 | |
| 24 | - public function __construct( $file ) |
|
| 24 | + public function __construct($file) |
|
| 25 | 25 | { |
| 26 | 26 | $this->file = $file; |
| 27 | 27 | $this->dir = dirname($this->file); |
| 28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
| 28 | + $this->assets_dir = trailingslashit($this->dir).'assets'; |
|
| 29 | 29 | $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
| 30 | 30 | $this->taxonomy = 'module'; |
| 31 | 31 | $this->order_page_slug = 'module-order'; |
| 32 | 32 | |
| 33 | 33 | // setup taxonomy |
| 34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
| 34 | + add_action('init', array($this, 'setup_modules_taxonomy'), 10); |
|
| 35 | 35 | |
| 36 | 36 | // Manage lesson meta boxes for taxonomy |
| 37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
| 37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2); |
|
| 38 | 38 | |
| 39 | 39 | // Save lesson meta box |
| 40 | 40 | add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
| 41 | 41 | |
| 42 | 42 | //Reset the none modules lessons transient |
| 43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
| 43 | + add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient')); |
|
| 44 | 44 | |
| 45 | 45 | // Frontend styling |
| 46 | 46 | add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
| 47 | 47 | |
| 48 | 48 | // Admin styling |
| 49 | 49 | add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
| 50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
| 50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2); |
|
| 51 | 51 | |
| 52 | 52 | // Handle module completion record |
| 53 | 53 | add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
@@ -55,20 +55,20 @@ discard block |
||
| 55 | 55 | add_action('wp', array($this, 'save_module_progress'), 10); |
| 56 | 56 | |
| 57 | 57 | // Handle module ordering |
| 58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
| 58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30); |
|
| 59 | 59 | add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
| 60 | 60 | add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
| 61 | 61 | |
| 62 | 62 | // Ensure modules always show under courses |
| 63 | - add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
| 64 | - add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
| 65 | - add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
| 63 | + add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10); |
|
| 64 | + add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10); |
|
| 65 | + add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20); |
|
| 66 | 66 | |
| 67 | 67 | // Add course field to taxonomy |
| 68 | - add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | - add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | - add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | - add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 68 | + add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
| 69 | + add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
| 70 | + add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 71 | + add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
| 72 | 72 | add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
| 73 | 73 | |
| 74 | 74 | // Manage module taxonomy archive page |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | add_filter('body_class', array($this, 'module_archive_body_class')); |
| 81 | 81 | |
| 82 | 82 | // add modules to the single course template |
| 83 | - add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
| 83 | + add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8); |
|
| 84 | 84 | |
| 85 | 85 | //Single Course modules actions. Add to single-course/course-modules.php |
| 86 | - add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
| 86 | + add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20); |
|
| 87 | 87 | |
| 88 | 88 | // Set up display on single lesson page |
| 89 | 89 | add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
@@ -95,22 +95,22 @@ discard block |
||
| 95 | 95 | add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
| 96 | 96 | |
| 97 | 97 | // Manage module taxonomy columns |
| 98 | - add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | - add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 98 | + add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
| 99 | + add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
| 100 | 100 | add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
| 101 | 101 | |
| 102 | 102 | //store new modules created on the course edit screen |
| 103 | - add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
| 103 | + add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term')); |
|
| 104 | 104 | |
| 105 | 105 | // for non admin users, only show taxonomies that belong to them |
| 106 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 107 | - add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
| 106 | + add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
| 107 | + add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3); |
|
| 108 | 108 | |
| 109 | 109 | // add the teacher name next to the module term in for admin users |
| 110 | - add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
| 110 | + add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3); |
|
| 111 | 111 | |
| 112 | 112 | // remove the default modules metabox |
| 113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
| 113 | + add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box')); |
|
| 114 | 114 | |
| 115 | 115 | } // end constructor |
| 116 | 116 | |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @return void |
| 128 | 128 | * @deprecated since 1.9.0 |
| 129 | 129 | */ |
| 130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
| 130 | + public function change_module_term_slug($term_id, $tt_id, $taxonomy) { |
|
| 131 | 131 | |
| 132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
| 132 | + _deprecated_function('change_module_term_slug', '1.9.0'); |
|
| 133 | 133 | |
| 134 | 134 | }// end add_module_term_group |
| 135 | 135 | |
@@ -143,20 +143,20 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return void |
| 145 | 145 | */ |
| 146 | - public function modules_metaboxes( $post_type, $post ) |
|
| 146 | + public function modules_metaboxes($post_type, $post) |
|
| 147 | 147 | { |
| 148 | - if ('lesson' == $post_type ) { |
|
| 148 | + if ('lesson' == $post_type) { |
|
| 149 | 149 | |
| 150 | 150 | // Remove default taxonomy meta box from Lesson edit screen |
| 151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
| 151 | + remove_meta_box($this->taxonomy.'div', 'lesson', 'side'); |
|
| 152 | 152 | |
| 153 | 153 | // Add custom meta box to limit module selection to one per lesson |
| 154 | - add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 154 | + add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if( 'course' == $post_type ){ |
|
| 157 | + if ('course' == $post_type) { |
|
| 158 | 158 | // Course modules selection metabox |
| 159 | - add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 159 | + add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -192,21 +192,21 @@ discard block |
||
| 192 | 192 | $modules = $this->get_course_modules($lesson_course); |
| 193 | 193 | |
| 194 | 194 | // Build the HTML to output |
| 195 | - $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
| 195 | + $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />'; |
|
| 196 | 196 | if (is_array($modules) && count($modules) > 0) { |
| 197 | - $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
| 198 | - $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n"; |
|
| 198 | + $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 199 | 199 | foreach ($modules as $module) { |
| 200 | - $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
| 200 | + $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n"; |
|
| 201 | 201 | } |
| 202 | - $html .= '</select>' . "\n"; |
|
| 202 | + $html .= '</select>'."\n"; |
|
| 203 | 203 | } else { |
| 204 | - $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
| 205 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
| 204 | + $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit'); |
|
| 205 | + $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>'; |
|
| 206 | 206 | } // End If Statement |
| 207 | 207 | |
| 208 | 208 | } else { |
| 209 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
| 209 | + $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>'; |
|
| 210 | 210 | } // End If Statement |
| 211 | 211 | |
| 212 | 212 | // Output the HTML |
@@ -225,38 +225,38 @@ discard block |
||
| 225 | 225 | global $post; |
| 226 | 226 | |
| 227 | 227 | // Verify post type and nonce |
| 228 | - if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
| 229 | - ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
| 228 | + if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce']) |
|
| 229 | + ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) { |
|
| 230 | 230 | return $post_id; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Check if user has permissions to edit lessons |
| 234 | 234 | $post_type = get_post_type_object($post->post_type); |
| 235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 235 | + if ( ! current_user_can($post_type->cap->edit_post, $post_id)) { |
|
| 236 | 236 | return $post_id; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Check if user has permissions to edit this specific post |
| 240 | - if (!current_user_can('edit_post', $post_id)) { |
|
| 240 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
| 241 | 241 | return $post_id; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Cast module ID as an integer if selected, otherwise leave as empty string |
| 245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
| 245 | + if (isset($_POST['lesson_module'])) { |
|
| 246 | 246 | |
| 247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
| 248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
| 247 | + if (empty ($_POST['lesson_module'])) { |
|
| 248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy); |
|
| 249 | 249 | return true; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
| 252 | + $module_id = intval($_POST['lesson_module']); |
|
| 253 | 253 | |
| 254 | 254 | // Assign lesson to selected module |
| 255 | 255 | wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
| 256 | 256 | |
| 257 | 257 | // Set default order for lesson inside module |
| 258 | - if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
| 259 | - update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
| 258 | + if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) { |
|
| 259 | + update_post_meta($post_id, '_order_module_'.$module_id, 0); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $module_courses = array(); |
| 315 | 315 | if (isset($courses) && is_array($courses)) { |
| 316 | 316 | foreach ($courses as $course) { |
| 317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
| 317 | + $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
| 325 | 325 | <td> |
| 326 | 326 | <input type="hidden" |
| 327 | - data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>" |
|
| 328 | - value="<?php echo esc_attr( json_encode($module_courses) ); ?>" |
|
| 327 | + data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>" |
|
| 328 | + value="<?php echo esc_attr(json_encode($module_courses)); ?>" |
|
| 329 | 329 | id="module_courses" name="module_courses" |
| 330 | 330 | class="ajax_chosen_select_courses" |
| 331 | 331 | placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>" |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Add module to selected courses |
| 373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
| 373 | + if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) { |
|
| 374 | 374 | |
| 375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
| 375 | + $course_ids = explode(",", $_POST['module_courses']); |
|
| 376 | 376 | |
| 377 | - foreach ( $course_ids as $course_id ) { |
|
| 377 | + foreach ($course_ids as $course_id) { |
|
| 378 | 378 | |
| 379 | 379 | wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
| 380 | 380 | |
@@ -438,11 +438,11 @@ discard block |
||
| 438 | 438 | * @since 1.8.0 |
| 439 | 439 | * @return void |
| 440 | 440 | */ |
| 441 | - public function single_course_modules(){ |
|
| 441 | + public function single_course_modules() { |
|
| 442 | 442 | |
| 443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 443 | + _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
| 444 | 444 | // only show modules on the course that has modules |
| 445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
| 445 | + if (is_singular('course') && has_term('', 'module')) { |
|
| 446 | 446 | |
| 447 | 447 | $this->load_course_module_content_template(); |
| 448 | 448 | |
@@ -459,15 +459,15 @@ discard block |
||
| 459 | 459 | |
| 460 | 460 | if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) { |
| 461 | 461 | $is_user_taking_course = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
| 462 | - if (!$is_user_taking_course) { |
|
| 462 | + if ( ! $is_user_taking_course) { |
|
| 463 | 463 | if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
| 464 | 464 | $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
| 465 | 465 | // Remove brackets for display here |
| 466 | 466 | $title_text = str_replace('(', '', $title_text); |
| 467 | 467 | $title_text = str_replace(')', '', $title_text); |
| 468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
| 468 | + $title_text = '<span class="preview-label">'.$title_text.'</span>'; |
|
| 469 | 469 | } |
| 470 | - $title .= ' ' . $title_text; |
|
| 470 | + $title .= ' '.$title_text; |
|
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | |
@@ -481,8 +481,8 @@ discard block |
||
| 481 | 481 | if (is_singular('lesson')) { |
| 482 | 482 | if (has_term('', $this->taxonomy, $post->ID)) { |
| 483 | 483 | $module = $this->get_lesson_module($post->ID); |
| 484 | - if( $module ) { |
|
| 485 | - $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
| 484 | + if ($module) { |
|
| 485 | + $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>'; |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | if (is_tax($this->taxonomy)) { |
| 491 | 491 | if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
| 492 | 492 | $course_id = intval($_GET['course_id']); |
| 493 | - $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
| 493 | + $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>'; |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | return $html; |
@@ -505,18 +505,18 @@ discard block |
||
| 505 | 505 | */ |
| 506 | 506 | public function module_archive_template($template) { |
| 507 | 507 | |
| 508 | - if ( ! is_tax($this->taxonomy) ) { |
|
| 508 | + if ( ! is_tax($this->taxonomy)) { |
|
| 509 | 509 | return $template; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | $file = 'archive-lesson.php'; |
| 513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
| 513 | + $find = array($file, Sensei()->template_url.$file); |
|
| 514 | 514 | |
| 515 | 515 | // locate the template file |
| 516 | 516 | $template = locate_template($find); |
| 517 | - if (!$template) { |
|
| 517 | + if ( ! $template) { |
|
| 518 | 518 | |
| 519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
| 519 | + $template = Sensei()->plugin_path().'templates/'.$file; |
|
| 520 | 520 | |
| 521 | 521 | } |
| 522 | 522 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | // Set order of lessons |
| 543 | 543 | if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
| 544 | 544 | $module_id = $query->queried_object_id; |
| 545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
| 545 | + $query->set('meta_key', '_order_module_'.$module_id); |
|
| 546 | 546 | $query->set('orderby', 'meta_value_num date'); |
| 547 | 547 | } else { |
| 548 | 548 | $query->set('orderby', 'menu_order'); |
@@ -603,10 +603,10 @@ discard block |
||
| 603 | 603 | $status = __('In progress', 'woothemes-sensei'); |
| 604 | 604 | $class = 'in-progress'; |
| 605 | 605 | } |
| 606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
| 606 | + echo '<p class="status '.esc_attr($class).'">'.$status.'</p>'; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
| 609 | + echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>'; |
|
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
| 732 | 732 | { |
| 733 | 733 | $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
| 734 | - update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
| 734 | + update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress)); |
|
| 735 | 735 | |
| 736 | 736 | do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
| 737 | 737 | } |
@@ -748,9 +748,9 @@ discard block |
||
| 748 | 748 | */ |
| 749 | 749 | public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
| 750 | 750 | { |
| 751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
| 751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true); |
|
| 752 | 752 | if ($module_progress) { |
| 753 | - return (float)$module_progress; |
|
| 753 | + return (float) $module_progress; |
|
| 754 | 754 | } |
| 755 | 755 | return false; |
| 756 | 756 | } |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | } |
| 804 | 804 | $module_progress = ($completed_count / $lesson_count) * 100; |
| 805 | 805 | |
| 806 | - return (float)$module_progress; |
|
| 806 | + return (float) $module_progress; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | public function register_modules_admin_menu_items() |
| 817 | 817 | { |
| 818 | 818 | //add the modules link under the Course main menu |
| 819 | - add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
| 819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', ''); |
|
| 820 | 820 | |
| 821 | 821 | // Regsiter new admin page for module ordering |
| 822 | 822 | $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
@@ -843,19 +843,19 @@ discard block |
||
| 843 | 843 | $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
| 844 | 844 | |
| 845 | 845 | if ($ordered) { |
| 846 | - $html .= '<div class="updated fade">' . "\n"; |
|
| 847 | - $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
| 848 | - $html .= '</div>' . "\n"; |
|
| 846 | + $html .= '<div class="updated fade">'."\n"; |
|
| 847 | + $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n"; |
|
| 848 | + $html .= '</div>'."\n"; |
|
| 849 | 849 | } |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | $courses = Sensei()->course->get_all_courses(); |
| 853 | 853 | |
| 854 | - $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
| 855 | - $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
| 856 | - $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
| 857 | - $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
| 858 | - $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
| 854 | + $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n"; |
|
| 855 | + $html .= '<input type="hidden" name="post_type" value="course" />'."\n"; |
|
| 856 | + $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n"; |
|
| 857 | + $html .= '<select id="module-order-course" name="course_id">'."\n"; |
|
| 858 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n"; |
|
| 859 | 859 | |
| 860 | 860 | foreach ($courses as $course) { |
| 861 | 861 | if (has_term('', $this->taxonomy, $course->ID)) { |
@@ -863,30 +863,30 @@ discard block |
||
| 863 | 863 | if (isset($_GET['course_id'])) { |
| 864 | 864 | $course_id = intval($_GET['course_id']); |
| 865 | 865 | } |
| 866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
| 866 | + $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n"; |
|
| 867 | 867 | } |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | - $html .= '</select>' . "\n"; |
|
| 871 | - $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
| 872 | - $html .= '</form>' . "\n"; |
|
| 870 | + $html .= '</select>'."\n"; |
|
| 871 | + $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n"; |
|
| 872 | + $html .= '</form>'."\n"; |
|
| 873 | 873 | |
| 874 | 874 | if (isset($_GET['course_id'])) { |
| 875 | 875 | $course_id = intval($_GET['course_id']); |
| 876 | 876 | if ($course_id > 0) { |
| 877 | 877 | $modules = $this->get_course_modules($course_id); |
| 878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
| 878 | + $modules = $this->append_teacher_name_to_module($modules, array('module'), array()); |
|
| 879 | 879 | if ($modules) { |
| 880 | 880 | |
| 881 | 881 | $order = $this->get_course_module_order($course_id); |
| 882 | 882 | |
| 883 | - $order_string=''; |
|
| 883 | + $order_string = ''; |
|
| 884 | 884 | if ($order) { |
| 885 | 885 | $order_string = implode(',', $order); |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
| 889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
| 888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
| 889 | + $html .= '<ul class="sortable-module-list">'."\n"; |
|
| 890 | 890 | $count = 0; |
| 891 | 891 | foreach ($modules as $module) { |
| 892 | 892 | $count++; |
@@ -900,14 +900,14 @@ discard block |
||
| 900 | 900 | if ($count % 2 != 0) { |
| 901 | 901 | $class .= ' alternate'; |
| 902 | 902 | } |
| 903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
| 903 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n"; |
|
| 904 | 904 | } |
| 905 | - $html .= '</ul>' . "\n"; |
|
| 905 | + $html .= '</ul>'."\n"; |
|
| 906 | 906 | |
| 907 | - $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
| 908 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
| 909 | - $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
| 910 | - $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
| 907 | + $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n"; |
|
| 908 | + $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n"; |
|
| 909 | + $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n"; |
|
| 910 | + $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n"; |
|
| 911 | 911 | } |
| 912 | 912 | } |
| 913 | 913 | } |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | { |
| 945 | 945 | if ($column == 'module_order') { |
| 946 | 946 | if (has_term('', $this->taxonomy, $course_id)) { |
| 947 | - echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
| 947 | + echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>'; |
|
| 948 | 948 | } |
| 949 | 949 | } |
| 950 | 950 | } |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | $args['post_type'] = 'lesson'; |
| 1037 | 1037 | $lessons = get_posts($args); |
| 1038 | 1038 | $total_lessons = count($lessons); |
| 1039 | - $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
| 1039 | + $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>'; |
|
| 1040 | 1040 | break; |
| 1041 | 1041 | } |
| 1042 | 1042 | |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | public function analysis_overview_column_title($columns) |
| 1055 | 1055 | { |
| 1056 | 1056 | |
| 1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1057 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
| 1058 | 1058 | $new_columns = array(); |
| 1059 | 1059 | if (is_array($columns) && 0 < count($columns)) { |
| 1060 | 1060 | foreach ($columns as $column => $title) { |
@@ -1082,15 +1082,15 @@ discard block |
||
| 1082 | 1082 | * @param WP_Post $lesson |
| 1083 | 1083 | * @return array Updated column data |
| 1084 | 1084 | */ |
| 1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
| 1085 | + public function analysis_overview_column_data($columns, $lesson) |
|
| 1086 | 1086 | { |
| 1087 | 1087 | |
| 1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1088 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
| 1089 | 1089 | $lesson_module = ''; |
| 1090 | 1090 | $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
| 1091 | 1091 | if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
| 1092 | 1092 | foreach ($lesson_module_list as $single_module) { |
| 1093 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1093 | + $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>'; |
|
| 1094 | 1094 | break; |
| 1095 | 1095 | } |
| 1096 | 1096 | } |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | */ |
| 1112 | 1112 | public function analysis_course_column_title($columns) |
| 1113 | 1113 | { |
| 1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
| 1114 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
| 1115 | 1115 | $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
| 1116 | 1116 | } |
| 1117 | 1117 | return $columns; |
@@ -1126,15 +1126,15 @@ discard block |
||
| 1126 | 1126 | * @param WP_Post $lesson |
| 1127 | 1127 | * @return array Updated columns data |
| 1128 | 1128 | */ |
| 1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
| 1129 | + public function analysis_course_column_data($columns, $lesson) |
|
| 1130 | 1130 | { |
| 1131 | 1131 | |
| 1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 1132 | + if (isset($_GET['course_id'])) { |
|
| 1133 | 1133 | $lesson_module = ''; |
| 1134 | 1134 | $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
| 1135 | 1135 | if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
| 1136 | 1136 | foreach ($lesson_module_list as $single_module) { |
| 1137 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
| 1137 | + $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>'; |
|
| 1138 | 1138 | break; |
| 1139 | 1139 | } |
| 1140 | 1140 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | public function get_lesson_module($lesson_id = 0) |
| 1162 | 1162 | { |
| 1163 | 1163 | $lesson_id = intval($lesson_id); |
| 1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
| 1164 | + if ( ! (intval($lesson_id > 0))) { |
|
| 1165 | 1165 | return false; |
| 1166 | 1166 | } |
| 1167 | 1167 | |
@@ -1169,13 +1169,13 @@ discard block |
||
| 1169 | 1169 | $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
| 1170 | 1170 | |
| 1171 | 1171 | //check if error returned |
| 1172 | - if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
| 1172 | + if (empty($modules) || isset($modules['errors'])) { |
|
| 1173 | 1173 | return false; |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | // get the last item in the array there should be only be 1 really. |
| 1177 | 1177 | // this method works for all php versions. |
| 1178 | - foreach( $modules as $module ){ |
|
| 1178 | + foreach ($modules as $module) { |
|
| 1179 | 1179 | break; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | if (isset($course_id) && 0 < $course_id) { |
| 1189 | 1189 | |
| 1190 | 1190 | // the course should contain the same module taxonomy term for this to be valid |
| 1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
| 1191 | + if ( ! has_term($module, $this->taxonomy, $course_id)) { |
|
| 1192 | 1192 | return false; |
| 1193 | 1193 | } |
| 1194 | 1194 | |
@@ -1262,8 +1262,8 @@ discard block |
||
| 1262 | 1262 | { |
| 1263 | 1263 | |
| 1264 | 1264 | |
| 1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1265 | + wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version); |
|
| 1266 | + wp_enqueue_style($this->taxonomy.'-frontend'); |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | 1269 | /** |
@@ -1273,37 +1273,37 @@ discard block |
||
| 1273 | 1273 | * |
| 1274 | 1274 | * @return void |
| 1275 | 1275 | */ |
| 1276 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1276 | + public function admin_enqueue_scripts($hook) { |
|
| 1277 | 1277 | |
| 1278 | 1278 | /** |
| 1279 | 1279 | * Filter the page hooks where modules admin script can be loaded on. |
| 1280 | 1280 | * |
| 1281 | 1281 | * @param array $white_listed_pages |
| 1282 | 1282 | */ |
| 1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1283 | + $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array( |
|
| 1284 | 1284 | 'edit-tags.php', |
| 1285 | 1285 | 'course_page_module-order', |
| 1286 | 1286 | 'post-new.php', |
| 1287 | 1287 | 'post.php' |
| 1288 | - ) ); |
|
| 1288 | + )); |
|
| 1289 | 1289 | |
| 1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1290 | + if ( ! in_array($hook, $script_on_pages_white_list)) { |
|
| 1291 | 1291 | return; |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1294 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1295 | 1295 | |
| 1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1298 | - wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true ); |
|
| 1296 | + wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true); |
|
| 1297 | + wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true); |
|
| 1298 | + wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2'), Sensei()->version, true); |
|
| 1299 | 1299 | |
| 1300 | 1300 | // localized module data |
| 1301 | 1301 | $localize_modulesAdmin = array( |
| 1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1302 | + 'search_courses_nonce' => wp_create_nonce('search-courses'), |
|
| 1303 | + 'selectPlaceholder' => __('Search for courses', 'woothemes-sensei') |
|
| 1304 | 1304 | ); |
| 1305 | 1305 | |
| 1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1306 | + wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | /** |
@@ -1316,8 +1316,8 @@ discard block |
||
| 1316 | 1316 | public function admin_enqueue_styles() { |
| 1317 | 1317 | |
| 1318 | 1318 | |
| 1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1319 | + wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version); |
|
| 1320 | + wp_enqueue_style($this->taxonomy.'-sortable'); |
|
| 1321 | 1321 | |
| 1322 | 1322 | } |
| 1323 | 1323 | |
@@ -1331,9 +1331,9 @@ discard block |
||
| 1331 | 1331 | */ |
| 1332 | 1332 | public function course_modules_title( ) { |
| 1333 | 1333 | |
| 1334 | - if( sensei_module_has_lessons() ){ |
|
| 1334 | + if (sensei_module_has_lessons()) { |
|
| 1335 | 1335 | |
| 1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1336 | + echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>'; |
|
| 1337 | 1337 | |
| 1338 | 1338 | } |
| 1339 | 1339 | |
@@ -1346,18 +1346,18 @@ discard block |
||
| 1346 | 1346 | * @since 1.8.0 |
| 1347 | 1347 | * @return void |
| 1348 | 1348 | */ |
| 1349 | - public function load_course_module_content_template(){ |
|
| 1349 | + public function load_course_module_content_template() { |
|
| 1350 | 1350 | |
| 1351 | 1351 | // load backwards compatible template name if it exists in the users theme |
| 1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1353 | - if( $located_template ){ |
|
| 1352 | + $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php'); |
|
| 1353 | + if ($located_template) { |
|
| 1354 | 1354 | |
| 1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1355 | + Sensei_Templates::get_template('single-course/course-modules.php'); |
|
| 1356 | 1356 | return; |
| 1357 | 1357 | |
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1360 | + Sensei_Templates::get_template('single-course/modules.php'); |
|
| 1361 | 1361 | |
| 1362 | 1362 | } // end course_module_content |
| 1363 | 1363 | |
@@ -1370,15 +1370,15 @@ discard block |
||
| 1370 | 1370 | * @param $term_id |
| 1371 | 1371 | * @return array $lessons |
| 1372 | 1372 | */ |
| 1373 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1373 | + public function get_lessons($course_id, $term_id) { |
|
| 1374 | 1374 | |
| 1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1375 | + $lesson_query = $this->get_lessons_query($course_id, $term_id); |
|
| 1376 | 1376 | |
| 1377 | - if( isset( $lesson_query->posts ) ){ |
|
| 1377 | + if (isset($lesson_query->posts)) { |
|
| 1378 | 1378 | |
| 1379 | 1379 | return $lesson_query->posts; |
| 1380 | 1380 | |
| 1381 | - }else{ |
|
| 1381 | + } else { |
|
| 1382 | 1382 | |
| 1383 | 1383 | return array(); |
| 1384 | 1384 | |
@@ -1395,9 +1395,9 @@ discard block |
||
| 1395 | 1395 | * @param $term_id |
| 1396 | 1396 | * @return WP_Query $lessons_query |
| 1397 | 1397 | */ |
| 1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1398 | + public function get_lessons_query($course_id, $term_id) { |
|
| 1399 | 1399 | |
| 1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1400 | + if (empty($term_id) || empty($course_id)) { |
|
| 1401 | 1401 | |
| 1402 | 1402 | return array(); |
| 1403 | 1403 | |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | array( |
| 1419 | 1419 | 'taxonomy' => 'module', |
| 1420 | 1420 | 'field' => 'id', |
| 1421 | - 'terms' => intval( $term_id ) |
|
| 1421 | + 'terms' => intval($term_id) |
|
| 1422 | 1422 | ) |
| 1423 | 1423 | ), |
| 1424 | 1424 | 'orderby' => 'menu_order', |
@@ -1426,12 +1426,12 @@ discard block |
||
| 1426 | 1426 | 'suppress_filters' => 0 |
| 1427 | 1427 | ); |
| 1428 | 1428 | |
| 1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1429 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 1430 | + $args['meta_key'] = '_order_module_'.intval($term_id); |
|
| 1431 | 1431 | $args['orderby'] = 'meta_value_num date'; |
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | - $lessons_query = new WP_Query( $args ); |
|
| 1434 | + $lessons_query = new WP_Query($args); |
|
| 1435 | 1435 | |
| 1436 | 1436 | return $lessons_query; |
| 1437 | 1437 | |
@@ -1446,37 +1446,37 @@ discard block |
||
| 1446 | 1446 | * |
| 1447 | 1447 | * @return array $non_module_lessons |
| 1448 | 1448 | */ |
| 1449 | - public function get_none_module_lessons( $course_id ){ |
|
| 1449 | + public function get_none_module_lessons($course_id) { |
|
| 1450 | 1450 | |
| 1451 | 1451 | $non_module_lessons = array(); |
| 1452 | 1452 | |
| 1453 | 1453 | //exit if there is no course id passed in |
| 1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1454 | + if (empty($course_id) || 'course' != get_post_type($course_id)) { |
|
| 1455 | 1455 | |
| 1456 | 1456 | return $non_module_lessons; |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | //save some time and check if we already have the saved |
| 1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1460 | + if (get_transient('sensei_'.$course_id.'_none_module_lessons')) { |
|
| 1461 | 1461 | |
| 1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1462 | + return get_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
| 1463 | 1463 | |
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // create terms array which must be excluded from other arrays |
| 1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1467 | + $course_modules = $this->get_course_modules($course_id); |
|
| 1468 | 1468 | |
| 1469 | 1469 | //exit if there are no module on this course |
| 1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1470 | + if (empty($course_modules) || ! is_array($course_modules)) { |
|
| 1471 | 1471 | |
| 1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1472 | + return Sensei()->course->course_lessons($course_id); |
|
| 1473 | 1473 | |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | $terms = array(); |
| 1477 | - foreach( $course_modules as $module ){ |
|
| 1477 | + foreach ($course_modules as $module) { |
|
| 1478 | 1478 | |
| 1479 | - array_push( $terms , $module->term_id ); |
|
| 1479 | + array_push($terms, $module->term_id); |
|
| 1480 | 1480 | |
| 1481 | 1481 | } |
| 1482 | 1482 | |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | 'meta_query' => array( |
| 1488 | 1488 | array( |
| 1489 | 1489 | 'key' => '_lesson_course', |
| 1490 | - 'value' => intval( $course_id ), |
|
| 1490 | + 'value' => intval($course_id), |
|
| 1491 | 1491 | 'compare' => '=' |
| 1492 | 1492 | ) |
| 1493 | 1493 | ), |
@@ -1504,11 +1504,11 @@ discard block |
||
| 1504 | 1504 | 'suppress_filters' => 0 |
| 1505 | 1505 | ); |
| 1506 | 1506 | |
| 1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1507 | + $wp_lessons_query = new WP_Query($args); |
|
| 1508 | 1508 | |
| 1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1509 | + if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) { |
|
| 1510 | 1510 | $non_module_lessons = $wp_lessons_query->get_posts(); |
| 1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1511 | + set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS); |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | return $non_module_lessons; |
@@ -1519,7 +1519,7 @@ discard block |
||
| 1519 | 1519 | * |
| 1520 | 1520 | * @since 1.8.0 |
| 1521 | 1521 | */ |
| 1522 | - public function setup_modules_taxonomy(){ |
|
| 1522 | + public function setup_modules_taxonomy() { |
|
| 1523 | 1523 | |
| 1524 | 1524 | $labels = array( |
| 1525 | 1525 | 'name' => __('Modules', 'woothemes-sensei'), |
@@ -1556,11 +1556,11 @@ discard block |
||
| 1556 | 1556 | 'show_in_nav_menus' => false, |
| 1557 | 1557 | 'show_in_quick_edit' => false, |
| 1558 | 1558 | 'show_ui' => true, |
| 1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug), |
|
| 1560 | 1560 | 'labels' => $labels |
| 1561 | 1561 | ); |
| 1562 | 1562 | |
| 1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1563 | + register_taxonomy('module', array('course', 'lesson'), $args); |
|
| 1564 | 1564 | |
| 1565 | 1565 | }// end setup_modules_taxonomy |
| 1566 | 1566 | |
@@ -1572,12 +1572,12 @@ discard block |
||
| 1572 | 1572 | * @since 1.8.0 |
| 1573 | 1573 | * @return void |
| 1574 | 1574 | */ |
| 1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1575 | + function redirect_to_lesson_module_taxonomy_to_course( ) { |
|
| 1576 | 1576 | |
| 1577 | - global $typenow , $taxnow; |
|
| 1577 | + global $typenow, $taxnow; |
|
| 1578 | 1578 | |
| 1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1579 | + if ('lesson' == $typenow && 'module' == $taxnow) { |
|
| 1580 | + wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course')); |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | }// end redirect to course taxonomy |
@@ -1590,18 +1590,18 @@ discard block |
||
| 1590 | 1590 | * @since 1.8.0 |
| 1591 | 1591 | * @return void |
| 1592 | 1592 | */ |
| 1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1593 | + public function remove_lessons_menu_model_taxonomy() { |
|
| 1594 | 1594 | global $submenu; |
| 1595 | 1595 | |
| 1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1596 | + if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) { |
|
| 1597 | 1597 | return; // exit |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
| 1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1601 | + foreach ($lesson_main_menu as $index => $sub_item) { |
|
| 1602 | 1602 | |
| 1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1603 | + if ('edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2]) { |
|
| 1604 | + unset($submenu['edit.php?post_type=lesson'][$index]); |
|
| 1605 | 1605 | } |
| 1606 | 1606 | } |
| 1607 | 1607 | |
@@ -1615,18 +1615,18 @@ discard block |
||
| 1615 | 1615 | * @since 1.8.0 |
| 1616 | 1616 | * @return void |
| 1617 | 1617 | */ |
| 1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1618 | + public function remove_courses_menu_model_taxonomy() { |
|
| 1619 | 1619 | global $submenu; |
| 1620 | 1620 | |
| 1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1621 | + if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) { |
|
| 1622 | 1622 | return; // exit |
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | $course_main_menu = $submenu['edit.php?post_type=course']; |
| 1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1626 | + foreach ($course_main_menu as $index => $sub_item) { |
|
| 1627 | 1627 | |
| 1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1628 | + if ('edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2]) { |
|
| 1629 | + unset($submenu['edit.php?post_type=course'][$index]); |
|
| 1630 | 1630 | } |
| 1631 | 1631 | } |
| 1632 | 1632 | |
@@ -1642,12 +1642,12 @@ discard block |
||
| 1642 | 1642 | * @param string $term_name |
| 1643 | 1643 | * @return array $owners { type WP_User }. Empty array if none if found. |
| 1644 | 1644 | */ |
| 1645 | - public static function get_term_authors( $term_name ){ |
|
| 1645 | + public static function get_term_authors($term_name) { |
|
| 1646 | 1646 | |
| 1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1647 | + $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false)); |
|
| 1648 | 1648 | |
| 1649 | 1649 | $owners = array(); |
| 1650 | - if( empty( $terms ) ){ |
|
| 1650 | + if (empty($terms)) { |
|
| 1651 | 1651 | |
| 1652 | 1652 | return $owners; |
| 1653 | 1653 | |
@@ -1657,11 +1657,11 @@ discard block |
||
| 1657 | 1657 | |
| 1658 | 1658 | |
| 1659 | 1659 | //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
| 1660 | - foreach( $terms as $term){ |
|
| 1661 | - if( $term->name == $term_name ){ |
|
| 1660 | + foreach ($terms as $term) { |
|
| 1661 | + if ($term->name == $term_name) { |
|
| 1662 | 1662 | |
| 1663 | 1663 | // look for the author in the slug |
| 1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1664 | + $owners[] = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1665 | 1665 | |
| 1666 | 1666 | }// end if term name |
| 1667 | 1667 | |
@@ -1682,30 +1682,30 @@ discard block |
||
| 1682 | 1682 | * @param $slug |
| 1683 | 1683 | * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
| 1684 | 1684 | */ |
| 1685 | - public static function get_term_author( $slug='' ){ |
|
| 1685 | + public static function get_term_author($slug = '') { |
|
| 1686 | 1686 | |
| 1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1687 | + $term_owner = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1688 | 1688 | |
| 1689 | - if( empty( $slug ) ){ |
|
| 1689 | + if (empty($slug)) { |
|
| 1690 | 1690 | |
| 1691 | 1691 | return $term_owner; |
| 1692 | 1692 | |
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | // look for the author in the slug |
| 1696 | - $slug_parts = explode( '-', $slug ); |
|
| 1696 | + $slug_parts = explode('-', $slug); |
|
| 1697 | 1697 | |
| 1698 | - if( count( $slug_parts ) > 1 ){ |
|
| 1698 | + if (count($slug_parts) > 1) { |
|
| 1699 | 1699 | |
| 1700 | 1700 | // get the user data |
| 1701 | 1701 | $possible_user_id = $slug_parts[0]; |
| 1702 | - $author = get_userdata( $possible_user_id ); |
|
| 1702 | + $author = get_userdata($possible_user_id); |
|
| 1703 | 1703 | |
| 1704 | 1704 | // if the user doesnt exist for the first part of the slug |
| 1705 | 1705 | // then this slug was also created by admin |
| 1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1706 | + if (is_a($author, 'WP_User')) { |
|
| 1707 | 1707 | |
| 1708 | - $term_owner = $author; |
|
| 1708 | + $term_owner = $author; |
|
| 1709 | 1709 | |
| 1710 | 1710 | } |
| 1711 | 1711 | } |
@@ -1722,48 +1722,48 @@ discard block |
||
| 1722 | 1722 | * |
| 1723 | 1723 | * @param WP_Post $post Post object. |
| 1724 | 1724 | */ |
| 1725 | - public function course_module_metabox( $post ) { |
|
| 1725 | + public function course_module_metabox($post) { |
|
| 1726 | 1726 | |
| 1727 | 1727 | $tax_name = 'module'; |
| 1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1728 | + $taxonomy = get_taxonomy('module'); |
|
| 1729 | 1729 | |
| 1730 | 1730 | ?> |
| 1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
| 1734 | - <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li> |
|
| 1734 | + <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li> |
|
| 1735 | 1735 | </ul> |
| 1736 | 1736 | |
| 1737 | 1737 | <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;"> |
| 1738 | 1738 | <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" > |
| 1739 | - <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?> |
|
| 1739 | + <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?> |
|
| 1740 | 1740 | </ul> |
| 1741 | 1741 | </div> |
| 1742 | 1742 | |
| 1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1744 | 1744 | <?php |
| 1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1745 | + $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']'; |
|
| 1746 | 1746 | echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
| 1747 | 1747 | ?> |
| 1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1749 | - <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
|
| 1749 | + <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?> |
|
| 1750 | 1750 | </ul> |
| 1751 | 1751 | </div> |
| 1752 | - <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> |
|
| 1752 | + <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?> |
|
| 1753 | 1753 | <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children"> |
| 1754 | 1754 | <h4> |
| 1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1756 | 1756 | <?php |
| 1757 | 1757 | /* translators: %s: add new taxonomy label */ |
| 1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1758 | + printf(__('+ %s'), $taxonomy->labels->add_new_item); |
|
| 1759 | 1759 | ?> |
| 1760 | 1760 | </a> |
| 1761 | 1761 | </h4> |
| 1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
| 1763 | 1763 | <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
| 1764 | - <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/> |
|
| 1765 | - <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a> |
|
| 1766 | - <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?> |
|
| 1764 | + <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/> |
|
| 1765 | + <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a> |
|
| 1766 | + <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?> |
|
| 1767 | 1767 | <span id="<?php echo $tax_name; ?>-ajax-response"></span> |
| 1768 | 1768 | </p> |
| 1769 | 1769 | </div> |
@@ -1783,55 +1783,55 @@ discard block |
||
| 1783 | 1783 | public static function add_new_module_term( ) { |
| 1784 | 1784 | |
| 1785 | 1785 | |
| 1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1786 | + if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) { |
|
| 1787 | + wp_send_json_error(array('error'=> 'wrong security nonce')); |
|
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | 1790 | // get the term an create the new term storing infomration |
| 1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1791 | + $term_name = sanitize_text_field($_POST['newTerm']); |
|
| 1792 | 1792 | |
| 1793 | - if( current_user_can('manage_options' ) ) { |
|
| 1793 | + if (current_user_can('manage_options')) { |
|
| 1794 | 1794 | |
| 1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1795 | + $term_slug = str_ireplace(' ', '-', trim($term_name)); |
|
| 1796 | 1796 | |
| 1797 | 1797 | } else { |
| 1798 | 1798 | |
| 1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1799 | + $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name)); |
|
| 1800 | 1800 | |
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1803 | + $course_id = sanitize_text_field($_POST['course_id']); |
|
| 1804 | 1804 | |
| 1805 | 1805 | // save the term |
| 1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1806 | + $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug)); |
|
| 1807 | 1807 | |
| 1808 | 1808 | // send error for all errors except term exits |
| 1809 | - if( is_wp_error( $slug ) ){ |
|
| 1809 | + if (is_wp_error($slug)) { |
|
| 1810 | 1810 | |
| 1811 | 1811 | // prepare for possible term name and id to be passed down if term exists |
| 1812 | 1812 | $term_data = array(); |
| 1813 | 1813 | |
| 1814 | 1814 | // if term exists also send back the term name and id |
| 1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1815 | + if (isset($slug->errors['term_exists'])) { |
|
| 1816 | 1816 | |
| 1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1817 | + $term = get_term_by('slug', $term_slug, 'module'); |
|
| 1818 | 1818 | $term_data['name'] = $term_name; |
| 1819 | 1819 | $term_data['id'] = $term->term_id; |
| 1820 | 1820 | |
| 1821 | 1821 | // set the object terms |
| 1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1822 | + wp_set_object_terms($course_id, $term->term_id, 'module', true); |
|
| 1823 | 1823 | } |
| 1824 | 1824 | |
| 1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1825 | + wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data)); |
|
| 1826 | 1826 | |
| 1827 | 1827 | } |
| 1828 | 1828 | |
| 1829 | 1829 | //make sure the new term is checked for this course |
| 1830 | 1830 | |
| 1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1831 | + wp_set_object_terms($course_id, $slug['term_id'], 'module', true); |
|
| 1832 | 1832 | |
| 1833 | 1833 | // Handle request then generate response using WP_Ajax_Response |
| 1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1834 | + wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name)); |
|
| 1835 | 1835 | |
| 1836 | 1836 | } |
| 1837 | 1837 | |
@@ -1843,26 +1843,26 @@ discard block |
||
| 1843 | 1843 | * |
| 1844 | 1844 | * @since 1.8.0 |
| 1845 | 1845 | */ |
| 1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1846 | + public function filter_module_terms($terms, $taxonomies, $args) { |
|
| 1847 | 1847 | |
| 1848 | 1848 | //dont limit for admins and other taxonomies. This should also only apply to admin |
| 1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1849 | + if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
| 1850 | 1850 | return $terms; |
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | 1853 | // avoid infinite call loop |
| 1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1854 | + remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
| 1855 | 1855 | |
| 1856 | 1856 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
| 1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1857 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
| 1858 | 1858 | // change only scrub the terms ids form the array keys |
| 1859 | - $terms = array_keys( $terms ); |
|
| 1859 | + $terms = array_keys($terms); |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1862 | + $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
| 1863 | 1863 | |
| 1864 | 1864 | // add filter again as removed above |
| 1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1865 | + add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
| 1866 | 1866 | |
| 1867 | 1867 | return $teachers_terms; |
| 1868 | 1868 | }// end filter_module_terms |
@@ -1875,25 +1875,25 @@ discard block |
||
| 1875 | 1875 | * |
| 1876 | 1876 | * @since 1.8.0 |
| 1877 | 1877 | */ |
| 1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1878 | + public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) { |
|
| 1879 | 1879 | |
| 1880 | 1880 | //dont limit for admins and other taxonomies. This should also only apply to admin |
| 1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1881 | + if (current_user_can('manage_options') || ! is_admin() || empty($terms) |
|
| 1882 | 1882 | // only apply this to module only taxonomy queries so 1 taxonomy only: |
| 1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1883 | + || count($taxonomies) > 1 || ! in_array('module', $taxonomies)) { |
|
| 1884 | 1884 | return $terms; |
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1887 | + $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
| 1888 | 1888 | |
| 1889 | 1889 | // if term objects were passed in send back objects |
| 1890 | 1890 | // if term id were passed in send that back |
| 1891 | - if( is_object( $terms[0] ) ){ |
|
| 1891 | + if (is_object($terms[0])) { |
|
| 1892 | 1892 | return $term_objects; |
| 1893 | 1893 | } |
| 1894 | 1894 | |
| 1895 | 1895 | $terms = array(); |
| 1896 | - foreach( $term_objects as $term_object ){ |
|
| 1896 | + foreach ($term_objects as $term_object) { |
|
| 1897 | 1897 | $terms[] = $term_object->term_id; |
| 1898 | 1898 | } |
| 1899 | 1899 | |
@@ -1911,20 +1911,20 @@ discard block |
||
| 1911 | 1911 | * @param $user_id |
| 1912 | 1912 | * @return array |
| 1913 | 1913 | */ |
| 1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1914 | + public function filter_terms_by_owner($terms, $user_id) { |
|
| 1915 | 1915 | |
| 1916 | 1916 | $users_terms = array(); |
| 1917 | 1917 | |
| 1918 | - foreach( $terms as $index => $term ){ |
|
| 1918 | + foreach ($terms as $index => $term) { |
|
| 1919 | 1919 | |
| 1920 | - if( is_numeric( $term ) ){ |
|
| 1920 | + if (is_numeric($term)) { |
|
| 1921 | 1921 | // the term id was given, get the term object |
| 1922 | - $term = get_term( $term, 'module' ); |
|
| 1922 | + $term = get_term($term, 'module'); |
|
| 1923 | 1923 | } |
| 1924 | 1924 | |
| 1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1925 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1926 | 1926 | |
| 1927 | - if ( $user_id == $author->ID ) { |
|
| 1927 | + if ($user_id == $author->ID) { |
|
| 1928 | 1928 | // add the term to the teachers terms |
| 1929 | 1929 | $users_terms[] = $term; |
| 1930 | 1930 | } |
@@ -1943,34 +1943,34 @@ discard block |
||
| 1943 | 1943 | * |
| 1944 | 1944 | * @since 1.8.0 |
| 1945 | 1945 | */ |
| 1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1946 | + public function append_teacher_name_to_module($terms, $taxonomies, $args) |
|
| 1947 | 1947 | { |
| 1948 | 1948 | |
| 1949 | 1949 | // only for admin users ont he module taxonomy |
| 1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1950 | + if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
| 1951 | 1951 | return $terms; |
| 1952 | 1952 | } |
| 1953 | 1953 | |
| 1954 | 1954 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
| 1955 | 1955 | // simply return this as wp doesn't need an array of stdObject Term |
| 1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1956 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
| 1957 | 1957 | |
| 1958 | 1958 | return $terms; |
| 1959 | 1959 | |
| 1960 | 1960 | } |
| 1961 | 1961 | |
| 1962 | 1962 | // loop through and update all terms adding the author name |
| 1963 | - foreach( $terms as $index => $term ){ |
|
| 1963 | + foreach ($terms as $index => $term) { |
|
| 1964 | 1964 | |
| 1965 | - if( is_numeric( $term ) ){ |
|
| 1965 | + if (is_numeric($term)) { |
|
| 1966 | 1966 | // the term id was given, get the term object |
| 1967 | - $term = get_term( $term, 'module' ); |
|
| 1967 | + $term = get_term($term, 'module'); |
|
| 1968 | 1968 | } |
| 1969 | 1969 | |
| 1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1970 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1971 | 1971 | |
| 1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
| 1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1972 | + if ( ! user_can($author, 'manage_options')) { |
|
| 1973 | + $term->name = $term->name.' ('.$author->display_name.') '; |
|
| 1974 | 1974 | } |
| 1975 | 1975 | |
| 1976 | 1976 | // add the term to the teachers terms |
@@ -1999,23 +1999,23 @@ discard block |
||
| 1999 | 1999 | * @sine 1.9.0 |
| 2000 | 2000 | * @param $post_id |
| 2001 | 2001 | */ |
| 2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 2002 | + public static function reset_none_modules_transient($post_id) { |
|
| 2003 | 2003 | |
| 2004 | 2004 | // this should only apply to course and lesson post types |
| 2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2005 | + if (in_array(get_post_type($post_id), array('course', 'lesson'))) { |
|
| 2006 | 2006 | |
| 2007 | 2007 | $course_id = ''; |
| 2008 | 2008 | |
| 2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2009 | + if ('lesson' == get_post_type($post_id)) { |
|
| 2010 | 2010 | |
| 2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2011 | + $course_id = Sensei()->lesson->get_course_id($post_id); |
|
| 2012 | 2012 | |
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | 2015 | |
| 2016 | - if( !empty( $course_id ) ){ |
|
| 2016 | + if ( ! empty($course_id)) { |
|
| 2017 | 2017 | |
| 2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2018 | + delete_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
| 2019 | 2019 | |
| 2020 | 2020 | } |
| 2021 | 2021 | |
@@ -2030,9 +2030,9 @@ discard block |
||
| 2030 | 2030 | * @deprecated since 1.9.0 |
| 2031 | 2031 | * |
| 2032 | 2032 | */ |
| 2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2033 | + public static function deprecate_sensei_single_course_modules_content() { |
|
| 2034 | 2034 | |
| 2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2035 | + sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after'); |
|
| 2036 | 2036 | |
| 2037 | 2037 | } |
| 2038 | 2038 | |
@@ -2043,12 +2043,12 @@ discard block |
||
| 2043 | 2043 | * |
| 2044 | 2044 | * @since 1.9.0 |
| 2045 | 2045 | */ |
| 2046 | - public static function setup_single_course_module_loop(){ |
|
| 2046 | + public static function setup_single_course_module_loop() { |
|
| 2047 | 2047 | |
| 2048 | 2048 | global $sensei_modules_loop, $post; |
| 2049 | 2049 | $course_id = $post->ID; |
| 2050 | 2050 | |
| 2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2051 | + $modules = Sensei()->modules->get_course_modules($course_id); |
|
| 2052 | 2052 | |
| 2053 | 2053 | //initial setup |
| 2054 | 2054 | $sensei_modules_loop['total'] = 0; |
@@ -2056,22 +2056,22 @@ discard block |
||
| 2056 | 2056 | $sensei_modules_loop['current'] = -1; |
| 2057 | 2057 | |
| 2058 | 2058 | // exit if this course doesn't have modules |
| 2059 | - if( !$modules || empty( $modules ) ){ |
|
| 2059 | + if ( ! $modules || empty($modules)) { |
|
| 2060 | 2060 | return; |
| 2061 | 2061 | } |
| 2062 | 2062 | |
| 2063 | 2063 | |
| 2064 | 2064 | $lessons_in_all_modules = array(); |
| 2065 | - foreach( $modules as $term ){ |
|
| 2065 | + foreach ($modules as $term) { |
|
| 2066 | 2066 | |
| 2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id); |
|
| 2068 | + $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module); |
|
| 2069 | 2069 | |
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | |
| 2073 | 2073 | //setup all of the modules loop variables |
| 2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2074 | + $sensei_modules_loop['total'] = count($modules); |
|
| 2075 | 2075 | $sensei_modules_loop['modules'] = $modules; |
| 2076 | 2076 | $sensei_modules_loop['current'] = -1; |
| 2077 | 2077 | $sensei_modules_loop['course_id'] = $course_id; |
@@ -2084,7 +2084,7 @@ discard block |
||
| 2084 | 2084 | * @since 1.9.0 |
| 2085 | 2085 | * |
| 2086 | 2086 | */ |
| 2087 | - public static function teardown_single_course_module_loop(){ |
|
| 2087 | + public static function teardown_single_course_module_loop() { |
|
| 2088 | 2088 | |
| 2089 | 2089 | global $sensei_modules_loop, $wp_query, $post; |
| 2090 | 2090 | |
@@ -1,6 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | /** |
| 6 | 8 | * Sensei Modules Class |
@@ -401,8 +403,9 @@ discard block |
||
| 401 | 403 | $term = urldecode(stripslashes($_GET['term'])); |
| 402 | 404 | |
| 403 | 405 | // Return nothing if term is empty |
| 404 | - if (empty($term)) |
|
| 405 | - die(); |
|
| 406 | + if (empty($term)) { |
|
| 407 | + die(); |
|
| 408 | + } |
|
| 406 | 409 | |
| 407 | 410 | // Set a default if none is given |
| 408 | 411 | $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
@@ -789,7 +792,9 @@ discard block |
||
| 789 | 792 | ); |
| 790 | 793 | $lessons = get_posts($args); |
| 791 | 794 | |
| 792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
| 795 | + if (is_wp_error($lessons) || 0 >= count($lessons)) { |
|
| 796 | + return 0; |
|
| 797 | + } |
|
| 793 | 798 | |
| 794 | 799 | $completed = false; |
| 795 | 800 | $lesson_count = 0; |
@@ -1378,7 +1383,7 @@ discard block |
||
| 1378 | 1383 | |
| 1379 | 1384 | return $lesson_query->posts; |
| 1380 | 1385 | |
| 1381 | - }else{ |
|
| 1386 | + } else{ |
|
| 1382 | 1387 | |
| 1383 | 1388 | return array(); |
| 1384 | 1389 | |
@@ -33,10 +33,6 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * |
| 35 | 35 | * |
| 36 | - * @param string $message |
|
| 37 | - * @param string $type defaults to alert options( alert, tick , download , note ) |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | 36 | */ |
| 41 | 37 | |
| 42 | 38 | public function add_notice( $content , $type = 'alert' ){ |
@@ -47,10 +43,6 @@ discard block |
||
| 47 | 43 | /** |
| 48 | 44 | * Output all notices added |
| 49 | 45 | * |
| 50 | - * @param string $message |
|
| 51 | - * @param string $type |
|
| 52 | - * |
|
| 53 | - * @return void |
|
| 54 | 46 | */ |
| 55 | 47 | |
| 56 | 48 | public function print_notices(){ |
@@ -16,28 +16,28 @@ discard block |
||
| 16 | 16 | class Sensei_Notices{ |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * @var $notices |
|
| 20 | - */ |
|
| 19 | + * @var $notices |
|
| 20 | + */ |
|
| 21 | 21 | protected $notices; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * constructor |
|
| 25 | - */ |
|
| 24 | + * constructor |
|
| 25 | + */ |
|
| 26 | 26 | public function __construct(){ |
| 27 | 27 | //initialize the notices variable |
| 28 | 28 | $this->notices = array(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Add a notice to the array of notices for display at a later stage. |
|
| 33 | - * |
|
| 34 | - * |
|
| 35 | - * |
|
| 36 | - * @param string $message |
|
| 37 | - * @param string $type defaults to alert options( alert, tick , download , note ) |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 32 | + * Add a notice to the array of notices for display at a later stage. |
|
| 33 | + * |
|
| 34 | + * |
|
| 35 | + * |
|
| 36 | + * @param string $message |
|
| 37 | + * @param string $type defaults to alert options( alert, tick , download , note ) |
|
| 38 | + * |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | 42 | public function add_notice( $content , $type = 'alert' ){ |
| 43 | 43 | // append the new notice |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | } // end add_notice() |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Output all notices added |
|
| 49 | - * |
|
| 50 | - * @param string $message |
|
| 51 | - * @param string $type |
|
| 52 | - * |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 48 | + * Output all notices added |
|
| 49 | + * |
|
| 50 | + * @param string $message |
|
| 51 | + * @param string $type |
|
| 52 | + * |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | 55 | |
| 56 | 56 | public function print_notices(){ |
| 57 | 57 | if( count( $this->notices ) > 0 ){ |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | } // end print_notice() |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Clear all notices |
|
| 72 | - * |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 71 | + * Clear all notices |
|
| 72 | + * |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | 75 | |
| 76 | 76 | public function clear_notices(){ |
| 77 | 77 | // assign an empty array to clear all existing notices |
@@ -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 Notices Class |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * @since 1.6.3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -class Sensei_Notices{ |
|
| 16 | +class Sensei_Notices { |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @var $notices |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * constructor |
| 25 | 25 | */ |
| 26 | - public function __construct(){ |
|
| 26 | + public function __construct() { |
|
| 27 | 27 | //initialize the notices variable |
| 28 | 28 | $this->notices = array(); |
| 29 | 29 | } |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - public function add_notice( $content , $type = 'alert' ){ |
|
| 42 | + public function add_notice($content, $type = 'alert') { |
|
| 43 | 43 | // append the new notice |
| 44 | - $this->notices[] = array('content' => $content , 'type'=> $type ); |
|
| 44 | + $this->notices[] = array('content' => $content, 'type'=> $type); |
|
| 45 | 45 | } // end add_notice() |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | 55 | |
| 56 | - public function print_notices(){ |
|
| 57 | - if( count( $this->notices ) > 0 ){ |
|
| 56 | + public function print_notices() { |
|
| 57 | + if (count($this->notices) > 0) { |
|
| 58 | 58 | foreach ($this->notices as $notice) { |
| 59 | 59 | |
| 60 | - $classes = 'sensei-message '. $notice['type']; |
|
| 61 | - $html = '<div class="'. $classes . '">'. $notice['content'] . '</div>'; |
|
| 60 | + $classes = 'sensei-message '.$notice['type']; |
|
| 61 | + $html = '<div class="'.$classes.'">'.$notice['content'].'</div>'; |
|
| 62 | 62 | |
| 63 | 63 | echo $html; |
| 64 | 64 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | 75 | |
| 76 | - public function clear_notices(){ |
|
| 76 | + public function clear_notices() { |
|
| 77 | 77 | // assign an empty array to clear all existing notices |
| 78 | 78 | $this->notices = array(); |
| 79 | 79 | } // end clear_notices() |
@@ -85,4 +85,4 @@ discard block |
||
| 85 | 85 | * for backward compatibility |
| 86 | 86 | * @since 1.9.0 |
| 87 | 87 | */ |
| 88 | -class Woothemes_Sensei_Notices extends Sensei_Notices{} |
|
| 88 | +class Woothemes_Sensei_Notices extends Sensei_Notices {} |
|
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * This function simply loads the question type template |
| 403 | 403 | * |
| 404 | 404 | * @since 1.9.0 |
| 405 | - * @param $question_type |
|
| 405 | + * @param string $question_type |
|
| 406 | 406 | */ |
| 407 | 407 | public static function load_question_template( $question_type ){ |
| 408 | 408 | |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | * Get the questions media markup |
| 488 | 488 | * |
| 489 | 489 | * @since 1.9.0 |
| 490 | - * @param $question_id |
|
| 490 | + * @param string $question_id |
|
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | 493 | public static function get_the_question_media( $question_id ){ |
@@ -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 = WooThemes_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' ] = WooThemes_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 = WooThemes_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' ] = WooThemes_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; |
|
| 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; |
|
| 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 |
@@ -20,34 +20,34 @@ discard block |
||
| 20 | 20 | * Constructor. |
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | - public function __construct () { |
|
| 23 | + public function __construct() { |
|
| 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 = WooThemes_Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 745 | + $user_lesson_end = WooThemes_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' ] = WooThemes_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'] = WooThemes_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,26 +943,26 @@ 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 | 968 | $question_answers_options[] = $question_option; |
@@ -972,47 +972,47 @@ discard block |
||
| 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 | * 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 {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Question Class |
@@ -211,7 +214,9 @@ discard block |
||
| 211 | 214 | |
| 212 | 215 | $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
| 213 | 216 | |
| 214 | - if( ! $lesson_id ) continue; |
|
| 217 | + if( ! $lesson_id ) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 215 | 220 | |
| 216 | 221 | $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
| 217 | 222 | $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
@@ -880,7 +885,7 @@ discard block |
||
| 880 | 885 | |
| 881 | 886 | $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
| 882 | 887 | |
| 883 | - } else { |
|
| 888 | + } else { |
|
| 884 | 889 | |
| 885 | 890 | array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
| 886 | 891 | $merged_options = $question_data[ 'question_wrong_answers' ]; |
@@ -908,7 +913,7 @@ discard block |
||
| 908 | 913 | |
| 909 | 914 | $user_correct = true; |
| 910 | 915 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 916 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 912 | 917 | |
| 913 | 918 | $user_correct = true; |
| 914 | 919 | |
@@ -923,7 +928,7 @@ discard block |
||
| 923 | 928 | |
| 924 | 929 | $answer_class .= ' right_answer'; |
| 925 | 930 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 931 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 927 | 932 | |
| 928 | 933 | $answer_class .= ' right_answer'; |
| 929 | 934 | |
@@ -1006,13 +1011,13 @@ discard block |
||
| 1006 | 1011 | } |
| 1007 | 1012 | } |
| 1008 | 1013 | |
| 1009 | - }else{ |
|
| 1014 | + } else{ |
|
| 1010 | 1015 | |
| 1011 | 1016 | $answer_options_sorted = $question_answers_options; |
| 1012 | 1017 | |
| 1013 | 1018 | } |
| 1014 | 1019 | |
| 1015 | - }else{ |
|
| 1020 | + } else{ |
|
| 1016 | 1021 | |
| 1017 | 1022 | $answer_options_sorted = $question_answers_options; |
| 1018 | 1023 | |
@@ -1075,12 +1080,12 @@ discard block |
||
| 1075 | 1080 | |
| 1076 | 1081 | $right_answer = ucfirst($right_answer); |
| 1077 | 1082 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1083 | + } elseif( 'multiple-choice' == $type ) { |
|
| 1079 | 1084 | |
| 1080 | 1085 | $right_answer = (array) $right_answer; |
| 1081 | 1086 | $right_answer = implode( ', ', $right_answer ); |
| 1082 | 1087 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1088 | + } elseif( 'gap-fill' == $type ) { |
|
| 1084 | 1089 | |
| 1085 | 1090 | $right_answer_array = explode( '||', $right_answer ); |
| 1086 | 1091 | if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
@@ -1089,7 +1094,7 @@ discard block |
||
| 1089 | 1094 | |
| 1090 | 1095 | $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
| 1091 | 1096 | |
| 1092 | - }else{ |
|
| 1097 | + } else{ |
|
| 1093 | 1098 | |
| 1094 | 1099 | // for non auto gradable question types no answer should be returned. |
| 1095 | 1100 | $right_answer = ''; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * This function hooks into the quiz page and accepts the answer form save post. |
| 125 | 125 | * @since 1.7.3 |
| 126 | - * @return bool $saved; |
|
| 126 | + * @return boolean|null $saved; |
|
| 127 | 127 | */ |
| 128 | 128 | public function user_save_quiz_answers_listener(){ |
| 129 | 129 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param int $lesson_id |
| 215 | 215 | * @param int $user_id |
| 216 | 216 | * |
| 217 | - * @return array $answers or false |
|
| 217 | + * @return boolean $answers or false |
|
| 218 | 218 | */ |
| 219 | 219 | public function get_user_answers( $lesson_id, $user_id ){ |
| 220 | 220 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @type int $question_id |
| 708 | 708 | * @type int $question_grade |
| 709 | 709 | * } |
| 710 | - * @param $lesson_id |
|
| 710 | + * @param integer $lesson_id |
|
| 711 | 711 | * @param $user_id (Optional) will use the current user if not supplied |
| 712 | 712 | * |
| 713 | 713 | * @return bool |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | * |
| 755 | 755 | * @since 1.7.4 |
| 756 | 756 | * |
| 757 | - * @param $lesson_id |
|
| 757 | + * @param integer $lesson_id |
|
| 758 | 758 | * @param $user_id (Optional) will use the current user if not supplied |
| 759 | 759 | * |
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users |
@@ -1090,7 +1090,6 @@ discard block |
||
| 1090 | 1090 | * Filter the single title and add the Quiz to it. |
| 1091 | 1091 | * |
| 1092 | 1092 | * @param string $title |
| 1093 | - * @param int $id title post id |
|
| 1094 | 1093 | * @return string $quiz_title |
| 1095 | 1094 | */ |
| 1096 | 1095 | public static function single_quiz_title( $title, $post_id ){ |
@@ -31,63 +31,63 @@ discard block |
||
| 31 | 31 | // listen to the reset button click |
| 32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
| 33 | 33 | |
| 34 | - // fire the complete quiz button submit for grading action |
|
| 35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 34 | + // fire the complete quiz button submit for grading action |
|
| 35 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder |
| 38 | 38 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
| 39 | 39 | |
| 40 | - // fire the load global data function |
|
| 41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 40 | + // fire the load global data function |
|
| 41 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - } // End __construct() |
|
| 46 | + } // End __construct() |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Update the quiz author when the lesson post type is save |
|
| 50 | - * |
|
| 51 | - * @param int $post_id |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 49 | + * Update the quiz author when the lesson post type is save |
|
| 50 | + * |
|
| 51 | + * @param int $post_id |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | 54 | public function update_author( $post_id ){ |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // If this isn't a 'lesson' post, don't update it. |
| 58 | - // if this is a revision don't save it |
|
| 59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 60 | - || wp_is_post_revision( $post_id ) ) { |
|
| 58 | + // if this is a revision don't save it |
|
| 59 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 60 | + || wp_is_post_revision( $post_id ) ) { |
|
| 61 | 61 | |
| 62 | - return; |
|
| 62 | + return; |
|
| 63 | 63 | |
| 64 | - } |
|
| 65 | - // get the lesson author id to be use late |
|
| 66 | - $saved_post = get_post( $post_id ); |
|
| 67 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 64 | + } |
|
| 65 | + // get the lesson author id to be use late |
|
| 66 | + $saved_post = get_post( $post_id ); |
|
| 67 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 68 | 68 | |
| 69 | - //get the lessons quiz |
|
| 69 | + //get the lessons quiz |
|
| 70 | 70 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
| 71 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 71 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 72 | 72 | |
| 73 | - if( ! $quiz_item ) { |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 73 | + if( ! $quiz_item ) { |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - // setup the quiz items new author value |
|
| 77 | + // setup the quiz items new author value |
|
| 78 | 78 | $my_post = array( |
| 79 | - 'ID' => $quiz_item, |
|
| 80 | - 'post_author' => $new_lesson_author_id |
|
| 79 | + 'ID' => $quiz_item, |
|
| 80 | + 'post_author' => $new_lesson_author_id |
|
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - // remove the action so that it doesn't fire again |
|
| 84 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 83 | + // remove the action so that it doesn't fire again |
|
| 84 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 85 | 85 | |
| 86 | 86 | // Update the post into the database |
| 87 | 87 | wp_update_post( $my_post ); |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return; |
|
| 90 | + return; |
|
| 91 | 91 | }// end update_author |
| 92 | 92 | |
| 93 | 93 | |
@@ -118,32 +118,32 @@ discard block |
||
| 118 | 118 | } // end lesson |
| 119 | 119 | |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * user_save_quiz_answers_listener |
|
| 123 | - * |
|
| 124 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
| 125 | - * @since 1.7.3 |
|
| 126 | - * @return bool $saved; |
|
| 127 | - */ |
|
| 128 | - public function user_save_quiz_answers_listener(){ |
|
| 121 | + /** |
|
| 122 | + * user_save_quiz_answers_listener |
|
| 123 | + * |
|
| 124 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
| 125 | + * @since 1.7.3 |
|
| 126 | + * @return bool $saved; |
|
| 127 | + */ |
|
| 128 | + public function user_save_quiz_answers_listener(){ |
|
| 129 | 129 | |
| 130 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 131 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 133 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 134 | - return; |
|
| 135 | - } |
|
| 130 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 131 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 132 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 133 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 134 | + return; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - global $post; |
|
| 138 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 139 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 140 | - // call the save function |
|
| 141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 137 | + global $post; |
|
| 138 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 139 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 140 | + // call the save function |
|
| 141 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 142 | 142 | |
| 143 | - // remove the hook as it should only fire once per click |
|
| 144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 143 | + // remove the hook as it should only fire once per click |
|
| 144 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 145 | 145 | |
| 146 | - } // end user_save_quiz_answers_listener |
|
| 146 | + } // end user_save_quiz_answers_listener |
|
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * Save the user answers for the given lesson's quiz |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @access public |
| 155 | 155 | * |
| 156 | 156 | * @param array $quiz_answers |
| 157 | - * @param array $files from global $_FILES |
|
| 157 | + * @param array $files from global $_FILES |
|
| 158 | 158 | * @param int $lesson_id |
| 159 | 159 | * @param int $user_id |
| 160 | 160 | * |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
| 164 | 164 | |
| 165 | - if( ! ( $user_id > 0 ) ){ |
|
| 166 | - $user_id = get_current_user_id(); |
|
| 167 | - } |
|
| 165 | + if( ! ( $user_id > 0 ) ){ |
|
| 166 | + $user_id = get_current_user_id(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - // make sure the parameters are valid before continuing |
|
| 169 | + // make sure the parameters are valid before continuing |
|
| 170 | 170 | if( empty( $lesson_id ) || empty( $user_id ) |
| 171 | 171 | || 'lesson' != get_post_type( $lesson_id ) |
| 172 | 172 | ||!get_userdata( $user_id ) |
@@ -177,25 +177,25 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
| 180 | - // start the lesson before saving the data in case the user has not started the lesson |
|
| 181 | - $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 180 | + // start the lesson before saving the data in case the user has not started the lesson |
|
| 181 | + $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 182 | 182 | |
| 183 | 183 | //prepare the answers |
| 184 | 184 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
| 185 | 185 | |
| 186 | 186 | // save the user data |
| 187 | - $answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | + $answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 188 | 188 | |
| 189 | 189 | // were the answers saved correctly? |
| 190 | 190 | if( intval( $answers_saved ) > 0){ |
| 191 | 191 | |
| 192 | - // save transient to make retrieval faster |
|
| 193 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 192 | + // save transient to make retrieval faster |
|
| 193 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 194 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 195 | 195 | |
| 196 | - // update the message showed to user |
|
| 197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 198 | - } |
|
| 196 | + // update the message showed to user |
|
| 197 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | return $answers_saved; |
| 201 | 201 | |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Get the user answers for the given lesson's quiz. |
| 206 | - * |
|
| 207 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 208 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
| 206 | + * |
|
| 207 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 208 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
| 209 | 209 | * |
| 210 | 210 | * |
| 211 | 211 | * @since 1.7.4 |
@@ -225,27 +225,27 @@ discard block |
||
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - // save some time and get the transient cached data |
|
| 229 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 230 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 228 | + // save some time and get the transient cached data |
|
| 229 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 230 | + $transient_cached_answers = get_transient( $transient_key ); |
|
| 231 | 231 | |
| 232 | - // return the transient or get the values get the values from the comment meta |
|
| 233 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 232 | + // return the transient or get the values get the values from the comment meta |
|
| 233 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 234 | 234 | |
| 235 | - $encoded_user_answers = $transient_cached_answers; |
|
| 235 | + $encoded_user_answers = $transient_cached_answers; |
|
| 236 | 236 | |
| 237 | - }else{ |
|
| 237 | + }else{ |
|
| 238 | 238 | |
| 239 | - $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | + $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 240 | 240 | |
| 241 | - } // end if transient check |
|
| 241 | + } // end if transient check |
|
| 242 | 242 | |
| 243 | 243 | if( ! is_array( $encoded_user_answers ) ){ |
| 244 | 244 | return false; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - //set the transient with the new valid data for faster retrieval in future |
|
| 248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 247 | + //set the transient with the new valid data for faster retrieval in future |
|
| 248 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 249 | 249 | |
| 250 | 250 | // decode an unserialize all answers |
| 251 | 251 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | $current_quiz_id = $post->ID; |
| 280 | 280 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
| 281 | 281 | |
| 282 | - // reset all user data |
|
| 283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 282 | + // reset all user data |
|
| 283 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 284 | 284 | |
| 285 | 285 | //this function should only run once |
| 286 | 286 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * Complete/ submit quiz hooked function |
| 292 | 292 | * |
| 293 | 293 | * This function listens to the complete button submit action and processes the users submitted answers |
| 294 | - * not that this function submits the given users quiz answers for grading. |
|
| 294 | + * not that this function submits the given users quiz answers for grading. |
|
| 295 | 295 | * |
| 296 | 296 | * @since 1.7.4 |
| 297 | 297 | * @access public |
@@ -301,90 +301,90 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | public function user_quiz_submit_listener() { |
| 303 | 303 | |
| 304 | - // only respond to valid quiz completion submissions |
|
| 305 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 306 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 308 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 309 | - return; |
|
| 310 | - } |
|
| 304 | + // only respond to valid quiz completion submissions |
|
| 305 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 306 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 307 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 308 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 309 | + return; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - global $post, $current_user; |
|
| 313 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 314 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 312 | + global $post, $current_user; |
|
| 313 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 314 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 315 | 315 | |
| 316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 317 | 317 | |
| 318 | 318 | } // End sensei_complete_quiz() |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * This function set's up the data need for the quiz page |
|
| 322 | - * |
|
| 323 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 324 | - * current quiz. |
|
| 325 | - * |
|
| 326 | - * @since 1.7.4 |
|
| 327 | - * @access public |
|
| 328 | - * |
|
| 329 | - */ |
|
| 330 | - public function load_global_quiz_data(){ |
|
| 320 | + /** |
|
| 321 | + * This function set's up the data need for the quiz page |
|
| 322 | + * |
|
| 323 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 324 | + * current quiz. |
|
| 325 | + * |
|
| 326 | + * @since 1.7.4 |
|
| 327 | + * @access public |
|
| 328 | + * |
|
| 329 | + */ |
|
| 330 | + public function load_global_quiz_data(){ |
|
| 331 | 331 | |
| 332 | - global $post, $current_user; |
|
| 333 | - $this->data = new stdClass(); |
|
| 332 | + global $post, $current_user; |
|
| 333 | + $this->data = new stdClass(); |
|
| 334 | 334 | |
| 335 | - // Default grade |
|
| 336 | - $grade = 0; |
|
| 335 | + // Default grade |
|
| 336 | + $grade = 0; |
|
| 337 | 337 | |
| 338 | - // Get Quiz Questions |
|
| 339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 338 | + // Get Quiz Questions |
|
| 339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 340 | 340 | |
| 341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 342 | 342 | |
| 343 | - // Get quiz grade type |
|
| 344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 343 | + // Get quiz grade type |
|
| 344 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 345 | 345 | |
| 346 | - // Get quiz pass setting |
|
| 347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 346 | + // Get quiz pass setting |
|
| 347 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 348 | 348 | |
| 349 | - // Get quiz pass mark |
|
| 350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 349 | + // Get quiz pass mark |
|
| 350 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 351 | 351 | |
| 352 | - // Get latest quiz answers and grades |
|
| 353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 355 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 356 | - $user_quiz_grade = 0; |
|
| 357 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 359 | - } |
|
| 352 | + // Get latest quiz answers and grades |
|
| 353 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 354 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 355 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 356 | + $user_quiz_grade = 0; |
|
| 357 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 358 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 362 | 362 | |
| 363 | - // Check again that the lesson is complete |
|
| 364 | - $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 365 | - $user_lesson_complete = false; |
|
| 366 | - if ( $user_lesson_end ) { |
|
| 367 | - $user_lesson_complete = true; |
|
| 368 | - } // End If Statement |
|
| 363 | + // Check again that the lesson is complete |
|
| 364 | + $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 365 | + $user_lesson_complete = false; |
|
| 366 | + if ( $user_lesson_end ) { |
|
| 367 | + $user_lesson_complete = true; |
|
| 368 | + } // End If Statement |
|
| 369 | 369 | |
| 370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 371 | - //backwards compatibility |
|
| 372 | - if( 'on' == $reset_allowed ) { |
|
| 373 | - $reset_allowed = 1; |
|
| 374 | - } |
|
| 370 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 371 | + //backwards compatibility |
|
| 372 | + if( 'on' == $reset_allowed ) { |
|
| 373 | + $reset_allowed = 1; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - // Build frontend data object for backwards compatibility |
|
| 377 | - // using this is no longer recommended |
|
| 378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 379 | - $this->data->quiz_passmark = $quiz_passmark; |
|
| 380 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 381 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 382 | - $this->data->user_lesson_end = $user_lesson_end; |
|
| 383 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 384 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 385 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 376 | + // Build frontend data object for backwards compatibility |
|
| 377 | + // using this is no longer recommended |
|
| 378 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 379 | + $this->data->quiz_passmark = $quiz_passmark; |
|
| 380 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 381 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 382 | + $this->data->user_lesson_end = $user_lesson_end; |
|
| 383 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 384 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 385 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 386 | 386 | |
| 387 | - } // end load_global_quiz_data |
|
| 387 | + } // end load_global_quiz_data |
|
| 388 | 388 | |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -414,25 +414,25 @@ discard block |
||
| 414 | 414 | foreach( $unprepared_answers as $question_id => $answer ) { |
| 415 | 415 | |
| 416 | 416 | //get the current questions question type |
| 417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 418 | 418 | |
| 419 | 419 | // Sanitise answer |
| 420 | 420 | if( 0 == get_magic_quotes_gpc() ) { |
| 421 | 421 | $answer = wp_unslash( $answer ); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - // compress the answer for saving |
|
| 424 | + // compress the answer for saving |
|
| 425 | 425 | if( 'multi-line' == $question_type ) { |
| 426 | - $answer = esc_html( $answer ); |
|
| 427 | - }elseif( 'file-upload' == $question_type ){ |
|
| 428 | - $file_key = 'file_upload_' . $question_id; |
|
| 429 | - if( isset( $files[ $file_key ] ) ) { |
|
| 430 | - $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 431 | - if( $attachment_id ) { |
|
| 432 | - $answer = $attachment_id; |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - } // end if |
|
| 426 | + $answer = esc_html( $answer ); |
|
| 427 | + }elseif( 'file-upload' == $question_type ){ |
|
| 428 | + $file_key = 'file_upload_' . $question_id; |
|
| 429 | + if( isset( $files[ $file_key ] ) ) { |
|
| 430 | + $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 431 | + if( $attachment_id ) { |
|
| 432 | + $answer = $attachment_id; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + } // end if |
|
| 436 | 436 | |
| 437 | 437 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
| 438 | 438 | |
@@ -441,814 +441,814 @@ discard block |
||
| 441 | 441 | return $prepared_answers; |
| 442 | 442 | } // prepare_form_submitted_answers |
| 443 | 443 | |
| 444 | - /** |
|
| 445 | - * Reset user submitted questions |
|
| 446 | - * |
|
| 447 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 448 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 449 | - * |
|
| 450 | - * @since 1.7.4 |
|
| 451 | - * @access public |
|
| 452 | - * |
|
| 453 | - * @return bool $reset_success |
|
| 454 | - * @param int $user_id |
|
| 455 | - * @param int $lesson_id |
|
| 456 | - */ |
|
| 457 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 444 | + /** |
|
| 445 | + * Reset user submitted questions |
|
| 446 | + * |
|
| 447 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 448 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 449 | + * |
|
| 450 | + * @since 1.7.4 |
|
| 451 | + * @access public |
|
| 452 | + * |
|
| 453 | + * @return bool $reset_success |
|
| 454 | + * @param int $user_id |
|
| 455 | + * @param int $lesson_id |
|
| 456 | + */ |
|
| 457 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 458 | + |
|
| 459 | + //make sure the parameters are valid |
|
| 460 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 461 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 462 | + || ! get_userdata( $user_id ) ){ |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + //get the users lesson status to make |
|
| 469 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 470 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 471 | + // this user is not taking this lesson so this process is not needed |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + //get the lesson quiz and course |
|
| 476 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 477 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 478 | + |
|
| 479 | + // reset the transients |
|
| 480 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 481 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 482 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 483 | + delete_transient( $answers_transient_key ); |
|
| 484 | + delete_transient( $grades_transient_key ); |
|
| 485 | + delete_transient( $answers_feedback_transient_key ); |
|
| 486 | + |
|
| 487 | + // reset the quiz answers and feedback notes |
|
| 488 | + $deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 489 | + $deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 490 | + $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 491 | + |
|
| 492 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 493 | + WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 494 | + |
|
| 495 | + WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 496 | + |
|
| 497 | + // Update course completion |
|
| 498 | + WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 458 | 499 | |
| 459 | - //make sure the parameters are valid |
|
| 460 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 461 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 462 | - || ! get_userdata( $user_id ) ){ |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - //get the users lesson status to make |
|
| 469 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 470 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 471 | - // this user is not taking this lesson so this process is not needed |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 500 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 501 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 502 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 474 | 503 | |
| 475 | - //get the lesson quiz and course |
|
| 476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 504 | + return ( $deleted_answers && $deleted_grades ) ; |
|
| 478 | 505 | |
| 479 | - // reset the transients |
|
| 480 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 481 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 482 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 483 | - delete_transient( $answers_transient_key ); |
|
| 484 | - delete_transient( $grades_transient_key ); |
|
| 485 | - delete_transient( $answers_feedback_transient_key ); |
|
| 506 | + } // end reset_user_lesson_data |
|
| 486 | 507 | |
| 487 | - // reset the quiz answers and feedback notes |
|
| 488 | - $deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 489 | - $deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 490 | - $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 508 | + /** |
|
| 509 | + * Submit the users quiz answers for grading |
|
| 510 | + * |
|
| 511 | + * This function accepts users answers and stores it but also initiates the grading |
|
| 512 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 513 | + * |
|
| 514 | + * @since 1.7.4 |
|
| 515 | + * @access public |
|
| 516 | + * |
|
| 517 | + * @param array $quiz_answers |
|
| 518 | + * @param array $files from $_FILES |
|
| 519 | + * @param int $user_id |
|
| 520 | + * @param int $lesson_id |
|
| 521 | + * |
|
| 522 | + * @return bool $answers_submitted |
|
| 523 | + */ |
|
| 524 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 491 | 525 | |
| 492 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 493 | - WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 526 | + $answers_submitted = false; |
|
| 494 | 527 | |
| 495 | - WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 528 | + // get the user_id if none was passed in use the current logged in user |
|
| 529 | + if( ! intval( $user_id ) > 0 ) { |
|
| 530 | + $user_id = get_current_user_id(); |
|
| 531 | + } |
|
| 496 | 532 | |
| 497 | - // Update course completion |
|
| 498 | - WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 533 | + // make sure the parameters are valid before continuing |
|
| 534 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 535 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 536 | + ||!get_userdata( $user_id ) |
|
| 537 | + || !is_array( $quiz_answers ) ){ |
|
| 499 | 538 | |
| 500 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 539 | + return false; |
|
| 503 | 540 | |
| 504 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 541 | + } |
|
| 505 | 542 | |
| 506 | - } // end reset_user_lesson_data |
|
| 543 | + // Default grade |
|
| 544 | + $grade = 0; |
|
| 507 | 545 | |
| 508 | - /** |
|
| 509 | - * Submit the users quiz answers for grading |
|
| 510 | - * |
|
| 511 | - * This function accepts users answers and stores it but also initiates the grading |
|
| 512 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 513 | - * |
|
| 514 | - * @since 1.7.4 |
|
| 515 | - * @access public |
|
| 516 | - * |
|
| 517 | - * @param array $quiz_answers |
|
| 518 | - * @param array $files from $_FILES |
|
| 519 | - * @param int $user_id |
|
| 520 | - * @param int $lesson_id |
|
| 521 | - * |
|
| 522 | - * @return bool $answers_submitted |
|
| 523 | - */ |
|
| 524 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 546 | + // Get Quiz ID |
|
| 547 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 525 | 548 | |
| 526 | - $answers_submitted = false; |
|
| 549 | + // Get quiz grade type |
|
| 550 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 527 | 551 | |
| 528 | - // get the user_id if none was passed in use the current logged in user |
|
| 529 | - if( ! intval( $user_id ) > 0 ) { |
|
| 530 | - $user_id = get_current_user_id(); |
|
| 531 | - } |
|
| 552 | + // Get quiz pass setting |
|
| 553 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 532 | 554 | |
| 533 | - // make sure the parameters are valid before continuing |
|
| 534 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 535 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 536 | - ||!get_userdata( $user_id ) |
|
| 537 | - || !is_array( $quiz_answers ) ){ |
|
| 555 | + // Get the minimum percentage need to pass this quiz |
|
| 556 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 538 | 557 | |
| 539 | - return false; |
|
| 558 | + // Handle Quiz Questions asked |
|
| 559 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 560 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 561 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 562 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 563 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 564 | + if( empty( $questions_asked ) ){ |
|
| 540 | 565 | |
| 541 | - } |
|
| 566 | + $questions_asked = array_keys( $quiz_answers ); |
|
| 567 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
| 542 | 568 | |
| 543 | - // Default grade |
|
| 544 | - $grade = 0; |
|
| 569 | + // Save questions that were asked in this quiz |
|
| 570 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 545 | 571 | |
| 546 | - // Get Quiz ID |
|
| 547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 572 | + } |
|
| 548 | 573 | |
| 549 | - // Get quiz grade type |
|
| 550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 574 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 575 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 551 | 576 | |
| 552 | - // Get quiz pass setting |
|
| 553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 577 | + // Grade quiz |
|
| 578 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 554 | 579 | |
| 555 | - // Get the minimum percentage need to pass this quiz |
|
| 556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 580 | + // Get Lesson Grading Setting |
|
| 581 | + $lesson_metadata = array(); |
|
| 582 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 557 | 583 | |
| 558 | - // Handle Quiz Questions asked |
|
| 559 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 560 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 561 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 562 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 564 | - if( empty( $questions_asked ) ){ |
|
| 584 | + // At this point the answers have been submitted |
|
| 585 | + $answers_submitted = true; |
|
| 565 | 586 | |
| 566 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 567 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 568 | - |
|
| 569 | - // Save questions that were asked in this quiz |
|
| 570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 587 | + // if this condition is false the quiz should manually be graded by admin |
|
| 588 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 571 | 589 | |
| 572 | - } |
|
| 590 | + // Quiz has been automatically Graded |
|
| 591 | + if ( 'on' == $pass_required ) { |
|
| 573 | 592 | |
| 574 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 593 | + // Student has reached the pass mark and lesson is complete |
|
| 594 | + if ( $quiz_pass_percentage <= $grade ) { |
|
| 576 | 595 | |
| 577 | - // Grade quiz |
|
| 578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 596 | + $lesson_status = 'passed'; |
|
| 579 | 597 | |
| 580 | - // Get Lesson Grading Setting |
|
| 581 | - $lesson_metadata = array(); |
|
| 582 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 598 | + } else { |
|
| 583 | 599 | |
| 584 | - // At this point the answers have been submitted |
|
| 585 | - $answers_submitted = true; |
|
| 600 | + $lesson_status = 'failed'; |
|
| 586 | 601 | |
| 587 | - // if this condition is false the quiz should manually be graded by admin |
|
| 588 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 602 | + } // End If Statement |
|
| 589 | 603 | |
| 590 | - // Quiz has been automatically Graded |
|
| 591 | - if ( 'on' == $pass_required ) { |
|
| 604 | + } else { |
|
| 592 | 605 | |
| 593 | - // Student has reached the pass mark and lesson is complete |
|
| 594 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 606 | + // Student only has to partake the quiz |
|
| 607 | + $lesson_status = 'graded'; |
|
| 608 | + |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 612 | + |
|
| 613 | + } // end if ! is_wp_error( $grade ... |
|
| 614 | + |
|
| 615 | + WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 595 | 616 | |
| 596 | - $lesson_status = 'passed'; |
|
| 617 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 597 | 618 | |
| 598 | - } else { |
|
| 619 | + /** |
|
| 620 | + * Lesson end action hook |
|
| 621 | + * |
|
| 622 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 623 | + * |
|
| 624 | + * @param int $user_id |
|
| 625 | + * @param int $lesson_id |
|
| 626 | + */ |
|
| 627 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 599 | 628 | |
| 600 | - $lesson_status = 'failed'; |
|
| 629 | + } |
|
| 601 | 630 | |
| 602 | - } // End If Statement |
|
| 631 | + /** |
|
| 632 | + * User quiz has been submitted |
|
| 633 | + * |
|
| 634 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 635 | + * results. |
|
| 636 | + * |
|
| 637 | + * @param int $user_id |
|
| 638 | + * @param int $quiz_id |
|
| 639 | + * @param string $grade |
|
| 640 | + * @param string $quiz_pass_percentage |
|
| 641 | + * @param string $quiz_grade_type |
|
| 642 | + */ |
|
| 643 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 603 | 644 | |
| 604 | - } else { |
|
| 645 | + return $answers_submitted; |
|
| 605 | 646 | |
| 606 | - // Student only has to partake the quiz |
|
| 607 | - $lesson_status = 'graded'; |
|
| 608 | - |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 612 | - |
|
| 613 | - } // end if ! is_wp_error( $grade ... |
|
| 614 | - |
|
| 615 | - WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 647 | + }// end submit_answers_for_grading |
|
| 616 | 648 | |
| 617 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 649 | + /** |
|
| 650 | + * Get the user question answer |
|
| 651 | + * |
|
| 652 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 653 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 654 | + * |
|
| 655 | + * @since 1.7.4 |
|
| 656 | + * |
|
| 657 | + * @param int $lesson_id |
|
| 658 | + * @param int $question_id |
|
| 659 | + * @param int $user_id ( optional ) |
|
| 660 | + * |
|
| 661 | + * @return bool $answers_submitted |
|
| 662 | + */ |
|
| 663 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 618 | 664 | |
| 619 | - /** |
|
| 620 | - * Lesson end action hook |
|
| 621 | - * |
|
| 622 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 623 | - * |
|
| 624 | - * @param int $user_id |
|
| 625 | - * @param int $lesson_id |
|
| 626 | - */ |
|
| 627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 665 | + // parameter validation |
|
| 666 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 667 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 668 | + || ! ( intval( $question_id ) > 0 ) |
|
| 669 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 670 | + || 'question' != get_post_type( $question_id )) { |
|
| 628 | 671 | |
| 629 | - } |
|
| 672 | + return false; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 676 | + $user_id = get_current_user_id(); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 680 | + |
|
| 681 | + if( !$users_answers || empty( $users_answers ) |
|
| 682 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 683 | + |
|
| 684 | + //Fallback for pre 1.7.4 data |
|
| 685 | + $comment = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 686 | + |
|
| 687 | + if( ! isset( $comment->comment_content ) ){ |
|
| 688 | + return false; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return $users_answers[ $question_id ]; |
|
| 695 | + |
|
| 696 | + }// end get_user_question_answer |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Saving the users quiz question grades |
|
| 700 | + * |
|
| 701 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
| 702 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 703 | + * |
|
| 704 | + * @since 1.7.4 |
|
| 705 | + * |
|
| 706 | + * @param array $quiz_grades{ |
|
| 707 | + * @type int $question_id |
|
| 708 | + * @type int $question_grade |
|
| 709 | + * } |
|
| 710 | + * @param $lesson_id |
|
| 711 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 712 | + * |
|
| 713 | + * @return bool |
|
| 714 | + */ |
|
| 715 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 716 | + |
|
| 717 | + // get the user_id if none was passed in use the current logged in user |
|
| 718 | + if( ! intval( $user_id ) > 0 ) { |
|
| 719 | + $user_id = get_current_user_id(); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + // make sure the parameters are valid before continuing |
|
| 723 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 724 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 725 | + ||!get_userdata( $user_id ) |
|
| 726 | + || !is_array( $quiz_grades ) ){ |
|
| 727 | + |
|
| 728 | + return false; |
|
| 729 | + |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + $success = false; |
|
| 733 | + |
|
| 734 | + // save that data for the user on the lesson comment meta |
|
| 735 | + $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 736 | + |
|
| 737 | + // were the grades save successfully ? |
|
| 738 | + if( intval( $comment_meta_id ) > 0 ) { |
|
| 739 | + |
|
| 740 | + $success = true; |
|
| 741 | + // save transient |
|
| 742 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 743 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + return $success; |
|
| 747 | + |
|
| 748 | + }// end set_user_grades |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Retrieve the users quiz question grades |
|
| 752 | + * |
|
| 753 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 754 | + * |
|
| 755 | + * @since 1.7.4 |
|
| 756 | + * |
|
| 757 | + * @param $lesson_id |
|
| 758 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 759 | + * |
|
| 760 | + * @return array $user_quiz_grades or false if none exists for this users |
|
| 761 | + */ |
|
| 762 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 763 | + |
|
| 764 | + $user_grades = array(); |
|
| 765 | + |
|
| 766 | + // get the user_id if none was passed in use the current logged in user |
|
| 767 | + if( ! intval( $user_id ) > 0 ) { |
|
| 768 | + $user_id = get_current_user_id(); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 772 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 773 | + return false; |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + // save some time and get the transient cached data |
|
| 777 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 778 | + $user_grades = get_transient( $transient_key ); |
|
| 779 | + |
|
| 780 | + // get the data if nothing was stored in the transient |
|
| 781 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
| 782 | + |
|
| 783 | + $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 784 | + |
|
| 785 | + //set the transient with the new valid data for faster retrieval in future |
|
| 786 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 787 | + |
|
| 788 | + } // end if transient check |
|
| 789 | + |
|
| 790 | + // if there is no data for this user |
|
| 791 | + if( ! is_array( $user_grades ) ){ |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + return $user_grades; |
|
| 796 | + |
|
| 797 | + }// end get_user_grades |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Get the user question grade |
|
| 801 | + * |
|
| 802 | + * This function gets the grade on a quiz for the given question parameter |
|
| 803 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 804 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 805 | + * |
|
| 806 | + * @since 1.7.4 |
|
| 807 | + * |
|
| 808 | + * @param int $lesson_id |
|
| 809 | + * @param int $question_id |
|
| 810 | + * @param int $user_id ( optional ) |
|
| 811 | + * |
|
| 812 | + * @return bool $question_grade |
|
| 813 | + */ |
|
| 814 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 815 | + |
|
| 816 | + // parameter validation |
|
| 817 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 818 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 819 | + || ! ( intval( $question_id ) > 0 ) |
|
| 820 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 821 | + || 'question' != get_post_type( $question_id )) { |
|
| 822 | + |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 827 | + |
|
| 828 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 829 | + |
|
| 830 | + //fallback to data pre 1.7.4 |
|
| 831 | + $args = array( |
|
| 832 | + 'post_id' => $question_id, |
|
| 833 | + 'user_id' => $user_id, |
|
| 834 | + 'type' => 'sensei_user_answer' |
|
| 835 | + ); |
|
| 836 | + |
|
| 837 | + $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 838 | + $fall_back_grade = false; |
|
| 839 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 840 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + return $fall_back_grade; |
|
| 844 | + |
|
| 845 | + } // end if $all_user_grades... |
|
| 846 | + |
|
| 847 | + return $all_user_grades[ $question_id ]; |
|
| 848 | + |
|
| 849 | + }// end get_user_question_grade |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Save the user's answers feedback |
|
| 853 | + * |
|
| 854 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
| 855 | + * The data will be saved on the lesson ID supplied. |
|
| 856 | + * |
|
| 857 | + * @since 1.7.5 |
|
| 858 | + * @access public |
|
| 859 | + * |
|
| 860 | + * @param array $answers_feedback{ |
|
| 861 | + * $type int $question_id |
|
| 862 | + * $type string $question_feedback |
|
| 863 | + * } |
|
| 864 | + * @param int $lesson_id |
|
| 865 | + * @param int $user_id |
|
| 866 | + * |
|
| 867 | + * @return false or int $feedback_saved |
|
| 868 | + */ |
|
| 869 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 870 | + |
|
| 871 | + // make sure the parameters are valid before continuing |
|
| 872 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 873 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 874 | + ||!get_userdata( $user_id ) |
|
| 875 | + || !is_array( $answers_feedback ) ){ |
|
| 876 | + |
|
| 877 | + return false; |
|
| 878 | + |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
| 883 | + if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 884 | + WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 885 | + } |
|
| 630 | 886 | |
| 631 | - /** |
|
| 632 | - * User quiz has been submitted |
|
| 633 | - * |
|
| 634 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 635 | - * results. |
|
| 636 | - * |
|
| 637 | - * @param int $user_id |
|
| 638 | - * @param int $quiz_id |
|
| 639 | - * @param string $grade |
|
| 640 | - * @param string $quiz_pass_percentage |
|
| 641 | - * @param string $quiz_grade_type |
|
| 642 | - */ |
|
| 643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 887 | + // encode the feedback |
|
| 888 | + $encoded_answers_feedback = array(); |
|
| 889 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 890 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + // save the user data |
|
| 894 | + $feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 895 | + |
|
| 896 | + //Were the the question feedback save correctly? |
|
| 897 | + if( intval( $feedback_saved ) > 0){ |
|
| 898 | + |
|
| 899 | + // save transient to make retrieval faster in future |
|
| 900 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 901 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 644 | 902 | |
| 645 | - return $answers_submitted; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + return $feedback_saved; |
|
| 906 | + |
|
| 907 | + } // end save_user_answers_feedback |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Get the user's answers feedback. |
|
| 911 | + * |
|
| 912 | + * This function returns the feedback submitted by the teacher/admin |
|
| 913 | + * during grading. Grading occurs manually or automatically. |
|
| 914 | + * |
|
| 915 | + * @since 1.7.5 |
|
| 916 | + * @access public |
|
| 917 | + * |
|
| 918 | + * @param int $lesson_id |
|
| 919 | + * @param int $user_id |
|
| 920 | + * |
|
| 921 | + * @return false | array $answers_feedback{ |
|
| 922 | + * $type int $question_id |
|
| 923 | + * $type string $question_feedback |
|
| 924 | + * } |
|
| 925 | + */ |
|
| 926 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 927 | + |
|
| 928 | + $answers_feedback = array(); |
|
| 646 | 929 | |
| 647 | - }// end submit_answers_for_grading |
|
| 930 | + // get the user_id if none was passed in use the current logged in user |
|
| 931 | + if( ! intval( $user_id ) > 0 ) { |
|
| 932 | + $user_id = get_current_user_id(); |
|
| 933 | + } |
|
| 648 | 934 | |
| 649 | - /** |
|
| 650 | - * Get the user question answer |
|
| 651 | - * |
|
| 652 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 653 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 654 | - * |
|
| 655 | - * @since 1.7.4 |
|
| 656 | - * |
|
| 657 | - * @param int $lesson_id |
|
| 658 | - * @param int $question_id |
|
| 659 | - * @param int $user_id ( optional ) |
|
| 660 | - * |
|
| 661 | - * @return bool $answers_submitted |
|
| 662 | - */ |
|
| 663 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 935 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 936 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 937 | + return false; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + // first check the transient to save a few split seconds |
|
| 941 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 942 | + $encoded_feedback = get_transient( $transient_key ); |
|
| 943 | + |
|
| 944 | + // get the data if nothing was stored in the transient |
|
| 945 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 664 | 946 | |
| 665 | - // parameter validation |
|
| 666 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 667 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 668 | - || ! ( intval( $question_id ) > 0 ) |
|
| 669 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 670 | - || 'question' != get_post_type( $question_id )) { |
|
| 947 | + $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 948 | + |
|
| 949 | + //set the transient with the new valid data for faster retrieval in future |
|
| 950 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 951 | + |
|
| 952 | + } // end if transient check |
|
| 671 | 953 | |
| 672 | - return false; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 676 | - $user_id = get_current_user_id(); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 680 | - |
|
| 681 | - if( !$users_answers || empty( $users_answers ) |
|
| 682 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 683 | - |
|
| 684 | - //Fallback for pre 1.7.4 data |
|
| 685 | - $comment = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 686 | - |
|
| 687 | - if( ! isset( $comment->comment_content ) ){ |
|
| 688 | - return false; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return $users_answers[ $question_id ]; |
|
| 695 | - |
|
| 696 | - }// end get_user_question_answer |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Saving the users quiz question grades |
|
| 700 | - * |
|
| 701 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
| 702 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 703 | - * |
|
| 704 | - * @since 1.7.4 |
|
| 705 | - * |
|
| 706 | - * @param array $quiz_grades{ |
|
| 707 | - * @type int $question_id |
|
| 708 | - * @type int $question_grade |
|
| 709 | - * } |
|
| 710 | - * @param $lesson_id |
|
| 711 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 712 | - * |
|
| 713 | - * @return bool |
|
| 714 | - */ |
|
| 715 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 716 | - |
|
| 717 | - // get the user_id if none was passed in use the current logged in user |
|
| 718 | - if( ! intval( $user_id ) > 0 ) { |
|
| 719 | - $user_id = get_current_user_id(); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - // make sure the parameters are valid before continuing |
|
| 723 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 724 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 725 | - ||!get_userdata( $user_id ) |
|
| 726 | - || !is_array( $quiz_grades ) ){ |
|
| 727 | - |
|
| 728 | - return false; |
|
| 729 | - |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - $success = false; |
|
| 733 | - |
|
| 734 | - // save that data for the user on the lesson comment meta |
|
| 735 | - $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 736 | - |
|
| 737 | - // were the grades save successfully ? |
|
| 738 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 739 | - |
|
| 740 | - $success = true; |
|
| 741 | - // save transient |
|
| 742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - return $success; |
|
| 747 | - |
|
| 748 | - }// end set_user_grades |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Retrieve the users quiz question grades |
|
| 752 | - * |
|
| 753 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 754 | - * |
|
| 755 | - * @since 1.7.4 |
|
| 756 | - * |
|
| 757 | - * @param $lesson_id |
|
| 758 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 759 | - * |
|
| 760 | - * @return array $user_quiz_grades or false if none exists for this users |
|
| 761 | - */ |
|
| 762 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 763 | - |
|
| 764 | - $user_grades = array(); |
|
| 765 | - |
|
| 766 | - // get the user_id if none was passed in use the current logged in user |
|
| 767 | - if( ! intval( $user_id ) > 0 ) { |
|
| 768 | - $user_id = get_current_user_id(); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 772 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 773 | - return false; |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - // save some time and get the transient cached data |
|
| 777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 778 | - $user_grades = get_transient( $transient_key ); |
|
| 779 | - |
|
| 780 | - // get the data if nothing was stored in the transient |
|
| 781 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 782 | - |
|
| 783 | - $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 784 | - |
|
| 785 | - //set the transient with the new valid data for faster retrieval in future |
|
| 786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 787 | - |
|
| 788 | - } // end if transient check |
|
| 789 | - |
|
| 790 | - // if there is no data for this user |
|
| 791 | - if( ! is_array( $user_grades ) ){ |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - return $user_grades; |
|
| 796 | - |
|
| 797 | - }// end get_user_grades |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Get the user question grade |
|
| 801 | - * |
|
| 802 | - * This function gets the grade on a quiz for the given question parameter |
|
| 803 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 804 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 805 | - * |
|
| 806 | - * @since 1.7.4 |
|
| 807 | - * |
|
| 808 | - * @param int $lesson_id |
|
| 809 | - * @param int $question_id |
|
| 810 | - * @param int $user_id ( optional ) |
|
| 811 | - * |
|
| 812 | - * @return bool $question_grade |
|
| 813 | - */ |
|
| 814 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 815 | - |
|
| 816 | - // parameter validation |
|
| 817 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 818 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 819 | - || ! ( intval( $question_id ) > 0 ) |
|
| 820 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 821 | - || 'question' != get_post_type( $question_id )) { |
|
| 822 | - |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 827 | - |
|
| 828 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 829 | - |
|
| 830 | - //fallback to data pre 1.7.4 |
|
| 831 | - $args = array( |
|
| 832 | - 'post_id' => $question_id, |
|
| 833 | - 'user_id' => $user_id, |
|
| 834 | - 'type' => 'sensei_user_answer' |
|
| 835 | - ); |
|
| 836 | - |
|
| 837 | - $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 838 | - $fall_back_grade = false; |
|
| 839 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - return $fall_back_grade; |
|
| 844 | - |
|
| 845 | - } // end if $all_user_grades... |
|
| 846 | - |
|
| 847 | - return $all_user_grades[ $question_id ]; |
|
| 848 | - |
|
| 849 | - }// end get_user_question_grade |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Save the user's answers feedback |
|
| 853 | - * |
|
| 854 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
| 855 | - * The data will be saved on the lesson ID supplied. |
|
| 856 | - * |
|
| 857 | - * @since 1.7.5 |
|
| 858 | - * @access public |
|
| 859 | - * |
|
| 860 | - * @param array $answers_feedback{ |
|
| 861 | - * $type int $question_id |
|
| 862 | - * $type string $question_feedback |
|
| 863 | - * } |
|
| 864 | - * @param int $lesson_id |
|
| 865 | - * @param int $user_id |
|
| 866 | - * |
|
| 867 | - * @return false or int $feedback_saved |
|
| 868 | - */ |
|
| 869 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 870 | - |
|
| 871 | - // make sure the parameters are valid before continuing |
|
| 872 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 873 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 874 | - ||!get_userdata( $user_id ) |
|
| 875 | - || !is_array( $answers_feedback ) ){ |
|
| 876 | - |
|
| 877 | - return false; |
|
| 878 | - |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
| 883 | - if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 884 | - WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - // encode the feedback |
|
| 888 | - $encoded_answers_feedback = array(); |
|
| 889 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - // save the user data |
|
| 894 | - $feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 895 | - |
|
| 896 | - //Were the the question feedback save correctly? |
|
| 897 | - if( intval( $feedback_saved ) > 0){ |
|
| 898 | - |
|
| 899 | - // save transient to make retrieval faster in future |
|
| 900 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 902 | - |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - return $feedback_saved; |
|
| 906 | - |
|
| 907 | - } // end save_user_answers_feedback |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Get the user's answers feedback. |
|
| 911 | - * |
|
| 912 | - * This function returns the feedback submitted by the teacher/admin |
|
| 913 | - * during grading. Grading occurs manually or automatically. |
|
| 914 | - * |
|
| 915 | - * @since 1.7.5 |
|
| 916 | - * @access public |
|
| 917 | - * |
|
| 918 | - * @param int $lesson_id |
|
| 919 | - * @param int $user_id |
|
| 920 | - * |
|
| 921 | - * @return false | array $answers_feedback{ |
|
| 922 | - * $type int $question_id |
|
| 923 | - * $type string $question_feedback |
|
| 924 | - * } |
|
| 925 | - */ |
|
| 926 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 927 | - |
|
| 928 | - $answers_feedback = array(); |
|
| 929 | - |
|
| 930 | - // get the user_id if none was passed in use the current logged in user |
|
| 931 | - if( ! intval( $user_id ) > 0 ) { |
|
| 932 | - $user_id = get_current_user_id(); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 936 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 937 | - return false; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - // first check the transient to save a few split seconds |
|
| 941 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 942 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 943 | - |
|
| 944 | - // get the data if nothing was stored in the transient |
|
| 945 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 946 | - |
|
| 947 | - $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 948 | - |
|
| 949 | - //set the transient with the new valid data for faster retrieval in future |
|
| 950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 951 | - |
|
| 952 | - } // end if transient check |
|
| 953 | - |
|
| 954 | - // if there is no data for this user |
|
| 955 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 956 | - return false; |
|
| 957 | - } |
|
| 954 | + // if there is no data for this user |
|
| 955 | + if( ! is_array( $encoded_feedback ) ){ |
|
| 956 | + return false; |
|
| 957 | + } |
|
| 958 | 958 | |
| 959 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 960 | 960 | |
| 961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 962 | 962 | |
| 963 | - } |
|
| 963 | + } |
|
| 964 | 964 | |
| 965 | - return $answers_feedback; |
|
| 965 | + return $answers_feedback; |
|
| 966 | 966 | |
| 967 | - } // end get_user_answers_feedback |
|
| 967 | + } // end get_user_answers_feedback |
|
| 968 | 968 | |
| 969 | - /** |
|
| 970 | - * Get the user's answer feedback for a specific question. |
|
| 971 | - * |
|
| 972 | - * This function gives you a single answer note/feedback string |
|
| 973 | - * for the user on the given question. |
|
| 974 | - * |
|
| 975 | - * @since 1.7.5 |
|
| 976 | - * @access public |
|
| 977 | - * |
|
| 978 | - * @param int $lesson_id |
|
| 979 | - * @param int $question_id |
|
| 980 | - * @param int $user_id |
|
| 981 | - * |
|
| 982 | - * @return string $feedback or bool if false |
|
| 983 | - */ |
|
| 984 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 969 | + /** |
|
| 970 | + * Get the user's answer feedback for a specific question. |
|
| 971 | + * |
|
| 972 | + * This function gives you a single answer note/feedback string |
|
| 973 | + * for the user on the given question. |
|
| 974 | + * |
|
| 975 | + * @since 1.7.5 |
|
| 976 | + * @access public |
|
| 977 | + * |
|
| 978 | + * @param int $lesson_id |
|
| 979 | + * @param int $question_id |
|
| 980 | + * @param int $user_id |
|
| 981 | + * |
|
| 982 | + * @return string $feedback or bool if false |
|
| 983 | + */ |
|
| 984 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 985 | 985 | |
| 986 | - $feedback = false; |
|
| 986 | + $feedback = false; |
|
| 987 | 987 | |
| 988 | - // parameter validation |
|
| 989 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 990 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 991 | - || ! ( intval( $question_id ) > 0 ) |
|
| 992 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 993 | - || 'question' != get_post_type( $question_id )) { |
|
| 988 | + // parameter validation |
|
| 989 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 990 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 991 | + || ! ( intval( $question_id ) > 0 ) |
|
| 992 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 993 | + || 'question' != get_post_type( $question_id )) { |
|
| 994 | 994 | |
| 995 | - return false; |
|
| 996 | - } |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | 997 | |
| 998 | - // get all the feedback for the user on the given lesson |
|
| 999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 998 | + // get all the feedback for the user on the given lesson |
|
| 999 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 1000 | 1000 | |
| 1001 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1002 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1001 | + if( !$all_feedback || empty( $all_feedback ) |
|
| 1002 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1003 | 1003 | |
| 1004 | - //fallback to data pre 1.7.4 |
|
| 1004 | + //fallback to data pre 1.7.4 |
|
| 1005 | 1005 | |
| 1006 | - // setup the sensei data query |
|
| 1007 | - $args = array( |
|
| 1008 | - 'post_id' => $question_id, |
|
| 1009 | - 'user_id' => $user_id, |
|
| 1010 | - 'type' => 'sensei_user_answer' |
|
| 1011 | - ); |
|
| 1012 | - $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1006 | + // setup the sensei data query |
|
| 1007 | + $args = array( |
|
| 1008 | + 'post_id' => $question_id, |
|
| 1009 | + 'user_id' => $user_id, |
|
| 1010 | + 'type' => 'sensei_user_answer' |
|
| 1011 | + ); |
|
| 1012 | + $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1013 | 1013 | |
| 1014 | - // set the default to false and return that if no old data is available. |
|
| 1015 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1017 | - } |
|
| 1014 | + // set the default to false and return that if no old data is available. |
|
| 1015 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 1016 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | - // finally use the default question feedback |
|
| 1020 | - if( empty( $feedback ) ){ |
|
| 1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1022 | - } |
|
| 1019 | + // finally use the default question feedback |
|
| 1020 | + if( empty( $feedback ) ){ |
|
| 1021 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - return $feedback; |
|
| 1024 | + return $feedback; |
|
| 1025 | 1025 | |
| 1026 | - } |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | - return $all_feedback[ $question_id ]; |
|
| 1028 | + return $all_feedback[ $question_id ]; |
|
| 1029 | 1029 | |
| 1030 | - } // end get_user_question_feedback |
|
| 1030 | + } // end get_user_question_feedback |
|
| 1031 | 1031 | |
| 1032 | - /** |
|
| 1033 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1034 | - * |
|
| 1035 | - * Though a quiz is created for each lesson, it should not be visible |
|
| 1036 | - * unless it has questions. |
|
| 1037 | - * |
|
| 1038 | - * @since 1.9.0 |
|
| 1039 | - * @access public |
|
| 1040 | - * @param none |
|
| 1041 | - * @return void |
|
| 1042 | - */ |
|
| 1032 | + /** |
|
| 1033 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1034 | + * |
|
| 1035 | + * Though a quiz is created for each lesson, it should not be visible |
|
| 1036 | + * unless it has questions. |
|
| 1037 | + * |
|
| 1038 | + * @since 1.9.0 |
|
| 1039 | + * @access public |
|
| 1040 | + * @param none |
|
| 1041 | + * @return void |
|
| 1042 | + */ |
|
| 1043 | 1043 | |
| 1044 | - public function quiz_has_no_questions() { |
|
| 1044 | + public function quiz_has_no_questions() { |
|
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1048 | - return; |
|
| 1049 | - } |
|
| 1047 | + if( ! is_singular( 'quiz' ) ) { |
|
| 1048 | + return; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - global $post; |
|
| 1051 | + global $post; |
|
| 1052 | 1052 | |
| 1053 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1053 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1054 | 1054 | |
| 1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1055 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1056 | 1056 | |
| 1057 | - $lesson = get_post($lesson_id); |
|
| 1057 | + $lesson = get_post($lesson_id); |
|
| 1058 | 1058 | |
| 1059 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1059 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1060 | 1060 | |
| 1061 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1062 | - exit; |
|
| 1061 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1062 | + exit; |
|
| 1063 | 1063 | |
| 1064 | - } |
|
| 1064 | + } |
|
| 1065 | 1065 | |
| 1066 | - } // end quiz_has_no_questions |
|
| 1066 | + } // end quiz_has_no_questions |
|
| 1067 | 1067 | |
| 1068 | 1068 | /** |
| 1069 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1070 | - * |
|
| 1071 | - * @deprecated since 1.9.0 |
|
| 1072 | - */ |
|
| 1069 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1070 | + * |
|
| 1071 | + * @deprecated since 1.9.0 |
|
| 1072 | + */ |
|
| 1073 | 1073 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
| 1074 | 1074 | |
| 1075 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1075 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1076 | 1076 | |
| 1077 | 1077 | } |
| 1078 | - /* |
|
| 1078 | + /* |
|
| 1079 | 1079 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
| 1080 | 1080 | * |
| 1081 | 1081 | * @deprecated since 1.9.0 |
| 1082 | 1082 | */ |
| 1083 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1083 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1084 | 1084 | |
| 1085 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1085 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1086 | 1086 | |
| 1087 | - } |
|
| 1087 | + } |
|
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * Filter the single title and add the Quiz to it. |
|
| 1091 | - * |
|
| 1092 | - * @param string $title |
|
| 1093 | - * @param int $id title post id |
|
| 1094 | - * @return string $quiz_title |
|
| 1095 | - */ |
|
| 1096 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1089 | + /** |
|
| 1090 | + * Filter the single title and add the Quiz to it. |
|
| 1091 | + * |
|
| 1092 | + * @param string $title |
|
| 1093 | + * @param int $id title post id |
|
| 1094 | + * @return string $quiz_title |
|
| 1095 | + */ |
|
| 1096 | + public static function single_quiz_title( $title, $post_id ){ |
|
| 1097 | 1097 | |
| 1098 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1098 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1099 | 1099 | |
| 1100 | - $title_with_no_quizzes = $title; |
|
| 1100 | + $title_with_no_quizzes = $title; |
|
| 1101 | 1101 | |
| 1102 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1103 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1102 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1103 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1104 | 1104 | |
| 1105 | - // remove all possible appearances of quiz |
|
| 1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1105 | + // remove all possible appearances of quiz |
|
| 1106 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1107 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1108 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1109 | 1109 | |
| 1110 | - } |
|
| 1110 | + } |
|
| 1111 | 1111 | |
| 1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1113 | - } |
|
| 1112 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | - /** |
|
| 1116 | - * hook document in class-woothemes-sensei-message.php |
|
| 1117 | - */ |
|
| 1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1115 | + /** |
|
| 1116 | + * hook document in class-woothemes-sensei-message.php |
|
| 1117 | + */ |
|
| 1118 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1119 | 1119 | |
| 1120 | - } |
|
| 1120 | + } |
|
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * Initialize the quiz question loop on the single quiz template |
|
| 1124 | - * |
|
| 1125 | - * The function will create a global quiz loop varialbe. |
|
| 1126 | - * |
|
| 1127 | - * @since 1.9.0 |
|
| 1128 | - * |
|
| 1129 | - */ |
|
| 1130 | - public static function start_quiz_questions_loop(){ |
|
| 1122 | + /** |
|
| 1123 | + * Initialize the quiz question loop on the single quiz template |
|
| 1124 | + * |
|
| 1125 | + * The function will create a global quiz loop varialbe. |
|
| 1126 | + * |
|
| 1127 | + * @since 1.9.0 |
|
| 1128 | + * |
|
| 1129 | + */ |
|
| 1130 | + public static function start_quiz_questions_loop(){ |
|
| 1131 | 1131 | |
| 1132 | - global $sensei_question_loop; |
|
| 1132 | + global $sensei_question_loop; |
|
| 1133 | 1133 | |
| 1134 | - //intialize the questions loop object |
|
| 1135 | - $sensei_question_loop['current'] = -1; |
|
| 1136 | - $sensei_question_loop['total'] = 0; |
|
| 1137 | - $sensei_question_loop['questions'] = array(); |
|
| 1134 | + //intialize the questions loop object |
|
| 1135 | + $sensei_question_loop['current'] = -1; |
|
| 1136 | + $sensei_question_loop['total'] = 0; |
|
| 1137 | + $sensei_question_loop['questions'] = array(); |
|
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1140 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1141 | 1141 | |
| 1142 | - if( count( $questions ) > 0 ){ |
|
| 1142 | + if( count( $questions ) > 0 ){ |
|
| 1143 | 1143 | |
| 1144 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1145 | - $sensei_question_loop['questions'] = $questions; |
|
| 1146 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1144 | + $sensei_question_loop['total'] = count( $questions ); |
|
| 1145 | + $sensei_question_loop['questions'] = $questions; |
|
| 1146 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1147 | 1147 | |
| 1148 | - } |
|
| 1148 | + } |
|
| 1149 | 1149 | |
| 1150 | - }// static function |
|
| 1150 | + }// static function |
|
| 1151 | 1151 | |
| 1152 | - /** |
|
| 1153 | - * Initialize the quiz question loop on the single quiz template |
|
| 1154 | - * |
|
| 1155 | - * The function will create a global quiz loop varialbe. |
|
| 1156 | - * |
|
| 1157 | - * @since 1.9.0 |
|
| 1158 | - * |
|
| 1159 | - */ |
|
| 1160 | - public static function stop_quiz_questions_loop(){ |
|
| 1152 | + /** |
|
| 1153 | + * Initialize the quiz question loop on the single quiz template |
|
| 1154 | + * |
|
| 1155 | + * The function will create a global quiz loop varialbe. |
|
| 1156 | + * |
|
| 1157 | + * @since 1.9.0 |
|
| 1158 | + * |
|
| 1159 | + */ |
|
| 1160 | + public static function stop_quiz_questions_loop(){ |
|
| 1161 | 1161 | |
| 1162 | - $sensei_question_loop['total'] = 0; |
|
| 1163 | - $sensei_question_loop['questions'] = array(); |
|
| 1164 | - $sensei_question_loop['quiz_id'] = ''; |
|
| 1162 | + $sensei_question_loop['total'] = 0; |
|
| 1163 | + $sensei_question_loop['questions'] = array(); |
|
| 1164 | + $sensei_question_loop['quiz_id'] = ''; |
|
| 1165 | 1165 | |
| 1166 | - } |
|
| 1166 | + } |
|
| 1167 | 1167 | |
| 1168 | - /** |
|
| 1169 | - * Output the title for the single quiz page |
|
| 1170 | - * |
|
| 1171 | - * @since 1.9.0 |
|
| 1172 | - */ |
|
| 1173 | - public static function the_title(){ |
|
| 1174 | - ?> |
|
| 1168 | + /** |
|
| 1169 | + * Output the title for the single quiz page |
|
| 1170 | + * |
|
| 1171 | + * @since 1.9.0 |
|
| 1172 | + */ |
|
| 1173 | + public static function the_title(){ |
|
| 1174 | + ?> |
|
| 1175 | 1175 | <header> |
| 1176 | 1176 | |
| 1177 | 1177 | <h1> |
| 1178 | 1178 | |
| 1179 | 1179 | <?php |
| 1180 | - /** |
|
| 1181 | - * Filter documented in class-sensei-messages.php the_title |
|
| 1182 | - */ |
|
| 1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1184 | - ?> |
|
| 1180 | + /** |
|
| 1181 | + * Filter documented in class-sensei-messages.php the_title |
|
| 1182 | + */ |
|
| 1183 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1184 | + ?> |
|
| 1185 | 1185 | |
| 1186 | 1186 | </h1> |
| 1187 | 1187 | |
| 1188 | 1188 | </header> |
| 1189 | 1189 | |
| 1190 | 1190 | <?php |
| 1191 | - }//the_title |
|
| 1191 | + }//the_title |
|
| 1192 | 1192 | |
| 1193 | - /** |
|
| 1194 | - * Output the sensei quiz status message. |
|
| 1195 | - * |
|
| 1196 | - * @param $quiz_id |
|
| 1197 | - */ |
|
| 1198 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1193 | + /** |
|
| 1194 | + * Output the sensei quiz status message. |
|
| 1195 | + * |
|
| 1196 | + * @param $quiz_id |
|
| 1197 | + */ |
|
| 1198 | + public static function the_user_status_message( $quiz_id ){ |
|
| 1199 | 1199 | |
| 1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1201 | - $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1200 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1201 | + $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1202 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1203 | 1203 | |
| 1204 | - } |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | - /** |
|
| 1207 | - * This functions runs the old sensei_quiz_action_buttons action |
|
| 1208 | - * for backwards compatiblity sake. |
|
| 1209 | - * |
|
| 1210 | - * @since 1.9.0 |
|
| 1211 | - * @deprecated |
|
| 1212 | - */ |
|
| 1213 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1206 | + /** |
|
| 1207 | + * This functions runs the old sensei_quiz_action_buttons action |
|
| 1208 | + * for backwards compatiblity sake. |
|
| 1209 | + * |
|
| 1210 | + * @since 1.9.0 |
|
| 1211 | + * @deprecated |
|
| 1212 | + */ |
|
| 1213 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1214 | 1214 | |
| 1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1215 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1216 | 1216 | |
| 1217 | - } |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | - /** |
|
| 1220 | - * The quiz action buttons needed to ouput quiz |
|
| 1221 | - * action such as reset complete and save. |
|
| 1222 | - * |
|
| 1223 | - * @since 1.3.0 |
|
| 1224 | - */ |
|
| 1225 | - public static function action_buttons() { |
|
| 1219 | + /** |
|
| 1220 | + * The quiz action buttons needed to ouput quiz |
|
| 1221 | + * action such as reset complete and save. |
|
| 1222 | + * |
|
| 1223 | + * @since 1.3.0 |
|
| 1224 | + */ |
|
| 1225 | + public static function action_buttons() { |
|
| 1226 | 1226 | |
| 1227 | - global $post, $current_user; |
|
| 1227 | + global $post, $current_user; |
|
| 1228 | 1228 | |
| 1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1232 | - $show_actions = true; |
|
| 1233 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1229 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1230 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1231 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1232 | + $show_actions = true; |
|
| 1233 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1234 | 1234 | |
| 1235 | - //setup quiz grade |
|
| 1236 | - $user_quiz_grade = ''; |
|
| 1237 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1239 | - } |
|
| 1235 | + //setup quiz grade |
|
| 1236 | + $user_quiz_grade = ''; |
|
| 1237 | + if( ! empty( $user_lesson_status ) ){ |
|
| 1238 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | |
| 1242 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1242 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1243 | 1243 | |
| 1244 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 1245 | - $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1244 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 1245 | + $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1246 | 1246 | |
| 1247 | - } |
|
| 1248 | - if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1247 | + } |
|
| 1248 | + if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1249 | 1249 | |
| 1250 | - // Get Reset Settings |
|
| 1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1250 | + // Get Reset Settings |
|
| 1251 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1252 | 1252 | |
| 1253 | 1253 | <!-- Action Nonce's --> |
| 1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1275,55 +1275,55 @@ discard block |
||
| 1275 | 1275 | |
| 1276 | 1276 | <?php } |
| 1277 | 1277 | |
| 1278 | - } // End sensei_quiz_action_buttons() |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Fetch the quiz grade |
|
| 1282 | - * |
|
| 1283 | - * @since 1.9.0 |
|
| 1284 | - * |
|
| 1285 | - * @param int $lesson_id |
|
| 1286 | - * @param int $user_id |
|
| 1287 | - * |
|
| 1288 | - * @return double $user_quiz_grade |
|
| 1289 | - */ |
|
| 1290 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1291 | - |
|
| 1292 | - // get the quiz grade |
|
| 1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1294 | - $user_quiz_grade = 0; |
|
| 1295 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - return (double) $user_quiz_grade; |
|
| 1300 | - |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Check the quiz reset property for a given lesson's quiz. |
|
| 1305 | - * |
|
| 1306 | - * The data is stored on the quiz but going forward the quiz post |
|
| 1307 | - * type will be retired, hence the lesson_id is a require parameter. |
|
| 1308 | - * |
|
| 1309 | - * @since 1.9.0 |
|
| 1310 | - * |
|
| 1311 | - * @param int $lesson_id |
|
| 1312 | - * @return bool |
|
| 1313 | - */ |
|
| 1314 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1315 | - |
|
| 1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1317 | - |
|
| 1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1319 | - //backwards compatibility |
|
| 1320 | - if( 'on' == $reset_allowed ) { |
|
| 1321 | - $reset_allowed = 1; |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - return (bool) $reset_allowed; |
|
| 1325 | - |
|
| 1326 | - } |
|
| 1278 | + } // End sensei_quiz_action_buttons() |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Fetch the quiz grade |
|
| 1282 | + * |
|
| 1283 | + * @since 1.9.0 |
|
| 1284 | + * |
|
| 1285 | + * @param int $lesson_id |
|
| 1286 | + * @param int $user_id |
|
| 1287 | + * |
|
| 1288 | + * @return double $user_quiz_grade |
|
| 1289 | + */ |
|
| 1290 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1291 | + |
|
| 1292 | + // get the quiz grade |
|
| 1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1294 | + $user_quiz_grade = 0; |
|
| 1295 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1296 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + return (double) $user_quiz_grade; |
|
| 1300 | + |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Check the quiz reset property for a given lesson's quiz. |
|
| 1305 | + * |
|
| 1306 | + * The data is stored on the quiz but going forward the quiz post |
|
| 1307 | + * type will be retired, hence the lesson_id is a require parameter. |
|
| 1308 | + * |
|
| 1309 | + * @since 1.9.0 |
|
| 1310 | + * |
|
| 1311 | + * @param int $lesson_id |
|
| 1312 | + * @return bool |
|
| 1313 | + */ |
|
| 1314 | + public static function is_reset_allowed( $lesson_id ){ |
|
| 1315 | + |
|
| 1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1317 | + |
|
| 1318 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1319 | + //backwards compatibility |
|
| 1320 | + if( 'on' == $reset_allowed ) { |
|
| 1321 | + $reset_allowed = 1; |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + return (bool) $reset_allowed; |
|
| 1325 | + |
|
| 1326 | + } |
|
| 1327 | 1327 | |
| 1328 | 1328 | } // End Class WooThemes_Sensei_Quiz |
| 1329 | 1329 | |
@@ -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 Quiz Class |
@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param $file |
| 25 | 25 | */ |
| 26 | - public function __construct ( $file = __FILE__ ) { |
|
| 26 | + public function __construct($file = __FILE__) { |
|
| 27 | 27 | $this->file = $file; |
| 28 | - $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
|
| 29 | - add_action( 'save_post', array( $this, 'update_author' )); |
|
| 28 | + $this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset'); |
|
| 29 | + add_action('save_post', array($this, 'update_author')); |
|
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click |
| 32 | - add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
| 32 | + add_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
| 33 | 33 | |
| 34 | 34 | // fire the complete quiz button submit for grading action |
| 35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 35 | + add_action('sensei_complete_quiz', array($this, 'user_quiz_submit_listener')); |
|
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder |
| 38 | - add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
|
| 38 | + add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener')); |
|
| 39 | 39 | |
| 40 | 40 | // fire the load global data function |
| 41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 41 | + add_action('sensei_complete_quiz', array($this, 'load_global_quiz_data'), 80); |
|
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 43 | + add_action('template_redirect', array($this, 'quiz_has_no_questions')); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | } // End __construct() |
@@ -51,26 +51,26 @@ discard block |
||
| 51 | 51 | * @param int $post_id |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function update_author( $post_id ){ |
|
| 54 | + public function update_author($post_id) { |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // If this isn't a 'lesson' post, don't update it. |
| 58 | 58 | // if this is a revision don't save it |
| 59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 60 | - || wp_is_post_revision( $post_id ) ) { |
|
| 59 | + if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type'] |
|
| 60 | + || wp_is_post_revision($post_id)) { |
|
| 61 | 61 | |
| 62 | 62 | return; |
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | // get the lesson author id to be use late |
| 66 | - $saved_post = get_post( $post_id ); |
|
| 67 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 66 | + $saved_post = get_post($post_id); |
|
| 67 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 68 | 68 | |
| 69 | 69 | //get the lessons quiz |
| 70 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
|
| 71 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 70 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id); |
|
| 71 | + foreach ((array) $lesson_quizzes as $quiz_item) { |
|
| 72 | 72 | |
| 73 | - if( ! $quiz_item ) { |
|
| 73 | + if ( ! $quiz_item) { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | // remove the action so that it doesn't fire again |
| 84 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | + remove_action('save_post', array($this, 'update_author')); |
|
| 85 | 85 | |
| 86 | 86 | // Update the post into the database |
| 87 | - wp_update_post( $my_post ); |
|
| 87 | + wp_update_post($my_post); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return; |
@@ -98,19 +98,19 @@ discard block |
||
| 98 | 98 | * @param int $quiz_id |
| 99 | 99 | * @return int @lesson_id |
| 100 | 100 | */ |
| 101 | - public function get_lesson_id( $quiz_id ){ |
|
| 101 | + public function get_lesson_id($quiz_id) { |
|
| 102 | 102 | |
| 103 | - if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){ |
|
| 103 | + if (empty($quiz_id) || ! intval($quiz_id) > 0) { |
|
| 104 | 104 | global $post; |
| 105 | - if( 'quiz' == get_post_type( $post ) ){ |
|
| 105 | + if ('quiz' == get_post_type($post)) { |
|
| 106 | 106 | $quiz_id = $post->ID; |
| 107 | - }else{ |
|
| 107 | + } else { |
|
| 108 | 108 | return false; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $quiz = get_post( $quiz_id ); |
|
| 113 | + $quiz = get_post($quiz_id); |
|
| 114 | 114 | $lesson_id = $quiz->post_parent; |
| 115 | 115 | |
| 116 | 116 | return $lesson_id; |
@@ -125,23 +125,23 @@ discard block |
||
| 125 | 125 | * @since 1.7.3 |
| 126 | 126 | * @return bool $saved; |
| 127 | 127 | */ |
| 128 | - public function user_save_quiz_answers_listener(){ |
|
| 128 | + public function user_save_quiz_answers_listener() { |
|
| 129 | 129 | |
| 130 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 131 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 133 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 130 | + if ( ! isset($_POST['quiz_save']) |
|
| 131 | + || ! isset($_POST['sensei_question']) |
|
| 132 | + || empty($_POST['sensei_question']) |
|
| 133 | + || ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) { |
|
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | global $post; |
| 138 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 139 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 138 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 139 | + $quiz_answers = $_POST['sensei_question']; |
|
| 140 | 140 | // call the save function |
| 141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 141 | + self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id()); |
|
| 142 | 142 | |
| 143 | 143 | // remove the hook as it should only fire once per click |
| 144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 144 | + remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener'); |
|
| 145 | 145 | |
| 146 | 146 | } // end user_save_quiz_answers_listener |
| 147 | 147 | |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return false or int $answers_saved |
| 162 | 162 | */ |
| 163 | - public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
|
| 163 | + public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
| 164 | 164 | |
| 165 | - if( ! ( $user_id > 0 ) ){ |
|
| 165 | + if ( ! ($user_id > 0)) { |
|
| 166 | 166 | $user_id = get_current_user_id(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // make sure the parameters are valid before continuing |
| 170 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 171 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 172 | - ||!get_userdata( $user_id ) |
|
| 173 | - || !is_array( $quiz_answers ) ){ |
|
| 170 | + if (empty($lesson_id) || empty($user_id) |
|
| 171 | + || 'lesson' != get_post_type($lesson_id) |
|
| 172 | + ||! get_userdata($user_id) |
|
| 173 | + || ! is_array($quiz_answers)) { |
|
| 174 | 174 | |
| 175 | 175 | return false; |
| 176 | 176 | |
@@ -178,23 +178,23 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | // start the lesson before saving the data in case the user has not started the lesson |
| 181 | - $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | + $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 182 | 182 | |
| 183 | 183 | //prepare the answers |
| 184 | - $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
|
| 184 | + $prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files); |
|
| 185 | 185 | |
| 186 | 186 | // save the user data |
| 187 | - $answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | + $answers_saved = WooThemes_Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id); |
|
| 188 | 188 | |
| 189 | 189 | // were the answers saved correctly? |
| 190 | - if( intval( $answers_saved ) > 0){ |
|
| 190 | + if (intval($answers_saved) > 0) { |
|
| 191 | 191 | |
| 192 | 192 | // save transient to make retrieval faster |
| 193 | 193 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 194 | + set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS); |
|
| 195 | 195 | |
| 196 | 196 | // update the message showed to user |
| 197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>'; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $answers_saved; |
@@ -216,41 +216,41 @@ discard block |
||
| 216 | 216 | * |
| 217 | 217 | * @return array $answers or false |
| 218 | 218 | */ |
| 219 | - public function get_user_answers( $lesson_id, $user_id ){ |
|
| 219 | + public function get_user_answers($lesson_id, $user_id) { |
|
| 220 | 220 | |
| 221 | 221 | $answers = false; |
| 222 | 222 | |
| 223 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 224 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 223 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 224 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // save some time and get the transient cached data |
| 229 | 229 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 230 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 230 | + $transient_cached_answers = get_transient($transient_key); |
|
| 231 | 231 | |
| 232 | 232 | // return the transient or get the values get the values from the comment meta |
| 233 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | + if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) { |
|
| 234 | 234 | |
| 235 | 235 | $encoded_user_answers = $transient_cached_answers; |
| 236 | 236 | |
| 237 | - }else{ |
|
| 237 | + } else { |
|
| 238 | 238 | |
| 239 | - $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | + $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id); |
|
| 240 | 240 | |
| 241 | 241 | } // end if transient check |
| 242 | 242 | |
| 243 | - if( ! is_array( $encoded_user_answers ) ){ |
|
| 243 | + if ( ! is_array($encoded_user_answers)) { |
|
| 244 | 244 | return false; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | //set the transient with the new valid data for faster retrieval in future |
| 248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | + set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 249 | 249 | |
| 250 | 250 | // decode an unserialize all answers |
| 251 | - foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
|
| 252 | - $decoded_answer = base64_decode( $encoded_answer ); |
|
| 253 | - $answers[$question_id] = maybe_unserialize( $decoded_answer ); |
|
| 251 | + foreach ($encoded_user_answers as $question_id => $encoded_answer) { |
|
| 252 | + $decoded_answer = base64_decode($encoded_answer); |
|
| 253 | + $answers[$question_id] = maybe_unserialize($decoded_answer); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | return $answers; |
@@ -267,23 +267,23 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void; |
| 269 | 269 | */ |
| 270 | - public function reset_button_click_listener( ){ |
|
| 270 | + public function reset_button_click_listener( ) { |
|
| 271 | 271 | |
| 272 | - if( ! isset( $_POST[ 'quiz_reset' ]) |
|
| 273 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce' ) > 1 ) { |
|
| 272 | + if ( ! isset($_POST['quiz_reset']) |
|
| 273 | + || ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) { |
|
| 274 | 274 | |
| 275 | 275 | return; // exit |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | global $post; |
| 279 | 279 | $current_quiz_id = $post->ID; |
| 280 | - $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
|
| 280 | + $lesson_id = $this->get_lesson_id($current_quiz_id); |
|
| 281 | 281 | |
| 282 | 282 | // reset all user data |
| 283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | + $this->reset_user_lesson_data($lesson_id, get_current_user_id()); |
|
| 284 | 284 | |
| 285 | 285 | //this function should only run once |
| 286 | - remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
| 286 | + remove_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
| 287 | 287 | |
| 288 | 288 | } // end reset_button_click_listener |
| 289 | 289 | |
@@ -302,18 +302,18 @@ discard block |
||
| 302 | 302 | public function user_quiz_submit_listener() { |
| 303 | 303 | |
| 304 | 304 | // only respond to valid quiz completion submissions |
| 305 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 306 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 308 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 305 | + if ( ! isset($_POST['quiz_complete']) |
|
| 306 | + || ! isset($_POST['sensei_question']) |
|
| 307 | + || empty($_POST['sensei_question']) |
|
| 308 | + || ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) { |
|
| 309 | 309 | return; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | global $post, $current_user; |
| 313 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 314 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 313 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 314 | + $quiz_answers = $_POST['sensei_question']; |
|
| 315 | 315 | |
| 316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | + self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID); |
|
| 317 | 317 | |
| 318 | 318 | } // End sensei_complete_quiz() |
| 319 | 319 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @access public |
| 328 | 328 | * |
| 329 | 329 | */ |
| 330 | - public function load_global_quiz_data(){ |
|
| 330 | + public function load_global_quiz_data() { |
|
| 331 | 331 | |
| 332 | 332 | global $post, $current_user; |
| 333 | 333 | $this->data = new stdClass(); |
@@ -336,46 +336,46 @@ discard block |
||
| 336 | 336 | $grade = 0; |
| 337 | 337 | |
| 338 | 338 | // Get Quiz Questions |
| 339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID); |
|
| 340 | 340 | |
| 341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | + $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true)); |
|
| 342 | 342 | |
| 343 | 343 | // Get quiz grade type |
| 344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | + $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true); |
|
| 345 | 345 | |
| 346 | 346 | // Get quiz pass setting |
| 347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | + $pass_required = get_post_meta($post->ID, '_pass_required', true); |
|
| 348 | 348 | |
| 349 | 349 | // Get quiz pass mark |
| 350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | + $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2)); |
|
| 351 | 351 | |
| 352 | 352 | // Get latest quiz answers and grades |
| 353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 355 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 353 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); |
|
| 354 | + $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id()); |
|
| 355 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID); |
|
| 356 | 356 | $user_quiz_grade = 0; |
| 357 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 357 | + if (isset($user_lesson_status->comment_ID)) { |
|
| 358 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | + if ( ! is_array($user_quizzes)) { $user_quizzes = array(); } |
|
| 362 | 362 | |
| 363 | 363 | // Check again that the lesson is complete |
| 364 | - $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | + $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
| 365 | 365 | $user_lesson_complete = false; |
| 366 | - if ( $user_lesson_end ) { |
|
| 366 | + if ($user_lesson_end) { |
|
| 367 | 367 | $user_lesson_complete = true; |
| 368 | 368 | } // End If Statement |
| 369 | 369 | |
| 370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | + $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); |
|
| 371 | 371 | //backwards compatibility |
| 372 | - if( 'on' == $reset_allowed ) { |
|
| 372 | + if ('on' == $reset_allowed) { |
|
| 373 | 373 | $reset_allowed = 1; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // Build frontend data object for backwards compatibility |
| 377 | 377 | // using this is no longer recommended |
| 378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | + $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 379 | 379 | $this->data->quiz_passmark = $quiz_passmark; |
| 380 | 380 | $this->data->quiz_lesson = $quiz_lesson_id; |
| 381 | 381 | $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
@@ -400,41 +400,41 @@ discard block |
||
| 400 | 400 | * @param $files |
| 401 | 401 | * @return array |
| 402 | 402 | */ |
| 403 | - public static function prepare_form_submitted_answers( $unprepared_answers, $files ){ |
|
| 403 | + public static function prepare_form_submitted_answers($unprepared_answers, $files) { |
|
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | $prepared_answers = array(); |
| 407 | 407 | |
| 408 | 408 | // validate incoming answers |
| 409 | - if( empty( $unprepared_answers ) || ! is_array( $unprepared_answers ) ){ |
|
| 409 | + if (empty($unprepared_answers) || ! is_array($unprepared_answers)) { |
|
| 410 | 410 | return false; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // Loop through submitted quiz answers and save them appropriately |
| 414 | - foreach( $unprepared_answers as $question_id => $answer ) { |
|
| 414 | + foreach ($unprepared_answers as $question_id => $answer) { |
|
| 415 | 415 | |
| 416 | 416 | //get the current questions question type |
| 417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 418 | 418 | |
| 419 | 419 | // Sanitise answer |
| 420 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 421 | - $answer = wp_unslash( $answer ); |
|
| 420 | + if (0 == get_magic_quotes_gpc()) { |
|
| 421 | + $answer = wp_unslash($answer); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | // compress the answer for saving |
| 425 | - if( 'multi-line' == $question_type ) { |
|
| 426 | - $answer = esc_html( $answer ); |
|
| 427 | - }elseif( 'file-upload' == $question_type ){ |
|
| 428 | - $file_key = 'file_upload_' . $question_id; |
|
| 429 | - if( isset( $files[ $file_key ] ) ) { |
|
| 430 | - $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 431 | - if( $attachment_id ) { |
|
| 425 | + if ('multi-line' == $question_type) { |
|
| 426 | + $answer = esc_html($answer); |
|
| 427 | + }elseif ('file-upload' == $question_type) { |
|
| 428 | + $file_key = 'file_upload_'.$question_id; |
|
| 429 | + if (isset($files[$file_key])) { |
|
| 430 | + $attachment_id = WooThemes_Sensei_Utils::upload_file($files[$file_key]); |
|
| 431 | + if ($attachment_id) { |
|
| 432 | 432 | $answer = $attachment_id; |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } // end if |
| 436 | 436 | |
| 437 | - $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
|
| 437 | + $prepared_answers[$question_id] = base64_encode(maybe_serialize($answer)); |
|
| 438 | 438 | |
| 439 | 439 | }// end for each $quiz_answers |
| 440 | 440 | |
@@ -454,54 +454,54 @@ discard block |
||
| 454 | 454 | * @param int $user_id |
| 455 | 455 | * @param int $lesson_id |
| 456 | 456 | */ |
| 457 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 457 | + public function reset_user_lesson_data($lesson_id, $user_id = 0) { |
|
| 458 | 458 | |
| 459 | 459 | //make sure the parameters are valid |
| 460 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 461 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 462 | - || ! get_userdata( $user_id ) ){ |
|
| 460 | + if (empty($lesson_id) || empty($user_id) |
|
| 461 | + || 'lesson' != get_post_type($lesson_id) |
|
| 462 | + || ! get_userdata($user_id)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
| 467 | 467 | |
| 468 | 468 | //get the users lesson status to make |
| 469 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 470 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 469 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 470 | + if ( ! isset($user_lesson_status->comment_ID)) { |
|
| 471 | 471 | // this user is not taking this lesson so this process is not needed |
| 472 | 472 | return false; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | //get the lesson quiz and course |
| 476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 476 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 477 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 478 | 478 | |
| 479 | 479 | // reset the transients |
| 480 | 480 | $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 481 | 481 | $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
| 482 | 482 | $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 483 | - delete_transient( $answers_transient_key ); |
|
| 484 | - delete_transient( $grades_transient_key ); |
|
| 485 | - delete_transient( $answers_feedback_transient_key ); |
|
| 483 | + delete_transient($answers_transient_key); |
|
| 484 | + delete_transient($grades_transient_key); |
|
| 485 | + delete_transient($answers_feedback_transient_key); |
|
| 486 | 486 | |
| 487 | 487 | // reset the quiz answers and feedback notes |
| 488 | - $deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 489 | - $deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 490 | - $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 488 | + $deleted_answers = WooThemes_Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id); |
|
| 489 | + $deleted_grades = WooThemes_Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id); |
|
| 490 | + $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
| 491 | 491 | |
| 492 | 492 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
| 493 | - WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 493 | + WooThemes_Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id); |
|
| 494 | 494 | |
| 495 | - WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 495 | + WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => '')); |
|
| 496 | 496 | |
| 497 | 497 | // Update course completion |
| 498 | - WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 498 | + WooThemes_Sensei_Utils::update_course_status($user_id, $course_id); |
|
| 499 | 499 | |
| 500 | 500 | // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
| 501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 501 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
| 502 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>'; |
|
| 503 | 503 | |
| 504 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 504 | + return ($deleted_answers && $deleted_grades); |
|
| 505 | 505 | |
| 506 | 506 | } // end reset_user_lesson_data |
| 507 | 507 | |
@@ -521,20 +521,20 @@ discard block |
||
| 521 | 521 | * |
| 522 | 522 | * @return bool $answers_submitted |
| 523 | 523 | */ |
| 524 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 524 | + public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
| 525 | 525 | |
| 526 | 526 | $answers_submitted = false; |
| 527 | 527 | |
| 528 | 528 | // get the user_id if none was passed in use the current logged in user |
| 529 | - if( ! intval( $user_id ) > 0 ) { |
|
| 529 | + if ( ! intval($user_id) > 0) { |
|
| 530 | 530 | $user_id = get_current_user_id(); |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // make sure the parameters are valid before continuing |
| 534 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 535 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 536 | - ||!get_userdata( $user_id ) |
|
| 537 | - || !is_array( $quiz_answers ) ){ |
|
| 534 | + if (empty($lesson_id) || empty($user_id) |
|
| 535 | + || 'lesson' != get_post_type($lesson_id) |
|
| 536 | + ||! get_userdata($user_id) |
|
| 537 | + || ! is_array($quiz_answers)) { |
|
| 538 | 538 | |
| 539 | 539 | return false; |
| 540 | 540 | |
@@ -544,38 +544,38 @@ discard block |
||
| 544 | 544 | $grade = 0; |
| 545 | 545 | |
| 546 | 546 | // Get Quiz ID |
| 547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 547 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 548 | 548 | |
| 549 | 549 | // Get quiz grade type |
| 550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 550 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 551 | 551 | |
| 552 | 552 | // Get quiz pass setting |
| 553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 553 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 554 | 554 | |
| 555 | 555 | // Get the minimum percentage need to pass this quiz |
| 556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 556 | + $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 557 | 557 | |
| 558 | 558 | // Handle Quiz Questions asked |
| 559 | 559 | // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
| 560 | 560 | // the quiz is reset by admin or user( user: only if the setting is enabled ). |
| 561 | 561 | // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
| 562 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 564 | - if( empty( $questions_asked ) ){ |
|
| 562 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 563 | + $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); |
|
| 564 | + if (empty($questions_asked)) { |
|
| 565 | 565 | |
| 566 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 567 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 566 | + $questions_asked = array_keys($quiz_answers); |
|
| 567 | + $questions_asked_string = implode(',', $questions_asked); |
|
| 568 | 568 | |
| 569 | 569 | // Save questions that were asked in this quiz |
| 570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 570 | + update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string); |
|
| 571 | 571 | |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
| 575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 575 | + self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id); |
|
| 576 | 576 | |
| 577 | 577 | // Grade quiz |
| 578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 578 | + $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type); |
|
| 579 | 579 | |
| 580 | 580 | // Get Lesson Grading Setting |
| 581 | 581 | $lesson_metadata = array(); |
@@ -585,13 +585,13 @@ discard block |
||
| 585 | 585 | $answers_submitted = true; |
| 586 | 586 | |
| 587 | 587 | // if this condition is false the quiz should manually be graded by admin |
| 588 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 588 | + if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) { |
|
| 589 | 589 | |
| 590 | 590 | // Quiz has been automatically Graded |
| 591 | - if ( 'on' == $pass_required ) { |
|
| 591 | + if ('on' == $pass_required) { |
|
| 592 | 592 | |
| 593 | 593 | // Student has reached the pass mark and lesson is complete |
| 594 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 594 | + if ($quiz_pass_percentage <= $grade) { |
|
| 595 | 595 | |
| 596 | 596 | $lesson_status = 'passed'; |
| 597 | 597 | |
@@ -612,9 +612,9 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | } // end if ! is_wp_error( $grade ... |
| 614 | 614 | |
| 615 | - WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 615 | + WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata); |
|
| 616 | 616 | |
| 617 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 617 | + if ('passed' == $lesson_status || 'graded' == $lesson_status) { |
|
| 618 | 618 | |
| 619 | 619 | /** |
| 620 | 620 | * Lesson end action hook |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * @param int $user_id |
| 625 | 625 | * @param int $lesson_id |
| 626 | 626 | */ |
| 627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 627 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
| 628 | 628 | |
| 629 | 629 | } |
| 630 | 630 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | * @param string $quiz_pass_percentage |
| 641 | 641 | * @param string $quiz_grade_type |
| 642 | 642 | */ |
| 643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 643 | + do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type); |
|
| 644 | 644 | |
| 645 | 645 | return $answers_submitted; |
| 646 | 646 | |
@@ -660,38 +660,38 @@ discard block |
||
| 660 | 660 | * |
| 661 | 661 | * @return bool $answers_submitted |
| 662 | 662 | */ |
| 663 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 663 | + public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) { |
|
| 664 | 664 | |
| 665 | 665 | // parameter validation |
| 666 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 667 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 668 | - || ! ( intval( $question_id ) > 0 ) |
|
| 669 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 670 | - || 'question' != get_post_type( $question_id )) { |
|
| 666 | + if (empty($lesson_id) || empty($question_id) |
|
| 667 | + || ! (intval($lesson_id) > 0) |
|
| 668 | + || ! (intval($question_id) > 0) |
|
| 669 | + || 'lesson' != get_post_type($lesson_id) |
|
| 670 | + || 'question' != get_post_type($question_id)) { |
|
| 671 | 671 | |
| 672 | 672 | return false; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | + if ( ! (intval($user_id) > 0)) { |
|
| 676 | 676 | $user_id = get_current_user_id(); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | + $users_answers = $this->get_user_answers($lesson_id, $user_id); |
|
| 680 | 680 | |
| 681 | - if( !$users_answers || empty( $users_answers ) |
|
| 682 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 681 | + if ( ! $users_answers || empty($users_answers) |
|
| 682 | + || ! is_array($users_answers) || ! isset($users_answers[$question_id])) { |
|
| 683 | 683 | |
| 684 | 684 | //Fallback for pre 1.7.4 data |
| 685 | - $comment = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | + $comment = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true); |
|
| 686 | 686 | |
| 687 | - if( ! isset( $comment->comment_content ) ){ |
|
| 687 | + if ( ! isset($comment->comment_content)) { |
|
| 688 | 688 | return false; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | + return maybe_unserialize(base64_decode($comment->comment_content)); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - return $users_answers[ $question_id ]; |
|
| 694 | + return $users_answers[$question_id]; |
|
| 695 | 695 | |
| 696 | 696 | }// end get_user_question_answer |
| 697 | 697 | |
@@ -712,18 +712,18 @@ discard block |
||
| 712 | 712 | * |
| 713 | 713 | * @return bool |
| 714 | 714 | */ |
| 715 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | + public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) { |
|
| 716 | 716 | |
| 717 | 717 | // get the user_id if none was passed in use the current logged in user |
| 718 | - if( ! intval( $user_id ) > 0 ) { |
|
| 718 | + if ( ! intval($user_id) > 0) { |
|
| 719 | 719 | $user_id = get_current_user_id(); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // make sure the parameters are valid before continuing |
| 723 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 724 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 725 | - ||!get_userdata( $user_id ) |
|
| 726 | - || !is_array( $quiz_grades ) ){ |
|
| 723 | + if (empty($lesson_id) || empty($user_id) |
|
| 724 | + || 'lesson' != get_post_type($lesson_id) |
|
| 725 | + ||! get_userdata($user_id) |
|
| 726 | + || ! is_array($quiz_grades)) { |
|
| 727 | 727 | |
| 728 | 728 | return false; |
| 729 | 729 | |
@@ -732,15 +732,15 @@ discard block |
||
| 732 | 732 | $success = false; |
| 733 | 733 | |
| 734 | 734 | // save that data for the user on the lesson comment meta |
| 735 | - $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | + $comment_meta_id = WooThemes_Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id); |
|
| 736 | 736 | |
| 737 | 737 | // were the grades save successfully ? |
| 738 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | + if (intval($comment_meta_id) > 0) { |
|
| 739 | 739 | |
| 740 | 740 | $success = true; |
| 741 | 741 | // save transient |
| 742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 742 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 743 | + set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | return $success; |
@@ -759,36 +759,36 @@ discard block |
||
| 759 | 759 | * |
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users |
| 761 | 761 | */ |
| 762 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | + public function get_user_grades($lesson_id, $user_id = 0) { |
|
| 763 | 763 | |
| 764 | 764 | $user_grades = array(); |
| 765 | 765 | |
| 766 | 766 | // get the user_id if none was passed in use the current logged in user |
| 767 | - if( ! intval( $user_id ) > 0 ) { |
|
| 767 | + if ( ! intval($user_id) > 0) { |
|
| 768 | 768 | $user_id = get_current_user_id(); |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 772 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 771 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 772 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 773 | 773 | return false; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | // save some time and get the transient cached data |
| 777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 778 | - $user_grades = get_transient( $transient_key ); |
|
| 777 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 778 | + $user_grades = get_transient($transient_key); |
|
| 779 | 779 | |
| 780 | 780 | // get the data if nothing was stored in the transient |
| 781 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | + if (empty($user_grades) || false != $user_grades) { |
|
| 782 | 782 | |
| 783 | - $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | + $user_grades = WooThemes_Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id); |
|
| 784 | 784 | |
| 785 | 785 | //set the transient with the new valid data for faster retrieval in future |
| 786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | + set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS); |
|
| 787 | 787 | |
| 788 | 788 | } // end if transient check |
| 789 | 789 | |
| 790 | 790 | // if there is no data for this user |
| 791 | - if( ! is_array( $user_grades ) ){ |
|
| 791 | + if ( ! is_array($user_grades)) { |
|
| 792 | 792 | return false; |
| 793 | 793 | } |
| 794 | 794 | |
@@ -811,21 +811,21 @@ discard block |
||
| 811 | 811 | * |
| 812 | 812 | * @return bool $question_grade |
| 813 | 813 | */ |
| 814 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | + public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) { |
|
| 815 | 815 | |
| 816 | 816 | // parameter validation |
| 817 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 818 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 819 | - || ! ( intval( $question_id ) > 0 ) |
|
| 820 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 821 | - || 'question' != get_post_type( $question_id )) { |
|
| 817 | + if (empty($lesson_id) || empty($question_id) |
|
| 818 | + || ! (intval($lesson_id) > 0) |
|
| 819 | + || ! (intval($question_id) > 0) |
|
| 820 | + || 'lesson' != get_post_type($lesson_id) |
|
| 821 | + || 'question' != get_post_type($question_id)) { |
|
| 822 | 822 | |
| 823 | 823 | return false; |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | + $all_user_grades = self::get_user_grades($lesson_id, $user_id); |
|
| 827 | 827 | |
| 828 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | + if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) { |
|
| 829 | 829 | |
| 830 | 830 | //fallback to data pre 1.7.4 |
| 831 | 831 | $args = array( |
@@ -834,17 +834,17 @@ discard block |
||
| 834 | 834 | 'type' => 'sensei_user_answer' |
| 835 | 835 | ); |
| 836 | 836 | |
| 837 | - $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | + $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 838 | 838 | $fall_back_grade = false; |
| 839 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 839 | + if (isset($question_activity->comment_ID)) { |
|
| 840 | + $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | return $fall_back_grade; |
| 844 | 844 | |
| 845 | 845 | } // end if $all_user_grades... |
| 846 | 846 | |
| 847 | - return $all_user_grades[ $question_id ]; |
|
| 847 | + return $all_user_grades[$question_id]; |
|
| 848 | 848 | |
| 849 | 849 | }// end get_user_question_grade |
| 850 | 850 | |
@@ -866,13 +866,13 @@ discard block |
||
| 866 | 866 | * |
| 867 | 867 | * @return false or int $feedback_saved |
| 868 | 868 | */ |
| 869 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | + public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) { |
|
| 870 | 870 | |
| 871 | 871 | // make sure the parameters are valid before continuing |
| 872 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 873 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 874 | - ||!get_userdata( $user_id ) |
|
| 875 | - || !is_array( $answers_feedback ) ){ |
|
| 872 | + if (empty($lesson_id) || empty($user_id) |
|
| 873 | + || 'lesson' != get_post_type($lesson_id) |
|
| 874 | + ||! get_userdata($user_id) |
|
| 875 | + || ! is_array($answers_feedback)) { |
|
| 876 | 876 | |
| 877 | 877 | return false; |
| 878 | 878 | |
@@ -880,25 +880,25 @@ discard block |
||
| 880 | 880 | |
| 881 | 881 | |
| 882 | 882 | // check if the lesson is started before saving, if not start the lesson for the user |
| 883 | - if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 884 | - WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 883 | + if ( ! (0 < intval(WooThemes_Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) { |
|
| 884 | + WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | // encode the feedback |
| 888 | - $encoded_answers_feedback = array(); |
|
| 889 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 888 | + $encoded_answers_feedback = array(); |
|
| 889 | + foreach ($answers_feedback as $question_id => $feedback) { |
|
| 890 | + $encoded_answers_feedback[$question_id] = base64_encode($feedback); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | // save the user data |
| 894 | - $feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | + $feedback_saved = WooThemes_Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id); |
|
| 895 | 895 | |
| 896 | 896 | //Were the the question feedback save correctly? |
| 897 | - if( intval( $feedback_saved ) > 0){ |
|
| 897 | + if (intval($feedback_saved) > 0) { |
|
| 898 | 898 | |
| 899 | 899 | // save transient to make retrieval faster in future |
| 900 | 900 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 901 | + set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS); |
|
| 902 | 902 | |
| 903 | 903 | } |
| 904 | 904 | |
@@ -923,42 +923,42 @@ discard block |
||
| 923 | 923 | * $type string $question_feedback |
| 924 | 924 | * } |
| 925 | 925 | */ |
| 926 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | + public function get_user_answers_feedback($lesson_id, $user_id = 0) { |
|
| 927 | 927 | |
| 928 | 928 | $answers_feedback = array(); |
| 929 | 929 | |
| 930 | 930 | // get the user_id if none was passed in use the current logged in user |
| 931 | - if( ! intval( $user_id ) > 0 ) { |
|
| 931 | + if ( ! intval($user_id) > 0) { |
|
| 932 | 932 | $user_id = get_current_user_id(); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 936 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 935 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 936 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 937 | 937 | return false; |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | // first check the transient to save a few split seconds |
| 941 | 941 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 942 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | + $encoded_feedback = get_transient($transient_key); |
|
| 943 | 943 | |
| 944 | 944 | // get the data if nothing was stored in the transient |
| 945 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | + if (empty($encoded_feedback) || ! $encoded_feedback) { |
|
| 946 | 946 | |
| 947 | - $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | + $encoded_feedback = WooThemes_Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
| 948 | 948 | |
| 949 | 949 | //set the transient with the new valid data for faster retrieval in future |
| 950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | + set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 951 | 951 | |
| 952 | 952 | } // end if transient check |
| 953 | 953 | |
| 954 | 954 | // if there is no data for this user |
| 955 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | + if ( ! is_array($encoded_feedback)) { |
|
| 956 | 956 | return false; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | + foreach ($encoded_feedback as $question_id => $feedback) { |
|
| 960 | 960 | |
| 961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | + $answers_feedback[$question_id] = base64_decode($feedback); |
|
| 962 | 962 | |
| 963 | 963 | } |
| 964 | 964 | |
@@ -981,25 +981,25 @@ discard block |
||
| 981 | 981 | * |
| 982 | 982 | * @return string $feedback or bool if false |
| 983 | 983 | */ |
| 984 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 984 | + public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) { |
|
| 985 | 985 | |
| 986 | 986 | $feedback = false; |
| 987 | 987 | |
| 988 | 988 | // parameter validation |
| 989 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 990 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 991 | - || ! ( intval( $question_id ) > 0 ) |
|
| 992 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 993 | - || 'question' != get_post_type( $question_id )) { |
|
| 989 | + if (empty($lesson_id) || empty($question_id) |
|
| 990 | + || ! (intval($lesson_id) > 0) |
|
| 991 | + || ! (intval($question_id) > 0) |
|
| 992 | + || 'lesson' != get_post_type($lesson_id) |
|
| 993 | + || 'question' != get_post_type($question_id)) { |
|
| 994 | 994 | |
| 995 | 995 | return false; |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | // get all the feedback for the user on the given lesson |
| 999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | + $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id); |
|
| 1000 | 1000 | |
| 1001 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1002 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1001 | + if ( ! $all_feedback || empty($all_feedback) |
|
| 1002 | + || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) { |
|
| 1003 | 1003 | |
| 1004 | 1004 | //fallback to data pre 1.7.4 |
| 1005 | 1005 | |
@@ -1009,23 +1009,23 @@ discard block |
||
| 1009 | 1009 | 'user_id' => $user_id, |
| 1010 | 1010 | 'type' => 'sensei_user_answer' |
| 1011 | 1011 | ); |
| 1012 | - $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1012 | + $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 1013 | 1013 | |
| 1014 | 1014 | // set the default to false and return that if no old data is available. |
| 1015 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1015 | + if (isset($question_activity->comment_ID)) { |
|
| 1016 | + $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true)); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | // finally use the default question feedback |
| 1020 | - if( empty( $feedback ) ){ |
|
| 1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1020 | + if (empty($feedback)) { |
|
| 1021 | + $feedback = get_post_meta($question_id, '_answer_feedback', true); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | return $feedback; |
| 1025 | 1025 | |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - return $all_feedback[ $question_id ]; |
|
| 1028 | + return $all_feedback[$question_id]; |
|
| 1029 | 1029 | |
| 1030 | 1030 | } // end get_user_question_feedback |
| 1031 | 1031 | |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | public function quiz_has_no_questions() { |
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1047 | + if ( ! is_singular('quiz')) { |
|
| 1048 | 1048 | return; |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1052,11 +1052,11 @@ discard block |
||
| 1052 | 1052 | |
| 1053 | 1053 | $lesson_id = $this->get_lesson_id($post->ID); |
| 1054 | 1054 | |
| 1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1055 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1056 | 1056 | |
| 1057 | 1057 | $lesson = get_post($lesson_id); |
| 1058 | 1058 | |
| 1059 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1059 | + if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") { |
|
| 1060 | 1060 | |
| 1061 | 1061 | wp_redirect(get_permalink($lesson->ID), 301); |
| 1062 | 1062 | exit; |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * |
| 1071 | 1071 | * @deprecated since 1.9.0 |
| 1072 | 1072 | */ |
| 1073 | - public static function deprecate_quiz_sensei_single_main_content_hook(){ |
|
| 1073 | + public static function deprecate_quiz_sensei_single_main_content_hook() { |
|
| 1074 | 1074 | |
| 1075 | 1075 | sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
| 1076 | 1076 | |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | * |
| 1081 | 1081 | * @deprecated since 1.9.0 |
| 1082 | 1082 | */ |
| 1083 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1083 | + public static function deprecate_quiz_sensei_quiz_single_title_hook() { |
|
| 1084 | 1084 | |
| 1085 | 1085 | sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
| 1086 | 1086 | |
@@ -1093,29 +1093,29 @@ discard block |
||
| 1093 | 1093 | * @param int $id title post id |
| 1094 | 1094 | * @return string $quiz_title |
| 1095 | 1095 | */ |
| 1096 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1096 | + public static function single_quiz_title($title, $post_id) { |
|
| 1097 | 1097 | |
| 1098 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1098 | + if ('quiz' == get_post_type($post_id)) { |
|
| 1099 | 1099 | |
| 1100 | 1100 | $title_with_no_quizzes = $title; |
| 1101 | 1101 | |
| 1102 | 1102 | // if the title has quiz, remove it: legacy titles have the word quiz stored. |
| 1103 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1103 | + if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) { |
|
| 1104 | 1104 | |
| 1105 | 1105 | // remove all possible appearances of quiz |
| 1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1106 | + $title_with_no_quizzes = str_replace('quiz', '', $title); |
|
| 1107 | + $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes); |
|
| 1108 | + $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes); |
|
| 1109 | 1109 | |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1112 | + $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei'); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
| 1116 | 1116 | * hook document in class-woothemes-sensei-message.php |
| 1117 | 1117 | */ |
| 1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1118 | + return apply_filters('sensei_single_title', $title, get_post_type( )); |
|
| 1119 | 1119 | |
| 1120 | 1120 | } |
| 1121 | 1121 | |
@@ -1127,21 +1127,21 @@ discard block |
||
| 1127 | 1127 | * @since 1.9.0 |
| 1128 | 1128 | * |
| 1129 | 1129 | */ |
| 1130 | - public static function start_quiz_questions_loop(){ |
|
| 1130 | + public static function start_quiz_questions_loop() { |
|
| 1131 | 1131 | |
| 1132 | 1132 | global $sensei_question_loop; |
| 1133 | 1133 | |
| 1134 | 1134 | //intialize the questions loop object |
| 1135 | 1135 | $sensei_question_loop['current'] = -1; |
| 1136 | - $sensei_question_loop['total'] = 0; |
|
| 1136 | + $sensei_question_loop['total'] = 0; |
|
| 1137 | 1137 | $sensei_question_loop['questions'] = array(); |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1140 | + $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID()); |
|
| 1141 | 1141 | |
| 1142 | - if( count( $questions ) > 0 ){ |
|
| 1142 | + if (count($questions) > 0) { |
|
| 1143 | 1143 | |
| 1144 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1144 | + $sensei_question_loop['total'] = count($questions); |
|
| 1145 | 1145 | $sensei_question_loop['questions'] = $questions; |
| 1146 | 1146 | $sensei_question_loop['quiz_id'] = get_the_ID(); |
| 1147 | 1147 | |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | * @since 1.9.0 |
| 1158 | 1158 | * |
| 1159 | 1159 | */ |
| 1160 | - public static function stop_quiz_questions_loop(){ |
|
| 1160 | + public static function stop_quiz_questions_loop() { |
|
| 1161 | 1161 | |
| 1162 | - $sensei_question_loop['total'] = 0; |
|
| 1162 | + $sensei_question_loop['total'] = 0; |
|
| 1163 | 1163 | $sensei_question_loop['questions'] = array(); |
| 1164 | 1164 | $sensei_question_loop['quiz_id'] = ''; |
| 1165 | 1165 | |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | * |
| 1171 | 1171 | * @since 1.9.0 |
| 1172 | 1172 | */ |
| 1173 | - public static function the_title(){ |
|
| 1173 | + public static function the_title() { |
|
| 1174 | 1174 | ?> |
| 1175 | 1175 | <header> |
| 1176 | 1176 | |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | /** |
| 1181 | 1181 | * Filter documented in class-sensei-messages.php the_title |
| 1182 | 1182 | */ |
| 1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1183 | + echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID())); |
|
| 1184 | 1184 | ?> |
| 1185 | 1185 | |
| 1186 | 1186 | </h1> |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | * |
| 1196 | 1196 | * @param $quiz_id |
| 1197 | 1197 | */ |
| 1198 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1198 | + public static function the_user_status_message($quiz_id) { |
|
| 1199 | 1199 | |
| 1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1201 | - $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1200 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 1201 | + $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id()); |
|
| 1202 | + echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>'; |
|
| 1203 | 1203 | |
| 1204 | 1204 | } |
| 1205 | 1205 | |
@@ -1210,9 +1210,9 @@ discard block |
||
| 1210 | 1210 | * @since 1.9.0 |
| 1211 | 1211 | * @deprecated |
| 1212 | 1212 | */ |
| 1213 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1213 | + public static function deprecate_sensei_quiz_action_buttons_hook() { |
|
| 1214 | 1214 | |
| 1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1215 | + sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1216 | 1216 | |
| 1217 | 1217 | } |
| 1218 | 1218 | |
@@ -1226,50 +1226,50 @@ discard block |
||
| 1226 | 1226 | |
| 1227 | 1227 | global $post, $current_user; |
| 1228 | 1228 | |
| 1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1229 | + $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true); |
|
| 1230 | + $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true); |
|
| 1231 | + $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 1232 | 1232 | $show_actions = true; |
| 1233 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1233 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID); |
|
| 1234 | 1234 | |
| 1235 | 1235 | //setup quiz grade |
| 1236 | 1236 | $user_quiz_grade = ''; |
| 1237 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | + if ( ! empty($user_lesson_status)) { |
|
| 1238 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
| 1242 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1242 | + if (intval($lesson_prerequisite) > 0) { |
|
| 1243 | 1243 | |
| 1244 | 1244 | // If the user hasn't completed the prereq then hide the current actions |
| 1245 | - $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1245 | + $show_actions = WooThemes_Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID); |
|
| 1246 | 1246 | |
| 1247 | 1247 | } |
| 1248 | - if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1248 | + if ($show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
| 1249 | 1249 | |
| 1250 | 1250 | // Get Reset Settings |
| 1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1251 | + $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?> |
|
| 1252 | 1252 | |
| 1253 | 1253 | <!-- Action Nonce's --> |
| 1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
| 1255 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" /> |
|
| 1255 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" /> |
|
| 1256 | 1256 | <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce" |
| 1257 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" /> |
|
| 1257 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" /> |
|
| 1258 | 1258 | <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce" |
| 1259 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" /> |
|
| 1259 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" /> |
|
| 1260 | 1260 | <!--#end Action Nonce's --> |
| 1261 | 1261 | |
| 1262 | - <?php if ( '' == $user_quiz_grade) { ?> |
|
| 1262 | + <?php if ('' == $user_quiz_grade) { ?> |
|
| 1263 | 1263 | |
| 1264 | - <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1264 | + <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1265 | 1265 | |
| 1266 | - <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1266 | + <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1267 | 1267 | |
| 1268 | 1268 | <?php } // End If Statement ?> |
| 1269 | 1269 | |
| 1270 | - <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?> |
|
| 1270 | + <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?> |
|
| 1271 | 1271 | |
| 1272 | - <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1272 | + <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1273 | 1273 | |
| 1274 | 1274 | <?php } ?> |
| 1275 | 1275 | |
@@ -1287,13 +1287,13 @@ discard block |
||
| 1287 | 1287 | * |
| 1288 | 1288 | * @return double $user_quiz_grade |
| 1289 | 1289 | */ |
| 1290 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1290 | + public static function get_user_quiz_grade($lesson_id, $user_id) { |
|
| 1291 | 1291 | |
| 1292 | 1292 | // get the quiz grade |
| 1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1294 | 1294 | $user_quiz_grade = 0; |
| 1295 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | + if (isset($user_lesson_status->comment_ID)) { |
|
| 1296 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | return (double) $user_quiz_grade; |
@@ -1311,13 +1311,13 @@ discard block |
||
| 1311 | 1311 | * @param int $lesson_id |
| 1312 | 1312 | * @return bool |
| 1313 | 1313 | */ |
| 1314 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1314 | + public static function is_reset_allowed($lesson_id) { |
|
| 1315 | 1315 | |
| 1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1317 | 1317 | |
| 1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1318 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 1319 | 1319 | //backwards compatibility |
| 1320 | - if( 'on' == $reset_allowed ) { |
|
| 1320 | + if ('on' == $reset_allowed) { |
|
| 1321 | 1321 | $reset_allowed = 1; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
@@ -1334,4 +1334,4 @@ discard block |
||
| 1334 | 1334 | * for backward compatibility |
| 1335 | 1335 | * @since 1.9.0 |
| 1336 | 1336 | */ |
| 1337 | -class WooThemes_Sensei_Quiz extends Sensei_Quiz{} |
|
| 1337 | +class WooThemes_Sensei_Quiz extends Sensei_Quiz {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Quiz Class |
@@ -104,7 +107,7 @@ discard block |
||
| 104 | 107 | global $post; |
| 105 | 108 | if( 'quiz' == get_post_type( $post ) ){ |
| 106 | 109 | $quiz_id = $post->ID; |
| 107 | - }else{ |
|
| 110 | + } else{ |
|
| 108 | 111 | return false; |
| 109 | 112 | } |
| 110 | 113 | |
@@ -234,7 +237,7 @@ discard block |
||
| 234 | 237 | |
| 235 | 238 | $encoded_user_answers = $transient_cached_answers; |
| 236 | 239 | |
| 237 | - }else{ |
|
| 240 | + } else{ |
|
| 238 | 241 | |
| 239 | 242 | $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
| 240 | 243 | |
@@ -424,7 +427,7 @@ discard block |
||
| 424 | 427 | // compress the answer for saving |
| 425 | 428 | if( 'multi-line' == $question_type ) { |
| 426 | 429 | $answer = esc_html( $answer ); |
| 427 | - }elseif( 'file-upload' == $question_type ){ |
|
| 430 | + } elseif( 'file-upload' == $question_type ){ |
|
| 428 | 431 | $file_key = 'file_upload_' . $question_id; |
| 429 | 432 | if( isset( $files[ $file_key ] ) ) { |
| 430 | 433 | $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); |
@@ -793,7 +793,7 @@ |
||
| 793 | 793 | * Return an array of field types expecting an array value returned. |
| 794 | 794 | * @access protected |
| 795 | 795 | * @since 1.0.0 |
| 796 | - * @return void |
|
| 796 | + * @return string[] |
|
| 797 | 797 | */ |
| 798 | 798 | protected function get_array_field_types () { |
| 799 | 799 | return array( 'multicheck' ); |
@@ -416,9 +416,9 @@ |
||
| 416 | 416 | echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
| 417 | 417 | if ( $has_description ) { |
| 418 | 418 | echo wp_kses( $args['data']['description'], array( 'a' => array( |
| 419 | - 'href' => array(), |
|
| 420 | - 'title' => array() |
|
| 421 | - ) |
|
| 419 | + 'href' => array(), |
|
| 420 | + 'title' => array() |
|
| 421 | + ) |
|
| 422 | 422 | ) |
| 423 | 423 | ) . '</label>' . "\n"; |
| 424 | 424 | } |
@@ -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 Settings API Class |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @since 1.0.0 |
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | - public function __construct () { |
|
| 37 | + public function __construct() { |
|
| 38 | 38 | $this->token = 'woothemes-sensei'; |
| 39 | 39 | $this->page_slug = 'woothemes-sensei-settings-api'; |
| 40 | 40 | |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | * @since 1.0.0 |
| 57 | 57 | * @return void |
| 58 | 58 | */ |
| 59 | - public function setup_settings () { |
|
| 60 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 61 | - add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
|
| 62 | - add_action( 'init', array( $this, 'general_init' ) ); |
|
| 59 | + public function setup_settings() { |
|
| 60 | + add_action('admin_menu', array($this, 'register_settings_screen'), 60); |
|
| 61 | + add_action('admin_init', array($this, 'settings_fields')); |
|
| 62 | + add_action('init', array($this, 'general_init')); |
|
| 63 | 63 | } // End setup_settings() |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $this->init_sections(); |
| 73 | 73 | $this->init_fields(); |
| 74 | 74 | $this->get_settings(); |
| 75 | - if ( $this->has_tabs == true ) { |
|
| 75 | + if ($this->has_tabs == true) { |
|
| 76 | 76 | $this->create_tabs(); |
| 77 | 77 | } // End If Statement |
| 78 | 78 | } // End general_init() |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * @since 1.0.0 |
| 84 | 84 | * @return void |
| 85 | 85 | */ |
| 86 | - public function init_sections () { |
|
| 86 | + public function init_sections() { |
|
| 87 | 87 | // Override this function in your class and assign the array of sections to $this->sections. |
| 88 | - _e( 'Override init_sections() in your class.', 'woothemes-sensei' ); |
|
| 88 | + _e('Override init_sections() in your class.', 'woothemes-sensei'); |
|
| 89 | 89 | } // End init_sections() |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @since 1.0.0 |
| 95 | 95 | * @return void |
| 96 | 96 | */ |
| 97 | - public function init_fields () { |
|
| 97 | + public function init_fields() { |
|
| 98 | 98 | // Override this function in your class and assign the array of sections to $this->fields. |
| 99 | - _e( 'Override init_fields() in your class.', 'woothemes-sensei' ); |
|
| 99 | + _e('Override init_fields() in your class.', 'woothemes-sensei'); |
|
| 100 | 100 | } // End init_fields() |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,33 +105,33 @@ discard block |
||
| 105 | 105 | * @since 1.1.0 |
| 106 | 106 | * @return void |
| 107 | 107 | */ |
| 108 | - public function settings_tabs () { |
|
| 109 | - if ( ! $this->has_tabs ) { return; } |
|
| 108 | + public function settings_tabs() { |
|
| 109 | + if ( ! $this->has_tabs) { return; } |
|
| 110 | 110 | |
| 111 | - if ( count( $this->tabs ) > 0 ) { |
|
| 111 | + if (count($this->tabs) > 0) { |
|
| 112 | 112 | $html = ''; |
| 113 | 113 | |
| 114 | - $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n"; |
|
| 114 | + $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n"; |
|
| 115 | 115 | |
| 116 | 116 | $sections = array( |
| 117 | - 'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' ) |
|
| 117 | + 'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab') |
|
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | - foreach ( $this->tabs as $k => $v ) { |
|
| 121 | - $sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' ); |
|
| 120 | + foreach ($this->tabs as $k => $v) { |
|
| 121 | + $sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab'); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $count = 1; |
| 125 | - foreach ( $sections as $k => $v ) { |
|
| 125 | + foreach ($sections as $k => $v) { |
|
| 126 | 126 | $count++; |
| 127 | - $html .= '<li><a href="' . $v['href'] . '"'; |
|
| 128 | - if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; } |
|
| 129 | - $html .= '>' . esc_attr( $v['name'] ) . '</a>'; |
|
| 130 | - if ( $count <= count( $sections ) ) { $html .= ' | '; } |
|
| 131 | - $html .= '</li>' . "\n"; |
|
| 127 | + $html .= '<li><a href="'.$v['href'].'"'; |
|
| 128 | + if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; } |
|
| 129 | + $html .= '>'.esc_attr($v['name']).'</a>'; |
|
| 130 | + if ($count <= count($sections)) { $html .= ' | '; } |
|
| 131 | + $html .= '</li>'."\n"; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $html .= '</ul><div class="clear"></div>' . "\n"; |
|
| 134 | + $html .= '</ul><div class="clear"></div>'."\n"; |
|
| 135 | 135 | |
| 136 | 136 | echo $html; |
| 137 | 137 | } |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * @since 1.1.0 |
| 144 | 144 | * @return void |
| 145 | 145 | */ |
| 146 | - private function create_tabs () { |
|
| 147 | - if ( count( $this->sections ) > 0 ) { |
|
| 146 | + private function create_tabs() { |
|
| 147 | + if (count($this->sections) > 0) { |
|
| 148 | 148 | $tabs = array(); |
| 149 | - foreach ( $this->sections as $k => $v ) { |
|
| 149 | + foreach ($this->sections as $k => $v) { |
|
| 150 | 150 | $tabs[$k] = $v; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | * @since 1.0.0 |
| 161 | 161 | * @return void |
| 162 | 162 | */ |
| 163 | - public function create_sections () { |
|
| 164 | - if ( count( $this->sections ) > 0 ) { |
|
| 165 | - foreach ( $this->sections as $k => $v ) { |
|
| 166 | - add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token ); |
|
| 163 | + public function create_sections() { |
|
| 164 | + if (count($this->sections) > 0) { |
|
| 165 | + foreach ($this->sections as $k => $v) { |
|
| 166 | + add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } // End create_sections() |
@@ -174,18 +174,18 @@ discard block |
||
| 174 | 174 | * @since 1.0.0 |
| 175 | 175 | * @return void |
| 176 | 176 | */ |
| 177 | - public function create_fields () { |
|
| 178 | - if ( count( $this->sections ) > 0 ) { |
|
| 177 | + public function create_fields() { |
|
| 178 | + if (count($this->sections) > 0) { |
|
| 179 | 179 | // $this->parse_fields( $this->fields ); |
| 180 | 180 | |
| 181 | - foreach ( $this->fields as $k => $v ) { |
|
| 182 | - $method = $this->determine_method( $v, 'form' ); |
|
| 181 | + foreach ($this->fields as $k => $v) { |
|
| 182 | + $method = $this->determine_method($v, 'form'); |
|
| 183 | 183 | $name = $v['name']; |
| 184 | - if ( $v['type'] == 'info' ) { $name = ''; } |
|
| 185 | - add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) ); |
|
| 184 | + if ($v['type'] == 'info') { $name = ''; } |
|
| 185 | + add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v)); |
|
| 186 | 186 | |
| 187 | 187 | // Let the API know that we have a colourpicker field. |
| 188 | - if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; } |
|
| 188 | + if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; } |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } // End create_fields() |
@@ -197,43 +197,43 @@ discard block |
||
| 197 | 197 | * @param array $data |
| 198 | 198 | * @return callable, array or string |
| 199 | 199 | */ |
| 200 | - protected function determine_method ( $data, $type = 'form' ) { |
|
| 200 | + protected function determine_method($data, $type = 'form') { |
|
| 201 | 201 | $method = ''; |
| 202 | 202 | |
| 203 | - if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; } |
|
| 203 | + if ( ! in_array($type, array('form', 'validate', 'check'))) { return; } |
|
| 204 | 204 | |
| 205 | 205 | // Check for custom functions. |
| 206 | - if ( isset( $data[$type] ) ) { |
|
| 207 | - if ( function_exists( $data[$type] ) ) { |
|
| 206 | + if (isset($data[$type])) { |
|
| 207 | + if (function_exists($data[$type])) { |
|
| 208 | 208 | $method = $data[$type]; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( $method == '' && method_exists( $this, $data[$type] ) ) { |
|
| 212 | - if ( $type == 'form' ) { |
|
| 213 | - $method = array( $this, $data[$type] ); |
|
| 211 | + if ($method == '' && method_exists($this, $data[$type])) { |
|
| 212 | + if ($type == 'form') { |
|
| 213 | + $method = array($this, $data[$type]); |
|
| 214 | 214 | } else { |
| 215 | 215 | $method = $data[$type]; |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) { |
|
| 221 | - if ( $type == 'form' ) { |
|
| 222 | - $method = array( $this, $type . '_field_' . $data['type'] ); |
|
| 220 | + if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) { |
|
| 221 | + if ($type == 'form') { |
|
| 222 | + $method = array($this, $type.'_field_'.$data['type']); |
|
| 223 | 223 | } else { |
| 224 | - $method = $type . '_field_' . $data['type']; |
|
| 224 | + $method = $type.'_field_'.$data['type']; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) { |
|
| 229 | - $method = $this->token . '_' . $type . '_field_' . $data['type']; |
|
| 228 | + if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) { |
|
| 229 | + $method = $this->token.'_'.$type.'_field_'.$data['type']; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( $method == '' ) { |
|
| 233 | - if ( $type == 'form' ) { |
|
| 234 | - $method = array( $this, $type . '_field_text' ); |
|
| 232 | + if ($method == '') { |
|
| 233 | + if ($type == 'form') { |
|
| 234 | + $method = array($this, $type.'_field_text'); |
|
| 235 | 235 | } else { |
| 236 | - $method = $type . '_field_text'; |
|
| 236 | + $method = $type.'_field_text'; |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | * @param array $fields |
| 248 | 248 | * @return void |
| 249 | 249 | */ |
| 250 | - public function parse_fields ( $fields ) { |
|
| 251 | - foreach ( $fields as $k => $v ) { |
|
| 252 | - if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) { |
|
| 253 | - if ( ! isset( $this->sections[$v['section']]['fields'] ) ) { |
|
| 250 | + public function parse_fields($fields) { |
|
| 251 | + foreach ($fields as $k => $v) { |
|
| 252 | + if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) { |
|
| 253 | + if ( ! isset($this->sections[$v['section']]['fields'])) { |
|
| 254 | 254 | $this->sections[$v['section']]['fields'] = array(); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -267,19 +267,19 @@ discard block |
||
| 267 | 267 | * @since 1.0.0 |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public function register_settings_screen () { |
|
| 270 | + public function register_settings_screen() { |
|
| 271 | 271 | |
| 272 | 272 | |
| 273 | - if ( current_user_can( 'manage_sensei' ) ) { |
|
| 274 | - $hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) ); |
|
| 273 | + if (current_user_can('manage_sensei')) { |
|
| 274 | + $hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen')); |
|
| 275 | 275 | |
| 276 | 276 | $this->hook = $hook; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
| 280 | - add_action( 'admin_notices', array( $this, 'settings_errors' ) ); |
|
| 281 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 282 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
| 279 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
| 280 | + add_action('admin_notices', array($this, 'settings_errors')); |
|
| 281 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
| 282 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
| 283 | 283 | } |
| 284 | 284 | } // End register_settings_screen() |
| 285 | 285 | |
@@ -289,21 +289,21 @@ discard block |
||
| 289 | 289 | * @since 1.0.0 |
| 290 | 290 | * @return void |
| 291 | 291 | */ |
| 292 | - public function settings_screen () { |
|
| 292 | + public function settings_screen() { |
|
| 293 | 293 | |
| 294 | 294 | ?> |
| 295 | -<div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"> |
|
| 296 | - <?php screen_icon( 'woothemes-sensei' ); ?> |
|
| 297 | - <h2><?php echo esc_html( $this->name ); ?><?php if ( '' != $this->settings_version ) { echo ' <span class="version">' . $this->settings_version . '</span>'; } ?></h2> |
|
| 298 | - <p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
| 299 | - <?php do_action( 'settings_before_form' ); ?> |
|
| 295 | +<div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"> |
|
| 296 | + <?php screen_icon('woothemes-sensei'); ?> |
|
| 297 | + <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { echo ' <span class="version">'.$this->settings_version.'</span>'; } ?></h2> |
|
| 298 | + <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
| 299 | + <?php do_action('settings_before_form'); ?> |
|
| 300 | 300 | <form action="options.php" method="post"> |
| 301 | 301 | <?php $this->settings_tabs(); ?> |
| 302 | - <?php settings_fields( $this->token ); ?> |
|
| 303 | - <?php do_settings_sections( $this->token ); ?> |
|
| 302 | + <?php settings_fields($this->token); ?> |
|
| 303 | + <?php do_settings_sections($this->token); ?> |
|
| 304 | 304 | <?php submit_button(); ?> |
| 305 | 305 | </form> |
| 306 | - <?php do_action( 'settings_after_form' ); ?> |
|
| 306 | + <?php do_action('settings_after_form'); ?> |
|
| 307 | 307 | </div><!--/#woothemes-sensei--> |
| 308 | 308 | <?php |
| 309 | 309 | } // End settings_screen() |
@@ -314,16 +314,16 @@ discard block |
||
| 314 | 314 | * @since 1.0.0 |
| 315 | 315 | * @return void |
| 316 | 316 | */ |
| 317 | - public function get_settings () { |
|
| 318 | - if ( ! is_array( $this->settings ) ) { |
|
| 319 | - $this->settings = get_option( $this->token, array() ); |
|
| 317 | + public function get_settings() { |
|
| 318 | + if ( ! is_array($this->settings)) { |
|
| 319 | + $this->settings = get_option($this->token, array()); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - foreach ( $this->fields as $k => $v ) { |
|
| 323 | - if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) { |
|
| 322 | + foreach ($this->fields as $k => $v) { |
|
| 323 | + if ( ! isset($this->settings[$k]) && isset($v['default'])) { |
|
| 324 | 324 | $this->settings[$k] = $v['default']; |
| 325 | 325 | } |
| 326 | - if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) { |
|
| 326 | + if ($v['type'] == 'checkbox' && $this->settings[$k] != true) { |
|
| 327 | 327 | $this->settings[$k] = 0; |
| 328 | 328 | } |
| 329 | 329 | } |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | * @since 1.0.0 |
| 338 | 338 | * @return void |
| 339 | 339 | */ |
| 340 | - public function settings_fields () { |
|
| 341 | - register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) ); |
|
| 340 | + public function settings_fields() { |
|
| 341 | + register_setting($this->token, $this->token, array($this, 'validate_fields')); |
|
| 342 | 342 | $this->create_sections(); |
| 343 | 343 | $this->create_fields(); |
| 344 | 344 | } // End settings_fields() |
@@ -349,8 +349,8 @@ discard block |
||
| 349 | 349 | * @since 1.0.0 |
| 350 | 350 | * @return void |
| 351 | 351 | */ |
| 352 | - public function settings_errors () { |
|
| 353 | - echo settings_errors( $this->token . '-errors' ); |
|
| 352 | + public function settings_errors() { |
|
| 353 | + echo settings_errors($this->token.'-errors'); |
|
| 354 | 354 | } // End settings_errors() |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | * @since 1.0.0 |
| 360 | 360 | * @return void |
| 361 | 361 | */ |
| 362 | - public function section_description ( $section ) { |
|
| 363 | - if ( isset( $this->sections[$section['id']]['description'] ) ) { |
|
| 364 | - echo wpautop( $this->sections[$section['id']]['description'] ); |
|
| 362 | + public function section_description($section) { |
|
| 363 | + if (isset($this->sections[$section['id']]['description'])) { |
|
| 364 | + echo wpautop($this->sections[$section['id']]['description']); |
|
| 365 | 365 | } |
| 366 | 366 | } // End section_description_main() |
| 367 | 367 | |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | * @param array $args |
| 373 | 373 | * @return void |
| 374 | 374 | */ |
| 375 | - public function form_field_text ( $args ) { |
|
| 375 | + public function form_field_text($args) { |
|
| 376 | 376 | $options = $this->get_settings(); |
| 377 | 377 | |
| 378 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 379 | - if ( isset( $args['data']['description'] ) ) { |
|
| 380 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 378 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 379 | + if (isset($args['data']['description'])) { |
|
| 380 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 381 | 381 | } |
| 382 | 382 | } // End form_field_text() |
| 383 | 383 | |
@@ -388,13 +388,13 @@ discard block |
||
| 388 | 388 | * @param array $args |
| 389 | 389 | * @return void |
| 390 | 390 | */ |
| 391 | - public function form_field_color ( $args ) { |
|
| 391 | + public function form_field_color($args) { |
|
| 392 | 392 | $options = $this->get_settings(); |
| 393 | 393 | |
| 394 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 394 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 395 | 395 | echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>'; |
| 396 | - if ( isset( $args['data']['description'] ) ) { |
|
| 397 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 396 | + if (isset($args['data']['description'])) { |
|
| 397 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 398 | 398 | } |
| 399 | 399 | } // End form_field_text() |
| 400 | 400 | |
@@ -405,22 +405,22 @@ discard block |
||
| 405 | 405 | * @param array $args |
| 406 | 406 | * @return void |
| 407 | 407 | */ |
| 408 | - public function form_field_checkbox ( $args ) { |
|
| 408 | + public function form_field_checkbox($args) { |
|
| 409 | 409 | $options = $this->get_settings(); |
| 410 | 410 | |
| 411 | 411 | $has_description = false; |
| 412 | - if ( isset( $args['data']['description'] ) ) { |
|
| 412 | + if (isset($args['data']['description'])) { |
|
| 413 | 413 | $has_description = true; |
| 414 | - echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n"; |
|
| 414 | + echo '<label for="'.esc_attr($args['key']).'">'."\n"; |
|
| 415 | 415 | } |
| 416 | - echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
|
| 417 | - if ( $has_description ) { |
|
| 418 | - echo wp_kses( $args['data']['description'], array( 'a' => array( |
|
| 416 | + echo '<input id="'.$args['key'].'" name="'.$this->token.'['.esc_attr($args['key']).']" type="checkbox" value="1"'.checked(esc_attr($options[$args['key']]), '1', false).' />'."\n"; |
|
| 417 | + if ($has_description) { |
|
| 418 | + echo wp_kses($args['data']['description'], array('a' => array( |
|
| 419 | 419 | 'href' => array(), |
| 420 | 420 | 'title' => array() |
| 421 | 421 | ) |
| 422 | 422 | ) |
| 423 | - ) . '</label>' . "\n"; |
|
| 423 | + ).'</label>'."\n"; |
|
| 424 | 424 | } |
| 425 | 425 | } // End form_field_checkbox() |
| 426 | 426 | |
@@ -431,12 +431,12 @@ discard block |
||
| 431 | 431 | * @param array $args |
| 432 | 432 | * @return void |
| 433 | 433 | */ |
| 434 | - public function form_field_textarea ( $args ) { |
|
| 434 | + public function form_field_textarea($args) { |
|
| 435 | 435 | $options = $this->get_settings(); |
| 436 | 436 | |
| 437 | - echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n"; |
|
| 438 | - if ( isset( $args['data']['description'] ) ) { |
|
| 439 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 437 | + echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n"; |
|
| 438 | + if (isset($args['data']['description'])) { |
|
| 439 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 440 | 440 | } |
| 441 | 441 | } // End form_field_textarea() |
| 442 | 442 | |
@@ -447,20 +447,20 @@ discard block |
||
| 447 | 447 | * @param array $args |
| 448 | 448 | * @return void |
| 449 | 449 | */ |
| 450 | - public function form_field_select ( $args ) { |
|
| 450 | + public function form_field_select($args) { |
|
| 451 | 451 | $options = $this->get_settings(); |
| 452 | 452 | |
| 453 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 453 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 454 | 454 | $html = ''; |
| 455 | - $html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n"; |
|
| 456 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 457 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 455 | + $html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n"; |
|
| 456 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 457 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 458 | 458 | } |
| 459 | - $html .= '</select>' . "\n"; |
|
| 459 | + $html .= '</select>'."\n"; |
|
| 460 | 460 | echo $html; |
| 461 | 461 | |
| 462 | - if ( isset( $args['data']['description'] ) ) { |
|
| 463 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 462 | + if (isset($args['data']['description'])) { |
|
| 463 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | } // End form_field_select() |
@@ -472,18 +472,18 @@ discard block |
||
| 472 | 472 | * @param array $args |
| 473 | 473 | * @return void |
| 474 | 474 | */ |
| 475 | - public function form_field_radio ( $args ) { |
|
| 475 | + public function form_field_radio($args) { |
|
| 476 | 476 | $options = $this->get_settings(); |
| 477 | 477 | |
| 478 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 478 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 479 | 479 | $html = ''; |
| 480 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 481 | - $html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 480 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 481 | + $html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 482 | 482 | } |
| 483 | 483 | echo $html; |
| 484 | 484 | |
| 485 | - if ( isset( $args['data']['description'] ) ) { |
|
| 486 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 485 | + if (isset($args['data']['description'])) { |
|
| 486 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } // End form_field_radio() |
@@ -495,28 +495,28 @@ discard block |
||
| 495 | 495 | * @param array $args |
| 496 | 496 | * @return void |
| 497 | 497 | */ |
| 498 | - public function form_field_multicheck ( $args ) { |
|
| 498 | + public function form_field_multicheck($args) { |
|
| 499 | 499 | $options = $this->get_settings(); |
| 500 | 500 | |
| 501 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 502 | - $html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n"; |
|
| 503 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 501 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 502 | + $html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n"; |
|
| 503 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 504 | 504 | $checked = ''; |
| 505 | 505 | |
| 506 | - if( isset( $options[ $args['key'] ] ) ) { |
|
| 507 | - if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; } |
|
| 506 | + if (isset($options[$args['key']])) { |
|
| 507 | + if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; } |
|
| 508 | 508 | } else { |
| 509 | - if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; } |
|
| 509 | + if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; } |
|
| 510 | 510 | } |
| 511 | - $html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n"; |
|
| 512 | - $html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n"; |
|
| 513 | - $html .= '</label><br />' . "\n"; |
|
| 511 | + $html .= '<label for="checkbox-'.esc_attr($k).'">'."\n"; |
|
| 512 | + $html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n"; |
|
| 513 | + $html .= '</label><br />'."\n"; |
|
| 514 | 514 | } |
| 515 | - $html .= '</div>' . "\n"; |
|
| 515 | + $html .= '</div>'."\n"; |
|
| 516 | 516 | echo $html; |
| 517 | 517 | |
| 518 | - if ( isset( $args['data']['description'] ) ) { |
|
| 519 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 518 | + if (isset($args['data']['description'])) { |
|
| 519 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | } // End form_field_multicheck() |
@@ -528,20 +528,20 @@ discard block |
||
| 528 | 528 | * @param array $args |
| 529 | 529 | * @return void |
| 530 | 530 | */ |
| 531 | - public function form_field_range ( $args ) { |
|
| 531 | + public function form_field_range($args) { |
|
| 532 | 532 | $options = $this->get_settings(); |
| 533 | 533 | |
| 534 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 534 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 535 | 535 | $html = ''; |
| 536 | - $html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n"; |
|
| 537 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 538 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 536 | + $html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n"; |
|
| 537 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 538 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 539 | 539 | } |
| 540 | - $html .= '</select>' . "\n"; |
|
| 540 | + $html .= '</select>'."\n"; |
|
| 541 | 541 | echo $html; |
| 542 | 542 | |
| 543 | - if ( isset( $args['data']['description'] ) ) { |
|
| 544 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 543 | + if (isset($args['data']['description'])) { |
|
| 544 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 545 | 545 | } |
| 546 | 546 | } |
| 547 | 547 | } // End form_field_range() |
@@ -553,18 +553,18 @@ discard block |
||
| 553 | 553 | * @param array $args |
| 554 | 554 | * @return void |
| 555 | 555 | */ |
| 556 | - public function form_field_images ( $args ) { |
|
| 556 | + public function form_field_images($args) { |
|
| 557 | 557 | $options = $this->get_settings(); |
| 558 | 558 | |
| 559 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 559 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 560 | 560 | $html = ''; |
| 561 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 562 | - $html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 561 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 562 | + $html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 563 | 563 | } |
| 564 | 564 | echo $html; |
| 565 | 565 | |
| 566 | - if ( isset( $args['data']['description'] ) ) { |
|
| 567 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 566 | + if (isset($args['data']['description'])) { |
|
| 567 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | } // End form_field_images() |
@@ -576,19 +576,19 @@ discard block |
||
| 576 | 576 | * @param array $args |
| 577 | 577 | * @return void |
| 578 | 578 | */ |
| 579 | - public function form_field_info ( $args ) { |
|
| 579 | + public function form_field_info($args) { |
|
| 580 | 580 | $class = ''; |
| 581 | - if ( isset( $args['data']['class'] ) ) { |
|
| 582 | - $class = ' ' . esc_attr( $args['data']['class'] ); |
|
| 581 | + if (isset($args['data']['class'])) { |
|
| 582 | + $class = ' '.esc_attr($args['data']['class']); |
|
| 583 | 583 | } |
| 584 | - $html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n"; |
|
| 585 | - if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) { |
|
| 586 | - $html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n"; |
|
| 584 | + $html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n"; |
|
| 585 | + if (isset($args['data']['name']) && ($args['data']['name'] != '')) { |
|
| 586 | + $html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n"; |
|
| 587 | 587 | } |
| 588 | - if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) { |
|
| 589 | - $html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n"; |
|
| 588 | + if (isset($args['data']['description']) && ($args['data']['description'] != '')) { |
|
| 589 | + $html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n"; |
|
| 590 | 590 | } |
| 591 | - $html .= '</div>' . "\n"; |
|
| 591 | + $html .= '</div>'."\n"; |
|
| 592 | 592 | |
| 593 | 593 | echo $html; |
| 594 | 594 | } // End form_field_info() |
@@ -600,14 +600,14 @@ discard block |
||
| 600 | 600 | * @since 1.9.0 |
| 601 | 601 | * @param array $args |
| 602 | 602 | */ |
| 603 | - public function form_field_button( $args ) { |
|
| 603 | + public function form_field_button($args) { |
|
| 604 | 604 | $options = $this->get_settings(); |
| 605 | 605 | |
| 606 | - if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) { |
|
| 607 | - printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) ); |
|
| 606 | + if (isset($args['data']['target']) && isset($args['data']['label'])) { |
|
| 607 | + printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label'])); |
|
| 608 | 608 | |
| 609 | - if ( isset( $args['data']['description'] ) ) { |
|
| 610 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 609 | + if (isset($args['data']['description'])) { |
|
| 610 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | 613 | } // End form_field_button() |
@@ -621,23 +621,23 @@ discard block |
||
| 621 | 621 | * @uses $this->parse_errors() |
| 622 | 622 | * @return array $options |
| 623 | 623 | */ |
| 624 | - public function validate_fields ( $input ) { |
|
| 624 | + public function validate_fields($input) { |
|
| 625 | 625 | $options = $this->get_settings(); |
| 626 | 626 | |
| 627 | - foreach ( $this->fields as $k => $v ) { |
|
| 627 | + foreach ($this->fields as $k => $v) { |
|
| 628 | 628 | // Make sure checkboxes are present even when false. |
| 629 | - if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 630 | - if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 629 | + if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 630 | + if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 631 | 631 | |
| 632 | - if ( isset( $input[$k] ) ) { |
|
| 632 | + if (isset($input[$k])) { |
|
| 633 | 633 | // Perform checks on required fields. |
| 634 | - if ( isset( $v['required'] ) && ( $v['required'] == true ) ) { |
|
| 635 | - if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) { |
|
| 636 | - $this->add_error( $k, $v ); |
|
| 634 | + if (isset($v['required']) && ($v['required'] == true)) { |
|
| 635 | + if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) { |
|
| 636 | + $this->add_error($k, $v); |
|
| 637 | 637 | continue; |
| 638 | 638 | } else { |
| 639 | - if ( $input[$k] == '' ) { |
|
| 640 | - $this->add_error( $k, $v ); |
|
| 639 | + if ($input[$k] == '') { |
|
| 640 | + $this->add_error($k, $v); |
|
| 641 | 641 | continue; |
| 642 | 642 | } |
| 643 | 643 | } |
@@ -646,28 +646,28 @@ discard block |
||
| 646 | 646 | $value = $input[$k]; |
| 647 | 647 | |
| 648 | 648 | // Check if the field is valid. |
| 649 | - $method = $this->determine_method( $v, 'check' ); |
|
| 649 | + $method = $this->determine_method($v, 'check'); |
|
| 650 | 650 | |
| 651 | - if ( function_exists ( $method ) ) { |
|
| 652 | - $is_valid = $method( $value ); |
|
| 651 | + if (function_exists($method)) { |
|
| 652 | + $is_valid = $method($value); |
|
| 653 | 653 | } else { |
| 654 | - if ( method_exists( $this, $method ) ) { |
|
| 655 | - $is_valid = $this->$method( $value ); |
|
| 654 | + if (method_exists($this, $method)) { |
|
| 655 | + $is_valid = $this->$method($value); |
|
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - if ( ! $is_valid ) { |
|
| 660 | - $this->add_error( $k, $v ); |
|
| 659 | + if ( ! $is_valid) { |
|
| 660 | + $this->add_error($k, $v); |
|
| 661 | 661 | continue; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - $method = $this->determine_method( $v, 'validate' ); |
|
| 664 | + $method = $this->determine_method($v, 'validate'); |
|
| 665 | 665 | |
| 666 | - if ( function_exists ( $method ) ) { |
|
| 667 | - $options[$k] = $method( $value ); |
|
| 666 | + if (function_exists($method)) { |
|
| 667 | + $options[$k] = $method($value); |
|
| 668 | 668 | } else { |
| 669 | - if ( method_exists( $this, $method ) ) { |
|
| 670 | - $options[$k] = $this->$method( $value ); |
|
| 669 | + if (method_exists($this, $method)) { |
|
| 670 | + $options[$k] = $this->$method($value); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | } |
@@ -685,8 +685,8 @@ discard block |
||
| 685 | 685 | * @param string $input |
| 686 | 686 | * @return string |
| 687 | 687 | */ |
| 688 | - public function validate_field_text ( $input ) { |
|
| 689 | - return trim( esc_attr( $input ) ); |
|
| 688 | + public function validate_field_text($input) { |
|
| 689 | + return trim(esc_attr($input)); |
|
| 690 | 690 | } // End validate_field_text() |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -696,11 +696,11 @@ discard block |
||
| 696 | 696 | * @param string $input |
| 697 | 697 | * @return string |
| 698 | 698 | */ |
| 699 | - public function validate_field_checkbox ( $input ) { |
|
| 700 | - if ( ! isset( $input ) ) { |
|
| 699 | + public function validate_field_checkbox($input) { |
|
| 700 | + if ( ! isset($input)) { |
|
| 701 | 701 | return 0; |
| 702 | 702 | } else { |
| 703 | - return (bool)$input; |
|
| 703 | + return (bool) $input; |
|
| 704 | 704 | } |
| 705 | 705 | } // End validate_field_checkbox() |
| 706 | 706 | |
@@ -711,10 +711,10 @@ discard block |
||
| 711 | 711 | * @param string $input |
| 712 | 712 | * @return string |
| 713 | 713 | */ |
| 714 | - public function validate_field_multicheck ( $input ) { |
|
| 714 | + public function validate_field_multicheck($input) { |
|
| 715 | 715 | $input = (array) $input; |
| 716 | 716 | |
| 717 | - $input = array_map( 'esc_attr', $input ); |
|
| 717 | + $input = array_map('esc_attr', $input); |
|
| 718 | 718 | |
| 719 | 719 | return $input; |
| 720 | 720 | } // End validate_field_multicheck() |
@@ -726,8 +726,8 @@ discard block |
||
| 726 | 726 | * @param string $input |
| 727 | 727 | * @return string |
| 728 | 728 | */ |
| 729 | - public function validate_field_range ( $input ) { |
|
| 730 | - $input = number_format( floatval( $input ), 0 ); |
|
| 729 | + public function validate_field_range($input) { |
|
| 730 | + $input = number_format(floatval($input), 0); |
|
| 731 | 731 | |
| 732 | 732 | return $input; |
| 733 | 733 | } // End validate_field_range() |
@@ -739,8 +739,8 @@ discard block |
||
| 739 | 739 | * @param string $input |
| 740 | 740 | * @return string |
| 741 | 741 | */ |
| 742 | - public function validate_field_url ( $input ) { |
|
| 743 | - return trim( esc_url( $input ) ); |
|
| 742 | + public function validate_field_url($input) { |
|
| 743 | + return trim(esc_url($input)); |
|
| 744 | 744 | } // End validate_field_url() |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @since 1.1.0 |
| 750 | 750 | * @return boolean Is the value valid? |
| 751 | 751 | */ |
| 752 | - public function check_field_text ( $input ) { |
|
| 752 | + public function check_field_text($input) { |
|
| 753 | 753 | $is_valid = true; |
| 754 | 754 | |
| 755 | 755 | return $is_valid; |
@@ -763,11 +763,11 @@ discard block |
||
| 763 | 763 | * @param array $data |
| 764 | 764 | * @return void |
| 765 | 765 | */ |
| 766 | - protected function add_error ( $key, $data ) { |
|
| 767 | - if ( isset( $data['error_message'] ) ) { |
|
| 766 | + protected function add_error($key, $data) { |
|
| 767 | + if (isset($data['error_message'])) { |
|
| 768 | 768 | $message = $data['error_message']; |
| 769 | 769 | } else { |
| 770 | - $message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] ); |
|
| 770 | + $message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']); |
|
| 771 | 771 | } |
| 772 | 772 | $this->errors[$key] = $message; |
| 773 | 773 | } // End add_error() |
@@ -778,14 +778,14 @@ discard block |
||
| 778 | 778 | * @since 1.0.0 |
| 779 | 779 | * @return void |
| 780 | 780 | */ |
| 781 | - protected function parse_errors () { |
|
| 782 | - if ( count ( $this->errors ) > 0 ) { |
|
| 783 | - foreach ( $this->errors as $k => $v ) { |
|
| 784 | - add_settings_error( $this->token . '-errors', $k, $v, 'error' ); |
|
| 781 | + protected function parse_errors() { |
|
| 782 | + if (count($this->errors) > 0) { |
|
| 783 | + foreach ($this->errors as $k => $v) { |
|
| 784 | + add_settings_error($this->token.'-errors', $k, $v, 'error'); |
|
| 785 | 785 | } |
| 786 | 786 | } else { |
| 787 | - $message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name ); |
|
| 788 | - add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' ); |
|
| 787 | + $message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name); |
|
| 788 | + add_settings_error($this->token.'-errors', $this->token, $message, 'updated'); |
|
| 789 | 789 | } |
| 790 | 790 | } // End parse_errors() |
| 791 | 791 | |
@@ -795,8 +795,8 @@ discard block |
||
| 795 | 795 | * @since 1.0.0 |
| 796 | 796 | * @return void |
| 797 | 797 | */ |
| 798 | - protected function get_array_field_types () { |
|
| 799 | - return array( 'multicheck' ); |
|
| 798 | + protected function get_array_field_types() { |
|
| 799 | + return array('multicheck'); |
|
| 800 | 800 | } // End get_array_field_types() |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -805,22 +805,22 @@ discard block |
||
| 805 | 805 | * @since 1.0.0 |
| 806 | 806 | * @return void |
| 807 | 807 | */ |
| 808 | - public function enqueue_scripts () { |
|
| 808 | + public function enqueue_scripts() { |
|
| 809 | 809 | |
| 810 | 810 | |
| 811 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 811 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 812 | 812 | |
| 813 | - wp_enqueue_script( 'farbtastic' ); |
|
| 814 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version ); |
|
| 813 | + wp_enqueue_script('farbtastic'); |
|
| 814 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version); |
|
| 815 | 815 | |
| 816 | - if ( $this->has_range ) { |
|
| 817 | - wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version ); |
|
| 816 | + if ($this->has_range) { |
|
| 817 | + wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version ); |
|
| 820 | + wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version); |
|
| 821 | 821 | |
| 822 | - if ( $this->has_imageselector ) { |
|
| 823 | - wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' ); |
|
| 822 | + if ($this->has_imageselector) { |
|
| 823 | + wp_enqueue_script('woothemes-sensei-settings-imageselectors'); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | } // End enqueue_scripts() |
@@ -831,12 +831,12 @@ discard block |
||
| 831 | 831 | * @since 1.0.0 |
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | - public function enqueue_styles () { |
|
| 834 | + public function enqueue_styles() { |
|
| 835 | 835 | |
| 836 | - wp_enqueue_style( Sensei()->token . '-admin' ); |
|
| 836 | + wp_enqueue_style(Sensei()->token.'-admin'); |
|
| 837 | 837 | |
| 838 | - wp_enqueue_style( 'farbtastic' ); |
|
| 839 | - wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version ); |
|
| 838 | + wp_enqueue_style('farbtastic'); |
|
| 839 | + wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version); |
|
| 840 | 840 | |
| 841 | 841 | $this->enqueue_field_styles(); |
| 842 | 842 | } // End enqueue_styles() |
@@ -847,17 +847,17 @@ discard block |
||
| 847 | 847 | * @since 1.0.0 |
| 848 | 848 | * @return void |
| 849 | 849 | */ |
| 850 | - public function enqueue_field_styles () { |
|
| 850 | + public function enqueue_field_styles() { |
|
| 851 | 851 | |
| 852 | 852 | |
| 853 | - if ( $this->has_range ) { |
|
| 854 | - wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version ); |
|
| 853 | + if ($this->has_range) { |
|
| 854 | + wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | - wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version ); |
|
| 857 | + wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version); |
|
| 858 | 858 | |
| 859 | - if ( $this->has_imageselector ) { |
|
| 860 | - wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' ); |
|
| 859 | + if ($this->has_imageselector) { |
|
| 860 | + wp_enqueue_style('woothemes-sensei-settings-imageselectors'); |
|
| 861 | 861 | } |
| 862 | 862 | } // End enqueue_field_styles() |
| 863 | 863 | } // End Class |
@@ -867,4 +867,4 @@ discard block |
||
| 867 | 867 | * for backward compatibility |
| 868 | 868 | * @since 1.9.0 |
| 869 | 869 | */ |
| 870 | -class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{} |
|
| 870 | +class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {} |
|
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @param $course_id |
| 365 | 365 | * @param $new_teacher_id |
| 366 | - * @return void |
|
| 366 | + * @return false|null |
|
| 367 | 367 | */ |
| 368 | 368 | public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
| 369 | 369 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | * @since 1.8.0 |
| 455 | 455 | * @access public |
| 456 | 456 | * @parameters |
| 457 | - * @return array $users user id array |
|
| 457 | + * @return boolean $users user id array |
|
| 458 | 458 | */ |
| 459 | 459 | public function update_course_lessons_author ( $course_id, $new_author ){ |
| 460 | 460 | |
@@ -843,8 +843,7 @@ discard block |
||
| 843 | 843 | * This function hooks into wp_insert_post |
| 844 | 844 | * |
| 845 | 845 | * @since 1.8.0 |
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 846 | + * @return false|null |
|
| 848 | 847 | */ |
| 849 | 848 | public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
| 850 | 849 | |
@@ -14,251 +14,251 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Teacher { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * $teacher_role |
|
| 19 | - * |
|
| 20 | - * Keeps a reference to the teacher role object |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @since 1.8.0 |
|
| 24 | - */ |
|
| 25 | - protected $teacher_role; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $token |
|
| 29 | - * |
|
| 30 | - * Keeps a reference to the global sensei token |
|
| 31 | - * |
|
| 32 | - * @access protected |
|
| 33 | - * @since 1.8.0 |
|
| 34 | - */ |
|
| 35 | - public $token; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Sensei_Teacher::__constructor |
|
| 39 | - * |
|
| 40 | - * Constructor Function |
|
| 41 | - * |
|
| 42 | - * @since 1.8.0 |
|
| 43 | - * @access public |
|
| 44 | - */ |
|
| 45 | - public function __construct ( ) { |
|
| 46 | - |
|
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | - |
|
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | - |
|
| 55 | - //filter the quiz submissions |
|
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | - |
|
| 58 | - //grading totals count only those belonging to the teacher |
|
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | - |
|
| 61 | - // show the courses owned by a user on his author archive page |
|
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | - |
|
| 64 | - // notify admin when a teacher creates a course |
|
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | - |
|
| 67 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | - |
|
| 70 | - // give teacher access to question post type |
|
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | - |
|
| 73 | - // Teacher column on the courses list on the admin edit screen |
|
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | - |
|
| 77 | - //admin edit messages query limit teacher |
|
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | - |
|
| 80 | - //add filter by teacher on courses list |
|
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | - |
|
| 84 | - // Handle media library restrictions |
|
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | - |
|
| 88 | - // update lesson owner to course teacher when saved |
|
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | - |
|
| 91 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - } // end __constructor() |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Sensei_Teacher::create_teacher_role |
|
| 103 | - * |
|
| 104 | - * This function checks if the role exist, if not it creates it. |
|
| 105 | - * for the teacher role |
|
| 106 | - * |
|
| 107 | - * @since 1.8.0 |
|
| 108 | - * @access public |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function create_role ( ) { |
|
| 112 | - |
|
| 113 | - // check if the role exists |
|
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | - |
|
| 116 | - // if the the teacher is not a valid WordPress role create it |
|
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | - // create the role |
|
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // add the capabilities before returning |
|
| 123 | - $this->add_capabilities(); |
|
| 124 | - |
|
| 125 | - }// end create_teacher_role |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Sensei_Teacher::add_capabilities |
|
| 129 | - * |
|
| 130 | - * @since 1.8.0 |
|
| 131 | - * @access protected |
|
| 132 | - */ |
|
| 133 | - protected function add_capabilities ( ) { |
|
| 134 | - |
|
| 135 | - // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Sensei teachers capabilities array filter |
|
| 142 | - * |
|
| 143 | - * These capabilities will be applied to the teacher role |
|
| 144 | - * @param array $capabilities |
|
| 145 | - * keys: (string) $cap_name => (bool) $grant |
|
| 146 | - */ |
|
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | - // General access rules |
|
| 149 | - 'read' => true, |
|
| 150 | - 'manage_sensei_grades' => true, |
|
| 151 | - 'moderate_comments'=> true, |
|
| 152 | - 'upload_files' => true, |
|
| 153 | - 'edit_files' => true, |
|
| 154 | - |
|
| 155 | - //Lessons |
|
| 156 | - 'publish_lessons' => true, |
|
| 157 | - 'manage_lesson_categories' => true, |
|
| 158 | - 'edit_lessons' => true, |
|
| 159 | - 'edit_published_lessons' => true, |
|
| 160 | - 'edit_private_lessons' => true, |
|
| 161 | - 'read_private_lessons' => true, |
|
| 162 | - 'delete_published_lessons' => true, |
|
| 163 | - |
|
| 164 | - // Courses |
|
| 165 | - 'create_courses' => true, |
|
| 166 | - 'publish_courses' => false, |
|
| 167 | - 'manage_course_categories' => true, |
|
| 168 | - 'edit_courses' => true, |
|
| 169 | - 'edit_published_courses' => true, |
|
| 170 | - 'edit_private_courses' => true, |
|
| 171 | - 'read_private_courses' => true, |
|
| 172 | - 'delete_published_courses' => true, |
|
| 173 | - |
|
| 174 | - // Quiz |
|
| 175 | - 'publish_quizzes' => true, |
|
| 176 | - 'edit_quizzes' => true, |
|
| 177 | - 'edit_published_quizzes' => true, |
|
| 178 | - 'edit_private_quizzes' => true, |
|
| 179 | - 'read_private_quizzes' => true, |
|
| 180 | - |
|
| 181 | - // Questions |
|
| 182 | - 'publish_questions' => true, |
|
| 183 | - 'edit_questions' => true, |
|
| 184 | - 'edit_published_questions' => true, |
|
| 185 | - 'edit_private_questions' => true, |
|
| 186 | - 'read_private_questions' => true, |
|
| 187 | - |
|
| 188 | - //messages |
|
| 189 | - 'publish_sensei_messages' => true, |
|
| 190 | - 'edit_sensei_messages' => true, |
|
| 191 | - 'edit_published_sensei_messages' => true, |
|
| 192 | - 'edit_private_sensei_messages' => true, |
|
| 193 | - 'read_private_sensei_messages' => true, |
|
| 194 | - |
|
| 195 | - // Comments - |
|
| 196 | - // Necessary cap so Teachers can moderate comments |
|
| 197 | - // on their own lessons. We restrict access to other |
|
| 198 | - // post types in $this->restrict_posts_menu_page() |
|
| 199 | - |
|
| 200 | - 'edit_posts' => true, |
|
| 201 | - |
|
| 202 | - )); |
|
| 203 | - |
|
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 205 | - |
|
| 206 | - // load the capability on to the teacher role |
|
| 207 | - $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | - |
|
| 209 | - } // end for each |
|
| 210 | - |
|
| 211 | - }// end add_cap |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Sensei_Teacher::teacher_meta_box |
|
| 215 | - * |
|
| 216 | - * Add the teacher metabox to the course post type edit screen |
|
| 217 | - * |
|
| 218 | - * @since 1.8.0 |
|
| 219 | - * @access public |
|
| 220 | - * @parameter string $post_type |
|
| 221 | - * @parameter WP_Post $post |
|
| 222 | - * @return void |
|
| 223 | - */ |
|
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | - |
|
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | - 'course', |
|
| 231 | - 'side', |
|
| 232 | - 'core' |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - } // end teacher_meta_box() |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | - * |
|
| 240 | - * Render the teacher meta box markup |
|
| 241 | - * |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - * @access public |
|
| 244 | - * @parameters |
|
| 245 | - */ |
|
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 247 | - |
|
| 248 | - // get the current author |
|
| 249 | - $current_author = $post->post_author; |
|
| 250 | - |
|
| 251 | - //get the users authorised to author courses |
|
| 252 | - $users = $this->get_teachers_and_authors(); |
|
| 253 | - |
|
| 254 | - ?> |
|
| 17 | + /** |
|
| 18 | + * $teacher_role |
|
| 19 | + * |
|
| 20 | + * Keeps a reference to the teacher role object |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @since 1.8.0 |
|
| 24 | + */ |
|
| 25 | + protected $teacher_role; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $token |
|
| 29 | + * |
|
| 30 | + * Keeps a reference to the global sensei token |
|
| 31 | + * |
|
| 32 | + * @access protected |
|
| 33 | + * @since 1.8.0 |
|
| 34 | + */ |
|
| 35 | + public $token; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Sensei_Teacher::__constructor |
|
| 39 | + * |
|
| 40 | + * Constructor Function |
|
| 41 | + * |
|
| 42 | + * @since 1.8.0 |
|
| 43 | + * @access public |
|
| 44 | + */ |
|
| 45 | + public function __construct ( ) { |
|
| 46 | + |
|
| 47 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | + |
|
| 53 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | + |
|
| 55 | + //filter the quiz submissions |
|
| 56 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | + |
|
| 58 | + //grading totals count only those belonging to the teacher |
|
| 59 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | + |
|
| 61 | + // show the courses owned by a user on his author archive page |
|
| 62 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | + |
|
| 64 | + // notify admin when a teacher creates a course |
|
| 65 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | + |
|
| 67 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | + |
|
| 70 | + // give teacher access to question post type |
|
| 71 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | + |
|
| 73 | + // Teacher column on the courses list on the admin edit screen |
|
| 74 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | + |
|
| 77 | + //admin edit messages query limit teacher |
|
| 78 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | + |
|
| 80 | + //add filter by teacher on courses list |
|
| 81 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | + |
|
| 84 | + // Handle media library restrictions |
|
| 85 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | + |
|
| 88 | + // update lesson owner to course teacher when saved |
|
| 89 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | + |
|
| 91 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + } // end __constructor() |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Sensei_Teacher::create_teacher_role |
|
| 103 | + * |
|
| 104 | + * This function checks if the role exist, if not it creates it. |
|
| 105 | + * for the teacher role |
|
| 106 | + * |
|
| 107 | + * @since 1.8.0 |
|
| 108 | + * @access public |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function create_role ( ) { |
|
| 112 | + |
|
| 113 | + // check if the role exists |
|
| 114 | + $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | + |
|
| 116 | + // if the the teacher is not a valid WordPress role create it |
|
| 117 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | + // create the role |
|
| 119 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // add the capabilities before returning |
|
| 123 | + $this->add_capabilities(); |
|
| 124 | + |
|
| 125 | + }// end create_teacher_role |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Sensei_Teacher::add_capabilities |
|
| 129 | + * |
|
| 130 | + * @since 1.8.0 |
|
| 131 | + * @access protected |
|
| 132 | + */ |
|
| 133 | + protected function add_capabilities ( ) { |
|
| 134 | + |
|
| 135 | + // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Sensei teachers capabilities array filter |
|
| 142 | + * |
|
| 143 | + * These capabilities will be applied to the teacher role |
|
| 144 | + * @param array $capabilities |
|
| 145 | + * keys: (string) $cap_name => (bool) $grant |
|
| 146 | + */ |
|
| 147 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | + // General access rules |
|
| 149 | + 'read' => true, |
|
| 150 | + 'manage_sensei_grades' => true, |
|
| 151 | + 'moderate_comments'=> true, |
|
| 152 | + 'upload_files' => true, |
|
| 153 | + 'edit_files' => true, |
|
| 154 | + |
|
| 155 | + //Lessons |
|
| 156 | + 'publish_lessons' => true, |
|
| 157 | + 'manage_lesson_categories' => true, |
|
| 158 | + 'edit_lessons' => true, |
|
| 159 | + 'edit_published_lessons' => true, |
|
| 160 | + 'edit_private_lessons' => true, |
|
| 161 | + 'read_private_lessons' => true, |
|
| 162 | + 'delete_published_lessons' => true, |
|
| 163 | + |
|
| 164 | + // Courses |
|
| 165 | + 'create_courses' => true, |
|
| 166 | + 'publish_courses' => false, |
|
| 167 | + 'manage_course_categories' => true, |
|
| 168 | + 'edit_courses' => true, |
|
| 169 | + 'edit_published_courses' => true, |
|
| 170 | + 'edit_private_courses' => true, |
|
| 171 | + 'read_private_courses' => true, |
|
| 172 | + 'delete_published_courses' => true, |
|
| 173 | + |
|
| 174 | + // Quiz |
|
| 175 | + 'publish_quizzes' => true, |
|
| 176 | + 'edit_quizzes' => true, |
|
| 177 | + 'edit_published_quizzes' => true, |
|
| 178 | + 'edit_private_quizzes' => true, |
|
| 179 | + 'read_private_quizzes' => true, |
|
| 180 | + |
|
| 181 | + // Questions |
|
| 182 | + 'publish_questions' => true, |
|
| 183 | + 'edit_questions' => true, |
|
| 184 | + 'edit_published_questions' => true, |
|
| 185 | + 'edit_private_questions' => true, |
|
| 186 | + 'read_private_questions' => true, |
|
| 187 | + |
|
| 188 | + //messages |
|
| 189 | + 'publish_sensei_messages' => true, |
|
| 190 | + 'edit_sensei_messages' => true, |
|
| 191 | + 'edit_published_sensei_messages' => true, |
|
| 192 | + 'edit_private_sensei_messages' => true, |
|
| 193 | + 'read_private_sensei_messages' => true, |
|
| 194 | + |
|
| 195 | + // Comments - |
|
| 196 | + // Necessary cap so Teachers can moderate comments |
|
| 197 | + // on their own lessons. We restrict access to other |
|
| 198 | + // post types in $this->restrict_posts_menu_page() |
|
| 199 | + |
|
| 200 | + 'edit_posts' => true, |
|
| 201 | + |
|
| 202 | + )); |
|
| 203 | + |
|
| 204 | + foreach ( $caps as $cap => $grant ) { |
|
| 205 | + |
|
| 206 | + // load the capability on to the teacher role |
|
| 207 | + $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | + |
|
| 209 | + } // end for each |
|
| 210 | + |
|
| 211 | + }// end add_cap |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Sensei_Teacher::teacher_meta_box |
|
| 215 | + * |
|
| 216 | + * Add the teacher metabox to the course post type edit screen |
|
| 217 | + * |
|
| 218 | + * @since 1.8.0 |
|
| 219 | + * @access public |
|
| 220 | + * @parameter string $post_type |
|
| 221 | + * @parameter WP_Post $post |
|
| 222 | + * @return void |
|
| 223 | + */ |
|
| 224 | + public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | + |
|
| 226 | + if( !current_user_can('manage_options') ){ |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | + 'course', |
|
| 231 | + 'side', |
|
| 232 | + 'core' |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + } // end teacher_meta_box() |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | + * |
|
| 240 | + * Render the teacher meta box markup |
|
| 241 | + * |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + * @access public |
|
| 244 | + * @parameters |
|
| 245 | + */ |
|
| 246 | + public function teacher_meta_box_content ( $post ) { |
|
| 247 | + |
|
| 248 | + // get the current author |
|
| 249 | + $current_author = $post->post_author; |
|
| 250 | + |
|
| 251 | + //get the users authorised to author courses |
|
| 252 | + $users = $this->get_teachers_and_authors(); |
|
| 253 | + |
|
| 254 | + ?> |
|
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | 257 | <?php foreach ( $users as $user_id ) { ?> |
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | - $user = get_user_by('id', $user_id); |
|
| 261 | - ?> |
|
| 260 | + $user = get_user_by('id', $user_id); |
|
| 261 | + ?> |
|
| 262 | 262 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
@@ -269,1289 +269,1289 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | <?php |
| 271 | 271 | |
| 272 | - } // end render_teacher_meta_box() |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | - * |
|
| 277 | - * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | - * |
|
| 279 | - * @since 1.8.0 |
|
| 280 | - * @access public |
|
| 281 | - * @parameters |
|
| 282 | - * @return array $users user id array |
|
| 283 | - */ |
|
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 285 | - |
|
| 286 | - $author_query_args = array( |
|
| 287 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | - 'fields' => 'any', |
|
| 289 | - 'who' => 'authors' |
|
| 290 | - ); |
|
| 291 | - |
|
| 292 | - $authors = get_users( $author_query_args ); |
|
| 293 | - |
|
| 294 | - $teacher_query_args = array( |
|
| 295 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | - 'fields' => 'any', |
|
| 297 | - 'role' => 'teacher', |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 301 | - |
|
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | - |
|
| 304 | - }// end get_teachers_and_authors |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | - * |
|
| 309 | - * Save the new teacher / author to course and all lessons |
|
| 310 | - * |
|
| 311 | - * Hooked into admin_init |
|
| 312 | - * |
|
| 313 | - * @since 1.8.0 |
|
| 314 | - * @access public |
|
| 315 | - * @parameters |
|
| 316 | - * @return array $users user id array |
|
| 317 | - */ |
|
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 272 | + } // end render_teacher_meta_box() |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | + * |
|
| 277 | + * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | + * |
|
| 279 | + * @since 1.8.0 |
|
| 280 | + * @access public |
|
| 281 | + * @parameters |
|
| 282 | + * @return array $users user id array |
|
| 283 | + */ |
|
| 284 | + public function get_teachers_and_authors ( ){ |
|
| 285 | + |
|
| 286 | + $author_query_args = array( |
|
| 287 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | + 'fields' => 'any', |
|
| 289 | + 'who' => 'authors' |
|
| 290 | + ); |
|
| 291 | + |
|
| 292 | + $authors = get_users( $author_query_args ); |
|
| 293 | + |
|
| 294 | + $teacher_query_args = array( |
|
| 295 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | + 'fields' => 'any', |
|
| 297 | + 'role' => 'teacher', |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + $teachers = get_users( $teacher_query_args ); |
|
| 301 | + |
|
| 302 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | + |
|
| 304 | + }// end get_teachers_and_authors |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | + * |
|
| 309 | + * Save the new teacher / author to course and all lessons |
|
| 310 | + * |
|
| 311 | + * Hooked into admin_init |
|
| 312 | + * |
|
| 313 | + * @since 1.8.0 |
|
| 314 | + * @access public |
|
| 315 | + * @parameters |
|
| 316 | + * @return array $users user id array |
|
| 317 | + */ |
|
| 318 | + public function save_teacher_meta_box ( $course_id ){ |
|
| 319 | 319 | |
| 320 | - // check if this is a post from saving the teacher, if not exit early |
|
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // check if this is a post from saving the teacher, if not exit early |
|
| 321 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - //don't fire this hook again |
|
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 325 | + //don't fire this hook again |
|
| 326 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 327 | 327 | |
| 328 | - // get the current post object |
|
| 329 | - $post = get_post( $course_id ); |
|
| 328 | + // get the current post object |
|
| 329 | + $post = get_post( $course_id ); |
|
| 330 | 330 | |
| 331 | - // get the current teacher/author |
|
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 331 | + // get the current teacher/author |
|
| 332 | + $current_author = absint( $post->post_author ); |
|
| 333 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 334 | 334 | |
| 335 | - // loop through all post lessons to update their authors as well |
|
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 335 | + // loop through all post lessons to update their authors as well |
|
| 336 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 337 | 337 | |
| 338 | - // do not do any processing if the selected author is the same as the current author |
|
| 339 | - if( $current_author == $new_author ){ |
|
| 340 | - return; |
|
| 341 | - } |
|
| 338 | + // do not do any processing if the selected author is the same as the current author |
|
| 339 | + if( $current_author == $new_author ){ |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // save the course author |
|
| 344 | - $post_updates = array( |
|
| 345 | - 'ID' => $post->ID , |
|
| 346 | - 'post_author' => $new_author |
|
| 347 | - ); |
|
| 348 | - wp_update_post( $post_updates ); |
|
| 343 | + // save the course author |
|
| 344 | + $post_updates = array( |
|
| 345 | + 'ID' => $post->ID , |
|
| 346 | + 'post_author' => $new_author |
|
| 347 | + ); |
|
| 348 | + wp_update_post( $post_updates ); |
|
| 349 | 349 | |
| 350 | - // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 350 | + // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 352 | 352 | |
| 353 | - // notify the new teacher |
|
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 353 | + // notify the new teacher |
|
| 354 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 355 | 355 | |
| 356 | - } // end save_teacher_meta_box |
|
| 356 | + } // end save_teacher_meta_box |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | - * the new author. Making sure the course terms are maintained. |
|
| 361 | - * |
|
| 362 | - * This function also checks if terms are shared, with other courses |
|
| 363 | - * |
|
| 364 | - * @param $course_id |
|
| 365 | - * @param $new_teacher_id |
|
| 366 | - * @return void |
|
| 367 | - */ |
|
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 358 | + /** |
|
| 359 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | + * the new author. Making sure the course terms are maintained. |
|
| 361 | + * |
|
| 362 | + * This function also checks if terms are shared, with other courses |
|
| 363 | + * |
|
| 364 | + * @param $course_id |
|
| 365 | + * @param $new_teacher_id |
|
| 366 | + * @return void |
|
| 367 | + */ |
|
| 368 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 370 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 377 | - return; |
|
| 378 | - } |
|
| 376 | + if( empty( $terms_selected_on_course ) ){ |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach( $terms_selected_on_course as $term ){ |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | + if( $new_teacher_id != $term_author->ID ){ |
|
| 384 | 384 | |
| 385 | - $new_term = ''; |
|
| 385 | + $new_term = ''; |
|
| 386 | 386 | |
| 387 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 387 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 394 | - // insert it even if it exists |
|
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | - } |
|
| 397 | - } |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | + if( !empty( $existing_admin_terms ) ){ |
|
| 394 | + // insert it even if it exists |
|
| 395 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if( empty ( $new_term ) ){ |
|
| 400 | 400 | |
| 401 | - //setup the new slug |
|
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | - |
|
| 404 | - // create new term and set it |
|
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | - |
|
| 407 | - } |
|
| 401 | + //setup the new slug |
|
| 402 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | + |
|
| 404 | + // create new term and set it |
|
| 405 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - // if term exists |
|
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 411 | + // if term exists |
|
| 412 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | - $term_id = $existing_term->term_id; |
|
| 414 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | + $term_id = $existing_term->term_id; |
|
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + }else{ |
|
| 418 | 418 | |
| 419 | - // for a new term simply get the term from the returned value |
|
| 420 | - $term_id = $new_term['term_id']; |
|
| 419 | + // for a new term simply get the term from the returned value |
|
| 420 | + $term_id = $new_term['term_id']; |
|
| 421 | 421 | |
| 422 | - } // end if term exist |
|
| 422 | + } // end if term exist |
|
| 423 | 423 | |
| 424 | - // set the terms selected on the course |
|
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 424 | + // set the terms selected on the course |
|
| 425 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 426 | 426 | |
| 427 | - // remove old term |
|
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 427 | + // remove old term |
|
| 428 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 429 | 429 | |
| 430 | - // update the lessons within the current module term |
|
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 430 | + // update the lessons within the current module term |
|
| 431 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | + foreach( $lessons as $lesson ){ |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 435 | 435 | |
| 436 | - // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | - // with the new term. |
|
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | - } |
|
| 436 | + // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | + // with the new term. |
|
| 438 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - }// end for each |
|
| 442 | + }// end for each |
|
| 443 | 443 | |
| 444 | - } |
|
| 445 | - } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - }// end update_course_module_terms_author |
|
| 447 | + }// end update_course_module_terms_author |
|
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Sensei_Teacher::update_course_lessons_author |
|
| 451 | - * |
|
| 452 | - * Update all course lessons and their quiz with a new author |
|
| 453 | - * |
|
| 454 | - * @since 1.8.0 |
|
| 455 | - * @access public |
|
| 456 | - * @parameters |
|
| 457 | - * @return array $users user id array |
|
| 458 | - */ |
|
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 449 | + /** |
|
| 450 | + * Sensei_Teacher::update_course_lessons_author |
|
| 451 | + * |
|
| 452 | + * Update all course lessons and their quiz with a new author |
|
| 453 | + * |
|
| 454 | + * @since 1.8.0 |
|
| 455 | + * @access public |
|
| 456 | + * @parameters |
|
| 457 | + * @return array $users user id array |
|
| 458 | + */ |
|
| 459 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 462 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - //get a list of course lessons |
|
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 466 | + //get a list of course lessons |
|
| 467 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 469 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - // update each lesson and quiz author |
|
| 474 | - foreach( $lessons as $lesson ){ |
|
| 473 | + // update each lesson and quiz author |
|
| 474 | + foreach( $lessons as $lesson ){ |
|
| 475 | 475 | |
| 476 | - // don't update if the author is tha same as the new author |
|
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 478 | - continue; |
|
| 479 | - } |
|
| 476 | + // don't update if the author is tha same as the new author |
|
| 477 | + if( $new_author == $lesson->post_author ){ |
|
| 478 | + continue; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - // update lesson author |
|
| 482 | - wp_update_post( array( |
|
| 483 | - 'ID'=> $lesson->ID, |
|
| 484 | - 'post_author' => $new_author |
|
| 485 | - ) ); |
|
| 481 | + // update lesson author |
|
| 482 | + wp_update_post( array( |
|
| 483 | + 'ID'=> $lesson->ID, |
|
| 484 | + 'post_author' => $new_author |
|
| 485 | + ) ); |
|
| 486 | 486 | |
| 487 | - // update quiz author |
|
| 488 | - //get the lessons quiz |
|
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | - // update quiz with new author |
|
| 493 | - wp_update_post( array( |
|
| 494 | - 'ID' => $quiz_id, |
|
| 495 | - 'post_author' => $new_author |
|
| 496 | - ) ); |
|
| 497 | - } |
|
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 500 | - 'ID' => $lesson_quizzes, |
|
| 501 | - 'post_author' => $new_author |
|
| 502 | - ) ); |
|
| 503 | - } |
|
| 487 | + // update quiz author |
|
| 488 | + //get the lessons quiz |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | + if( is_array( $lesson_quizzes ) ){ |
|
| 491 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | + // update quiz with new author |
|
| 493 | + wp_update_post( array( |
|
| 494 | + 'ID' => $quiz_id, |
|
| 495 | + 'post_author' => $new_author |
|
| 496 | + ) ); |
|
| 497 | + } |
|
| 498 | + }else{ |
|
| 499 | + wp_update_post( array( |
|
| 500 | + 'ID' => $lesson_quizzes, |
|
| 501 | + 'post_author' => $new_author |
|
| 502 | + ) ); |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - } // end for each lessons |
|
| 505 | + } // end for each lessons |
|
| 506 | 506 | |
| 507 | - return true; |
|
| 507 | + return true; |
|
| 508 | 508 | |
| 509 | - }// end update_course_lessons_author |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | - * |
|
| 516 | - * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | - * |
|
| 518 | - * @since 1.8.0 |
|
| 519 | - * @access public |
|
| 520 | - * @parameters $query |
|
| 521 | - * @return array $users user id array |
|
| 522 | - */ |
|
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | - |
|
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | - return $query; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | - return $query; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $screen = get_current_screen(); |
|
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | - |
|
| 536 | - // exit early for the following conditions |
|
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | - |
|
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | - return $query; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - global $current_user; |
|
| 545 | - // set the query author to the current user to only show those those posts |
|
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 547 | - return $query; |
|
| 548 | - |
|
| 549 | - }// end course_analysis_teacher_access_limit |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | - * |
|
| 555 | - * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | - * |
|
| 557 | - * @since 1.8.0 |
|
| 558 | - * @access public |
|
| 559 | - * @parameters array $wp_query |
|
| 560 | - * @return bool $is_admin_teacher |
|
| 561 | - */ |
|
| 562 | - public function is_admin_teacher ( ){ |
|
| 563 | - |
|
| 564 | - if( ! is_user_logged_in()){ |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $is_admin_teacher = false; |
|
| 568 | - |
|
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | - |
|
| 571 | - $is_admin_teacher = true; |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $is_admin_teacher; |
|
| 576 | - |
|
| 577 | - } // end is_admin_teacher |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Show correct post counts on list table for Sensei post types |
|
| 581 | - * |
|
| 582 | - * @since 1.8.0 |
|
| 583 | - * |
|
| 584 | - * @param object $counts Default status counts |
|
| 585 | - * @param string $type Current post type |
|
| 586 | - * @param string $perm User permission level |
|
| 587 | - * @return object Modified status counts |
|
| 588 | - */ |
|
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | - global $current_user; |
|
| 591 | - |
|
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | - return $counts; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 597 | - return $counts; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $args = array( |
|
| 601 | - 'post_type' => $type, |
|
| 602 | - 'author' => $current_user->ID, |
|
| 603 | - 'posts_per_page' => -1 |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - // Get all available statuses |
|
| 607 | - $stati = get_post_stati(); |
|
| 608 | - |
|
| 609 | - // Update count object |
|
| 610 | - foreach( $stati as $status ) { |
|
| 611 | - $args['post_status'] = $status; |
|
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - return $counts; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Filter the post queries to show |
|
| 621 | - * only lesson /course and users that belong |
|
| 622 | - * to the current logged teacher. |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * |
|
| 626 | - */ |
|
| 627 | - public function filter_queries ( $query ) { |
|
| 628 | - global $current_user; |
|
| 629 | - |
|
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 631 | - return; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $screen = get_current_screen(); |
|
| 639 | - if( empty( $screen ) ) { |
|
| 640 | - return $query; |
|
| 641 | - } |
|
| 642 | - switch( $screen->id ) { |
|
| 643 | - case 'sensei_page_sensei_grading': |
|
| 644 | - case 'sensei_page_sensei_analysis': |
|
| 645 | - case 'sensei_page_sensei_learners': |
|
| 646 | - case 'lesson': |
|
| 647 | - case 'course': |
|
| 648 | - case 'question': |
|
| 649 | - case 'lesson_page_module-order': |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * sensei_filter_queries_set_author |
|
| 653 | - * Filter the author Sensei set for queries |
|
| 654 | - * |
|
| 655 | - * @since 1.8.0 |
|
| 656 | - * |
|
| 657 | - * @param int $user_id |
|
| 658 | - * @param string $screen_id |
|
| 659 | - * |
|
| 660 | - */ |
|
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | - * . This excludes the admin user. |
|
| 669 | - * |
|
| 670 | - * @since 1.8.0 |
|
| 671 | - * @hooked into the_comments |
|
| 672 | - * @param array $comments |
|
| 673 | - * |
|
| 674 | - * @return array $comments |
|
| 675 | - */ |
|
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 677 | - |
|
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - //check if we're on the grading screen |
|
| 683 | - $screen = get_current_screen(); |
|
| 684 | - |
|
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | - return $comments; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - // get the course and determine if the current teacher is the owner |
|
| 690 | - // if not remove it from the list of comments to be returned |
|
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | - //remove this as the teacher should see this. |
|
| 697 | - unset( $comments[ $key ] ); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - return $comments ; |
|
| 701 | - |
|
| 702 | - }// end function filter grading |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Limit the grading screen totals to only show lessons in the course |
|
| 706 | - * belonging to the currently logged in teacher. This only applies to |
|
| 707 | - * the teacher role. |
|
| 708 | - * |
|
| 709 | - * @since 1.8.0 |
|
| 710 | - * |
|
| 711 | - * @hooked into sensei_count_statuses_args |
|
| 712 | - * @param array $args |
|
| 713 | - * |
|
| 714 | - * @return array $args |
|
| 715 | - */ |
|
| 716 | - public function limit_grading_totals( $args ){ |
|
| 717 | - |
|
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - //get the teachers courses |
|
| 723 | - // the query is already filtered to only the teacher |
|
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 725 | - |
|
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | - return $args; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - //setup the lessons quizzes to limit the grading totals to |
|
| 731 | - $quiz_scope = array(); |
|
| 732 | - foreach( $courses as $course ){ |
|
| 733 | - |
|
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | - |
|
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | - |
|
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 739 | - |
|
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 742 | - |
|
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 744 | - |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - $args['post__in'] = $quiz_scope; |
|
| 754 | - |
|
| 755 | - return $args; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * It ensures that the author archive shows course by the current user. |
|
| 760 | - * |
|
| 761 | - * This function is hooked into the pre_get_posts filter |
|
| 762 | - * |
|
| 763 | - * @param WP_Query $query |
|
| 764 | - * @return WP_Query $query |
|
| 765 | - */ |
|
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 767 | - |
|
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | - return $query; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // this should only apply to users with the teacher role |
|
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | - |
|
| 776 | - return $query; |
|
| 777 | - |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Change post types depending on what is set already |
|
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 783 | - |
|
| 784 | - // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 786 | - |
|
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 788 | - |
|
| 789 | - // merge the post types instead of overwriting it |
|
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | - |
|
| 792 | - }else{ |
|
| 793 | - |
|
| 794 | - // in this instance it is probably just one post type in string format |
|
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | - |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // change the query before returning it |
|
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Change the query on the teacher author archive template |
|
| 804 | - * |
|
| 805 | - * @since 1.8.4 |
|
| 806 | - * @param WP_Query $query |
|
| 807 | - */ |
|
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | - |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Notify teacher when someone assigns a course to their account. |
|
| 814 | - * |
|
| 815 | - * @since 1.8.0 |
|
| 816 | - * |
|
| 817 | - * @param $teacher_id |
|
| 818 | - * @param $course_id |
|
| 819 | - * @return bool |
|
| 820 | - */ |
|
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | - |
|
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - // if new user is the same as the current logged user, they don't need an email |
|
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - // load the email class |
|
| 833 | - include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | - $email = new Teacher_New_Course_Assignment(); |
|
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 836 | - |
|
| 837 | - return true; |
|
| 838 | - } // end teacher_course_assigned_notification |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Email the admin when a teacher creates a new course |
|
| 842 | - * |
|
| 843 | - * This function hooks into wp_insert_post |
|
| 844 | - * |
|
| 845 | - * @since 1.8.0 |
|
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 848 | - */ |
|
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | - |
|
| 851 | - $course_id = $post->ID; |
|
| 852 | - |
|
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | - |
|
| 856 | - return false; |
|
| 857 | - |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Filter the option to send admin notification emails when teachers creation |
|
| 862 | - * course. |
|
| 863 | - * |
|
| 864 | - * @since 1.8.0 |
|
| 865 | - * |
|
| 866 | - * @param bool $on default true |
|
| 867 | - */ |
|
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | - return false; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // setting up the data needed by the email template |
|
| 873 | - global $sensei_email_data; |
|
| 874 | - $template = 'admin-teacher-new-course-created'; |
|
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 877 | - $recipient = get_option('admin_email', true); |
|
| 878 | - |
|
| 879 | - // don't send if the course is created by admin |
|
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 881 | - return; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | - * |
|
| 887 | - * @since 1.8.0 |
|
| 888 | - * @param string $template |
|
| 889 | - */ |
|
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Filter the email subject for the the |
|
| 894 | - * admin-teacher-new-course-created template |
|
| 895 | - * |
|
| 896 | - * @since 1.8.0 |
|
| 897 | - * @param string $subject default New course assigned to you |
|
| 898 | - * @param string $template |
|
| 899 | - */ |
|
| 900 | - $subject = apply_filters('sensei_email_subject', |
|
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 903 | - |
|
| 904 | - //course edit link |
|
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | - |
|
| 907 | - // Construct data array |
|
| 908 | - $email_data = array( |
|
| 909 | - 'template' => $template, |
|
| 910 | - 'heading' => $heading, |
|
| 911 | - 'teacher' => $teacher, |
|
| 912 | - 'course_id' => $course_id, |
|
| 913 | - 'course_name' => $course->post_title, |
|
| 914 | - 'course_edit_link' => $course_edit_link, |
|
| 915 | - ); |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | - * |
|
| 920 | - * @since 1.8.0 |
|
| 921 | - * @param array $email_data |
|
| 922 | - * @param string $template |
|
| 923 | - */ |
|
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | - |
|
| 926 | - // Send mail |
|
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | - |
|
| 929 | - }// end notify admin of course creation |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | - * |
|
| 934 | - * Hooked into sensei_analysis_get_learners |
|
| 935 | - * @param array $args WP_User_Query arguments |
|
| 936 | - * @return array $learners_query_results |
|
| 937 | - */ |
|
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 939 | - |
|
| 940 | - // show default for none teachers |
|
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | - return $args; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - // for teachers all courses only return those which belong to the teacher |
|
| 946 | - // as they don't have access to course belonging to other users |
|
| 947 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 509 | + }// end update_course_lessons_author |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | + * |
|
| 516 | + * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | + * |
|
| 518 | + * @since 1.8.0 |
|
| 519 | + * @access public |
|
| 520 | + * @parameters $query |
|
| 521 | + * @return array $users user id array |
|
| 522 | + */ |
|
| 523 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | + |
|
| 525 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | + return $query; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | + return $query; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $screen = get_current_screen(); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | + |
|
| 536 | + // exit early for the following conditions |
|
| 537 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | + |
|
| 539 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | + return $query; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + global $current_user; |
|
| 545 | + // set the query author to the current user to only show those those posts |
|
| 546 | + $query->set( 'author', $current_user->ID ); |
|
| 547 | + return $query; |
|
| 548 | + |
|
| 549 | + }// end course_analysis_teacher_access_limit |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | + * |
|
| 555 | + * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | + * |
|
| 557 | + * @since 1.8.0 |
|
| 558 | + * @access public |
|
| 559 | + * @parameters array $wp_query |
|
| 560 | + * @return bool $is_admin_teacher |
|
| 561 | + */ |
|
| 562 | + public function is_admin_teacher ( ){ |
|
| 563 | + |
|
| 564 | + if( ! is_user_logged_in()){ |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $is_admin_teacher = false; |
|
| 568 | + |
|
| 569 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | + |
|
| 571 | + $is_admin_teacher = true; |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $is_admin_teacher; |
|
| 576 | + |
|
| 577 | + } // end is_admin_teacher |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Show correct post counts on list table for Sensei post types |
|
| 581 | + * |
|
| 582 | + * @since 1.8.0 |
|
| 583 | + * |
|
| 584 | + * @param object $counts Default status counts |
|
| 585 | + * @param string $type Current post type |
|
| 586 | + * @param string $perm User permission level |
|
| 587 | + * @return object Modified status counts |
|
| 588 | + */ |
|
| 589 | + public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | + global $current_user; |
|
| 591 | + |
|
| 592 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | + return $counts; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if( ! $this->is_admin_teacher() ) { |
|
| 597 | + return $counts; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $args = array( |
|
| 601 | + 'post_type' => $type, |
|
| 602 | + 'author' => $current_user->ID, |
|
| 603 | + 'posts_per_page' => -1 |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + // Get all available statuses |
|
| 607 | + $stati = get_post_stati(); |
|
| 608 | + |
|
| 609 | + // Update count object |
|
| 610 | + foreach( $stati as $status ) { |
|
| 611 | + $args['post_status'] = $status; |
|
| 612 | + $posts = get_posts( $args ); |
|
| 613 | + $counts->$status = count( $posts ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + return $counts; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Filter the post queries to show |
|
| 621 | + * only lesson /course and users that belong |
|
| 622 | + * to the current logged teacher. |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * |
|
| 626 | + */ |
|
| 627 | + public function filter_queries ( $query ) { |
|
| 628 | + global $current_user; |
|
| 629 | + |
|
| 630 | + if( ! $this->is_admin_teacher() ) { |
|
| 631 | + return; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $screen = get_current_screen(); |
|
| 639 | + if( empty( $screen ) ) { |
|
| 640 | + return $query; |
|
| 641 | + } |
|
| 642 | + switch( $screen->id ) { |
|
| 643 | + case 'sensei_page_sensei_grading': |
|
| 644 | + case 'sensei_page_sensei_analysis': |
|
| 645 | + case 'sensei_page_sensei_learners': |
|
| 646 | + case 'lesson': |
|
| 647 | + case 'course': |
|
| 648 | + case 'question': |
|
| 649 | + case 'lesson_page_module-order': |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * sensei_filter_queries_set_author |
|
| 653 | + * Filter the author Sensei set for queries |
|
| 654 | + * |
|
| 655 | + * @since 1.8.0 |
|
| 656 | + * |
|
| 657 | + * @param int $user_id |
|
| 658 | + * @param string $screen_id |
|
| 659 | + * |
|
| 660 | + */ |
|
| 661 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | + * . This excludes the admin user. |
|
| 669 | + * |
|
| 670 | + * @since 1.8.0 |
|
| 671 | + * @hooked into the_comments |
|
| 672 | + * @param array $comments |
|
| 673 | + * |
|
| 674 | + * @return array $comments |
|
| 675 | + */ |
|
| 676 | + public function filter_grading_activity_queries( $comments ){ |
|
| 677 | + |
|
| 678 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | + return $comments ; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + //check if we're on the grading screen |
|
| 683 | + $screen = get_current_screen(); |
|
| 684 | + |
|
| 685 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | + return $comments; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + // get the course and determine if the current teacher is the owner |
|
| 690 | + // if not remove it from the list of comments to be returned |
|
| 691 | + foreach( $comments as $key => $comment){ |
|
| 692 | + $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | + $course = get_post( $course_id ); |
|
| 695 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | + //remove this as the teacher should see this. |
|
| 697 | + unset( $comments[ $key ] ); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + return $comments ; |
|
| 701 | + |
|
| 702 | + }// end function filter grading |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Limit the grading screen totals to only show lessons in the course |
|
| 706 | + * belonging to the currently logged in teacher. This only applies to |
|
| 707 | + * the teacher role. |
|
| 708 | + * |
|
| 709 | + * @since 1.8.0 |
|
| 710 | + * |
|
| 711 | + * @hooked into sensei_count_statuses_args |
|
| 712 | + * @param array $args |
|
| 713 | + * |
|
| 714 | + * @return array $args |
|
| 715 | + */ |
|
| 716 | + public function limit_grading_totals( $args ){ |
|
| 717 | + |
|
| 718 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | + return $args ; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + //get the teachers courses |
|
| 723 | + // the query is already filtered to only the teacher |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | + |
|
| 726 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | + return $args; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + //setup the lessons quizzes to limit the grading totals to |
|
| 731 | + $quiz_scope = array(); |
|
| 732 | + foreach( $courses as $course ){ |
|
| 733 | + |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | + |
|
| 736 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | + |
|
| 738 | + foreach( $course_lessons as $lesson ){ |
|
| 739 | + |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | + if( !empty( $quiz_id ) ) { |
|
| 742 | + |
|
| 743 | + array_push( $quiz_scope, $quiz_id ); |
|
| 744 | + |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + $args['post__in'] = $quiz_scope; |
|
| 754 | + |
|
| 755 | + return $args; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * It ensures that the author archive shows course by the current user. |
|
| 760 | + * |
|
| 761 | + * This function is hooked into the pre_get_posts filter |
|
| 762 | + * |
|
| 763 | + * @param WP_Query $query |
|
| 764 | + * @return WP_Query $query |
|
| 765 | + */ |
|
| 766 | + public function add_courses_to_author_archive( $query ) { |
|
| 767 | + |
|
| 768 | + if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | + return $query; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // this should only apply to users with the teacher role |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | + |
|
| 776 | + return $query; |
|
| 777 | + |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // Change post types depending on what is set already |
|
| 781 | + $current_post_types = $query->get( 'post_type' ); |
|
| 782 | + if( empty( $current_post_types ) ){ |
|
| 783 | + |
|
| 784 | + // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | + $new_post_types = array( 'post', 'course' ); |
|
| 786 | + |
|
| 787 | + } elseif( is_array( $current_post_types ) ) { |
|
| 788 | + |
|
| 789 | + // merge the post types instead of overwriting it |
|
| 790 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | + |
|
| 792 | + }else{ |
|
| 793 | + |
|
| 794 | + // in this instance it is probably just one post type in string format |
|
| 795 | + $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | + |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // change the query before returning it |
|
| 800 | + $query->set('post_type', $new_post_types ); |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Change the query on the teacher author archive template |
|
| 804 | + * |
|
| 805 | + * @since 1.8.4 |
|
| 806 | + * @param WP_Query $query |
|
| 807 | + */ |
|
| 808 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | + |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Notify teacher when someone assigns a course to their account. |
|
| 814 | + * |
|
| 815 | + * @since 1.8.0 |
|
| 816 | + * |
|
| 817 | + * @param $teacher_id |
|
| 818 | + * @param $course_id |
|
| 819 | + * @return bool |
|
| 820 | + */ |
|
| 821 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | + |
|
| 823 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + // if new user is the same as the current logged user, they don't need an email |
|
| 828 | + if( $teacher_id == get_current_user_id() ){ |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + // load the email class |
|
| 833 | + include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | + $email = new Teacher_New_Course_Assignment(); |
|
| 835 | + $email->trigger( $teacher_id, $course_id ); |
|
| 836 | + |
|
| 837 | + return true; |
|
| 838 | + } // end teacher_course_assigned_notification |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Email the admin when a teacher creates a new course |
|
| 842 | + * |
|
| 843 | + * This function hooks into wp_insert_post |
|
| 844 | + * |
|
| 845 | + * @since 1.8.0 |
|
| 846 | + * @param int $course_id |
|
| 847 | + * @return bool |
|
| 848 | + */ |
|
| 849 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | + |
|
| 851 | + $course_id = $post->ID; |
|
| 852 | + |
|
| 853 | + if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | + |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Filter the option to send admin notification emails when teachers creation |
|
| 862 | + * course. |
|
| 863 | + * |
|
| 864 | + * @since 1.8.0 |
|
| 865 | + * |
|
| 866 | + * @param bool $on default true |
|
| 867 | + */ |
|
| 868 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | + return false; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // setting up the data needed by the email template |
|
| 873 | + global $sensei_email_data; |
|
| 874 | + $template = 'admin-teacher-new-course-created'; |
|
| 875 | + $course = get_post( $course_id ); |
|
| 876 | + $teacher = new WP_User( $course->post_author ); |
|
| 877 | + $recipient = get_option('admin_email', true); |
|
| 878 | + |
|
| 879 | + // don't send if the course is created by admin |
|
| 880 | + if( $recipient == $teacher->user_email ){ |
|
| 881 | + return; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | + * |
|
| 887 | + * @since 1.8.0 |
|
| 888 | + * @param string $template |
|
| 889 | + */ |
|
| 890 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Filter the email subject for the the |
|
| 894 | + * admin-teacher-new-course-created template |
|
| 895 | + * |
|
| 896 | + * @since 1.8.0 |
|
| 897 | + * @param string $subject default New course assigned to you |
|
| 898 | + * @param string $template |
|
| 899 | + */ |
|
| 900 | + $subject = apply_filters('sensei_email_subject', |
|
| 901 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | + $template ); |
|
| 903 | + |
|
| 904 | + //course edit link |
|
| 905 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | + |
|
| 907 | + // Construct data array |
|
| 908 | + $email_data = array( |
|
| 909 | + 'template' => $template, |
|
| 910 | + 'heading' => $heading, |
|
| 911 | + 'teacher' => $teacher, |
|
| 912 | + 'course_id' => $course_id, |
|
| 913 | + 'course_name' => $course->post_title, |
|
| 914 | + 'course_edit_link' => $course_edit_link, |
|
| 915 | + ); |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | + * |
|
| 920 | + * @since 1.8.0 |
|
| 921 | + * @param array $email_data |
|
| 922 | + * @param string $template |
|
| 923 | + */ |
|
| 924 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | + |
|
| 926 | + // Send mail |
|
| 927 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | + |
|
| 929 | + }// end notify admin of course creation |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | + * |
|
| 934 | + * Hooked into sensei_analysis_get_learners |
|
| 935 | + * @param array $args WP_User_Query arguments |
|
| 936 | + * @return array $learners_query_results |
|
| 937 | + */ |
|
| 938 | + public function limit_analysis_learners( $args ){ |
|
| 939 | + |
|
| 940 | + // show default for none teachers |
|
| 941 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | + return $args; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + // for teachers all courses only return those which belong to the teacher |
|
| 946 | + // as they don't have access to course belonging to other users |
|
| 947 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 948 | 948 | |
| 949 | - // if the user has no courses they should see no users |
|
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | - // tell the query to return 0 students |
|
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 953 | - return $args; |
|
| 954 | - |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - $learner_ids_for_teacher_courses = array(); |
|
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 959 | - |
|
| 960 | - $course_learner_ids = array(); |
|
| 961 | - $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | - |
|
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | - continue; // skip to the next course as there are no users on this course |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // it could be an array of comments or a single comment |
|
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 949 | + // if the user has no courses they should see no users |
|
| 950 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | + // tell the query to return 0 students |
|
| 952 | + $args[ 'include'] = array( 0 ); |
|
| 953 | + return $args; |
|
| 954 | + |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + $learner_ids_for_teacher_courses = array(); |
|
| 958 | + foreach( $teacher_courses as $course ){ |
|
| 959 | + |
|
| 960 | + $course_learner_ids = array(); |
|
| 961 | + $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | + |
|
| 963 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | + continue; // skip to the next course as there are no users on this course |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // it could be an array of comments or a single comment |
|
| 968 | + if( is_array( $activity_comments ) ){ |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach( $activity_comments as $comment ){ |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata( $comment->user_id ); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 975 | - // next comment in this array |
|
| 976 | - continue; |
|
| 977 | - } |
|
| 974 | + if( empty( $user ) ){ |
|
| 975 | + // next comment in this array |
|
| 976 | + continue; |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - $course_learner_ids[] = $user->ID; |
|
| 980 | - } |
|
| 979 | + $course_learner_ids[] = $user->ID; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + }else{ |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | - $course_learner_ids[] = $user->ID; |
|
| 984 | + $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | + $course_learner_ids[] = $user->ID; |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | - // add learners on this course to the all courses learner list |
|
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 989 | + // add learners on this course to the all courses learner list |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 991 | 991 | |
| 992 | - } |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | - // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 994 | + // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | + if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args[ 'include'] = array( 0 ); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + }else{ |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | - } |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | - // return the WP_Use_Query arguments |
|
| 1006 | - return $args; |
|
| 1005 | + // return the WP_Use_Query arguments |
|
| 1006 | + return $args; |
|
| 1007 | 1007 | |
| 1008 | - }// end limit_analysis_learners |
|
| 1008 | + }// end limit_analysis_learners |
|
| 1009 | 1009 | |
| 1010 | - /** |
|
| 1011 | - * Give teacher full admin access to the question post type |
|
| 1012 | - * in certain cases. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.8.0 |
|
| 1015 | - * @param $questions |
|
| 1016 | - * @return mixed |
|
| 1017 | - */ |
|
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1010 | + /** |
|
| 1011 | + * Give teacher full admin access to the question post type |
|
| 1012 | + * in certain cases. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.8.0 |
|
| 1015 | + * @param $questions |
|
| 1016 | + * @return mixed |
|
| 1017 | + */ |
|
| 1018 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1021 | - return $questions; |
|
| 1022 | - } |
|
| 1020 | + if( ! $this->is_admin_teacher() ){ |
|
| 1021 | + return $questions; |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - $screen = get_current_screen(); |
|
| 1024 | + $screen = get_current_screen(); |
|
| 1025 | 1025 | |
| 1026 | - // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1026 | + // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | + remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1030 | 1030 | |
| 1031 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1031 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | + if( ! empty($admin_user) ){ |
|
| 1033 | 1033 | |
| 1034 | - $current_teacher_id = get_current_user_id(); |
|
| 1034 | + $current_teacher_id = get_current_user_id(); |
|
| 1035 | 1035 | |
| 1036 | - // set current user to admin so teacher can view all questions |
|
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1036 | + // set current user to admin so teacher can view all questions |
|
| 1037 | + wp_set_current_user( $admin_user->ID ); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1039 | 1039 | |
| 1040 | - // set the teacher as the current use again |
|
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1042 | - } |
|
| 1040 | + // set the teacher as the current use again |
|
| 1041 | + wp_set_current_user( $current_teacher_id ); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - } |
|
| 1045 | - // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1044 | + } |
|
| 1045 | + // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1047 | 1047 | |
| 1048 | - return $questions; |
|
| 1049 | - } |
|
| 1048 | + return $questions; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Give the teacher role access to questions from the question bank |
|
| 1053 | - * |
|
| 1054 | - * @since 1.8.0 |
|
| 1055 | - * @param $wp_query |
|
| 1056 | - * @return mixed |
|
| 1057 | - */ |
|
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1051 | + /** |
|
| 1052 | + * Give the teacher role access to questions from the question bank |
|
| 1053 | + * |
|
| 1054 | + * @since 1.8.0 |
|
| 1055 | + * @param $wp_query |
|
| 1056 | + * @return mixed |
|
| 1057 | + */ |
|
| 1058 | + public function give_access_to_all_questions( $wp_query ){ |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1061 | 1061 | |
| 1062 | - return $wp_query; |
|
| 1063 | - } |
|
| 1062 | + return $wp_query; |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - $screen = get_current_screen(); |
|
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1065 | + $screen = get_current_screen(); |
|
| 1066 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1068 | 1068 | |
| 1069 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1069 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | + if( ! empty($admin_user) ){ |
|
| 1071 | 1071 | |
| 1072 | - $current_teacher_id = get_current_user_id(); |
|
| 1072 | + $current_teacher_id = get_current_user_id(); |
|
| 1073 | 1073 | |
| 1074 | - // set current user to admin so teacher can view all questions |
|
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1074 | + // set current user to admin so teacher can view all questions |
|
| 1075 | + wp_set_current_user( $admin_user->ID ); |
|
| 1076 | 1076 | |
| 1077 | - //run new query as admin |
|
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1077 | + //run new query as admin |
|
| 1078 | + $wp_query = new WP_Query( $wp_query->query ); |
|
| 1079 | 1079 | |
| 1080 | - //set the teache as current use again |
|
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1080 | + //set the teache as current use again |
|
| 1081 | + wp_set_current_user( $current_teacher_id ); |
|
| 1082 | 1082 | |
| 1083 | - } |
|
| 1084 | - } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return $wp_query; |
|
| 1087 | - }// end give_access_to_all_questions |
|
| 1086 | + return $wp_query; |
|
| 1087 | + }// end give_access_to_all_questions |
|
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * Add new column heading to the course admin edit list |
|
| 1091 | - * |
|
| 1092 | - * @since 1.8.0 |
|
| 1093 | - * @param $columns |
|
| 1094 | - * @return array |
|
| 1095 | - */ |
|
| 1096 | - public function course_column_heading($columns) { |
|
| 1089 | + /** |
|
| 1090 | + * Add new column heading to the course admin edit list |
|
| 1091 | + * |
|
| 1092 | + * @since 1.8.0 |
|
| 1093 | + * @param $columns |
|
| 1094 | + * @return array |
|
| 1095 | + */ |
|
| 1096 | + public function course_column_heading($columns) { |
|
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1099 | - return $columns; |
|
| 1100 | - } |
|
| 1101 | - $new_columns = array( |
|
| 1102 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | - ); |
|
| 1104 | - return array_merge($columns, $new_columns); |
|
| 1098 | + if( $this->is_admin_teacher() ){ |
|
| 1099 | + return $columns; |
|
| 1100 | + } |
|
| 1101 | + $new_columns = array( |
|
| 1102 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | + ); |
|
| 1104 | + return array_merge($columns, $new_columns); |
|
| 1105 | 1105 | |
| 1106 | - }// end teacher column add |
|
| 1106 | + }// end teacher column add |
|
| 1107 | 1107 | |
| 1108 | - /** |
|
| 1109 | - * Print out teacher column data |
|
| 1110 | - * |
|
| 1111 | - * @since 1.8.0 |
|
| 1112 | - * @param $column |
|
| 1113 | - * @param $course_id |
|
| 1114 | - */ |
|
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1108 | + /** |
|
| 1109 | + * Print out teacher column data |
|
| 1110 | + * |
|
| 1111 | + * @since 1.8.0 |
|
| 1112 | + * @param $column |
|
| 1113 | + * @param $course_id |
|
| 1114 | + */ |
|
| 1115 | + public function course_column_data( $column, $course_id ){ |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | - return; |
|
| 1119 | - } |
|
| 1117 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | + return; |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post( $course_id ); |
|
| 1122 | + $teacher = get_userdata( $course->post_author ); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1125 | - return; |
|
| 1126 | - } |
|
| 1124 | + if( !$teacher ){ |
|
| 1125 | + return; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | - }// end course_column_ data |
|
| 1130 | + }// end course_column_ data |
|
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * Return only courses belonging to the given teacher. |
|
| 1134 | - * |
|
| 1135 | - * |
|
| 1136 | - * @since 1.8.0 |
|
| 1137 | - * |
|
| 1138 | - * @param int $teacher_id |
|
| 1139 | - * @param bool $return_ids_only |
|
| 1140 | - * |
|
| 1141 | - * @return array $teachers_courses |
|
| 1142 | - */ |
|
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1132 | + /** |
|
| 1133 | + * Return only courses belonging to the given teacher. |
|
| 1134 | + * |
|
| 1135 | + * |
|
| 1136 | + * @since 1.8.0 |
|
| 1137 | + * |
|
| 1138 | + * @param int $teacher_id |
|
| 1139 | + * @param bool $return_ids_only |
|
| 1140 | + * |
|
| 1141 | + * @return array $teachers_courses |
|
| 1142 | + */ |
|
| 1143 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1144 | 1144 | |
| 1145 | - $teachers_courses = array(); |
|
| 1145 | + $teachers_courses = array(); |
|
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1148 | - $teacher_id = get_current_user_id(); |
|
| 1149 | - } |
|
| 1147 | + if( empty( $teacher_id ) ){ |
|
| 1148 | + $teacher_id = get_current_user_id(); |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - $all_courses = Sensei()->course->get_all_courses(); |
|
| 1151 | + $all_courses = Sensei()->course->get_all_courses(); |
|
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1154 | - return $all_courses; |
|
| 1155 | - } |
|
| 1153 | + if( empty( $all_courses ) ){ |
|
| 1154 | + return $all_courses; |
|
| 1155 | + } |
|
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach( $all_courses as $course ){ |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1160 | - continue; |
|
| 1161 | - } |
|
| 1159 | + if( $course->post_author != $teacher_id ){ |
|
| 1160 | + continue; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if( $return_ids_only ){ |
|
| 1164 | 1164 | |
| 1165 | - $teachers_courses[] = $course->ID; |
|
| 1165 | + $teachers_courses[] = $course->ID; |
|
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + }else{ |
|
| 1168 | 1168 | |
| 1169 | - $teachers_courses[] = $course; |
|
| 1169 | + $teachers_courses[] = $course; |
|
| 1170 | 1170 | |
| 1171 | - } |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - } |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - return $teachers_courses; |
|
| 1175 | + return $teachers_courses; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * Limit the message display to only those sent to the current teacher |
|
| 1181 | - * |
|
| 1182 | - * @since 1.8.0 |
|
| 1183 | - * |
|
| 1184 | - * @param $query |
|
| 1185 | - * @return mixed |
|
| 1186 | - */ |
|
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | - return $query; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - $teacher = wp_get_current_user(); |
|
| 1193 | - |
|
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | - $meta_query_args = array( |
|
| 1196 | - 'key' => '_receiver', |
|
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1198 | - 'compare' => '=' |
|
| 1199 | - ); |
|
| 1179 | + /** |
|
| 1180 | + * Limit the message display to only those sent to the current teacher |
|
| 1181 | + * |
|
| 1182 | + * @since 1.8.0 |
|
| 1183 | + * |
|
| 1184 | + * @param $query |
|
| 1185 | + * @return mixed |
|
| 1186 | + */ |
|
| 1187 | + public function limit_edit_messages_query( $query ){ |
|
| 1188 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | + return $query; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + $teacher = wp_get_current_user(); |
|
| 1193 | + |
|
| 1194 | + $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | + $meta_query_args = array( |
|
| 1196 | + 'key' => '_receiver', |
|
| 1197 | + 'value' => $teacher->get('user_login') , |
|
| 1198 | + 'compare' => '=' |
|
| 1199 | + ); |
|
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args ); |
|
| 1202 | 1202 | |
| 1203 | - return $query; |
|
| 1204 | - } |
|
| 1203 | + return $query; |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Add options to filter courses by teacher |
|
| 1209 | - * |
|
| 1210 | - * @since 1.8.0 |
|
| 1211 | - * |
|
| 1212 | - * @return void |
|
| 1213 | - */ |
|
| 1214 | - public function course_teacher_filter_options() { |
|
| 1215 | - global $typenow; |
|
| 1207 | + /** |
|
| 1208 | + * Add options to filter courses by teacher |
|
| 1209 | + * |
|
| 1210 | + * @since 1.8.0 |
|
| 1211 | + * |
|
| 1212 | + * @return void |
|
| 1213 | + */ |
|
| 1214 | + public function course_teacher_filter_options() { |
|
| 1215 | + global $typenow; |
|
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | - return; |
|
| 1219 | - } |
|
| 1217 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | + return; |
|
| 1219 | + } |
|
| 1220 | 1220 | |
| 1221 | - // get all roles |
|
| 1222 | - $roles = get_editable_roles(); |
|
| 1221 | + // get all roles |
|
| 1222 | + $roles = get_editable_roles(); |
|
| 1223 | 1223 | |
| 1224 | - // get roles with the course edit capability |
|
| 1225 | - // and then get the users with those roles |
|
| 1226 | - $users_who_can_edit_courses = array(); |
|
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1224 | + // get roles with the course edit capability |
|
| 1225 | + // and then get the users with those roles |
|
| 1226 | + $users_who_can_edit_courses = array(); |
|
| 1227 | + foreach( $roles as $role_item ){ |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1235 | 1235 | |
| 1236 | - // add user from the current $user_role to all users |
|
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1236 | + // add user from the current $user_role to all users |
|
| 1237 | + $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1238 | 1238 | |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | - } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - // Create the select element with the given users who can edit course |
|
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | - $course_options = ''; |
|
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | - } |
|
| 1243 | + // Create the select element with the given users who can edit course |
|
| 1244 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | + $course_options = ''; |
|
| 1246 | + foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | + $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | - $output .= $course_options; |
|
| 1253 | - $output .= '</select>'; |
|
| 1250 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | + $output .= $course_options; |
|
| 1253 | + $output .= '</select>'; |
|
| 1254 | 1254 | |
| 1255 | - echo $output; |
|
| 1256 | - } |
|
| 1255 | + echo $output; |
|
| 1256 | + } |
|
| 1257 | 1257 | |
| 1258 | - /** |
|
| 1259 | - * Modify the main query on the admin course list screen |
|
| 1260 | - * |
|
| 1261 | - * @since 1.8.0 |
|
| 1262 | - * |
|
| 1263 | - * @param $query |
|
| 1264 | - * @return $query |
|
| 1265 | - */ |
|
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1267 | - global $typenow; |
|
| 1258 | + /** |
|
| 1259 | + * Modify the main query on the admin course list screen |
|
| 1260 | + * |
|
| 1261 | + * @since 1.8.0 |
|
| 1262 | + * |
|
| 1263 | + * @param $query |
|
| 1264 | + * @return $query |
|
| 1265 | + */ |
|
| 1266 | + public function teacher_filter_query_modify( $query ){ |
|
| 1267 | + global $typenow; |
|
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | - return $query; |
|
| 1271 | - } |
|
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | - |
|
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1275 | - return $query; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - $query['author'] = $course_teacher; |
|
| 1279 | - return $query; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Only show current teacher's media in the media library |
|
| 1284 | - * @param array $request Default request arguments |
|
| 1285 | - * @return array Modified request arguments |
|
| 1286 | - */ |
|
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1288 | - |
|
| 1289 | - if( ! is_admin() ) { |
|
| 1290 | - return $request; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1294 | - return $request; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - $screen = get_current_screen(); |
|
| 1298 | - |
|
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1301 | - |
|
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - return $request; |
|
| 1308 | - } // End restrict_media_library() |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | - * @param array $query Default query arguments |
|
| 1313 | - * @return array Modified query arguments |
|
| 1314 | - */ |
|
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | - |
|
| 1317 | - if( ! is_admin() ) { |
|
| 1318 | - return $query; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1322 | - return $query; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1326 | - |
|
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - return $query; |
|
| 1332 | - } // End restrict_media_library_modal() |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | - * |
|
| 1337 | - * @since 1.8.0 |
|
| 1338 | - * |
|
| 1339 | - * @param int $lesson_id |
|
| 1340 | - */ |
|
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | - |
|
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1269 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | + return $query; |
|
| 1271 | + } |
|
| 1272 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | + |
|
| 1274 | + if( empty( $course_teacher ) ) { |
|
| 1275 | + return $query; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + $query['author'] = $course_teacher; |
|
| 1279 | + return $query; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Only show current teacher's media in the media library |
|
| 1284 | + * @param array $request Default request arguments |
|
| 1285 | + * @return array Modified request arguments |
|
| 1286 | + */ |
|
| 1287 | + public function restrict_media_library( $request = array() ) { |
|
| 1288 | + |
|
| 1289 | + if( ! is_admin() ) { |
|
| 1290 | + return $request; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + if( ! $this->is_admin_teacher() ) { |
|
| 1294 | + return $request; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + $screen = get_current_screen(); |
|
| 1298 | + |
|
| 1299 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | + $teacher = intval( get_current_user_id() ); |
|
| 1301 | + |
|
| 1302 | + if( $teacher ) { |
|
| 1303 | + $request['author__in'] = array( $teacher ); |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + return $request; |
|
| 1308 | + } // End restrict_media_library() |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | + * @param array $query Default query arguments |
|
| 1313 | + * @return array Modified query arguments |
|
| 1314 | + */ |
|
| 1315 | + public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | + |
|
| 1317 | + if( ! is_admin() ) { |
|
| 1318 | + return $query; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + if( ! $this->is_admin_teacher() ) { |
|
| 1322 | + return $query; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + $teacher = intval( get_current_user_id() ); |
|
| 1326 | + |
|
| 1327 | + if( $teacher ) { |
|
| 1328 | + $query['author__in'] = array( $teacher ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + return $query; |
|
| 1332 | + } // End restrict_media_library_modal() |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | + * |
|
| 1337 | + * @since 1.8.0 |
|
| 1338 | + * |
|
| 1339 | + * @param int $lesson_id |
|
| 1340 | + */ |
|
| 1341 | + public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | + |
|
| 1343 | + if( 'lesson'!= get_post_type() ){ |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | - // this should only run once per request cycle |
|
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1347 | + // this should only run once per request cycle |
|
| 1348 | + remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | - return; |
|
| 1354 | - } |
|
| 1352 | + if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | + return; |
|
| 1354 | + } |
|
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post( $course_id ); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1360 | - 'post_author' => $course->post_author |
|
| 1361 | - ); |
|
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1358 | + $lesson_update_args= array( |
|
| 1359 | + 'ID' => $lesson_id , |
|
| 1360 | + 'post_author' => $course->post_author |
|
| 1361 | + ); |
|
| 1362 | + wp_update_post( $lesson_update_args ); |
|
| 1363 | 1363 | |
| 1364 | - } // end update_lesson_teacher |
|
| 1364 | + } // end update_lesson_teacher |
|
| 1365 | 1365 | |
| 1366 | - /** |
|
| 1367 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | - * |
|
| 1369 | - * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | - * |
|
| 1371 | - * @since 1.8.0 |
|
| 1372 | - * @access public |
|
| 1373 | - * @parameters array $wp_query |
|
| 1374 | - * @return WP_Query $wp_query |
|
| 1375 | - */ |
|
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | - global $current_user; |
|
| 1366 | + /** |
|
| 1367 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | + * |
|
| 1369 | + * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | + * |
|
| 1371 | + * @since 1.8.0 |
|
| 1372 | + * @access public |
|
| 1373 | + * @parameters array $wp_query |
|
| 1374 | + * @return WP_Query $wp_query |
|
| 1375 | + */ |
|
| 1376 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | + global $current_user; |
|
| 1378 | 1378 | |
| 1379 | - //exit early |
|
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1381 | - return $wp_query; |
|
| 1382 | - } |
|
| 1379 | + //exit early |
|
| 1380 | + if( ! $this->is_admin_teacher() ){ |
|
| 1381 | + return $wp_query; |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | - return $wp_query; |
|
| 1386 | - } |
|
| 1384 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | + return $wp_query; |
|
| 1386 | + } |
|
| 1387 | 1387 | |
| 1388 | - $screen = get_current_screen(); |
|
| 1388 | + $screen = get_current_screen(); |
|
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1391 | - return $wp_query; |
|
| 1392 | - } |
|
| 1390 | + if( empty( $screen ) ){ |
|
| 1391 | + return $wp_query; |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - // for any of these conditions limit what the teacher will see |
|
| 1395 | - $limit_screens = array( |
|
| 1396 | - 'edit-lesson', |
|
| 1397 | - 'edit-course', |
|
| 1398 | - 'edit-question', |
|
| 1399 | - 'course_page_course-order', |
|
| 1400 | - 'lesson_page_lesson-order', |
|
| 1401 | - ); |
|
| 1394 | + // for any of these conditions limit what the teacher will see |
|
| 1395 | + $limit_screens = array( |
|
| 1396 | + 'edit-lesson', |
|
| 1397 | + 'edit-course', |
|
| 1398 | + 'edit-question', |
|
| 1399 | + 'course_page_course-order', |
|
| 1400 | + 'lesson_page_lesson-order', |
|
| 1401 | + ); |
|
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if( in_array($screen->id , $limit_screens ) ) { |
|
| 1404 | 1404 | |
| 1405 | - // set the query author to the current user to only show those those posts |
|
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | - } |
|
| 1405 | + // set the query author to the current user to only show those those posts |
|
| 1406 | + $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | + } |
|
| 1408 | 1408 | |
| 1409 | - return $wp_query; |
|
| 1409 | + return $wp_query; |
|
| 1410 | 1410 | |
| 1411 | - } // end limit_teacher_edit_screen_post_types() |
|
| 1411 | + } // end limit_teacher_edit_screen_post_types() |
|
| 1412 | 1412 | |
| 1413 | 1413 | |
| 1414 | - /** |
|
| 1415 | - * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | - * |
|
| 1417 | - * Redirect teachers to /wp-admin/ after login |
|
| 1418 | - * |
|
| 1419 | - * @since 1.8.7 |
|
| 1420 | - * @access public |
|
| 1421 | - * @param string $user_login |
|
| 1422 | - * @param object $user |
|
| 1423 | - * @return void |
|
| 1424 | - */ |
|
| 1414 | + /** |
|
| 1415 | + * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | + * |
|
| 1417 | + * Redirect teachers to /wp-admin/ after login |
|
| 1418 | + * |
|
| 1419 | + * @since 1.8.7 |
|
| 1420 | + * @access public |
|
| 1421 | + * @param string $user_login |
|
| 1422 | + * @param object $user |
|
| 1423 | + * @return void |
|
| 1424 | + */ |
|
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect( $user_login, $user ) { |
|
| 1427 | 1427 | |
| 1428 | - if (user_can($user, 'edit_courses')) { |
|
| 1428 | + if (user_can($user, 'edit_courses')) { |
|
| 1429 | 1429 | |
| 1430 | - if (isset($_POST['redirect_to'])) { |
|
| 1430 | + if (isset($_POST['redirect_to'])) { |
|
| 1431 | 1431 | |
| 1432 | - wp_redirect($_POST['redirect_to'], 303); |
|
| 1432 | + wp_redirect($_POST['redirect_to'], 303); |
|
| 1433 | 1433 | |
| 1434 | - exit; |
|
| 1434 | + exit; |
|
| 1435 | 1435 | |
| 1436 | - } else { |
|
| 1436 | + } else { |
|
| 1437 | 1437 | |
| 1438 | - wp_redirect(admin_url(), 303); |
|
| 1438 | + wp_redirect(admin_url(), 303); |
|
| 1439 | 1439 | |
| 1440 | - exit; |
|
| 1440 | + exit; |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1443 | - } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - } // end teacher_login_redirect() |
|
| 1445 | + } // end teacher_login_redirect() |
|
| 1446 | 1446 | |
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | - /** |
|
| 1450 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | - * |
|
| 1452 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | - * so they can 'moderate_comments' as well. |
|
| 1455 | - * |
|
| 1456 | - * @since 1.8.7 |
|
| 1457 | - * @access public |
|
| 1458 | - * @parameters void |
|
| 1459 | - * @return void |
|
| 1460 | - */ |
|
| 1449 | + /** |
|
| 1450 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | + * |
|
| 1452 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | + * so they can 'moderate_comments' as well. |
|
| 1455 | + * |
|
| 1456 | + * @since 1.8.7 |
|
| 1457 | + * @access public |
|
| 1458 | + * @parameters void |
|
| 1459 | + * @return void |
|
| 1460 | + */ |
|
| 1461 | 1461 | |
| 1462 | - public function restrict_posts_menu_page() { |
|
| 1462 | + public function restrict_posts_menu_page() { |
|
| 1463 | 1463 | |
| 1464 | - global $pagenow, $typenow; |
|
| 1464 | + global $pagenow, $typenow; |
|
| 1465 | 1465 | |
| 1466 | - $user = wp_get_current_user(); |
|
| 1466 | + $user = wp_get_current_user(); |
|
| 1467 | 1467 | |
| 1468 | - /** |
|
| 1469 | - * Filter the option to hide the Posts menu page. |
|
| 1470 | - * |
|
| 1471 | - * @since 1.8.7 |
|
| 1472 | - * |
|
| 1473 | - * @param bool $restrict default true |
|
| 1474 | - */ |
|
| 1468 | + /** |
|
| 1469 | + * Filter the option to hide the Posts menu page. |
|
| 1470 | + * |
|
| 1471 | + * @since 1.8.7 |
|
| 1472 | + * |
|
| 1473 | + * @param bool $restrict default true |
|
| 1474 | + */ |
|
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | - remove_menu_page('edit.php'); |
|
| 1480 | + remove_menu_page('edit.php'); |
|
| 1481 | 1481 | |
| 1482 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1482 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1483 | 1483 | |
| 1484 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1484 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1485 | 1485 | |
| 1486 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1486 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1487 | 1487 | |
| 1488 | - } |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - } // end restrict_posts_menu_page() |
|
| 1494 | + } // end restrict_posts_menu_page() |
|
| 1495 | 1495 | |
| 1496 | - /** |
|
| 1497 | - * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | - * |
|
| 1499 | - * Restrict commendation moderation for teachers |
|
| 1500 | - * so they can only moderate comments made to posts they own. |
|
| 1501 | - * |
|
| 1502 | - * @since 1.8.7 |
|
| 1503 | - * @access public |
|
| 1504 | - * @parameters obj $clauses |
|
| 1505 | - * @return obj $clauses |
|
| 1506 | - */ |
|
| 1496 | + /** |
|
| 1497 | + * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | + * |
|
| 1499 | + * Restrict commendation moderation for teachers |
|
| 1500 | + * so they can only moderate comments made to posts they own. |
|
| 1501 | + * |
|
| 1502 | + * @since 1.8.7 |
|
| 1503 | + * @access public |
|
| 1504 | + * @parameters obj $clauses |
|
| 1505 | + * @return obj $clauses |
|
| 1506 | + */ |
|
| 1507 | 1507 | |
| 1508 | - public function restrict_comment_moderation($clauses) { |
|
| 1508 | + public function restrict_comment_moderation($clauses) { |
|
| 1509 | 1509 | |
| 1510 | - global $pagenow; |
|
| 1510 | + global $pagenow; |
|
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1514 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1515 | 1515 | |
| 1516 | - } |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - return $clauses; |
|
| 1518 | + return $clauses; |
|
| 1519 | 1519 | |
| 1520 | - } // end restrict_comment_moderation() |
|
| 1520 | + } // end restrict_comment_moderation() |
|
| 1521 | 1521 | |
| 1522 | - /** |
|
| 1523 | - * Determine if a user is a teacher by ID |
|
| 1524 | - * |
|
| 1525 | - * @param int $user_id |
|
| 1526 | - * |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1522 | + /** |
|
| 1523 | + * Determine if a user is a teacher by ID |
|
| 1524 | + * |
|
| 1525 | + * @param int $user_id |
|
| 1526 | + * |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function is_a_teacher( $user_id ){ |
|
| 1530 | 1530 | |
| 1531 | - $user = get_user_by('id', $user_id); |
|
| 1531 | + $user = get_user_by('id', $user_id); |
|
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1534 | 1534 | |
| 1535 | - return true; |
|
| 1535 | + return true; |
|
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + }else{ |
|
| 1538 | 1538 | |
| 1539 | - return false; |
|
| 1539 | + return false; |
|
| 1540 | 1540 | |
| 1541 | - } |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - }// end is_a_teacher |
|
| 1543 | + }// end is_a_teacher |
|
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * The archive title on the teacher archive filter |
|
| 1547 | - * |
|
| 1548 | - * @since 1.9.0 |
|
| 1549 | - */ |
|
| 1550 | - public static function archive_title(){ |
|
| 1545 | + /** |
|
| 1546 | + * The archive title on the teacher archive filter |
|
| 1547 | + * |
|
| 1548 | + * @since 1.9.0 |
|
| 1549 | + */ |
|
| 1550 | + public static function archive_title(){ |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | - $author_name = $author->display_name; |
|
| 1554 | - ?> |
|
| 1552 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | + $author_name = $author->display_name; |
|
| 1554 | + ?> |
|
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | 1557 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1559,17 +1559,17 @@ discard block |
||
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
| 1561 | 1561 | |
| 1562 | - }// archive title |
|
| 1562 | + }// archive title |
|
| 1563 | 1563 | |
| 1564 | - /** |
|
| 1565 | - * Removing course meta on the teacher archive page |
|
| 1566 | - * |
|
| 1567 | - * @since 1.9.0 |
|
| 1568 | - */ |
|
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1564 | + /** |
|
| 1565 | + * Removing course meta on the teacher archive page |
|
| 1566 | + * |
|
| 1567 | + * @since 1.9.0 |
|
| 1568 | + */ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive(){ |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1572 | 1572 | |
| 1573 | - } |
|
| 1573 | + } |
|
| 1574 | 1574 | |
| 1575 | 1575 | } // End Class |
@@ -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 Teacher class |
@@ -42,58 +42,58 @@ discard block |
||
| 42 | 42 | * @since 1.8.0 |
| 43 | 43 | * @access public |
| 44 | 44 | */ |
| 45 | - public function __construct ( ) { |
|
| 45 | + public function __construct( ) { |
|
| 46 | 46 | |
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 47 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
| 48 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 49 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
| 50 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
| 51 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
| 52 | 52 | |
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 53 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
| 54 | 54 | |
| 55 | 55 | //filter the quiz submissions |
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 56 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
| 57 | 57 | |
| 58 | 58 | //grading totals count only those belonging to the teacher |
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 59 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
| 60 | 60 | |
| 61 | 61 | // show the courses owned by a user on his author archive page |
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 62 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
| 63 | 63 | |
| 64 | 64 | // notify admin when a teacher creates a course |
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 65 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
| 66 | 66 | |
| 67 | 67 | // limit the analysis view to only the users taking courses belong to this teacher |
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 68 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
| 69 | 69 | |
| 70 | 70 | // give teacher access to question post type |
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 71 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 72 | 72 | |
| 73 | 73 | // Teacher column on the courses list on the admin edit screen |
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 74 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
| 75 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
| 76 | 76 | |
| 77 | 77 | //admin edit messages query limit teacher |
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 78 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
| 79 | 79 | |
| 80 | 80 | //add filter by teacher on courses list |
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 81 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
| 82 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
| 83 | 83 | |
| 84 | 84 | // Handle media library restrictions |
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 85 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
| 86 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
| 87 | 87 | |
| 88 | 88 | // update lesson owner to course teacher when saved |
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 89 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 90 | 90 | |
| 91 | 91 | // If a Teacher logs in, redirect to /wp-admin/ |
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 92 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 95 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | } // end __constructor() |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | * @access public |
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | - public function create_role ( ) { |
|
| 111 | + public function create_role( ) { |
|
| 112 | 112 | |
| 113 | 113 | // check if the role exists |
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 114 | + $this->teacher_role = get_role('teacher'); |
|
| 115 | 115 | |
| 116 | 116 | // if the the teacher is not a valid WordPress role create it |
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 117 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
| 118 | 118 | // create the role |
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 119 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // add the capabilities before returning |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @since 1.8.0 |
| 131 | 131 | * @access protected |
| 132 | 132 | */ |
| 133 | - protected function add_capabilities ( ) { |
|
| 133 | + protected function add_capabilities( ) { |
|
| 134 | 134 | |
| 135 | 135 | // if this is not a valid WP_Role object exit without adding anything |
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 136 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param array $capabilities |
| 145 | 145 | * keys: (string) $cap_name => (bool) $grant |
| 146 | 146 | */ |
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 147 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
| 148 | 148 | // General access rules |
| 149 | 149 | 'read' => true, |
| 150 | 150 | 'manage_sensei_grades' => true, |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | )); |
| 203 | 203 | |
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 204 | + foreach ($caps as $cap => $grant) { |
|
| 205 | 205 | |
| 206 | 206 | // load the capability on to the teacher role |
| 207 | 207 | $this->teacher_role->add_cap($cap, $grant); |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * @parameter WP_Post $post |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 224 | + public function add_teacher_meta_boxes($post) { |
|
| 225 | 225 | |
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 226 | + if ( ! current_user_can('manage_options')) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
| 229 | + add_meta_box('sensei-teacher', __('Teacher', $this->token), array($this, 'teacher_meta_box_content'), |
|
| 230 | 230 | 'course', |
| 231 | 231 | 'side', |
| 232 | 232 | 'core' |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @access public |
| 244 | 244 | * @parameters |
| 245 | 245 | */ |
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 246 | + public function teacher_meta_box_content($post) { |
|
| 247 | 247 | |
| 248 | 248 | // get the current author |
| 249 | 249 | $current_author = $post->post_author; |
@@ -254,12 +254,12 @@ discard block |
||
| 254 | 254 | ?> |
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | - <?php foreach ( $users as $user_id ) { ?> |
|
| 257 | + <?php foreach ($users as $user_id) { ?> |
|
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | 260 | $user = get_user_by('id', $user_id); |
| 261 | 261 | ?> |
| 262 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
| 262 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
| 265 | 265 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @parameters |
| 282 | 282 | * @return array $users user id array |
| 283 | 283 | */ |
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 284 | + public function get_teachers_and_authors( ) { |
|
| 285 | 285 | |
| 286 | 286 | $author_query_args = array( |
| 287 | 287 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'who' => 'authors' |
| 290 | 290 | ); |
| 291 | 291 | |
| 292 | - $authors = get_users( $author_query_args ); |
|
| 292 | + $authors = get_users($author_query_args); |
|
| 293 | 293 | |
| 294 | 294 | $teacher_query_args = array( |
| 295 | 295 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | 'role' => 'teacher', |
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 300 | + $teachers = get_users($teacher_query_args); |
|
| 301 | 301 | |
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 302 | + return array_unique(array_merge($teachers, $authors)); |
|
| 303 | 303 | |
| 304 | 304 | }// end get_teachers_and_authors |
| 305 | 305 | |
@@ -315,43 +315,43 @@ discard block |
||
| 315 | 315 | * @parameters |
| 316 | 316 | * @return array $users user id array |
| 317 | 317 | */ |
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 318 | + public function save_teacher_meta_box($course_id) { |
|
| 319 | 319 | |
| 320 | 320 | // check if this is a post from saving the teacher, if not exit early |
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 321 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | //don't fire this hook again |
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 326 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 327 | 327 | |
| 328 | 328 | // get the current post object |
| 329 | - $post = get_post( $course_id ); |
|
| 329 | + $post = get_post($course_id); |
|
| 330 | 330 | |
| 331 | 331 | // get the current teacher/author |
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 332 | + $current_author = absint($post->post_author); |
|
| 333 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
| 334 | 334 | |
| 335 | 335 | // loop through all post lessons to update their authors as well |
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 336 | + $this->update_course_lessons_author($course_id, $new_author); |
|
| 337 | 337 | |
| 338 | 338 | // do not do any processing if the selected author is the same as the current author |
| 339 | - if( $current_author == $new_author ){ |
|
| 339 | + if ($current_author == $new_author) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // save the course author |
| 344 | 344 | $post_updates = array( |
| 345 | - 'ID' => $post->ID , |
|
| 345 | + 'ID' => $post->ID, |
|
| 346 | 346 | 'post_author' => $new_author |
| 347 | 347 | ); |
| 348 | - wp_update_post( $post_updates ); |
|
| 348 | + wp_update_post($post_updates); |
|
| 349 | 349 | |
| 350 | 350 | // ensure the the modules are update so that then new teacher has access to them |
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 351 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
| 352 | 352 | |
| 353 | 353 | // notify the new teacher |
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 354 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
| 355 | 355 | |
| 356 | 356 | } // end save_teacher_meta_box |
| 357 | 357 | |
@@ -365,56 +365,56 @@ discard block |
||
| 365 | 365 | * @param $new_teacher_id |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 368 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 370 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 376 | + if (empty($terms_selected_on_course)) { |
|
| 377 | 377 | return; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach ($terms_selected_on_course as $term) { |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 383 | + if ($new_teacher_id != $term_author->ID) { |
|
| 384 | 384 | |
| 385 | 385 | $new_term = ''; |
| 386 | 386 | |
| 387 | 387 | //if the new teacher is admin first check to see if the term with this name already exists |
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 388 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
| 391 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
| 392 | + $existing_admin_terms = get_terms('module', $term_args); |
|
| 393 | + if ( ! empty($existing_admin_terms)) { |
|
| 394 | 394 | // insert it even if it exists |
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 395 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if (empty ($new_term)) { |
|
| 400 | 400 | |
| 401 | 401 | //setup the new slug |
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 402 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
| 403 | 403 | |
| 404 | 404 | // create new term and set it |
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 405 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
| 406 | 406 | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | 411 | // if term exists |
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 412 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 414 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
| 415 | 415 | $term_id = $existing_term->term_id; |
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + } else { |
|
| 418 | 418 | |
| 419 | 419 | // for a new term simply get the term from the returned value |
| 420 | 420 | $term_id = $new_term['term_id']; |
@@ -422,21 +422,21 @@ discard block |
||
| 422 | 422 | } // end if term exist |
| 423 | 423 | |
| 424 | 424 | // set the terms selected on the course |
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 425 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
| 426 | 426 | |
| 427 | 427 | // remove old term |
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 428 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
| 429 | 429 | |
| 430 | 430 | // update the lessons within the current module term |
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 431 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 432 | + foreach ($lessons as $lesson) { |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if (has_term($term->slug, 'module', $lesson)) { |
|
| 435 | 435 | |
| 436 | 436 | // add the new term, the false at the end says to replace all terms on this module |
| 437 | 437 | // with the new term. |
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 438 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
| 439 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | }// end for each |
@@ -456,50 +456,50 @@ discard block |
||
| 456 | 456 | * @parameters |
| 457 | 457 | * @return array $users user id array |
| 458 | 458 | */ |
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 459 | + public function update_course_lessons_author($course_id, $new_author) { |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 462 | + if (empty($course_id) || empty($new_author)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | //get a list of course lessons |
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 467 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 469 | + if (empty($lessons) || ! is_array($lessons)) { |
|
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // update each lesson and quiz author |
| 474 | - foreach( $lessons as $lesson ){ |
|
| 474 | + foreach ($lessons as $lesson) { |
|
| 475 | 475 | |
| 476 | 476 | // don't update if the author is tha same as the new author |
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 477 | + if ($new_author == $lesson->post_author) { |
|
| 478 | 478 | continue; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // update lesson author |
| 482 | - wp_update_post( array( |
|
| 482 | + wp_update_post(array( |
|
| 483 | 483 | 'ID'=> $lesson->ID, |
| 484 | 484 | 'post_author' => $new_author |
| 485 | - ) ); |
|
| 485 | + )); |
|
| 486 | 486 | |
| 487 | 487 | // update quiz author |
| 488 | 488 | //get the lessons quiz |
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 490 | + if (is_array($lesson_quizzes)) { |
|
| 491 | + foreach ($lesson_quizzes as $quiz_id) { |
|
| 492 | 492 | // update quiz with new author |
| 493 | - wp_update_post( array( |
|
| 493 | + wp_update_post(array( |
|
| 494 | 494 | 'ID' => $quiz_id, |
| 495 | 495 | 'post_author' => $new_author |
| 496 | - ) ); |
|
| 496 | + )); |
|
| 497 | 497 | } |
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 498 | + } else { |
|
| 499 | + wp_update_post(array( |
|
| 500 | 500 | 'ID' => $lesson_quizzes, |
| 501 | 501 | 'post_author' => $new_author |
| 502 | - ) ); |
|
| 502 | + )); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } // end for each lessons |
@@ -520,30 +520,30 @@ discard block |
||
| 520 | 520 | * @parameters $query |
| 521 | 521 | * @return array $users user id array |
| 522 | 522 | */ |
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 523 | + public function course_analysis_teacher_access_limit($query) { |
|
| 524 | 524 | |
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 525 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 526 | 526 | return $query; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 529 | + if ( ! function_exists('get_current_screen')) { |
|
| 530 | 530 | return $query; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $screen = get_current_screen(); |
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
| 535 | 535 | |
| 536 | 536 | // exit early for the following conditions |
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 537 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
| 538 | 538 | |
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 539 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
| 540 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
| 541 | 541 | return $query; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | global $current_user; |
| 545 | 545 | // set the query author to the current user to only show those those posts |
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 546 | + $query->set('author', $current_user->ID); |
|
| 547 | 547 | return $query; |
| 548 | 548 | |
| 549 | 549 | }// end course_analysis_teacher_access_limit |
@@ -559,14 +559,14 @@ discard block |
||
| 559 | 559 | * @parameters array $wp_query |
| 560 | 560 | * @return bool $is_admin_teacher |
| 561 | 561 | */ |
| 562 | - public function is_admin_teacher ( ){ |
|
| 562 | + public function is_admin_teacher( ) { |
|
| 563 | 563 | |
| 564 | - if( ! is_user_logged_in()){ |
|
| 564 | + if ( ! is_user_logged_in()) { |
|
| 565 | 565 | return false; |
| 566 | 566 | } |
| 567 | 567 | $is_admin_teacher = false; |
| 568 | 568 | |
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 569 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
| 570 | 570 | |
| 571 | 571 | $is_admin_teacher = true; |
| 572 | 572 | |
@@ -586,14 +586,14 @@ discard block |
||
| 586 | 586 | * @param string $perm User permission level |
| 587 | 587 | * @return object Modified status counts |
| 588 | 588 | */ |
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 589 | + public function list_table_counts($counts, $type, $perm) { |
|
| 590 | 590 | global $current_user; |
| 591 | 591 | |
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 592 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
| 593 | 593 | return $counts; |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 596 | + if ( ! $this->is_admin_teacher()) { |
|
| 597 | 597 | return $counts; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | $stati = get_post_stati(); |
| 608 | 608 | |
| 609 | 609 | // Update count object |
| 610 | - foreach( $stati as $status ) { |
|
| 610 | + foreach ($stati as $status) { |
|
| 611 | 611 | $args['post_status'] = $status; |
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 612 | + $posts = get_posts($args); |
|
| 613 | + $counts->$status = count($posts); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | return $counts; |
@@ -624,22 +624,22 @@ discard block |
||
| 624 | 624 | * @since 1.8.0 |
| 625 | 625 | * |
| 626 | 626 | */ |
| 627 | - public function filter_queries ( $query ) { |
|
| 627 | + public function filter_queries($query) { |
|
| 628 | 628 | global $current_user; |
| 629 | 629 | |
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 630 | + if ( ! $this->is_admin_teacher()) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 634 | + if ( ! function_exists('get_current_screen')) { |
|
| 635 | 635 | return; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | $screen = get_current_screen(); |
| 639 | - if( empty( $screen ) ) { |
|
| 639 | + if (empty($screen)) { |
|
| 640 | 640 | return $query; |
| 641 | 641 | } |
| 642 | - switch( $screen->id ) { |
|
| 642 | + switch ($screen->id) { |
|
| 643 | 643 | case 'sensei_page_sensei_grading': |
| 644 | 644 | case 'sensei_page_sensei_analysis': |
| 645 | 645 | case 'sensei_page_sensei_learners': |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @param string $screen_id |
| 659 | 659 | * |
| 660 | 660 | */ |
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 661 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
| 662 | 662 | break; |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -673,31 +673,31 @@ discard block |
||
| 673 | 673 | * |
| 674 | 674 | * @return array $comments |
| 675 | 675 | */ |
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 676 | + public function filter_grading_activity_queries($comments) { |
|
| 677 | 677 | |
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 678 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
| 679 | + return $comments; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | //check if we're on the grading screen |
| 683 | 683 | $screen = get_current_screen(); |
| 684 | 684 | |
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 685 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
| 686 | 686 | return $comments; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // get the course and determine if the current teacher is the owner |
| 690 | 690 | // if not remove it from the list of comments to be returned |
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 691 | + foreach ($comments as $key => $comment) { |
|
| 692 | + $lesson = get_post($comment->comment_post_ID); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
| 694 | + $course = get_post($course_id); |
|
| 695 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
| 696 | 696 | //remove this as the teacher should see this. |
| 697 | - unset( $comments[ $key ] ); |
|
| 697 | + unset($comments[$key]); |
|
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | - return $comments ; |
|
| 700 | + return $comments; |
|
| 701 | 701 | |
| 702 | 702 | }// end function filter grading |
| 703 | 703 | |
@@ -713,34 +713,34 @@ discard block |
||
| 713 | 713 | * |
| 714 | 714 | * @return array $args |
| 715 | 715 | */ |
| 716 | - public function limit_grading_totals( $args ){ |
|
| 716 | + public function limit_grading_totals($args) { |
|
| 717 | 717 | |
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 718 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
| 719 | + return $args; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | //get the teachers courses |
| 723 | 723 | // the query is already filtered to only the teacher |
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | 725 | |
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 726 | + if (empty($courses) || ! is_array($courses)) { |
|
| 727 | 727 | return $args; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | //setup the lessons quizzes to limit the grading totals to |
| 731 | 731 | $quiz_scope = array(); |
| 732 | - foreach( $courses as $course ){ |
|
| 732 | + foreach ($courses as $course) { |
|
| 733 | 733 | |
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
| 735 | 735 | |
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 736 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
| 737 | 737 | |
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 738 | + foreach ($course_lessons as $lesson) { |
|
| 739 | 739 | |
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 741 | + if ( ! empty($quiz_id)) { |
|
| 742 | 742 | |
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 743 | + array_push($quiz_scope, $quiz_id); |
|
| 744 | 744 | |
| 745 | 745 | } |
| 746 | 746 | |
@@ -763,41 +763,41 @@ discard block |
||
| 763 | 763 | * @param WP_Query $query |
| 764 | 764 | * @return WP_Query $query |
| 765 | 765 | */ |
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 766 | + public function add_courses_to_author_archive($query) { |
|
| 767 | 767 | |
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 768 | + if (is_admin() || ! $query->is_author()) { |
|
| 769 | 769 | return $query; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // this should only apply to users with the teacher role |
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
| 774 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
| 775 | 775 | |
| 776 | 776 | return $query; |
| 777 | 777 | |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // Change post types depending on what is set already |
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 781 | + $current_post_types = $query->get('post_type'); |
|
| 782 | + if (empty($current_post_types)) { |
|
| 783 | 783 | |
| 784 | 784 | // if empty it means post by default, so add post so that it also includes that for now |
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 785 | + $new_post_types = array('post', 'course'); |
|
| 786 | 786 | |
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 787 | + } elseif (is_array($current_post_types)) { |
|
| 788 | 788 | |
| 789 | 789 | // merge the post types instead of overwriting it |
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 790 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
| 791 | 791 | |
| 792 | - }else{ |
|
| 792 | + } else { |
|
| 793 | 793 | |
| 794 | 794 | // in this instance it is probably just one post type in string format |
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 795 | + $new_post_types = array($current_post_types, 'course'); |
|
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // change the query before returning it |
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 800 | + $query->set('post_type', $new_post_types); |
|
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | 803 | * Change the query on the teacher author archive template |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @since 1.8.4 |
| 806 | 806 | * @param WP_Query $query |
| 807 | 807 | */ |
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 808 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | |
@@ -818,21 +818,21 @@ discard block |
||
| 818 | 818 | * @param $course_id |
| 819 | 819 | * @return bool |
| 820 | 820 | */ |
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 821 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
| 822 | 822 | |
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 823 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
| 824 | 824 | return false; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | // if new user is the same as the current logged user, they don't need an email |
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 828 | + if ($teacher_id == get_current_user_id()) { |
|
| 829 | 829 | return true; |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | // load the email class |
| 833 | 833 | include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
| 834 | 834 | $email = new Teacher_New_Course_Assignment(); |
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 835 | + $email->trigger($teacher_id, $course_id); |
|
| 836 | 836 | |
| 837 | 837 | return true; |
| 838 | 838 | } // end teacher_course_assigned_notification |
@@ -846,12 +846,12 @@ discard block |
||
| 846 | 846 | * @param int $course_id |
| 847 | 847 | * @return bool |
| 848 | 848 | */ |
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 849 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
| 850 | 850 | |
| 851 | 851 | $course_id = $post->ID; |
| 852 | 852 | |
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 853 | + if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
| 854 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
| 855 | 855 | |
| 856 | 856 | return false; |
| 857 | 857 | |
@@ -865,19 +865,19 @@ discard block |
||
| 865 | 865 | * |
| 866 | 866 | * @param bool $on default true |
| 867 | 867 | */ |
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 868 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // setting up the data needed by the email template |
| 873 | 873 | global $sensei_email_data; |
| 874 | 874 | $template = 'admin-teacher-new-course-created'; |
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 875 | + $course = get_post($course_id); |
|
| 876 | + $teacher = new WP_User($course->post_author); |
|
| 877 | 877 | $recipient = get_option('admin_email', true); |
| 878 | 878 | |
| 879 | 879 | // don't send if the course is created by admin |
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 880 | + if ($recipient == $teacher->user_email) { |
|
| 881 | 881 | return; |
| 882 | 882 | } |
| 883 | 883 | |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @since 1.8.0 |
| 888 | 888 | * @param string $template |
| 889 | 889 | */ |
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 890 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
| 891 | 891 | |
| 892 | 892 | /** |
| 893 | 893 | * Filter the email subject for the the |
@@ -898,11 +898,11 @@ discard block |
||
| 898 | 898 | * @param string $template |
| 899 | 899 | */ |
| 900 | 900 | $subject = apply_filters('sensei_email_subject', |
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 901 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
| 902 | + $template); |
|
| 903 | 903 | |
| 904 | 904 | //course edit link |
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 905 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
| 906 | 906 | |
| 907 | 907 | // Construct data array |
| 908 | 908 | $email_data = array( |
@@ -921,10 +921,10 @@ discard block |
||
| 921 | 921 | * @param array $email_data |
| 922 | 922 | * @param string $template |
| 923 | 923 | */ |
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 924 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
| 925 | 925 | |
| 926 | 926 | // Send mail |
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 927 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
| 928 | 928 | |
| 929 | 929 | }// end notify admin of course creation |
| 930 | 930 | |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @param array $args WP_User_Query arguments |
| 936 | 936 | * @return array $learners_query_results |
| 937 | 937 | */ |
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 938 | + public function limit_analysis_learners($args) { |
|
| 939 | 939 | |
| 940 | 940 | // show default for none teachers |
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 941 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
| 942 | 942 | return $args; |
| 943 | 943 | } |
| 944 | 944 | |
@@ -947,31 +947,31 @@ discard block |
||
| 947 | 947 | $teacher_courses = Sensei()->course->get_all_courses(); |
| 948 | 948 | |
| 949 | 949 | // if the user has no courses they should see no users |
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 950 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
| 951 | 951 | // tell the query to return 0 students |
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 952 | + $args['include'] = array(0); |
|
| 953 | 953 | return $args; |
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | $learner_ids_for_teacher_courses = array(); |
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 958 | + foreach ($teacher_courses as $course) { |
|
| 959 | 959 | |
| 960 | 960 | $course_learner_ids = array(); |
| 961 | - $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 961 | + $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
| 962 | 962 | |
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 963 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
| 964 | 964 | continue; // skip to the next course as there are no users on this course |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | // it could be an array of comments or a single comment |
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 968 | + if (is_array($activity_comments)) { |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach ($activity_comments as $comment) { |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata($comment->user_id); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 974 | + if (empty($user)) { |
|
| 975 | 975 | // next comment in this array |
| 976 | 976 | continue; |
| 977 | 977 | } |
@@ -979,26 +979,26 @@ discard block |
||
| 979 | 979 | $course_learner_ids[] = $user->ID; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + } else { |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 984 | + $user = get_userdata($activity_comments->user_id); |
|
| 985 | 985 | $course_learner_ids[] = $user->ID; |
| 986 | 986 | |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | // add learners on this course to the all courses learner list |
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
| 991 | 991 | |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | // if there are no students taking the courses by this teacher don't show them any of the other users |
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 995 | + if (empty($learner_ids_for_teacher_courses)) { |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args['include'] = array(0); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + } else { |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | 1003 | } |
| 1004 | 1004 | |
@@ -1015,35 +1015,35 @@ discard block |
||
| 1015 | 1015 | * @param $questions |
| 1016 | 1016 | * @return mixed |
| 1017 | 1017 | */ |
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1018 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1020 | + if ( ! $this->is_admin_teacher()) { |
|
| 1021 | 1021 | return $questions; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | $screen = get_current_screen(); |
| 1025 | 1025 | |
| 1026 | 1026 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1027 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
| 1030 | 1030 | |
| 1031 | 1031 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1032 | + if ( ! empty($admin_user)) { |
|
| 1033 | 1033 | |
| 1034 | 1034 | $current_teacher_id = get_current_user_id(); |
| 1035 | 1035 | |
| 1036 | 1036 | // set current user to admin so teacher can view all questions |
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1037 | + wp_set_current_user($admin_user->ID); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // set the teacher as the current use again |
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1041 | + wp_set_current_user($current_teacher_id); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | } |
| 1045 | 1045 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1046 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 1047 | 1047 | |
| 1048 | 1048 | return $questions; |
| 1049 | 1049 | } |
@@ -1055,30 +1055,30 @@ discard block |
||
| 1055 | 1055 | * @param $wp_query |
| 1056 | 1056 | * @return mixed |
| 1057 | 1057 | */ |
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1058 | + public function give_access_to_all_questions($wp_query) { |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
| 1061 | 1061 | |
| 1062 | 1062 | return $wp_query; |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | $screen = get_current_screen(); |
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1066 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
| 1067 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1070 | + if ( ! empty($admin_user)) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | $current_teacher_id = get_current_user_id(); |
| 1073 | 1073 | |
| 1074 | 1074 | // set current user to admin so teacher can view all questions |
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1075 | + wp_set_current_user($admin_user->ID); |
|
| 1076 | 1076 | |
| 1077 | 1077 | //run new query as admin |
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1078 | + $wp_query = new WP_Query($wp_query->query); |
|
| 1079 | 1079 | |
| 1080 | 1080 | //set the teache as current use again |
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1081 | + wp_set_current_user($current_teacher_id); |
|
| 1082 | 1082 | |
| 1083 | 1083 | } |
| 1084 | 1084 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | */ |
| 1096 | 1096 | public function course_column_heading($columns) { |
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1098 | + if ($this->is_admin_teacher()) { |
|
| 1099 | 1099 | return $columns; |
| 1100 | 1100 | } |
| 1101 | 1101 | $new_columns = array( |
@@ -1112,20 +1112,20 @@ discard block |
||
| 1112 | 1112 | * @param $column |
| 1113 | 1113 | * @param $course_id |
| 1114 | 1114 | */ |
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1115 | + public function course_column_data($column, $course_id) { |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1117 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
| 1118 | 1118 | return; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post($course_id); |
|
| 1122 | + $teacher = get_userdata($course->post_author); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1124 | + if ( ! $teacher) { |
|
| 1125 | 1125 | return; |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | 1130 | }// end course_column_ data |
| 1131 | 1131 | |
@@ -1140,31 +1140,31 @@ discard block |
||
| 1140 | 1140 | * |
| 1141 | 1141 | * @return array $teachers_courses |
| 1142 | 1142 | */ |
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1143 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
| 1144 | 1144 | |
| 1145 | 1145 | $teachers_courses = array(); |
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1147 | + if (empty($teacher_id)) { |
|
| 1148 | 1148 | $teacher_id = get_current_user_id(); |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | $all_courses = Sensei()->course->get_all_courses(); |
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1153 | + if (empty($all_courses)) { |
|
| 1154 | 1154 | return $all_courses; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach ($all_courses as $course) { |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1159 | + if ($course->post_author != $teacher_id) { |
|
| 1160 | 1160 | continue; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if ($return_ids_only) { |
|
| 1164 | 1164 | |
| 1165 | 1165 | $teachers_courses[] = $course->ID; |
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + } else { |
|
| 1168 | 1168 | |
| 1169 | 1169 | $teachers_courses[] = $course; |
| 1170 | 1170 | |
@@ -1184,21 +1184,21 @@ discard block |
||
| 1184 | 1184 | * @param $query |
| 1185 | 1185 | * @return mixed |
| 1186 | 1186 | */ |
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1187 | + public function limit_edit_messages_query($query) { |
|
| 1188 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
| 1189 | 1189 | return $query; |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | $teacher = wp_get_current_user(); |
| 1193 | 1193 | |
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1194 | + $query->set('meta_key', '_receiver'); |
|
| 1195 | 1195 | $meta_query_args = array( |
| 1196 | 1196 | 'key' => '_receiver', |
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1197 | + 'value' => $teacher->get('user_login'), |
|
| 1198 | 1198 | 'compare' => '=' |
| 1199 | 1199 | ); |
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args); |
|
| 1202 | 1202 | |
| 1203 | 1203 | return $query; |
| 1204 | 1204 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
| 1214 | 1214 | public function course_teacher_filter_options() { |
| 1215 | 1215 | global $typenow; |
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1217 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1218 | 1218 | return; |
| 1219 | 1219 | } |
| 1220 | 1220 | |
@@ -1224,31 +1224,31 @@ discard block |
||
| 1224 | 1224 | // get roles with the course edit capability |
| 1225 | 1225 | // and then get the users with those roles |
| 1226 | 1226 | $users_who_can_edit_courses = array(); |
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1227 | + foreach ($roles as $role_item) { |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role(strtolower($role_item['name'])); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
| 1235 | 1235 | |
| 1236 | 1236 | // add user from the current $user_role to all users |
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1237 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
| 1238 | 1238 | |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | // Create the select element with the given users who can edit course |
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1244 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1245 | 1245 | $course_options = ''; |
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1246 | + foreach ($users_who_can_edit_courses as $user) { |
|
| 1247 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1251 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
| 1252 | 1252 | $output .= $course_options; |
| 1253 | 1253 | $output .= '</select>'; |
| 1254 | 1254 | |
@@ -1263,15 +1263,15 @@ discard block |
||
| 1263 | 1263 | * @param $query |
| 1264 | 1264 | * @return $query |
| 1265 | 1265 | */ |
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1266 | + public function teacher_filter_query_modify($query) { |
|
| 1267 | 1267 | global $typenow; |
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1269 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1270 | 1270 | return $query; |
| 1271 | 1271 | } |
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1272 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1273 | 1273 | |
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1274 | + if (empty($course_teacher)) { |
|
| 1275 | 1275 | return $query; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1284,23 +1284,23 @@ discard block |
||
| 1284 | 1284 | * @param array $request Default request arguments |
| 1285 | 1285 | * @return array Modified request arguments |
| 1286 | 1286 | */ |
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1287 | + public function restrict_media_library($request = array()) { |
|
| 1288 | 1288 | |
| 1289 | - if( ! is_admin() ) { |
|
| 1289 | + if ( ! is_admin()) { |
|
| 1290 | 1290 | return $request; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1293 | + if ( ! $this->is_admin_teacher()) { |
|
| 1294 | 1294 | return $request; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | $screen = get_current_screen(); |
| 1298 | 1298 | |
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1299 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
| 1300 | + $teacher = intval(get_current_user_id()); |
|
| 1301 | 1301 | |
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1302 | + if ($teacher) { |
|
| 1303 | + $request['author__in'] = array($teacher); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | } |
| 1306 | 1306 | |
@@ -1312,20 +1312,20 @@ discard block |
||
| 1312 | 1312 | * @param array $query Default query arguments |
| 1313 | 1313 | * @return array Modified query arguments |
| 1314 | 1314 | */ |
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1315 | + public function restrict_media_library_modal($query = array()) { |
|
| 1316 | 1316 | |
| 1317 | - if( ! is_admin() ) { |
|
| 1317 | + if ( ! is_admin()) { |
|
| 1318 | 1318 | return $query; |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1321 | + if ( ! $this->is_admin_teacher()) { |
|
| 1322 | 1322 | return $query; |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1325 | + $teacher = intval(get_current_user_id()); |
|
| 1326 | 1326 | |
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1327 | + if ($teacher) { |
|
| 1328 | + $query['author__in'] = array($teacher); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | return $query; |
@@ -1338,28 +1338,28 @@ discard block |
||
| 1338 | 1338 | * |
| 1339 | 1339 | * @param int $lesson_id |
| 1340 | 1340 | */ |
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1341 | + public function update_lesson_teacher($lesson_id) { |
|
| 1342 | 1342 | |
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1343 | + if ('lesson' != get_post_type()) { |
|
| 1344 | 1344 | return; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | // this should only run once per request cycle |
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1348 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1352 | + if (empty($course_id) || ! $course_id) { |
|
| 1353 | 1353 | return; |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post($course_id); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1358 | + $lesson_update_args = array( |
|
| 1359 | + 'ID' => $lesson_id, |
|
| 1360 | 1360 | 'post_author' => $course->post_author |
| 1361 | 1361 | ); |
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1362 | + wp_update_post($lesson_update_args); |
|
| 1363 | 1363 | |
| 1364 | 1364 | } // end update_lesson_teacher |
| 1365 | 1365 | |
@@ -1373,21 +1373,21 @@ discard block |
||
| 1373 | 1373 | * @parameters array $wp_query |
| 1374 | 1374 | * @return WP_Query $wp_query |
| 1375 | 1375 | */ |
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1376 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
| 1377 | 1377 | global $current_user; |
| 1378 | 1378 | |
| 1379 | 1379 | //exit early |
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1380 | + if ( ! $this->is_admin_teacher()) { |
|
| 1381 | 1381 | return $wp_query; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1384 | + if ( ! function_exists('get_current_screen')) { |
|
| 1385 | 1385 | return $wp_query; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | $screen = get_current_screen(); |
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1390 | + if (empty($screen)) { |
|
| 1391 | 1391 | return $wp_query; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1400,10 +1400,10 @@ discard block |
||
| 1400 | 1400 | 'lesson_page_lesson-order', |
| 1401 | 1401 | ); |
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if (in_array($screen->id, $limit_screens)) { |
|
| 1404 | 1404 | |
| 1405 | 1405 | // set the query author to the current user to only show those those posts |
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1406 | + $wp_query->set('author', $current_user->ID); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | return $wp_query; |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | * @return void |
| 1424 | 1424 | */ |
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect($user_login, $user) { |
|
| 1427 | 1427 | |
| 1428 | 1428 | if (user_can($user, 'edit_courses')) { |
| 1429 | 1429 | |
@@ -1473,9 +1473,9 @@ discard block |
||
| 1473 | 1473 | * @param bool $restrict default true |
| 1474 | 1474 | */ |
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | 1480 | remove_menu_page('edit.php'); |
| 1481 | 1481 | |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | |
| 1510 | 1510 | global $pagenow; |
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | 1514 | $clauses->query_vars['post_author'] = get_current_user_id(); |
| 1515 | 1515 | |
@@ -1526,15 +1526,15 @@ discard block |
||
| 1526 | 1526 | * |
| 1527 | 1527 | * @return bool |
| 1528 | 1528 | */ |
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1529 | + public static function is_a_teacher($user_id) { |
|
| 1530 | 1530 | |
| 1531 | 1531 | $user = get_user_by('id', $user_id); |
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
| 1534 | 1534 | |
| 1535 | 1535 | return true; |
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + } else { |
|
| 1538 | 1538 | |
| 1539 | 1539 | return false; |
| 1540 | 1540 | |
@@ -1547,14 +1547,14 @@ discard block |
||
| 1547 | 1547 | * |
| 1548 | 1548 | * @since 1.9.0 |
| 1549 | 1549 | */ |
| 1550 | - public static function archive_title(){ |
|
| 1550 | + public static function archive_title() { |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1552 | + $author = get_user_by('id', get_query_var('author')); |
|
| 1553 | 1553 | $author_name = $author->display_name; |
| 1554 | 1554 | ?> |
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
| 1557 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
| 1558 | 1558 | |
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
@@ -1566,9 +1566,9 @@ discard block |
||
| 1566 | 1566 | * |
| 1567 | 1567 | * @since 1.9.0 |
| 1568 | 1568 | */ |
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive() { |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
| 1572 | 1572 | |
| 1573 | 1573 | } |
| 1574 | 1574 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Teacher class |
@@ -414,7 +417,7 @@ discard block |
||
| 414 | 417 | $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
| 415 | 418 | $term_id = $existing_term->term_id; |
| 416 | 419 | |
| 417 | - }else{ |
|
| 420 | + } else{ |
|
| 418 | 421 | |
| 419 | 422 | // for a new term simply get the term from the returned value |
| 420 | 423 | $term_id = $new_term['term_id']; |
@@ -495,7 +498,7 @@ discard block |
||
| 495 | 498 | 'post_author' => $new_author |
| 496 | 499 | ) ); |
| 497 | 500 | } |
| 498 | - }else{ |
|
| 501 | + } else{ |
|
| 499 | 502 | wp_update_post( array( |
| 500 | 503 | 'ID' => $lesson_quizzes, |
| 501 | 504 | 'post_author' => $new_author |
@@ -789,7 +792,7 @@ discard block |
||
| 789 | 792 | // merge the post types instead of overwriting it |
| 790 | 793 | $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
| 791 | 794 | |
| 792 | - }else{ |
|
| 795 | + } else{ |
|
| 793 | 796 | |
| 794 | 797 | // in this instance it is probably just one post type in string format |
| 795 | 798 | $new_post_types = array( $current_post_types , 'course'); |
@@ -979,7 +982,7 @@ discard block |
||
| 979 | 982 | $course_learner_ids[] = $user->ID; |
| 980 | 983 | } |
| 981 | 984 | |
| 982 | - }else{ |
|
| 985 | + } else{ |
|
| 983 | 986 | |
| 984 | 987 | $user = get_userdata( $activity_comments->user_id ); |
| 985 | 988 | $course_learner_ids[] = $user->ID; |
@@ -996,7 +999,7 @@ discard block |
||
| 996 | 999 | |
| 997 | 1000 | $args[ 'include'] = array( 0 ); |
| 998 | 1001 | |
| 999 | - }else{ |
|
| 1002 | + } else{ |
|
| 1000 | 1003 | |
| 1001 | 1004 | $args[ 'include'] = $learner_ids_for_teacher_courses; |
| 1002 | 1005 | |
@@ -1164,7 +1167,7 @@ discard block |
||
| 1164 | 1167 | |
| 1165 | 1168 | $teachers_courses[] = $course->ID; |
| 1166 | 1169 | |
| 1167 | - }else{ |
|
| 1170 | + } else{ |
|
| 1168 | 1171 | |
| 1169 | 1172 | $teachers_courses[] = $course; |
| 1170 | 1173 | |
@@ -1534,7 +1537,7 @@ discard block |
||
| 1534 | 1537 | |
| 1535 | 1538 | return true; |
| 1536 | 1539 | |
| 1537 | - }else{ |
|
| 1540 | + } else{ |
|
| 1538 | 1541 | |
| 1539 | 1542 | return false; |
| 1540 | 1543 | |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * |
| 456 | 456 | * @since 1.1.0 |
| 457 | 457 | * @access public |
| 458 | - * @return void |
|
| 458 | + * @return boolean |
|
| 459 | 459 | */ |
| 460 | 460 | public function assign_role_caps() { |
| 461 | 461 | foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * |
| 481 | 481 | * @since 1.3.0 |
| 482 | 482 | * @access public |
| 483 | - * @return void |
|
| 483 | + * @return boolean |
|
| 484 | 484 | */ |
| 485 | 485 | public function set_default_quiz_grade_type() { |
| 486 | 486 | $args = array( 'post_type' => 'quiz', |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * |
| 503 | 503 | * @since 1.3.0 |
| 504 | 504 | * @access public |
| 505 | - * @return void |
|
| 505 | + * @return boolean |
|
| 506 | 506 | */ |
| 507 | 507 | public function set_default_question_type() { |
| 508 | 508 | $args = array( 'post_type' => 'question', |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @since 1.3.0 |
| 534 | 534 | * @access public |
| 535 | - * @return void |
|
| 535 | + * @return boolean |
|
| 536 | 536 | */ |
| 537 | 537 | public function update_question_answer_data( $n = 50, $offset = 0 ) { |
| 538 | 538 | |
@@ -1429,8 +1429,8 @@ discard block |
||
| 1429 | 1429 | * |
| 1430 | 1430 | * @global type $woothemes_sensei |
| 1431 | 1431 | * @global type $wpdb |
| 1432 | - * @param type $n |
|
| 1433 | - * @param type $offset |
|
| 1432 | + * @param integer $n |
|
| 1433 | + * @param integer $offset |
|
| 1434 | 1434 | * @return boolean |
| 1435 | 1435 | */ |
| 1436 | 1436 | function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
@@ -1674,8 +1674,8 @@ discard block |
||
| 1674 | 1674 | * Update the comment counts for all Courses and Lessons now that sensei comments will no longer be counted. |
| 1675 | 1675 | * |
| 1676 | 1676 | * @global type $wpdb |
| 1677 | - * @param type $n |
|
| 1678 | - * @param type $offset |
|
| 1677 | + * @param integer $n |
|
| 1678 | + * @param integer $offset |
|
| 1679 | 1679 | * @return boolean |
| 1680 | 1680 | */ |
| 1681 | 1681 | public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | '1.7.2' => array( 'auto' => array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ), |
| 71 | 71 | /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
| 72 | 72 | ), |
| 73 | - '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 74 | - 'manual' => array() |
|
| 75 | - ), |
|
| 73 | + '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 74 | + 'manual' => array() |
|
| 75 | + ), |
|
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | 78 | $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } // End For Loop |
| 330 | 330 | } // End For Loop |
| 331 | 331 | |
| 332 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 332 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 333 | 333 | update_option( $this->token . '-upgrades', $this->updates_run ); |
| 334 | 334 | return true; |
| 335 | 335 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | private function set_update_run( $update ) { |
| 448 | 448 | array_push( $this->updates_run, $update ); |
| 449 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 449 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 450 | 450 | update_option( $this->token . '-upgrades', $this->updates_run ); |
| 451 | 451 | } |
| 452 | 452 | |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 921 | + $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 922 | 922 | |
| 923 | - if( $module ) { |
|
| 924 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 925 | - } |
|
| 923 | + if( $module ) { |
|
| 924 | + update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | 927 | } |
| 928 | 928 | |
@@ -1732,22 +1732,22 @@ discard block |
||
| 1732 | 1732 | |
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | - /** |
|
| 1736 | - * WooThemes_Sensei_Updates::enhance_teacher_role |
|
| 1737 | - * |
|
| 1738 | - * This runs the update to create the teacher role |
|
| 1739 | - * @access public |
|
| 1740 | - * @since 1.8.0 |
|
| 1741 | - * @return bool; |
|
| 1742 | - */ |
|
| 1743 | - public function enhance_teacher_role ( ) { |
|
| 1744 | - |
|
| 1745 | - require_once('class-sensei-teacher.php'); |
|
| 1746 | - $teacher = new Sensei_Teacher(); |
|
| 1747 | - $teacher->create_role(); |
|
| 1748 | - return true; |
|
| 1749 | - |
|
| 1750 | - }// end enhance_teacher_role |
|
| 1735 | + /** |
|
| 1736 | + * WooThemes_Sensei_Updates::enhance_teacher_role |
|
| 1737 | + * |
|
| 1738 | + * This runs the update to create the teacher role |
|
| 1739 | + * @access public |
|
| 1740 | + * @since 1.8.0 |
|
| 1741 | + * @return bool; |
|
| 1742 | + */ |
|
| 1743 | + public function enhance_teacher_role ( ) { |
|
| 1744 | + |
|
| 1745 | + require_once('class-sensei-teacher.php'); |
|
| 1746 | + $teacher = new Sensei_Teacher(); |
|
| 1747 | + $teacher->create_role(); |
|
| 1748 | + return true; |
|
| 1749 | + |
|
| 1750 | + }// end enhance_teacher_role |
|
| 1751 | 1751 | |
| 1752 | 1752 | } // End Class |
| 1753 | 1753 | |
@@ -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 Updates Class |
@@ -27,59 +27,59 @@ discard block |
||
| 27 | 27 | * @param string $parent The main Sensei object by Ref. |
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | - public function __construct ( $parent ) { |
|
| 30 | + public function __construct($parent) { |
|
| 31 | 31 | |
| 32 | 32 | // Setup object data |
| 33 | 33 | $this->parent = $parent; |
| 34 | - $this->updates_run = get_option( $this->token . '-upgrades', array() ); |
|
| 34 | + $this->updates_run = get_option($this->token.'-upgrades', array()); |
|
| 35 | 35 | |
| 36 | 36 | // The list of upgrades to run |
| 37 | - $this->updates = array( '1.1.0' => array( 'auto' => array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ), |
|
| 37 | + $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
|
| 38 | 38 | 'manual' => array() |
| 39 | 39 | ), |
| 40 | - '1.3.0' => array( 'auto' => array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ), |
|
| 41 | - 'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) ) |
|
| 40 | + '1.3.0' => array('auto' => array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')), |
|
| 41 | + 'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei')) |
|
| 42 | 42 | ), |
| 43 | - 'manual' => array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) ) |
|
| 43 | + 'manual' => array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei'))) |
|
| 44 | 44 | ), |
| 45 | - '1.4.0' => array( 'auto' => array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ), |
|
| 45 | + '1.4.0' => array('auto' => array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))), |
|
| 46 | 46 | 'manual' => array() |
| 47 | 47 | ), |
| 48 | - '1.5.0' => array( 'auto' => array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ), |
|
| 49 | - 'manual' => array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ), |
|
| 50 | - 'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ), |
|
| 51 | - 'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) ) |
|
| 48 | + '1.5.0' => array('auto' => array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))), |
|
| 49 | + 'manual' => array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')), |
|
| 50 | + 'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')), |
|
| 51 | + 'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei'))) |
|
| 52 | 52 | ), |
| 53 | - '1.6.0' => array( 'auto' => array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ), |
|
| 54 | - 'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ), |
|
| 55 | - 'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ), |
|
| 56 | - 'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ), |
|
| 57 | - 'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ), |
|
| 53 | + '1.6.0' => array('auto' => array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')), |
|
| 54 | + 'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')), |
|
| 55 | + 'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')), |
|
| 56 | + 'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')), |
|
| 57 | + 'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),), |
|
| 58 | 58 | 'manual' => array() |
| 59 | 59 | ), |
| 60 | - '1.7.0' => array( 'auto' => array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ), |
|
| 61 | - 'forced' => array( 'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ), |
|
| 62 | - 'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ), |
|
| 63 | - 'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ), |
|
| 64 | - 'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ), |
|
| 65 | - 'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ), |
|
| 66 | - 'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ), |
|
| 67 | - 'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ), |
|
| 68 | - 'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ), |
|
| 60 | + '1.7.0' => array('auto' => array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),), |
|
| 61 | + 'forced' => array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')), |
|
| 62 | + 'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')), |
|
| 63 | + 'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')), |
|
| 64 | + 'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')), |
|
| 65 | + 'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')), |
|
| 66 | + 'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')), |
|
| 67 | + 'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')), |
|
| 68 | + 'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),), |
|
| 69 | 69 | ), |
| 70 | - '1.7.2' => array( 'auto' => array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ), |
|
| 70 | + '1.7.2' => array('auto' => array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),), |
|
| 71 | 71 | /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
| 72 | 72 | ), |
| 73 | - '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 73 | + '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),), |
|
| 74 | 74 | 'manual' => array() |
| 75 | 75 | ), |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
|
| 79 | - $this->version = get_option( $this->token . '-version' ); |
|
| 78 | + $this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates); |
|
| 79 | + $this->version = get_option($this->token.'-version'); |
|
| 80 | 80 | |
| 81 | 81 | // Manual Update Screen |
| 82 | - add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 ); |
|
| 82 | + add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
|
| 83 | 83 | |
| 84 | 84 | } // End __construct() |
| 85 | 85 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | 93 | public function add_update_admin_screen() { |
| 94 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 95 | - add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) ); |
|
| 94 | + if (current_user_can('manage_options')) { |
|
| 95 | + add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page')); |
|
| 96 | 96 | } |
| 97 | 97 | } // End add_update_admin_screen() |
| 98 | 98 | |
@@ -106,80 +106,80 @@ discard block |
||
| 106 | 106 | public function sensei_updates_page() { |
| 107 | 107 | |
| 108 | 108 | // Only allow admins to load this page and run the update functions |
| 109 | - if( current_user_can( 'manage_options' ) ) { |
|
| 109 | + if (current_user_can('manage_options')) { |
|
| 110 | 110 | ?> |
| 111 | 111 | <div class="wrap"> |
| 112 | 112 | |
| 113 | 113 | <div id="icon-woothemes-sensei" class="icon32"><br></div> |
| 114 | - <h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2> |
|
| 114 | + <h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2> |
|
| 115 | 115 | |
| 116 | 116 | <?php |
| 117 | - if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) { |
|
| 117 | + if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
| 118 | 118 | |
| 119 | 119 | // Setup the data variables |
| 120 | - $n = intval( $_GET['n'] ); |
|
| 120 | + $n = intval($_GET['n']); |
|
| 121 | 121 | $functions_list = ''; |
| 122 | 122 | $done_processing = false; |
| 123 | 123 | |
| 124 | 124 | // Check for updates to run |
| 125 | - if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) { |
|
| 125 | + if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) { |
|
| 126 | 126 | |
| 127 | - foreach ( $_POST['checked'] as $key => $value ) { |
|
| 127 | + foreach ($_POST['checked'] as $key => $value) { |
|
| 128 | 128 | |
| 129 | 129 | // Dynamic function call |
| 130 | - if ( method_exists( $this, $value) ) { |
|
| 131 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 130 | + if (method_exists($this, $value)) { |
|
| 131 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 132 | 132 | } else { |
| 133 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 133 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 134 | 134 | } // End If Statement |
| 135 | 135 | |
| 136 | 136 | // Add to functions list get args |
| 137 | - if ( '' == $functions_list ) { |
|
| 137 | + if ('' == $functions_list) { |
|
| 138 | 138 | $functions_list .= $value; |
| 139 | 139 | } else { |
| 140 | - $functions_list .= '+' . $value; |
|
| 140 | + $functions_list .= '+'.$value; |
|
| 141 | 141 | } // End If Statement |
| 142 | 142 | |
| 143 | 143 | // Mark update has having been run |
| 144 | - $this->set_update_run( $value ); |
|
| 144 | + $this->set_update_run($value); |
|
| 145 | 145 | |
| 146 | 146 | } // End For Loop |
| 147 | 147 | |
| 148 | 148 | } // End If Statement |
| 149 | 149 | |
| 150 | 150 | // Check for updates to run |
| 151 | - if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) { |
|
| 151 | + if (isset($_GET['functions']) && '' != $_GET['functions']) { |
|
| 152 | 152 | |
| 153 | 153 | // Existing functions from GET variables instead of POST |
| 154 | 154 | $functions_array = $_GET['functions']; |
| 155 | 155 | |
| 156 | - foreach ( $functions_array as $key => $value ) { |
|
| 156 | + foreach ($functions_array as $key => $value) { |
|
| 157 | 157 | |
| 158 | 158 | // Dynamic function call |
| 159 | - if ( method_exists( $this, $value) ) { |
|
| 160 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 159 | + if (method_exists($this, $value)) { |
|
| 160 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 161 | 161 | } else { |
| 162 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 162 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 163 | 163 | } // End If Statement |
| 164 | 164 | |
| 165 | 165 | // Add to functions list get args |
| 166 | - if ( '' == $functions_list ) { |
|
| 166 | + if ('' == $functions_list) { |
|
| 167 | 167 | $functions_list .= $value; |
| 168 | 168 | } else { |
| 169 | - $functions_list .= '+' . $value; |
|
| 169 | + $functions_list .= '+'.$value; |
|
| 170 | 170 | } // End If Statement |
| 171 | 171 | |
| 172 | - $this->set_update_run( $value ); |
|
| 172 | + $this->set_update_run($value); |
|
| 173 | 173 | |
| 174 | 174 | } // End For Loop |
| 175 | 175 | |
| 176 | 176 | } // End If Statement |
| 177 | 177 | |
| 178 | - if ( ! $done_processing ) { ?> |
|
| 178 | + if ( ! $done_processing) { ?> |
|
| 179 | 179 | |
| 180 | - <h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3> |
|
| 180 | + <h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3> |
|
| 181 | 181 | |
| 182 | - <p><?php _e( 'If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p> |
|
| 182 | + <p><?php _e('If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p> |
|
| 183 | 183 | <script type='text/javascript'> |
| 184 | 184 | <!-- |
| 185 | 185 | function sensei_nextpage() { |
@@ -191,48 +191,48 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | } else { ?> |
| 193 | 193 | |
| 194 | - <p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p> |
|
| 195 | - <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p> |
|
| 194 | + <p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p> |
|
| 195 | + <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p> |
|
| 196 | 196 | |
| 197 | 197 | <?php } // End If Statement |
| 198 | 198 | |
| 199 | 199 | } else { ?> |
| 200 | 200 | |
| 201 | - <h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3> |
|
| 202 | - <p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p> |
|
| 201 | + <h3><?php _e('Updates', 'woothemes-sensei'); ?></h3> |
|
| 202 | + <p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p> |
|
| 203 | 203 | |
| 204 | - <div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div> |
|
| 204 | + <div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div> |
|
| 205 | 205 | |
| 206 | 206 | <table class="widefat" cellspacing="0" id="update-plugins-table"> |
| 207 | 207 | |
| 208 | 208 | <thead> |
| 209 | 209 | <tr> |
| 210 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 211 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 212 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 210 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 211 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 212 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 213 | 213 | </tr> |
| 214 | 214 | </thead> |
| 215 | 215 | |
| 216 | 216 | <tfoot> |
| 217 | 217 | <tr> |
| 218 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 219 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 220 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 218 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 219 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 220 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 221 | 221 | </tr> |
| 222 | 222 | </tfoot> |
| 223 | 223 | |
| 224 | 224 | <tbody class="updates"> |
| 225 | 225 | <?php |
| 226 | 226 | // Sort updates with the latest at the top |
| 227 | - uksort( $this->updates, array( $this, 'sort_updates' ) ); |
|
| 228 | - $this->updates = array_reverse( $this->updates, true ); |
|
| 227 | + uksort($this->updates, array($this, 'sort_updates')); |
|
| 228 | + $this->updates = array_reverse($this->updates, true); |
|
| 229 | 229 | $class = 'alternate'; |
| 230 | - foreach( $this->updates as $version => $version_updates ) { |
|
| 231 | - foreach( $version_updates as $type => $updates ) { |
|
| 232 | - foreach( $updates as $update => $data ) { |
|
| 233 | - $update_run = $this->has_update_run( $update ); |
|
| 230 | + foreach ($this->updates as $version => $version_updates) { |
|
| 231 | + foreach ($version_updates as $type => $updates) { |
|
| 232 | + foreach ($updates as $update => $data) { |
|
| 233 | + $update_run = $this->has_update_run($update); |
|
| 234 | 234 | $product = 'Sensei'; |
| 235 | - if ( isset( $data['product'] ) && '' != $data['product'] ) { |
|
| 235 | + if (isset($data['product']) && '' != $data['product']) { |
|
| 236 | 236 | $product = $data['product']; |
| 237 | 237 | } // End If Statement |
| 238 | 238 | ?> |
@@ -242,21 +242,21 @@ discard block |
||
| 242 | 242 | <p> |
| 243 | 243 | <input type="hidden" name="checked[]" value="<?php echo $update; ?>"> |
| 244 | 244 | <strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br> |
| 245 | - <em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em> |
|
| 245 | + <em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em> |
|
| 246 | 246 | </p> |
| 247 | 247 | </td> |
| 248 | 248 | <?php |
| 249 | - $type_label = __( 'Auto', 'woothemes-sensei' ); |
|
| 250 | - if( $type != 'auto' ) { |
|
| 251 | - $type_label = __( 'Manual', 'woothemes-sensei' ); |
|
| 249 | + $type_label = __('Auto', 'woothemes-sensei'); |
|
| 250 | + if ($type != 'auto') { |
|
| 251 | + $type_label = __('Manual', 'woothemes-sensei'); |
|
| 252 | 252 | } |
| 253 | 253 | ?> |
| 254 | 254 | <td><p><?php echo $type_label; ?></p></td> |
| 255 | - <td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td> |
|
| 255 | + <td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td> |
|
| 256 | 256 | </tr> |
| 257 | 257 | </form> |
| 258 | 258 | <?php |
| 259 | - if( 'alternate' == $class ) { |
|
| 259 | + if ('alternate' == $class) { |
|
| 260 | 260 | $class = ''; |
| 261 | 261 | } else { |
| 262 | 262 | $class = 'alternate'; |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param string $b Second key |
| 284 | 284 | * @return integer |
| 285 | 285 | */ |
| 286 | - private function sort_updates( $a, $b ) { |
|
| 287 | - return strcmp( $a, $b ); |
|
| 286 | + private function sort_updates($a, $b) { |
|
| 287 | + return strcmp($a, $b); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,32 +295,32 @@ discard block |
||
| 295 | 295 | * @access public |
| 296 | 296 | * @return boolean |
| 297 | 297 | */ |
| 298 | - public function update ( $type = 'auto' ) { |
|
| 298 | + public function update($type = 'auto') { |
|
| 299 | 299 | |
| 300 | 300 | // Only allow admins to run update functions |
| 301 | - if( current_user_can( 'manage_options' ) ) { |
|
| 301 | + if (current_user_can('manage_options')) { |
|
| 302 | 302 | |
| 303 | 303 | $this->force_updates(); |
| 304 | 304 | |
| 305 | 305 | // Run through all functions |
| 306 | - foreach ( $this->updates as $version => $value ) { |
|
| 307 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 308 | - if ( $upgrade_type == $type ) { |
|
| 306 | + foreach ($this->updates as $version => $value) { |
|
| 307 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 308 | + if ($upgrade_type == $type) { |
|
| 309 | 309 | $updated = false; |
| 310 | 310 | // Run the update function |
| 311 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 312 | - if ( isset( $function_name ) && '' != $function_name ) { |
|
| 313 | - if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
| 311 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 312 | + if (isset($function_name) && '' != $function_name) { |
|
| 313 | + if ( ! in_array($function_name, $this->updates_run)) { |
|
| 314 | 314 | $updated = false; |
| 315 | - if ( method_exists( $this, $function_name ) ) { |
|
| 316 | - $updated = call_user_func( array( $this, $function_name ) ); |
|
| 317 | - } elseif( function_exists( $function_name ) ) { |
|
| 318 | - $updated = call_user_func( $function_name ); |
|
| 315 | + if (method_exists($this, $function_name)) { |
|
| 316 | + $updated = call_user_func(array($this, $function_name)); |
|
| 317 | + } elseif (function_exists($function_name)) { |
|
| 318 | + $updated = call_user_func($function_name); |
|
| 319 | 319 | } else { |
| 320 | 320 | // Nothing to see here... |
| 321 | 321 | } // End If Statement |
| 322 | - if ( $updated ) { |
|
| 323 | - array_push( $this->updates_run, $function_name ); |
|
| 322 | + if ($updated) { |
|
| 323 | + array_push($this->updates_run, $function_name); |
|
| 324 | 324 | } // End If Statement |
| 325 | 325 | } |
| 326 | 326 | } // End If Statement |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | } // End For Loop |
| 330 | 330 | } // End For Loop |
| 331 | 331 | |
| 332 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 333 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
| 332 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 333 | + update_option($this->token.'-upgrades', $this->updates_run); |
|
| 334 | 334 | return true; |
| 335 | 335 | |
| 336 | 336 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | private function force_updates() { |
| 341 | 341 | |
| 342 | - if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) { |
|
| 342 | + if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) { |
|
| 343 | 343 | |
| 344 | 344 | // $skip_forced_updates = false; |
| 345 | 345 | // if( ! get_option( 'woothemes-sensei-force-updates', false ) ) { |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // Force critical updates if only if lessons already exist |
| 350 | 350 | $skip_forced_updates = false; |
| 351 | - $lesson_posts = wp_count_posts( 'lesson' ); |
|
| 352 | - if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) { |
|
| 351 | + $lesson_posts = wp_count_posts('lesson'); |
|
| 352 | + if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) { |
|
| 353 | 353 | $skip_forced_updates = true; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -357,69 +357,69 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | $updates_to_run = array(); |
| 359 | 359 | |
| 360 | - foreach ( $this->updates as $version => $value ) { |
|
| 361 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 362 | - if ( $upgrade_type == 'forced' ) { |
|
| 363 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 360 | + foreach ($this->updates as $version => $value) { |
|
| 361 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 362 | + if ($upgrade_type == 'forced') { |
|
| 363 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 364 | 364 | |
| 365 | - if( $skip_forced_updates ) { |
|
| 366 | - $this->set_update_run( $function_name ); |
|
| 365 | + if ($skip_forced_updates) { |
|
| 366 | + $this->set_update_run($function_name); |
|
| 367 | 367 | continue; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $update_run = $this->has_update_run( $function_name ); |
|
| 370 | + $update_run = $this->has_update_run($function_name); |
|
| 371 | 371 | |
| 372 | - if( ! $update_run ) { |
|
| 372 | + if ( ! $update_run) { |
|
| 373 | 373 | $use_the_force = true; |
| 374 | - $updates_to_run[ $function_name ] = $update_data; |
|
| 374 | + $updates_to_run[$function_name] = $update_data; |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if( $skip_forced_updates ) { |
|
| 381 | + if ($skip_forced_updates) { |
|
| 382 | 382 | return; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if( $use_the_force && 0 < count( $updates_to_run ) ) { |
|
| 385 | + if ($use_the_force && 0 < count($updates_to_run)) { |
|
| 386 | 386 | |
| 387 | - $update_title = __( 'Important Sensei updates required', 'woothemes-sensei' ); |
|
| 387 | + $update_title = __('Important Sensei updates required', 'woothemes-sensei'); |
|
| 388 | 388 | |
| 389 | - $update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n"; |
|
| 389 | + $update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n"; |
|
| 390 | 390 | |
| 391 | 391 | // $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n"; |
| 392 | 392 | |
| 393 | - $update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 393 | + $update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n"; |
|
| 394 | 394 | |
| 395 | - $update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 395 | + $update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 396 | 396 | |
| 397 | - $update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 397 | + $update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n"; |
|
| 398 | 398 | |
| 399 | - $update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 399 | + $update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 400 | 400 | |
| 401 | - $update_message .= '<ol>' . "\n"; |
|
| 401 | + $update_message .= '<ol>'."\n"; |
|
| 402 | 402 | |
| 403 | - foreach( $updates_to_run as $function => $data ) { |
|
| 403 | + foreach ($updates_to_run as $function => $data) { |
|
| 404 | 404 | |
| 405 | - if( ! isset( $data['title'] ) ) { |
|
| 405 | + if ( ! isset($data['title'])) { |
|
| 406 | 406 | break; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>'; |
|
| 409 | + $update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $update_message .= '</ol>' . "\n"; |
|
| 412 | + $update_message .= '</ol>'."\n"; |
|
| 413 | 413 | |
| 414 | - switch( $version ) { |
|
| 414 | + switch ($version) { |
|
| 415 | 415 | |
| 416 | 416 | case '1.7.0': |
| 417 | - $update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n"; |
|
| 417 | + $update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n"; |
|
| 418 | 418 | break; |
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - wp_die( $update_message, $update_title ); |
|
| 422 | + wp_die($update_message, $update_title); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @since 1.4.0 |
| 432 | 432 | * @return boolean |
| 433 | 433 | */ |
| 434 | - private function has_update_run( $update ) { |
|
| 435 | - if ( in_array( $update, $this->updates_run ) ) { |
|
| 434 | + private function has_update_run($update) { |
|
| 435 | + if (in_array($update, $this->updates_run)) { |
|
| 436 | 436 | return true; |
| 437 | 437 | } |
| 438 | 438 | return false; |
@@ -444,10 +444,10 @@ discard block |
||
| 444 | 444 | * @param string $update Update to process |
| 445 | 445 | * @since 1.4.0 |
| 446 | 446 | */ |
| 447 | - private function set_update_run( $update ) { |
|
| 448 | - array_push( $this->updates_run, $update ); |
|
| 449 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 450 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
| 447 | + private function set_update_run($update) { |
|
| 448 | + array_push($this->updates_run, $update); |
|
| 449 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 450 | + update_option($this->token.'-upgrades', $this->updates_run); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -458,15 +458,15 @@ discard block |
||
| 458 | 458 | * @return void |
| 459 | 459 | */ |
| 460 | 460 | public function assign_role_caps() { |
| 461 | - foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
|
| 462 | - foreach ( $role_cap_set as $role_key => $capabilities_array ) { |
|
| 461 | + foreach ($this->parent->post_types->role_caps as $role_cap_set) { |
|
| 462 | + foreach ($role_cap_set as $role_key => $capabilities_array) { |
|
| 463 | 463 | /* Get the role. */ |
| 464 | - $role = get_role( $role_key ); |
|
| 465 | - foreach ( $capabilities_array as $cap_name ) { |
|
| 464 | + $role = get_role($role_key); |
|
| 465 | + foreach ($capabilities_array as $cap_name) { |
|
| 466 | 466 | /* If the role exists, add required capabilities for the plugin. */ |
| 467 | - if ( !empty( $role ) ) { |
|
| 468 | - if ( !$role->has_cap( $cap_name ) ) { |
|
| 469 | - $role->add_cap( $cap_name ); |
|
| 467 | + if ( ! empty($role)) { |
|
| 468 | + if ( ! $role->has_cap($cap_name)) { |
|
| 469 | + $role->add_cap($cap_name); |
|
| 470 | 470 | } // End If Statement |
| 471 | 471 | } // End If Statement |
| 472 | 472 | } // End For Loop |
@@ -483,16 +483,16 @@ discard block |
||
| 483 | 483 | * @return void |
| 484 | 484 | */ |
| 485 | 485 | public function set_default_quiz_grade_type() { |
| 486 | - $args = array( 'post_type' => 'quiz', |
|
| 486 | + $args = array('post_type' => 'quiz', |
|
| 487 | 487 | 'posts_per_page' => -1, |
| 488 | 488 | 'post_status' => 'publish', |
| 489 | 489 | 'suppress_filters' => 0 |
| 490 | 490 | ); |
| 491 | - $quizzes = get_posts( $args ); |
|
| 491 | + $quizzes = get_posts($args); |
|
| 492 | 492 | |
| 493 | - foreach( $quizzes as $quiz ) { |
|
| 494 | - update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' ); |
|
| 495 | - update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' ); |
|
| 493 | + foreach ($quizzes as $quiz) { |
|
| 494 | + update_post_meta($quiz->ID, '_quiz_grade_type', 'auto'); |
|
| 495 | + update_post_meta($quiz->ID, '_quiz_grade_type_disabled', ''); |
|
| 496 | 496 | } |
| 497 | 497 | return true; |
| 498 | 498 | } // End set_default_quiz_grade_type |
@@ -505,23 +505,23 @@ discard block |
||
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | 507 | public function set_default_question_type() { |
| 508 | - $args = array( 'post_type' => 'question', |
|
| 508 | + $args = array('post_type' => 'question', |
|
| 509 | 509 | 'posts_per_page' => -1, |
| 510 | 510 | 'post_status' => 'publish', |
| 511 | 511 | 'suppress_filters' => 0 |
| 512 | 512 | ); |
| 513 | - $questions = get_posts( $args ); |
|
| 513 | + $questions = get_posts($args); |
|
| 514 | 514 | |
| 515 | 515 | $already_run = true; |
| 516 | - foreach( $questions as $question ) { |
|
| 517 | - if( $already_run ) { |
|
| 518 | - $terms = wp_get_post_terms( $question->ID, 'question-type' ); |
|
| 519 | - if( is_array( $terms ) && count( $terms ) > 0 ) { |
|
| 516 | + foreach ($questions as $question) { |
|
| 517 | + if ($already_run) { |
|
| 518 | + $terms = wp_get_post_terms($question->ID, 'question-type'); |
|
| 519 | + if (is_array($terms) && count($terms) > 0) { |
|
| 520 | 520 | break; |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | $already_run = false; |
| 524 | - wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' ); |
|
| 524 | + wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | return true; |
@@ -534,90 +534,90 @@ discard block |
||
| 534 | 534 | * @access public |
| 535 | 535 | * @return void |
| 536 | 536 | */ |
| 537 | - public function update_question_answer_data( $n = 50, $offset = 0 ) { |
|
| 537 | + public function update_question_answer_data($n = 50, $offset = 0) { |
|
| 538 | 538 | |
| 539 | 539 | // Get Total Number of Updates to run |
| 540 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 540 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 541 | 541 | $quiz_count_published = $quiz_count_object->publish; |
| 542 | 542 | |
| 543 | 543 | // Calculate if this is the last page |
| 544 | - if ( 0 == $offset ) { |
|
| 544 | + if (0 == $offset) { |
|
| 545 | 545 | $current_page = 1; |
| 546 | 546 | } else { |
| 547 | - $current_page = intval( $offset / $n ); |
|
| 547 | + $current_page = intval($offset / $n); |
|
| 548 | 548 | } // End If Statement |
| 549 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 549 | + $total_pages = intval($quiz_count_published / $n); |
|
| 550 | 550 | |
| 551 | 551 | |
| 552 | - $args = array( 'post_type' => 'quiz', |
|
| 552 | + $args = array('post_type' => 'quiz', |
|
| 553 | 553 | 'posts_per_page' => $n, |
| 554 | 554 | 'offset' => $offset, |
| 555 | 555 | 'post_status' => 'publish', |
| 556 | 556 | 'suppress_filters' => 0 |
| 557 | 557 | ); |
| 558 | - $quizzes = get_posts( $args ); |
|
| 558 | + $quizzes = get_posts($args); |
|
| 559 | 559 | |
| 560 | 560 | $old_answers = array(); |
| 561 | 561 | $right_answers = array(); |
| 562 | 562 | $old_user_answers = array(); |
| 563 | 563 | |
| 564 | - if( is_array( $quizzes ) ) { |
|
| 565 | - foreach( $quizzes as $quiz ) { |
|
| 564 | + if (is_array($quizzes)) { |
|
| 565 | + foreach ($quizzes as $quiz) { |
|
| 566 | 566 | $quiz_id = $quiz->ID; |
| 567 | 567 | |
| 568 | 568 | // Get current user answers |
| 569 | - $comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true ); |
|
| 569 | + $comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true); |
|
| 570 | 570 | // Need to always return an array, even with only 1 item |
| 571 | - if ( !is_array($comments) ) { |
|
| 572 | - $comments = array( $comments ); |
|
| 571 | + if ( ! is_array($comments)) { |
|
| 572 | + $comments = array($comments); |
|
| 573 | 573 | } |
| 574 | - foreach ( $comments as $comment ) { |
|
| 574 | + foreach ($comments as $comment) { |
|
| 575 | 575 | $user_id = $comment->user_id; |
| 576 | - $content = maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 577 | - $old_user_answers[ $quiz_id ][ $user_id ] = $content; |
|
| 576 | + $content = maybe_unserialize(base64_decode($comment->comment_content)); |
|
| 577 | + $old_user_answers[$quiz_id][$user_id] = $content; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | // Get correct answers |
| 581 | - $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 582 | - if( is_array( $questions ) ) { |
|
| 583 | - foreach( $questions as $question ) { |
|
| 584 | - $right_answer = get_post_meta( $question->ID, '_question_right_answer', true ); |
|
| 585 | - $right_answers[ $quiz_id ][ $question->ID ] = $right_answer; |
|
| 581 | + $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 582 | + if (is_array($questions)) { |
|
| 583 | + foreach ($questions as $question) { |
|
| 584 | + $right_answer = get_post_meta($question->ID, '_question_right_answer', true); |
|
| 585 | + $right_answers[$quiz_id][$question->ID] = $right_answer; |
|
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if( is_array( $right_answers ) ) { |
|
| 592 | - foreach( $right_answers as $quiz_id => $question ) { |
|
| 591 | + if (is_array($right_answers)) { |
|
| 592 | + foreach ($right_answers as $quiz_id => $question) { |
|
| 593 | 593 | $count = 0; |
| 594 | - if( is_array( $question ) ) { |
|
| 595 | - foreach( $question as $question_id => $answer ) { |
|
| 594 | + if (is_array($question)) { |
|
| 595 | + foreach ($question as $question_id => $answer) { |
|
| 596 | 596 | ++$count; |
| 597 | - if( isset( $old_user_answers[ $quiz_id ] ) ) { |
|
| 598 | - $answers_linkup[ $quiz_id ][ $count ] = $question_id; |
|
| 597 | + if (isset($old_user_answers[$quiz_id])) { |
|
| 598 | + $answers_linkup[$quiz_id][$count] = $question_id; |
|
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - if( is_array( $old_user_answers ) ) { |
|
| 606 | - foreach( $old_user_answers as $quiz_id => $user_answers ) { |
|
| 607 | - foreach( $user_answers as $user_id => $answers ) { |
|
| 608 | - foreach( $answers as $answer_id => $user_answer ) { |
|
| 609 | - $question_id = $answers_linkup[ $quiz_id ][ $answer_id ]; |
|
| 610 | - $new_user_answers[ $question_id ] = $user_answer; |
|
| 611 | - WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id ); |
|
| 605 | + if (is_array($old_user_answers)) { |
|
| 606 | + foreach ($old_user_answers as $quiz_id => $user_answers) { |
|
| 607 | + foreach ($user_answers as $user_id => $answers) { |
|
| 608 | + foreach ($answers as $answer_id => $user_answer) { |
|
| 609 | + $question_id = $answers_linkup[$quiz_id][$answer_id]; |
|
| 610 | + $new_user_answers[$question_id] = $user_answer; |
|
| 611 | + WooThemes_Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id); |
|
| 612 | 612 | } |
| 613 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 614 | - WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 615 | - WooThemes_Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id ); |
|
| 613 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 614 | + WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 615 | + WooThemes_Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - if ( $current_page == $total_pages ) { |
|
| 620 | + if ($current_page == $total_pages) { |
|
| 621 | 621 | return true; |
| 622 | 622 | } else { |
| 623 | 623 | return false; |
@@ -632,15 +632,15 @@ discard block |
||
| 632 | 632 | * @return boolean |
| 633 | 633 | */ |
| 634 | 634 | public function update_question_grade_points() { |
| 635 | - $args = array( 'post_type' => 'question', |
|
| 635 | + $args = array('post_type' => 'question', |
|
| 636 | 636 | 'posts_per_page' => -1, |
| 637 | 637 | 'post_status' => 'publish', |
| 638 | 638 | 'suppress_filters' => 0 |
| 639 | 639 | ); |
| 640 | - $questions = get_posts( $args ); |
|
| 640 | + $questions = get_posts($args); |
|
| 641 | 641 | |
| 642 | - foreach( $questions as $question ) { |
|
| 643 | - update_post_meta( $question->ID, '_question_grade', '1' ); |
|
| 642 | + foreach ($questions as $question) { |
|
| 643 | + update_post_meta($question->ID, '_question_grade', '1'); |
|
| 644 | 644 | } |
| 645 | 645 | return true; |
| 646 | 646 | } // End update_question_grade_points |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | * @return boolean |
| 653 | 653 | */ |
| 654 | 654 | public function convert_essay_paste_questions() { |
| 655 | - $args = array( 'post_type' => 'question', |
|
| 655 | + $args = array('post_type' => 'question', |
|
| 656 | 656 | 'posts_per_page' => -1, |
| 657 | 657 | 'post_status' => 'publish', |
| 658 | 658 | 'tax_query' => array( |
@@ -664,14 +664,14 @@ discard block |
||
| 664 | 664 | ), |
| 665 | 665 | 'suppress_filters' => 0 |
| 666 | 666 | ); |
| 667 | - $questions = get_posts( $args ); |
|
| 667 | + $questions = get_posts($args); |
|
| 668 | 668 | |
| 669 | - foreach( $questions as $question ) { |
|
| 670 | - wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false ); |
|
| 669 | + foreach ($questions as $question) { |
|
| 670 | + wp_set_object_terms($question->ID, 'multi-line', 'question-type', false); |
|
| 671 | 671 | |
| 672 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 673 | - if( 0 < intval( $quiz_id ) ) { |
|
| 674 | - add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true ); |
|
| 672 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 673 | + if (0 < intval($quiz_id)) { |
|
| 674 | + add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | return true; |
@@ -683,33 +683,33 @@ discard block |
||
| 683 | 683 | * @since 1.5.0 |
| 684 | 684 | * @return boolean |
| 685 | 685 | */ |
| 686 | - public function set_random_question_order( $n = 50, $offset = 0 ) { |
|
| 686 | + public function set_random_question_order($n = 50, $offset = 0) { |
|
| 687 | 687 | |
| 688 | 688 | // Get Total Number of Updates to run |
| 689 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 689 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 690 | 690 | $quiz_count_published = $quiz_count_object->publish; |
| 691 | 691 | |
| 692 | 692 | // Calculate if this is the last page |
| 693 | - if ( 0 == $offset ) { |
|
| 693 | + if (0 == $offset) { |
|
| 694 | 694 | $current_page = 1; |
| 695 | 695 | } else { |
| 696 | - $current_page = intval( $offset / $n ); |
|
| 696 | + $current_page = intval($offset / $n); |
|
| 697 | 697 | } // End If Statement |
| 698 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 698 | + $total_pages = intval($quiz_count_published / $n); |
|
| 699 | 699 | |
| 700 | - $args = array( 'post_type' => 'quiz', |
|
| 700 | + $args = array('post_type' => 'quiz', |
|
| 701 | 701 | 'post_status' => 'any', |
| 702 | 702 | 'posts_per_page' => $n, |
| 703 | 703 | 'offset' => $offset, |
| 704 | 704 | 'suppress_filters' => 0 |
| 705 | 705 | ); |
| 706 | - $quizzes = get_posts( $args ); |
|
| 706 | + $quizzes = get_posts($args); |
|
| 707 | 707 | |
| 708 | - foreach( $quizzes as $quiz ) { |
|
| 709 | - update_post_meta( $quiz->ID, '_random_question_order', 'yes' ); |
|
| 708 | + foreach ($quizzes as $quiz) { |
|
| 709 | + update_post_meta($quiz->ID, '_random_question_order', 'yes'); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - if ( $current_page == $total_pages ) { |
|
| 712 | + if ($current_page == $total_pages) { |
|
| 713 | 713 | return true; |
| 714 | 714 | } else { |
| 715 | 715 | return false; |
@@ -723,37 +723,37 @@ discard block |
||
| 723 | 723 | * @since 1.5.0 |
| 724 | 724 | * @return boolean |
| 725 | 725 | */ |
| 726 | - public function set_default_show_question_count( $n = 50, $offset = 0 ) { |
|
| 726 | + public function set_default_show_question_count($n = 50, $offset = 0) { |
|
| 727 | 727 | |
| 728 | - $args = array( 'post_type' => 'quiz', |
|
| 728 | + $args = array('post_type' => 'quiz', |
|
| 729 | 729 | 'post_status' => 'any', |
| 730 | 730 | 'posts_per_page' => $n, |
| 731 | 731 | 'offset' => $offset, |
| 732 | 732 | 'meta_key' => '_show_questions', |
| 733 | 733 | 'suppress_filters' => 0 |
| 734 | 734 | ); |
| 735 | - $quizzes = get_posts( $args ); |
|
| 735 | + $quizzes = get_posts($args); |
|
| 736 | 736 | |
| 737 | - $total_quizzes = count( $quizzes ); |
|
| 737 | + $total_quizzes = count($quizzes); |
|
| 738 | 738 | |
| 739 | - if( 0 == intval( $total_quizzes ) ) { |
|
| 739 | + if (0 == intval($total_quizzes)) { |
|
| 740 | 740 | return true; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - foreach( $quizzes as $quiz ) { |
|
| 744 | - delete_post_meta( $quiz->ID, '_show_questions' ); |
|
| 743 | + foreach ($quizzes as $quiz) { |
|
| 744 | + delete_post_meta($quiz->ID, '_show_questions'); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $total_pages = intval( $total_quizzes / $n ); |
|
| 747 | + $total_pages = intval($total_quizzes / $n); |
|
| 748 | 748 | |
| 749 | 749 | // Calculate if this is the last page |
| 750 | - if ( 0 == $offset ) { |
|
| 750 | + if (0 == $offset) { |
|
| 751 | 751 | $current_page = 1; |
| 752 | 752 | } else { |
| 753 | - $current_page = intval( $offset / $n ); |
|
| 753 | + $current_page = intval($offset / $n); |
|
| 754 | 754 | } // End If Statement |
| 755 | 755 | |
| 756 | - if ( $current_page == $total_pages ) { |
|
| 756 | + if ($current_page == $total_pages) { |
|
| 757 | 757 | return true; |
| 758 | 758 | } else { |
| 759 | 759 | return false; |
@@ -761,17 +761,17 @@ discard block |
||
| 761 | 761 | |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - public function remove_deleted_user_activity( $n = 50, $offset = 0 ) { |
|
| 764 | + public function remove_deleted_user_activity($n = 50, $offset = 0) { |
|
| 765 | 765 | |
| 766 | 766 | |
| 767 | 767 | // remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 768 | 768 | |
| 769 | - $all_activity = get_comments( array( 'status' => 'approve' ) ); |
|
| 769 | + $all_activity = get_comments(array('status' => 'approve')); |
|
| 770 | 770 | $activity_count = array(); |
| 771 | - foreach( $all_activity as $activity ) { |
|
| 772 | - if( '' == $activity->comment_type ) continue; |
|
| 773 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 774 | - if( 0 == $activity->user_id ) continue; |
|
| 771 | + foreach ($all_activity as $activity) { |
|
| 772 | + if ('' == $activity->comment_type) continue; |
|
| 773 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 774 | + if (0 == $activity->user_id) continue; |
|
| 775 | 775 | $activity_count[] = $activity->comment_ID; |
| 776 | 776 | } |
| 777 | 777 | |
@@ -781,35 +781,35 @@ discard block |
||
| 781 | 781 | 'status' => 'approve' |
| 782 | 782 | ); |
| 783 | 783 | |
| 784 | - $activities = get_comments( $args ); |
|
| 784 | + $activities = get_comments($args); |
|
| 785 | 785 | |
| 786 | - foreach( $activities as $activity ) { |
|
| 787 | - if( '' == $activity->comment_type ) continue; |
|
| 788 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 789 | - if( 0 == $activity->user_id ) continue; |
|
| 786 | + foreach ($activities as $activity) { |
|
| 787 | + if ('' == $activity->comment_type) continue; |
|
| 788 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 789 | + if (0 == $activity->user_id) continue; |
|
| 790 | 790 | |
| 791 | - $user_exists = get_userdata( $activity->user_id ); |
|
| 791 | + $user_exists = get_userdata($activity->user_id); |
|
| 792 | 792 | |
| 793 | - if( ! $user_exists ) { |
|
| 794 | - wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 793 | + if ( ! $user_exists) { |
|
| 794 | + wp_delete_comment(intval($activity->comment_ID), true); |
|
| 795 | 795 | wp_cache_flush(); |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - $total_activities = count( $activity_count ); |
|
| 799 | + $total_activities = count($activity_count); |
|
| 800 | 800 | |
| 801 | - $total_pages = intval( $total_activities / $n ); |
|
| 801 | + $total_pages = intval($total_activities / $n); |
|
| 802 | 802 | |
| 803 | 803 | // Calculate if this is the last page |
| 804 | - if ( 0 == $offset ) { |
|
| 804 | + if (0 == $offset) { |
|
| 805 | 805 | $current_page = 1; |
| 806 | 806 | } else { |
| 807 | - $current_page = intval( $offset / $n ); |
|
| 807 | + $current_page = intval($offset / $n); |
|
| 808 | 808 | } // End If Statement |
| 809 | 809 | |
| 810 | 810 | // add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 811 | 811 | |
| 812 | - if ( $current_page >= $total_pages ) { |
|
| 812 | + if ($current_page >= $total_pages) { |
|
| 813 | 813 | return true; |
| 814 | 814 | } else { |
| 815 | 815 | return false; |
@@ -818,16 +818,16 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | public function add_teacher_role() { |
| 821 | - add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) ); |
|
| 821 | + add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true)); |
|
| 822 | 822 | return true; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | public function add_sensei_caps() { |
| 826 | - $role = get_role( 'administrator' ); |
|
| 826 | + $role = get_role('administrator'); |
|
| 827 | 827 | |
| 828 | - if( ! is_null( $role ) ) { |
|
| 829 | - $role->add_cap( 'manage_sensei' ); |
|
| 830 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 828 | + if ( ! is_null($role)) { |
|
| 829 | + $role->add_cap('manage_sensei'); |
|
| 830 | + $role->add_cap('manage_sensei_grades'); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | return true; |
@@ -841,16 +841,16 @@ discard block |
||
| 841 | 841 | 'suppress_filters' => 0 |
| 842 | 842 | ); |
| 843 | 843 | |
| 844 | - $questions = get_posts( $args ); |
|
| 844 | + $questions = get_posts($args); |
|
| 845 | 845 | |
| 846 | - foreach( $questions as $question ) { |
|
| 846 | + foreach ($questions as $question) { |
|
| 847 | 847 | |
| 848 | - if( ! isset( $question->ID ) ) continue; |
|
| 848 | + if ( ! isset($question->ID)) continue; |
|
| 849 | 849 | |
| 850 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 850 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 851 | 851 | |
| 852 | - $question_order = get_post_meta( $question->ID, '_quiz_question_order', true ); |
|
| 853 | - update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order ); |
|
| 852 | + $question_order = get_post_meta($question->ID, '_quiz_question_order', true); |
|
| 853 | + update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order); |
|
| 854 | 854 | |
| 855 | 855 | } |
| 856 | 856 | |
@@ -859,15 +859,15 @@ discard block |
||
| 859 | 859 | |
| 860 | 860 | public function update_quiz_settings() { |
| 861 | 861 | |
| 862 | - $settings = get_option( 'woothemes-sensei-settings', array() ); |
|
| 862 | + $settings = get_option('woothemes-sensei-settings', array()); |
|
| 863 | 863 | |
| 864 | 864 | $lesson_completion = false; |
| 865 | - if( isset( $settings['lesson_completion'] ) ) { |
|
| 865 | + if (isset($settings['lesson_completion'])) { |
|
| 866 | 866 | $lesson_completion = $settings['lesson_completion']; |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | $reset_quiz_allowed = false; |
| 870 | - if( isset( $settings['quiz_reset_allowed'] ) ) { |
|
| 870 | + if (isset($settings['quiz_reset_allowed'])) { |
|
| 871 | 871 | $reset_quiz_allowed = $settings['quiz_reset_allowed']; |
| 872 | 872 | } |
| 873 | 873 | |
@@ -878,20 +878,20 @@ discard block |
||
| 878 | 878 | 'suppress_filters' => 0 |
| 879 | 879 | ); |
| 880 | 880 | |
| 881 | - $quizzes = get_posts( $args ); |
|
| 881 | + $quizzes = get_posts($args); |
|
| 882 | 882 | |
| 883 | - foreach( $quizzes as $quiz ) { |
|
| 883 | + foreach ($quizzes as $quiz) { |
|
| 884 | 884 | |
| 885 | - if( ! isset( $quiz->ID ) ) continue; |
|
| 885 | + if ( ! isset($quiz->ID)) continue; |
|
| 886 | 886 | |
| 887 | - if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
|
| 888 | - update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
|
| 887 | + if (isset($lesson_completion) && 'passed' == $lesson_completion) { |
|
| 888 | + update_post_meta($quiz->ID, '_pass_required', 'on'); |
|
| 889 | 889 | } else { |
| 890 | - update_post_meta( $quiz->ID, '_quiz_passmark', 0 ); |
|
| 890 | + update_post_meta($quiz->ID, '_quiz_passmark', 0); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { |
|
| 894 | - update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' ); |
|
| 893 | + if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { |
|
| 894 | + update_post_meta($quiz->ID, '_enable_quiz_reset', 'on'); |
|
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
@@ -906,22 +906,22 @@ discard block |
||
| 906 | 906 | 'suppress_filters' => 0 |
| 907 | 907 | ); |
| 908 | 908 | |
| 909 | - $lessons = get_posts( $args ); |
|
| 909 | + $lessons = get_posts($args); |
|
| 910 | 910 | |
| 911 | - foreach( $lessons as $lesson ) { |
|
| 911 | + foreach ($lessons as $lesson) { |
|
| 912 | 912 | |
| 913 | - if( ! isset( $lesson->ID ) ) continue; |
|
| 913 | + if ( ! isset($lesson->ID)) continue; |
|
| 914 | 914 | |
| 915 | - $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
|
| 915 | + $course_id = get_post_meta($lesson->ID, '_lesson_course', true); |
|
| 916 | 916 | |
| 917 | - if( $course_id ) { |
|
| 918 | - update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
|
| 917 | + if ($course_id) { |
|
| 918 | + update_post_meta($lesson->ID, '_order_'.$course_id, 0); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 921 | + $module = Sensei()->modules->get_lesson_module($lesson->ID); |
|
| 922 | 922 | |
| 923 | - if( $module ) { |
|
| 924 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 923 | + if ($module) { |
|
| 924 | + update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | } |
@@ -930,10 +930,10 @@ discard block |
||
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | public function add_editor_caps() { |
| 933 | - $role = get_role( 'editor' ); |
|
| 933 | + $role = get_role('editor'); |
|
| 934 | 934 | |
| 935 | - if( ! is_null( $role ) ) { |
|
| 936 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 935 | + if ( ! is_null($role)) { |
|
| 936 | + $role->add_cap('manage_sensei_grades'); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | return true; |
@@ -952,26 +952,26 @@ discard block |
||
| 952 | 952 | WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%' |
| 953 | 953 | AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id |
| 954 | 954 | AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'"; |
| 955 | - $wpdb->query( $sql ); |
|
| 955 | + $wpdb->query($sql); |
|
| 956 | 956 | |
| 957 | 957 | return true; |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) { |
|
| 961 | - $count_object = wp_count_posts( 'quiz' ); |
|
| 960 | + public function update_quiz_lesson_relationship($n = 50, $offset = 0) { |
|
| 961 | + $count_object = wp_count_posts('quiz'); |
|
| 962 | 962 | |
| 963 | 963 | $count_published = 0; |
| 964 | - foreach ( $count_object AS $status => $count ) { |
|
| 964 | + foreach ($count_object AS $status => $count) { |
|
| 965 | 965 | $count_published += $count; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | // Calculate if this is the last page |
| 969 | - if ( 0 == $offset ) { |
|
| 969 | + if (0 == $offset) { |
|
| 970 | 970 | $current_page = 1; |
| 971 | 971 | } else { |
| 972 | - $current_page = intval( $offset / $n ); |
|
| 972 | + $current_page = intval($offset / $n); |
|
| 973 | 973 | } |
| 974 | - $total_pages = ceil( $count_published / $n ); |
|
| 974 | + $total_pages = ceil($count_published / $n); |
|
| 975 | 975 | |
| 976 | 976 | $args = array( |
| 977 | 977 | 'post_type' => 'quiz', |
@@ -980,52 +980,52 @@ discard block |
||
| 980 | 980 | 'post_status' => 'any' |
| 981 | 981 | ); |
| 982 | 982 | |
| 983 | - $quizzes = get_posts( $args ); |
|
| 983 | + $quizzes = get_posts($args); |
|
| 984 | 984 | |
| 985 | - foreach( $quizzes as $quiz ) { |
|
| 985 | + foreach ($quizzes as $quiz) { |
|
| 986 | 986 | |
| 987 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
| 987 | + if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue; |
|
| 988 | 988 | |
| 989 | - $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
|
| 989 | + $lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true); |
|
| 990 | 990 | |
| 991 | - if( empty( $lesson_id ) ) continue; |
|
| 991 | + if (empty($lesson_id)) continue; |
|
| 992 | 992 | |
| 993 | 993 | $data = array( |
| 994 | 994 | 'ID' => $quiz->ID, |
| 995 | 995 | 'post_parent' => $lesson_id, |
| 996 | 996 | ); |
| 997 | - wp_update_post( $data ); |
|
| 997 | + wp_update_post($data); |
|
| 998 | 998 | |
| 999 | - update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID ); |
|
| 999 | + update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - if ( $current_page == $total_pages || 0 == $total_pages ) { |
|
| 1002 | + if ($current_page == $total_pages || 0 == $total_pages) { |
|
| 1003 | 1003 | return true; |
| 1004 | 1004 | } else { |
| 1005 | 1005 | return false; |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - function status_changes_fix_lessons( $n = 50, $offset = 0 ) { |
|
| 1009 | + function status_changes_fix_lessons($n = 50, $offset = 0) { |
|
| 1010 | 1010 | global $wpdb; |
| 1011 | 1011 | |
| 1012 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1012 | + $count_object = wp_count_posts('lesson'); |
|
| 1013 | 1013 | $count_published = 0; |
| 1014 | - foreach ( $count_object AS $status => $count ) { |
|
| 1014 | + foreach ($count_object AS $status => $count) { |
|
| 1015 | 1015 | $count_published += $count; |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - if ( 0 == $count_published ) { |
|
| 1018 | + if (0 == $count_published) { |
|
| 1019 | 1019 | return true; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | // Calculate if this is the last page |
| 1023 | - if ( 0 == $offset ) { |
|
| 1023 | + if (0 == $offset) { |
|
| 1024 | 1024 | $current_page = 1; |
| 1025 | 1025 | } else { |
| 1026 | - $current_page = intval( $offset / $n ); |
|
| 1026 | + $current_page = intval($offset / $n); |
|
| 1027 | 1027 | } |
| 1028 | - $total_pages = ceil( $count_published / $n ); |
|
| 1028 | + $total_pages = ceil($count_published / $n); |
|
| 1029 | 1029 | |
| 1030 | 1030 | // Get all Lessons with (and without) Quizzes... |
| 1031 | 1031 | $args = array( |
@@ -1035,26 +1035,26 @@ discard block |
||
| 1035 | 1035 | 'offset' => $offset, |
| 1036 | 1036 | 'fields' => 'ids' |
| 1037 | 1037 | ); |
| 1038 | - $lesson_ids = get_posts( $args ); |
|
| 1038 | + $lesson_ids = get_posts($args); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // ...get all Quiz IDs for the above Lessons |
| 1041 | - $id_list = join( ',', $lesson_ids ); |
|
| 1042 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1041 | + $id_list = join(',', $lesson_ids); |
|
| 1042 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1043 | 1043 | $lesson_quiz_ids = array(); |
| 1044 | - if ( !empty($meta_list) ) { |
|
| 1045 | - foreach ( $meta_list as $metarow ) { |
|
| 1044 | + if ( ! empty($meta_list)) { |
|
| 1045 | + foreach ($meta_list as $metarow) { |
|
| 1046 | 1046 | $lesson_id = $metarow['meta_value']; |
| 1047 | 1047 | $quiz_id = $metarow['post_id']; |
| 1048 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1048 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | // ...check all Quiz IDs for questions |
| 1053 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1054 | - $meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1053 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1054 | + $meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1055 | 1055 | $lesson_quiz_ids_with_questions = array(); |
| 1056 | - if ( !empty($meta_list) ) { |
|
| 1057 | - foreach ( $meta_list as $metarow ) { |
|
| 1056 | + if ( ! empty($meta_list)) { |
|
| 1057 | + foreach ($meta_list as $metarow) { |
|
| 1058 | 1058 | $quiz_id = $metarow['meta_value']; |
| 1059 | 1059 | $lesson_quiz_ids_with_questions[] = $quiz_id; |
| 1060 | 1060 | } |
@@ -1062,49 +1062,49 @@ discard block |
||
| 1062 | 1062 | |
| 1063 | 1063 | // For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons |
| 1064 | 1064 | // if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons |
| 1065 | - $d_count = $a_count =0; |
|
| 1066 | - foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) { |
|
| 1067 | - if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1065 | + $d_count = $a_count = 0; |
|
| 1066 | + foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) { |
|
| 1067 | + if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | // Quiz has no questions, drop the corresponding data |
| 1070 | - delete_post_meta( $quiz_id, '_pass_required' ); |
|
| 1071 | - delete_post_meta( $quiz_id, '_quiz_passmark' ); |
|
| 1072 | - delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
|
| 1070 | + delete_post_meta($quiz_id, '_pass_required'); |
|
| 1071 | + delete_post_meta($quiz_id, '_quiz_passmark'); |
|
| 1072 | + delete_post_meta($lesson_id, '_quiz_has_questions'); |
|
| 1073 | 1073 | $d_count++; |
| 1074 | 1074 | } |
| 1075 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1075 | + else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1076 | 1076 | |
| 1077 | 1077 | // Quiz has no questions, drop the corresponding data |
| 1078 | - update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1078 | + update_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1079 | 1079 | $a_count++; |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - if ( $current_page == $total_pages ) { |
|
| 1083 | + if ($current_page == $total_pages) { |
|
| 1084 | 1084 | return true; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | return false; |
| 1087 | 1087 | } |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | - function status_changes_convert_lessons( $n = 50, $offset = 0 ) { |
|
| 1090 | + function status_changes_convert_lessons($n = 50, $offset = 0) { |
|
| 1091 | 1091 | global $wpdb; |
| 1092 | 1092 | |
| 1093 | - wp_defer_comment_counting( true ); |
|
| 1093 | + wp_defer_comment_counting(true); |
|
| 1094 | 1094 | |
| 1095 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1095 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1096 | 1096 | |
| 1097 | - if ( 0 == $user_count_result ) { |
|
| 1097 | + if (0 == $user_count_result) { |
|
| 1098 | 1098 | return true; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | - if ( 0 == $offset ) { |
|
| 1101 | + if (0 == $offset) { |
|
| 1102 | 1102 | $current_page = 1; |
| 1103 | 1103 | } else { |
| 1104 | - $current_page = intval( $offset / $n ); |
|
| 1104 | + $current_page = intval($offset / $n); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1107 | + $total_pages = ceil($user_count_result / $n); |
|
| 1108 | 1108 | |
| 1109 | 1109 | // Get all Lessons with Quizzes... |
| 1110 | 1110 | $args = array( |
@@ -1119,34 +1119,34 @@ discard block |
||
| 1119 | 1119 | ), |
| 1120 | 1120 | 'fields' => 'ids' |
| 1121 | 1121 | ); |
| 1122 | - $lesson_ids_with_quizzes = get_posts( $args ); |
|
| 1122 | + $lesson_ids_with_quizzes = get_posts($args); |
|
| 1123 | 1123 | // ...get all Quiz IDs for the above Lessons |
| 1124 | - $id_list = join( ',', $lesson_ids_with_quizzes ); |
|
| 1125 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1124 | + $id_list = join(',', $lesson_ids_with_quizzes); |
|
| 1125 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1126 | 1126 | $lesson_quiz_ids = array(); |
| 1127 | - if ( !empty($meta_list) ) { |
|
| 1128 | - foreach ( $meta_list as $metarow ) { |
|
| 1127 | + if ( ! empty($meta_list)) { |
|
| 1128 | + foreach ($meta_list as $metarow) { |
|
| 1129 | 1129 | $lesson_id = $metarow['meta_value']; |
| 1130 | 1130 | $quiz_id = $metarow['post_id']; |
| 1131 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1131 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // ...get all Pass Required & Passmarks for the above Lesson/Quizzes |
| 1136 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1137 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A ); |
|
| 1136 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1137 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A); |
|
| 1138 | 1138 | $quizzes_pass_required = $quizzes_passmarks = array(); |
| 1139 | - if ( !empty($meta_list) ) { |
|
| 1140 | - foreach ( $meta_list as $metarow ) { |
|
| 1141 | - if ( !empty($metarow['meta_value']) ) { |
|
| 1139 | + if ( ! empty($meta_list)) { |
|
| 1140 | + foreach ($meta_list as $metarow) { |
|
| 1141 | + if ( ! empty($metarow['meta_value'])) { |
|
| 1142 | 1142 | $quiz_id = $metarow['post_id']; |
| 1143 | 1143 | $key = $metarow['meta_key']; |
| 1144 | 1144 | $value = $metarow['meta_value']; |
| 1145 | - if ( '_pass_required' == $key ) { |
|
| 1146 | - $quizzes_pass_required[ $quiz_id ] = $value; |
|
| 1145 | + if ('_pass_required' == $key) { |
|
| 1146 | + $quizzes_pass_required[$quiz_id] = $value; |
|
| 1147 | 1147 | } |
| 1148 | - if ( '_quiz_passmark' == $key ) { |
|
| 1149 | - $quizzes_passmarks[ $quiz_id ] = $value; |
|
| 1148 | + if ('_quiz_passmark' == $key) { |
|
| 1149 | + $quizzes_passmarks[$quiz_id] = $value; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | 1152 | } |
@@ -1160,41 +1160,41 @@ discard block |
||
| 1160 | 1160 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' "; |
| 1161 | 1161 | |
| 1162 | 1162 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1163 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1163 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1164 | 1164 | |
| 1165 | - foreach ( $user_ids AS $user_id ) { |
|
| 1165 | + foreach ($user_ids AS $user_id) { |
|
| 1166 | 1166 | |
| 1167 | 1167 | $lesson_ends = $lesson_grades = $lesson_answers = array(); |
| 1168 | 1168 | |
| 1169 | 1169 | // Pre-process the lesson ends |
| 1170 | - $_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A ); |
|
| 1171 | - foreach ( $_lesson_ends as $lesson_end ) { |
|
| 1170 | + $_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A); |
|
| 1171 | + foreach ($_lesson_ends as $lesson_end) { |
|
| 1172 | 1172 | // This will overwrite existing entries with the newer ones |
| 1173 | - $lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date']; |
|
| 1173 | + $lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date']; |
|
| 1174 | 1174 | } |
| 1175 | - unset( $_lesson_ends ); |
|
| 1175 | + unset($_lesson_ends); |
|
| 1176 | 1176 | |
| 1177 | 1177 | // Pre-process the lesson grades |
| 1178 | - $_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A ); |
|
| 1179 | - foreach ( $_lesson_grades as $lesson_grade ) { |
|
| 1178 | + $_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A); |
|
| 1179 | + foreach ($_lesson_grades as $lesson_grade) { |
|
| 1180 | 1180 | // This will overwrite existing entries with the newer ones (assuming the grade is higher) |
| 1181 | - if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) { |
|
| 1182 | - $lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content']; |
|
| 1181 | + if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) { |
|
| 1182 | + $lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content']; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | } |
| 1185 | - unset( $_lesson_grades ); |
|
| 1185 | + unset($_lesson_grades); |
|
| 1186 | 1186 | |
| 1187 | 1187 | // Pre-process the lesson answers |
| 1188 | - $_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A ); |
|
| 1189 | - foreach ( $_lesson_answers as $lesson_answer ) { |
|
| 1188 | + $_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A); |
|
| 1189 | + foreach ($_lesson_answers as $lesson_answer) { |
|
| 1190 | 1190 | // This will overwrite existing entries with the newer ones |
| 1191 | - $lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content']; |
|
| 1191 | + $lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content']; |
|
| 1192 | 1192 | } |
| 1193 | - unset( $_lesson_answers ); |
|
| 1193 | + unset($_lesson_answers); |
|
| 1194 | 1194 | |
| 1195 | 1195 | // Grab all the lesson starts for the user |
| 1196 | - $lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1197 | - foreach ( $lesson_starts as $lesson_log ) { |
|
| 1196 | + $lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1197 | + foreach ($lesson_starts as $lesson_log) { |
|
| 1198 | 1198 | |
| 1199 | 1199 | $lesson_id = $lesson_log['comment_post_ID']; |
| 1200 | 1200 | |
@@ -1207,23 +1207,23 @@ discard block |
||
| 1207 | 1207 | 'start' => $status_date, |
| 1208 | 1208 | ); |
| 1209 | 1209 | // Check if there is a lesson end |
| 1210 | - if ( !empty($lesson_ends[$lesson_id]) ) { |
|
| 1210 | + if ( ! empty($lesson_ends[$lesson_id])) { |
|
| 1211 | 1211 | $status_date = $lesson_ends[$lesson_id]; |
| 1212 | 1212 | // Check lesson has quiz |
| 1213 | - if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) { |
|
| 1213 | + if ( ! empty($lesson_quiz_ids[$lesson_id])) { |
|
| 1214 | 1214 | // Check for the quiz answers |
| 1215 | - if ( !empty($lesson_answers[$quiz_id]) ) { |
|
| 1215 | + if ( ! empty($lesson_answers[$quiz_id])) { |
|
| 1216 | 1216 | $meta_data['questions_asked'] = $lesson_answers[$quiz_id]; |
| 1217 | 1217 | } |
| 1218 | 1218 | // Check if there is a quiz grade |
| 1219 | 1219 | $quiz_id = $lesson_quiz_ids[$lesson_id]; |
| 1220 | - if ( !empty($lesson_grades[$quiz_id]) ) { |
|
| 1220 | + if ( ! empty($lesson_grades[$quiz_id])) { |
|
| 1221 | 1221 | $meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id]; |
| 1222 | 1222 | // Check if the user has to get the passmark and has or not |
| 1223 | - if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
|
| 1223 | + if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) { |
|
| 1224 | 1224 | $status = 'passed'; |
| 1225 | 1225 | } |
| 1226 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1226 | + elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) { |
|
| 1227 | 1227 | $status = 'failed'; |
| 1228 | 1228 | } |
| 1229 | 1229 | else { |
@@ -1251,26 +1251,26 @@ discard block |
||
| 1251 | 1251 | 'comment_author' => '', |
| 1252 | 1252 | ); |
| 1253 | 1253 | // Check it doesn't already exist |
| 1254 | - $sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id ); |
|
| 1255 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1256 | - if ( !$comment_ID ) { |
|
| 1254 | + $sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id); |
|
| 1255 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1256 | + if ( ! $comment_ID) { |
|
| 1257 | 1257 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1258 | 1258 | $wpdb->insert($wpdb->comments, $data); |
| 1259 | 1259 | $comment_ID = (int) $wpdb->insert_id; |
| 1260 | 1260 | |
| 1261 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1262 | - foreach ( $meta_data as $key => $value ) { |
|
| 1261 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1262 | + foreach ($meta_data as $key => $value) { |
|
| 1263 | 1263 | // Bypassing WP add_comment_meta(() so no actions/filters are run |
| 1264 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1264 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1265 | 1265 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1266 | - $comment_ID, $key ) ) ) { |
|
| 1266 | + $comment_ID, $key ))) { |
|
| 1267 | 1267 | continue; // Found the meta data already |
| 1268 | 1268 | } |
| 1269 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1269 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1270 | 1270 | 'comment_id' => $comment_ID, |
| 1271 | 1271 | 'meta_key' => $key, |
| 1272 | 1272 | 'meta_value' => $value |
| 1273 | - ) ); |
|
| 1273 | + )); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
@@ -1278,40 +1278,40 @@ discard block |
||
| 1278 | 1278 | } |
| 1279 | 1279 | $wpdb->flush(); |
| 1280 | 1280 | |
| 1281 | - if ( $current_page == $total_pages ) { |
|
| 1281 | + if ($current_page == $total_pages) { |
|
| 1282 | 1282 | return true; |
| 1283 | 1283 | } else { |
| 1284 | 1284 | return false; |
| 1285 | 1285 | } |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - function status_changes_convert_courses( $n = 50, $offset = 0 ) { |
|
| 1288 | + function status_changes_convert_courses($n = 50, $offset = 0) { |
|
| 1289 | 1289 | global $wpdb; |
| 1290 | 1290 | |
| 1291 | - wp_defer_comment_counting( true ); |
|
| 1291 | + wp_defer_comment_counting(true); |
|
| 1292 | 1292 | |
| 1293 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1293 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1294 | 1294 | |
| 1295 | - if ( 0 == $user_count_result ) { |
|
| 1295 | + if (0 == $user_count_result) { |
|
| 1296 | 1296 | return true; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - if ( 0 == $offset ) { |
|
| 1299 | + if (0 == $offset) { |
|
| 1300 | 1300 | $current_page = 1; |
| 1301 | 1301 | } else { |
| 1302 | - $current_page = intval( $offset / $n ); |
|
| 1302 | + $current_page = intval($offset / $n); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1305 | + $total_pages = ceil($user_count_result / $n); |
|
| 1306 | 1306 | |
| 1307 | 1307 | // Get all Lesson => Course relationships |
| 1308 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A ); |
|
| 1308 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A); |
|
| 1309 | 1309 | $course_lesson_ids = array(); |
| 1310 | - if ( !empty($meta_list) ) { |
|
| 1311 | - foreach ( $meta_list as $metarow ) { |
|
| 1310 | + if ( ! empty($meta_list)) { |
|
| 1311 | + foreach ($meta_list as $metarow) { |
|
| 1312 | 1312 | $lesson_id = $metarow['post_id']; |
| 1313 | 1313 | $course_id = $metarow['meta_value']; |
| 1314 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1314 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1315 | 1315 | } |
| 1316 | 1316 | } |
| 1317 | 1317 | |
@@ -1321,13 +1321,13 @@ discard block |
||
| 1321 | 1321 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' "; |
| 1322 | 1322 | |
| 1323 | 1323 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1324 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1324 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1325 | 1325 | |
| 1326 | - foreach ( $user_ids AS $user_id ) { |
|
| 1326 | + foreach ($user_ids AS $user_id) { |
|
| 1327 | 1327 | |
| 1328 | 1328 | // Grab all the course starts for the user |
| 1329 | - $course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1330 | - foreach ( $course_starts as $course_log ) { |
|
| 1329 | + $course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1330 | + foreach ($course_starts as $course_log) { |
|
| 1331 | 1331 | |
| 1332 | 1332 | $course_id = $course_log['comment_post_ID']; |
| 1333 | 1333 | |
@@ -1342,23 +1342,23 @@ discard block |
||
| 1342 | 1342 | 'percent' => 0, |
| 1343 | 1343 | ); |
| 1344 | 1344 | // Check if the course has lessons |
| 1345 | - if ( !empty( $course_lesson_ids[$course_id] ) ) { |
|
| 1345 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1346 | 1346 | |
| 1347 | 1347 | $lessons_completed = 0; |
| 1348 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1348 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1349 | 1349 | |
| 1350 | 1350 | // Don't use prepare as we need to provide the id join |
| 1351 | - $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) ); |
|
| 1351 | + $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id])); |
|
| 1352 | 1352 | // Get all lesson statuses for this Courses' lessons |
| 1353 | - $lesson_statuses = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1353 | + $lesson_statuses = $wpdb->get_results($sql, ARRAY_A); |
|
| 1354 | 1354 | // Not enough lesson statuses, thus cannot be complete |
| 1355 | - if ( $total_lessons > count($lesson_statuses) ) { |
|
| 1355 | + if ($total_lessons > count($lesson_statuses)) { |
|
| 1356 | 1356 | $status = 'in-progress'; |
| 1357 | 1357 | } |
| 1358 | 1358 | // Count each lesson to work out the overall percentage |
| 1359 | - foreach ( $lesson_statuses as $lesson_status ) { |
|
| 1359 | + foreach ($lesson_statuses as $lesson_status) { |
|
| 1360 | 1360 | $status_date = $lesson_status['comment_date']; |
| 1361 | - switch ( $lesson_status['status'] ) { |
|
| 1361 | + switch ($lesson_status['status']) { |
|
| 1362 | 1362 | case 'complete': // Lesson has no quiz/questions |
| 1363 | 1363 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1364 | 1364 | case 'passed': |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | } |
| 1374 | 1374 | } |
| 1375 | 1375 | $meta_data['complete'] = $lessons_completed; |
| 1376 | - $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1376 | + $meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | else { |
| 1379 | 1379 | // Course has no lessons, therefore cannot be 'complete' |
@@ -1390,26 +1390,26 @@ discard block |
||
| 1390 | 1390 | 'comment_author' => '', |
| 1391 | 1391 | ); |
| 1392 | 1392 | // Check it doesn't already exist |
| 1393 | - $sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id ); |
|
| 1394 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1395 | - if ( !$comment_ID ) { |
|
| 1393 | + $sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id); |
|
| 1394 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1395 | + if ( ! $comment_ID) { |
|
| 1396 | 1396 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1397 | 1397 | $wpdb->insert($wpdb->comments, $data); |
| 1398 | 1398 | $comment_ID = (int) $wpdb->insert_id; |
| 1399 | 1399 | |
| 1400 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1401 | - foreach ( $meta_data as $key => $value ) { |
|
| 1400 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1401 | + foreach ($meta_data as $key => $value) { |
|
| 1402 | 1402 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1403 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1403 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1404 | 1404 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1405 | - $comment_ID, $key ) ) ) { |
|
| 1405 | + $comment_ID, $key ))) { |
|
| 1406 | 1406 | continue; // Found the meta data already |
| 1407 | 1407 | } |
| 1408 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1408 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1409 | 1409 | 'comment_id' => $comment_ID, |
| 1410 | 1410 | 'meta_key' => $key, |
| 1411 | 1411 | 'meta_value' => $value |
| 1412 | - ) ); |
|
| 1412 | + )); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | } |
| 1415 | 1415 | } |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | } |
| 1418 | 1418 | $wpdb->flush(); |
| 1419 | 1419 | |
| 1420 | - if ( $current_page == $total_pages ) { |
|
| 1420 | + if ($current_page == $total_pages) { |
|
| 1421 | 1421 | return true; |
| 1422 | 1422 | } else { |
| 1423 | 1423 | return false; |
@@ -1433,70 +1433,70 @@ discard block |
||
| 1433 | 1433 | * @param type $offset |
| 1434 | 1434 | * @return boolean |
| 1435 | 1435 | */ |
| 1436 | - function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
|
| 1436 | + function status_changes_repair_course_statuses($n = 50, $offset = 0) { |
|
| 1437 | 1437 | global $wpdb; |
| 1438 | 1438 | |
| 1439 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1439 | + $count_object = wp_count_posts('lesson'); |
|
| 1440 | 1440 | $count_published = $count_object->publish; |
| 1441 | 1441 | |
| 1442 | - if ( 0 == $count_published ) { |
|
| 1442 | + if (0 == $count_published) { |
|
| 1443 | 1443 | return true; |
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | // Calculate if this is the last page |
| 1447 | - if ( 0 == $offset ) { |
|
| 1447 | + if (0 == $offset) { |
|
| 1448 | 1448 | $current_page = 1; |
| 1449 | 1449 | } else { |
| 1450 | - $current_page = intval( $offset / $n ); |
|
| 1450 | + $current_page = intval($offset / $n); |
|
| 1451 | 1451 | } |
| 1452 | - $total_pages = ceil( $count_published / $n ); |
|
| 1452 | + $total_pages = ceil($count_published / $n); |
|
| 1453 | 1453 | |
| 1454 | 1454 | $course_lesson_ids = $lesson_user_statuses = array(); |
| 1455 | 1455 | |
| 1456 | 1456 | // Get all Lesson => Course relationships |
| 1457 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A ); |
|
| 1458 | - if ( !empty($meta_list) ) { |
|
| 1459 | - foreach ( $meta_list as $metarow ) { |
|
| 1457 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A); |
|
| 1458 | + if ( ! empty($meta_list)) { |
|
| 1459 | + foreach ($meta_list as $metarow) { |
|
| 1460 | 1460 | $lesson_id = $metarow['post_id']; |
| 1461 | 1461 | $course_id = $metarow['meta_value']; |
| 1462 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1462 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // Get all Lesson => Course relationships |
| 1467 | - $status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A ); |
|
| 1468 | - if ( !empty($status_list) ) { |
|
| 1469 | - foreach ( $status_list as $status ) { |
|
| 1470 | - $lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved']; |
|
| 1467 | + $status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A); |
|
| 1468 | + if ( ! empty($status_list)) { |
|
| 1469 | + foreach ($status_list as $status) { |
|
| 1470 | + $lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved']; |
|
| 1471 | 1471 | } |
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1474 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1475 | 1475 | |
| 1476 | 1476 | $per_page = 40; |
| 1477 | 1477 | $comment_id_offset = $count = 0; |
| 1478 | 1478 | |
| 1479 | 1479 | $course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page"; |
| 1480 | 1480 | // $per_page users at a time |
| 1481 | - while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) { |
|
| 1481 | + while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) { |
|
| 1482 | 1482 | |
| 1483 | - foreach ( $course_statuses AS $course_status ) { |
|
| 1483 | + foreach ($course_statuses AS $course_status) { |
|
| 1484 | 1484 | $user_id = $course_status->user_id; |
| 1485 | 1485 | $course_id = $course_status->comment_post_ID; |
| 1486 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1487 | - if ( $total_lessons <= 0 ) { |
|
| 1486 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1487 | + if ($total_lessons <= 0) { |
|
| 1488 | 1488 | $total_lessons = 1; // Fix division of zero error, some courses have no lessons |
| 1489 | 1489 | } |
| 1490 | 1490 | $lessons_completed = 0; |
| 1491 | 1491 | $status = 'in-progress'; |
| 1492 | 1492 | |
| 1493 | 1493 | // Some Courses have no lessons... (can they ever be complete?) |
| 1494 | - if ( !empty($course_lesson_ids[ $course_id ]) ) { |
|
| 1495 | - foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) { |
|
| 1496 | - $lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ]; |
|
| 1494 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1495 | + foreach ($course_lesson_ids[$course_id] AS $lesson_id) { |
|
| 1496 | + $lesson_status = $lesson_user_statuses[$lesson_id][$user_id]; |
|
| 1497 | 1497 | // If lessons are complete without needing quizzes to be passed |
| 1498 | - if ( 'passed' != $course_completion ) { |
|
| 1499 | - switch ( $lesson_status ) { |
|
| 1498 | + if ('passed' != $course_completion) { |
|
| 1499 | + switch ($lesson_status) { |
|
| 1500 | 1500 | // A user cannot 'complete' a course if a lesson... |
| 1501 | 1501 | case 'in-progress': // ...is still in progress |
| 1502 | 1502 | case 'ungraded': // ...hasn't yet been graded |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | } |
| 1509 | 1509 | } |
| 1510 | 1510 | else { |
| 1511 | - switch ( $lesson_status ) { |
|
| 1511 | + switch ($lesson_status) { |
|
| 1512 | 1512 | case 'complete': // Lesson has no quiz/questions |
| 1513 | 1513 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1514 | 1514 | case 'passed': // Lesson has quiz and the user passed |
@@ -1523,79 +1523,79 @@ discard block |
||
| 1523 | 1523 | } |
| 1524 | 1524 | } // Each lesson |
| 1525 | 1525 | } // Check for lessons |
| 1526 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1526 | + if ($lessons_completed == $total_lessons) { |
|
| 1527 | 1527 | $status = 'complete'; |
| 1528 | 1528 | } |
| 1529 | 1529 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1530 | 1530 | $metadata = array( |
| 1531 | 1531 | 'complete' => $lessons_completed, |
| 1532 | - 'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ), |
|
| 1532 | + 'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)), |
|
| 1533 | 1533 | ); |
| 1534 | - WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata ); |
|
| 1534 | + WooThemes_Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata); |
|
| 1535 | 1535 | $count++; |
| 1536 | 1536 | |
| 1537 | 1537 | } // per course status |
| 1538 | 1538 | $comment_id_offset = $course_status->comment_ID; |
| 1539 | 1539 | } // all course statuses |
| 1540 | 1540 | |
| 1541 | - if ( $current_page == $total_pages ) { |
|
| 1541 | + if ($current_page == $total_pages) { |
|
| 1542 | 1542 | return true; |
| 1543 | 1543 | } else { |
| 1544 | 1544 | return false; |
| 1545 | 1545 | } |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | - function status_changes_convert_questions( $n = 50, $offset = 0 ) { |
|
| 1548 | + function status_changes_convert_questions($n = 50, $offset = 0) { |
|
| 1549 | 1549 | global $wpdb; |
| 1550 | 1550 | |
| 1551 | - wp_defer_comment_counting( true ); |
|
| 1551 | + wp_defer_comment_counting(true); |
|
| 1552 | 1552 | |
| 1553 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1553 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1554 | 1554 | |
| 1555 | - if ( 0 == $user_count_result ) { |
|
| 1555 | + if (0 == $user_count_result) { |
|
| 1556 | 1556 | return true; |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | // Calculate if this is the last page |
| 1560 | - if ( 0 == $offset ) { |
|
| 1560 | + if (0 == $offset) { |
|
| 1561 | 1561 | $current_page = 1; |
| 1562 | 1562 | } else { |
| 1563 | - $current_page = intval( $offset / $n ); |
|
| 1563 | + $current_page = intval($offset / $n); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1566 | + $total_pages = ceil($user_count_result / $n); |
|
| 1567 | 1567 | |
| 1568 | 1568 | $users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d"; |
| 1569 | 1569 | $answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID "; |
| 1570 | 1570 | $grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID "; |
| 1571 | 1571 | $notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID "; |
| 1572 | 1572 | |
| 1573 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1573 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1574 | 1574 | |
| 1575 | - foreach ( $user_ids AS $user_id ) { |
|
| 1575 | + foreach ($user_ids AS $user_id) { |
|
| 1576 | 1576 | |
| 1577 | 1577 | $answer_grades = $answer_notes = array(); |
| 1578 | 1578 | |
| 1579 | 1579 | // Pre-process the answer grades |
| 1580 | - $_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A ); |
|
| 1581 | - foreach ( $_answer_grades as $answer_grade ) { |
|
| 1580 | + $_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A); |
|
| 1581 | + foreach ($_answer_grades as $answer_grade) { |
|
| 1582 | 1582 | // This will overwrite existing entries with the newer ones |
| 1583 | - $answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content']; |
|
| 1583 | + $answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content']; |
|
| 1584 | 1584 | } |
| 1585 | - unset( $_answer_grades ); |
|
| 1585 | + unset($_answer_grades); |
|
| 1586 | 1586 | |
| 1587 | 1587 | // Pre-process the answer notes |
| 1588 | - $_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A ); |
|
| 1589 | - foreach ( $_answer_notes as $answer_note ) { |
|
| 1588 | + $_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A); |
|
| 1589 | + foreach ($_answer_notes as $answer_note) { |
|
| 1590 | 1590 | // This will overwrite existing entries with the newer ones |
| 1591 | - $answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content']; |
|
| 1591 | + $answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content']; |
|
| 1592 | 1592 | } |
| 1593 | - unset( $_answer_notes ); |
|
| 1593 | + unset($_answer_notes); |
|
| 1594 | 1594 | |
| 1595 | 1595 | // Grab all the questions for the user |
| 1596 | 1596 | $sql = $wpdb->prepare($answers_sql, $user_id); |
| 1597 | - $answers = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1598 | - foreach ( $answers as $answer ) { |
|
| 1597 | + $answers = $wpdb->get_results($sql, ARRAY_A); |
|
| 1598 | + foreach ($answers as $answer) { |
|
| 1599 | 1599 | |
| 1600 | 1600 | // Excape data |
| 1601 | 1601 | $answer = wp_slash($answer); |
@@ -1605,12 +1605,12 @@ discard block |
||
| 1605 | 1605 | $meta_data = array(); |
| 1606 | 1606 | |
| 1607 | 1607 | // Check if the question has been graded, add as meta |
| 1608 | - if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) { |
|
| 1609 | - $meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ]; |
|
| 1608 | + if ( ! empty($answer_grades[$answer['comment_post_ID']])) { |
|
| 1609 | + $meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']]; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | // Check if there is an answer note, add as meta |
| 1612 | - if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) { |
|
| 1613 | - $meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ]; |
|
| 1612 | + if ( ! empty($answer_notes[$answer['comment_post_ID']])) { |
|
| 1613 | + $meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']]; |
|
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | 1616 | // Wipe the unnessary data from the main comment |
@@ -1623,21 +1623,21 @@ discard block |
||
| 1623 | 1623 | ); |
| 1624 | 1624 | $data = array_merge($answer, $data); |
| 1625 | 1625 | |
| 1626 | - $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
|
| 1627 | - if ( $rval ) { |
|
| 1628 | - if ( !empty($meta_data) ) { |
|
| 1629 | - foreach ( $meta_data as $key => $value ) { |
|
| 1626 | + $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID')); |
|
| 1627 | + if ($rval) { |
|
| 1628 | + if ( ! empty($meta_data)) { |
|
| 1629 | + foreach ($meta_data as $key => $value) { |
|
| 1630 | 1630 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1631 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1631 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1632 | 1632 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1633 | - $comment_ID, $key ) ) ) { |
|
| 1633 | + $comment_ID, $key ))) { |
|
| 1634 | 1634 | continue; // Found the meta data already |
| 1635 | 1635 | } |
| 1636 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1636 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1637 | 1637 | 'comment_id' => $comment_ID, |
| 1638 | 1638 | 'meta_key' => $key, |
| 1639 | 1639 | 'meta_value' => $value |
| 1640 | - ) ); |
|
| 1640 | + )); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | } |
| 1643 | 1643 | } |
@@ -1645,7 +1645,7 @@ discard block |
||
| 1645 | 1645 | } |
| 1646 | 1646 | $wpdb->flush(); |
| 1647 | 1647 | |
| 1648 | - if ( $current_page == $total_pages ) { |
|
| 1648 | + if ($current_page == $total_pages) { |
|
| 1649 | 1649 | return true; |
| 1650 | 1650 | } else { |
| 1651 | 1651 | return false; |
@@ -1662,10 +1662,10 @@ discard block |
||
| 1662 | 1662 | global $wpdb; |
| 1663 | 1663 | |
| 1664 | 1664 | // Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts |
| 1665 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " ); |
|
| 1665 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' "); |
|
| 1666 | 1666 | |
| 1667 | 1667 | // Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required |
| 1668 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " ); |
|
| 1668 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') "); |
|
| 1669 | 1669 | |
| 1670 | 1670 | return true; |
| 1671 | 1671 | } |
@@ -1678,50 +1678,50 @@ discard block |
||
| 1678 | 1678 | * @param type $offset |
| 1679 | 1679 | * @return boolean |
| 1680 | 1680 | */ |
| 1681 | - public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
|
| 1681 | + public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) { |
|
| 1682 | 1682 | global $wpdb; |
| 1683 | 1683 | |
| 1684 | - $item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " ); |
|
| 1684 | + $item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') "); |
|
| 1685 | 1685 | |
| 1686 | - if ( 0 == $item_count_result ) { |
|
| 1686 | + if (0 == $item_count_result) { |
|
| 1687 | 1687 | return true; |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | // Calculate if this is the last page |
| 1691 | - if ( 0 == $offset ) { |
|
| 1691 | + if (0 == $offset) { |
|
| 1692 | 1692 | $current_page = 1; |
| 1693 | 1693 | } else { |
| 1694 | - $current_page = intval( $offset / $n ); |
|
| 1694 | + $current_page = intval($offset / $n); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - $total_pages = ceil( $item_count_result / $n ); |
|
| 1697 | + $total_pages = ceil($item_count_result / $n); |
|
| 1698 | 1698 | |
| 1699 | 1699 | // Recalculate all counts |
| 1700 | - $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) ); |
|
| 1701 | - foreach ( (array) $items as $post ) { |
|
| 1700 | + $items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset)); |
|
| 1701 | + foreach ((array) $items as $post) { |
|
| 1702 | 1702 | // Code copied from wp_update_comment_count_now() |
| 1703 | - $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) ); |
|
| 1704 | - $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) ); |
|
| 1703 | + $new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID)); |
|
| 1704 | + $wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID)); |
|
| 1705 | 1705 | |
| 1706 | - clean_post_cache( $post->ID ); |
|
| 1706 | + clean_post_cache($post->ID); |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | - if ( $current_page == $total_pages ) { |
|
| 1709 | + if ($current_page == $total_pages) { |
|
| 1710 | 1710 | return true; |
| 1711 | 1711 | } else { |
| 1712 | 1712 | return false; |
| 1713 | 1713 | } |
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | - public function remove_legacy_comments () { |
|
| 1716 | + public function remove_legacy_comments() { |
|
| 1717 | 1717 | global $wpdb; |
| 1718 | 1718 | |
| 1719 | - $result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) ); |
|
| 1719 | + $result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy')); |
|
| 1720 | 1720 | |
| 1721 | 1721 | return true; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | - public function index_comment_status_field () { |
|
| 1724 | + public function index_comment_status_field() { |
|
| 1725 | 1725 | global $wpdb; |
| 1726 | 1726 | |
| 1727 | 1727 | $wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )"); |
@@ -1740,7 +1740,7 @@ discard block |
||
| 1740 | 1740 | * @since 1.8.0 |
| 1741 | 1741 | * @return bool; |
| 1742 | 1742 | */ |
| 1743 | - public function enhance_teacher_role ( ) { |
|
| 1743 | + public function enhance_teacher_role( ) { |
|
| 1744 | 1744 | |
| 1745 | 1745 | require_once('class-sensei-teacher.php'); |
| 1746 | 1746 | $teacher = new Sensei_Teacher(); |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Updates Class |
@@ -769,9 +772,15 @@ discard block |
||
| 769 | 772 | $all_activity = get_comments( array( 'status' => 'approve' ) ); |
| 770 | 773 | $activity_count = array(); |
| 771 | 774 | foreach( $all_activity as $activity ) { |
| 772 | - if( '' == $activity->comment_type ) continue; |
|
| 773 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 774 | - if( 0 == $activity->user_id ) continue; |
|
| 775 | + if( '' == $activity->comment_type ) { |
|
| 776 | + continue; |
|
| 777 | + } |
|
| 778 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
| 779 | + continue; |
|
| 780 | + } |
|
| 781 | + if( 0 == $activity->user_id ) { |
|
| 782 | + continue; |
|
| 783 | + } |
|
| 775 | 784 | $activity_count[] = $activity->comment_ID; |
| 776 | 785 | } |
| 777 | 786 | |
@@ -784,9 +793,15 @@ discard block |
||
| 784 | 793 | $activities = get_comments( $args ); |
| 785 | 794 | |
| 786 | 795 | foreach( $activities as $activity ) { |
| 787 | - if( '' == $activity->comment_type ) continue; |
|
| 788 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 789 | - if( 0 == $activity->user_id ) continue; |
|
| 796 | + if( '' == $activity->comment_type ) { |
|
| 797 | + continue; |
|
| 798 | + } |
|
| 799 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
| 800 | + continue; |
|
| 801 | + } |
|
| 802 | + if( 0 == $activity->user_id ) { |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 790 | 805 | |
| 791 | 806 | $user_exists = get_userdata( $activity->user_id ); |
| 792 | 807 | |
@@ -845,7 +860,9 @@ discard block |
||
| 845 | 860 | |
| 846 | 861 | foreach( $questions as $question ) { |
| 847 | 862 | |
| 848 | - if( ! isset( $question->ID ) ) continue; |
|
| 863 | + if( ! isset( $question->ID ) ) { |
|
| 864 | + continue; |
|
| 865 | + } |
|
| 849 | 866 | |
| 850 | 867 | $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
| 851 | 868 | |
@@ -882,7 +899,9 @@ discard block |
||
| 882 | 899 | |
| 883 | 900 | foreach( $quizzes as $quiz ) { |
| 884 | 901 | |
| 885 | - if( ! isset( $quiz->ID ) ) continue; |
|
| 902 | + if( ! isset( $quiz->ID ) ) { |
|
| 903 | + continue; |
|
| 904 | + } |
|
| 886 | 905 | |
| 887 | 906 | if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
| 888 | 907 | update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
@@ -910,7 +929,9 @@ discard block |
||
| 910 | 929 | |
| 911 | 930 | foreach( $lessons as $lesson ) { |
| 912 | 931 | |
| 913 | - if( ! isset( $lesson->ID ) ) continue; |
|
| 932 | + if( ! isset( $lesson->ID ) ) { |
|
| 933 | + continue; |
|
| 934 | + } |
|
| 914 | 935 | |
| 915 | 936 | $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
| 916 | 937 | |
@@ -984,11 +1005,15 @@ discard block |
||
| 984 | 1005 | |
| 985 | 1006 | foreach( $quizzes as $quiz ) { |
| 986 | 1007 | |
| 987 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
| 1008 | + if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) { |
|
| 1009 | + continue; |
|
| 1010 | + } |
|
| 988 | 1011 | |
| 989 | 1012 | $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
| 990 | 1013 | |
| 991 | - if( empty( $lesson_id ) ) continue; |
|
| 1014 | + if( empty( $lesson_id ) ) { |
|
| 1015 | + continue; |
|
| 1016 | + } |
|
| 992 | 1017 | |
| 993 | 1018 | $data = array( |
| 994 | 1019 | 'ID' => $quiz->ID, |
@@ -1071,8 +1096,7 @@ discard block |
||
| 1071 | 1096 | delete_post_meta( $quiz_id, '_quiz_passmark' ); |
| 1072 | 1097 | delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
| 1073 | 1098 | $d_count++; |
| 1074 | - } |
|
| 1075 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1099 | + } else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1076 | 1100 | |
| 1077 | 1101 | // Quiz has no questions, drop the corresponding data |
| 1078 | 1102 | update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
@@ -1222,20 +1246,16 @@ discard block |
||
| 1222 | 1246 | // Check if the user has to get the passmark and has or not |
| 1223 | 1247 | if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
| 1224 | 1248 | $status = 'passed'; |
| 1225 | - } |
|
| 1226 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1249 | + } elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1227 | 1250 | $status = 'failed'; |
| 1228 | - } |
|
| 1229 | - else { |
|
| 1251 | + } else { |
|
| 1230 | 1252 | $status = 'graded'; |
| 1231 | 1253 | } |
| 1232 | - } |
|
| 1233 | - else { |
|
| 1254 | + } else { |
|
| 1234 | 1255 | // If the lesson has a quiz, but the user doesn't have a grade, it's not yet been graded |
| 1235 | 1256 | $status = 'ungraded'; |
| 1236 | 1257 | } |
| 1237 | - } |
|
| 1238 | - else { |
|
| 1258 | + } else { |
|
| 1239 | 1259 | // Lesson has no quiz, so it can only ever be this status |
| 1240 | 1260 | $status = 'complete'; |
| 1241 | 1261 | } |
@@ -1374,8 +1394,7 @@ discard block |
||
| 1374 | 1394 | } |
| 1375 | 1395 | $meta_data['complete'] = $lessons_completed; |
| 1376 | 1396 | $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
| 1377 | - } |
|
| 1378 | - else { |
|
| 1397 | + } else { |
|
| 1379 | 1398 | // Course has no lessons, therefore cannot be 'complete' |
| 1380 | 1399 | $status = 'in-progress'; |
| 1381 | 1400 | } |
@@ -1506,8 +1525,7 @@ discard block |
||
| 1506 | 1525 | $lessons_completed++; |
| 1507 | 1526 | break; |
| 1508 | 1527 | } |
| 1509 | - } |
|
| 1510 | - else { |
|
| 1528 | + } else { |
|
| 1511 | 1529 | switch ( $lesson_status ) { |
| 1512 | 1530 | case 'complete': // Lesson has no quiz/questions |
| 1513 | 1531 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @access public |
| 30 | 30 | * @since 1.0.2 |
| 31 | 31 | * @static |
| 32 | - * @return void |
|
| 32 | + * @return boolean |
|
| 33 | 33 | */ |
| 34 | 34 | public static function sensei_is_woocommerce_present () { |
| 35 | 35 | if ( class_exists( 'Woocommerce' ) ) { |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * @param string $customer_email |
| 348 | 348 | * @param int $user_id |
| 349 | 349 | * @param int $product_id |
| 350 | - * @return bool |
|
| 350 | + * @return boolean|null |
|
| 351 | 351 | */ |
| 352 | 352 | public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
| 353 | 353 | global $wpdb; |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | /** |
| 445 | 445 | * Save quiz answers submitted by users |
| 446 | 446 | * @param boolean $submitted User's quiz answers |
| 447 | - * @return boolean Whether the answers were saved or not |
|
| 447 | + * @return null|false Whether the answers were saved or not |
|
| 448 | 448 | */ |
| 449 | 449 | public static function sensei_save_quiz_answers( $submitted = false, $user_id = 0 ) { |
| 450 | 450 | if( intval( $user_id ) == 0 ) { |
@@ -507,6 +507,9 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | } // End sensei_save_quiz_answers() |
| 509 | 509 | |
| 510 | + /** |
|
| 511 | + * @return string |
|
| 512 | + */ |
|
| 510 | 513 | public static function upload_file( $file = array() ) { |
| 511 | 514 | |
| 512 | 515 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
@@ -771,8 +774,8 @@ discard block |
||
| 771 | 774 | /** |
| 772 | 775 | * Remove user from lesson, deleting all data from the corresponding quiz |
| 773 | 776 | * |
| 774 | - * @param type $lesson_id |
|
| 775 | - * @param type $user_id |
|
| 777 | + * @param integer $lesson_id |
|
| 778 | + * @param integer $user_id |
|
| 776 | 779 | * @return boolean |
| 777 | 780 | */ |
| 778 | 781 | public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
@@ -809,8 +812,8 @@ discard block |
||
| 809 | 812 | /** |
| 810 | 813 | * Remove a user from a course, deleting all activities across all lessons |
| 811 | 814 | * |
| 812 | - * @param type $course_id |
|
| 813 | - * @param type $user_id |
|
| 815 | + * @param integer $course_id |
|
| 816 | + * @param integer $user_id |
|
| 814 | 817 | * @return boolean |
| 815 | 818 | */ |
| 816 | 819 | public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
@@ -875,7 +878,7 @@ discard block |
||
| 875 | 878 | /** |
| 876 | 879 | * Returns the user_grade for a specific question and user, or sensei_user_answer entry |
| 877 | 880 | * |
| 878 | - * @param mixed $question |
|
| 881 | + * @param integer $question |
|
| 879 | 882 | * @param int $user_id |
| 880 | 883 | * @return string |
| 881 | 884 | */ |
@@ -903,7 +906,7 @@ discard block |
||
| 903 | 906 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 904 | 907 | * |
| 905 | 908 | * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
| 906 | - * @param mixed $question |
|
| 909 | + * @param integer $question |
|
| 907 | 910 | * @param int $user_id |
| 908 | 911 | * @return string |
| 909 | 912 | */ |
@@ -1015,7 +1018,7 @@ discard block |
||
| 1015 | 1018 | * sort_array_by_key sorts array by key |
| 1016 | 1019 | * @since 1.3.0 |
| 1017 | 1020 | * @param $array by ref |
| 1018 | - * @param $key string column name in array |
|
| 1021 | + * @param string $key string column name in array |
|
| 1019 | 1022 | * @return void |
| 1020 | 1023 | */ |
| 1021 | 1024 | public static function sort_array_by_key( $array, $key ) { |
@@ -1062,7 +1065,7 @@ discard block |
||
| 1062 | 1065 | /** |
| 1063 | 1066 | * Get pass mark for course |
| 1064 | 1067 | * @param integer $course_id ID of course |
| 1065 | - * @return integer Pass mark for course |
|
| 1068 | + * @return double Pass mark for course |
|
| 1066 | 1069 | */ |
| 1067 | 1070 | public static function sensei_course_pass_grade( $course_id = 0 ) { |
| 1068 | 1071 | |
@@ -1103,7 +1106,7 @@ discard block |
||
| 1103 | 1106 | * Get user total grade for course |
| 1104 | 1107 | * @param integer $course_id ID of course |
| 1105 | 1108 | * @param integer $user_id ID of user |
| 1106 | - * @return integer User's total grade |
|
| 1109 | + * @return double User's total grade |
|
| 1107 | 1110 | */ |
| 1108 | 1111 | public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
| 1109 | 1112 | |
@@ -1395,9 +1398,9 @@ discard block |
||
| 1395 | 1398 | * Check if a user has started a course or not |
| 1396 | 1399 | * |
| 1397 | 1400 | * @since 1.7.0 |
| 1398 | - * @param type $course_id |
|
| 1399 | - * @param type $user_id |
|
| 1400 | - * @return mixed false or comment_ID |
|
| 1401 | + * @param integer $course_id |
|
| 1402 | + * @param integer $user_id |
|
| 1403 | + * @return false|string false or comment_ID |
|
| 1401 | 1404 | */ |
| 1402 | 1405 | public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
| 1403 | 1406 | |
@@ -1424,7 +1427,7 @@ discard block |
||
| 1424 | 1427 | * @since 1.7.0 |
| 1425 | 1428 | * @param integer $course_id Course ID |
| 1426 | 1429 | * @param integer $user_id User ID |
| 1427 | - * @return int |
|
| 1430 | + * @return null|false |
|
| 1428 | 1431 | */ |
| 1429 | 1432 | public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
| 1430 | 1433 | global $wp_version; |
@@ -1531,7 +1534,7 @@ discard block |
||
| 1531 | 1534 | /** |
| 1532 | 1535 | * Check if a user has completed a course or not |
| 1533 | 1536 | * |
| 1534 | - * @param mixed $course course_id or sensei_course_status entry |
|
| 1537 | + * @param integer $course course_id or sensei_course_status entry |
|
| 1535 | 1538 | * @param int $user_id |
| 1536 | 1539 | * @return boolean |
| 1537 | 1540 | */ |
@@ -1570,9 +1573,9 @@ discard block |
||
| 1570 | 1573 | * Check if a user has started a lesson or not |
| 1571 | 1574 | * |
| 1572 | 1575 | * @since 1.7.0 |
| 1573 | - * @param type $lesson_id |
|
| 1574 | - * @param type $user_id |
|
| 1575 | - * @return mixed false or comment_ID |
|
| 1576 | + * @param integer $lesson_id |
|
| 1577 | + * @param integer $user_id |
|
| 1578 | + * @return string|false false or comment_ID |
|
| 1576 | 1579 | */ |
| 1577 | 1580 | public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
| 1578 | 1581 | |
@@ -1593,7 +1596,7 @@ discard block |
||
| 1593 | 1596 | * Check if a user has completed a lesson or not |
| 1594 | 1597 | * |
| 1595 | 1598 | * @uses Sensei() |
| 1596 | - * @param mixed $lesson lesson_id or sensei_lesson_status entry |
|
| 1599 | + * @param integer $lesson lesson_id or sensei_lesson_status entry |
|
| 1597 | 1600 | * @param int $user_id |
| 1598 | 1601 | * @return boolean |
| 1599 | 1602 | */ |
@@ -1666,9 +1669,9 @@ discard block |
||
| 1666 | 1669 | * Returns the requested course status |
| 1667 | 1670 | * |
| 1668 | 1671 | * @since 1.7.0 |
| 1669 | - * @param type $course_id |
|
| 1670 | - * @param type $user_id |
|
| 1671 | - * @return object |
|
| 1672 | + * @param integer $course_id |
|
| 1673 | + * @param integer $user_id |
|
| 1674 | + * @return integer |
|
| 1672 | 1675 | */ |
| 1673 | 1676 | public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
| 1674 | 1677 | |
@@ -1691,7 +1694,7 @@ discard block |
||
| 1691 | 1694 | * @since 1.7.0 |
| 1692 | 1695 | * @param int $lesson_id |
| 1693 | 1696 | * @param int $user_id |
| 1694 | - * @return object | bool |
|
| 1697 | + * @return integer | bool |
|
| 1695 | 1698 | */ |
| 1696 | 1699 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1697 | 1700 | |
@@ -1750,11 +1753,11 @@ discard block |
||
| 1750 | 1753 | * @since 1.7.0 |
| 1751 | 1754 | * |
| 1752 | 1755 | * @param int|string $user_id |
| 1753 | - * @param int|string $lesson_id |
|
| 1756 | + * @param integer $lesson_id |
|
| 1754 | 1757 | * @param string $status |
| 1755 | 1758 | * @param array $metadata |
| 1756 | 1759 | * |
| 1757 | - * @return mixed false or comment_ID |
|
| 1760 | + * @return null|false false or comment_ID |
|
| 1758 | 1761 | */ |
| 1759 | 1762 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
| 1760 | 1763 | $comment_id = false; |
@@ -1792,7 +1795,7 @@ discard block |
||
| 1792 | 1795 | * @param type $course_id |
| 1793 | 1796 | * @param type $status |
| 1794 | 1797 | * @param type $metadata |
| 1795 | - * @return mixed false or comment_ID |
|
| 1798 | + * @return null|false false or comment_ID |
|
| 1796 | 1799 | */ |
| 1797 | 1800 | public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
| 1798 | 1801 | $comment_id = false; |
@@ -1981,7 +1984,7 @@ discard block |
||
| 1981 | 1984 | * |
| 1982 | 1985 | * @since 1.7.4 |
| 1983 | 1986 | * |
| 1984 | - * @param $data_key |
|
| 1987 | + * @param string $data_key |
|
| 1985 | 1988 | * @param $post_id |
| 1986 | 1989 | * @param int $user_id |
| 1987 | 1990 | * |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Check if WooCommerce is active. |
| 49 | - * |
|
| 49 | + * |
|
| 50 | 50 | * @access public |
| 51 | 51 | * @since 1.0.2 |
| 52 | 52 | * @static |
@@ -191,15 +191,15 @@ discard block |
||
| 191 | 191 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - //Get the comments |
|
| 195 | - /** |
|
| 196 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 197 | - * |
|
| 198 | - * It runs while getting the comments for the given request. |
|
| 199 | - * |
|
| 200 | - * @param int|array $comments |
|
| 201 | - */ |
|
| 202 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 194 | + //Get the comments |
|
| 195 | + /** |
|
| 196 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 197 | + * |
|
| 198 | + * It runs while getting the comments for the given request. |
|
| 199 | + * |
|
| 200 | + * @param int|array $comments |
|
| 201 | + */ |
|
| 202 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 203 | 203 | |
| 204 | 204 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 205 | 205 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -284,18 +284,18 @@ discard block |
||
| 284 | 284 | return $dataset_changes; |
| 285 | 285 | } // End sensei_delete_activities() |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Delete all activity for specified user |
|
| 289 | - * @access public |
|
| 287 | + /** |
|
| 288 | + * Delete all activity for specified user |
|
| 289 | + * @access public |
|
| 290 | 290 | * @since 1.5.0 |
| 291 | - * @param integer $user_id User ID |
|
| 292 | - * @return boolean |
|
| 293 | - */ |
|
| 294 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 291 | + * @param integer $user_id User ID |
|
| 292 | + * @return boolean |
|
| 293 | + */ |
|
| 294 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 295 | 295 | |
| 296 | - $dataset_changes = false; |
|
| 296 | + $dataset_changes = false; |
|
| 297 | 297 | |
| 298 | - if( $user_id ) { |
|
| 298 | + if( $user_id ) { |
|
| 299 | 299 | |
| 300 | 300 | $activities = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
| 301 | 301 | |
@@ -366,11 +366,11 @@ discard block |
||
| 366 | 366 | return false; |
| 367 | 367 | |
| 368 | 368 | $orders = get_posts( array( |
| 369 | - 'posts_per_page' => -1, |
|
| 370 | - 'meta_key' => '_customer_user', |
|
| 371 | - 'meta_value' => intval( $user_id ), |
|
| 372 | - 'post_type' => 'shop_order', |
|
| 373 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 369 | + 'posts_per_page' => -1, |
|
| 370 | + 'meta_key' => '_customer_user', |
|
| 371 | + 'meta_value' => intval( $user_id ), |
|
| 372 | + 'post_type' => 'shop_order', |
|
| 373 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 374 | 374 | ) ); |
| 375 | 375 | |
| 376 | 376 | foreach ( $orders as $order_id ) { |
@@ -511,72 +511,72 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 513 | 513 | |
| 514 | - /** |
|
| 515 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
| 516 | - * |
|
| 517 | - * This filter was mainly added for Unit Testing purposes. |
|
| 518 | - * |
|
| 519 | - * @since 1.7.4 |
|
| 520 | - * |
|
| 521 | - * @param array $file_upload_args { |
|
| 522 | - * array of current values |
|
| 523 | - * |
|
| 524 | - * @type string test_form set to false by default |
|
| 525 | - * } |
|
| 526 | - */ |
|
| 527 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 528 | - |
|
| 529 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 530 | - |
|
| 531 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 532 | - return false; |
|
| 533 | - } else { |
|
| 514 | + /** |
|
| 515 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
| 516 | + * |
|
| 517 | + * This filter was mainly added for Unit Testing purposes. |
|
| 518 | + * |
|
| 519 | + * @since 1.7.4 |
|
| 520 | + * |
|
| 521 | + * @param array $file_upload_args { |
|
| 522 | + * array of current values |
|
| 523 | + * |
|
| 524 | + * @type string test_form set to false by default |
|
| 525 | + * } |
|
| 526 | + */ |
|
| 527 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 528 | + |
|
| 529 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 530 | + |
|
| 531 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 532 | + return false; |
|
| 533 | + } else { |
|
| 534 | 534 | |
| 535 | - $filename = $file_return['file']; |
|
| 535 | + $filename = $file_return['file']; |
|
| 536 | 536 | |
| 537 | - $attachment = array( |
|
| 538 | - 'post_mime_type' => $file_return['type'], |
|
| 539 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 540 | - 'post_content' => '', |
|
| 541 | - 'post_status' => 'inherit', |
|
| 542 | - 'guid' => $file_return['url'] |
|
| 543 | - ); |
|
| 537 | + $attachment = array( |
|
| 538 | + 'post_mime_type' => $file_return['type'], |
|
| 539 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 540 | + 'post_content' => '', |
|
| 541 | + 'post_status' => 'inherit', |
|
| 542 | + 'guid' => $file_return['url'] |
|
| 543 | + ); |
|
| 544 | 544 | |
| 545 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 545 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 546 | 546 | |
| 547 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 548 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 549 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 547 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 548 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 549 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 550 | 550 | |
| 551 | - if( 0 < intval( $attachment_id ) ) { |
|
| 552 | - return $attachment_id; |
|
| 553 | - } |
|
| 554 | - } |
|
| 551 | + if( 0 < intval( $attachment_id ) ) { |
|
| 552 | + return $attachment_id; |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - return false; |
|
| 556 | + return false; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
| 560 | 560 | * Grade quiz automatically |
| 561 | - * |
|
| 562 | - * This function grades each question automatically if the are auto gradable. |
|
| 563 | - * It store all question grades. |
|
| 564 | - * |
|
| 565 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 566 | - * |
|
| 561 | + * |
|
| 562 | + * This function grades each question automatically if the are auto gradable. |
|
| 563 | + * It store all question grades. |
|
| 564 | + * |
|
| 565 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 566 | + * |
|
| 567 | 567 | * @param integer $quiz_id ID of quiz |
| 568 | 568 | * @param array $submitted questions id ans answers { |
| 569 | - * @type int $question_id |
|
| 570 | - * @type mixed $answer |
|
| 571 | - * } |
|
| 569 | + * @type int $question_id |
|
| 570 | + * @type mixed $answer |
|
| 571 | + * } |
|
| 572 | 572 | * @param integer $total_questions Total questions in quiz (not used) |
| 573 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 574 | - * |
|
| 573 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 574 | + * |
|
| 575 | 575 | * @return int $quiz_grade total sum of all question grades |
| 576 | 576 | */ |
| 577 | 577 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
| 578 | 578 | |
| 579 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 579 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 580 | 580 | |
| 581 | 581 | } // End sensei_grade_quiz_auto() |
| 582 | 582 | |
@@ -608,21 +608,21 @@ discard block |
||
| 608 | 608 | |
| 609 | 609 | /** |
| 610 | 610 | * Grade question automatically |
| 611 | - * |
|
| 612 | - * This function checks the question typ and then grades it accordingly. |
|
| 613 | - * |
|
| 614 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 615 | - * |
|
| 611 | + * |
|
| 612 | + * This function checks the question typ and then grades it accordingly. |
|
| 613 | + * |
|
| 614 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 615 | + * |
|
| 616 | 616 | * @param integer $question_id |
| 617 | - * @param string $question_type of the standard Sensei question types |
|
| 617 | + * @param string $question_type of the standard Sensei question types |
|
| 618 | 618 | * @param string $answer |
| 619 | - * @param int $user_id |
|
| 620 | - * |
|
| 619 | + * @param int $user_id |
|
| 620 | + * |
|
| 621 | 621 | * @return int $question_grade |
| 622 | 622 | */ |
| 623 | 623 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
| 624 | 624 | |
| 625 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 625 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 626 | 626 | |
| 627 | 627 | } // end sensei_grade_question_auto |
| 628 | 628 | |
@@ -668,35 +668,35 @@ discard block |
||
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
| 671 | - /** |
|
| 672 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 673 | - * |
|
| 674 | - * @since 1.7.4 |
|
| 675 | - * |
|
| 676 | - * @param integer $user_id |
|
| 677 | - * @param integer $lesson_id |
|
| 678 | - * @param bool $complete |
|
| 679 | - * |
|
| 680 | - * @return mixed boolean or comment_ID |
|
| 681 | - */ |
|
| 682 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 671 | + /** |
|
| 672 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 673 | + * |
|
| 674 | + * @since 1.7.4 |
|
| 675 | + * |
|
| 676 | + * @param integer $user_id |
|
| 677 | + * @param integer $lesson_id |
|
| 678 | + * @param bool $complete |
|
| 679 | + * |
|
| 680 | + * @return mixed boolean or comment_ID |
|
| 681 | + */ |
|
| 682 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 683 | 683 | |
| 684 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 684 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 685 | 685 | |
| 686 | - }// end user_start_lesson() |
|
| 686 | + }// end user_start_lesson() |
|
| 687 | 687 | |
| 688 | 688 | /** |
| 689 | 689 | * Mark a lesson as started for user |
| 690 | - * |
|
| 691 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 692 | - * |
|
| 693 | - * @since 1.6.0 |
|
| 694 | - * |
|
| 690 | + * |
|
| 691 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 692 | + * |
|
| 693 | + * @since 1.6.0 |
|
| 694 | + * |
|
| 695 | 695 | * @param integer $lesson_id ID of lesson |
| 696 | 696 | * @param int| string $user_id default 0 |
| 697 | - * @param bool $complete default false |
|
| 698 | - * |
|
| 699 | - * @return mixed boolean or comment_ID |
|
| 697 | + * @param bool $complete default false |
|
| 698 | + * |
|
| 699 | + * @return mixed boolean or comment_ID |
|
| 700 | 700 | */ |
| 701 | 701 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 702 | 702 | |
@@ -742,21 +742,21 @@ discard block |
||
| 742 | 742 | $metadata['start'] = current_time('mysql'); |
| 743 | 743 | $activity_logged = WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
| 744 | 744 | |
| 745 | - } else { |
|
| 745 | + } else { |
|
| 746 | 746 | |
| 747 | - // if users is already taking the lesson and the status changes to complete update it |
|
| 748 | - $current_user_activity = get_comment($activity_logged); |
|
| 749 | - if( $status=='complete' && |
|
| 750 | - $status != $current_user_activity->comment_approved ){ |
|
| 747 | + // if users is already taking the lesson and the status changes to complete update it |
|
| 748 | + $current_user_activity = get_comment($activity_logged); |
|
| 749 | + if( $status=='complete' && |
|
| 750 | + $status != $current_user_activity->comment_approved ){ |
|
| 751 | 751 | |
| 752 | - $comment = array(); |
|
| 753 | - $comment['comment_ID'] = $activity_logged; |
|
| 754 | - $comment['comment_approved'] = $status; |
|
| 755 | - wp_update_comment( $comment ); |
|
| 752 | + $comment = array(); |
|
| 753 | + $comment['comment_ID'] = $activity_logged; |
|
| 754 | + $comment['comment_approved'] = $status; |
|
| 755 | + wp_update_comment( $comment ); |
|
| 756 | 756 | |
| 757 | - } |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - } |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | 761 | if ( $complete ) { |
| 762 | 762 | // Run this *after* the lesson status has been created/updated |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | /** |
| 903 | 903 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 904 | 904 | * |
| 905 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 905 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 906 | 906 | * @param mixed $question |
| 907 | 907 | * @param int $user_id |
| 908 | 908 | * @return string |
@@ -1019,17 +1019,17 @@ discard block |
||
| 1019 | 1019 | * @return void |
| 1020 | 1020 | */ |
| 1021 | 1021 | public static function sort_array_by_key( $array, $key ) { |
| 1022 | - $sorter = array(); |
|
| 1023 | - $ret = array(); |
|
| 1024 | - reset( $array ); |
|
| 1025 | - foreach ( $array as $ii => $va ) { |
|
| 1026 | - $sorter[$ii] = $va[$key]; |
|
| 1027 | - } // End For Loop |
|
| 1028 | - asort( $sorter ); |
|
| 1029 | - foreach ( $sorter as $ii => $va ) { |
|
| 1030 | - $ret[$ii] = $array[$ii]; |
|
| 1031 | - } // End For Loop |
|
| 1032 | - $array = $ret; |
|
| 1022 | + $sorter = array(); |
|
| 1023 | + $ret = array(); |
|
| 1024 | + reset( $array ); |
|
| 1025 | + foreach ( $array as $ii => $va ) { |
|
| 1026 | + $sorter[$ii] = $va[$key]; |
|
| 1027 | + } // End For Loop |
|
| 1028 | + asort( $sorter ); |
|
| 1029 | + foreach ( $sorter as $ii => $va ) { |
|
| 1030 | + $ret[$ii] = $array[$ii]; |
|
| 1031 | + } // End For Loop |
|
| 1032 | + $array = $ret; |
|
| 1033 | 1033 | } // End sort_array_by_key() |
| 1034 | 1034 | |
| 1035 | 1035 | /** |
@@ -1042,21 +1042,21 @@ discard block |
||
| 1042 | 1042 | $questions_array = array(); |
| 1043 | 1043 | if ( 0 < $quiz_id ) { |
| 1044 | 1044 | $question_args = array( 'post_type' => 'question', |
| 1045 | - 'posts_per_page' => -1, |
|
| 1046 | - 'orderby' => 'ID', |
|
| 1047 | - 'order' => 'ASC', |
|
| 1048 | - 'meta_query' => array( |
|
| 1045 | + 'posts_per_page' => -1, |
|
| 1046 | + 'orderby' => 'ID', |
|
| 1047 | + 'order' => 'ASC', |
|
| 1048 | + 'meta_query' => array( |
|
| 1049 | 1049 | array( |
| 1050 | 1050 | 'key' => '_quiz_id', |
| 1051 | 1051 | 'value' => $quiz_id, |
| 1052 | 1052 | ) |
| 1053 | 1053 | ), |
| 1054 | - 'post_status' => 'any', |
|
| 1055 | - 'suppress_filters' => 0 |
|
| 1056 | - ); |
|
| 1057 | - $questions_array = get_posts( $question_args ); |
|
| 1058 | - } // End If Statement |
|
| 1059 | - return $questions_array; |
|
| 1054 | + 'post_status' => 'any', |
|
| 1055 | + 'suppress_filters' => 0 |
|
| 1056 | + ); |
|
| 1057 | + $questions_array = get_posts( $question_args ); |
|
| 1058 | + } // End If Statement |
|
| 1059 | + return $questions_array; |
|
| 1060 | 1060 | } // End lesson_quiz_questions() |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1296,20 +1296,20 @@ discard block |
||
| 1296 | 1296 | } |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - // add next lesson button |
|
| 1300 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1301 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1299 | + // add next lesson button |
|
| 1300 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1301 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1302 | 1302 | |
| 1303 | - // Output HTML |
|
| 1304 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1305 | - $message .= '<a class="button next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1306 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1307 | - .'</a>'; |
|
| 1303 | + // Output HTML |
|
| 1304 | + if ( ( 0 < $next_lesson_id ) ) { |
|
| 1305 | + $message .= '<a class="button next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1306 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1307 | + .'</a>'; |
|
| 1308 | 1308 | |
| 1309 | - } |
|
| 1309 | + } |
|
| 1310 | 1310 | |
| 1311 | 1311 | } |
| 1312 | - // Lesson/Quiz not complete |
|
| 1312 | + // Lesson/Quiz not complete |
|
| 1313 | 1313 | else { |
| 1314 | 1314 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1315 | 1315 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1406,9 +1406,9 @@ discard block |
||
| 1406 | 1406 | $user_id = get_current_user_id(); |
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | - if( ! $user_id > 0 ){ |
|
| 1410 | - return false; |
|
| 1411 | - } |
|
| 1409 | + if( ! $user_id > 0 ){ |
|
| 1410 | + return false; |
|
| 1411 | + } |
|
| 1412 | 1412 | |
| 1413 | 1413 | $user_course_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
| 1414 | 1414 | if( $user_course_status_id ) { |
@@ -1549,14 +1549,14 @@ discard block |
||
| 1549 | 1549 | $user_id = get_current_user_id(); |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1553 | - $course = $course->ID; |
|
| 1554 | - } |
|
| 1552 | + if( is_a( $course, 'WP_Post' ) ){ |
|
| 1553 | + $course = $course->ID; |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | 1556 | $user_course_status = WooThemes_Sensei_Utils::user_course_status( $course , $user_id ); |
| 1557 | 1557 | if( isset( $user_course_status->comment_approved ) ){ |
| 1558 | - $user_course_status = $user_course_status->comment_approved; |
|
| 1559 | - } |
|
| 1558 | + $user_course_status = $user_course_status->comment_approved; |
|
| 1559 | + } |
|
| 1560 | 1560 | |
| 1561 | 1561 | } |
| 1562 | 1562 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1592,7 +1592,7 @@ discard block |
||
| 1592 | 1592 | /** |
| 1593 | 1593 | * Check if a user has completed a lesson or not |
| 1594 | 1594 | * |
| 1595 | - * @uses Sensei() |
|
| 1595 | + * @uses Sensei() |
|
| 1596 | 1596 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
| 1597 | 1597 | * @param int $user_id |
| 1598 | 1598 | * @return boolean |
@@ -1613,10 +1613,10 @@ discard block |
||
| 1613 | 1613 | $user_id = get_current_user_id(); |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | - // the user is not logged in |
|
| 1617 | - if( ! $user_id > 0 ){ |
|
| 1618 | - return false; |
|
| 1619 | - } |
|
| 1616 | + // the user is not logged in |
|
| 1617 | + if( ! $user_id > 0 ){ |
|
| 1618 | + return false; |
|
| 1619 | + } |
|
| 1620 | 1620 | $_user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
| 1621 | 1621 | |
| 1622 | 1622 | if ( $_user_lesson_status ) { |
@@ -1695,9 +1695,9 @@ discard block |
||
| 1695 | 1695 | */ |
| 1696 | 1696 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1697 | 1697 | |
| 1698 | - if( ! $user_id ) { |
|
| 1699 | - $user_id = get_current_user_id(); |
|
| 1700 | - } |
|
| 1698 | + if( ! $user_id ) { |
|
| 1699 | + $user_id = get_current_user_id(); |
|
| 1700 | + } |
|
| 1701 | 1701 | |
| 1702 | 1702 | if( $lesson_id > 0 && $user_id > 0 ) { |
| 1703 | 1703 | |
@@ -1748,12 +1748,12 @@ discard block |
||
| 1748 | 1748 | * Sets the status for the lesson |
| 1749 | 1749 | * |
| 1750 | 1750 | * @since 1.7.0 |
| 1751 | - * |
|
| 1751 | + * |
|
| 1752 | 1752 | * @param int|string $user_id |
| 1753 | 1753 | * @param int|string $lesson_id |
| 1754 | 1754 | * @param string $status |
| 1755 | 1755 | * @param array $metadata |
| 1756 | - * |
|
| 1756 | + * |
|
| 1757 | 1757 | * @return mixed false or comment_ID |
| 1758 | 1758 | */ |
| 1759 | 1759 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1903,360 +1903,360 @@ discard block |
||
| 1903 | 1903 | return $pieces; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | - /** |
|
| 1907 | - * |
|
| 1908 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1909 | - * @since 1.7.4 |
|
| 1910 | - * |
|
| 1911 | - * @param string $data_key maximum 39 characters allowed |
|
| 1912 | - * @param int $post_id |
|
| 1913 | - * @param mixed $value |
|
| 1914 | - * @param int $user_id |
|
| 1915 | - * |
|
| 1916 | - * @return bool $success |
|
| 1917 | - */ |
|
| 1918 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1919 | - |
|
| 1920 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1921 | - |
|
| 1922 | - }// end add_user_data |
|
| 1923 | - |
|
| 1924 | - /** |
|
| 1925 | - * add user specific data to the passed in sensei post type id |
|
| 1926 | - * |
|
| 1927 | - * This function saves comment meta on the users current status. If no status is available |
|
| 1928 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1929 | - * |
|
| 1930 | - * @since 1.7.4 |
|
| 1931 | - * |
|
| 1932 | - * @param string $data_key maximum 39 characters allowed |
|
| 1933 | - * @param int $post_id |
|
| 1934 | - * @param mixed $value |
|
| 1935 | - * @param int $user_id |
|
| 1936 | - * |
|
| 1937 | - * @return bool $success |
|
| 1938 | - */ |
|
| 1939 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1940 | - |
|
| 1941 | - if( ! ( $user_id > 0 ) ){ |
|
| 1942 | - $user_id = get_current_user_id(); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1946 | - $post_type = get_post_type( $post_id ); |
|
| 1947 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1948 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1949 | - || !get_userdata( $user_id ) |
|
| 1950 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1951 | - |
|
| 1952 | - return false; |
|
| 1953 | - } |
|
| 1954 | - |
|
| 1955 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1956 | - // and get the activity ID |
|
| 1957 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1958 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1959 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1960 | - |
|
| 1961 | - $start_function = 'user_start_'.$post_type; |
|
| 1962 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1963 | - |
|
| 1964 | - }else{ |
|
| 1965 | - |
|
| 1966 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1967 | - |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - // store the data |
|
| 1971 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1972 | - |
|
| 1973 | - return $success; |
|
| 1974 | - |
|
| 1975 | - }//update_user_data |
|
| 1976 | - |
|
| 1977 | - /** |
|
| 1978 | - * Get the user data stored on the passed in post type |
|
| 1979 | - * |
|
| 1980 | - * This function gets the comment meta on the lesson or course status |
|
| 1981 | - * |
|
| 1982 | - * @since 1.7.4 |
|
| 1983 | - * |
|
| 1984 | - * @param $data_key |
|
| 1985 | - * @param $post_id |
|
| 1986 | - * @param int $user_id |
|
| 1987 | - * |
|
| 1988 | - * @return mixed $user_data_value |
|
| 1989 | - */ |
|
| 1990 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1991 | - |
|
| 1992 | - $user_data_value = true; |
|
| 1993 | - |
|
| 1994 | - if( ! ( $user_id > 0 ) ){ |
|
| 1995 | - $user_id = get_current_user_id(); |
|
| 1996 | - } |
|
| 1997 | - |
|
| 1998 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1999 | - $post_type = get_post_type( $post_id ); |
|
| 2000 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2001 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2002 | - || ! get_userdata( $user_id ) |
|
| 2003 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2004 | - |
|
| 2005 | - return false; |
|
| 2006 | - } |
|
| 2007 | - |
|
| 2008 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2009 | - // and get the activity ID |
|
| 2010 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2011 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2012 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2013 | - return false; |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2017 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2018 | - |
|
| 2019 | - return $user_data_value; |
|
| 2020 | - |
|
| 2021 | - }// end get_user_data |
|
| 2022 | - |
|
| 2023 | - /** |
|
| 2024 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 2025 | - * |
|
| 2026 | - * @param int $data_key |
|
| 2027 | - * @param int $post_id |
|
| 2028 | - * @param int $user_id |
|
| 2029 | - * |
|
| 2030 | - * @return bool $deleted |
|
| 2031 | - */ |
|
| 2032 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2033 | - $deleted = true; |
|
| 1906 | + /** |
|
| 1907 | + * |
|
| 1908 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1909 | + * @since 1.7.4 |
|
| 1910 | + * |
|
| 1911 | + * @param string $data_key maximum 39 characters allowed |
|
| 1912 | + * @param int $post_id |
|
| 1913 | + * @param mixed $value |
|
| 1914 | + * @param int $user_id |
|
| 1915 | + * |
|
| 1916 | + * @return bool $success |
|
| 1917 | + */ |
|
| 1918 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 2034 | 1919 | |
| 2035 | - if( ! ( $user_id > 0 ) ){ |
|
| 2036 | - $user_id = get_current_user_id(); |
|
| 2037 | - } |
|
| 1920 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 2038 | 1921 | |
| 2039 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2040 | - $post_type = get_post_type( $post_id ); |
|
| 2041 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2042 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2043 | - || ! get_userdata( $user_id ) |
|
| 2044 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1922 | + }// end add_user_data |
|
| 2045 | 1923 | |
| 2046 | - return false; |
|
| 2047 | - } |
|
| 1924 | + /** |
|
| 1925 | + * add user specific data to the passed in sensei post type id |
|
| 1926 | + * |
|
| 1927 | + * This function saves comment meta on the users current status. If no status is available |
|
| 1928 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1929 | + * |
|
| 1930 | + * @since 1.7.4 |
|
| 1931 | + * |
|
| 1932 | + * @param string $data_key maximum 39 characters allowed |
|
| 1933 | + * @param int $post_id |
|
| 1934 | + * @param mixed $value |
|
| 1935 | + * @param int $user_id |
|
| 1936 | + * |
|
| 1937 | + * @return bool $success |
|
| 1938 | + */ |
|
| 1939 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 2048 | 1940 | |
| 2049 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2050 | - // and get the activity ID |
|
| 2051 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2052 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2053 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2054 | - return false; |
|
| 2055 | - } |
|
| 1941 | + if( ! ( $user_id > 0 ) ){ |
|
| 1942 | + $user_id = get_current_user_id(); |
|
| 1943 | + } |
|
| 2056 | 1944 | |
| 2057 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2058 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 1945 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1946 | + $post_type = get_post_type( $post_id ); |
|
| 1947 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1948 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1949 | + || !get_userdata( $user_id ) |
|
| 1950 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 2059 | 1951 | |
| 2060 | - return $deleted; |
|
| 1952 | + return false; |
|
| 1953 | + } |
|
| 2061 | 1954 | |
| 2062 | - }// end delete_user_data |
|
| 1955 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1956 | + // and get the activity ID |
|
| 1957 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1958 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1959 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2063 | 1960 | |
| 1961 | + $start_function = 'user_start_'.$post_type; |
|
| 1962 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 2064 | 1963 | |
| 2065 | - /** |
|
| 2066 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2067 | - * |
|
| 2068 | - * @since 1.8.0 |
|
| 2069 | - * |
|
| 2070 | - * @param string $selected_value |
|
| 2071 | - * @param $options{ |
|
| 2072 | - * @type string $value the value saved in the database |
|
| 2073 | - * @type string $option what the user will see in the list of items |
|
| 2074 | - * } |
|
| 2075 | - * @param array $attributes{ |
|
| 2076 | - * @type string $attribute type such name or id etc. |
|
| 2077 | - * @type string $value |
|
| 2078 | - * } |
|
| 2079 | - * @param bool $enable_none_option |
|
| 2080 | - * |
|
| 2081 | - * @return string $drop_down_element |
|
| 2082 | - */ |
|
| 2083 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 1964 | + }else{ |
|
| 2084 | 1965 | |
| 2085 | - $drop_down_element = ''; |
|
| 1966 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2086 | 1967 | |
| 2087 | - // setup the basic attributes |
|
| 2088 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 1968 | + } |
|
| 2089 | 1969 | |
| 2090 | - $attributes['name'] = 'sensei-options'; |
|
| 1970 | + // store the data |
|
| 1971 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 2091 | 1972 | |
| 2092 | - } |
|
| 1973 | + return $success; |
|
| 2093 | 1974 | |
| 2094 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 1975 | + }//update_user_data |
|
| 2095 | 1976 | |
| 2096 | - $attributes['id'] = 'sensei-options'; |
|
| 1977 | + /** |
|
| 1978 | + * Get the user data stored on the passed in post type |
|
| 1979 | + * |
|
| 1980 | + * This function gets the comment meta on the lesson or course status |
|
| 1981 | + * |
|
| 1982 | + * @since 1.7.4 |
|
| 1983 | + * |
|
| 1984 | + * @param $data_key |
|
| 1985 | + * @param $post_id |
|
| 1986 | + * @param int $user_id |
|
| 1987 | + * |
|
| 1988 | + * @return mixed $user_data_value |
|
| 1989 | + */ |
|
| 1990 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 2097 | 1991 | |
| 2098 | - } |
|
| 1992 | + $user_data_value = true; |
|
| 2099 | 1993 | |
| 2100 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 1994 | + if( ! ( $user_id > 0 ) ){ |
|
| 1995 | + $user_id = get_current_user_id(); |
|
| 1996 | + } |
|
| 2101 | 1997 | |
| 2102 | - $attributes['class'] ='chosen_select widefat'; |
|
| 1998 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1999 | + $post_type = get_post_type( $post_id ); |
|
| 2000 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2001 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2002 | + || ! get_userdata( $user_id ) |
|
| 2003 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2103 | 2004 | |
| 2104 | - } |
|
| 2005 | + return false; |
|
| 2006 | + } |
|
| 2007 | + |
|
| 2008 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2009 | + // and get the activity ID |
|
| 2010 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2011 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2012 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2013 | + return false; |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2017 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2018 | + |
|
| 2019 | + return $user_data_value; |
|
| 2020 | + |
|
| 2021 | + }// end get_user_data |
|
| 2022 | + |
|
| 2023 | + /** |
|
| 2024 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 2025 | + * |
|
| 2026 | + * @param int $data_key |
|
| 2027 | + * @param int $post_id |
|
| 2028 | + * @param int $user_id |
|
| 2029 | + * |
|
| 2030 | + * @return bool $deleted |
|
| 2031 | + */ |
|
| 2032 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2033 | + $deleted = true; |
|
| 2034 | + |
|
| 2035 | + if( ! ( $user_id > 0 ) ){ |
|
| 2036 | + $user_id = get_current_user_id(); |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2040 | + $post_type = get_post_type( $post_id ); |
|
| 2041 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2042 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2043 | + || ! get_userdata( $user_id ) |
|
| 2044 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2045 | + |
|
| 2046 | + return false; |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2050 | + // and get the activity ID |
|
| 2051 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2052 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2053 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2054 | + return false; |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2058 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2059 | + |
|
| 2060 | + return $deleted; |
|
| 2061 | + |
|
| 2062 | + }// end delete_user_data |
|
| 2063 | + |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2067 | + * |
|
| 2068 | + * @since 1.8.0 |
|
| 2069 | + * |
|
| 2070 | + * @param string $selected_value |
|
| 2071 | + * @param $options{ |
|
| 2072 | + * @type string $value the value saved in the database |
|
| 2073 | + * @type string $option what the user will see in the list of items |
|
| 2074 | + * } |
|
| 2075 | + * @param array $attributes{ |
|
| 2076 | + * @type string $attribute type such name or id etc. |
|
| 2077 | + * @type string $value |
|
| 2078 | + * } |
|
| 2079 | + * @param bool $enable_none_option |
|
| 2080 | + * |
|
| 2081 | + * @return string $drop_down_element |
|
| 2082 | + */ |
|
| 2083 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2084 | + |
|
| 2085 | + $drop_down_element = ''; |
|
| 2105 | 2086 | |
| 2106 | - // create element attributes |
|
| 2107 | - $combined_attributes = ''; |
|
| 2108 | - foreach( $attributes as $attribute => $value ){ |
|
| 2087 | + // setup the basic attributes |
|
| 2088 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2109 | 2089 | |
| 2110 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2090 | + $attributes['name'] = 'sensei-options'; |
|
| 2111 | 2091 | |
| 2112 | - }// end for each |
|
| 2092 | + } |
|
| 2113 | 2093 | |
| 2094 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2114 | 2095 | |
| 2115 | - // create the select element |
|
| 2116 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2096 | + $attributes['id'] = 'sensei-options'; |
|
| 2117 | 2097 | |
| 2118 | - // show the none option if the client requested |
|
| 2119 | - if( $enable_none_option ) { |
|
| 2120 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2121 | - } |
|
| 2098 | + } |
|
| 2122 | 2099 | |
| 2123 | - if ( count( $options ) > 0 ) { |
|
| 2100 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2124 | 2101 | |
| 2125 | - foreach ($options as $value => $option ){ |
|
| 2102 | + $attributes['class'] ='chosen_select widefat'; |
|
| 2126 | 2103 | |
| 2127 | - $element = ''; |
|
| 2128 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2129 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2130 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2104 | + } |
|
| 2131 | 2105 | |
| 2132 | - // add the element to the select html |
|
| 2133 | - $drop_down_element.= $element; |
|
| 2134 | - } // End For Loop |
|
| 2106 | + // create element attributes |
|
| 2107 | + $combined_attributes = ''; |
|
| 2108 | + foreach( $attributes as $attribute => $value ){ |
|
| 2135 | 2109 | |
| 2136 | - } // End If Statement |
|
| 2110 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2137 | 2111 | |
| 2138 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2112 | + }// end for each |
|
| 2139 | 2113 | |
| 2140 | - return $drop_down_element; |
|
| 2141 | 2114 | |
| 2142 | - }// generate_drop_down |
|
| 2115 | + // create the select element |
|
| 2116 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2117 | + |
|
| 2118 | + // show the none option if the client requested |
|
| 2119 | + if( $enable_none_option ) { |
|
| 2120 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2121 | + } |
|
| 2143 | 2122 | |
| 2144 | - /** |
|
| 2145 | - * Wrapper for the default php round() function. |
|
| 2146 | - * This allows us to give more control to a user on how they can round Sensei |
|
| 2147 | - * decimals passed through this function. |
|
| 2148 | - * |
|
| 2149 | - * @since 1.8.5 |
|
| 2150 | - * |
|
| 2151 | - * @param double $val |
|
| 2152 | - * @param int $precision |
|
| 2153 | - * @param $mode |
|
| 2154 | - * @param string $context |
|
| 2155 | - * |
|
| 2156 | - * @return double $val |
|
| 2157 | - */ |
|
| 2158 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2123 | + if ( count( $options ) > 0 ) { |
|
| 2159 | 2124 | |
| 2160 | - /**å |
|
| 2125 | + foreach ($options as $value => $option ){ |
|
| 2126 | + |
|
| 2127 | + $element = ''; |
|
| 2128 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2129 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2130 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2131 | + |
|
| 2132 | + // add the element to the select html |
|
| 2133 | + $drop_down_element.= $element; |
|
| 2134 | + } // End For Loop |
|
| 2135 | + |
|
| 2136 | + } // End If Statement |
|
| 2137 | + |
|
| 2138 | + $drop_down_element .= '</select>' . "\n"; |
|
| 2139 | + |
|
| 2140 | + return $drop_down_element; |
|
| 2141 | + |
|
| 2142 | + }// generate_drop_down |
|
| 2143 | + |
|
| 2144 | + /** |
|
| 2145 | + * Wrapper for the default php round() function. |
|
| 2146 | + * This allows us to give more control to a user on how they can round Sensei |
|
| 2147 | + * decimals passed through this function. |
|
| 2148 | + * |
|
| 2149 | + * @since 1.8.5 |
|
| 2150 | + * |
|
| 2151 | + * @param double $val |
|
| 2152 | + * @param int $precision |
|
| 2153 | + * @param $mode |
|
| 2154 | + * @param string $context |
|
| 2155 | + * |
|
| 2156 | + * @return double $val |
|
| 2157 | + */ |
|
| 2158 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2159 | + |
|
| 2160 | + /**å |
|
| 2161 | 2161 | * Change the precision for the Sensei_Utils::round function. |
| 2162 | 2162 | * the precision given will be passed into the php round function |
| 2163 | 2163 | * @since 1.8.5 |
| 2164 | 2164 | */ |
| 2165 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2166 | - |
|
| 2167 | - /** |
|
| 2168 | - * Change the mode for the Sensei_Utils::round function. |
|
| 2169 | - * the mode given will be passed into the php round function |
|
| 2170 | - * |
|
| 2171 | - * This applies only to PHP version 5.3.0 and greater |
|
| 2172 | - * |
|
| 2173 | - * @since 1.8.5 |
|
| 2174 | - */ |
|
| 2175 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2165 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2176 | 2166 | |
| 2177 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2167 | + /** |
|
| 2168 | + * Change the mode for the Sensei_Utils::round function. |
|
| 2169 | + * the mode given will be passed into the php round function |
|
| 2170 | + * |
|
| 2171 | + * This applies only to PHP version 5.3.0 and greater |
|
| 2172 | + * |
|
| 2173 | + * @since 1.8.5 |
|
| 2174 | + */ |
|
| 2175 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2178 | 2176 | |
| 2179 | - return round( $val, $precision, $mode ); |
|
| 2177 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2180 | 2178 | |
| 2181 | - }else{ |
|
| 2179 | + return round( $val, $precision, $mode ); |
|
| 2182 | 2180 | |
| 2183 | - return round( $val, $precision ); |
|
| 2181 | + }else{ |
|
| 2184 | 2182 | |
| 2185 | - } |
|
| 2183 | + return round( $val, $precision ); |
|
| 2186 | 2184 | |
| 2187 | - } |
|
| 2185 | + } |
|
| 2188 | 2186 | |
| 2189 | - /** |
|
| 2190 | - * Returns the current url with all the query vars |
|
| 2191 | - * |
|
| 2192 | - * @since 1.9.0 |
|
| 2193 | - * @return string $url |
|
| 2194 | - */ |
|
| 2195 | - public static function get_current_url(){ |
|
| 2187 | + } |
|
| 2196 | 2188 | |
| 2197 | - global $wp; |
|
| 2198 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2199 | - if ( isset( $_GET ) ) { |
|
| 2189 | + /** |
|
| 2190 | + * Returns the current url with all the query vars |
|
| 2191 | + * |
|
| 2192 | + * @since 1.9.0 |
|
| 2193 | + * @return string $url |
|
| 2194 | + */ |
|
| 2195 | + public static function get_current_url(){ |
|
| 2200 | 2196 | |
| 2201 | - foreach ($_GET as $param => $val ) { |
|
| 2197 | + global $wp; |
|
| 2198 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2199 | + if ( isset( $_GET ) ) { |
|
| 2202 | 2200 | |
| 2203 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2201 | + foreach ($_GET as $param => $val ) { |
|
| 2204 | 2202 | |
| 2205 | - } |
|
| 2206 | - } |
|
| 2203 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2207 | 2204 | |
| 2208 | - return $current_url; |
|
| 2209 | - } |
|
| 2205 | + } |
|
| 2206 | + } |
|
| 2210 | 2207 | |
| 2211 | - /** |
|
| 2212 | - * Restore the global WP_Query |
|
| 2213 | - * |
|
| 2214 | - * @since 1.9.0 |
|
| 2215 | - */ |
|
| 2216 | - public static function restore_wp_query() { |
|
| 2208 | + return $current_url; |
|
| 2209 | + } |
|
| 2217 | 2210 | |
| 2218 | - wp_reset_query(); |
|
| 2211 | + /** |
|
| 2212 | + * Restore the global WP_Query |
|
| 2213 | + * |
|
| 2214 | + * @since 1.9.0 |
|
| 2215 | + */ |
|
| 2216 | + public static function restore_wp_query() { |
|
| 2219 | 2217 | |
| 2220 | - } |
|
| 2218 | + wp_reset_query(); |
|
| 2221 | 2219 | |
| 2222 | - /** |
|
| 2223 | - * Merge two arrays in a zip like fashion. |
|
| 2224 | - * If one array is longer than the other the elements will be apended |
|
| 2225 | - * to the end of the resulting array. |
|
| 2226 | - * |
|
| 2227 | - * @since 1.9.0 |
|
| 2228 | - * |
|
| 2229 | - * @param array $array_a |
|
| 2230 | - * @param array $array_b |
|
| 2231 | - * @return array $merged_array |
|
| 2232 | - */ |
|
| 2233 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2220 | + } |
|
| 2234 | 2221 | |
| 2235 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2236 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2237 | - } |
|
| 2222 | + /** |
|
| 2223 | + * Merge two arrays in a zip like fashion. |
|
| 2224 | + * If one array is longer than the other the elements will be apended |
|
| 2225 | + * to the end of the resulting array. |
|
| 2226 | + * |
|
| 2227 | + * @since 1.9.0 |
|
| 2228 | + * |
|
| 2229 | + * @param array $array_a |
|
| 2230 | + * @param array $array_b |
|
| 2231 | + * @return array $merged_array |
|
| 2232 | + */ |
|
| 2233 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2238 | 2234 | |
| 2239 | - $merged_array = array(); |
|
| 2240 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2235 | + if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2236 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2237 | + } |
|
| 2241 | 2238 | |
| 2242 | - // Zip arrays |
|
| 2243 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2239 | + $merged_array = array(); |
|
| 2240 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2244 | 2241 | |
| 2245 | - // if has an element at current index push a on top |
|
| 2246 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2247 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2248 | - } |
|
| 2242 | + // Zip arrays |
|
| 2243 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2249 | 2244 | |
| 2250 | - // next if $array_b has an element at current index push a on top of the element |
|
| 2251 | - // from a if there was one, if not the element before that. |
|
| 2252 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2253 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2254 | - } |
|
| 2245 | + // if has an element at current index push a on top |
|
| 2246 | + if( isset( $array_a[ $i ] ) ){ |
|
| 2247 | + $merged_array[] = $array_a[ $i ] ; |
|
| 2248 | + } |
|
| 2255 | 2249 | |
| 2256 | - } |
|
| 2250 | + // next if $array_b has an element at current index push a on top of the element |
|
| 2251 | + // from a if there was one, if not the element before that. |
|
| 2252 | + if( isset( $array_b[ $i ] ) ){ |
|
| 2253 | + $merged_array[] = $array_b[ $i ] ; |
|
| 2254 | + } |
|
| 2255 | + |
|
| 2256 | + } |
|
| 2257 | 2257 | |
| 2258 | - return $merged_array; |
|
| 2259 | - } |
|
| 2258 | + return $merged_array; |
|
| 2259 | + } |
|
| 2260 | 2260 | |
| 2261 | 2261 | } // End Class |
| 2262 | 2262 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Utilities Class |
@@ -19,9 +19,9 @@ discard block |
||
| 19 | 19 | * @since 1.0.0 |
| 20 | 20 | * @return string The URL to the placeholder thumbnail image. |
| 21 | 21 | */ |
| 22 | - public static function get_placeholder_image () { |
|
| 22 | + public static function get_placeholder_image() { |
|
| 23 | 23 | |
| 24 | - return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) ); |
|
| 24 | + return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png')); |
|
| 25 | 25 | } // End get_placeholder_image() |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * @static |
| 32 | 32 | * @return void |
| 33 | 33 | */ |
| 34 | - public static function sensei_is_woocommerce_present () { |
|
| 35 | - if ( class_exists( 'Woocommerce' ) ) { |
|
| 34 | + public static function sensei_is_woocommerce_present() { |
|
| 35 | + if (class_exists('Woocommerce')) { |
|
| 36 | 36 | return true; |
| 37 | 37 | } else { |
| 38 | - $active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) ); |
|
| 39 | - if ( is_array( $active_plugins ) && in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) { |
|
| 38 | + $active_plugins = apply_filters('active_plugins', get_option('active_plugins')); |
|
| 39 | + if (is_array($active_plugins) && in_array('woocommerce/woocommerce.php', $active_plugins)) { |
|
| 40 | 40 | return true; |
| 41 | 41 | } else { |
| 42 | 42 | return false; |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @static |
| 53 | 53 | * @return boolean |
| 54 | 54 | */ |
| 55 | - public static function sensei_is_woocommerce_activated () { |
|
| 55 | + public static function sensei_is_woocommerce_activated() { |
|
| 56 | 56 | |
| 57 | - return WooThemes_Sensei_Utils::sensei_is_woocommerce_present() && isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 57 | + return WooThemes_Sensei_Utils::sensei_is_woocommerce_present() && isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 58 | 58 | |
| 59 | 59 | } // End sensei_is_woocommerce_activated() |
| 60 | 60 | |
@@ -65,70 +65,70 @@ discard block |
||
| 65 | 65 | * @param array $args (default: array()) |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public static function sensei_log_activity ( $args = array() ) { |
|
| 68 | + public static function sensei_log_activity($args = array()) { |
|
| 69 | 69 | global $wpdb; |
| 70 | 70 | |
| 71 | 71 | // Args, minimum data required for WP |
| 72 | 72 | $data = array( |
| 73 | - 'comment_post_ID' => intval( $args['post_id'] ), |
|
| 73 | + 'comment_post_ID' => intval($args['post_id']), |
|
| 74 | 74 | 'comment_author' => '', // Not needed |
| 75 | 75 | 'comment_author_email' => '', // Not needed |
| 76 | 76 | 'comment_author_url' => '', // Not needed |
| 77 | - 'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '', |
|
| 78 | - 'comment_type' => esc_attr( $args['type'] ), |
|
| 79 | - 'user_id' => intval( $args['user_id'] ), |
|
| 80 | - 'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer' |
|
| 77 | + 'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '', |
|
| 78 | + 'comment_type' => esc_attr($args['type']), |
|
| 79 | + 'user_id' => intval($args['user_id']), |
|
| 80 | + 'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer' |
|
| 81 | 81 | ); |
| 82 | 82 | // Allow extra data |
| 83 | - if ( !empty($args['username']) ) { |
|
| 84 | - $data['comment_author'] = sanitize_user( $args['username'] ); |
|
| 83 | + if ( ! empty($args['username'])) { |
|
| 84 | + $data['comment_author'] = sanitize_user($args['username']); |
|
| 85 | 85 | } |
| 86 | - if ( !empty($args['user_email']) ) { |
|
| 87 | - $data['comment_author_email'] = sanitize_email( $args['user_email'] ); |
|
| 86 | + if ( ! empty($args['user_email'])) { |
|
| 87 | + $data['comment_author_email'] = sanitize_email($args['user_email']); |
|
| 88 | 88 | } |
| 89 | - if ( !empty($args['user_url']) ) { |
|
| 90 | - $data['comment_author_url'] = esc_url( $args['user_url'] ); |
|
| 89 | + if ( ! empty($args['user_url'])) { |
|
| 90 | + $data['comment_author_url'] = esc_url($args['user_url']); |
|
| 91 | 91 | } |
| 92 | - if ( !empty($args['parent']) ) { |
|
| 92 | + if ( ! empty($args['parent'])) { |
|
| 93 | 93 | $data['comment_parent'] = $args['parent']; |
| 94 | 94 | } |
| 95 | 95 | // Sanity check |
| 96 | - if ( empty($args['user_id']) ) { |
|
| 97 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 96 | + if (empty($args['user_id'])) { |
|
| 97 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - do_action( 'sensei_log_activity_before', $args, $data ); |
|
| 101 | + do_action('sensei_log_activity_before', $args, $data); |
|
| 102 | 102 | |
| 103 | 103 | $flush_cache = false; |
| 104 | 104 | |
| 105 | 105 | // Custom Logic |
| 106 | 106 | // Check if comment exists first |
| 107 | - $comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) ); |
|
| 108 | - if ( ! $comment_id ) { |
|
| 107 | + $comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'])); |
|
| 108 | + if ( ! $comment_id) { |
|
| 109 | 109 | // Add the comment |
| 110 | - $comment_id = wp_insert_comment( $data ); |
|
| 110 | + $comment_id = wp_insert_comment($data); |
|
| 111 | 111 | |
| 112 | 112 | $flush_cache = true; |
| 113 | - } elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) { |
|
| 113 | + } elseif (isset($args['action']) && 'update' == $args['action']) { |
|
| 114 | 114 | // Update the comment if an update was requested |
| 115 | 115 | $data['comment_ID'] = $comment_id; |
| 116 | 116 | // By default update the timestamp of the comment |
| 117 | - if ( empty($args['keep_time']) ) { |
|
| 117 | + if (empty($args['keep_time'])) { |
|
| 118 | 118 | $data['comment_date'] = current_time('mysql'); |
| 119 | 119 | } |
| 120 | - wp_update_comment( $data ); |
|
| 120 | + wp_update_comment($data); |
|
| 121 | 121 | $flush_cache = true; |
| 122 | 122 | } // End If Statement |
| 123 | 123 | |
| 124 | 124 | // Manually Flush the Cache |
| 125 | - if ( $flush_cache ) { |
|
| 125 | + if ($flush_cache) { |
|
| 126 | 126 | wp_cache_flush(); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - do_action( 'sensei_log_activity_after', $args, $data, $comment_id ); |
|
| 129 | + do_action('sensei_log_activity_after', $args, $data, $comment_id); |
|
| 130 | 130 | |
| 131 | - if ( 0 < $comment_id ) { |
|
| 131 | + if (0 < $comment_id) { |
|
| 132 | 132 | // Return the ID so that it can be used for meta data storage |
| 133 | 133 | return $comment_id; |
| 134 | 134 | } else { |
@@ -145,41 +145,41 @@ discard block |
||
| 145 | 145 | * @param bool $return_comments (default: false) |
| 146 | 146 | * @return mixed | int |
| 147 | 147 | */ |
| 148 | - public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) { |
|
| 148 | + public static function sensei_check_for_activity($args = array(), $return_comments = false) { |
|
| 149 | 149 | |
| 150 | 150 | global $wp_version; |
| 151 | - if ( !$return_comments ) { |
|
| 151 | + if ( ! $return_comments) { |
|
| 152 | 152 | $args['count'] = true; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Are we only retrieving a single entry, or not care about the order... |
| 156 | - if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){ |
|
| 156 | + if (isset($args['count']) || isset($args['post_id'])) { |
|
| 157 | 157 | |
| 158 | 158 | // ...then we don't need to ask the db to order the results, this overrides WP default behaviour |
| 159 | - if ( version_compare( $wp_version, '4.1', '>=' ) ) { |
|
| 159 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 160 | 160 | $args['order'] = false; |
| 161 | 161 | $args['orderby'] = false; |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // A user ID of 0 is in valid, so shortcut this |
| 166 | - if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) { |
|
| 167 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 166 | + if (isset($args['user_id']) && 0 == intval($args['user_id'])) { |
|
| 167 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | // Check for legacy code |
| 171 | - if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) { |
|
| 172 | - _deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) ); |
|
| 171 | + if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) { |
|
| 172 | + _deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'])); |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | // Are we checking for specific comment_approved statuses? |
| 176 | - if ( isset($args['status']) ) { |
|
| 176 | + if (isset($args['status'])) { |
|
| 177 | 177 | // Temporarily store as a custom status if requesting an array... |
| 178 | - if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 178 | + if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 179 | 179 | // Encode now, decode later |
| 180 | - $args['status'] = implode( ",", $args['status'] ); |
|
| 180 | + $args['status'] = implode(",", $args['status']); |
|
| 181 | 181 | // ...use a filter to switch the encoding back |
| 182 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 182 | + add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | else { |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 ' |
| 190 | - if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 191 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 190 | + if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 191 | + add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | //Get the comments |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @param int|array $comments |
| 201 | 201 | */ |
| 202 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 202 | + $comments = apply_filters('sensei_check_for_activity', get_comments($args)); |
|
| 203 | 203 | |
| 204 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 205 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 204 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 205 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 206 | 206 | // Return comments |
| 207 | - if ( $return_comments ) { |
|
| 207 | + if ($return_comments) { |
|
| 208 | 208 | // Could check for array of 1 and just return the 1 item? |
| 209 | - if ( is_array($comments) && 1 == count($comments) ) { |
|
| 209 | + if (is_array($comments) && 1 == count($comments)) { |
|
| 210 | 210 | $comments = array_shift($comments); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -224,31 +224,31 @@ discard block |
||
| 224 | 224 | * @param array $args (default: array()) |
| 225 | 225 | * @return void |
| 226 | 226 | */ |
| 227 | - public static function sensei_activity_ids ( $args = array() ) { |
|
| 227 | + public static function sensei_activity_ids($args = array()) { |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | - $comments = WooThemes_Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 230 | + $comments = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 231 | 231 | // Need to always use an array, even with only 1 item |
| 232 | - if ( !is_array($comments) ) { |
|
| 233 | - $comments = array( $comments ); |
|
| 232 | + if ( ! is_array($comments)) { |
|
| 233 | + $comments = array($comments); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | $post_ids = array(); |
| 237 | 237 | // Count comments |
| 238 | - if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) { |
|
| 239 | - foreach ( $comments as $key => $value ) { |
|
| 238 | + if (is_array($comments) && (0 < intval(count($comments)))) { |
|
| 239 | + foreach ($comments as $key => $value) { |
|
| 240 | 240 | // Add matches to id array |
| 241 | - if ( isset( $args['field'] ) && 'comment' == $args['field'] ) { |
|
| 242 | - array_push( $post_ids, $value->comment_ID ); |
|
| 243 | - } elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) { |
|
| 244 | - array_push( $post_ids, $value->user_id ); |
|
| 241 | + if (isset($args['field']) && 'comment' == $args['field']) { |
|
| 242 | + array_push($post_ids, $value->comment_ID); |
|
| 243 | + } elseif (isset($args['field']) && 'user_id' == $args['field']) { |
|
| 244 | + array_push($post_ids, $value->user_id); |
|
| 245 | 245 | } else { |
| 246 | - array_push( $post_ids, $value->comment_post_ID ); |
|
| 246 | + array_push($post_ids, $value->comment_post_ID); |
|
| 247 | 247 | } // End If Statement |
| 248 | 248 | } // End For Loop |
| 249 | 249 | // Reset array indexes |
| 250 | - $post_ids = array_unique( $post_ids ); |
|
| 251 | - $post_ids = array_values( $post_ids ); |
|
| 250 | + $post_ids = array_unique($post_ids); |
|
| 251 | + $post_ids = array_values($post_ids); |
|
| 252 | 252 | } // End If Statement |
| 253 | 253 | |
| 254 | 254 | return $post_ids; |
@@ -262,20 +262,20 @@ discard block |
||
| 262 | 262 | * @param array $args (default: array()) |
| 263 | 263 | * @return boolean |
| 264 | 264 | */ |
| 265 | - public static function sensei_delete_activities ( $args = array() ) { |
|
| 265 | + public static function sensei_delete_activities($args = array()) { |
|
| 266 | 266 | |
| 267 | 267 | $dataset_changes = false; |
| 268 | 268 | |
| 269 | 269 | // If activity exists remove activity from log |
| 270 | - $comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true ); |
|
| 271 | - if( $comments ) { |
|
| 270 | + $comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true); |
|
| 271 | + if ($comments) { |
|
| 272 | 272 | // Need to always return an array, even with only 1 item |
| 273 | - if ( !is_array( $comments ) ) { |
|
| 274 | - $comments = array( $comments ); |
|
| 273 | + if ( ! is_array($comments)) { |
|
| 274 | + $comments = array($comments); |
|
| 275 | 275 | } |
| 276 | - foreach ( $comments as $key => $value ) { |
|
| 277 | - if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { |
|
| 278 | - $dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true ); |
|
| 276 | + foreach ($comments as $key => $value) { |
|
| 277 | + if (isset($value->comment_ID) && 0 < $value->comment_ID) { |
|
| 278 | + $dataset_changes = wp_delete_comment(intval($value->comment_ID), true); |
|
| 279 | 279 | } // End If Statement |
| 280 | 280 | } // End For Loop |
| 281 | 281 | // Manually flush the cache |
@@ -291,25 +291,25 @@ discard block |
||
| 291 | 291 | * @param integer $user_id User ID |
| 292 | 292 | * @return boolean |
| 293 | 293 | */ |
| 294 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 294 | + public static function delete_all_user_activity($user_id = 0) { |
|
| 295 | 295 | |
| 296 | 296 | $dataset_changes = false; |
| 297 | 297 | |
| 298 | - if( $user_id ) { |
|
| 298 | + if ($user_id) { |
|
| 299 | 299 | |
| 300 | - $activities = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
|
| 300 | + $activities = WooThemes_Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true); |
|
| 301 | 301 | |
| 302 | - if( $activities ) { |
|
| 302 | + if ($activities) { |
|
| 303 | 303 | |
| 304 | 304 | // Need to always return an array, even with only 1 item |
| 305 | - if ( ! is_array( $activities ) ) { |
|
| 306 | - $activities = array( $activities ); |
|
| 305 | + if ( ! is_array($activities)) { |
|
| 306 | + $activities = array($activities); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - foreach( $activities as $activity ) { |
|
| 310 | - if( '' == $activity->comment_type ) continue; |
|
| 311 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 312 | - $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 309 | + foreach ($activities as $activity) { |
|
| 310 | + if ('' == $activity->comment_type) continue; |
|
| 311 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 312 | + $dataset_changes = wp_delete_comment(intval($activity->comment_ID), true); |
|
| 313 | 313 | wp_cache_flush(); |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -326,14 +326,14 @@ discard block |
||
| 326 | 326 | * @param array $args (default: array()) |
| 327 | 327 | * @return string |
| 328 | 328 | */ |
| 329 | - public static function sensei_get_activity_value ( $args = array() ) { |
|
| 329 | + public static function sensei_get_activity_value($args = array()) { |
|
| 330 | 330 | |
| 331 | 331 | |
| 332 | 332 | $activity_value = false; |
| 333 | - if ( !empty($args['field']) ) { |
|
| 334 | - $comment = WooThemes_Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 333 | + if ( ! empty($args['field'])) { |
|
| 334 | + $comment = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 335 | 335 | |
| 336 | - if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 336 | + if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 337 | 337 | $activity_value = $comment->{$args['field']}; |
| 338 | 338 | } // End If Statement |
| 339 | 339 | } |
@@ -349,49 +349,49 @@ discard block |
||
| 349 | 349 | * @param int $product_id |
| 350 | 350 | * @return bool |
| 351 | 351 | */ |
| 352 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 352 | + public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) { |
|
| 353 | 353 | global $wpdb; |
| 354 | 354 | |
| 355 | 355 | $emails = array(); |
| 356 | 356 | |
| 357 | - if ( $user_id ) { |
|
| 358 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 357 | + if ($user_id) { |
|
| 358 | + $user = get_user_by('id', intval($user_id)); |
|
| 359 | 359 | $emails[] = $user->user_email; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( is_email( $customer_email ) ) |
|
| 362 | + if (is_email($customer_email)) |
|
| 363 | 363 | $emails[] = $customer_email; |
| 364 | 364 | |
| 365 | - if ( sizeof( $emails ) == 0 ) |
|
| 365 | + if (sizeof($emails) == 0) |
|
| 366 | 366 | return false; |
| 367 | 367 | |
| 368 | - $orders = get_posts( array( |
|
| 368 | + $orders = get_posts(array( |
|
| 369 | 369 | 'posts_per_page' => -1, |
| 370 | 370 | 'meta_key' => '_customer_user', |
| 371 | - 'meta_value' => intval( $user_id ), |
|
| 371 | + 'meta_value' => intval($user_id), |
|
| 372 | 372 | 'post_type' => 'shop_order', |
| 373 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 374 | - ) ); |
|
| 373 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 374 | + )); |
|
| 375 | 375 | |
| 376 | - foreach ( $orders as $order_id ) { |
|
| 377 | - $order = new WC_Order( $order_id->ID ); |
|
| 378 | - if ( $order->post_status == 'wc-completed' || $order->post_status == 'wc-processing' ) { |
|
| 379 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 380 | - foreach( $order->get_items() as $item ) { |
|
| 376 | + foreach ($orders as $order_id) { |
|
| 377 | + $order = new WC_Order($order_id->ID); |
|
| 378 | + if ($order->post_status == 'wc-completed' || $order->post_status == 'wc-processing') { |
|
| 379 | + if (0 < sizeof($order->get_items())) { |
|
| 380 | + foreach ($order->get_items() as $item) { |
|
| 381 | 381 | |
| 382 | 382 | // Allow product ID to be filtered |
| 383 | - $product_id = apply_filters( 'sensei_bought_product_id', $product_id, $order ); |
|
| 383 | + $product_id = apply_filters('sensei_bought_product_id', $product_id, $order); |
|
| 384 | 384 | |
| 385 | 385 | // Check if user has bought product |
| 386 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 386 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
| 387 | 387 | |
| 388 | 388 | // Check if user has an active subscription for product |
| 389 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 390 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 391 | - if( $sub_key ) { |
|
| 392 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 393 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 394 | - if( 'active' == $sub['status'] ) { |
|
| 389 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
| 390 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id); |
|
| 391 | + if ($sub_key) { |
|
| 392 | + $sub = WC_Subscriptions_Manager::get_subscription($sub_key); |
|
| 393 | + if ($sub && isset($sub['status'])) { |
|
| 394 | + if ('active' == $sub['status']) { |
|
| 395 | 395 | return true; |
| 396 | 396 | } else { |
| 397 | 397 | return false; |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * @param string $input_name Name for textarea form element |
| 418 | 418 | * @return void |
| 419 | 419 | */ |
| 420 | - public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
|
| 420 | + public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') { |
|
| 421 | 421 | |
| 422 | - if( ! $input_name ) $input_name = $editor_id; |
|
| 422 | + if ( ! $input_name) $input_name = $editor_id; |
|
| 423 | 423 | |
| 424 | 424 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
| 425 | 425 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | 'quicktags' => false |
| 438 | 438 | ); |
| 439 | 439 | |
| 440 | - wp_editor( $content, $editor_id, $settings ); |
|
| 440 | + wp_editor($content, $editor_id, $settings); |
|
| 441 | 441 | |
| 442 | 442 | } // End sensei_text_editor() |
| 443 | 443 | |
@@ -446,56 +446,56 @@ discard block |
||
| 446 | 446 | * @param boolean $submitted User's quiz answers |
| 447 | 447 | * @return boolean Whether the answers were saved or not |
| 448 | 448 | */ |
| 449 | - public static function sensei_save_quiz_answers( $submitted = false, $user_id = 0 ) { |
|
| 450 | - if( intval( $user_id ) == 0 ) { |
|
| 449 | + public static function sensei_save_quiz_answers($submitted = false, $user_id = 0) { |
|
| 450 | + if (intval($user_id) == 0) { |
|
| 451 | 451 | $user_id = get_current_user_id(); |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | $answers_saved = false; |
| 455 | 455 | |
| 456 | - if( $submitted && intval( $user_id ) > 0 ) { |
|
| 456 | + if ($submitted && intval($user_id) > 0) { |
|
| 457 | 457 | |
| 458 | - foreach( $submitted as $question_id => $answer ) { |
|
| 458 | + foreach ($submitted as $question_id => $answer) { |
|
| 459 | 459 | |
| 460 | 460 | // Get question type |
| 461 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 461 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 462 | 462 | |
| 463 | 463 | // Sanitise answer |
| 464 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 465 | - $answer = wp_unslash( $answer ); |
|
| 464 | + if (0 == get_magic_quotes_gpc()) { |
|
| 465 | + $answer = wp_unslash($answer); |
|
| 466 | 466 | } |
| 467 | - switch( $question_type ) { |
|
| 468 | - case 'multi-line': $answer = nl2br( $answer ); break; |
|
| 467 | + switch ($question_type) { |
|
| 468 | + case 'multi-line': $answer = nl2br($answer); break; |
|
| 469 | 469 | case 'single-line': break; |
| 470 | 470 | case 'gap-fill': break; |
| 471 | - default: $answer = maybe_serialize( $answer ); break; |
|
| 471 | + default: $answer = maybe_serialize($answer); break; |
|
| 472 | 472 | } |
| 473 | 473 | $args = array( |
| 474 | 474 | 'post_id' => $question_id, |
| 475 | - 'data' => base64_encode( $answer ), |
|
| 475 | + 'data' => base64_encode($answer), |
|
| 476 | 476 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 477 | 477 | 'user_id' => $user_id, |
| 478 | 478 | 'action' => 'update' |
| 479 | 479 | ); |
| 480 | - $answers_saved = WooThemes_Sensei_Utils::sensei_log_activity( $args ); |
|
| 480 | + $answers_saved = WooThemes_Sensei_Utils::sensei_log_activity($args); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // Handle file upload questions |
| 484 | - if( isset( $_FILES ) ) { |
|
| 485 | - foreach( $_FILES as $field => $file ) { |
|
| 486 | - if( strpos( $field, 'file_upload_' ) !== false ) { |
|
| 487 | - $question_id = str_replace( 'file_upload_', '', $field ); |
|
| 488 | - if( $file && $question_id ) { |
|
| 489 | - $attachment_id = self::upload_file( $file ); |
|
| 490 | - if( $attachment_id ) { |
|
| 484 | + if (isset($_FILES)) { |
|
| 485 | + foreach ($_FILES as $field => $file) { |
|
| 486 | + if (strpos($field, 'file_upload_') !== false) { |
|
| 487 | + $question_id = str_replace('file_upload_', '', $field); |
|
| 488 | + if ($file && $question_id) { |
|
| 489 | + $attachment_id = self::upload_file($file); |
|
| 490 | + if ($attachment_id) { |
|
| 491 | 491 | $args = array( |
| 492 | 492 | 'post_id' => $question_id, |
| 493 | - 'data' => base64_encode( $attachment_id ), |
|
| 493 | + 'data' => base64_encode($attachment_id), |
|
| 494 | 494 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 495 | 495 | 'user_id' => $user_id, |
| 496 | 496 | 'action' => 'update' |
| 497 | 497 | ); |
| 498 | - $answers_saved = WooThemes_Sensei_Utils::sensei_log_activity( $args ); |
|
| 498 | + $answers_saved = WooThemes_Sensei_Utils::sensei_log_activity($args); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -507,9 +507,9 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | } // End sensei_save_quiz_answers() |
| 509 | 509 | |
| 510 | - public static function upload_file( $file = array() ) { |
|
| 510 | + public static function upload_file($file = array()) { |
|
| 511 | 511 | |
| 512 | - require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
|
| 512 | + require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | 515 | * Filter the data array for the Sensei wp_handle_upload function call |
@@ -524,11 +524,11 @@ discard block |
||
| 524 | 524 | * @type string test_form set to false by default |
| 525 | 525 | * } |
| 526 | 526 | */ |
| 527 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 527 | + $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false)); |
|
| 528 | 528 | |
| 529 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 529 | + $file_return = wp_handle_upload($file, $file_upload_args); |
|
| 530 | 530 | |
| 531 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 531 | + if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { |
|
| 532 | 532 | return false; |
| 533 | 533 | } else { |
| 534 | 534 | |
@@ -536,19 +536,19 @@ discard block |
||
| 536 | 536 | |
| 537 | 537 | $attachment = array( |
| 538 | 538 | 'post_mime_type' => $file_return['type'], |
| 539 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 539 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
| 540 | 540 | 'post_content' => '', |
| 541 | 541 | 'post_status' => 'inherit', |
| 542 | 542 | 'guid' => $file_return['url'] |
| 543 | 543 | ); |
| 544 | 544 | |
| 545 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 545 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
| 546 | 546 | |
| 547 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 548 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 549 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 547 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 548 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
| 549 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
| 550 | 550 | |
| 551 | - if( 0 < intval( $attachment_id ) ) { |
|
| 551 | + if (0 < intval($attachment_id)) { |
|
| 552 | 552 | return $attachment_id; |
| 553 | 553 | } |
| 554 | 554 | } |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | * |
| 575 | 575 | * @return int $quiz_grade total sum of all question grades |
| 576 | 576 | */ |
| 577 | - public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 577 | + public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
| 578 | 578 | |
| 579 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 579 | + return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); |
|
| 580 | 580 | |
| 581 | 581 | } // End sensei_grade_quiz_auto() |
| 582 | 582 | |
@@ -587,20 +587,20 @@ discard block |
||
| 587 | 587 | * @param integer $user_id ID of user being graded |
| 588 | 588 | * @return boolean |
| 589 | 589 | */ |
| 590 | - public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
|
| 591 | - if( intval( $user_id ) == 0 ) { |
|
| 590 | + public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') { |
|
| 591 | + if (intval($user_id) == 0) { |
|
| 592 | 592 | $user_id = get_current_user_id(); |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | $activity_logged = false; |
| 596 | - if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 597 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 598 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 599 | - $activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade ); |
|
| 596 | + if (intval($quiz_id) > 0 && intval($user_id) > 0) { |
|
| 597 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 598 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 599 | + $activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade); |
|
| 600 | 600 | |
| 601 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 601 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 602 | 602 | |
| 603 | - do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type ); |
|
| 603 | + do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | return $activity_logged; |
@@ -620,9 +620,9 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | * @return int $question_grade |
| 622 | 622 | */ |
| 623 | - public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 623 | + public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
| 624 | 624 | |
| 625 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 625 | + return WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
| 626 | 626 | |
| 627 | 627 | } // end sensei_grade_question_auto |
| 628 | 628 | |
@@ -632,20 +632,20 @@ discard block |
||
| 632 | 632 | * @param integer $grade Grade received |
| 633 | 633 | * @return boolean |
| 634 | 634 | */ |
| 635 | - public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
|
| 636 | - if( intval( $user_id ) == 0 ) { |
|
| 635 | + public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) { |
|
| 636 | + if (intval($user_id) == 0) { |
|
| 637 | 637 | $user_id = get_current_user_id(); |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | $activity_logged = false; |
| 641 | - if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 641 | + if (intval($question_id) > 0 && intval($user_id) > 0) { |
|
| 642 | 642 | |
| 643 | - $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 644 | - $activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade ); |
|
| 643 | + $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 644 | + $activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade); |
|
| 645 | 645 | |
| 646 | - $answer_notes = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 647 | - if ( !empty($answer_notes) ) { |
|
| 648 | - update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) ); |
|
| 646 | + $answer_notes = get_post_meta($question_id, '_answer_feedback', true); |
|
| 647 | + if ( ! empty($answer_notes)) { |
|
| 648 | + update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes)); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | } |
@@ -653,15 +653,15 @@ discard block |
||
| 653 | 653 | return $activity_logged; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) { |
|
| 657 | - if( intval( $user_id ) == 0 ) { |
|
| 656 | + public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) { |
|
| 657 | + if (intval($user_id) == 0) { |
|
| 658 | 658 | $user_id = get_current_user_id(); |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | $activity_logged = false; |
| 662 | - if( intval( $question_id ) > 0 ) { |
|
| 663 | - $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 664 | - $activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' ); |
|
| 662 | + if (intval($question_id) > 0) { |
|
| 663 | + $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 664 | + $activity_logged = delete_comment_meta($user_answer_id, 'user_grade'); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | return $activity_logged; |
@@ -679,9 +679,9 @@ discard block |
||
| 679 | 679 | * |
| 680 | 680 | * @return mixed boolean or comment_ID |
| 681 | 681 | */ |
| 682 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 682 | + public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) { |
|
| 683 | 683 | |
| 684 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 684 | + return self::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
| 685 | 685 | |
| 686 | 686 | }// end user_start_lesson() |
| 687 | 687 | |
@@ -698,22 +698,22 @@ discard block |
||
| 698 | 698 | * |
| 699 | 699 | * @return mixed boolean or comment_ID |
| 700 | 700 | */ |
| 701 | - public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
|
| 701 | + public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) { |
|
| 702 | 702 | |
| 703 | 703 | |
| 704 | - if( intval( $user_id ) == 0 ) { |
|
| 704 | + if (intval($user_id) == 0) { |
|
| 705 | 705 | $user_id = get_current_user_id(); |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $activity_logged = false; |
| 709 | 709 | |
| 710 | - if( intval( $lesson_id ) > 0 ) { |
|
| 710 | + if (intval($lesson_id) > 0) { |
|
| 711 | 711 | |
| 712 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 713 | - if( $course_id ) { |
|
| 714 | - $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 715 | - if( ! $is_user_taking_course ) { |
|
| 716 | - WooThemes_Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 712 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 713 | + if ($course_id) { |
|
| 714 | + $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 715 | + if ( ! $is_user_taking_course) { |
|
| 716 | + WooThemes_Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | |
@@ -721,12 +721,12 @@ discard block |
||
| 721 | 721 | $status = 'in-progress'; |
| 722 | 722 | |
| 723 | 723 | // Note: When this action runs the lesson status may not yet exist |
| 724 | - do_action( 'sensei_user_lesson_start', $user_id, $lesson_id ); |
|
| 724 | + do_action('sensei_user_lesson_start', $user_id, $lesson_id); |
|
| 725 | 725 | |
| 726 | - if( $complete ) { |
|
| 726 | + if ($complete) { |
|
| 727 | 727 | |
| 728 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 729 | - if ( $has_questions ) { |
|
| 728 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 729 | + if ($has_questions) { |
|
| 730 | 730 | $status = 'passed'; // Force a pass |
| 731 | 731 | $metadata['grade'] = 0; |
| 732 | 732 | } |
@@ -736,31 +736,31 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | // Check if user is already taking the lesson |
| 739 | - $activity_logged = WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id ); |
|
| 740 | - if( ! $activity_logged ) { |
|
| 739 | + $activity_logged = WooThemes_Sensei_Utils::user_started_lesson($lesson_id, $user_id); |
|
| 740 | + if ( ! $activity_logged) { |
|
| 741 | 741 | |
| 742 | 742 | $metadata['start'] = current_time('mysql'); |
| 743 | - $activity_logged = WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
|
| 743 | + $activity_logged = WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata); |
|
| 744 | 744 | |
| 745 | 745 | } else { |
| 746 | 746 | |
| 747 | 747 | // if users is already taking the lesson and the status changes to complete update it |
| 748 | 748 | $current_user_activity = get_comment($activity_logged); |
| 749 | - if( $status=='complete' && |
|
| 750 | - $status != $current_user_activity->comment_approved ){ |
|
| 749 | + if ($status == 'complete' && |
|
| 750 | + $status != $current_user_activity->comment_approved) { |
|
| 751 | 751 | |
| 752 | 752 | $comment = array(); |
| 753 | 753 | $comment['comment_ID'] = $activity_logged; |
| 754 | 754 | $comment['comment_approved'] = $status; |
| 755 | - wp_update_comment( $comment ); |
|
| 755 | + wp_update_comment($comment); |
|
| 756 | 756 | |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | - if ( $complete ) { |
|
| 761 | + if ($complete) { |
|
| 762 | 762 | // Run this *after* the lesson status has been created/updated |
| 763 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 763 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | } |
@@ -775,20 +775,20 @@ discard block |
||
| 775 | 775 | * @param type $user_id |
| 776 | 776 | * @return boolean |
| 777 | 777 | */ |
| 778 | - public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
|
| 778 | + public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) { |
|
| 779 | 779 | |
| 780 | 780 | |
| 781 | - if( ! $lesson_id ) return false; |
|
| 781 | + if ( ! $lesson_id) return false; |
|
| 782 | 782 | |
| 783 | - if( intval( $user_id ) == 0 ) { |
|
| 783 | + if (intval($user_id) == 0) { |
|
| 784 | 784 | $user_id = get_current_user_id(); |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // Process quiz |
| 788 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 788 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 789 | 789 | |
| 790 | 790 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
| 791 | - WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id ); |
|
| 791 | + WooThemes_Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id); |
|
| 792 | 792 | |
| 793 | 793 | // Delete lesson status |
| 794 | 794 | $args = array( |
@@ -797,10 +797,10 @@ discard block |
||
| 797 | 797 | 'user_id' => $user_id, |
| 798 | 798 | ); |
| 799 | 799 | // This auto deletes the corresponding meta data, such as the quiz grade, and questions asked |
| 800 | - WooThemes_Sensei_Utils::sensei_delete_activities( $args ); |
|
| 800 | + WooThemes_Sensei_Utils::sensei_delete_activities($args); |
|
| 801 | 801 | |
| 802 | - if( ! $from_course ) { |
|
| 803 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 802 | + if ( ! $from_course) { |
|
| 803 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | return true; |
@@ -813,19 +813,19 @@ discard block |
||
| 813 | 813 | * @param type $user_id |
| 814 | 814 | * @return boolean |
| 815 | 815 | */ |
| 816 | - public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
|
| 816 | + public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) { |
|
| 817 | 817 | |
| 818 | 818 | |
| 819 | - if( ! $course_id ) return false; |
|
| 819 | + if ( ! $course_id) return false; |
|
| 820 | 820 | |
| 821 | - if( intval( $user_id ) == 0 ) { |
|
| 821 | + if (intval($user_id) == 0) { |
|
| 822 | 822 | $user_id = get_current_user_id(); |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 825 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 826 | 826 | |
| 827 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 828 | - WooThemes_Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true ); |
|
| 827 | + foreach ($lesson_ids as $lesson_id) { |
|
| 828 | + WooThemes_Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | // Delete course status |
@@ -835,36 +835,36 @@ discard block |
||
| 835 | 835 | 'user_id' => $user_id, |
| 836 | 836 | ); |
| 837 | 837 | |
| 838 | - WooThemes_Sensei_Utils::sensei_delete_activities( $args ); |
|
| 838 | + WooThemes_Sensei_Utils::sensei_delete_activities($args); |
|
| 839 | 839 | |
| 840 | - do_action( 'sensei_user_course_reset', $user_id, $course_id ); |
|
| 840 | + do_action('sensei_user_course_reset', $user_id, $course_id); |
|
| 841 | 841 | |
| 842 | 842 | return true; |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - public static function sensei_get_quiz_questions( $quiz_id = 0 ) { |
|
| 845 | + public static function sensei_get_quiz_questions($quiz_id = 0) { |
|
| 846 | 846 | |
| 847 | 847 | |
| 848 | 848 | $questions = array(); |
| 849 | 849 | |
| 850 | - if( intval( $quiz_id ) > 0 ) { |
|
| 851 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 852 | - $questions = WooThemes_Sensei_Utils::array_sort_reorder( $questions ); |
|
| 850 | + if (intval($quiz_id) > 0) { |
|
| 851 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 852 | + $questions = WooThemes_Sensei_Utils::array_sort_reorder($questions); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | return $questions; |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | - public static function sensei_get_quiz_total( $quiz_id = 0 ) { |
|
| 858 | + public static function sensei_get_quiz_total($quiz_id = 0) { |
|
| 859 | 859 | |
| 860 | 860 | |
| 861 | 861 | $quiz_total = 0; |
| 862 | 862 | |
| 863 | - if( $quiz_id > 0 ) { |
|
| 864 | - $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 863 | + if ($quiz_id > 0) { |
|
| 864 | + $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 865 | 865 | $question_grade = 0; |
| 866 | - foreach( $questions as $question ) { |
|
| 867 | - $question_grade = Sensei()->question->get_question_grade( $question->ID ); |
|
| 866 | + foreach ($questions as $question) { |
|
| 867 | + $question_grade = Sensei()->question->get_question_grade($question->ID); |
|
| 868 | 868 | $quiz_total += $question_grade; |
| 869 | 869 | } |
| 870 | 870 | } |
@@ -879,20 +879,20 @@ discard block |
||
| 879 | 879 | * @param int $user_id |
| 880 | 880 | * @return string |
| 881 | 881 | */ |
| 882 | - public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) { |
|
| 882 | + public static function sensei_get_user_question_grade($question = 0, $user_id = 0) { |
|
| 883 | 883 | $question_grade = false; |
| 884 | - if( $question ) { |
|
| 885 | - if ( is_object( $question ) ) { |
|
| 884 | + if ($question) { |
|
| 885 | + if (is_object($question)) { |
|
| 886 | 886 | $user_answer_id = $question->comment_ID; |
| 887 | 887 | } |
| 888 | 888 | else { |
| 889 | - if( intval( $user_id ) == 0 ) { |
|
| 889 | + if (intval($user_id) == 0) { |
|
| 890 | 890 | $user_id = get_current_user_id(); |
| 891 | 891 | } |
| 892 | - $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 892 | + $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 893 | 893 | } |
| 894 | - if ( $user_answer_id ) { |
|
| 895 | - $question_grade = get_comment_meta( $user_answer_id, 'user_grade', true ); |
|
| 894 | + if ($user_answer_id) { |
|
| 895 | + $question_grade = get_comment_meta($user_answer_id, 'user_grade', true); |
|
| 896 | 896 | } |
| 897 | 897 | } |
| 898 | 898 | |
@@ -907,52 +907,52 @@ discard block |
||
| 907 | 907 | * @param int $user_id |
| 908 | 908 | * @return string |
| 909 | 909 | */ |
| 910 | - public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) { |
|
| 910 | + public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) { |
|
| 911 | 911 | $answer_notes = false; |
| 912 | - if( $question ) { |
|
| 913 | - if ( is_object( $question ) ) { |
|
| 912 | + if ($question) { |
|
| 913 | + if (is_object($question)) { |
|
| 914 | 914 | $user_answer_id = $question->comment_ID; |
| 915 | 915 | } |
| 916 | 916 | else { |
| 917 | - if( intval( $user_id ) == 0 ) { |
|
| 917 | + if (intval($user_id) == 0) { |
|
| 918 | 918 | $user_id = get_current_user_id(); |
| 919 | 919 | } |
| 920 | - $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 920 | + $user_answer_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 921 | 921 | } |
| 922 | - if ( $user_answer_id ) { |
|
| 923 | - $answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) ); |
|
| 922 | + if ($user_answer_id) { |
|
| 923 | + $answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true)); |
|
| 924 | 924 | } |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | return $answer_notes; |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) { |
|
| 931 | - if( intval( $user_id ) == 0 ) { |
|
| 930 | + public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) { |
|
| 931 | + if (intval($user_id) == 0) { |
|
| 932 | 932 | $user_id = get_current_user_id(); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | $delete_answers = false; |
| 936 | - if( intval( $quiz_id ) > 0 ) { |
|
| 937 | - $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 938 | - foreach( $questions as $question ) { |
|
| 939 | - $delete_answers = WooThemes_Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) ); |
|
| 936 | + if (intval($quiz_id) > 0) { |
|
| 937 | + $questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 938 | + foreach ($questions as $question) { |
|
| 939 | + $delete_answers = WooThemes_Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer')); |
|
| 940 | 940 | } |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | return $delete_answers; |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) { |
|
| 947 | - if( intval( $user_id ) == 0 ) { |
|
| 946 | + public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) { |
|
| 947 | + if (intval($user_id) == 0) { |
|
| 948 | 948 | $user_id = get_current_user_id(); |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | $delete_grade = false; |
| 952 | - if( intval( $quiz_id ) > 0 ) { |
|
| 953 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 954 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 955 | - $delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' ); |
|
| 952 | + if (intval($quiz_id) > 0) { |
|
| 953 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 954 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 955 | + $delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade'); |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | return $delete_grade; |
@@ -964,20 +964,20 @@ discard block |
||
| 964 | 964 | * @param integer $user_id ID of user |
| 965 | 965 | * @return boolean |
| 966 | 966 | */ |
| 967 | - public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
|
| 968 | - if( intval( $user_id ) == 0 ) { |
|
| 967 | + public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') { |
|
| 968 | + if (intval($user_id) == 0) { |
|
| 969 | 969 | $user_id = get_current_user_id(); |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | $activity_logged = false; |
| 973 | 973 | |
| 974 | - if( intval( $question_id ) > 0 ) { |
|
| 975 | - $notes = base64_encode( $notes ); |
|
| 974 | + if (intval($question_id) > 0) { |
|
| 975 | + $notes = base64_encode($notes); |
|
| 976 | 976 | |
| 977 | 977 | // Don't store empty values, no point |
| 978 | - if ( !empty($notes) ) { |
|
| 979 | - $user_lesson_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 980 | - $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
|
| 978 | + if ( ! empty($notes)) { |
|
| 979 | + $user_lesson_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 980 | + $activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes); |
|
| 981 | 981 | } |
| 982 | 982 | else { |
| 983 | 983 | $activity_logged = true; |
@@ -993,16 +993,16 @@ discard block |
||
| 993 | 993 | * @param array $return_array data to be ordered |
| 994 | 994 | * @return array $return_array ordered data |
| 995 | 995 | */ |
| 996 | - public static function array_sort_reorder( $return_array ) { |
|
| 997 | - if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) { |
|
| 996 | + public static function array_sort_reorder($return_array) { |
|
| 997 | + if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) { |
|
| 998 | 998 | $sort_key = ''; |
| 999 | 999 | // if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) { |
| 1000 | 1000 | // $sort_key = esc_html( $_GET['orderby'] ); |
| 1001 | 1001 | // } // End If Statement |
| 1002 | - if ( '' != $sort_key ) { |
|
| 1003 | - WooThemes_Sensei_Utils::sort_array_by_key($return_array,$sort_key); |
|
| 1004 | - if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) { |
|
| 1005 | - $return_array = array_reverse( $return_array, true ); |
|
| 1002 | + if ('' != $sort_key) { |
|
| 1003 | + WooThemes_Sensei_Utils::sort_array_by_key($return_array, $sort_key); |
|
| 1004 | + if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) { |
|
| 1005 | + $return_array = array_reverse($return_array, true); |
|
| 1006 | 1006 | } // End If Statement |
| 1007 | 1007 | } // End If Statement |
| 1008 | 1008 | return $return_array; |
@@ -1018,15 +1018,15 @@ discard block |
||
| 1018 | 1018 | * @param $key string column name in array |
| 1019 | 1019 | * @return void |
| 1020 | 1020 | */ |
| 1021 | - public static function sort_array_by_key( $array, $key ) { |
|
| 1021 | + public static function sort_array_by_key($array, $key) { |
|
| 1022 | 1022 | $sorter = array(); |
| 1023 | 1023 | $ret = array(); |
| 1024 | - reset( $array ); |
|
| 1025 | - foreach ( $array as $ii => $va ) { |
|
| 1024 | + reset($array); |
|
| 1025 | + foreach ($array as $ii => $va) { |
|
| 1026 | 1026 | $sorter[$ii] = $va[$key]; |
| 1027 | 1027 | } // End For Loop |
| 1028 | - asort( $sorter ); |
|
| 1029 | - foreach ( $sorter as $ii => $va ) { |
|
| 1028 | + asort($sorter); |
|
| 1029 | + foreach ($sorter as $ii => $va) { |
|
| 1030 | 1030 | $ret[$ii] = $array[$ii]; |
| 1031 | 1031 | } // End For Loop |
| 1032 | 1032 | $array = $ret; |
@@ -1038,10 +1038,10 @@ discard block |
||
| 1038 | 1038 | * @param integer $quiz_id |
| 1039 | 1039 | * @return array of quiz questions |
| 1040 | 1040 | */ |
| 1041 | - public static function lesson_quiz_questions( $quiz_id = 0 ) { |
|
| 1041 | + public static function lesson_quiz_questions($quiz_id = 0) { |
|
| 1042 | 1042 | $questions_array = array(); |
| 1043 | - if ( 0 < $quiz_id ) { |
|
| 1044 | - $question_args = array( 'post_type' => 'question', |
|
| 1043 | + if (0 < $quiz_id) { |
|
| 1044 | + $question_args = array('post_type' => 'question', |
|
| 1045 | 1045 | 'posts_per_page' => -1, |
| 1046 | 1046 | 'orderby' => 'ID', |
| 1047 | 1047 | 'order' => 'ASC', |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | 'post_status' => 'any', |
| 1055 | 1055 | 'suppress_filters' => 0 |
| 1056 | 1056 | ); |
| 1057 | - $questions_array = get_posts( $question_args ); |
|
| 1057 | + $questions_array = get_posts($question_args); |
|
| 1058 | 1058 | } // End If Statement |
| 1059 | 1059 | return $questions_array; |
| 1060 | 1060 | } // End lesson_quiz_questions() |
@@ -1064,25 +1064,25 @@ discard block |
||
| 1064 | 1064 | * @param integer $course_id ID of course |
| 1065 | 1065 | * @return integer Pass mark for course |
| 1066 | 1066 | */ |
| 1067 | - public static function sensei_course_pass_grade( $course_id = 0 ) { |
|
| 1067 | + public static function sensei_course_pass_grade($course_id = 0) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | |
| 1070 | 1070 | $course_passmark = 0; |
| 1071 | 1071 | |
| 1072 | - if( $course_id > 0 ) { |
|
| 1073 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1072 | + if ($course_id > 0) { |
|
| 1073 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1074 | 1074 | $lesson_count = 0; |
| 1075 | 1075 | $total_passmark = 0; |
| 1076 | - foreach( $lessons as $lesson ) { |
|
| 1076 | + foreach ($lessons as $lesson) { |
|
| 1077 | 1077 | |
| 1078 | 1078 | // Get Quiz ID |
| 1079 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 1079 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 1080 | 1080 | |
| 1081 | 1081 | // Check for a pass being required |
| 1082 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1083 | - if ( $pass_required ) { |
|
| 1082 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1083 | + if ($pass_required) { |
|
| 1084 | 1084 | // Get quiz passmark |
| 1085 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1085 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1086 | 1086 | |
| 1087 | 1087 | // Add up total passmark |
| 1088 | 1088 | $total_passmark += $quiz_passmark; |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | // Might be a case of no required lessons |
| 1094 | - if ( $lesson_count ) { |
|
| 1095 | - $course_passmark = ( $total_passmark / $lesson_count ); |
|
| 1094 | + if ($lesson_count) { |
|
| 1095 | + $course_passmark = ($total_passmark / $lesson_count); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | - return Woothemes_Sensei_Utils::round( $course_passmark ); |
|
| 1099 | + return Woothemes_Sensei_Utils::round($course_passmark); |
|
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | /** |
@@ -1105,27 +1105,27 @@ discard block |
||
| 1105 | 1105 | * @param integer $user_id ID of user |
| 1106 | 1106 | * @return integer User's total grade |
| 1107 | 1107 | */ |
| 1108 | - public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
|
| 1108 | + public static function sensei_course_user_grade($course_id = 0, $user_id = 0) { |
|
| 1109 | 1109 | |
| 1110 | 1110 | |
| 1111 | - if( intval( $user_id ) == 0 ) { |
|
| 1111 | + if (intval($user_id) == 0) { |
|
| 1112 | 1112 | $user_id = get_current_user_id(); |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | $total_grade = 0; |
| 1116 | 1116 | |
| 1117 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1118 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1117 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1118 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1119 | 1119 | $lesson_count = 0; |
| 1120 | 1120 | $total_grade = 0; |
| 1121 | - foreach( $lessons as $lesson ) { |
|
| 1121 | + foreach ($lessons as $lesson) { |
|
| 1122 | 1122 | |
| 1123 | 1123 | // Check for lesson having questions, thus a quiz, thus having a grade |
| 1124 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 1125 | - if ( $has_questions ) { |
|
| 1126 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson->ID, $user_id ); |
|
| 1124 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
| 1125 | + if ($has_questions) { |
|
| 1126 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson->ID, $user_id); |
|
| 1127 | 1127 | // Get user quiz grade |
| 1128 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1128 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1129 | 1129 | |
| 1130 | 1130 | // Add up total grade |
| 1131 | 1131 | $total_grade += $quiz_grade; |
@@ -1135,13 +1135,13 @@ discard block |
||
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | // Might be a case of no lessons with quizzes |
| 1138 | - if ( $lesson_count ) { |
|
| 1139 | - $total_grade = ( $total_grade / $lesson_count ); |
|
| 1138 | + if ($lesson_count) { |
|
| 1139 | + $total_grade = ($total_grade / $lesson_count); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | - return WooThemes_Sensei_Utils::round( $total_grade ); |
|
| 1144 | + return WooThemes_Sensei_Utils::round($total_grade); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1150,18 +1150,18 @@ discard block |
||
| 1150 | 1150 | * @param integer $user_id ID of user |
| 1151 | 1151 | * @return boolean |
| 1152 | 1152 | */ |
| 1153 | - public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) { |
|
| 1154 | - if( intval( $user_id ) == 0 ) { |
|
| 1153 | + public static function sensei_user_passed_course($course_id = 0, $user_id = 0) { |
|
| 1154 | + if (intval($user_id) == 0) { |
|
| 1155 | 1155 | $user_id = get_current_user_id(); |
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | $pass = false; |
| 1159 | 1159 | |
| 1160 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1161 | - $passmark = WooThemes_Sensei_Utils::sensei_course_pass_grade( $course_id ); |
|
| 1162 | - $user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); |
|
| 1160 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1161 | + $passmark = WooThemes_Sensei_Utils::sensei_course_pass_grade($course_id); |
|
| 1162 | + $user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course_id, $user_id); |
|
| 1163 | 1163 | |
| 1164 | - if( $user_grade >= $passmark ) { |
|
| 1164 | + if ($user_grade >= $passmark) { |
|
| 1165 | 1165 | $pass = true; |
| 1166 | 1166 | } |
| 1167 | 1167 | } |
@@ -1176,38 +1176,38 @@ discard block |
||
| 1176 | 1176 | * @param integer $user_id ID of user |
| 1177 | 1177 | * @return array Status code and message |
| 1178 | 1178 | */ |
| 1179 | - public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) { |
|
| 1180 | - if( intval( $user_id ) == 0 ) { |
|
| 1179 | + public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) { |
|
| 1180 | + if (intval($user_id) == 0) { |
|
| 1181 | 1181 | $user_id = get_current_user_id(); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | $status = 'not_started'; |
| 1185 | 1185 | $box_class = 'info'; |
| 1186 | - $message = __( 'You have not started this course yet.', 'woothemes-sensei' ); |
|
| 1186 | + $message = __('You have not started this course yet.', 'woothemes-sensei'); |
|
| 1187 | 1187 | |
| 1188 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1188 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1189 | 1189 | |
| 1190 | - $started_course = WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1190 | + $started_course = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1191 | 1191 | |
| 1192 | - if( $started_course ) { |
|
| 1193 | - $passmark = WooThemes_Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()! |
|
| 1194 | - $user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()! |
|
| 1195 | - if( $user_grade >= $passmark ) { |
|
| 1192 | + if ($started_course) { |
|
| 1193 | + $passmark = WooThemes_Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()! |
|
| 1194 | + $user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()! |
|
| 1195 | + if ($user_grade >= $passmark) { |
|
| 1196 | 1196 | $status = 'passed'; |
| 1197 | 1197 | $box_class = 'tick'; |
| 1198 | - $message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade ); |
|
| 1198 | + $message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade); |
|
| 1199 | 1199 | } else { |
| 1200 | 1200 | $status = 'failed'; |
| 1201 | 1201 | $box_class = 'alert'; |
| 1202 | - $message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade ); |
|
| 1202 | + $message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - $message = apply_filters( 'sensei_user_course_status_' . $status, $message ); |
|
| 1208 | + $message = apply_filters('sensei_user_course_status_'.$status, $message); |
|
| 1209 | 1209 | |
| 1210 | - return array( 'status' => $status, 'box_class' => $box_class, 'message' => $message ); |
|
| 1210 | + return array('status' => $status, 'box_class' => $box_class, 'message' => $message); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | /** |
@@ -1216,94 +1216,94 @@ discard block |
||
| 1216 | 1216 | * @param integer $user_id ID of user |
| 1217 | 1217 | * @return array Status code and message |
| 1218 | 1218 | */ |
| 1219 | - public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
|
| 1219 | + public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) { |
|
| 1220 | 1220 | global $current_user; |
| 1221 | - if( intval( $user_id ) == 0 ) { |
|
| 1221 | + if (intval($user_id) == 0) { |
|
| 1222 | 1222 | $user_id = $current_user->ID; |
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | 1225 | $status = 'not_started'; |
| 1226 | 1226 | $box_class = 'info'; |
| 1227 | - $message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' ); |
|
| 1227 | + $message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei'); |
|
| 1228 | 1228 | $extra = ''; |
| 1229 | 1229 | |
| 1230 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1230 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1231 | 1231 | |
| 1232 | 1232 | // Prerequisite lesson |
| 1233 | - $prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1233 | + $prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 1234 | 1234 | |
| 1235 | 1235 | // Course ID |
| 1236 | - $course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
| 1236 | + $course_id = absint(get_post_meta($lesson_id, '_lesson_course', true)); |
|
| 1237 | 1237 | |
| 1238 | 1238 | // Has user started course |
| 1239 | - $started_course = WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1239 | + $started_course = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1240 | 1240 | |
| 1241 | 1241 | // Has user completed lesson |
| 1242 | - $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1243 | - $lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 1242 | + $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1243 | + $lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
| 1244 | 1244 | |
| 1245 | 1245 | // Quiz ID |
| 1246 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1246 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1247 | 1247 | |
| 1248 | 1248 | // Quiz grade |
| 1249 | 1249 | $quiz_grade = 0; |
| 1250 | - if ( $user_lesson_status ) { |
|
| 1251 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1250 | + if ($user_lesson_status) { |
|
| 1251 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | // Quiz passmark |
| 1255 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1255 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1256 | 1256 | $quiz_passmark_float = (float) $quiz_passmark; |
| 1257 | 1257 | |
| 1258 | 1258 | // Pass required |
| 1259 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1259 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1260 | 1260 | |
| 1261 | 1261 | // Quiz questions |
| 1262 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1262 | + $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1263 | 1263 | |
| 1264 | - if ( ! $started_course ) { |
|
| 1264 | + if ( ! $started_course) { |
|
| 1265 | 1265 | |
| 1266 | 1266 | $status = 'not_started_course'; |
| 1267 | 1267 | $box_class = 'info'; |
| 1268 | - $message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' ); |
|
| 1268 | + $message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>'); |
|
| 1269 | 1269 | |
| 1270 | - } elseif ( ! is_user_logged_in() ) { |
|
| 1270 | + } elseif ( ! is_user_logged_in()) { |
|
| 1271 | 1271 | |
| 1272 | 1272 | $status = 'login_required'; |
| 1273 | 1273 | $box_class = 'info'; |
| 1274 | - $message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' ); |
|
| 1274 | + $message = __('You must be logged in to take this quiz', 'woothemes-sensei'); |
|
| 1275 | 1275 | |
| 1276 | 1276 | } |
| 1277 | 1277 | // Lesson/Quiz is marked as complete thus passing any quiz restrictions |
| 1278 | - elseif ( $lesson_complete ) { |
|
| 1278 | + elseif ($lesson_complete) { |
|
| 1279 | 1279 | |
| 1280 | 1280 | $status = 'passed'; |
| 1281 | 1281 | $box_class = 'tick'; |
| 1282 | 1282 | // Lesson status will be "complete" (has no Quiz) |
| 1283 | - if ( ! $has_quiz_questions ) { |
|
| 1284 | - $message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) ); |
|
| 1283 | + if ( ! $has_quiz_questions) { |
|
| 1284 | + $message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei')); |
|
| 1285 | 1285 | } |
| 1286 | 1286 | // Lesson status will be "graded" (no passmark required so might have failed all the questions) |
| 1287 | - elseif ( empty( $quiz_grade ) ) { |
|
| 1288 | - $message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) ); |
|
| 1287 | + elseif (empty($quiz_grade)) { |
|
| 1288 | + $message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei')); |
|
| 1289 | 1289 | } |
| 1290 | 1290 | // Lesson status will be "passed" (passmark reached) |
| 1291 | - elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) { |
|
| 1292 | - if( $is_lesson ) { |
|
| 1293 | - $message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_grade ) ); |
|
| 1291 | + elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) { |
|
| 1292 | + if ($is_lesson) { |
|
| 1293 | + $message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_grade)); |
|
| 1294 | 1294 | } else { |
| 1295 | - $message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_grade ) ); |
|
| 1295 | + $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_grade)); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | // add next lesson button |
| 1300 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1301 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1300 | + $nav_id_array = sensei_get_prev_next_lessons($lesson_id); |
|
| 1301 | + $next_lesson_id = absint($nav_id_array['next_lesson']); |
|
| 1302 | 1302 | |
| 1303 | 1303 | // Output HTML |
| 1304 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1305 | - $message .= '<a class="button next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1306 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1304 | + if ((0 < $next_lesson_id)) { |
|
| 1305 | + $message .= '<a class="button next-lesson" href="'.esc_url(get_permalink($next_lesson_id)) |
|
| 1306 | + . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei') |
|
| 1307 | 1307 | .'</a>'; |
| 1308 | 1308 | |
| 1309 | 1309 | } |
@@ -1312,33 +1312,33 @@ discard block |
||
| 1312 | 1312 | // Lesson/Quiz not complete |
| 1313 | 1313 | else { |
| 1314 | 1314 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1315 | - if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
|
| 1315 | + if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) { |
|
| 1316 | 1316 | $status = 'complete'; |
| 1317 | 1317 | $box_class = 'info'; |
| 1318 | - if( $is_lesson ) { |
|
| 1319 | - $message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' ); |
|
| 1318 | + if ($is_lesson) { |
|
| 1319 | + $message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>'); |
|
| 1320 | 1320 | } else { |
| 1321 | - $message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1321 | + $message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark)); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | } |
| 1324 | 1324 | // Lesson status must be "failed" |
| 1325 | - elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) { |
|
| 1325 | + elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) { |
|
| 1326 | 1326 | $status = 'failed'; |
| 1327 | 1327 | $box_class = 'alert'; |
| 1328 | - if( $is_lesson ) { |
|
| 1329 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_passmark ), WooThemes_Sensei_Utils::round( $quiz_grade ) ); |
|
| 1328 | + if ($is_lesson) { |
|
| 1329 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark), WooThemes_Sensei_Utils::round($quiz_grade)); |
|
| 1330 | 1330 | } else { |
| 1331 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_passmark ), WooThemes_Sensei_Utils::round( $quiz_grade ) ); |
|
| 1331 | + $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark), WooThemes_Sensei_Utils::round($quiz_grade)); |
|
| 1332 | 1332 | } |
| 1333 | 1333 | } |
| 1334 | 1334 | // Lesson/Quiz requires a pass |
| 1335 | - elseif( $pass_required ) { |
|
| 1335 | + elseif ($pass_required) { |
|
| 1336 | 1336 | $status = 'not_started'; |
| 1337 | 1337 | $box_class = 'info'; |
| 1338 | - if( $is_lesson ) { |
|
| 1339 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1338 | + if ($is_lesson) { |
|
| 1339 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark)); |
|
| 1340 | 1340 | } else { |
| 1341 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), WooThemes_Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1341 | + $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark)); |
|
| 1342 | 1342 | } |
| 1343 | 1343 | } |
| 1344 | 1344 | } |
@@ -1346,14 +1346,14 @@ discard block |
||
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | 1348 | // Legacy filter |
| 1349 | - $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
|
| 1349 | + $message = apply_filters('sensei_user_quiz_status_'.$status, $message); |
|
| 1350 | 1350 | |
| 1351 | - if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
|
| 1352 | - $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
|
| 1351 | + if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) { |
|
| 1352 | + $extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>'; |
|
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | // Filter of all messages |
| 1356 | - return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson ); |
|
| 1356 | + return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | /** |
@@ -1363,14 +1363,14 @@ discard block |
||
| 1363 | 1363 | * @param integer $course_id Course ID |
| 1364 | 1364 | * @return mixed boolean or comment_ID |
| 1365 | 1365 | */ |
| 1366 | - public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
|
| 1366 | + public static function user_start_course($user_id = 0, $course_id = 0) { |
|
| 1367 | 1367 | |
| 1368 | 1368 | $activity_logged = false; |
| 1369 | 1369 | |
| 1370 | - if( $user_id && $course_id ) { |
|
| 1370 | + if ($user_id && $course_id) { |
|
| 1371 | 1371 | // Check if user is already on the Course |
| 1372 | - $activity_logged = WooThemes_Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1373 | - if ( ! $activity_logged ) { |
|
| 1372 | + $activity_logged = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1373 | + if ( ! $activity_logged) { |
|
| 1374 | 1374 | |
| 1375 | 1375 | // Add user to course |
| 1376 | 1376 | $course_metadata = array( |
@@ -1379,11 +1379,11 @@ discard block |
||
| 1379 | 1379 | 'complete' => 0, |
| 1380 | 1380 | ); |
| 1381 | 1381 | |
| 1382 | - $activity_logged = WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata ); |
|
| 1382 | + $activity_logged = WooThemes_Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata); |
|
| 1383 | 1383 | |
| 1384 | 1384 | // Allow further actions |
| 1385 | - if ( $activity_logged ) { |
|
| 1386 | - do_action( 'sensei_user_course_start', $user_id, $course_id ); |
|
| 1385 | + if ($activity_logged) { |
|
| 1386 | + do_action('sensei_user_course_start', $user_id, $course_id); |
|
| 1387 | 1387 | } |
| 1388 | 1388 | } |
| 1389 | 1389 | } |
@@ -1399,19 +1399,19 @@ discard block |
||
| 1399 | 1399 | * @param type $user_id |
| 1400 | 1400 | * @return mixed false or comment_ID |
| 1401 | 1401 | */ |
| 1402 | - public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
|
| 1402 | + public static function user_started_course($course_id = 0, $user_id = 0) { |
|
| 1403 | 1403 | |
| 1404 | - if( $course_id ) { |
|
| 1405 | - if( ! $user_id ) { |
|
| 1404 | + if ($course_id) { |
|
| 1405 | + if ( ! $user_id) { |
|
| 1406 | 1406 | $user_id = get_current_user_id(); |
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | - if( ! $user_id > 0 ){ |
|
| 1409 | + if ( ! $user_id > 0) { |
|
| 1410 | 1410 | return false; |
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | - $user_course_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
|
| 1414 | - if( $user_course_status_id ) { |
|
| 1413 | + $user_course_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID')); |
|
| 1414 | + if ($user_course_status_id) { |
|
| 1415 | 1415 | return $user_course_status_id; |
| 1416 | 1416 | } |
| 1417 | 1417 | } |
@@ -1426,17 +1426,17 @@ discard block |
||
| 1426 | 1426 | * @param integer $user_id User ID |
| 1427 | 1427 | * @return int |
| 1428 | 1428 | */ |
| 1429 | - public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
|
| 1429 | + public static function user_complete_course($course_id = 0, $user_id = 0) { |
|
| 1430 | 1430 | global $wp_version; |
| 1431 | 1431 | |
| 1432 | - if( $course_id ) { |
|
| 1433 | - if( ! $user_id ) { |
|
| 1432 | + if ($course_id) { |
|
| 1433 | + if ( ! $user_id) { |
|
| 1434 | 1434 | $user_id = get_current_user_id(); |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | $course_status = 'in-progress'; |
| 1438 | 1438 | $course_metadata = array(); |
| 1439 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1439 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1440 | 1440 | $lessons_completed = $total_lessons = 0; |
| 1441 | 1441 | $lesson_status_args = array( |
| 1442 | 1442 | 'user_id' => $user_id, |
@@ -1445,8 +1445,8 @@ discard block |
||
| 1445 | 1445 | ); |
| 1446 | 1446 | |
| 1447 | 1447 | // Grab all of this Courses' lessons, looping through each... |
| 1448 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 1449 | - $total_lessons = count( $lesson_ids ); |
|
| 1448 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 1449 | + $total_lessons = count($lesson_ids); |
|
| 1450 | 1450 | // ...if course completion not set to 'passed', and all lessons are complete or graded, |
| 1451 | 1451 | // ......then all lessons are 'passed' |
| 1452 | 1452 | // ...else if course completion is set to 'passed', check if each lesson has questions... |
@@ -1459,29 +1459,29 @@ discard block |
||
| 1459 | 1459 | // The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson() |
| 1460 | 1460 | $all_lesson_statuses = array(); |
| 1461 | 1461 | // In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs |
| 1462 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1462 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1463 | 1463 | $lesson_status_args['post__in'] = $lesson_ids; |
| 1464 | - $all_lesson_statuses = WooThemes_Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1464 | + $all_lesson_statuses = WooThemes_Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1465 | 1465 | // Need to always return an array, even with only 1 item |
| 1466 | - if ( !is_array($all_lesson_statuses) ) { |
|
| 1467 | - $all_lesson_statuses = array( $all_lesson_statuses ); |
|
| 1466 | + if ( ! is_array($all_lesson_statuses)) { |
|
| 1467 | + $all_lesson_statuses = array($all_lesson_statuses); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | } |
| 1470 | 1470 | // ...otherwise check each one |
| 1471 | 1471 | else { |
| 1472 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 1472 | + foreach ($lesson_ids as $lesson_id) { |
|
| 1473 | 1473 | $lesson_status_args['post_id'] = $lesson_id; |
| 1474 | - $each_lesson_status = WooThemes_Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1474 | + $each_lesson_status = WooThemes_Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1475 | 1475 | // Check for valid return before using |
| 1476 | - if ( !empty($each_lesson_status->comment_approved) ) { |
|
| 1476 | + if ( ! empty($each_lesson_status->comment_approved)) { |
|
| 1477 | 1477 | $all_lesson_statuses[] = $each_lesson_status; |
| 1478 | 1478 | } |
| 1479 | 1479 | } |
| 1480 | 1480 | } |
| 1481 | - foreach( $all_lesson_statuses as $lesson_status ) { |
|
| 1481 | + foreach ($all_lesson_statuses as $lesson_status) { |
|
| 1482 | 1482 | // If lessons are complete without needing quizzes to be passed |
| 1483 | - if ( 'passed' != $course_completion ) { |
|
| 1484 | - switch ( $lesson_status->comment_approved ) { |
|
| 1483 | + if ('passed' != $course_completion) { |
|
| 1484 | + switch ($lesson_status->comment_approved) { |
|
| 1485 | 1485 | // A user cannot 'complete' a course if a lesson... |
| 1486 | 1486 | case 'in-progress': // ...is still in progress |
| 1487 | 1487 | case 'ungraded': // ...hasn't yet been graded |
@@ -1493,7 +1493,7 @@ discard block |
||
| 1493 | 1493 | } |
| 1494 | 1494 | } |
| 1495 | 1495 | else { |
| 1496 | - switch ( $lesson_status->comment_approved ) { |
|
| 1496 | + switch ($lesson_status->comment_approved) { |
|
| 1497 | 1497 | case 'complete': // Lesson has no quiz/questions |
| 1498 | 1498 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1499 | 1499 | case 'passed': // Lesson has quiz and the user passed |
@@ -1507,20 +1507,20 @@ discard block |
||
| 1507 | 1507 | } |
| 1508 | 1508 | } |
| 1509 | 1509 | } // Each lesson |
| 1510 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1510 | + if ($lessons_completed == $total_lessons) { |
|
| 1511 | 1511 | $course_status = 'complete'; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | // Update meta data on how many lessons have been completed |
| 1515 | 1515 | $course_metadata['complete'] = $lessons_completed; |
| 1516 | 1516 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1517 | - $course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1517 | + $course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1518 | 1518 | |
| 1519 | - $activity_logged = WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata ); |
|
| 1519 | + $activity_logged = WooThemes_Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata); |
|
| 1520 | 1520 | |
| 1521 | 1521 | // Allow further actions |
| 1522 | - if ( 'complete' == $course_status ) { |
|
| 1523 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
| 1522 | + if ('complete' == $course_status) { |
|
| 1523 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
| 1524 | 1524 | } |
| 1525 | 1525 | return $activity_logged; |
| 1526 | 1526 | } |
@@ -1535,31 +1535,31 @@ discard block |
||
| 1535 | 1535 | * @param int $user_id |
| 1536 | 1536 | * @return boolean |
| 1537 | 1537 | */ |
| 1538 | - public static function user_completed_course( $course = 0, $user_id = 0 ) { |
|
| 1538 | + public static function user_completed_course($course = 0, $user_id = 0) { |
|
| 1539 | 1539 | |
| 1540 | - if( $course ) { |
|
| 1541 | - if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
|
| 1540 | + if ($course) { |
|
| 1541 | + if (is_object($course) && is_a($course, 'WP_Comment')) { |
|
| 1542 | 1542 | $user_course_status = $course->comment_approved; |
| 1543 | 1543 | } |
| 1544 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
| 1544 | + elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) { |
|
| 1545 | 1545 | $user_course_status = $course; |
| 1546 | 1546 | } |
| 1547 | 1547 | else { |
| 1548 | - if( ! $user_id ) { |
|
| 1548 | + if ( ! $user_id) { |
|
| 1549 | 1549 | $user_id = get_current_user_id(); |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1553 | - $course = $course->ID; |
|
| 1552 | + if (is_a($course, 'WP_Post')) { |
|
| 1553 | + $course = $course->ID; |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | - $user_course_status = WooThemes_Sensei_Utils::user_course_status( $course , $user_id ); |
|
| 1557 | - if( isset( $user_course_status->comment_approved ) ){ |
|
| 1556 | + $user_course_status = WooThemes_Sensei_Utils::user_course_status($course, $user_id); |
|
| 1557 | + if (isset($user_course_status->comment_approved)) { |
|
| 1558 | 1558 | $user_course_status = $user_course_status->comment_approved; |
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | } |
| 1562 | - if( $user_course_status && 'complete' == $user_course_status ) { |
|
| 1562 | + if ($user_course_status && 'complete' == $user_course_status) { |
|
| 1563 | 1563 | return true; |
| 1564 | 1564 | } |
| 1565 | 1565 | } |
@@ -1574,15 +1574,15 @@ discard block |
||
| 1574 | 1574 | * @param type $user_id |
| 1575 | 1575 | * @return mixed false or comment_ID |
| 1576 | 1576 | */ |
| 1577 | - public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
|
| 1577 | + public static function user_started_lesson($lesson_id = 0, $user_id = 0) { |
|
| 1578 | 1578 | |
| 1579 | - if( $lesson_id ) { |
|
| 1580 | - if( ! $user_id ) { |
|
| 1579 | + if ($lesson_id) { |
|
| 1580 | + if ( ! $user_id) { |
|
| 1581 | 1581 | $user_id = get_current_user_id(); |
| 1582 | 1582 | } |
| 1583 | 1583 | |
| 1584 | - $user_lesson_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID' ) ); |
|
| 1585 | - if( $user_lesson_status_id ) { |
|
| 1584 | + $user_lesson_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); |
|
| 1585 | + if ($user_lesson_status_id) { |
|
| 1586 | 1586 | return $user_lesson_status_id; |
| 1587 | 1587 | } |
| 1588 | 1588 | } |
@@ -1597,29 +1597,29 @@ discard block |
||
| 1597 | 1597 | * @param int $user_id |
| 1598 | 1598 | * @return boolean |
| 1599 | 1599 | */ |
| 1600 | - public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) { |
|
| 1600 | + public static function user_completed_lesson($lesson = 0, $user_id = 0) { |
|
| 1601 | 1601 | |
| 1602 | - if( $lesson ) { |
|
| 1602 | + if ($lesson) { |
|
| 1603 | 1603 | $lesson_id = 0; |
| 1604 | - if ( is_object( $lesson ) ) { |
|
| 1604 | + if (is_object($lesson)) { |
|
| 1605 | 1605 | $user_lesson_status = $lesson->comment_approved; |
| 1606 | 1606 | $lesson_id = $lesson->comment_post_ID; |
| 1607 | 1607 | } |
| 1608 | - elseif ( ! is_numeric( $lesson ) ) { |
|
| 1608 | + elseif ( ! is_numeric($lesson)) { |
|
| 1609 | 1609 | $user_lesson_status = $lesson; |
| 1610 | 1610 | } |
| 1611 | 1611 | else { |
| 1612 | - if( ! $user_id ) { |
|
| 1612 | + if ( ! $user_id) { |
|
| 1613 | 1613 | $user_id = get_current_user_id(); |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | 1616 | // the user is not logged in |
| 1617 | - if( ! $user_id > 0 ){ |
|
| 1617 | + if ( ! $user_id > 0) { |
|
| 1618 | 1618 | return false; |
| 1619 | 1619 | } |
| 1620 | - $_user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
|
| 1620 | + $_user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson, $user_id); |
|
| 1621 | 1621 | |
| 1622 | - if ( $_user_lesson_status ) { |
|
| 1622 | + if ($_user_lesson_status) { |
|
| 1623 | 1623 | $user_lesson_status = $_user_lesson_status->comment_approved; |
| 1624 | 1624 | } |
| 1625 | 1625 | else { |
@@ -1627,12 +1627,12 @@ discard block |
||
| 1627 | 1627 | } |
| 1628 | 1628 | $lesson_id = $lesson; |
| 1629 | 1629 | } |
| 1630 | - if ( 'in-progress' != $user_lesson_status ) { |
|
| 1630 | + if ('in-progress' != $user_lesson_status) { |
|
| 1631 | 1631 | // Check for Passed or Completed Setting |
| 1632 | 1632 | // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting |
| 1633 | 1633 | // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
| 1634 | 1634 | // if ( 'passed' == $course_completion ) { |
| 1635 | - switch( $user_lesson_status ) { |
|
| 1635 | + switch ($user_lesson_status) { |
|
| 1636 | 1636 | case 'complete': |
| 1637 | 1637 | case 'graded': |
| 1638 | 1638 | case 'passed': |
@@ -1641,13 +1641,13 @@ discard block |
||
| 1641 | 1641 | |
| 1642 | 1642 | case 'failed': |
| 1643 | 1643 | // This may be 'completed' depending on... |
| 1644 | - if ( $lesson_id ) { |
|
| 1644 | + if ($lesson_id) { |
|
| 1645 | 1645 | // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson |
| 1646 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1647 | - if ( $lesson_quiz_id ) { |
|
| 1646 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1647 | + if ($lesson_quiz_id) { |
|
| 1648 | 1648 | // ...the quiz pass setting |
| 1649 | - $pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true ); |
|
| 1650 | - if ( empty($pass_required) ) { |
|
| 1649 | + $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); |
|
| 1650 | + if (empty($pass_required)) { |
|
| 1651 | 1651 | // We just require the user to have done the quiz, not to have passed |
| 1652 | 1652 | return true; |
| 1653 | 1653 | } |
@@ -1670,15 +1670,15 @@ discard block |
||
| 1670 | 1670 | * @param type $user_id |
| 1671 | 1671 | * @return object |
| 1672 | 1672 | */ |
| 1673 | - public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
|
| 1673 | + public static function user_course_status($course_id = 0, $user_id = 0) { |
|
| 1674 | 1674 | |
| 1675 | 1675 | |
| 1676 | - if( $course_id ) { |
|
| 1677 | - if( ! $user_id ) { |
|
| 1676 | + if ($course_id) { |
|
| 1677 | + if ( ! $user_id) { |
|
| 1678 | 1678 | $user_id = get_current_user_id(); |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | - $user_course_status = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true ); |
|
| 1681 | + $user_course_status = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true); |
|
| 1682 | 1682 | return $user_course_status; |
| 1683 | 1683 | } |
| 1684 | 1684 | |
@@ -1693,27 +1693,27 @@ discard block |
||
| 1693 | 1693 | * @param int $user_id |
| 1694 | 1694 | * @return object | bool |
| 1695 | 1695 | */ |
| 1696 | - public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
|
| 1696 | + public static function user_lesson_status($lesson_id = 0, $user_id = 0) { |
|
| 1697 | 1697 | |
| 1698 | - if( ! $user_id ) { |
|
| 1698 | + if ( ! $user_id) { |
|
| 1699 | 1699 | $user_id = get_current_user_id(); |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1702 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1703 | 1703 | |
| 1704 | - $user_lesson_status = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true ); |
|
| 1704 | + $user_lesson_status = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true); |
|
| 1705 | 1705 | return $user_lesson_status; |
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | return false; |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | - public static function is_preview_lesson( $lesson_id ) { |
|
| 1711 | + public static function is_preview_lesson($lesson_id) { |
|
| 1712 | 1712 | $is_preview = false; |
| 1713 | 1713 | |
| 1714 | - if( 'lesson' == get_post_type( $lesson_id ) ) { |
|
| 1715 | - $lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true ); |
|
| 1716 | - if ( isset( $lesson_preview ) && '' != $lesson_preview ) { |
|
| 1714 | + if ('lesson' == get_post_type($lesson_id)) { |
|
| 1715 | + $lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true); |
|
| 1716 | + if (isset($lesson_preview) && '' != $lesson_preview) { |
|
| 1717 | 1717 | $is_preview = true; |
| 1718 | 1718 | } |
| 1719 | 1719 | } |
@@ -1721,22 +1721,22 @@ discard block |
||
| 1721 | 1721 | return $is_preview; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | - public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
|
| 1724 | + public static function user_passed_quiz($quiz_id = 0, $user_id = 0) { |
|
| 1725 | 1725 | |
| 1726 | - if( ! $quiz_id ) return false; |
|
| 1726 | + if ( ! $quiz_id) return false; |
|
| 1727 | 1727 | |
| 1728 | - if( ! $user_id ) { |
|
| 1728 | + if ( ! $user_id) { |
|
| 1729 | 1729 | $user_id = get_current_user_id(); |
| 1730 | 1730 | } |
| 1731 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 1731 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 1732 | 1732 | |
| 1733 | 1733 | // Quiz Grade |
| 1734 | - $lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1735 | - $quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 1734 | + $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1735 | + $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 1736 | 1736 | |
| 1737 | 1737 | // Check if Grade is greater than or equal to pass percentage |
| 1738 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 1739 | - if ( $quiz_passmark <= intval( $quiz_grade ) ) { |
|
| 1738 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 1739 | + if ($quiz_passmark <= intval($quiz_grade)) { |
|
| 1740 | 1740 | return true; |
| 1741 | 1741 | } |
| 1742 | 1742 | |
@@ -1756,9 +1756,9 @@ discard block |
||
| 1756 | 1756 | * |
| 1757 | 1757 | * @return mixed false or comment_ID |
| 1758 | 1758 | */ |
| 1759 | - public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1759 | + public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) { |
|
| 1760 | 1760 | $comment_id = false; |
| 1761 | - if ( !empty($status) ) { |
|
| 1761 | + if ( ! empty($status)) { |
|
| 1762 | 1762 | $args = array( |
| 1763 | 1763 | 'user_id' => $user_id, |
| 1764 | 1764 | 'post_id' => $lesson_id, |
@@ -1767,18 +1767,18 @@ discard block |
||
| 1767 | 1767 | 'action' => 'update', // Update the existing status... |
| 1768 | 1768 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1769 | 1769 | ); |
| 1770 | - if( 'in-progress' == $status ) { |
|
| 1771 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1770 | + if ('in-progress' == $status) { |
|
| 1771 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1772 | 1772 | } |
| 1773 | 1773 | |
| 1774 | - $comment_id = WooThemes_Sensei_Utils::sensei_log_activity( $args ); |
|
| 1775 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1776 | - foreach( $metadata as $key => $value ) { |
|
| 1777 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1774 | + $comment_id = WooThemes_Sensei_Utils::sensei_log_activity($args); |
|
| 1775 | + if ($comment_id && ! empty($metadata)) { |
|
| 1776 | + foreach ($metadata as $key => $value) { |
|
| 1777 | + update_comment_meta($comment_id, $key, $value); |
|
| 1778 | 1778 | } |
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | - do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id ); |
|
| 1781 | + do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | return $comment_id; |
| 1784 | 1784 | } |
@@ -1794,9 +1794,9 @@ discard block |
||
| 1794 | 1794 | * @param type $metadata |
| 1795 | 1795 | * @return mixed false or comment_ID |
| 1796 | 1796 | */ |
| 1797 | - public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1797 | + public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) { |
|
| 1798 | 1798 | $comment_id = false; |
| 1799 | - if ( !empty($status) ) { |
|
| 1799 | + if ( ! empty($status)) { |
|
| 1800 | 1800 | $args = array( |
| 1801 | 1801 | 'user_id' => $user_id, |
| 1802 | 1802 | 'post_id' => $course_id, |
@@ -1805,17 +1805,17 @@ discard block |
||
| 1805 | 1805 | 'action' => 'update', // Update the existing status... |
| 1806 | 1806 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1807 | 1807 | ); |
| 1808 | - if( 'in-progress' == $status ) { |
|
| 1809 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1808 | + if ('in-progress' == $status) { |
|
| 1809 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | - $comment_id = WooThemes_Sensei_Utils::sensei_log_activity( $args ); |
|
| 1813 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1814 | - foreach( $metadata as $key => $value ) { |
|
| 1815 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1812 | + $comment_id = WooThemes_Sensei_Utils::sensei_log_activity($args); |
|
| 1813 | + if ($comment_id && ! empty($metadata)) { |
|
| 1814 | + foreach ($metadata as $key => $value) { |
|
| 1815 | + update_comment_meta($comment_id, $key, $value); |
|
| 1816 | 1816 | } |
| 1817 | 1817 | } |
| 1818 | - do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id ); |
|
| 1818 | + do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id); |
|
| 1819 | 1819 | } |
| 1820 | 1820 | return $comment_id; |
| 1821 | 1821 | } |
@@ -1827,9 +1827,9 @@ discard block |
||
| 1827 | 1827 | * @param array $pieces (default: array()) |
| 1828 | 1828 | * @return array |
| 1829 | 1829 | */ |
| 1830 | - public static function single_comment_filter( $pieces ) { |
|
| 1831 | - unset( $pieces['orderby'] ); |
|
| 1832 | - unset( $pieces['order'] ); |
|
| 1830 | + public static function single_comment_filter($pieces) { |
|
| 1831 | + unset($pieces['orderby']); |
|
| 1832 | + unset($pieces['order']); |
|
| 1833 | 1833 | |
| 1834 | 1834 | return $pieces; |
| 1835 | 1835 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
| 1841 | 1841 | * @param array $pieces (default: array()) |
| 1842 | 1842 | * @return array |
| 1843 | 1843 | */ |
| 1844 | - public static function comment_any_status_filter( $pieces ) { |
|
| 1844 | + public static function comment_any_status_filter($pieces) { |
|
| 1845 | 1845 | |
| 1846 | - $pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] ); |
|
| 1846 | + $pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']); |
|
| 1847 | 1847 | |
| 1848 | 1848 | return $pieces; |
| 1849 | 1849 | } |
@@ -1855,12 +1855,12 @@ discard block |
||
| 1855 | 1855 | * @param array $pieces (default: array()) |
| 1856 | 1856 | * @return array |
| 1857 | 1857 | */ |
| 1858 | - public static function comment_multiple_status_filter( $pieces ) { |
|
| 1858 | + public static function comment_multiple_status_filter($pieces) { |
|
| 1859 | 1859 | |
| 1860 | - preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder ); |
|
| 1861 | - if ( !empty($placeholder[1]) ) { |
|
| 1862 | - $statuses = explode( ',', $placeholder[1] ); |
|
| 1863 | - $pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] ); |
|
| 1860 | + preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder); |
|
| 1861 | + if ( ! empty($placeholder[1])) { |
|
| 1862 | + $statuses = explode(',', $placeholder[1]); |
|
| 1863 | + $pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']); |
|
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | return $pieces; |
@@ -1871,12 +1871,12 @@ discard block |
||
| 1871 | 1871 | * @since 1.7.0 |
| 1872 | 1872 | * @return array |
| 1873 | 1873 | */ |
| 1874 | - public static function comment_total_sum_meta_value_filter( $pieces ) { |
|
| 1874 | + public static function comment_total_sum_meta_value_filter($pieces) { |
|
| 1875 | 1875 | global $wpdb, $wp_version; |
| 1876 | 1876 | |
| 1877 | 1877 | $pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum "; |
| 1878 | - unset( $pieces['groupby'] ); |
|
| 1879 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1878 | + unset($pieces['groupby']); |
|
| 1879 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1880 | 1880 | $args['order'] = false; |
| 1881 | 1881 | $args['orderby'] = false; |
| 1882 | 1882 | } |
@@ -1891,12 +1891,12 @@ discard block |
||
| 1891 | 1891 | * @param array $pieces (default: array()) |
| 1892 | 1892 | * @return array |
| 1893 | 1893 | */ |
| 1894 | - public static function get_posts_count_only_filter( $pieces ) { |
|
| 1894 | + public static function get_posts_count_only_filter($pieces) { |
|
| 1895 | 1895 | global $wp_version; |
| 1896 | 1896 | |
| 1897 | 1897 | $pieces['fields'] = " COUNT(*) AS total "; |
| 1898 | - unset( $pieces['groupby'] ); |
|
| 1899 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1898 | + unset($pieces['groupby']); |
|
| 1899 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1900 | 1900 | $args['order'] = false; |
| 1901 | 1901 | $args['orderby'] = false; |
| 1902 | 1902 | } |
@@ -1915,9 +1915,9 @@ discard block |
||
| 1915 | 1915 | * |
| 1916 | 1916 | * @return bool $success |
| 1917 | 1917 | */ |
| 1918 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1918 | + public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1919 | 1919 | |
| 1920 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1920 | + return self::update_user_data($data_key, $post_id, $value, $user_id); |
|
| 1921 | 1921 | |
| 1922 | 1922 | }// end add_user_data |
| 1923 | 1923 | |
@@ -1936,18 +1936,18 @@ discard block |
||
| 1936 | 1936 | * |
| 1937 | 1937 | * @return bool $success |
| 1938 | 1938 | */ |
| 1939 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1939 | + public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1940 | 1940 | |
| 1941 | - if( ! ( $user_id > 0 ) ){ |
|
| 1941 | + if ( ! ($user_id > 0)) { |
|
| 1942 | 1942 | $user_id = get_current_user_id(); |
| 1943 | 1943 | } |
| 1944 | 1944 | |
| 1945 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1946 | - $post_type = get_post_type( $post_id ); |
|
| 1947 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1948 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1949 | - || !get_userdata( $user_id ) |
|
| 1950 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1945 | + $supported_post_types = array('course', 'lesson'); |
|
| 1946 | + $post_type = get_post_type($post_id); |
|
| 1947 | + if (empty($post_id) || empty($data_key) |
|
| 1948 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 1949 | + || ! get_userdata($user_id) |
|
| 1950 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 1951 | 1951 | |
| 1952 | 1952 | return false; |
| 1953 | 1953 | } |
@@ -1955,20 +1955,20 @@ discard block |
||
| 1955 | 1955 | // check if there and existing Sensei status on this post type if not create it |
| 1956 | 1956 | // and get the activity ID |
| 1957 | 1957 | $status_function = 'user_'.$post_type.'_status'; |
| 1958 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1959 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1958 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 1959 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 1960 | 1960 | |
| 1961 | 1961 | $start_function = 'user_start_'.$post_type; |
| 1962 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1962 | + $sensei_user_activity_id = self::$start_function($user_id, $post_id); |
|
| 1963 | 1963 | |
| 1964 | - }else{ |
|
| 1964 | + } else { |
|
| 1965 | 1965 | |
| 1966 | 1966 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 1967 | 1967 | |
| 1968 | 1968 | } |
| 1969 | 1969 | |
| 1970 | 1970 | // store the data |
| 1971 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1971 | + $success = update_comment_meta($sensei_user_activity_id, $data_key, $value); |
|
| 1972 | 1972 | |
| 1973 | 1973 | return $success; |
| 1974 | 1974 | |
@@ -1987,20 +1987,20 @@ discard block |
||
| 1987 | 1987 | * |
| 1988 | 1988 | * @return mixed $user_data_value |
| 1989 | 1989 | */ |
| 1990 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1990 | + public static function get_user_data($data_key, $post_id, $user_id = 0) { |
|
| 1991 | 1991 | |
| 1992 | 1992 | $user_data_value = true; |
| 1993 | 1993 | |
| 1994 | - if( ! ( $user_id > 0 ) ){ |
|
| 1994 | + if ( ! ($user_id > 0)) { |
|
| 1995 | 1995 | $user_id = get_current_user_id(); |
| 1996 | 1996 | } |
| 1997 | 1997 | |
| 1998 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1999 | - $post_type = get_post_type( $post_id ); |
|
| 2000 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2001 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2002 | - || ! get_userdata( $user_id ) |
|
| 2003 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1998 | + $supported_post_types = array('course', 'lesson'); |
|
| 1999 | + $post_type = get_post_type($post_id); |
|
| 2000 | + if (empty($post_id) || empty($data_key) |
|
| 2001 | + || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2002 | + || ! get_userdata($user_id) |
|
| 2003 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2004 | 2004 | |
| 2005 | 2005 | return false; |
| 2006 | 2006 | } |
@@ -2008,13 +2008,13 @@ discard block |
||
| 2008 | 2008 | // check if there and existing Sensei status on this post type if not create it |
| 2009 | 2009 | // and get the activity ID |
| 2010 | 2010 | $status_function = 'user_'.$post_type.'_status'; |
| 2011 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2012 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2011 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2012 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2013 | 2013 | return false; |
| 2014 | 2014 | } |
| 2015 | 2015 | |
| 2016 | 2016 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2017 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2017 | + $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true); |
|
| 2018 | 2018 | |
| 2019 | 2019 | return $user_data_value; |
| 2020 | 2020 | |
@@ -2029,19 +2029,19 @@ discard block |
||
| 2029 | 2029 | * |
| 2030 | 2030 | * @return bool $deleted |
| 2031 | 2031 | */ |
| 2032 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2032 | + public static function delete_user_data($data_key, $post_id, $user_id) { |
|
| 2033 | 2033 | $deleted = true; |
| 2034 | 2034 | |
| 2035 | - if( ! ( $user_id > 0 ) ){ |
|
| 2035 | + if ( ! ($user_id > 0)) { |
|
| 2036 | 2036 | $user_id = get_current_user_id(); |
| 2037 | 2037 | } |
| 2038 | 2038 | |
| 2039 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2040 | - $post_type = get_post_type( $post_id ); |
|
| 2041 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2042 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2043 | - || ! get_userdata( $user_id ) |
|
| 2044 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2039 | + $supported_post_types = array('course', 'lesson'); |
|
| 2040 | + $post_type = get_post_type($post_id); |
|
| 2041 | + if (empty($post_id) || empty($data_key) |
|
| 2042 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2043 | + || ! get_userdata($user_id) |
|
| 2044 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2045 | 2045 | |
| 2046 | 2046 | return false; |
| 2047 | 2047 | } |
@@ -2049,13 +2049,13 @@ discard block |
||
| 2049 | 2049 | // check if there and existing Sensei status on this post type if not create it |
| 2050 | 2050 | // and get the activity ID |
| 2051 | 2051 | $status_function = 'user_'.$post_type.'_status'; |
| 2052 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2053 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2052 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2053 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2054 | 2054 | return false; |
| 2055 | 2055 | } |
| 2056 | 2056 | |
| 2057 | 2057 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2058 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2058 | + $deleted = delete_comment_meta($sensei_user_activity_id, $data_key); |
|
| 2059 | 2059 | |
| 2060 | 2060 | return $deleted; |
| 2061 | 2061 | |
@@ -2080,62 +2080,62 @@ discard block |
||
| 2080 | 2080 | * |
| 2081 | 2081 | * @return string $drop_down_element |
| 2082 | 2082 | */ |
| 2083 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2083 | + public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) { |
|
| 2084 | 2084 | |
| 2085 | 2085 | $drop_down_element = ''; |
| 2086 | 2086 | |
| 2087 | 2087 | // setup the basic attributes |
| 2088 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2088 | + if ( ! isset($attributes['name']) || empty($attributes['name'])) { |
|
| 2089 | 2089 | |
| 2090 | 2090 | $attributes['name'] = 'sensei-options'; |
| 2091 | 2091 | |
| 2092 | 2092 | } |
| 2093 | 2093 | |
| 2094 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2094 | + if ( ! isset($attributes['id']) || empty($attributes['id'])) { |
|
| 2095 | 2095 | |
| 2096 | 2096 | $attributes['id'] = 'sensei-options'; |
| 2097 | 2097 | |
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2100 | + if ( ! isset($attributes['class']) || empty($attributes['class'])) { |
|
| 2101 | 2101 | |
| 2102 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2102 | + $attributes['class'] = 'chosen_select widefat'; |
|
| 2103 | 2103 | |
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | 2106 | // create element attributes |
| 2107 | 2107 | $combined_attributes = ''; |
| 2108 | - foreach( $attributes as $attribute => $value ){ |
|
| 2108 | + foreach ($attributes as $attribute => $value) { |
|
| 2109 | 2109 | |
| 2110 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2110 | + $combined_attributes .= $attribute.'="'.$value.'"'.' '; |
|
| 2111 | 2111 | |
| 2112 | 2112 | }// end for each |
| 2113 | 2113 | |
| 2114 | 2114 | |
| 2115 | 2115 | // create the select element |
| 2116 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2116 | + $drop_down_element .= '<select '.$combined_attributes.' >'."\n"; |
|
| 2117 | 2117 | |
| 2118 | 2118 | // show the none option if the client requested |
| 2119 | - if( $enable_none_option ) { |
|
| 2120 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2119 | + if ($enable_none_option) { |
|
| 2120 | + $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | - if ( count( $options ) > 0 ) { |
|
| 2123 | + if (count($options) > 0) { |
|
| 2124 | 2124 | |
| 2125 | - foreach ($options as $value => $option ){ |
|
| 2125 | + foreach ($options as $value => $option) { |
|
| 2126 | 2126 | |
| 2127 | 2127 | $element = ''; |
| 2128 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2129 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2130 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2128 | + $element .= '<option value="'.esc_attr($value).'"'; |
|
| 2129 | + $element .= selected($value, $selected_value, false).'>'; |
|
| 2130 | + $element .= esc_html($option).'</option>'."\n"; |
|
| 2131 | 2131 | |
| 2132 | 2132 | // add the element to the select html |
| 2133 | - $drop_down_element.= $element; |
|
| 2133 | + $drop_down_element .= $element; |
|
| 2134 | 2134 | } // End For Loop |
| 2135 | 2135 | |
| 2136 | 2136 | } // End If Statement |
| 2137 | 2137 | |
| 2138 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2138 | + $drop_down_element .= '</select>'."\n"; |
|
| 2139 | 2139 | |
| 2140 | 2140 | return $drop_down_element; |
| 2141 | 2141 | |
@@ -2155,14 +2155,14 @@ discard block |
||
| 2155 | 2155 | * |
| 2156 | 2156 | * @return double $val |
| 2157 | 2157 | */ |
| 2158 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2158 | + public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') { |
|
| 2159 | 2159 | |
| 2160 | 2160 | /**å |
| 2161 | 2161 | * Change the precision for the Sensei_Utils::round function. |
| 2162 | 2162 | * the precision given will be passed into the php round function |
| 2163 | 2163 | * @since 1.8.5 |
| 2164 | 2164 | */ |
| 2165 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2165 | + $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode); |
|
| 2166 | 2166 | |
| 2167 | 2167 | /** |
| 2168 | 2168 | * Change the mode for the Sensei_Utils::round function. |
@@ -2172,15 +2172,15 @@ discard block |
||
| 2172 | 2172 | * |
| 2173 | 2173 | * @since 1.8.5 |
| 2174 | 2174 | */ |
| 2175 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2175 | + $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision); |
|
| 2176 | 2176 | |
| 2177 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2177 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
| 2178 | 2178 | |
| 2179 | - return round( $val, $precision, $mode ); |
|
| 2179 | + return round($val, $precision, $mode); |
|
| 2180 | 2180 | |
| 2181 | - }else{ |
|
| 2181 | + } else { |
|
| 2182 | 2182 | |
| 2183 | - return round( $val, $precision ); |
|
| 2183 | + return round($val, $precision); |
|
| 2184 | 2184 | |
| 2185 | 2185 | } |
| 2186 | 2186 | |
@@ -2192,15 +2192,15 @@ discard block |
||
| 2192 | 2192 | * @since 1.9.0 |
| 2193 | 2193 | * @return string $url |
| 2194 | 2194 | */ |
| 2195 | - public static function get_current_url(){ |
|
| 2195 | + public static function get_current_url() { |
|
| 2196 | 2196 | |
| 2197 | 2197 | global $wp; |
| 2198 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2199 | - if ( isset( $_GET ) ) { |
|
| 2198 | + $current_url = trailingslashit(home_url($wp->request)); |
|
| 2199 | + if (isset($_GET)) { |
|
| 2200 | 2200 | |
| 2201 | - foreach ($_GET as $param => $val ) { |
|
| 2201 | + foreach ($_GET as $param => $val) { |
|
| 2202 | 2202 | |
| 2203 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2203 | + $current_url = add_query_arg($param, $val, $current_url); |
|
| 2204 | 2204 | |
| 2205 | 2205 | } |
| 2206 | 2206 | } |
@@ -2230,27 +2230,27 @@ discard block |
||
| 2230 | 2230 | * @param array $array_b |
| 2231 | 2231 | * @return array $merged_array |
| 2232 | 2232 | */ |
| 2233 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2233 | + public static function array_zip_merge($array_a, $array_b) { |
|
| 2234 | 2234 | |
| 2235 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
| 2235 | + if ( ! isset($array_a[0]) || ! isset($array_b[0])) { |
|
| 2236 | 2236 | trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
| 2237 | 2237 | } |
| 2238 | 2238 | |
| 2239 | 2239 | $merged_array = array(); |
| 2240 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2240 | + $total_elements = count($array_a) + count($array_b); |
|
| 2241 | 2241 | |
| 2242 | 2242 | // Zip arrays |
| 2243 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2243 | + for ($i = 0; $i < $total_elements; $i++) { |
|
| 2244 | 2244 | |
| 2245 | 2245 | // if has an element at current index push a on top |
| 2246 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2247 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2246 | + if (isset($array_a[$i])) { |
|
| 2247 | + $merged_array[] = $array_a[$i]; |
|
| 2248 | 2248 | } |
| 2249 | 2249 | |
| 2250 | 2250 | // next if $array_b has an element at current index push a on top of the element |
| 2251 | 2251 | // from a if there was one, if not the element before that. |
| 2252 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2253 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2252 | + if (isset($array_b[$i])) { |
|
| 2253 | + $merged_array[] = $array_b[$i]; |
|
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | 2256 | } |
@@ -2265,4 +2265,4 @@ discard block |
||
| 2265 | 2265 | * for backward compatibility |
| 2266 | 2266 | * @since 1.9.0 |
| 2267 | 2267 | */ |
| 2268 | -class WooThemes_Sensei_Utils extends Sensei_Utils{} |
|
| 2268 | +class WooThemes_Sensei_Utils extends Sensei_Utils {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Utilities Class |
@@ -181,8 +184,7 @@ discard block |
||
| 181 | 184 | // ...use a filter to switch the encoding back |
| 182 | 185 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 183 | 186 | } |
| 184 | - } |
|
| 185 | - else { |
|
| 187 | + } else { |
|
| 186 | 188 | $args['status'] = 'any'; // 'log' == 'sensei_user_answer' |
| 187 | 189 | } |
| 188 | 190 | |
@@ -307,8 +309,12 @@ discard block |
||
| 307 | 309 | } |
| 308 | 310 | |
| 309 | 311 | foreach( $activities as $activity ) { |
| 310 | - if( '' == $activity->comment_type ) continue; |
|
| 311 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 312 | + if( '' == $activity->comment_type ) { |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
| 316 | + continue; |
|
| 317 | + } |
|
| 312 | 318 | $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
| 313 | 319 | wp_cache_flush(); |
| 314 | 320 | } |
@@ -359,11 +365,13 @@ discard block |
||
| 359 | 365 | $emails[] = $user->user_email; |
| 360 | 366 | } |
| 361 | 367 | |
| 362 | - if ( is_email( $customer_email ) ) |
|
| 363 | - $emails[] = $customer_email; |
|
| 368 | + if ( is_email( $customer_email ) ) { |
|
| 369 | + $emails[] = $customer_email; |
|
| 370 | + } |
|
| 364 | 371 | |
| 365 | - if ( sizeof( $emails ) == 0 ) |
|
| 366 | - return false; |
|
| 372 | + if ( sizeof( $emails ) == 0 ) { |
|
| 373 | + return false; |
|
| 374 | + } |
|
| 367 | 375 | |
| 368 | 376 | $orders = get_posts( array( |
| 369 | 377 | 'posts_per_page' => -1, |
@@ -419,7 +427,9 @@ discard block |
||
| 419 | 427 | */ |
| 420 | 428 | public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
| 421 | 429 | |
| 422 | - if( ! $input_name ) $input_name = $editor_id; |
|
| 430 | + if( ! $input_name ) { |
|
| 431 | + $input_name = $editor_id; |
|
| 432 | + } |
|
| 423 | 433 | |
| 424 | 434 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
| 425 | 435 | |
@@ -729,8 +739,7 @@ discard block |
||
| 729 | 739 | if ( $has_questions ) { |
| 730 | 740 | $status = 'passed'; // Force a pass |
| 731 | 741 | $metadata['grade'] = 0; |
| 732 | - } |
|
| 733 | - else { |
|
| 742 | + } else { |
|
| 734 | 743 | $status = 'complete'; |
| 735 | 744 | } |
| 736 | 745 | } |
@@ -778,7 +787,9 @@ discard block |
||
| 778 | 787 | public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
| 779 | 788 | |
| 780 | 789 | |
| 781 | - if( ! $lesson_id ) return false; |
|
| 790 | + if( ! $lesson_id ) { |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 782 | 793 | |
| 783 | 794 | if( intval( $user_id ) == 0 ) { |
| 784 | 795 | $user_id = get_current_user_id(); |
@@ -816,7 +827,9 @@ discard block |
||
| 816 | 827 | public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
| 817 | 828 | |
| 818 | 829 | |
| 819 | - if( ! $course_id ) return false; |
|
| 830 | + if( ! $course_id ) { |
|
| 831 | + return false; |
|
| 832 | + } |
|
| 820 | 833 | |
| 821 | 834 | if( intval( $user_id ) == 0 ) { |
| 822 | 835 | $user_id = get_current_user_id(); |
@@ -884,8 +897,7 @@ discard block |
||
| 884 | 897 | if( $question ) { |
| 885 | 898 | if ( is_object( $question ) ) { |
| 886 | 899 | $user_answer_id = $question->comment_ID; |
| 887 | - } |
|
| 888 | - else { |
|
| 900 | + } else { |
|
| 889 | 901 | if( intval( $user_id ) == 0 ) { |
| 890 | 902 | $user_id = get_current_user_id(); |
| 891 | 903 | } |
@@ -912,8 +924,7 @@ discard block |
||
| 912 | 924 | if( $question ) { |
| 913 | 925 | if ( is_object( $question ) ) { |
| 914 | 926 | $user_answer_id = $question->comment_ID; |
| 915 | - } |
|
| 916 | - else { |
|
| 927 | + } else { |
|
| 917 | 928 | if( intval( $user_id ) == 0 ) { |
| 918 | 929 | $user_id = get_current_user_id(); |
| 919 | 930 | } |
@@ -978,8 +989,7 @@ discard block |
||
| 978 | 989 | if ( !empty($notes) ) { |
| 979 | 990 | $user_lesson_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
| 980 | 991 | $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
| 981 | - } |
|
| 982 | - else { |
|
| 992 | + } else { |
|
| 983 | 993 | $activity_logged = true; |
| 984 | 994 | } |
| 985 | 995 | } |
@@ -1491,8 +1501,7 @@ discard block |
||
| 1491 | 1501 | $lessons_completed++; |
| 1492 | 1502 | break; |
| 1493 | 1503 | } |
| 1494 | - } |
|
| 1495 | - else { |
|
| 1504 | + } else { |
|
| 1496 | 1505 | switch ( $lesson_status->comment_approved ) { |
| 1497 | 1506 | case 'complete': // Lesson has no quiz/questions |
| 1498 | 1507 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
@@ -1540,11 +1549,9 @@ discard block |
||
| 1540 | 1549 | if( $course ) { |
| 1541 | 1550 | if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
| 1542 | 1551 | $user_course_status = $course->comment_approved; |
| 1543 | - } |
|
| 1544 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
| 1552 | + } elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
| 1545 | 1553 | $user_course_status = $course; |
| 1546 | - } |
|
| 1547 | - else { |
|
| 1554 | + } else { |
|
| 1548 | 1555 | if( ! $user_id ) { |
| 1549 | 1556 | $user_id = get_current_user_id(); |
| 1550 | 1557 | } |
@@ -1604,11 +1611,9 @@ discard block |
||
| 1604 | 1611 | if ( is_object( $lesson ) ) { |
| 1605 | 1612 | $user_lesson_status = $lesson->comment_approved; |
| 1606 | 1613 | $lesson_id = $lesson->comment_post_ID; |
| 1607 | - } |
|
| 1608 | - elseif ( ! is_numeric( $lesson ) ) { |
|
| 1614 | + } elseif ( ! is_numeric( $lesson ) ) { |
|
| 1609 | 1615 | $user_lesson_status = $lesson; |
| 1610 | - } |
|
| 1611 | - else { |
|
| 1616 | + } else { |
|
| 1612 | 1617 | if( ! $user_id ) { |
| 1613 | 1618 | $user_id = get_current_user_id(); |
| 1614 | 1619 | } |
@@ -1621,8 +1626,7 @@ discard block |
||
| 1621 | 1626 | |
| 1622 | 1627 | if ( $_user_lesson_status ) { |
| 1623 | 1628 | $user_lesson_status = $_user_lesson_status->comment_approved; |
| 1624 | - } |
|
| 1625 | - else { |
|
| 1629 | + } else { |
|
| 1626 | 1630 | return false; // No status means not complete |
| 1627 | 1631 | } |
| 1628 | 1632 | $lesson_id = $lesson; |
@@ -1723,7 +1727,9 @@ discard block |
||
| 1723 | 1727 | |
| 1724 | 1728 | public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
| 1725 | 1729 | |
| 1726 | - if( ! $quiz_id ) return false; |
|
| 1730 | + if( ! $quiz_id ) { |
|
| 1731 | + return false; |
|
| 1732 | + } |
|
| 1727 | 1733 | |
| 1728 | 1734 | if( ! $user_id ) { |
| 1729 | 1735 | $user_id = get_current_user_id(); |
@@ -1961,7 +1967,7 @@ discard block |
||
| 1961 | 1967 | $start_function = 'user_start_'.$post_type; |
| 1962 | 1968 | $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
| 1963 | 1969 | |
| 1964 | - }else{ |
|
| 1970 | + } else{ |
|
| 1965 | 1971 | |
| 1966 | 1972 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 1967 | 1973 | |
@@ -2178,7 +2184,7 @@ discard block |
||
| 2178 | 2184 | |
| 2179 | 2185 | return round( $val, $precision, $mode ); |
| 2180 | 2186 | |
| 2181 | - }else{ |
|
| 2187 | + } else{ |
|
| 2182 | 2188 | |
| 2183 | 2189 | return round( $val, $precision ); |
| 2184 | 2190 | |