@@ -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 |
@@ -40,58 +40,58 @@ discard block |
||
| 40 | 40 | * @since 1.8.0 |
| 41 | 41 | * @access public |
| 42 | 42 | */ |
| 43 | - public function __construct ( ) { |
|
| 43 | + public function __construct( ) { |
|
| 44 | 44 | |
| 45 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 46 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 47 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 48 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 49 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 45 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
| 46 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 47 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
| 48 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
| 49 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
| 50 | 50 | |
| 51 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 51 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
| 52 | 52 | |
| 53 | 53 | //filter the quiz submissions |
| 54 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 54 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
| 55 | 55 | |
| 56 | 56 | //grading totals count only those belonging to the teacher |
| 57 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 57 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
| 58 | 58 | |
| 59 | 59 | // show the courses owned by a user on his author archive page |
| 60 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 60 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
| 61 | 61 | |
| 62 | 62 | // notify admin when a teacher creates a course |
| 63 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 63 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
| 64 | 64 | |
| 65 | 65 | // limit the analysis view to only the users taking courses belong to this teacher |
| 66 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 66 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
| 67 | 67 | |
| 68 | 68 | // give teacher access to question post type |
| 69 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 69 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 70 | 70 | |
| 71 | 71 | // Teacher column on the courses list on the admin edit screen |
| 72 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 73 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 72 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
| 73 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
| 74 | 74 | |
| 75 | 75 | //admin edit messages query limit teacher |
| 76 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 76 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
| 77 | 77 | |
| 78 | 78 | //add filter by teacher on courses list |
| 79 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 80 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 79 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
| 80 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
| 81 | 81 | |
| 82 | 82 | // Handle media library restrictions |
| 83 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 84 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 83 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
| 84 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
| 85 | 85 | |
| 86 | 86 | // update lesson owner to course teacher when saved |
| 87 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 87 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 88 | 88 | |
| 89 | 89 | // If a Teacher logs in, redirect to /wp-admin/ |
| 90 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 90 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 94 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 93 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
| 94 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | } // end __constructor() |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | * @access public |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - public function create_role ( ) { |
|
| 109 | + public function create_role( ) { |
|
| 110 | 110 | |
| 111 | 111 | // check if the role exists |
| 112 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 112 | + $this->teacher_role = get_role('teacher'); |
|
| 113 | 113 | |
| 114 | 114 | // if the the teacher is not a valid WordPress role create it |
| 115 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 115 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
| 116 | 116 | // create the role |
| 117 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 117 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // add the capabilities before returning |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | * @since 1.8.0 |
| 129 | 129 | * @access protected |
| 130 | 130 | */ |
| 131 | - protected function add_capabilities ( ) { |
|
| 131 | + protected function add_capabilities( ) { |
|
| 132 | 132 | |
| 133 | 133 | // if this is not a valid WP_Role object exit without adding anything |
| 134 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 134 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
| 135 | 135 | return; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param array $capabilities |
| 143 | 143 | * keys: (string) $cap_name => (bool) $grant |
| 144 | 144 | */ |
| 145 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 145 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
| 146 | 146 | // General access rules |
| 147 | 147 | 'read' => true, |
| 148 | 148 | 'manage_sensei_grades' => true, |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | )); |
| 201 | 201 | |
| 202 | - foreach ( $caps as $cap => $grant ) { |
|
| 202 | + foreach ($caps as $cap => $grant) { |
|
| 203 | 203 | |
| 204 | 204 | // load the capability on to the teacher role |
| 205 | 205 | $this->teacher_role->add_cap($cap, $grant); |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @parameter WP_Post $post |
| 220 | 220 | * @return void |
| 221 | 221 | */ |
| 222 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 222 | + public function add_teacher_meta_boxes($post) { |
|
| 223 | 223 | |
| 224 | - if( !current_user_can('manage_options') ){ |
|
| 224 | + if ( ! current_user_can('manage_options')) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 227 | + add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'), |
|
| 228 | 228 | 'course', |
| 229 | 229 | 'side', |
| 230 | 230 | 'core' |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @access public |
| 242 | 242 | * @parameters |
| 243 | 243 | */ |
| 244 | - public function teacher_meta_box_content ( $post ) { |
|
| 244 | + public function teacher_meta_box_content($post) { |
|
| 245 | 245 | |
| 246 | 246 | // get the current author |
| 247 | 247 | $current_author = $post->post_author; |
@@ -252,12 +252,12 @@ discard block |
||
| 252 | 252 | ?> |
| 253 | 253 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 254 | 254 | |
| 255 | - <?php foreach ( $users as $user_id ) { ?> |
|
| 255 | + <?php foreach ($users as $user_id) { ?> |
|
| 256 | 256 | |
| 257 | 257 | <?php |
| 258 | 258 | $user = get_user_by('id', $user_id); |
| 259 | 259 | ?> |
| 260 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
| 260 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
| 261 | 261 | <?php echo $user->display_name; ?> |
| 262 | 262 | </option> |
| 263 | 263 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @parameters |
| 280 | 280 | * @return array $users user id array |
| 281 | 281 | */ |
| 282 | - public function get_teachers_and_authors ( ){ |
|
| 282 | + public function get_teachers_and_authors( ) { |
|
| 283 | 283 | |
| 284 | 284 | $author_query_args = array( |
| 285 | 285 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | 'who' => 'authors' |
| 288 | 288 | ); |
| 289 | 289 | |
| 290 | - $authors = get_users( $author_query_args ); |
|
| 290 | + $authors = get_users($author_query_args); |
|
| 291 | 291 | |
| 292 | 292 | $teacher_query_args = array( |
| 293 | 293 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | 'role' => 'teacher', |
| 296 | 296 | ); |
| 297 | 297 | |
| 298 | - $teachers = get_users( $teacher_query_args ); |
|
| 298 | + $teachers = get_users($teacher_query_args); |
|
| 299 | 299 | |
| 300 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 300 | + return array_unique(array_merge($teachers, $authors)); |
|
| 301 | 301 | |
| 302 | 302 | }// end get_teachers_and_authors |
| 303 | 303 | |
@@ -313,43 +313,43 @@ discard block |
||
| 313 | 313 | * @parameters |
| 314 | 314 | * @return array $users user id array |
| 315 | 315 | */ |
| 316 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 316 | + public function save_teacher_meta_box($course_id) { |
|
| 317 | 317 | |
| 318 | 318 | // check if this is a post from saving the teacher, if not exit early |
| 319 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 319 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
| 320 | 320 | return; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | //don't fire this hook again |
| 324 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 324 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 325 | 325 | |
| 326 | 326 | // get the current post object |
| 327 | - $post = get_post( $course_id ); |
|
| 327 | + $post = get_post($course_id); |
|
| 328 | 328 | |
| 329 | 329 | // get the current teacher/author |
| 330 | - $current_author = absint( $post->post_author ); |
|
| 331 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 330 | + $current_author = absint($post->post_author); |
|
| 331 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
| 332 | 332 | |
| 333 | 333 | // loop through all post lessons to update their authors as well |
| 334 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 334 | + $this->update_course_lessons_author($course_id, $new_author); |
|
| 335 | 335 | |
| 336 | 336 | // do not do any processing if the selected author is the same as the current author |
| 337 | - if( $current_author == $new_author ){ |
|
| 337 | + if ($current_author == $new_author) { |
|
| 338 | 338 | return; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | // save the course author |
| 342 | 342 | $post_updates = array( |
| 343 | - 'ID' => $post->ID , |
|
| 343 | + 'ID' => $post->ID, |
|
| 344 | 344 | 'post_author' => $new_author |
| 345 | 345 | ); |
| 346 | - wp_update_post( $post_updates ); |
|
| 346 | + wp_update_post($post_updates); |
|
| 347 | 347 | |
| 348 | 348 | // ensure the the modules are update so that then new teacher has access to them |
| 349 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 349 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
| 350 | 350 | |
| 351 | 351 | // notify the new teacher |
| 352 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 352 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
| 353 | 353 | |
| 354 | 354 | } // end save_teacher_meta_box |
| 355 | 355 | |
@@ -363,56 +363,56 @@ discard block |
||
| 363 | 363 | * @param $new_teacher_id |
| 364 | 364 | * @return void |
| 365 | 365 | */ |
| 366 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 366 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
| 367 | 367 | |
| 368 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 368 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
| 369 | 369 | return; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 372 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
| 373 | 373 | |
| 374 | - if( empty( $terms_selected_on_course ) ){ |
|
| 374 | + if (empty($terms_selected_on_course)) { |
|
| 375 | 375 | return; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - foreach( $terms_selected_on_course as $term ){ |
|
| 378 | + foreach ($terms_selected_on_course as $term) { |
|
| 379 | 379 | |
| 380 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 381 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 380 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 381 | + if ($new_teacher_id != $term_author->ID) { |
|
| 382 | 382 | |
| 383 | 383 | $new_term = ''; |
| 384 | 384 | |
| 385 | 385 | //if the new teacher is admin first check to see if the term with this name already exists |
| 386 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 386 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
| 387 | 387 | |
| 388 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 389 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 390 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 391 | - if( !empty( $existing_admin_terms ) ){ |
|
| 388 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
| 389 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
| 390 | + $existing_admin_terms = get_terms('module', $term_args); |
|
| 391 | + if ( ! empty($existing_admin_terms)) { |
|
| 392 | 392 | // insert it even if it exists |
| 393 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 393 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if( empty ( $new_term ) ){ |
|
| 397 | + if (empty ($new_term)) { |
|
| 398 | 398 | |
| 399 | 399 | //setup the new slug |
| 400 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 400 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
| 401 | 401 | |
| 402 | 402 | // create new term and set it |
| 403 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 403 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
| 404 | 404 | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
| 408 | 408 | |
| 409 | 409 | // if term exists |
| 410 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 410 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
| 411 | 411 | |
| 412 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 412 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
| 413 | 413 | $term_id = $existing_term->term_id; |
| 414 | 414 | |
| 415 | - }else{ |
|
| 415 | + } else { |
|
| 416 | 416 | |
| 417 | 417 | // for a new term simply get the term from the returned value |
| 418 | 418 | $term_id = $new_term['term_id']; |
@@ -420,21 +420,21 @@ discard block |
||
| 420 | 420 | } // end if term exist |
| 421 | 421 | |
| 422 | 422 | // set the terms selected on the course |
| 423 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 423 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
| 424 | 424 | |
| 425 | 425 | // remove old term |
| 426 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 426 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
| 427 | 427 | |
| 428 | 428 | // update the lessons within the current module term |
| 429 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 430 | - foreach( $lessons as $lesson ){ |
|
| 429 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 430 | + foreach ($lessons as $lesson) { |
|
| 431 | 431 | |
| 432 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 432 | + if (has_term($term->slug, 'module', $lesson)) { |
|
| 433 | 433 | |
| 434 | 434 | // add the new term, the false at the end says to replace all terms on this module |
| 435 | 435 | // with the new term. |
| 436 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 437 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 436 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
| 437 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | }// end for each |
@@ -454,50 +454,50 @@ discard block |
||
| 454 | 454 | * @parameters |
| 455 | 455 | * @return array $users user id array |
| 456 | 456 | */ |
| 457 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 457 | + public function update_course_lessons_author($course_id, $new_author) { |
|
| 458 | 458 | |
| 459 | 459 | |
| 460 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 460 | + if (empty($course_id) || empty($new_author)) { |
|
| 461 | 461 | return false; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | //get a list of course lessons |
| 465 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 465 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 466 | 466 | |
| 467 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 467 | + if (empty($lessons) || ! is_array($lessons)) { |
|
| 468 | 468 | return false; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | // update each lesson and quiz author |
| 472 | - foreach( $lessons as $lesson ){ |
|
| 472 | + foreach ($lessons as $lesson) { |
|
| 473 | 473 | |
| 474 | 474 | // don't update if the author is tha same as the new author |
| 475 | - if( $new_author == $lesson->post_author ){ |
|
| 475 | + if ($new_author == $lesson->post_author) { |
|
| 476 | 476 | continue; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // update lesson author |
| 480 | - wp_update_post( array( |
|
| 480 | + wp_update_post(array( |
|
| 481 | 481 | 'ID'=> $lesson->ID, |
| 482 | 482 | 'post_author' => $new_author |
| 483 | - ) ); |
|
| 483 | + )); |
|
| 484 | 484 | |
| 485 | 485 | // update quiz author |
| 486 | 486 | //get the lessons quiz |
| 487 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 488 | - if( is_array( $lesson_quizzes ) ){ |
|
| 489 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 487 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 488 | + if (is_array($lesson_quizzes)) { |
|
| 489 | + foreach ($lesson_quizzes as $quiz_id) { |
|
| 490 | 490 | // update quiz with new author |
| 491 | - wp_update_post( array( |
|
| 491 | + wp_update_post(array( |
|
| 492 | 492 | 'ID' => $quiz_id, |
| 493 | 493 | 'post_author' => $new_author |
| 494 | - ) ); |
|
| 494 | + )); |
|
| 495 | 495 | } |
| 496 | - }else{ |
|
| 497 | - wp_update_post( array( |
|
| 496 | + } else { |
|
| 497 | + wp_update_post(array( |
|
| 498 | 498 | 'ID' => $lesson_quizzes, |
| 499 | 499 | 'post_author' => $new_author |
| 500 | - ) ); |
|
| 500 | + )); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | } // end for each lessons |
@@ -518,30 +518,30 @@ discard block |
||
| 518 | 518 | * @parameters $query |
| 519 | 519 | * @return array $users user id array |
| 520 | 520 | */ |
| 521 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 521 | + public function course_analysis_teacher_access_limit($query) { |
|
| 522 | 522 | |
| 523 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 523 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 524 | 524 | return $query; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 527 | + if ( ! function_exists('get_current_screen')) { |
|
| 528 | 528 | return $query; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | $screen = get_current_screen(); |
| 532 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 532 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
| 533 | 533 | |
| 534 | 534 | // exit early for the following conditions |
| 535 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 535 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
| 536 | 536 | |
| 537 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 538 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 537 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
| 538 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
| 539 | 539 | return $query; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | global $current_user; |
| 543 | 543 | // set the query author to the current user to only show those those posts |
| 544 | - $query->set( 'author', $current_user->ID ); |
|
| 544 | + $query->set('author', $current_user->ID); |
|
| 545 | 545 | return $query; |
| 546 | 546 | |
| 547 | 547 | }// end course_analysis_teacher_access_limit |
@@ -557,14 +557,14 @@ discard block |
||
| 557 | 557 | * @parameters array $wp_query |
| 558 | 558 | * @return bool $is_admin_teacher |
| 559 | 559 | */ |
| 560 | - public function is_admin_teacher ( ){ |
|
| 560 | + public function is_admin_teacher( ) { |
|
| 561 | 561 | |
| 562 | - if( ! is_user_logged_in()){ |
|
| 562 | + if ( ! is_user_logged_in()) { |
|
| 563 | 563 | return false; |
| 564 | 564 | } |
| 565 | 565 | $is_admin_teacher = false; |
| 566 | 566 | |
| 567 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 567 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
| 568 | 568 | |
| 569 | 569 | $is_admin_teacher = true; |
| 570 | 570 | |
@@ -584,14 +584,14 @@ discard block |
||
| 584 | 584 | * @param string $perm User permission level |
| 585 | 585 | * @return object Modified status counts |
| 586 | 586 | */ |
| 587 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 587 | + public function list_table_counts($counts, $type, $perm) { |
|
| 588 | 588 | global $current_user; |
| 589 | 589 | |
| 590 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 590 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
| 591 | 591 | return $counts; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - if( ! $this->is_admin_teacher() ) { |
|
| 594 | + if ( ! $this->is_admin_teacher()) { |
|
| 595 | 595 | return $counts; |
| 596 | 596 | } |
| 597 | 597 | |
@@ -605,10 +605,10 @@ discard block |
||
| 605 | 605 | $stati = get_post_stati(); |
| 606 | 606 | |
| 607 | 607 | // Update count object |
| 608 | - foreach( $stati as $status ) { |
|
| 608 | + foreach ($stati as $status) { |
|
| 609 | 609 | $args['post_status'] = $status; |
| 610 | - $posts = get_posts( $args ); |
|
| 611 | - $counts->$status = count( $posts ); |
|
| 610 | + $posts = get_posts($args); |
|
| 611 | + $counts->$status = count($posts); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | return $counts; |
@@ -622,22 +622,22 @@ discard block |
||
| 622 | 622 | * @since 1.8.0 |
| 623 | 623 | * |
| 624 | 624 | */ |
| 625 | - public function filter_queries ( $query ) { |
|
| 625 | + public function filter_queries($query) { |
|
| 626 | 626 | global $current_user; |
| 627 | 627 | |
| 628 | - if( ! $this->is_admin_teacher() ) { |
|
| 628 | + if ( ! $this->is_admin_teacher()) { |
|
| 629 | 629 | return; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 632 | + if ( ! function_exists('get_current_screen')) { |
|
| 633 | 633 | return; |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | $screen = get_current_screen(); |
| 637 | - if( empty( $screen ) ) { |
|
| 637 | + if (empty($screen)) { |
|
| 638 | 638 | return $query; |
| 639 | 639 | } |
| 640 | - switch( $screen->id ) { |
|
| 640 | + switch ($screen->id) { |
|
| 641 | 641 | case 'sensei_page_sensei_grading': |
| 642 | 642 | case 'sensei_page_sensei_analysis': |
| 643 | 643 | case 'sensei_page_sensei_learners': |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | * @param string $screen_id |
| 657 | 657 | * |
| 658 | 658 | */ |
| 659 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 659 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
| 660 | 660 | break; |
| 661 | 661 | } |
| 662 | 662 | } |
@@ -671,31 +671,31 @@ discard block |
||
| 671 | 671 | * |
| 672 | 672 | * @return array $comments |
| 673 | 673 | */ |
| 674 | - public function filter_grading_activity_queries( $comments ){ |
|
| 674 | + public function filter_grading_activity_queries($comments) { |
|
| 675 | 675 | |
| 676 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 677 | - return $comments ; |
|
| 676 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
| 677 | + return $comments; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | //check if we're on the grading screen |
| 681 | 681 | $screen = get_current_screen(); |
| 682 | 682 | |
| 683 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 683 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
| 684 | 684 | return $comments; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // get the course and determine if the current teacher is the owner |
| 688 | 688 | // if not remove it from the list of comments to be returned |
| 689 | - foreach( $comments as $key => $comment){ |
|
| 690 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 691 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 692 | - $course = get_post( $course_id ); |
|
| 693 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 689 | + foreach ($comments as $key => $comment) { |
|
| 690 | + $lesson = get_post($comment->comment_post_ID); |
|
| 691 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
| 692 | + $course = get_post($course_id); |
|
| 693 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
| 694 | 694 | //remove this as the teacher should see this. |
| 695 | - unset( $comments[ $key ] ); |
|
| 695 | + unset($comments[$key]); |
|
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | - return $comments ; |
|
| 698 | + return $comments; |
|
| 699 | 699 | |
| 700 | 700 | }// end function filter grading |
| 701 | 701 | |
@@ -711,34 +711,34 @@ discard block |
||
| 711 | 711 | * |
| 712 | 712 | * @return array $args |
| 713 | 713 | */ |
| 714 | - public function limit_grading_totals( $args ){ |
|
| 714 | + public function limit_grading_totals($args) { |
|
| 715 | 715 | |
| 716 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 717 | - return $args ; |
|
| 716 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
| 717 | + return $args; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | //get the teachers courses |
| 721 | 721 | // the query is already filtered to only the teacher |
| 722 | - $courses = Sensei()->course->get_all_courses(); |
|
| 722 | + $courses = Sensei()->course->get_all_courses(); |
|
| 723 | 723 | |
| 724 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 724 | + if (empty($courses) || ! is_array($courses)) { |
|
| 725 | 725 | return $args; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | //setup the lessons quizzes to limit the grading totals to |
| 729 | 729 | $quiz_scope = array(); |
| 730 | - foreach( $courses as $course ){ |
|
| 730 | + foreach ($courses as $course) { |
|
| 731 | 731 | |
| 732 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 732 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
| 733 | 733 | |
| 734 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 734 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
| 735 | 735 | |
| 736 | - foreach( $course_lessons as $lesson ){ |
|
| 736 | + foreach ($course_lessons as $lesson) { |
|
| 737 | 737 | |
| 738 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 739 | - if( !empty( $quiz_id ) ) { |
|
| 738 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 739 | + if ( ! empty($quiz_id)) { |
|
| 740 | 740 | |
| 741 | - array_push( $quiz_scope, $quiz_id ); |
|
| 741 | + array_push($quiz_scope, $quiz_id); |
|
| 742 | 742 | |
| 743 | 743 | } |
| 744 | 744 | |
@@ -761,41 +761,41 @@ discard block |
||
| 761 | 761 | * @param WP_Query $query |
| 762 | 762 | * @return WP_Query $query |
| 763 | 763 | */ |
| 764 | - public function add_courses_to_author_archive( $query ) { |
|
| 764 | + public function add_courses_to_author_archive($query) { |
|
| 765 | 765 | |
| 766 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 766 | + if (is_admin() || ! $query->is_author()) { |
|
| 767 | 767 | return $query; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | // this should only apply to users with the teacher role |
| 771 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 772 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 771 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
| 772 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
| 773 | 773 | |
| 774 | 774 | return $query; |
| 775 | 775 | |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | // Change post types depending on what is set already |
| 779 | - $current_post_types = $query->get( 'post_type' ); |
|
| 780 | - if( empty( $current_post_types ) ){ |
|
| 779 | + $current_post_types = $query->get('post_type'); |
|
| 780 | + if (empty($current_post_types)) { |
|
| 781 | 781 | |
| 782 | 782 | // if empty it means post by default, so add post so that it also includes that for now |
| 783 | - $new_post_types = array( 'post', 'course' ); |
|
| 783 | + $new_post_types = array('post', 'course'); |
|
| 784 | 784 | |
| 785 | - } elseif( is_array( $current_post_types ) ) { |
|
| 785 | + } elseif (is_array($current_post_types)) { |
|
| 786 | 786 | |
| 787 | 787 | // merge the post types instead of overwriting it |
| 788 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 788 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
| 789 | 789 | |
| 790 | - }else{ |
|
| 790 | + } else { |
|
| 791 | 791 | |
| 792 | 792 | // in this instance it is probably just one post type in string format |
| 793 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 793 | + $new_post_types = array($current_post_types, 'course'); |
|
| 794 | 794 | |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | // change the query before returning it |
| 798 | - $query->set('post_type', $new_post_types ); |
|
| 798 | + $query->set('post_type', $new_post_types); |
|
| 799 | 799 | |
| 800 | 800 | /** |
| 801 | 801 | * Change the query on the teacher author archive template |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | * @since 1.8.4 |
| 804 | 804 | * @param WP_Query $query |
| 805 | 805 | */ |
| 806 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 806 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
| 807 | 807 | |
| 808 | 808 | } |
| 809 | 809 | |
@@ -816,21 +816,21 @@ discard block |
||
| 816 | 816 | * @param $course_id |
| 817 | 817 | * @return bool |
| 818 | 818 | */ |
| 819 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 819 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
| 820 | 820 | |
| 821 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 821 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
| 822 | 822 | return false; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | // if new user is the same as the current logged user, they don't need an email |
| 826 | - if( $teacher_id == get_current_user_id() ){ |
|
| 826 | + if ($teacher_id == get_current_user_id()) { |
|
| 827 | 827 | return true; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | // load the email class |
| 831 | 831 | include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
| 832 | 832 | $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
| 833 | - $email->trigger( $teacher_id, $course_id ); |
|
| 833 | + $email->trigger($teacher_id, $course_id); |
|
| 834 | 834 | |
| 835 | 835 | return true; |
| 836 | 836 | } // end teacher_course_assigned_notification |
@@ -844,12 +844,12 @@ discard block |
||
| 844 | 844 | * @param int $course_id |
| 845 | 845 | * @return bool |
| 846 | 846 | */ |
| 847 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 847 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
| 848 | 848 | |
| 849 | 849 | $course_id = $post->ID; |
| 850 | 850 | |
| 851 | - if( 'publish'== $old_status || 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 852 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 851 | + if ('publish' == $old_status || 'course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
| 852 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
| 853 | 853 | |
| 854 | 854 | return false; |
| 855 | 855 | |
@@ -863,19 +863,19 @@ discard block |
||
| 863 | 863 | * |
| 864 | 864 | * @param bool $on default true |
| 865 | 865 | */ |
| 866 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 866 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
| 867 | 867 | return false; |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | // setting up the data needed by the email template |
| 871 | 871 | global $sensei_email_data; |
| 872 | 872 | $template = 'admin-teacher-new-course-created'; |
| 873 | - $course = get_post( $course_id ); |
|
| 874 | - $teacher = new WP_User( $course->post_author ); |
|
| 873 | + $course = get_post($course_id); |
|
| 874 | + $teacher = new WP_User($course->post_author); |
|
| 875 | 875 | $recipient = get_option('admin_email', true); |
| 876 | 876 | |
| 877 | 877 | // don't send if the course is created by admin |
| 878 | - if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
| 878 | + if ($recipient == $teacher->user_email || current_user_can('manage_options')) { |
|
| 879 | 879 | return false; |
| 880 | 880 | } |
| 881 | 881 | |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | * @since 1.8.0 |
| 886 | 886 | * @param string $template |
| 887 | 887 | */ |
| 888 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 888 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
| 889 | 889 | |
| 890 | 890 | /** |
| 891 | 891 | * Filter the email subject for the the |
@@ -896,11 +896,11 @@ discard block |
||
| 896 | 896 | * @param string $template |
| 897 | 897 | */ |
| 898 | 898 | $subject = apply_filters('sensei_email_subject', |
| 899 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 900 | - $template ); |
|
| 899 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
| 900 | + $template); |
|
| 901 | 901 | |
| 902 | 902 | //course edit link |
| 903 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 903 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
| 904 | 904 | |
| 905 | 905 | // Construct data array |
| 906 | 906 | $email_data = array( |
@@ -919,10 +919,10 @@ discard block |
||
| 919 | 919 | * @param array $email_data |
| 920 | 920 | * @param string $template |
| 921 | 921 | */ |
| 922 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 922 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
| 923 | 923 | |
| 924 | 924 | // Send mail |
| 925 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 925 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
| 926 | 926 | |
| 927 | 927 | }// end notify admin of course creation |
| 928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
| 933 | 933 | * @param array $args WP_User_Query arguments |
| 934 | 934 | * @return array $learners_query_results |
| 935 | 935 | */ |
| 936 | - public function limit_analysis_learners( $args ){ |
|
| 936 | + public function limit_analysis_learners($args) { |
|
| 937 | 937 | |
| 938 | 938 | // show default for none teachers |
| 939 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 939 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
| 940 | 940 | return $args; |
| 941 | 941 | } |
| 942 | 942 | |
@@ -945,31 +945,31 @@ discard block |
||
| 945 | 945 | $teacher_courses = Sensei()->course->get_all_courses(); |
| 946 | 946 | |
| 947 | 947 | // if the user has no courses they should see no users |
| 948 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 948 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
| 949 | 949 | // tell the query to return 0 students |
| 950 | - $args[ 'include'] = array( 0 ); |
|
| 950 | + $args['include'] = array(0); |
|
| 951 | 951 | return $args; |
| 952 | 952 | |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | $learner_ids_for_teacher_courses = array(); |
| 956 | - foreach( $teacher_courses as $course ){ |
|
| 956 | + foreach ($teacher_courses as $course) { |
|
| 957 | 957 | |
| 958 | 958 | $course_learner_ids = array(); |
| 959 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 959 | + $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
| 960 | 960 | |
| 961 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 961 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
| 962 | 962 | continue; // skip to the next course as there are no users on this course |
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | // it could be an array of comments or a single comment |
| 966 | - if( is_array( $activity_comments ) ){ |
|
| 966 | + if (is_array($activity_comments)) { |
|
| 967 | 967 | |
| 968 | - foreach( $activity_comments as $comment ){ |
|
| 968 | + foreach ($activity_comments as $comment) { |
|
| 969 | 969 | |
| 970 | - $user = get_userdata( $comment->user_id ); |
|
| 970 | + $user = get_userdata($comment->user_id); |
|
| 971 | 971 | |
| 972 | - if( empty( $user ) ){ |
|
| 972 | + if (empty($user)) { |
|
| 973 | 973 | // next comment in this array |
| 974 | 974 | continue; |
| 975 | 975 | } |
@@ -977,26 +977,26 @@ discard block |
||
| 977 | 977 | $course_learner_ids[] = $user->ID; |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - }else{ |
|
| 980 | + } else { |
|
| 981 | 981 | |
| 982 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 982 | + $user = get_userdata($activity_comments->user_id); |
|
| 983 | 983 | $course_learner_ids[] = $user->ID; |
| 984 | 984 | |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | // add learners on this course to the all courses learner list |
| 988 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 988 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
| 989 | 989 | |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | // if there are no students taking the courses by this teacher don't show them any of the other users |
| 993 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 993 | + if (empty($learner_ids_for_teacher_courses)) { |
|
| 994 | 994 | |
| 995 | - $args[ 'include'] = array( 0 ); |
|
| 995 | + $args['include'] = array(0); |
|
| 996 | 996 | |
| 997 | - }else{ |
|
| 997 | + } else { |
|
| 998 | 998 | |
| 999 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 999 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
| 1000 | 1000 | |
| 1001 | 1001 | } |
| 1002 | 1002 | |
@@ -1013,35 +1013,35 @@ discard block |
||
| 1013 | 1013 | * @param $questions |
| 1014 | 1014 | * @return mixed |
| 1015 | 1015 | */ |
| 1016 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1016 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
| 1017 | 1017 | |
| 1018 | - if( ! $this->is_admin_teacher() ){ |
|
| 1018 | + if ( ! $this->is_admin_teacher()) { |
|
| 1019 | 1019 | return $questions; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | $screen = get_current_screen(); |
| 1023 | 1023 | |
| 1024 | 1024 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
| 1025 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1025 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
| 1026 | 1026 | |
| 1027 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1027 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
| 1028 | 1028 | |
| 1029 | 1029 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1030 | - if( ! empty($admin_user) ){ |
|
| 1030 | + if ( ! empty($admin_user)) { |
|
| 1031 | 1031 | |
| 1032 | 1032 | $current_teacher_id = get_current_user_id(); |
| 1033 | 1033 | |
| 1034 | 1034 | // set current user to admin so teacher can view all questions |
| 1035 | - wp_set_current_user( $admin_user->ID ); |
|
| 1036 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1035 | + wp_set_current_user($admin_user->ID); |
|
| 1036 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 1037 | 1037 | |
| 1038 | 1038 | // set the teacher as the current use again |
| 1039 | - wp_set_current_user( $current_teacher_id ); |
|
| 1039 | + wp_set_current_user($current_teacher_id); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | } |
| 1043 | 1043 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
| 1044 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1044 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 1045 | 1045 | |
| 1046 | 1046 | return $questions; |
| 1047 | 1047 | } |
@@ -1053,30 +1053,30 @@ discard block |
||
| 1053 | 1053 | * @param $wp_query |
| 1054 | 1054 | * @return mixed |
| 1055 | 1055 | */ |
| 1056 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1056 | + public function give_access_to_all_questions($wp_query) { |
|
| 1057 | 1057 | |
| 1058 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1058 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
| 1059 | 1059 | |
| 1060 | 1060 | return $wp_query; |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | 1063 | $screen = get_current_screen(); |
| 1064 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1065 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1064 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
| 1065 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 1066 | 1066 | |
| 1067 | 1067 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1068 | - if( ! empty($admin_user) ){ |
|
| 1068 | + if ( ! empty($admin_user)) { |
|
| 1069 | 1069 | |
| 1070 | 1070 | $current_teacher_id = get_current_user_id(); |
| 1071 | 1071 | |
| 1072 | 1072 | // set current user to admin so teacher can view all questions |
| 1073 | - wp_set_current_user( $admin_user->ID ); |
|
| 1073 | + wp_set_current_user($admin_user->ID); |
|
| 1074 | 1074 | |
| 1075 | 1075 | //run new query as admin |
| 1076 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1076 | + $wp_query = new WP_Query($wp_query->query); |
|
| 1077 | 1077 | |
| 1078 | 1078 | //set the teache as current use again |
| 1079 | - wp_set_current_user( $current_teacher_id ); |
|
| 1079 | + wp_set_current_user($current_teacher_id); |
|
| 1080 | 1080 | |
| 1081 | 1081 | } |
| 1082 | 1082 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
| 1093 | 1093 | */ |
| 1094 | 1094 | public function course_column_heading($columns) { |
| 1095 | 1095 | |
| 1096 | - if( $this->is_admin_teacher() ){ |
|
| 1096 | + if ($this->is_admin_teacher()) { |
|
| 1097 | 1097 | return $columns; |
| 1098 | 1098 | } |
| 1099 | 1099 | $new_columns = array( |
@@ -1110,20 +1110,20 @@ discard block |
||
| 1110 | 1110 | * @param $column |
| 1111 | 1111 | * @param $course_id |
| 1112 | 1112 | */ |
| 1113 | - public function course_column_data( $column, $course_id ){ |
|
| 1113 | + public function course_column_data($column, $course_id) { |
|
| 1114 | 1114 | |
| 1115 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1115 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
| 1116 | 1116 | return; |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | - $course = get_post( $course_id ); |
|
| 1120 | - $teacher = get_userdata( $course->post_author ); |
|
| 1119 | + $course = get_post($course_id); |
|
| 1120 | + $teacher = get_userdata($course->post_author); |
|
| 1121 | 1121 | |
| 1122 | - if( !$teacher ){ |
|
| 1122 | + if ( ! $teacher) { |
|
| 1123 | 1123 | return; |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1126 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
| 1127 | 1127 | |
| 1128 | 1128 | }// end course_column_ data |
| 1129 | 1129 | |
@@ -1138,31 +1138,31 @@ discard block |
||
| 1138 | 1138 | * |
| 1139 | 1139 | * @return array $teachers_courses |
| 1140 | 1140 | */ |
| 1141 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1141 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
| 1142 | 1142 | |
| 1143 | 1143 | $teachers_courses = array(); |
| 1144 | 1144 | |
| 1145 | - if( empty( $teacher_id ) ){ |
|
| 1145 | + if (empty($teacher_id)) { |
|
| 1146 | 1146 | $teacher_id = get_current_user_id(); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | $all_courses = Sensei()->course->get_all_courses(); |
| 1150 | 1150 | |
| 1151 | - if( empty( $all_courses ) ){ |
|
| 1151 | + if (empty($all_courses)) { |
|
| 1152 | 1152 | return $all_courses; |
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | - foreach( $all_courses as $course ){ |
|
| 1155 | + foreach ($all_courses as $course) { |
|
| 1156 | 1156 | |
| 1157 | - if( $course->post_author != $teacher_id ){ |
|
| 1157 | + if ($course->post_author != $teacher_id) { |
|
| 1158 | 1158 | continue; |
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | - if( $return_ids_only ){ |
|
| 1161 | + if ($return_ids_only) { |
|
| 1162 | 1162 | |
| 1163 | 1163 | $teachers_courses[] = $course->ID; |
| 1164 | 1164 | |
| 1165 | - }else{ |
|
| 1165 | + } else { |
|
| 1166 | 1166 | |
| 1167 | 1167 | $teachers_courses[] = $course; |
| 1168 | 1168 | |
@@ -1182,21 +1182,21 @@ discard block |
||
| 1182 | 1182 | * @param $query |
| 1183 | 1183 | * @return mixed |
| 1184 | 1184 | */ |
| 1185 | - public function limit_edit_messages_query( $query ){ |
|
| 1186 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1185 | + public function limit_edit_messages_query($query) { |
|
| 1186 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
| 1187 | 1187 | return $query; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | $teacher = wp_get_current_user(); |
| 1191 | 1191 | |
| 1192 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1192 | + $query->set('meta_key', '_receiver'); |
|
| 1193 | 1193 | $meta_query_args = array( |
| 1194 | 1194 | 'key' => '_receiver', |
| 1195 | - 'value' => $teacher->get('user_login') , |
|
| 1195 | + 'value' => $teacher->get('user_login'), |
|
| 1196 | 1196 | 'compare' => '=' |
| 1197 | 1197 | ); |
| 1198 | 1198 | |
| 1199 | - $query->set('meta_query', $meta_query_args ); |
|
| 1199 | + $query->set('meta_query', $meta_query_args); |
|
| 1200 | 1200 | |
| 1201 | 1201 | return $query; |
| 1202 | 1202 | } |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | public function course_teacher_filter_options() { |
| 1213 | 1213 | global $typenow; |
| 1214 | 1214 | |
| 1215 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1215 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1216 | 1216 | return; |
| 1217 | 1217 | } |
| 1218 | 1218 | |
@@ -1222,31 +1222,31 @@ discard block |
||
| 1222 | 1222 | // get roles with the course edit capability |
| 1223 | 1223 | // and then get the users with those roles |
| 1224 | 1224 | $users_who_can_edit_courses = array(); |
| 1225 | - foreach( $roles as $role_item ){ |
|
| 1225 | + foreach ($roles as $role_item) { |
|
| 1226 | 1226 | |
| 1227 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1227 | + $role = get_role(strtolower($role_item['name'])); |
|
| 1228 | 1228 | |
| 1229 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1229 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
| 1230 | 1230 | |
| 1231 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1232 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1231 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
| 1232 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
| 1233 | 1233 | |
| 1234 | 1234 | // add user from the current $user_role to all users |
| 1235 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1235 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
| 1236 | 1236 | |
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | // Create the select element with the given users who can edit course |
| 1242 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1242 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1243 | 1243 | $course_options = ''; |
| 1244 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1245 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1244 | + foreach ($users_who_can_edit_courses as $user) { |
|
| 1245 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
| 1249 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1249 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
| 1250 | 1250 | $output .= $course_options; |
| 1251 | 1251 | $output .= '</select>'; |
| 1252 | 1252 | |
@@ -1261,15 +1261,15 @@ discard block |
||
| 1261 | 1261 | * @param $query |
| 1262 | 1262 | * @return $query |
| 1263 | 1263 | */ |
| 1264 | - public function teacher_filter_query_modify( $query ){ |
|
| 1264 | + public function teacher_filter_query_modify($query) { |
|
| 1265 | 1265 | global $typenow; |
| 1266 | 1266 | |
| 1267 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1267 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1268 | 1268 | return $query; |
| 1269 | 1269 | } |
| 1270 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1270 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1271 | 1271 | |
| 1272 | - if( empty( $course_teacher ) ) { |
|
| 1272 | + if (empty($course_teacher)) { |
|
| 1273 | 1273 | return $query; |
| 1274 | 1274 | } |
| 1275 | 1275 | |
@@ -1282,23 +1282,23 @@ discard block |
||
| 1282 | 1282 | * @param array $request Default request arguments |
| 1283 | 1283 | * @return array Modified request arguments |
| 1284 | 1284 | */ |
| 1285 | - public function restrict_media_library( $request = array() ) { |
|
| 1285 | + public function restrict_media_library($request = array()) { |
|
| 1286 | 1286 | |
| 1287 | - if( ! is_admin() ) { |
|
| 1287 | + if ( ! is_admin()) { |
|
| 1288 | 1288 | return $request; |
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | - if( ! $this->is_admin_teacher() ) { |
|
| 1291 | + if ( ! $this->is_admin_teacher()) { |
|
| 1292 | 1292 | return $request; |
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | $screen = get_current_screen(); |
| 1296 | 1296 | |
| 1297 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1298 | - $teacher = intval( get_current_user_id() ); |
|
| 1297 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
| 1298 | + $teacher = intval(get_current_user_id()); |
|
| 1299 | 1299 | |
| 1300 | - if( $teacher ) { |
|
| 1301 | - $request['author__in'] = array( $teacher ); |
|
| 1300 | + if ($teacher) { |
|
| 1301 | + $request['author__in'] = array($teacher); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | } |
| 1304 | 1304 | |
@@ -1310,20 +1310,20 @@ discard block |
||
| 1310 | 1310 | * @param array $query Default query arguments |
| 1311 | 1311 | * @return array Modified query arguments |
| 1312 | 1312 | */ |
| 1313 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1313 | + public function restrict_media_library_modal($query = array()) { |
|
| 1314 | 1314 | |
| 1315 | - if( ! is_admin() ) { |
|
| 1315 | + if ( ! is_admin()) { |
|
| 1316 | 1316 | return $query; |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | - if( ! $this->is_admin_teacher() ) { |
|
| 1319 | + if ( ! $this->is_admin_teacher()) { |
|
| 1320 | 1320 | return $query; |
| 1321 | 1321 | } |
| 1322 | 1322 | |
| 1323 | - $teacher = intval( get_current_user_id() ); |
|
| 1323 | + $teacher = intval(get_current_user_id()); |
|
| 1324 | 1324 | |
| 1325 | - if( $teacher ) { |
|
| 1326 | - $query['author__in'] = array( $teacher ); |
|
| 1325 | + if ($teacher) { |
|
| 1326 | + $query['author__in'] = array($teacher); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | return $query; |
@@ -1336,28 +1336,28 @@ discard block |
||
| 1336 | 1336 | * |
| 1337 | 1337 | * @param int $lesson_id |
| 1338 | 1338 | */ |
| 1339 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1339 | + public function update_lesson_teacher($lesson_id) { |
|
| 1340 | 1340 | |
| 1341 | - if( 'lesson'!= get_post_type() ){ |
|
| 1341 | + if ('lesson' != get_post_type()) { |
|
| 1342 | 1342 | return; |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | // this should only run once per request cycle |
| 1346 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1346 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 1347 | 1347 | |
| 1348 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1348 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1349 | 1349 | |
| 1350 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1350 | + if (empty($course_id) || ! $course_id) { |
|
| 1351 | 1351 | return; |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | - $course = get_post( $course_id ); |
|
| 1354 | + $course = get_post($course_id); |
|
| 1355 | 1355 | |
| 1356 | - $lesson_update_args= array( |
|
| 1357 | - 'ID' => $lesson_id , |
|
| 1356 | + $lesson_update_args = array( |
|
| 1357 | + 'ID' => $lesson_id, |
|
| 1358 | 1358 | 'post_author' => $course->post_author |
| 1359 | 1359 | ); |
| 1360 | - wp_update_post( $lesson_update_args ); |
|
| 1360 | + wp_update_post($lesson_update_args); |
|
| 1361 | 1361 | |
| 1362 | 1362 | } // end update_lesson_teacher |
| 1363 | 1363 | |
@@ -1371,21 +1371,21 @@ discard block |
||
| 1371 | 1371 | * @parameters array $wp_query |
| 1372 | 1372 | * @return WP_Query $wp_query |
| 1373 | 1373 | */ |
| 1374 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1374 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
| 1375 | 1375 | global $current_user; |
| 1376 | 1376 | |
| 1377 | 1377 | //exit early |
| 1378 | - if( ! $this->is_admin_teacher() ){ |
|
| 1378 | + if ( ! $this->is_admin_teacher()) { |
|
| 1379 | 1379 | return $wp_query; |
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1382 | + if ( ! function_exists('get_current_screen')) { |
|
| 1383 | 1383 | return $wp_query; |
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | $screen = get_current_screen(); |
| 1387 | 1387 | |
| 1388 | - if( empty( $screen ) ){ |
|
| 1388 | + if (empty($screen)) { |
|
| 1389 | 1389 | return $wp_query; |
| 1390 | 1390 | } |
| 1391 | 1391 | |
@@ -1398,10 +1398,10 @@ discard block |
||
| 1398 | 1398 | 'lesson_page_lesson-order', |
| 1399 | 1399 | ); |
| 1400 | 1400 | |
| 1401 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1401 | + if (in_array($screen->id, $limit_screens)) { |
|
| 1402 | 1402 | |
| 1403 | 1403 | // set the query author to the current user to only show those those posts |
| 1404 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1404 | + $wp_query->set('author', $current_user->ID); |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | return $wp_query; |
@@ -1421,7 +1421,7 @@ discard block |
||
| 1421 | 1421 | * @return void |
| 1422 | 1422 | */ |
| 1423 | 1423 | |
| 1424 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1424 | + public function teacher_login_redirect($user_login, $user) { |
|
| 1425 | 1425 | |
| 1426 | 1426 | if (user_can($user, 'edit_courses')) { |
| 1427 | 1427 | |
@@ -1471,9 +1471,9 @@ discard block |
||
| 1471 | 1471 | * @param bool $restrict default true |
| 1472 | 1472 | */ |
| 1473 | 1473 | |
| 1474 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1474 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
| 1475 | 1475 | |
| 1476 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1476 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
| 1477 | 1477 | |
| 1478 | 1478 | remove_menu_page('edit.php'); |
| 1479 | 1479 | |
@@ -1503,11 +1503,11 @@ discard block |
||
| 1503 | 1503 | * @return WP_Comment_Query $clauses |
| 1504 | 1504 | */ |
| 1505 | 1505 | |
| 1506 | - public function restrict_comment_moderation ( $clauses ) { |
|
| 1506 | + public function restrict_comment_moderation($clauses) { |
|
| 1507 | 1507 | |
| 1508 | 1508 | global $pagenow; |
| 1509 | 1509 | |
| 1510 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1510 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
| 1511 | 1511 | |
| 1512 | 1512 | $clauses->query_vars['post_author'] = get_current_user_id(); |
| 1513 | 1513 | |
@@ -1524,15 +1524,15 @@ discard block |
||
| 1524 | 1524 | * |
| 1525 | 1525 | * @return bool |
| 1526 | 1526 | */ |
| 1527 | - public static function is_a_teacher( $user_id ){ |
|
| 1527 | + public static function is_a_teacher($user_id) { |
|
| 1528 | 1528 | |
| 1529 | 1529 | $user = get_user_by('id', $user_id); |
| 1530 | 1530 | |
| 1531 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1531 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
| 1532 | 1532 | |
| 1533 | 1533 | return true; |
| 1534 | 1534 | |
| 1535 | - }else{ |
|
| 1535 | + } else { |
|
| 1536 | 1536 | |
| 1537 | 1537 | return false; |
| 1538 | 1538 | |
@@ -1545,14 +1545,14 @@ discard block |
||
| 1545 | 1545 | * |
| 1546 | 1546 | * @since 1.9.0 |
| 1547 | 1547 | */ |
| 1548 | - public static function archive_title(){ |
|
| 1548 | + public static function archive_title() { |
|
| 1549 | 1549 | |
| 1550 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1550 | + $author = get_user_by('id', get_query_var('author')); |
|
| 1551 | 1551 | $author_name = $author->display_name; |
| 1552 | 1552 | ?> |
| 1553 | 1553 | <h2 class="teacher-archive-title"> |
| 1554 | 1554 | |
| 1555 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
| 1555 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
| 1556 | 1556 | |
| 1557 | 1557 | </h2> |
| 1558 | 1558 | <?php |
@@ -1564,9 +1564,9 @@ discard block |
||
| 1564 | 1564 | * |
| 1565 | 1565 | * @since 1.9.0 |
| 1566 | 1566 | */ |
| 1567 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1567 | + public static function remove_course_meta_on_teacher_archive() { |
|
| 1568 | 1568 | |
| 1569 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1569 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
| 1570 | 1570 | |
| 1571 | 1571 | } |
| 1572 | 1572 | |