@@ -12,251 +12,251 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Sensei_Teacher { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * $teacher_role |
|
| 17 | - * |
|
| 18 | - * Keeps a reference to the teacher role object |
|
| 19 | - * |
|
| 20 | - * @access protected |
|
| 21 | - * @since 1.8.0 |
|
| 22 | - */ |
|
| 23 | - protected $teacher_role; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * $token |
|
| 27 | - * |
|
| 28 | - * Keeps a reference to the global sensei token |
|
| 29 | - * |
|
| 30 | - * @access protected |
|
| 31 | - * @since 1.8.0 |
|
| 32 | - */ |
|
| 33 | - public $token; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Sensei_Teacher::__constructor |
|
| 37 | - * |
|
| 38 | - * Constructor Function |
|
| 39 | - * |
|
| 40 | - * @since 1.8.0 |
|
| 41 | - * @access public |
|
| 42 | - */ |
|
| 43 | - public function __construct ( ) { |
|
| 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 ); |
|
| 50 | - |
|
| 51 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 52 | - |
|
| 53 | - //filter the quiz submissions |
|
| 54 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 55 | - |
|
| 56 | - //grading totals count only those belonging to the teacher |
|
| 57 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 58 | - |
|
| 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' ) ); |
|
| 61 | - |
|
| 62 | - // notify admin when a teacher creates a course |
|
| 63 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 64 | - |
|
| 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 ); |
|
| 67 | - |
|
| 68 | - // give teacher access to question post type |
|
| 69 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 70 | - |
|
| 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 ); |
|
| 74 | - |
|
| 75 | - //admin edit messages query limit teacher |
|
| 76 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 77 | - |
|
| 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' ) ); |
|
| 81 | - |
|
| 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 ); |
|
| 85 | - |
|
| 86 | - // update lesson owner to course teacher when saved |
|
| 87 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 88 | - |
|
| 89 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
| 90 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 91 | - |
|
| 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); |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - } // end __constructor() |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Sensei_Teacher::create_teacher_role |
|
| 101 | - * |
|
| 102 | - * This function checks if the role exist, if not it creates it. |
|
| 103 | - * for the teacher role |
|
| 104 | - * |
|
| 105 | - * @since 1.8.0 |
|
| 106 | - * @access public |
|
| 107 | - * @return void |
|
| 108 | - */ |
|
| 109 | - public function create_role ( ) { |
|
| 110 | - |
|
| 111 | - // check if the role exists |
|
| 112 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 113 | - |
|
| 114 | - // if the the teacher is not a valid WordPress role create it |
|
| 115 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 116 | - // create the role |
|
| 117 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // add the capabilities before returning |
|
| 121 | - $this->add_capabilities(); |
|
| 122 | - |
|
| 123 | - }// end create_teacher_role |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Sensei_Teacher::add_capabilities |
|
| 127 | - * |
|
| 128 | - * @since 1.8.0 |
|
| 129 | - * @access protected |
|
| 130 | - */ |
|
| 131 | - protected function add_capabilities ( ) { |
|
| 132 | - |
|
| 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 ) ) { |
|
| 135 | - return; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Sensei teachers capabilities array filter |
|
| 140 | - * |
|
| 141 | - * These capabilities will be applied to the teacher role |
|
| 142 | - * @param array $capabilities |
|
| 143 | - * keys: (string) $cap_name => (bool) $grant |
|
| 144 | - */ |
|
| 145 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 146 | - // General access rules |
|
| 147 | - 'read' => true, |
|
| 148 | - 'manage_sensei_grades' => true, |
|
| 149 | - 'moderate_comments'=> true, |
|
| 150 | - 'upload_files' => true, |
|
| 151 | - 'edit_files' => true, |
|
| 152 | - |
|
| 153 | - //Lessons |
|
| 154 | - 'publish_lessons' => true, |
|
| 155 | - 'manage_lesson_categories' => true, |
|
| 156 | - 'edit_lessons' => true, |
|
| 157 | - 'edit_published_lessons' => true, |
|
| 158 | - 'edit_private_lessons' => true, |
|
| 159 | - 'read_private_lessons' => true, |
|
| 160 | - 'delete_published_lessons' => true, |
|
| 161 | - |
|
| 162 | - // Courses |
|
| 163 | - 'create_courses' => true, |
|
| 164 | - 'publish_courses' => false, |
|
| 165 | - 'manage_course_categories' => true, |
|
| 166 | - 'edit_courses' => true, |
|
| 167 | - 'edit_published_courses' => true, |
|
| 168 | - 'edit_private_courses' => true, |
|
| 169 | - 'read_private_courses' => true, |
|
| 170 | - 'delete_published_courses' => true, |
|
| 171 | - |
|
| 172 | - // Quiz |
|
| 173 | - 'publish_quizzes' => true, |
|
| 174 | - 'edit_quizzes' => true, |
|
| 175 | - 'edit_published_quizzes' => true, |
|
| 176 | - 'edit_private_quizzes' => true, |
|
| 177 | - 'read_private_quizzes' => true, |
|
| 178 | - |
|
| 179 | - // Questions |
|
| 180 | - 'publish_questions' => true, |
|
| 181 | - 'edit_questions' => true, |
|
| 182 | - 'edit_published_questions' => true, |
|
| 183 | - 'edit_private_questions' => true, |
|
| 184 | - 'read_private_questions' => true, |
|
| 185 | - |
|
| 186 | - //messages |
|
| 187 | - 'publish_sensei_messages' => true, |
|
| 188 | - 'edit_sensei_messages' => true, |
|
| 189 | - 'edit_published_sensei_messages' => true, |
|
| 190 | - 'edit_private_sensei_messages' => true, |
|
| 191 | - 'read_private_sensei_messages' => true, |
|
| 192 | - |
|
| 193 | - // Comments - |
|
| 194 | - // Necessary cap so Teachers can moderate comments |
|
| 195 | - // on their own lessons. We restrict access to other |
|
| 196 | - // post types in $this->restrict_posts_menu_page() |
|
| 197 | - |
|
| 198 | - 'edit_posts' => true, |
|
| 199 | - |
|
| 200 | - )); |
|
| 201 | - |
|
| 202 | - foreach ( $caps as $cap => $grant ) { |
|
| 203 | - |
|
| 204 | - // load the capability on to the teacher role |
|
| 205 | - $this->teacher_role->add_cap($cap, $grant); |
|
| 206 | - |
|
| 207 | - } // end for each |
|
| 208 | - |
|
| 209 | - }// end add_cap |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Sensei_Teacher::teacher_meta_box |
|
| 213 | - * |
|
| 214 | - * Add the teacher metabox to the course post type edit screen |
|
| 215 | - * |
|
| 216 | - * @since 1.8.0 |
|
| 217 | - * @access public |
|
| 218 | - * @parameter string $post_type |
|
| 219 | - * @parameter WP_Post $post |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 223 | - |
|
| 224 | - if( !current_user_can('manage_options') ){ |
|
| 225 | - return; |
|
| 226 | - } |
|
| 227 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 228 | - 'course', |
|
| 229 | - 'side', |
|
| 230 | - 'core' |
|
| 231 | - ); |
|
| 232 | - |
|
| 233 | - } // end teacher_meta_box() |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Sensei_Teacher::teacher_meta_box_content |
|
| 237 | - * |
|
| 238 | - * Render the teacher meta box markup |
|
| 239 | - * |
|
| 240 | - * @since 1.8.0 |
|
| 241 | - * @access public |
|
| 242 | - * @parameters |
|
| 243 | - */ |
|
| 244 | - public function teacher_meta_box_content ( $post ) { |
|
| 245 | - |
|
| 246 | - // get the current author |
|
| 247 | - $current_author = $post->post_author; |
|
| 248 | - |
|
| 249 | - //get the users authorised to author courses |
|
| 250 | - $users = $this->get_teachers_and_authors(); |
|
| 251 | - |
|
| 252 | - ?> |
|
| 15 | + /** |
|
| 16 | + * $teacher_role |
|
| 17 | + * |
|
| 18 | + * Keeps a reference to the teacher role object |
|
| 19 | + * |
|
| 20 | + * @access protected |
|
| 21 | + * @since 1.8.0 |
|
| 22 | + */ |
|
| 23 | + protected $teacher_role; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * $token |
|
| 27 | + * |
|
| 28 | + * Keeps a reference to the global sensei token |
|
| 29 | + * |
|
| 30 | + * @access protected |
|
| 31 | + * @since 1.8.0 |
|
| 32 | + */ |
|
| 33 | + public $token; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Sensei_Teacher::__constructor |
|
| 37 | + * |
|
| 38 | + * Constructor Function |
|
| 39 | + * |
|
| 40 | + * @since 1.8.0 |
|
| 41 | + * @access public |
|
| 42 | + */ |
|
| 43 | + public function __construct ( ) { |
|
| 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 ); |
|
| 50 | + |
|
| 51 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 52 | + |
|
| 53 | + //filter the quiz submissions |
|
| 54 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 55 | + |
|
| 56 | + //grading totals count only those belonging to the teacher |
|
| 57 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 58 | + |
|
| 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' ) ); |
|
| 61 | + |
|
| 62 | + // notify admin when a teacher creates a course |
|
| 63 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 64 | + |
|
| 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 ); |
|
| 67 | + |
|
| 68 | + // give teacher access to question post type |
|
| 69 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 70 | + |
|
| 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 ); |
|
| 74 | + |
|
| 75 | + //admin edit messages query limit teacher |
|
| 76 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 77 | + |
|
| 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' ) ); |
|
| 81 | + |
|
| 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 ); |
|
| 85 | + |
|
| 86 | + // update lesson owner to course teacher when saved |
|
| 87 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 88 | + |
|
| 89 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
| 90 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 91 | + |
|
| 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); |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + } // end __constructor() |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Sensei_Teacher::create_teacher_role |
|
| 101 | + * |
|
| 102 | + * This function checks if the role exist, if not it creates it. |
|
| 103 | + * for the teacher role |
|
| 104 | + * |
|
| 105 | + * @since 1.8.0 |
|
| 106 | + * @access public |
|
| 107 | + * @return void |
|
| 108 | + */ |
|
| 109 | + public function create_role ( ) { |
|
| 110 | + |
|
| 111 | + // check if the role exists |
|
| 112 | + $this->teacher_role = get_role( 'teacher' ); |
|
| 113 | + |
|
| 114 | + // if the the teacher is not a valid WordPress role create it |
|
| 115 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 116 | + // create the role |
|
| 117 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // add the capabilities before returning |
|
| 121 | + $this->add_capabilities(); |
|
| 122 | + |
|
| 123 | + }// end create_teacher_role |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Sensei_Teacher::add_capabilities |
|
| 127 | + * |
|
| 128 | + * @since 1.8.0 |
|
| 129 | + * @access protected |
|
| 130 | + */ |
|
| 131 | + protected function add_capabilities ( ) { |
|
| 132 | + |
|
| 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 ) ) { |
|
| 135 | + return; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Sensei teachers capabilities array filter |
|
| 140 | + * |
|
| 141 | + * These capabilities will be applied to the teacher role |
|
| 142 | + * @param array $capabilities |
|
| 143 | + * keys: (string) $cap_name => (bool) $grant |
|
| 144 | + */ |
|
| 145 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 146 | + // General access rules |
|
| 147 | + 'read' => true, |
|
| 148 | + 'manage_sensei_grades' => true, |
|
| 149 | + 'moderate_comments'=> true, |
|
| 150 | + 'upload_files' => true, |
|
| 151 | + 'edit_files' => true, |
|
| 152 | + |
|
| 153 | + //Lessons |
|
| 154 | + 'publish_lessons' => true, |
|
| 155 | + 'manage_lesson_categories' => true, |
|
| 156 | + 'edit_lessons' => true, |
|
| 157 | + 'edit_published_lessons' => true, |
|
| 158 | + 'edit_private_lessons' => true, |
|
| 159 | + 'read_private_lessons' => true, |
|
| 160 | + 'delete_published_lessons' => true, |
|
| 161 | + |
|
| 162 | + // Courses |
|
| 163 | + 'create_courses' => true, |
|
| 164 | + 'publish_courses' => false, |
|
| 165 | + 'manage_course_categories' => true, |
|
| 166 | + 'edit_courses' => true, |
|
| 167 | + 'edit_published_courses' => true, |
|
| 168 | + 'edit_private_courses' => true, |
|
| 169 | + 'read_private_courses' => true, |
|
| 170 | + 'delete_published_courses' => true, |
|
| 171 | + |
|
| 172 | + // Quiz |
|
| 173 | + 'publish_quizzes' => true, |
|
| 174 | + 'edit_quizzes' => true, |
|
| 175 | + 'edit_published_quizzes' => true, |
|
| 176 | + 'edit_private_quizzes' => true, |
|
| 177 | + 'read_private_quizzes' => true, |
|
| 178 | + |
|
| 179 | + // Questions |
|
| 180 | + 'publish_questions' => true, |
|
| 181 | + 'edit_questions' => true, |
|
| 182 | + 'edit_published_questions' => true, |
|
| 183 | + 'edit_private_questions' => true, |
|
| 184 | + 'read_private_questions' => true, |
|
| 185 | + |
|
| 186 | + //messages |
|
| 187 | + 'publish_sensei_messages' => true, |
|
| 188 | + 'edit_sensei_messages' => true, |
|
| 189 | + 'edit_published_sensei_messages' => true, |
|
| 190 | + 'edit_private_sensei_messages' => true, |
|
| 191 | + 'read_private_sensei_messages' => true, |
|
| 192 | + |
|
| 193 | + // Comments - |
|
| 194 | + // Necessary cap so Teachers can moderate comments |
|
| 195 | + // on their own lessons. We restrict access to other |
|
| 196 | + // post types in $this->restrict_posts_menu_page() |
|
| 197 | + |
|
| 198 | + 'edit_posts' => true, |
|
| 199 | + |
|
| 200 | + )); |
|
| 201 | + |
|
| 202 | + foreach ( $caps as $cap => $grant ) { |
|
| 203 | + |
|
| 204 | + // load the capability on to the teacher role |
|
| 205 | + $this->teacher_role->add_cap($cap, $grant); |
|
| 206 | + |
|
| 207 | + } // end for each |
|
| 208 | + |
|
| 209 | + }// end add_cap |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Sensei_Teacher::teacher_meta_box |
|
| 213 | + * |
|
| 214 | + * Add the teacher metabox to the course post type edit screen |
|
| 215 | + * |
|
| 216 | + * @since 1.8.0 |
|
| 217 | + * @access public |
|
| 218 | + * @parameter string $post_type |
|
| 219 | + * @parameter WP_Post $post |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + public function add_teacher_meta_boxes ( $post ) { |
|
| 223 | + |
|
| 224 | + if( !current_user_can('manage_options') ){ |
|
| 225 | + return; |
|
| 226 | + } |
|
| 227 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 228 | + 'course', |
|
| 229 | + 'side', |
|
| 230 | + 'core' |
|
| 231 | + ); |
|
| 232 | + |
|
| 233 | + } // end teacher_meta_box() |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Sensei_Teacher::teacher_meta_box_content |
|
| 237 | + * |
|
| 238 | + * Render the teacher meta box markup |
|
| 239 | + * |
|
| 240 | + * @since 1.8.0 |
|
| 241 | + * @access public |
|
| 242 | + * @parameters |
|
| 243 | + */ |
|
| 244 | + public function teacher_meta_box_content ( $post ) { |
|
| 245 | + |
|
| 246 | + // get the current author |
|
| 247 | + $current_author = $post->post_author; |
|
| 248 | + |
|
| 249 | + //get the users authorised to author courses |
|
| 250 | + $users = $this->get_teachers_and_authors(); |
|
| 251 | + |
|
| 252 | + ?> |
|
| 253 | 253 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 254 | 254 | |
| 255 | 255 | <?php foreach ( $users as $user_id ) { ?> |
| 256 | 256 | |
| 257 | 257 | <?php |
| 258 | - $user = get_user_by('id', $user_id); |
|
| 259 | - ?> |
|
| 258 | + $user = get_user_by('id', $user_id); |
|
| 259 | + ?> |
|
| 260 | 260 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
| 261 | 261 | <?php echo $user->display_name; ?> |
| 262 | 262 | </option> |
@@ -267,1289 +267,1289 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | <?php |
| 269 | 269 | |
| 270 | - } // end render_teacher_meta_box() |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Sensei_Teacher::get_teachers_and_authors |
|
| 274 | - * |
|
| 275 | - * Get a list of users who can author courses, lessons and quizes. |
|
| 276 | - * |
|
| 277 | - * @since 1.8.0 |
|
| 278 | - * @access public |
|
| 279 | - * @parameters |
|
| 280 | - * @return array $users user id array |
|
| 281 | - */ |
|
| 282 | - public function get_teachers_and_authors ( ){ |
|
| 283 | - |
|
| 284 | - $author_query_args = array( |
|
| 285 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 286 | - 'fields' => 'any', |
|
| 287 | - 'who' => 'authors' |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - $authors = get_users( $author_query_args ); |
|
| 291 | - |
|
| 292 | - $teacher_query_args = array( |
|
| 293 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 294 | - 'fields' => 'any', |
|
| 295 | - 'role' => 'teacher', |
|
| 296 | - ); |
|
| 297 | - |
|
| 298 | - $teachers = get_users( $teacher_query_args ); |
|
| 299 | - |
|
| 300 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 301 | - |
|
| 302 | - }// end get_teachers_and_authors |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Sensei_Teacher::save_teacher_meta_box |
|
| 306 | - * |
|
| 307 | - * Save the new teacher / author to course and all lessons |
|
| 308 | - * |
|
| 309 | - * Hooked into admin_init |
|
| 310 | - * |
|
| 311 | - * @since 1.8.0 |
|
| 312 | - * @access public |
|
| 313 | - * @parameters |
|
| 314 | - * @return array $users user id array |
|
| 315 | - */ |
|
| 316 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 270 | + } // end render_teacher_meta_box() |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Sensei_Teacher::get_teachers_and_authors |
|
| 274 | + * |
|
| 275 | + * Get a list of users who can author courses, lessons and quizes. |
|
| 276 | + * |
|
| 277 | + * @since 1.8.0 |
|
| 278 | + * @access public |
|
| 279 | + * @parameters |
|
| 280 | + * @return array $users user id array |
|
| 281 | + */ |
|
| 282 | + public function get_teachers_and_authors ( ){ |
|
| 283 | + |
|
| 284 | + $author_query_args = array( |
|
| 285 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 286 | + 'fields' => 'any', |
|
| 287 | + 'who' => 'authors' |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + $authors = get_users( $author_query_args ); |
|
| 291 | + |
|
| 292 | + $teacher_query_args = array( |
|
| 293 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 294 | + 'fields' => 'any', |
|
| 295 | + 'role' => 'teacher', |
|
| 296 | + ); |
|
| 297 | + |
|
| 298 | + $teachers = get_users( $teacher_query_args ); |
|
| 299 | + |
|
| 300 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
| 301 | + |
|
| 302 | + }// end get_teachers_and_authors |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Sensei_Teacher::save_teacher_meta_box |
|
| 306 | + * |
|
| 307 | + * Save the new teacher / author to course and all lessons |
|
| 308 | + * |
|
| 309 | + * Hooked into admin_init |
|
| 310 | + * |
|
| 311 | + * @since 1.8.0 |
|
| 312 | + * @access public |
|
| 313 | + * @parameters |
|
| 314 | + * @return array $users user id array |
|
| 315 | + */ |
|
| 316 | + public function save_teacher_meta_box ( $course_id ){ |
|
| 317 | 317 | |
| 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'] ) ){ |
|
| 320 | - return; |
|
| 321 | - } |
|
| 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'] ) ){ |
|
| 320 | + return; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - //don't fire this hook again |
|
| 324 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 323 | + //don't fire this hook again |
|
| 324 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 325 | 325 | |
| 326 | - // get the current post object |
|
| 327 | - $post = get_post( $course_id ); |
|
| 326 | + // get the current post object |
|
| 327 | + $post = get_post( $course_id ); |
|
| 328 | 328 | |
| 329 | - // get the current teacher/author |
|
| 330 | - $current_author = absint( $post->post_author ); |
|
| 331 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 329 | + // get the current teacher/author |
|
| 330 | + $current_author = absint( $post->post_author ); |
|
| 331 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 332 | 332 | |
| 333 | - // loop through all post lessons to update their authors as well |
|
| 334 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 333 | + // loop through all post lessons to update their authors as well |
|
| 334 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 335 | 335 | |
| 336 | - // do not do any processing if the selected author is the same as the current author |
|
| 337 | - if( $current_author == $new_author ){ |
|
| 338 | - return; |
|
| 339 | - } |
|
| 336 | + // do not do any processing if the selected author is the same as the current author |
|
| 337 | + if( $current_author == $new_author ){ |
|
| 338 | + return; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - // save the course author |
|
| 342 | - $post_updates = array( |
|
| 343 | - 'ID' => $post->ID , |
|
| 344 | - 'post_author' => $new_author |
|
| 345 | - ); |
|
| 346 | - wp_update_post( $post_updates ); |
|
| 341 | + // save the course author |
|
| 342 | + $post_updates = array( |
|
| 343 | + 'ID' => $post->ID , |
|
| 344 | + 'post_author' => $new_author |
|
| 345 | + ); |
|
| 346 | + wp_update_post( $post_updates ); |
|
| 347 | 347 | |
| 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 ); |
|
| 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 ); |
|
| 350 | 350 | |
| 351 | - // notify the new teacher |
|
| 352 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 351 | + // notify the new teacher |
|
| 352 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 353 | 353 | |
| 354 | - } // end save_teacher_meta_box |
|
| 354 | + } // end save_teacher_meta_box |
|
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 358 | - * the new author. Making sure the course terms are maintained. |
|
| 359 | - * |
|
| 360 | - * This function also checks if terms are shared, with other courses |
|
| 361 | - * |
|
| 362 | - * @param $course_id |
|
| 363 | - * @param $new_teacher_id |
|
| 364 | - * @return void |
|
| 365 | - */ |
|
| 366 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 356 | + /** |
|
| 357 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 358 | + * the new author. Making sure the course terms are maintained. |
|
| 359 | + * |
|
| 360 | + * This function also checks if terms are shared, with other courses |
|
| 361 | + * |
|
| 362 | + * @param $course_id |
|
| 363 | + * @param $new_teacher_id |
|
| 364 | + * @return void |
|
| 365 | + */ |
|
| 366 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 367 | 367 | |
| 368 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 369 | - return; |
|
| 370 | - } |
|
| 368 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 369 | + return; |
|
| 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 ) ){ |
|
| 375 | - return; |
|
| 376 | - } |
|
| 374 | + if( empty( $terms_selected_on_course ) ){ |
|
| 375 | + return; |
|
| 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 | - $new_term = ''; |
|
| 383 | + $new_term = ''; |
|
| 384 | 384 | |
| 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' ) ){ |
|
| 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' ) ){ |
|
| 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 ) ){ |
|
| 392 | - // insert it even if it exists |
|
| 393 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 394 | - } |
|
| 395 | - } |
|
| 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 | + // insert it even if it exists |
|
| 393 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | - if( empty ( $new_term ) ){ |
|
| 397 | + if( empty ( $new_term ) ){ |
|
| 398 | 398 | |
| 399 | - //setup the new slug |
|
| 400 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 401 | - |
|
| 402 | - // create new term and set it |
|
| 403 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 404 | - |
|
| 405 | - } |
|
| 399 | + //setup the new slug |
|
| 400 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 401 | + |
|
| 402 | + // create new term and set it |
|
| 403 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 404 | + |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | 407 | |
| 408 | 408 | |
| 409 | - // if term exists |
|
| 410 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 409 | + // if 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'); |
|
| 413 | - $term_id = $existing_term->term_id; |
|
| 412 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 413 | + $term_id = $existing_term->term_id; |
|
| 414 | 414 | |
| 415 | - }else{ |
|
| 415 | + }else{ |
|
| 416 | 416 | |
| 417 | - // for a new term simply get the term from the returned value |
|
| 418 | - $term_id = $new_term['term_id']; |
|
| 417 | + // for a new term simply get the term from the returned value |
|
| 418 | + $term_id = $new_term['term_id']; |
|
| 419 | 419 | |
| 420 | - } // end if term exist |
|
| 420 | + } // end if term exist |
|
| 421 | 421 | |
| 422 | - // set the terms selected on the course |
|
| 423 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 422 | + // set the terms selected on the course |
|
| 423 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 424 | 424 | |
| 425 | - // remove old term |
|
| 426 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 425 | + // remove old term |
|
| 426 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 427 | 427 | |
| 428 | - // update the lessons within the current module term |
|
| 429 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 430 | - foreach( $lessons as $lesson ){ |
|
| 428 | + // update the lessons within the current module term |
|
| 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 | - // add the new term, the false at the end says to replace all terms on this module |
|
| 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 ); |
|
| 438 | - } |
|
| 434 | + // add the new term, the false at the end says to replace all terms on this module |
|
| 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 ); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - }// end for each |
|
| 440 | + }// end for each |
|
| 441 | 441 | |
| 442 | - } |
|
| 443 | - } |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - }// end update_course_module_terms_author |
|
| 445 | + }// end update_course_module_terms_author |
|
| 446 | 446 | |
| 447 | - /** |
|
| 448 | - * Sensei_Teacher::update_course_lessons_author |
|
| 449 | - * |
|
| 450 | - * Update all course lessons and their quiz with a new author |
|
| 451 | - * |
|
| 452 | - * @since 1.8.0 |
|
| 453 | - * @access public |
|
| 454 | - * @parameters |
|
| 455 | - * @return array $users user id array |
|
| 456 | - */ |
|
| 457 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 447 | + /** |
|
| 448 | + * Sensei_Teacher::update_course_lessons_author |
|
| 449 | + * |
|
| 450 | + * Update all course lessons and their quiz with a new author |
|
| 451 | + * |
|
| 452 | + * @since 1.8.0 |
|
| 453 | + * @access public |
|
| 454 | + * @parameters |
|
| 455 | + * @return array $users user id array |
|
| 456 | + */ |
|
| 457 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 458 | 458 | |
| 459 | 459 | |
| 460 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 460 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - //get a list of course lessons |
|
| 465 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 464 | + //get a list of course lessons |
|
| 465 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 466 | 466 | |
| 467 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 468 | - return false; |
|
| 469 | - } |
|
| 467 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 470 | 470 | |
| 471 | - // update each lesson and quiz author |
|
| 472 | - foreach( $lessons as $lesson ){ |
|
| 471 | + // update each lesson and quiz author |
|
| 472 | + foreach( $lessons as $lesson ){ |
|
| 473 | 473 | |
| 474 | - // don't update if the author is tha same as the new author |
|
| 475 | - if( $new_author == $lesson->post_author ){ |
|
| 476 | - continue; |
|
| 477 | - } |
|
| 474 | + // don't update if the author is tha same as the new author |
|
| 475 | + if( $new_author == $lesson->post_author ){ |
|
| 476 | + continue; |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - // update lesson author |
|
| 480 | - wp_update_post( array( |
|
| 481 | - 'ID'=> $lesson->ID, |
|
| 482 | - 'post_author' => $new_author |
|
| 483 | - ) ); |
|
| 479 | + // update lesson author |
|
| 480 | + wp_update_post( array( |
|
| 481 | + 'ID'=> $lesson->ID, |
|
| 482 | + 'post_author' => $new_author |
|
| 483 | + ) ); |
|
| 484 | 484 | |
| 485 | - // update quiz author |
|
| 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 ) { |
|
| 490 | - // update quiz with new author |
|
| 491 | - wp_update_post( array( |
|
| 492 | - 'ID' => $quiz_id, |
|
| 493 | - 'post_author' => $new_author |
|
| 494 | - ) ); |
|
| 495 | - } |
|
| 496 | - }else{ |
|
| 497 | - wp_update_post( array( |
|
| 498 | - 'ID' => $lesson_quizzes, |
|
| 499 | - 'post_author' => $new_author |
|
| 500 | - ) ); |
|
| 501 | - } |
|
| 485 | + // update quiz author |
|
| 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 ) { |
|
| 490 | + // update quiz with new author |
|
| 491 | + wp_update_post( array( |
|
| 492 | + 'ID' => $quiz_id, |
|
| 493 | + 'post_author' => $new_author |
|
| 494 | + ) ); |
|
| 495 | + } |
|
| 496 | + }else{ |
|
| 497 | + wp_update_post( array( |
|
| 498 | + 'ID' => $lesson_quizzes, |
|
| 499 | + 'post_author' => $new_author |
|
| 500 | + ) ); |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - } // end for each lessons |
|
| 503 | + } // end for each lessons |
|
| 504 | 504 | |
| 505 | - return true; |
|
| 505 | + return true; |
|
| 506 | 506 | |
| 507 | - }// end update_course_lessons_author |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 513 | - * |
|
| 514 | - * Alter the query so that users can only see their courses on the analysis page |
|
| 515 | - * |
|
| 516 | - * @since 1.8.0 |
|
| 517 | - * @access public |
|
| 518 | - * @parameters $query |
|
| 519 | - * @return array $users user id array |
|
| 520 | - */ |
|
| 521 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 522 | - |
|
| 523 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 524 | - return $query; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 528 | - return $query; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $screen = get_current_screen(); |
|
| 532 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 533 | - |
|
| 534 | - // exit early for the following conditions |
|
| 535 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 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 ) ){ |
|
| 539 | - return $query; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - global $current_user; |
|
| 543 | - // set the query author to the current user to only show those those posts |
|
| 544 | - $query->set( 'author', $current_user->ID ); |
|
| 545 | - return $query; |
|
| 546 | - |
|
| 547 | - }// end course_analysis_teacher_access_limit |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 552 | - * |
|
| 553 | - * Determine if we're in admin and the current logged in use is a teacher |
|
| 554 | - * |
|
| 555 | - * @since 1.8.0 |
|
| 556 | - * @access public |
|
| 557 | - * @parameters array $wp_query |
|
| 558 | - * @return bool $is_admin_teacher |
|
| 559 | - */ |
|
| 560 | - public function is_admin_teacher ( ){ |
|
| 561 | - |
|
| 562 | - if( ! is_user_logged_in()){ |
|
| 563 | - return false; |
|
| 564 | - } |
|
| 565 | - $is_admin_teacher = false; |
|
| 566 | - |
|
| 567 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 568 | - |
|
| 569 | - $is_admin_teacher = true; |
|
| 570 | - |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $is_admin_teacher; |
|
| 574 | - |
|
| 575 | - } // end is_admin_teacher |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Show correct post counts on list table for Sensei post types |
|
| 579 | - * |
|
| 580 | - * @since 1.8.0 |
|
| 581 | - * |
|
| 582 | - * @param object $counts Default status counts |
|
| 583 | - * @param string $type Current post type |
|
| 584 | - * @param string $perm User permission level |
|
| 585 | - * @return object Modified status counts |
|
| 586 | - */ |
|
| 587 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 588 | - global $current_user; |
|
| 589 | - |
|
| 590 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 591 | - return $counts; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if( ! $this->is_admin_teacher() ) { |
|
| 595 | - return $counts; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - $args = array( |
|
| 599 | - 'post_type' => $type, |
|
| 600 | - 'author' => $current_user->ID, |
|
| 601 | - 'posts_per_page' => -1 |
|
| 602 | - ); |
|
| 603 | - |
|
| 604 | - // Get all available statuses |
|
| 605 | - $stati = get_post_stati(); |
|
| 606 | - |
|
| 607 | - // Update count object |
|
| 608 | - foreach( $stati as $status ) { |
|
| 609 | - $args['post_status'] = $status; |
|
| 610 | - $posts = get_posts( $args ); |
|
| 611 | - $counts->$status = count( $posts ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - return $counts; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Filter the post queries to show |
|
| 619 | - * only lesson /course and users that belong |
|
| 620 | - * to the current logged teacher. |
|
| 621 | - * |
|
| 622 | - * @since 1.8.0 |
|
| 623 | - * |
|
| 624 | - */ |
|
| 625 | - public function filter_queries ( $query ) { |
|
| 626 | - global $current_user; |
|
| 627 | - |
|
| 628 | - if( ! $this->is_admin_teacher() ) { |
|
| 629 | - return; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 633 | - return; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $screen = get_current_screen(); |
|
| 637 | - if( empty( $screen ) ) { |
|
| 638 | - return $query; |
|
| 639 | - } |
|
| 640 | - switch( $screen->id ) { |
|
| 641 | - case 'sensei_page_sensei_grading': |
|
| 642 | - case 'sensei_page_sensei_analysis': |
|
| 643 | - case 'sensei_page_sensei_learners': |
|
| 644 | - case 'lesson': |
|
| 645 | - case 'course': |
|
| 646 | - case 'question': |
|
| 647 | - case 'lesson_page_module-order': |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * sensei_filter_queries_set_author |
|
| 651 | - * Filter the author Sensei set for queries |
|
| 652 | - * |
|
| 653 | - * @since 1.8.0 |
|
| 654 | - * |
|
| 655 | - * @param int $user_id |
|
| 656 | - * @param string $screen_id |
|
| 657 | - * |
|
| 658 | - */ |
|
| 659 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 660 | - break; |
|
| 661 | - } |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 666 | - * . This excludes the admin user. |
|
| 667 | - * |
|
| 668 | - * @since 1.8.0 |
|
| 669 | - * @hooked into the_comments |
|
| 670 | - * @param array $comments |
|
| 671 | - * |
|
| 672 | - * @return array $comments |
|
| 673 | - */ |
|
| 674 | - public function filter_grading_activity_queries( $comments ){ |
|
| 675 | - |
|
| 676 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 677 | - return $comments ; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - //check if we're on the grading screen |
|
| 681 | - $screen = get_current_screen(); |
|
| 682 | - |
|
| 683 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 684 | - return $comments; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // get the course and determine if the current teacher is the owner |
|
| 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() ) ){ |
|
| 694 | - //remove this as the teacher should see this. |
|
| 695 | - unset( $comments[ $key ] ); |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - return $comments ; |
|
| 699 | - |
|
| 700 | - }// end function filter grading |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Limit the grading screen totals to only show lessons in the course |
|
| 704 | - * belonging to the currently logged in teacher. This only applies to |
|
| 705 | - * the teacher role. |
|
| 706 | - * |
|
| 707 | - * @since 1.8.0 |
|
| 708 | - * |
|
| 709 | - * @hooked into sensei_count_statuses_args |
|
| 710 | - * @param array $args |
|
| 711 | - * |
|
| 712 | - * @return array $args |
|
| 713 | - */ |
|
| 714 | - public function limit_grading_totals( $args ){ |
|
| 715 | - |
|
| 716 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 717 | - return $args ; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - //get the teachers courses |
|
| 721 | - // the query is already filtered to only the teacher |
|
| 722 | - $courses = Sensei()->course->get_all_courses(); |
|
| 723 | - |
|
| 724 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 725 | - return $args; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - //setup the lessons quizzes to limit the grading totals to |
|
| 729 | - $quiz_scope = array(); |
|
| 730 | - foreach( $courses as $course ){ |
|
| 731 | - |
|
| 732 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 733 | - |
|
| 734 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 735 | - |
|
| 736 | - foreach( $course_lessons as $lesson ){ |
|
| 737 | - |
|
| 738 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 739 | - if( !empty( $quiz_id ) ) { |
|
| 740 | - |
|
| 741 | - array_push( $quiz_scope, $quiz_id ); |
|
| 742 | - |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - $args['post__in'] = $quiz_scope; |
|
| 752 | - |
|
| 753 | - return $args; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * It ensures that the author archive shows course by the current user. |
|
| 758 | - * |
|
| 759 | - * This function is hooked into the pre_get_posts filter |
|
| 760 | - * |
|
| 761 | - * @param WP_Query $query |
|
| 762 | - * @return WP_Query $query |
|
| 763 | - */ |
|
| 764 | - public function add_courses_to_author_archive( $query ) { |
|
| 765 | - |
|
| 766 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 767 | - return $query; |
|
| 768 | - } |
|
| 769 | - |
|
| 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 ) ) { |
|
| 773 | - |
|
| 774 | - return $query; |
|
| 775 | - |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - // Change post types depending on what is set already |
|
| 779 | - $current_post_types = $query->get( 'post_type' ); |
|
| 780 | - if( empty( $current_post_types ) ){ |
|
| 781 | - |
|
| 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' ); |
|
| 784 | - |
|
| 785 | - } elseif( is_array( $current_post_types ) ) { |
|
| 786 | - |
|
| 787 | - // merge the post types instead of overwriting it |
|
| 788 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 789 | - |
|
| 790 | - }else{ |
|
| 791 | - |
|
| 792 | - // in this instance it is probably just one post type in string format |
|
| 793 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 794 | - |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - // change the query before returning it |
|
| 798 | - $query->set('post_type', $new_post_types ); |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Change the query on the teacher author archive template |
|
| 802 | - * |
|
| 803 | - * @since 1.8.4 |
|
| 804 | - * @param WP_Query $query |
|
| 805 | - */ |
|
| 806 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 807 | - |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * Notify teacher when someone assigns a course to their account. |
|
| 812 | - * |
|
| 813 | - * @since 1.8.0 |
|
| 814 | - * |
|
| 815 | - * @param $teacher_id |
|
| 816 | - * @param $course_id |
|
| 817 | - * @return bool |
|
| 818 | - */ |
|
| 819 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 820 | - |
|
| 821 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - |
|
| 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() ){ |
|
| 827 | - return true; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - // load the email class |
|
| 831 | - include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
|
| 832 | - $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
|
| 833 | - $email->trigger( $teacher_id, $course_id ); |
|
| 834 | - |
|
| 835 | - return true; |
|
| 836 | - } // end teacher_course_assigned_notification |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Email the admin when a teacher creates a new course |
|
| 840 | - * |
|
| 841 | - * This function hooks into wp_insert_post |
|
| 842 | - * |
|
| 843 | - * @since 1.8.0 |
|
| 844 | - * @param int $course_id |
|
| 845 | - * @return bool |
|
| 846 | - */ |
|
| 847 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 848 | - |
|
| 849 | - $course_id = $post->ID; |
|
| 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 ) ) { |
|
| 853 | - |
|
| 854 | - return false; |
|
| 855 | - |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * Filter the option to send admin notification emails when teachers creation |
|
| 860 | - * course. |
|
| 861 | - * |
|
| 862 | - * @since 1.8.0 |
|
| 863 | - * |
|
| 864 | - * @param bool $on default true |
|
| 865 | - */ |
|
| 866 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 867 | - return false; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - // setting up the data needed by the email template |
|
| 871 | - global $sensei_email_data; |
|
| 872 | - $template = 'admin-teacher-new-course-created'; |
|
| 873 | - $course = get_post( $course_id ); |
|
| 874 | - $teacher = new WP_User( $course->post_author ); |
|
| 875 | - $recipient = get_option('admin_email', true); |
|
| 876 | - |
|
| 877 | - // don't send if the course is created by admin |
|
| 878 | - if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
| 879 | - return false; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
| 884 | - * |
|
| 885 | - * @since 1.8.0 |
|
| 886 | - * @param string $template |
|
| 887 | - */ |
|
| 888 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Filter the email subject for the the |
|
| 892 | - * admin-teacher-new-course-created template |
|
| 893 | - * |
|
| 894 | - * @since 1.8.0 |
|
| 895 | - * @param string $subject default New course assigned to you |
|
| 896 | - * @param string $template |
|
| 897 | - */ |
|
| 898 | - $subject = apply_filters('sensei_email_subject', |
|
| 899 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 900 | - $template ); |
|
| 901 | - |
|
| 902 | - //course edit link |
|
| 903 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 904 | - |
|
| 905 | - // Construct data array |
|
| 906 | - $email_data = array( |
|
| 907 | - 'template' => $template, |
|
| 908 | - 'heading' => $heading, |
|
| 909 | - 'teacher' => $teacher, |
|
| 910 | - 'course_id' => $course_id, |
|
| 911 | - 'course_name' => $course->post_title, |
|
| 912 | - 'course_edit_link' => $course_edit_link, |
|
| 913 | - ); |
|
| 914 | - |
|
| 915 | - /** |
|
| 916 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 917 | - * |
|
| 918 | - * @since 1.8.0 |
|
| 919 | - * @param array $email_data |
|
| 920 | - * @param string $template |
|
| 921 | - */ |
|
| 922 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 923 | - |
|
| 924 | - // Send mail |
|
| 925 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 926 | - |
|
| 927 | - }// end notify admin of course creation |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 931 | - * |
|
| 932 | - * Hooked into sensei_analysis_get_learners |
|
| 933 | - * @param array $args WP_User_Query arguments |
|
| 934 | - * @return array $learners_query_results |
|
| 935 | - */ |
|
| 936 | - public function limit_analysis_learners( $args ){ |
|
| 937 | - |
|
| 938 | - // show default for none teachers |
|
| 939 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 940 | - return $args; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - // for teachers all courses only return those which belong to the teacher |
|
| 944 | - // as they don't have access to course belonging to other users |
|
| 945 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 507 | + }// end update_course_lessons_author |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 513 | + * |
|
| 514 | + * Alter the query so that users can only see their courses on the analysis page |
|
| 515 | + * |
|
| 516 | + * @since 1.8.0 |
|
| 517 | + * @access public |
|
| 518 | + * @parameters $query |
|
| 519 | + * @return array $users user id array |
|
| 520 | + */ |
|
| 521 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
| 522 | + |
|
| 523 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 524 | + return $query; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 528 | + return $query; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $screen = get_current_screen(); |
|
| 532 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 533 | + |
|
| 534 | + // exit early for the following conditions |
|
| 535 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 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 ) ){ |
|
| 539 | + return $query; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + global $current_user; |
|
| 543 | + // set the query author to the current user to only show those those posts |
|
| 544 | + $query->set( 'author', $current_user->ID ); |
|
| 545 | + return $query; |
|
| 546 | + |
|
| 547 | + }// end course_analysis_teacher_access_limit |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 552 | + * |
|
| 553 | + * Determine if we're in admin and the current logged in use is a teacher |
|
| 554 | + * |
|
| 555 | + * @since 1.8.0 |
|
| 556 | + * @access public |
|
| 557 | + * @parameters array $wp_query |
|
| 558 | + * @return bool $is_admin_teacher |
|
| 559 | + */ |
|
| 560 | + public function is_admin_teacher ( ){ |
|
| 561 | + |
|
| 562 | + if( ! is_user_logged_in()){ |
|
| 563 | + return false; |
|
| 564 | + } |
|
| 565 | + $is_admin_teacher = false; |
|
| 566 | + |
|
| 567 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 568 | + |
|
| 569 | + $is_admin_teacher = true; |
|
| 570 | + |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $is_admin_teacher; |
|
| 574 | + |
|
| 575 | + } // end is_admin_teacher |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Show correct post counts on list table for Sensei post types |
|
| 579 | + * |
|
| 580 | + * @since 1.8.0 |
|
| 581 | + * |
|
| 582 | + * @param object $counts Default status counts |
|
| 583 | + * @param string $type Current post type |
|
| 584 | + * @param string $perm User permission level |
|
| 585 | + * @return object Modified status counts |
|
| 586 | + */ |
|
| 587 | + public function list_table_counts( $counts, $type, $perm ) { |
|
| 588 | + global $current_user; |
|
| 589 | + |
|
| 590 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 591 | + return $counts; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if( ! $this->is_admin_teacher() ) { |
|
| 595 | + return $counts; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + $args = array( |
|
| 599 | + 'post_type' => $type, |
|
| 600 | + 'author' => $current_user->ID, |
|
| 601 | + 'posts_per_page' => -1 |
|
| 602 | + ); |
|
| 603 | + |
|
| 604 | + // Get all available statuses |
|
| 605 | + $stati = get_post_stati(); |
|
| 606 | + |
|
| 607 | + // Update count object |
|
| 608 | + foreach( $stati as $status ) { |
|
| 609 | + $args['post_status'] = $status; |
|
| 610 | + $posts = get_posts( $args ); |
|
| 611 | + $counts->$status = count( $posts ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + return $counts; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Filter the post queries to show |
|
| 619 | + * only lesson /course and users that belong |
|
| 620 | + * to the current logged teacher. |
|
| 621 | + * |
|
| 622 | + * @since 1.8.0 |
|
| 623 | + * |
|
| 624 | + */ |
|
| 625 | + public function filter_queries ( $query ) { |
|
| 626 | + global $current_user; |
|
| 627 | + |
|
| 628 | + if( ! $this->is_admin_teacher() ) { |
|
| 629 | + return; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 633 | + return; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $screen = get_current_screen(); |
|
| 637 | + if( empty( $screen ) ) { |
|
| 638 | + return $query; |
|
| 639 | + } |
|
| 640 | + switch( $screen->id ) { |
|
| 641 | + case 'sensei_page_sensei_grading': |
|
| 642 | + case 'sensei_page_sensei_analysis': |
|
| 643 | + case 'sensei_page_sensei_learners': |
|
| 644 | + case 'lesson': |
|
| 645 | + case 'course': |
|
| 646 | + case 'question': |
|
| 647 | + case 'lesson_page_module-order': |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * sensei_filter_queries_set_author |
|
| 651 | + * Filter the author Sensei set for queries |
|
| 652 | + * |
|
| 653 | + * @since 1.8.0 |
|
| 654 | + * |
|
| 655 | + * @param int $user_id |
|
| 656 | + * @param string $screen_id |
|
| 657 | + * |
|
| 658 | + */ |
|
| 659 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 660 | + break; |
|
| 661 | + } |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 666 | + * . This excludes the admin user. |
|
| 667 | + * |
|
| 668 | + * @since 1.8.0 |
|
| 669 | + * @hooked into the_comments |
|
| 670 | + * @param array $comments |
|
| 671 | + * |
|
| 672 | + * @return array $comments |
|
| 673 | + */ |
|
| 674 | + public function filter_grading_activity_queries( $comments ){ |
|
| 675 | + |
|
| 676 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 677 | + return $comments ; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + //check if we're on the grading screen |
|
| 681 | + $screen = get_current_screen(); |
|
| 682 | + |
|
| 683 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 684 | + return $comments; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // get the course and determine if the current teacher is the owner |
|
| 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() ) ){ |
|
| 694 | + //remove this as the teacher should see this. |
|
| 695 | + unset( $comments[ $key ] ); |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + return $comments ; |
|
| 699 | + |
|
| 700 | + }// end function filter grading |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Limit the grading screen totals to only show lessons in the course |
|
| 704 | + * belonging to the currently logged in teacher. This only applies to |
|
| 705 | + * the teacher role. |
|
| 706 | + * |
|
| 707 | + * @since 1.8.0 |
|
| 708 | + * |
|
| 709 | + * @hooked into sensei_count_statuses_args |
|
| 710 | + * @param array $args |
|
| 711 | + * |
|
| 712 | + * @return array $args |
|
| 713 | + */ |
|
| 714 | + public function limit_grading_totals( $args ){ |
|
| 715 | + |
|
| 716 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 717 | + return $args ; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + //get the teachers courses |
|
| 721 | + // the query is already filtered to only the teacher |
|
| 722 | + $courses = Sensei()->course->get_all_courses(); |
|
| 723 | + |
|
| 724 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 725 | + return $args; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + //setup the lessons quizzes to limit the grading totals to |
|
| 729 | + $quiz_scope = array(); |
|
| 730 | + foreach( $courses as $course ){ |
|
| 731 | + |
|
| 732 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 733 | + |
|
| 734 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 735 | + |
|
| 736 | + foreach( $course_lessons as $lesson ){ |
|
| 737 | + |
|
| 738 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 739 | + if( !empty( $quiz_id ) ) { |
|
| 740 | + |
|
| 741 | + array_push( $quiz_scope, $quiz_id ); |
|
| 742 | + |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + $args['post__in'] = $quiz_scope; |
|
| 752 | + |
|
| 753 | + return $args; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * It ensures that the author archive shows course by the current user. |
|
| 758 | + * |
|
| 759 | + * This function is hooked into the pre_get_posts filter |
|
| 760 | + * |
|
| 761 | + * @param WP_Query $query |
|
| 762 | + * @return WP_Query $query |
|
| 763 | + */ |
|
| 764 | + public function add_courses_to_author_archive( $query ) { |
|
| 765 | + |
|
| 766 | + if ( is_admin() || ! $query->is_author() ){ |
|
| 767 | + return $query; |
|
| 768 | + } |
|
| 769 | + |
|
| 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 ) ) { |
|
| 773 | + |
|
| 774 | + return $query; |
|
| 775 | + |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + // Change post types depending on what is set already |
|
| 779 | + $current_post_types = $query->get( 'post_type' ); |
|
| 780 | + if( empty( $current_post_types ) ){ |
|
| 781 | + |
|
| 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' ); |
|
| 784 | + |
|
| 785 | + } elseif( is_array( $current_post_types ) ) { |
|
| 786 | + |
|
| 787 | + // merge the post types instead of overwriting it |
|
| 788 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 789 | + |
|
| 790 | + }else{ |
|
| 791 | + |
|
| 792 | + // in this instance it is probably just one post type in string format |
|
| 793 | + $new_post_types = array( $current_post_types , 'course'); |
|
| 794 | + |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + // change the query before returning it |
|
| 798 | + $query->set('post_type', $new_post_types ); |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Change the query on the teacher author archive template |
|
| 802 | + * |
|
| 803 | + * @since 1.8.4 |
|
| 804 | + * @param WP_Query $query |
|
| 805 | + */ |
|
| 806 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 807 | + |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * Notify teacher when someone assigns a course to their account. |
|
| 812 | + * |
|
| 813 | + * @since 1.8.0 |
|
| 814 | + * |
|
| 815 | + * @param $teacher_id |
|
| 816 | + * @param $course_id |
|
| 817 | + * @return bool |
|
| 818 | + */ |
|
| 819 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 820 | + |
|
| 821 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + |
|
| 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() ){ |
|
| 827 | + return true; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + // load the email class |
|
| 831 | + include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
|
| 832 | + $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
|
| 833 | + $email->trigger( $teacher_id, $course_id ); |
|
| 834 | + |
|
| 835 | + return true; |
|
| 836 | + } // end teacher_course_assigned_notification |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Email the admin when a teacher creates a new course |
|
| 840 | + * |
|
| 841 | + * This function hooks into wp_insert_post |
|
| 842 | + * |
|
| 843 | + * @since 1.8.0 |
|
| 844 | + * @param int $course_id |
|
| 845 | + * @return bool |
|
| 846 | + */ |
|
| 847 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 848 | + |
|
| 849 | + $course_id = $post->ID; |
|
| 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 ) ) { |
|
| 853 | + |
|
| 854 | + return false; |
|
| 855 | + |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Filter the option to send admin notification emails when teachers creation |
|
| 860 | + * course. |
|
| 861 | + * |
|
| 862 | + * @since 1.8.0 |
|
| 863 | + * |
|
| 864 | + * @param bool $on default true |
|
| 865 | + */ |
|
| 866 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 867 | + return false; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + // setting up the data needed by the email template |
|
| 871 | + global $sensei_email_data; |
|
| 872 | + $template = 'admin-teacher-new-course-created'; |
|
| 873 | + $course = get_post( $course_id ); |
|
| 874 | + $teacher = new WP_User( $course->post_author ); |
|
| 875 | + $recipient = get_option('admin_email', true); |
|
| 876 | + |
|
| 877 | + // don't send if the course is created by admin |
|
| 878 | + if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
| 879 | + return false; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
| 884 | + * |
|
| 885 | + * @since 1.8.0 |
|
| 886 | + * @param string $template |
|
| 887 | + */ |
|
| 888 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Filter the email subject for the the |
|
| 892 | + * admin-teacher-new-course-created template |
|
| 893 | + * |
|
| 894 | + * @since 1.8.0 |
|
| 895 | + * @param string $subject default New course assigned to you |
|
| 896 | + * @param string $template |
|
| 897 | + */ |
|
| 898 | + $subject = apply_filters('sensei_email_subject', |
|
| 899 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 900 | + $template ); |
|
| 901 | + |
|
| 902 | + //course edit link |
|
| 903 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 904 | + |
|
| 905 | + // Construct data array |
|
| 906 | + $email_data = array( |
|
| 907 | + 'template' => $template, |
|
| 908 | + 'heading' => $heading, |
|
| 909 | + 'teacher' => $teacher, |
|
| 910 | + 'course_id' => $course_id, |
|
| 911 | + 'course_name' => $course->post_title, |
|
| 912 | + 'course_edit_link' => $course_edit_link, |
|
| 913 | + ); |
|
| 914 | + |
|
| 915 | + /** |
|
| 916 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 917 | + * |
|
| 918 | + * @since 1.8.0 |
|
| 919 | + * @param array $email_data |
|
| 920 | + * @param string $template |
|
| 921 | + */ |
|
| 922 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 923 | + |
|
| 924 | + // Send mail |
|
| 925 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 926 | + |
|
| 927 | + }// end notify admin of course creation |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 931 | + * |
|
| 932 | + * Hooked into sensei_analysis_get_learners |
|
| 933 | + * @param array $args WP_User_Query arguments |
|
| 934 | + * @return array $learners_query_results |
|
| 935 | + */ |
|
| 936 | + public function limit_analysis_learners( $args ){ |
|
| 937 | + |
|
| 938 | + // show default for none teachers |
|
| 939 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 940 | + return $args; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + // for teachers all courses only return those which belong to the teacher |
|
| 944 | + // as they don't have access to course belonging to other users |
|
| 945 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 946 | 946 | |
| 947 | - // if the user has no courses they should see no users |
|
| 948 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 949 | - // tell the query to return 0 students |
|
| 950 | - $args[ 'include'] = array( 0 ); |
|
| 951 | - return $args; |
|
| 952 | - |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - $learner_ids_for_teacher_courses = array(); |
|
| 956 | - foreach( $teacher_courses as $course ){ |
|
| 957 | - |
|
| 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 ); |
|
| 960 | - |
|
| 961 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 962 | - continue; // skip to the next course as there are no users on this course |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - // it could be an array of comments or a single comment |
|
| 966 | - if( is_array( $activity_comments ) ){ |
|
| 947 | + // if the user has no courses they should see no users |
|
| 948 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 949 | + // tell the query to return 0 students |
|
| 950 | + $args[ 'include'] = array( 0 ); |
|
| 951 | + return $args; |
|
| 952 | + |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + $learner_ids_for_teacher_courses = array(); |
|
| 956 | + foreach( $teacher_courses as $course ){ |
|
| 957 | + |
|
| 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 ); |
|
| 960 | + |
|
| 961 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 962 | + continue; // skip to the next course as there are no users on this course |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + // it could be an array of comments or a single comment |
|
| 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 ) ){ |
|
| 973 | - // next comment in this array |
|
| 974 | - continue; |
|
| 975 | - } |
|
| 972 | + if( empty( $user ) ){ |
|
| 973 | + // next comment in this array |
|
| 974 | + continue; |
|
| 975 | + } |
|
| 976 | 976 | |
| 977 | - $course_learner_ids[] = $user->ID; |
|
| 978 | - } |
|
| 977 | + $course_learner_ids[] = $user->ID; |
|
| 978 | + } |
|
| 979 | 979 | |
| 980 | - }else{ |
|
| 980 | + }else{ |
|
| 981 | 981 | |
| 982 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 983 | - $course_learner_ids[] = $user->ID; |
|
| 982 | + $user = get_userdata( $activity_comments->user_id ); |
|
| 983 | + $course_learner_ids[] = $user->ID; |
|
| 984 | 984 | |
| 985 | - } |
|
| 985 | + } |
|
| 986 | 986 | |
| 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 ); |
|
| 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 ); |
|
| 989 | 989 | |
| 990 | - } |
|
| 990 | + } |
|
| 991 | 991 | |
| 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 ) ){ |
|
| 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 ) ){ |
|
| 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 | |
| 1003 | - // return the WP_Use_Query arguments |
|
| 1004 | - return $args; |
|
| 1003 | + // return the WP_Use_Query arguments |
|
| 1004 | + return $args; |
|
| 1005 | 1005 | |
| 1006 | - }// end limit_analysis_learners |
|
| 1006 | + }// end limit_analysis_learners |
|
| 1007 | 1007 | |
| 1008 | - /** |
|
| 1009 | - * Give teacher full admin access to the question post type |
|
| 1010 | - * in certain cases. |
|
| 1011 | - * |
|
| 1012 | - * @since 1.8.0 |
|
| 1013 | - * @param $questions |
|
| 1014 | - * @return mixed |
|
| 1015 | - */ |
|
| 1016 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1008 | + /** |
|
| 1009 | + * Give teacher full admin access to the question post type |
|
| 1010 | + * in certain cases. |
|
| 1011 | + * |
|
| 1012 | + * @since 1.8.0 |
|
| 1013 | + * @param $questions |
|
| 1014 | + * @return mixed |
|
| 1015 | + */ |
|
| 1016 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1017 | 1017 | |
| 1018 | - if( ! $this->is_admin_teacher() ){ |
|
| 1019 | - return $questions; |
|
| 1020 | - } |
|
| 1018 | + if( ! $this->is_admin_teacher() ){ |
|
| 1019 | + return $questions; |
|
| 1020 | + } |
|
| 1021 | 1021 | |
| 1022 | - $screen = get_current_screen(); |
|
| 1022 | + $screen = get_current_screen(); |
|
| 1023 | 1023 | |
| 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 ); |
|
| 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 ); |
|
| 1026 | 1026 | |
| 1027 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1027 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1028 | 1028 | |
| 1029 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1030 | - if( ! empty($admin_user) ){ |
|
| 1029 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1030 | + if( ! empty($admin_user) ){ |
|
| 1031 | 1031 | |
| 1032 | - $current_teacher_id = get_current_user_id(); |
|
| 1032 | + $current_teacher_id = get_current_user_id(); |
|
| 1033 | 1033 | |
| 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 ); |
|
| 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 ); |
|
| 1037 | 1037 | |
| 1038 | - // set the teacher as the current use again |
|
| 1039 | - wp_set_current_user( $current_teacher_id ); |
|
| 1040 | - } |
|
| 1038 | + // set the teacher as the current use again |
|
| 1039 | + wp_set_current_user( $current_teacher_id ); |
|
| 1040 | + } |
|
| 1041 | 1041 | |
| 1042 | - } |
|
| 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 ); |
|
| 1042 | + } |
|
| 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 ); |
|
| 1045 | 1045 | |
| 1046 | - return $questions; |
|
| 1047 | - } |
|
| 1046 | + return $questions; |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | - /** |
|
| 1050 | - * Give the teacher role access to questions from the question bank |
|
| 1051 | - * |
|
| 1052 | - * @since 1.8.0 |
|
| 1053 | - * @param $wp_query |
|
| 1054 | - * @return mixed |
|
| 1055 | - */ |
|
| 1056 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1049 | + /** |
|
| 1050 | + * Give the teacher role access to questions from the question bank |
|
| 1051 | + * |
|
| 1052 | + * @since 1.8.0 |
|
| 1053 | + * @param $wp_query |
|
| 1054 | + * @return mixed |
|
| 1055 | + */ |
|
| 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 | - return $wp_query; |
|
| 1061 | - } |
|
| 1060 | + return $wp_query; |
|
| 1061 | + } |
|
| 1062 | 1062 | |
| 1063 | - $screen = get_current_screen(); |
|
| 1064 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1065 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1063 | + $screen = get_current_screen(); |
|
| 1064 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1065 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1066 | 1066 | |
| 1067 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1068 | - if( ! empty($admin_user) ){ |
|
| 1067 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1068 | + if( ! empty($admin_user) ){ |
|
| 1069 | 1069 | |
| 1070 | - $current_teacher_id = get_current_user_id(); |
|
| 1070 | + $current_teacher_id = get_current_user_id(); |
|
| 1071 | 1071 | |
| 1072 | - // set current user to admin so teacher can view all questions |
|
| 1073 | - wp_set_current_user( $admin_user->ID ); |
|
| 1072 | + // set current user to admin so teacher can view all questions |
|
| 1073 | + wp_set_current_user( $admin_user->ID ); |
|
| 1074 | 1074 | |
| 1075 | - //run new query as admin |
|
| 1076 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1075 | + //run new query as admin |
|
| 1076 | + $wp_query = new WP_Query( $wp_query->query ); |
|
| 1077 | 1077 | |
| 1078 | - //set the teache as current use again |
|
| 1079 | - wp_set_current_user( $current_teacher_id ); |
|
| 1078 | + //set the teache as current use again |
|
| 1079 | + wp_set_current_user( $current_teacher_id ); |
|
| 1080 | 1080 | |
| 1081 | - } |
|
| 1082 | - } |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | 1083 | |
| 1084 | - return $wp_query; |
|
| 1085 | - }// end give_access_to_all_questions |
|
| 1084 | + return $wp_query; |
|
| 1085 | + }// end give_access_to_all_questions |
|
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Add new column heading to the course admin edit list |
|
| 1089 | - * |
|
| 1090 | - * @since 1.8.0 |
|
| 1091 | - * @param $columns |
|
| 1092 | - * @return array |
|
| 1093 | - */ |
|
| 1094 | - public function course_column_heading($columns) { |
|
| 1087 | + /** |
|
| 1088 | + * Add new column heading to the course admin edit list |
|
| 1089 | + * |
|
| 1090 | + * @since 1.8.0 |
|
| 1091 | + * @param $columns |
|
| 1092 | + * @return array |
|
| 1093 | + */ |
|
| 1094 | + public function course_column_heading($columns) { |
|
| 1095 | 1095 | |
| 1096 | - if( $this->is_admin_teacher() ){ |
|
| 1097 | - return $columns; |
|
| 1098 | - } |
|
| 1099 | - $new_columns = array( |
|
| 1100 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1101 | - ); |
|
| 1102 | - return array_merge($columns, $new_columns); |
|
| 1096 | + if( $this->is_admin_teacher() ){ |
|
| 1097 | + return $columns; |
|
| 1098 | + } |
|
| 1099 | + $new_columns = array( |
|
| 1100 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1101 | + ); |
|
| 1102 | + return array_merge($columns, $new_columns); |
|
| 1103 | 1103 | |
| 1104 | - }// end teacher column add |
|
| 1104 | + }// end teacher column add |
|
| 1105 | 1105 | |
| 1106 | - /** |
|
| 1107 | - * Print out teacher column data |
|
| 1108 | - * |
|
| 1109 | - * @since 1.8.0 |
|
| 1110 | - * @param $column |
|
| 1111 | - * @param $course_id |
|
| 1112 | - */ |
|
| 1113 | - public function course_column_data( $column, $course_id ){ |
|
| 1106 | + /** |
|
| 1107 | + * Print out teacher column data |
|
| 1108 | + * |
|
| 1109 | + * @since 1.8.0 |
|
| 1110 | + * @param $column |
|
| 1111 | + * @param $course_id |
|
| 1112 | + */ |
|
| 1113 | + public function course_column_data( $column, $course_id ){ |
|
| 1114 | 1114 | |
| 1115 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1116 | - return; |
|
| 1117 | - } |
|
| 1115 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1116 | + return; |
|
| 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 ){ |
|
| 1123 | - return; |
|
| 1124 | - } |
|
| 1122 | + if( !$teacher ){ |
|
| 1123 | + return; |
|
| 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 | - }// end course_column_ data |
|
| 1128 | + }// end course_column_ data |
|
| 1129 | 1129 | |
| 1130 | - /** |
|
| 1131 | - * Return only courses belonging to the given teacher. |
|
| 1132 | - * |
|
| 1133 | - * |
|
| 1134 | - * @since 1.8.0 |
|
| 1135 | - * |
|
| 1136 | - * @param int $teacher_id |
|
| 1137 | - * @param bool $return_ids_only |
|
| 1138 | - * |
|
| 1139 | - * @return array $teachers_courses |
|
| 1140 | - */ |
|
| 1141 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1130 | + /** |
|
| 1131 | + * Return only courses belonging to the given teacher. |
|
| 1132 | + * |
|
| 1133 | + * |
|
| 1134 | + * @since 1.8.0 |
|
| 1135 | + * |
|
| 1136 | + * @param int $teacher_id |
|
| 1137 | + * @param bool $return_ids_only |
|
| 1138 | + * |
|
| 1139 | + * @return array $teachers_courses |
|
| 1140 | + */ |
|
| 1141 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1142 | 1142 | |
| 1143 | - $teachers_courses = array(); |
|
| 1143 | + $teachers_courses = array(); |
|
| 1144 | 1144 | |
| 1145 | - if( empty( $teacher_id ) ){ |
|
| 1146 | - $teacher_id = get_current_user_id(); |
|
| 1147 | - } |
|
| 1145 | + if( empty( $teacher_id ) ){ |
|
| 1146 | + $teacher_id = get_current_user_id(); |
|
| 1147 | + } |
|
| 1148 | 1148 | |
| 1149 | - $all_courses = Sensei()->course->get_all_courses(); |
|
| 1149 | + $all_courses = Sensei()->course->get_all_courses(); |
|
| 1150 | 1150 | |
| 1151 | - if( empty( $all_courses ) ){ |
|
| 1152 | - return $all_courses; |
|
| 1153 | - } |
|
| 1151 | + if( empty( $all_courses ) ){ |
|
| 1152 | + return $all_courses; |
|
| 1153 | + } |
|
| 1154 | 1154 | |
| 1155 | - foreach( $all_courses as $course ){ |
|
| 1155 | + foreach( $all_courses as $course ){ |
|
| 1156 | 1156 | |
| 1157 | - if( $course->post_author != $teacher_id ){ |
|
| 1158 | - continue; |
|
| 1159 | - } |
|
| 1157 | + if( $course->post_author != $teacher_id ){ |
|
| 1158 | + continue; |
|
| 1159 | + } |
|
| 1160 | 1160 | |
| 1161 | - if( $return_ids_only ){ |
|
| 1161 | + if( $return_ids_only ){ |
|
| 1162 | 1162 | |
| 1163 | - $teachers_courses[] = $course->ID; |
|
| 1163 | + $teachers_courses[] = $course->ID; |
|
| 1164 | 1164 | |
| 1165 | - }else{ |
|
| 1165 | + }else{ |
|
| 1166 | 1166 | |
| 1167 | - $teachers_courses[] = $course; |
|
| 1167 | + $teachers_courses[] = $course; |
|
| 1168 | 1168 | |
| 1169 | - } |
|
| 1169 | + } |
|
| 1170 | 1170 | |
| 1171 | - } |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - return $teachers_courses; |
|
| 1173 | + return $teachers_courses; |
|
| 1174 | 1174 | |
| 1175 | - } |
|
| 1175 | + } |
|
| 1176 | 1176 | |
| 1177 | - /** |
|
| 1178 | - * Limit the message display to only those sent to the current teacher |
|
| 1179 | - * |
|
| 1180 | - * @since 1.8.0 |
|
| 1181 | - * |
|
| 1182 | - * @param $query |
|
| 1183 | - * @return mixed |
|
| 1184 | - */ |
|
| 1185 | - public function limit_edit_messages_query( $query ){ |
|
| 1186 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1187 | - return $query; |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - $teacher = wp_get_current_user(); |
|
| 1191 | - |
|
| 1192 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1193 | - $meta_query_args = array( |
|
| 1194 | - 'key' => '_receiver', |
|
| 1195 | - 'value' => $teacher->get('user_login') , |
|
| 1196 | - 'compare' => '=' |
|
| 1197 | - ); |
|
| 1177 | + /** |
|
| 1178 | + * Limit the message display to only those sent to the current teacher |
|
| 1179 | + * |
|
| 1180 | + * @since 1.8.0 |
|
| 1181 | + * |
|
| 1182 | + * @param $query |
|
| 1183 | + * @return mixed |
|
| 1184 | + */ |
|
| 1185 | + public function limit_edit_messages_query( $query ){ |
|
| 1186 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1187 | + return $query; |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + $teacher = wp_get_current_user(); |
|
| 1191 | + |
|
| 1192 | + $query->set( 'meta_key', '_receiver' ); |
|
| 1193 | + $meta_query_args = array( |
|
| 1194 | + 'key' => '_receiver', |
|
| 1195 | + 'value' => $teacher->get('user_login') , |
|
| 1196 | + 'compare' => '=' |
|
| 1197 | + ); |
|
| 1198 | 1198 | |
| 1199 | - $query->set('meta_query', $meta_query_args ); |
|
| 1199 | + $query->set('meta_query', $meta_query_args ); |
|
| 1200 | 1200 | |
| 1201 | - return $query; |
|
| 1202 | - } |
|
| 1201 | + return $query; |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | 1204 | |
| 1205 | - /** |
|
| 1206 | - * Add options to filter courses by teacher |
|
| 1207 | - * |
|
| 1208 | - * @since 1.8.0 |
|
| 1209 | - * |
|
| 1210 | - * @return void |
|
| 1211 | - */ |
|
| 1212 | - public function course_teacher_filter_options() { |
|
| 1213 | - global $typenow; |
|
| 1205 | + /** |
|
| 1206 | + * Add options to filter courses by teacher |
|
| 1207 | + * |
|
| 1208 | + * @since 1.8.0 |
|
| 1209 | + * |
|
| 1210 | + * @return void |
|
| 1211 | + */ |
|
| 1212 | + public function course_teacher_filter_options() { |
|
| 1213 | + global $typenow; |
|
| 1214 | 1214 | |
| 1215 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1216 | - return; |
|
| 1217 | - } |
|
| 1215 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1216 | + return; |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | - // get all roles |
|
| 1220 | - $roles = get_editable_roles(); |
|
| 1219 | + // get all roles |
|
| 1220 | + $roles = get_editable_roles(); |
|
| 1221 | 1221 | |
| 1222 | - // get roles with the course edit capability |
|
| 1223 | - // and then get the users with those roles |
|
| 1224 | - $users_who_can_edit_courses = array(); |
|
| 1225 | - foreach( $roles as $role_item ){ |
|
| 1222 | + // get roles with the course edit capability |
|
| 1223 | + // and then get the users with those roles |
|
| 1224 | + $users_who_can_edit_courses = array(); |
|
| 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 | - // 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 ); |
|
| 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 ); |
|
| 1236 | 1236 | |
| 1237 | - } |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | - // Create the select element with the given users who can edit course |
|
| 1242 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 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>'; |
|
| 1246 | - } |
|
| 1241 | + // Create the select element with the given users who can edit course |
|
| 1242 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 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>'; |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1249 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1250 | - $output .= $course_options; |
|
| 1251 | - $output .= '</select>'; |
|
| 1248 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1249 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1250 | + $output .= $course_options; |
|
| 1251 | + $output .= '</select>'; |
|
| 1252 | 1252 | |
| 1253 | - echo $output; |
|
| 1254 | - } |
|
| 1253 | + echo $output; |
|
| 1254 | + } |
|
| 1255 | 1255 | |
| 1256 | - /** |
|
| 1257 | - * Modify the main query on the admin course list screen |
|
| 1258 | - * |
|
| 1259 | - * @since 1.8.0 |
|
| 1260 | - * |
|
| 1261 | - * @param $query |
|
| 1262 | - * @return $query |
|
| 1263 | - */ |
|
| 1264 | - public function teacher_filter_query_modify( $query ){ |
|
| 1265 | - global $typenow; |
|
| 1256 | + /** |
|
| 1257 | + * Modify the main query on the admin course list screen |
|
| 1258 | + * |
|
| 1259 | + * @since 1.8.0 |
|
| 1260 | + * |
|
| 1261 | + * @param $query |
|
| 1262 | + * @return $query |
|
| 1263 | + */ |
|
| 1264 | + public function teacher_filter_query_modify( $query ){ |
|
| 1265 | + global $typenow; |
|
| 1266 | 1266 | |
| 1267 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1268 | - return $query; |
|
| 1269 | - } |
|
| 1270 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1271 | - |
|
| 1272 | - if( empty( $course_teacher ) ) { |
|
| 1273 | - return $query; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - $query['author'] = $course_teacher; |
|
| 1277 | - return $query; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Only show current teacher's media in the media library |
|
| 1282 | - * @param array $request Default request arguments |
|
| 1283 | - * @return array Modified request arguments |
|
| 1284 | - */ |
|
| 1285 | - public function restrict_media_library( $request = array() ) { |
|
| 1286 | - |
|
| 1287 | - if( ! is_admin() ) { |
|
| 1288 | - return $request; |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - if( ! $this->is_admin_teacher() ) { |
|
| 1292 | - return $request; |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - $screen = get_current_screen(); |
|
| 1296 | - |
|
| 1297 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1298 | - $teacher = intval( get_current_user_id() ); |
|
| 1299 | - |
|
| 1300 | - if( $teacher ) { |
|
| 1301 | - $request['author__in'] = array( $teacher ); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - return $request; |
|
| 1306 | - } // End restrict_media_library() |
|
| 1307 | - |
|
| 1308 | - /** |
|
| 1309 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1310 | - * @param array $query Default query arguments |
|
| 1311 | - * @return array Modified query arguments |
|
| 1312 | - */ |
|
| 1313 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1314 | - |
|
| 1315 | - if( ! is_admin() ) { |
|
| 1316 | - return $query; |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - if( ! $this->is_admin_teacher() ) { |
|
| 1320 | - return $query; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - $teacher = intval( get_current_user_id() ); |
|
| 1324 | - |
|
| 1325 | - if( $teacher ) { |
|
| 1326 | - $query['author__in'] = array( $teacher ); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - return $query; |
|
| 1330 | - } // End restrict_media_library_modal() |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1334 | - * |
|
| 1335 | - * @since 1.8.0 |
|
| 1336 | - * |
|
| 1337 | - * @param int $lesson_id |
|
| 1338 | - */ |
|
| 1339 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1340 | - |
|
| 1341 | - if( 'lesson'!= get_post_type() ){ |
|
| 1342 | - return; |
|
| 1343 | - } |
|
| 1267 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1268 | + return $query; |
|
| 1269 | + } |
|
| 1270 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1271 | + |
|
| 1272 | + if( empty( $course_teacher ) ) { |
|
| 1273 | + return $query; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + $query['author'] = $course_teacher; |
|
| 1277 | + return $query; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Only show current teacher's media in the media library |
|
| 1282 | + * @param array $request Default request arguments |
|
| 1283 | + * @return array Modified request arguments |
|
| 1284 | + */ |
|
| 1285 | + public function restrict_media_library( $request = array() ) { |
|
| 1286 | + |
|
| 1287 | + if( ! is_admin() ) { |
|
| 1288 | + return $request; |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + if( ! $this->is_admin_teacher() ) { |
|
| 1292 | + return $request; |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + $screen = get_current_screen(); |
|
| 1296 | + |
|
| 1297 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1298 | + $teacher = intval( get_current_user_id() ); |
|
| 1299 | + |
|
| 1300 | + if( $teacher ) { |
|
| 1301 | + $request['author__in'] = array( $teacher ); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + return $request; |
|
| 1306 | + } // End restrict_media_library() |
|
| 1307 | + |
|
| 1308 | + /** |
|
| 1309 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1310 | + * @param array $query Default query arguments |
|
| 1311 | + * @return array Modified query arguments |
|
| 1312 | + */ |
|
| 1313 | + public function restrict_media_library_modal( $query = array() ) { |
|
| 1314 | + |
|
| 1315 | + if( ! is_admin() ) { |
|
| 1316 | + return $query; |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + if( ! $this->is_admin_teacher() ) { |
|
| 1320 | + return $query; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + $teacher = intval( get_current_user_id() ); |
|
| 1324 | + |
|
| 1325 | + if( $teacher ) { |
|
| 1326 | + $query['author__in'] = array( $teacher ); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + return $query; |
|
| 1330 | + } // End restrict_media_library_modal() |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1334 | + * |
|
| 1335 | + * @since 1.8.0 |
|
| 1336 | + * |
|
| 1337 | + * @param int $lesson_id |
|
| 1338 | + */ |
|
| 1339 | + public function update_lesson_teacher( $lesson_id ){ |
|
| 1340 | + |
|
| 1341 | + if( 'lesson'!= get_post_type() ){ |
|
| 1342 | + return; |
|
| 1343 | + } |
|
| 1344 | 1344 | |
| 1345 | - // this should only run once per request cycle |
|
| 1346 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1345 | + // this should only run once per request cycle |
|
| 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 ){ |
|
| 1351 | - return; |
|
| 1352 | - } |
|
| 1350 | + if( empty( $course_id ) || ! $course_id ){ |
|
| 1351 | + return; |
|
| 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 , |
|
| 1358 | - 'post_author' => $course->post_author |
|
| 1359 | - ); |
|
| 1360 | - wp_update_post( $lesson_update_args ); |
|
| 1356 | + $lesson_update_args= array( |
|
| 1357 | + 'ID' => $lesson_id , |
|
| 1358 | + 'post_author' => $course->post_author |
|
| 1359 | + ); |
|
| 1360 | + wp_update_post( $lesson_update_args ); |
|
| 1361 | 1361 | |
| 1362 | - } // end update_lesson_teacher |
|
| 1362 | + } // end update_lesson_teacher |
|
| 1363 | 1363 | |
| 1364 | - /** |
|
| 1365 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1366 | - * |
|
| 1367 | - * Limit teachers to only see their courses, lessons and questions |
|
| 1368 | - * |
|
| 1369 | - * @since 1.8.0 |
|
| 1370 | - * @access public |
|
| 1371 | - * @parameters array $wp_query |
|
| 1372 | - * @return WP_Query $wp_query |
|
| 1373 | - */ |
|
| 1374 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1375 | - global $current_user; |
|
| 1364 | + /** |
|
| 1365 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1366 | + * |
|
| 1367 | + * Limit teachers to only see their courses, lessons and questions |
|
| 1368 | + * |
|
| 1369 | + * @since 1.8.0 |
|
| 1370 | + * @access public |
|
| 1371 | + * @parameters array $wp_query |
|
| 1372 | + * @return WP_Query $wp_query |
|
| 1373 | + */ |
|
| 1374 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1375 | + global $current_user; |
|
| 1376 | 1376 | |
| 1377 | - //exit early |
|
| 1378 | - if( ! $this->is_admin_teacher() ){ |
|
| 1379 | - return $wp_query; |
|
| 1380 | - } |
|
| 1377 | + //exit early |
|
| 1378 | + if( ! $this->is_admin_teacher() ){ |
|
| 1379 | + return $wp_query; |
|
| 1380 | + } |
|
| 1381 | 1381 | |
| 1382 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1383 | - return $wp_query; |
|
| 1384 | - } |
|
| 1382 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1383 | + return $wp_query; |
|
| 1384 | + } |
|
| 1385 | 1385 | |
| 1386 | - $screen = get_current_screen(); |
|
| 1386 | + $screen = get_current_screen(); |
|
| 1387 | 1387 | |
| 1388 | - if( empty( $screen ) ){ |
|
| 1389 | - return $wp_query; |
|
| 1390 | - } |
|
| 1388 | + if( empty( $screen ) ){ |
|
| 1389 | + return $wp_query; |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - // for any of these conditions limit what the teacher will see |
|
| 1393 | - $limit_screens = array( |
|
| 1394 | - 'edit-lesson', |
|
| 1395 | - 'edit-course', |
|
| 1396 | - 'edit-question', |
|
| 1397 | - 'course_page_course-order', |
|
| 1398 | - 'lesson_page_lesson-order', |
|
| 1399 | - ); |
|
| 1392 | + // for any of these conditions limit what the teacher will see |
|
| 1393 | + $limit_screens = array( |
|
| 1394 | + 'edit-lesson', |
|
| 1395 | + 'edit-course', |
|
| 1396 | + 'edit-question', |
|
| 1397 | + 'course_page_course-order', |
|
| 1398 | + 'lesson_page_lesson-order', |
|
| 1399 | + ); |
|
| 1400 | 1400 | |
| 1401 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1401 | + if( in_array($screen->id , $limit_screens ) ) { |
|
| 1402 | 1402 | |
| 1403 | - // set the query author to the current user to only show those those posts |
|
| 1404 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1405 | - } |
|
| 1403 | + // set the query author to the current user to only show those those posts |
|
| 1404 | + $wp_query->set( 'author', $current_user->ID ); |
|
| 1405 | + } |
|
| 1406 | 1406 | |
| 1407 | - return $wp_query; |
|
| 1407 | + return $wp_query; |
|
| 1408 | 1408 | |
| 1409 | - } // end limit_teacher_edit_screen_post_types() |
|
| 1409 | + } // end limit_teacher_edit_screen_post_types() |
|
| 1410 | 1410 | |
| 1411 | 1411 | |
| 1412 | - /** |
|
| 1413 | - * Sensei_Teacher::teacher_login_redirect |
|
| 1414 | - * |
|
| 1415 | - * Redirect teachers to /wp-admin/ after login |
|
| 1416 | - * |
|
| 1417 | - * @since 1.8.7 |
|
| 1418 | - * @access public |
|
| 1419 | - * @param string $user_login |
|
| 1420 | - * @param object $user |
|
| 1421 | - * @return void |
|
| 1422 | - */ |
|
| 1412 | + /** |
|
| 1413 | + * Sensei_Teacher::teacher_login_redirect |
|
| 1414 | + * |
|
| 1415 | + * Redirect teachers to /wp-admin/ after login |
|
| 1416 | + * |
|
| 1417 | + * @since 1.8.7 |
|
| 1418 | + * @access public |
|
| 1419 | + * @param string $user_login |
|
| 1420 | + * @param object $user |
|
| 1421 | + * @return void |
|
| 1422 | + */ |
|
| 1423 | 1423 | |
| 1424 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1424 | + public function teacher_login_redirect( $user_login, $user ) { |
|
| 1425 | 1425 | |
| 1426 | - if (user_can($user, 'edit_courses')) { |
|
| 1426 | + if (user_can($user, 'edit_courses')) { |
|
| 1427 | 1427 | |
| 1428 | - if (isset($_POST['redirect_to'])) { |
|
| 1428 | + if (isset($_POST['redirect_to'])) { |
|
| 1429 | 1429 | |
| 1430 | - wp_redirect($_POST['redirect_to'], 303); |
|
| 1430 | + wp_redirect($_POST['redirect_to'], 303); |
|
| 1431 | 1431 | |
| 1432 | - exit; |
|
| 1432 | + exit; |
|
| 1433 | 1433 | |
| 1434 | - } else { |
|
| 1434 | + } else { |
|
| 1435 | 1435 | |
| 1436 | - wp_redirect(admin_url(), 303); |
|
| 1436 | + wp_redirect(admin_url(), 303); |
|
| 1437 | 1437 | |
| 1438 | - exit; |
|
| 1438 | + exit; |
|
| 1439 | 1439 | |
| 1440 | - } |
|
| 1441 | - } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | 1442 | |
| 1443 | - } // end teacher_login_redirect() |
|
| 1443 | + } // end teacher_login_redirect() |
|
| 1444 | 1444 | |
| 1445 | 1445 | |
| 1446 | 1446 | |
| 1447 | - /** |
|
| 1448 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1449 | - * |
|
| 1450 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1451 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1452 | - * so they can 'moderate_comments' as well. |
|
| 1453 | - * |
|
| 1454 | - * @since 1.8.7 |
|
| 1455 | - * @access public |
|
| 1456 | - * @parameters void |
|
| 1457 | - * @return void |
|
| 1458 | - */ |
|
| 1447 | + /** |
|
| 1448 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1449 | + * |
|
| 1450 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1451 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1452 | + * so they can 'moderate_comments' as well. |
|
| 1453 | + * |
|
| 1454 | + * @since 1.8.7 |
|
| 1455 | + * @access public |
|
| 1456 | + * @parameters void |
|
| 1457 | + * @return void |
|
| 1458 | + */ |
|
| 1459 | 1459 | |
| 1460 | - public function restrict_posts_menu_page() { |
|
| 1460 | + public function restrict_posts_menu_page() { |
|
| 1461 | 1461 | |
| 1462 | - global $pagenow, $typenow; |
|
| 1462 | + global $pagenow, $typenow; |
|
| 1463 | 1463 | |
| 1464 | - $user = wp_get_current_user(); |
|
| 1464 | + $user = wp_get_current_user(); |
|
| 1465 | 1465 | |
| 1466 | - /** |
|
| 1467 | - * Filter the option to hide the Posts menu page. |
|
| 1468 | - * |
|
| 1469 | - * @since 1.8.7 |
|
| 1470 | - * |
|
| 1471 | - * @param bool $restrict default true |
|
| 1472 | - */ |
|
| 1466 | + /** |
|
| 1467 | + * Filter the option to hide the Posts menu page. |
|
| 1468 | + * |
|
| 1469 | + * @since 1.8.7 |
|
| 1470 | + * |
|
| 1471 | + * @param bool $restrict default true |
|
| 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 | - remove_menu_page('edit.php'); |
|
| 1478 | + remove_menu_page('edit.php'); |
|
| 1479 | 1479 | |
| 1480 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1480 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1481 | 1481 | |
| 1482 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1482 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1483 | 1483 | |
| 1484 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1484 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1485 | 1485 | |
| 1486 | - } |
|
| 1486 | + } |
|
| 1487 | 1487 | |
| 1488 | - } |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } // end restrict_posts_menu_page() |
|
| 1492 | + } // end restrict_posts_menu_page() |
|
| 1493 | 1493 | |
| 1494 | - /** |
|
| 1495 | - * Sensei_Teacher::restrict_comment_moderation() |
|
| 1496 | - * |
|
| 1497 | - * Restrict commendation moderation for teachers |
|
| 1498 | - * so they can only moderate comments made to posts they own. |
|
| 1499 | - * |
|
| 1500 | - * @since 1.8.7 |
|
| 1501 | - * @access public |
|
| 1502 | - * @parameters obj $clauses |
|
| 1503 | - * @return WP_Comment_Query $clauses |
|
| 1504 | - */ |
|
| 1494 | + /** |
|
| 1495 | + * Sensei_Teacher::restrict_comment_moderation() |
|
| 1496 | + * |
|
| 1497 | + * Restrict commendation moderation for teachers |
|
| 1498 | + * so they can only moderate comments made to posts they own. |
|
| 1499 | + * |
|
| 1500 | + * @since 1.8.7 |
|
| 1501 | + * @access public |
|
| 1502 | + * @parameters obj $clauses |
|
| 1503 | + * @return WP_Comment_Query $clauses |
|
| 1504 | + */ |
|
| 1505 | 1505 | |
| 1506 | - public function restrict_comment_moderation ( $clauses ) { |
|
| 1506 | + public function restrict_comment_moderation ( $clauses ) { |
|
| 1507 | 1507 | |
| 1508 | - global $pagenow; |
|
| 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 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1512 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1513 | 1513 | |
| 1514 | - } |
|
| 1514 | + } |
|
| 1515 | 1515 | |
| 1516 | - return $clauses; |
|
| 1516 | + return $clauses; |
|
| 1517 | 1517 | |
| 1518 | - } // end restrict_comment_moderation() |
|
| 1518 | + } // end restrict_comment_moderation() |
|
| 1519 | 1519 | |
| 1520 | - /** |
|
| 1521 | - * Determine if a user is a teacher by ID |
|
| 1522 | - * |
|
| 1523 | - * @param int $user_id |
|
| 1524 | - * |
|
| 1525 | - * @return bool |
|
| 1526 | - */ |
|
| 1527 | - public static function is_a_teacher( $user_id ){ |
|
| 1520 | + /** |
|
| 1521 | + * Determine if a user is a teacher by ID |
|
| 1522 | + * |
|
| 1523 | + * @param int $user_id |
|
| 1524 | + * |
|
| 1525 | + * @return bool |
|
| 1526 | + */ |
|
| 1527 | + public static function is_a_teacher( $user_id ){ |
|
| 1528 | 1528 | |
| 1529 | - $user = get_user_by('id', $user_id); |
|
| 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 | - return true; |
|
| 1533 | + return true; |
|
| 1534 | 1534 | |
| 1535 | - }else{ |
|
| 1535 | + }else{ |
|
| 1536 | 1536 | |
| 1537 | - return false; |
|
| 1537 | + return false; |
|
| 1538 | 1538 | |
| 1539 | - } |
|
| 1539 | + } |
|
| 1540 | 1540 | |
| 1541 | - }// end is_a_teacher |
|
| 1541 | + }// end is_a_teacher |
|
| 1542 | 1542 | |
| 1543 | - /** |
|
| 1544 | - * The archive title on the teacher archive filter |
|
| 1545 | - * |
|
| 1546 | - * @since 1.9.0 |
|
| 1547 | - */ |
|
| 1548 | - public static function archive_title(){ |
|
| 1543 | + /** |
|
| 1544 | + * The archive title on the teacher archive filter |
|
| 1545 | + * |
|
| 1546 | + * @since 1.9.0 |
|
| 1547 | + */ |
|
| 1548 | + public static function archive_title(){ |
|
| 1549 | 1549 | |
| 1550 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1551 | - $author_name = $author->display_name; |
|
| 1552 | - ?> |
|
| 1550 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1551 | + $author_name = $author->display_name; |
|
| 1552 | + ?> |
|
| 1553 | 1553 | <h2 class="teacher-archive-title"> |
| 1554 | 1554 | |
| 1555 | 1555 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1557,17 +1557,17 @@ discard block |
||
| 1557 | 1557 | </h2> |
| 1558 | 1558 | <?php |
| 1559 | 1559 | |
| 1560 | - }// archive title |
|
| 1560 | + }// archive title |
|
| 1561 | 1561 | |
| 1562 | - /** |
|
| 1563 | - * Removing course meta on the teacher archive page |
|
| 1564 | - * |
|
| 1565 | - * @since 1.9.0 |
|
| 1566 | - */ |
|
| 1567 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1562 | + /** |
|
| 1563 | + * Removing course meta on the teacher archive page |
|
| 1564 | + * |
|
| 1565 | + * @since 1.9.0 |
|
| 1566 | + */ |
|
| 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 | |
| 1573 | 1573 | } // 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 |
@@ -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 | |