Completed
Push — master ( 78b9e3...efb4fd )
by Dwain
04:49
created
includes/emails/class-woothemes-sensei-email-teacher-completed-lesson.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	/**
36 36
 	 * trigger function.
37 37
 	 *
38
-     * @param int $learner_id
39
-     * @param int $lesson_id
40
-     *
38
+	 * @param int $learner_id
39
+	 * @param int $lesson_id
40
+	 *
41 41
 	 * @return void
42 42
 	 */
43 43
 	function trigger( $learner_id = 0, $lesson_id = 0 ) {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		$teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' );
52 52
 		$this->teacher = new WP_User( $teacher_id );
53 53
 
54
-        // Construct data array
54
+		// Construct data array
55 55
 		$sensei_email_data = apply_filters( 'sensei_email_data', array(
56 56
 			'template'			=> $this->template,
57 57
 			'heading'			=> $this->heading,
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		$this->recipient = stripslashes( $this->teacher->user_email );
66 66
 
67 67
 		// Send mail
68
-        Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
68
+		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
69 69
 	}
70 70
 }
71 71
 
Please login to merge, or discard this patch.
includes/class-sensei-analysis.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 		if ( current_user_can( 'manage_sensei_grades' ) ) {
54 54
 
55
-            add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) );
55
+			add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) );
56 56
 
57 57
 		}
58 58
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 									'analysis-lesson'
90 90
 									);
91 91
 		foreach ( $classes_to_load as $class_file ) {
92
-            Sensei()->load_class( $class_file );
92
+			Sensei()->load_class( $class_file );
93 93
 		} // End For Loop
94 94
 	} // End load_data_table_files()
95 95
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 
434 434
 			$user_id = intval( $_GET['user_id'] );
435 435
 			$url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) );
436
-            $user_name = Sensei_Learner::get_full_name( $user_id );
436
+			$user_name = Sensei_Learner::get_full_name( $user_id );
437 437
 			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
438 438
 
439 439
 		} // End If Statement
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 			$user_id = intval( $_GET['user_id'] );
455 455
 			$user_data = get_userdata( $user_id );
456 456
 			$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) );
457
-            $user_name = Sensei_Learner::get_full_name( $user_id );
458
-            $title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
457
+			$user_name = Sensei_Learner::get_full_name( $user_id );
458
+			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
459 459
 			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name );
460 460
 		} // End If Statement
461 461
 		if ( isset( $_GET['course_id'] ) ) { 
Please login to merge, or discard this patch.
includes/theme-integrations/storefront.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Class Sensei_Storefront
4
- *
5
- * Responsible for wrapping Storefront theme Sensei content
6
- * with the correct markup
7
- *
8
- * @package Views
9
- * @subpackage Theme-Integration
10
- * @author Automattic
11
- *
12
- * @since 1.9.0
3
+	 * Class Sensei_Storefront
4
+	 *
5
+	 * Responsible for wrapping Storefront theme Sensei content
6
+	 * with the correct markup
7
+	 *
8
+	 * @package Views
9
+	 * @subpackage Theme-Integration
10
+	 * @author Automattic
11
+	 *
12
+	 * @since 1.9.0
13 13
 */
14 14
 Class Sensei_Storefront extends Sensei__S { }
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-teacher-started-course.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@
 block discarded – undo
37 37
 	/**
38 38
 	 * trigger function.
39 39
 	 *
40
-     * @param int $learner_id
41
-     * @param int $course_id
42
-     *
40
+	 * @param int $learner_id
41
+	 * @param int $course_id
42
+	 *
43 43
 	 * @return void
44 44
 	 */
45 45
 	function trigger( $learner_id = 0, $course_id = 0 ) {
Please login to merge, or discard this patch.
templates/single-course.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * The Template for displaying all single courses.
4
- *
5
- * Override this template by copying it to yourtheme/sensei/single-course.php
6
- *
7
- * @author 		Automattic
8
- * @package 	Sensei
9
- * @category    Templates
10
- * @version     1.9.0
11
- */
3
+	 * The Template for displaying all single courses.
4
+	 *
5
+	 * Override this template by copying it to yourtheme/sensei/single-course.php
6
+	 *
7
+	 * @author 		Automattic
8
+	 * @package 	Sensei
9
+	 * @category    Templates
10
+	 * @version     1.9.0
11
+	 */
12 12
 ?>
13 13
 
14 14
 <?php  get_sensei_header();  ?>
@@ -17,24 +17,24 @@  discard block
 block discarded – undo
17 17
 
18 18
     <?php
19 19
 
20
-    /**
21
-     * Hook inside the single course post above the content
22
-     *
23
-     * @since 1.9.0
24
-     *
25
-     * @param integer $course_id
26
-     *
27
-     * @hooked Sensei()->frontend->sensei_course_start     -  10
28
-     * @hooked Sensei_Course::the_title                    -  10
29
-     * @hooked Sensei()->course->course_image              -  20
30
-     * @hooked Sensei_WC::course_in_cart_message           -  20
31
-     * @hooked Sensei_Course::the_course_enrolment_actions -  30
32
-     * @hooked Sensei()->message->send_message_link        -  35
33
-     * @hooked Sensei_Course::the_course_video             -  40
34
-     */
35
-    do_action( 'sensei_single_course_content_inside_before', get_the_ID() );
36
-
37
-    ?>
20
+	/**
21
+	 * Hook inside the single course post above the content
22
+	 *
23
+	 * @since 1.9.0
24
+	 *
25
+	 * @param integer $course_id
26
+	 *
27
+	 * @hooked Sensei()->frontend->sensei_course_start     -  10
28
+	 * @hooked Sensei_Course::the_title                    -  10
29
+	 * @hooked Sensei()->course->course_image              -  20
30
+	 * @hooked Sensei_WC::course_in_cart_message           -  20
31
+	 * @hooked Sensei_Course::the_course_enrolment_actions -  30
32
+	 * @hooked Sensei()->message->send_message_link        -  35
33
+	 * @hooked Sensei_Course::the_course_video             -  40
34
+	 */
35
+	do_action( 'sensei_single_course_content_inside_before', get_the_ID() );
36
+
37
+	?>
38 38
 
39 39
     <section class="entry fix">
40 40
 
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
 
45 45
     <?php
46 46
 
47
-    /**
48
-     * Hook inside the single course post above the content
49
-     *
50
-     * @since 1.9.0
51
-     *
52
-     * @param integer $course_id
53
-     *
54
-     */
55
-    do_action( 'sensei_single_course_content_inside_after', get_the_ID() );
56
-
57
-    ?>
47
+	/**
48
+	 * Hook inside the single course post above the content
49
+	 *
50
+	 * @since 1.9.0
51
+	 *
52
+	 * @param integer $course_id
53
+	 *
54
+	 */
55
+	do_action( 'sensei_single_course_content_inside_after', get_the_ID() );
56
+
57
+	?>
58 58
 </article><!-- .post .single-course -->
59 59
 
60 60
 <?php get_sensei_footer(); ?>
61 61
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 1 patch
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -12,251 +12,251 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
includes/admin/class-sensei-learner-management.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 
79 79
 		// Load Learners JS
80 80
 		wp_enqueue_script( 'sensei-learners-general',
81
-            Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
82
-                            array('jquery','sensei-core-select2','sensei-chosen-ajax' ), Sensei()->version, true );
81
+			Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
82
+							array('jquery','sensei-core-select2','sensei-chosen-ajax' ), Sensei()->version, true );
83 83
 
84 84
 		$data = array(
85 85
 			'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ),
86 86
 			'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ),
87 87
 			'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ),
88 88
 			'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ),
89
-            'search_users_nonce' => wp_create_nonce( 'search-users' ),
90
-            'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
89
+			'search_users_nonce' => wp_create_nonce( 'search-users' ),
90
+			'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
91 91
 		);
92 92
 
93 93
 		wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data );
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	/**
187 187
 	 * learners_headers outputs Learners general headers
188 188
 	 * @since  1.6.0
189
-     * @param array $args
189
+	 * @param array $args
190 190
 	 * @return void
191 191
 	 */
192 192
 	public function learners_headers( $args = array( 'nav' => 'default' ) ) {
@@ -252,38 +252,38 @@  discard block
 block discarded – undo
252 252
 
253 253
 	public function remove_user_from_post() {
254 254
 
255
-        // Parse POST data
256
-        $data = sanitize_text_field( $_POST['data'] );
257
-        $action_data = array();
258
-        parse_str( $data, $action_data );
255
+		// Parse POST data
256
+		$data = sanitize_text_field( $_POST['data'] );
257
+		$action_data = array();
258
+		parse_str( $data, $action_data );
259 259
 
260 260
 		// Security checks
261
-        // ensure the current user may remove users from post
262
-        // only teacher or admin can remove users
261
+		// ensure the current user may remove users from post
262
+		// only teacher or admin can remove users
263 263
 
264
-        // check the nonce, valid post
264
+		// check the nonce, valid post
265 265
 		$nonce = '';
266 266
 		if ( isset($_POST['remove_user_from_post_nonce']) ) {
267 267
 			$nonce = esc_html( $_POST['remove_user_from_post_nonce'] );
268 268
 		}
269
-        $post =  get_post( intval( $action_data[ 'post_id' ] ) );
269
+		$post =  get_post( intval( $action_data[ 'post_id' ] ) );
270 270
 
271
-        // validate the user
272
-        $may_remove_user = false;
273
-        if( current_user_can('manage_sensei')
274
-            ||  $post->post_author == get_current_user_id() ){
271
+		// validate the user
272
+		$may_remove_user = false;
273
+		if( current_user_can('manage_sensei')
274
+			||  $post->post_author == get_current_user_id() ){
275 275
 
276
-            $may_remove_user = true;
276
+			$may_remove_user = true;
277 277
 
278
-        }
278
+		}
279 279
 
280
-        if( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' )
281
-            || ! is_a( $post ,'WP_Post' )
282
-            || ! $may_remove_user ){
280
+		if( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' )
281
+			|| ! is_a( $post ,'WP_Post' )
282
+			|| ! $may_remove_user ){
283 283
 
284
-            die('');
284
+			die('');
285 285
 
286
-        }
286
+		}
287 287
 
288 288
 		if( $action_data['user_id'] && $action_data['post_id'] && $action_data['post_type'] ) {
289 289
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 
298 298
 				case 'course':
299 299
 
300
-                    $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
300
+					$removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
301 301
 
302 302
 				break;
303 303
 
@@ -344,19 +344,19 @@  discard block
 block discarded – undo
344 344
 
345 345
 		if ( $users ) {
346 346
 			foreach ( $users as $user ) {
347
-                $full_name = Sensei_Learner::get_full_name( $user->ID );
347
+				$full_name = Sensei_Learner::get_full_name( $user->ID );
348 348
 
349
-                if( trim($user->display_name ) == trim( $full_name ) ){
349
+				if( trim($user->display_name ) == trim( $full_name ) ){
350 350
 
351
-                    $name = $full_name;
351
+					$name = $full_name;
352 352
 
353
-                }else{
353
+				}else{
354 354
 
355
-                    $name = $full_name . ' ['. $user->display_name .']';
355
+					$name = $full_name . ' ['. $user->display_name .']';
356 356
 
357
-                }
357
+				}
358 358
 
359
-                $found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' &ndash; ' . sanitize_email( $user->user_email ) . ')';
359
+				$found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' &ndash; ' . sanitize_email( $user->user_email ) . ')';
360 360
 			}
361 361
 		}
362 362
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 			break;
401 401
 
402 402
 			case 'lesson':
403
-                $lesson_id = absint( $_POST['add_lesson_id'] );
403
+				$lesson_id = absint( $_POST['add_lesson_id'] );
404 404
 				$complete = false;
405 405
 				if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) {
406 406
 					$complete = true;
@@ -460,23 +460,23 @@  discard block
 block discarded – undo
460 460
 		}
461 461
 	}
462 462
 
463
-    /**
464
-     * Return the full name and surname or the display name of the user.
465
-     *
466
-     * The user must have both name and surname otherwise display name will be returned.
467
-     *
468
-     * @deprecated since 1.9.0 use Se
469
-     * @since 1.8.0
470
-     *
471
-     * @param int $user_id | bool false for an invalid $user_id
472
-     *
473
-     * @return string $full_name
474
-     */
475
-    public function get_learner_full_name( $user_id ){
476
-
477
-        return Sensei_Learner::get_full_name( $user_id );
478
-
479
-    } // end get_learner_full_name
463
+	/**
464
+	 * Return the full name and surname or the display name of the user.
465
+	 *
466
+	 * The user must have both name and surname otherwise display name will be returned.
467
+	 *
468
+	 * @deprecated since 1.9.0 use Se
469
+	 * @since 1.8.0
470
+	 *
471
+	 * @param int $user_id | bool false for an invalid $user_id
472
+	 *
473
+	 * @return string $full_name
474
+	 */
475
+	public function get_learner_full_name( $user_id ){
476
+
477
+		return Sensei_Learner::get_full_name( $user_id );
478
+
479
+	} // end get_learner_full_name
480 480
 
481 481
 } // End Class
482 482
 
Please login to merge, or discard this patch.
templates/single-quiz/question_type-multiple-choice.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
 
13 13
 <?php
14 14
 
15
-    /**
16
-     * Get the question data with the current quiz id
17
-     * All data is loaded in this array to keep the template clean.
18
-     */
19
-    $question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );
15
+	/**
16
+	 * Get the question data with the current quiz id
17
+	 * All data is loaded in this array to keep the template clean.
18
+	 */
19
+	$question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );
20 20
 
21 21
 ?>
22 22
 
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
 $count = 0;
27 27
 foreach( $question_data[ 'answer_options' ] as $id => $option ) {
28 28
 
29
-    $count++;
29
+	$count++;
30 30
 
31
-    ?>
31
+	?>
32 32
 
33 33
     <li class="<?php esc_attr_e( $option[ 'option_class' ] ); ?>">
34 34
         <input type="<?php echo $option[ 'type' ]; ?>"
Please login to merge, or discard this patch.
includes/class-sensei-question.php 1 patch
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @since  1.0.0
21 21
 	 */
22 22
 	public function __construct () {
23
-        $this->token = 'question';
23
+		$this->token = 'question';
24 24
 		$this->question_types = $this->question_types();
25 25
 		$this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' );
26 26
 		if ( is_admin() ) {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 			if( isset( $post->ID ) ) {
119 119
 
120
-                $question_type = Sensei()->question->get_question_type( $post->ID );
120
+				$question_type = Sensei()->question->get_question_type( $post->ID );
121 121
 
122 122
 				if( $question_type ) {
123 123
 					$type = $this->question_types[ $question_type ];
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
 	public function save_question( $post_id = 0 ) {
238 238
 
239 239
 		if( ! isset( $_POST['post_type']
240
-            ) || 'question' != $_POST['post_type'] ) {
241
-            return;
242
-        }
240
+			) || 'question' != $_POST['post_type'] ) {
241
+			return;
242
+		}
243 243
 
244 244
 
245 245
 
246
-        //setup the data for saving
246
+		//setup the data for saving
247 247
 		$data = $_POST ;
248
-        $data['quiz_id'] = 0;
248
+		$data['quiz_id'] = 0;
249 249
 		$data['question_id'] = $post_id;
250 250
 
251 251
 		if ( ! wp_is_post_revision( $post_id ) ){
@@ -339,34 +339,34 @@  discard block
 block discarded – undo
339 339
 		return $request;
340 340
 	}
341 341
 
342
-    /**
343
-     * Get the type of question by id
344
-     *
345
-     * This function uses the post terms to determine which question type
346
-     * the passed question id belongs to.
347
-     *
348
-     * @since 1.7.4
349
-     *
350
-     * @param int $question_id
351
-     *
352
-     * @return string $question_type | bool
353
-     */
354
-    public function get_question_type( $question_id ){
355
-
356
-        if( empty( $question_id ) || ! intval( $question_id ) > 0
357
-            || 'question' != get_post_type( $question_id )   ){
358
-            return false;
359
-        }
360
-
361
-        $question_type = 'multiple-choice';
362
-        $question_types = wp_get_post_terms( $question_id, 'question-type' );
363
-        foreach( $question_types as $type ) {
364
-            $question_type = $type->slug;
365
-        }
366
-
367
-        return $question_type;
368
-
369
-    }// end get_question_type
342
+	/**
343
+	 * Get the type of question by id
344
+	 *
345
+	 * This function uses the post terms to determine which question type
346
+	 * the passed question id belongs to.
347
+	 *
348
+	 * @since 1.7.4
349
+	 *
350
+	 * @param int $question_id
351
+	 *
352
+	 * @return string $question_type | bool
353
+	 */
354
+	public function get_question_type( $question_id ){
355
+
356
+		if( empty( $question_id ) || ! intval( $question_id ) > 0
357
+			|| 'question' != get_post_type( $question_id )   ){
358
+			return false;
359
+		}
360
+
361
+		$question_type = 'multiple-choice';
362
+		$question_types = wp_get_post_terms( $question_id, 'question-type' );
363
+		foreach( $question_types as $type ) {
364
+			$question_type = $type->slug;
365
+		}
366
+
367
+		return $question_type;
368
+
369
+	}// end get_question_type
370 370
 
371 371
 	/**
372 372
 	 * Given a question ID, return the grade that can be achieved.
@@ -398,317 +398,317 @@  discard block
 block discarded – undo
398 398
 	} // end get_question_grade
399 399
 
400 400
 
401
-    /**
402
-     * This function simply loads the question type template
403
-     *
404
-     * @since 1.9.0
405
-     * @param $question_type
406
-     */
407
-    public static function load_question_template( $question_type ){
408
-
409
-        Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
-    }
411
-
412
-    /**
413
-     * Echo the sensei question title.
414
-     *
415
-     * @uses WooThemes_Sensei_Question::get_the_question_title
416
-     *
417
-     * @since 1.9.0
418
-     * @param $question_id
419
-     */
420
-    public static function the_question_title( $question_id ){
421
-
422
-        echo self::get_the_question_title( $question_id );
423
-
424
-    }// end the_question_title
425
-
426
-    /**
427
-     * Generate the question title with it's grade.
428
-     *
429
-     * @since 1.9.0
430
-     *
431
-     * @param $question_id
432
-     * @return string
433
-     */
434
-    public static function get_the_question_title( $question_id ){
435
-
436
-        /**
437
-         * Filter the sensei question title
438
-         *
439
-         * @since 1.3.0
440
-         * @param $question_title
441
-         */
442
-        $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
-
444
-        /**
445
-         * hook document in class-woothemes-sensei-message.php the_title()
446
-         */
447
-        $title = apply_filters( 'sensei_single_title', $title, 'question');
448
-
449
-        $title_html  = '<span class="question question-title">';
450
-        $title_html .= $title;
451
-        $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
-        $title_html .='</span>';
453
-
454
-        return $title_html;
455
-    }
456
-
457
-    /**
458
-     * Tech the question description
459
-     *
460
-     * @param $question_id
461
-     * @return string
462
-     */
463
-    public static function get_the_question_description( $question_id ){
464
-
465
-        $question = get_post( $question_id );
466
-
467
-        /**
468
-         * Already documented within WordPress Core
469
-         */
470
-        return apply_filters( 'the_content', $question->post_content );
471
-
472
-    }
473
-
474
-    /**
475
-     * Output the question description
476
-     *
477
-     * @since 1.9.0
478
-     * @param $question_id
479
-     */
480
-    public static function the_question_description( $question_id  ){
481
-
482
-        echo self::get_the_question_description( $question_id );
483
-
484
-    }
485
-
486
-    /**
487
-     * Get the questions media markup
488
-     *
489
-     * @since 1.9.0
490
-     * @param $question_id
491
-     * @return string
492
-     */
493
-    public static function get_the_question_media( $question_id ){
494
-
495
-        $question_media = get_post_meta( $question_id, '_question_media', true );
496
-        $question_media_link = '';
497
-        if( 0 < intval( $question_media ) ) {
498
-            $mimetype = get_post_mime_type( $question_media );
499
-            if( $mimetype ) {
500
-                $mimetype_array = explode( '/', $mimetype);
501
-                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
-                    $question_media_type = $mimetype_array[0];
503
-                    $question_media_url = wp_get_attachment_url( $question_media );
504
-                    $attachment = get_post( $question_media );
505
-                    $question_media_title = $attachment->post_title;
506
-                    $question_media_description = $attachment->post_content;
507
-                    switch( $question_media_type ) {
508
-                        case 'image':
509
-                            $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
-                            $attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
-                            break;
513
-
514
-                        case 'audio':
515
-                            $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
-                            break;
517
-
518
-                        case 'video':
519
-                            $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
-                            break;
521
-
522
-                        default:
523
-                            $question_media_filename = basename( $question_media_url );
524
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
-                            break;
526
-                    }
527
-                }
528
-            }
529
-        }
530
-
531
-        $output = '';
532
-        if( $question_media_link ) {
533
-
534
-                $output .= '<div class="question_media_display">';
535
-                $output .=      $question_media_link;
536
-                $output .= '<dl>';
537
-
538
-                if( $question_media_title ) {
539
-
540
-                   $output .= '<dt>'. $question_media_title. '</dt>';
541
-
542
-                 }
543
-
544
-                if( $question_media_description ) {
545
-
546
-                    $output .= '<dd>' . $question_media_description . '</dd>';
547
-
548
-                }
549
-
550
-                $output .= '</dl>';
551
-                $output .= '</div>';
401
+	/**
402
+	 * This function simply loads the question type template
403
+	 *
404
+	 * @since 1.9.0
405
+	 * @param $question_type
406
+	 */
407
+	public static function load_question_template( $question_type ){
408
+
409
+		Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
+	}
411
+
412
+	/**
413
+	 * Echo the sensei question title.
414
+	 *
415
+	 * @uses WooThemes_Sensei_Question::get_the_question_title
416
+	 *
417
+	 * @since 1.9.0
418
+	 * @param $question_id
419
+	 */
420
+	public static function the_question_title( $question_id ){
421
+
422
+		echo self::get_the_question_title( $question_id );
423
+
424
+	}// end the_question_title
425
+
426
+	/**
427
+	 * Generate the question title with it's grade.
428
+	 *
429
+	 * @since 1.9.0
430
+	 *
431
+	 * @param $question_id
432
+	 * @return string
433
+	 */
434
+	public static function get_the_question_title( $question_id ){
435
+
436
+		/**
437
+		 * Filter the sensei question title
438
+		 *
439
+		 * @since 1.3.0
440
+		 * @param $question_title
441
+		 */
442
+		$title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
+
444
+		/**
445
+		 * hook document in class-woothemes-sensei-message.php the_title()
446
+		 */
447
+		$title = apply_filters( 'sensei_single_title', $title, 'question');
448
+
449
+		$title_html  = '<span class="question question-title">';
450
+		$title_html .= $title;
451
+		$title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
+		$title_html .='</span>';
453
+
454
+		return $title_html;
455
+	}
456
+
457
+	/**
458
+	 * Tech the question description
459
+	 *
460
+	 * @param $question_id
461
+	 * @return string
462
+	 */
463
+	public static function get_the_question_description( $question_id ){
464
+
465
+		$question = get_post( $question_id );
466
+
467
+		/**
468
+		 * Already documented within WordPress Core
469
+		 */
470
+		return apply_filters( 'the_content', $question->post_content );
471
+
472
+	}
473
+
474
+	/**
475
+	 * Output the question description
476
+	 *
477
+	 * @since 1.9.0
478
+	 * @param $question_id
479
+	 */
480
+	public static function the_question_description( $question_id  ){
481
+
482
+		echo self::get_the_question_description( $question_id );
483
+
484
+	}
485
+
486
+	/**
487
+	 * Get the questions media markup
488
+	 *
489
+	 * @since 1.9.0
490
+	 * @param $question_id
491
+	 * @return string
492
+	 */
493
+	public static function get_the_question_media( $question_id ){
494
+
495
+		$question_media = get_post_meta( $question_id, '_question_media', true );
496
+		$question_media_link = '';
497
+		if( 0 < intval( $question_media ) ) {
498
+			$mimetype = get_post_mime_type( $question_media );
499
+			if( $mimetype ) {
500
+				$mimetype_array = explode( '/', $mimetype);
501
+				if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
+					$question_media_type = $mimetype_array[0];
503
+					$question_media_url = wp_get_attachment_url( $question_media );
504
+					$attachment = get_post( $question_media );
505
+					$question_media_title = $attachment->post_title;
506
+					$question_media_description = $attachment->post_content;
507
+					switch( $question_media_type ) {
508
+						case 'image':
509
+							$image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
+							$attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
+							break;
513
+
514
+						case 'audio':
515
+							$question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
+							break;
517
+
518
+						case 'video':
519
+							$question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
+							break;
521
+
522
+						default:
523
+							$question_media_filename = basename( $question_media_url );
524
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
+							break;
526
+					}
527
+				}
528
+			}
529
+		}
530
+
531
+		$output = '';
532
+		if( $question_media_link ) {
552 533
 
534
+				$output .= '<div class="question_media_display">';
535
+				$output .=      $question_media_link;
536
+				$output .= '<dl>';
553 537
 
554
-         }
555
-
556
-        return $output;
557
-
558
-    } // end get_the_question_media
559
-
538
+				if( $question_media_title ) {
560 539
 
561
-    /**
562
-     * Output the question media
563
-     *
564
-     * @since 1.9.0
565
-     * @param string $question_id
566
-     */
567
-    public static function the_question_media( $question_id ){
540
+				   $output .= '<dt>'. $question_media_title. '</dt>';
568 541
 
569
-        echo self::get_the_question_media( $question_id );
542
+				 }
570 543
 
571
-    }
544
+				if( $question_media_description ) {
572 545
 
573
-    /**
574
-     * Output a special field for the question needed for question submission.
575
-     *
576
-     * @since 1.9.0
577
-     *
578
-     * @param $question_id
579
-     */
580
-    public static function the_question_hidden_fields( $question_id ){
581
-        ?>
546
+					$output .= '<dd>' . $question_media_description . '</dd>';
547
+
548
+				}
549
+
550
+				$output .= '</dl>';
551
+				$output .= '</div>';
552
+
553
+
554
+		 }
555
+
556
+		return $output;
557
+
558
+	} // end get_the_question_media
559
+
560
+
561
+	/**
562
+	 * Output the question media
563
+	 *
564
+	 * @since 1.9.0
565
+	 * @param string $question_id
566
+	 */
567
+	public static function the_question_media( $question_id ){
568
+
569
+		echo self::get_the_question_media( $question_id );
570
+
571
+	}
572
+
573
+	/**
574
+	 * Output a special field for the question needed for question submission.
575
+	 *
576
+	 * @since 1.9.0
577
+	 *
578
+	 * @param $question_id
579
+	 */
580
+	public static function the_question_hidden_fields( $question_id ){
581
+		?>
582 582
 
583 583
             <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" />
584 584
             <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" />
585 585
 
586 586
         <?php
587
-    }
587
+	}
588 588
 
589
-    /**
590
-     * This function can only be run withing the single quiz question loop
591
-     *
592
-     * @since 1.9.0
593
-     * @param $question_id
594
-     */
595
-    public static function answer_feedback_notes( $question_id ){
589
+	/**
590
+	 * This function can only be run withing the single quiz question loop
591
+	 *
592
+	 * @since 1.9.0
593
+	 * @param $question_id
594
+	 */
595
+	public static function answer_feedback_notes( $question_id ){
596 596
 
597
-        //IDS
598
-        $quiz_id = get_the_ID();
599
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
597
+		//IDS
598
+		$quiz_id = get_the_ID();
599
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
600 600
 
601
-        // Data to check before showing feedback
602
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
-        $not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
-        $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
-        $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
601
+		// Data to check before showing feedback
602
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
+		$not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
+		$lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
+		$quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
608 608
 
609
-        if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
-            ||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
-            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
609
+		if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
+			||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
+			|| ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
612 612
 
613
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
613
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
614 614
 
615
-            if( $answer_notes ) { ?>
615
+			if( $answer_notes ) { ?>
616 616
 
617 617
                 <div class="sensei-message info info-special answer-feedback">
618 618
 
619 619
                     <?php
620 620
 
621
-                        /**
622
-                         * Filter the answer feedback
623
-                         * Since 1.9.0
624
-                         *
625
-                         * @param string $answer_notes
626
-                         * @param string $question_id
627
-                         * @param string $lesson_id
628
-                         */
629
-                        echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
621
+						/**
622
+						 * Filter the answer feedback
623
+						 * Since 1.9.0
624
+						 *
625
+						 * @param string $answer_notes
626
+						 * @param string $question_id
627
+						 * @param string $lesson_id
628
+						 */
629
+						echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
630 630
 
631
-                    ?>
631
+					?>
632 632
 
633 633
                 </div>
634 634
 
635 635
             <?php }
636 636
 
637
-        }// end if we can show answer feedback
637
+		}// end if we can show answer feedback
638 638
 
639
-    }// end answer_feedback_notes
639
+	}// end answer_feedback_notes
640 640
 
641
-    /**
642
-     * This function has to be run inside the quiz question loop on the single quiz page.
643
-     *
644
-     *
645
-     * @since 1.9.0
646
-     * @param string $question_id
647
-     */
648
-    public static function the_answer_result_indication( $question_id ){
641
+	/**
642
+	 * This function has to be run inside the quiz question loop on the single quiz page.
643
+	 *
644
+	 *
645
+	 * @since 1.9.0
646
+	 * @param string $question_id
647
+	 */
648
+	public static function the_answer_result_indication( $question_id ){
649 649
 
650
-        global $post,  $current_user, $sensei_question_loop;
650
+		global $post,  $current_user, $sensei_question_loop;
651 651
 
652
-        // Post Data
653
-        $quiz_id = $sensei_question_loop['quiz_id'];
654
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
-        $question_item = $sensei_question_loop['current_question'];
652
+		// Post Data
653
+		$quiz_id = $sensei_question_loop['quiz_id'];
654
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
+		$question_item = $sensei_question_loop['current_question'];
656 656
 
657
-        // Setup variable needed to determine if the message should show and what it should show
658
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
-        $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
-        $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
657
+		// Setup variable needed to determine if the message should show and what it should show
658
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
+		$lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
+		$quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
662 662
 
663
-        // retrieve the question total grade
664
-        $question_grade = Sensei()->question->get_question_grade( $question_id );
663
+		// retrieve the question total grade
664
+		$question_grade = Sensei()->question->get_question_grade( $question_id );
665 665
 
666
-        // retrieve grade the user achieved
667
-        $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
666
+		// retrieve grade the user achieved
667
+		$user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
668 668
 
669
-        // Question ID
670
-        $question_id = $question_item->ID;
669
+		// Question ID
670
+		$question_id = $question_item->ID;
671 671
 
672
-        // conditions to check
673
-        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
-        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
-        $grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
672
+		// conditions to check
673
+		$completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
+		$completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
+		$grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
676 676
 
677
-        if (  $completed_with_valid_grade
678
-            || $completed_with_valid_grade_and_reset_not_allowed
679
-            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
677
+		if (  $completed_with_valid_grade
678
+			|| $completed_with_valid_grade_and_reset_not_allowed
679
+			|| $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
680 680
 
681
-            $user_correct = false;
682
-            $answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
-            $answer_message_class = 'user_wrong';
684
-            // For zero grade mark as 'correct' but add no classes
685
-            if ( 0 == $question_grade ) {
681
+			$user_correct = false;
682
+			$answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
+			$answer_message_class = 'user_wrong';
684
+			// For zero grade mark as 'correct' but add no classes
685
+			if ( 0 == $question_grade ) {
686 686
 
687
-                $user_correct = true;
688
-                $answer_message = '';
689
-                $answer_message_class = '';
687
+				$user_correct = true;
688
+				$answer_message = '';
689
+				$answer_message_class = '';
690 690
 
691
-            } else if( $user_question_grade > 0 ) {
691
+			} else if( $user_question_grade > 0 ) {
692 692
 
693
-                $user_correct = true;
694
-                $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
-                $answer_message_class = 'user_right';
693
+				$user_correct = true;
694
+				$answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
+				$answer_message_class = 'user_right';
696 696
 
697
-            }
697
+			}
698 698
 
699
-            // attach the correct answer if the question is auto gradable and user got it wrong
700
-            if( !$reset_quiz_allowed && !$user_correct ){
699
+			// attach the correct answer if the question is auto gradable and user got it wrong
700
+			if( !$reset_quiz_allowed && !$user_correct ){
701 701
 
702
-                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
702
+				$answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
703 703
 
704
-            }
704
+			}
705 705
 
706
-            // answer feedback
707
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
-            if( $answer_notes ) {
709
-                $answer_message_class .= ' has_notes';
710
-            }
711
-            ?>
706
+			// answer feedback
707
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
+			if( $answer_notes ) {
709
+				$answer_message_class .= ' has_notes';
710
+			}
711
+			?>
712 712
 
713 713
             <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>">
714 714
 
@@ -718,387 +718,387 @@  discard block
 block discarded – undo
718 718
 
719 719
             <?php
720 720
 
721
-        } // end if user can see all the goodies
722
-
723
-    }// end the_answer_result_indication
724
-
725
-    /**
726
-     * Generate the question template data and return it as an array.
727
-     *
728
-     * @since 1.9.0
729
-     *
730
-     * @param string $question_id
731
-     * @param $quiz_id
732
-     * @return array $question_data
733
-     */
734
-    public static function get_template_data( $question_id, $quiz_id ){
735
-
736
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
737
-
738
-        $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
-        //backwards compatibility
740
-        if( 'on' == $reset_allowed ) {
741
-            $reset_allowed = 1;
742
-        }
743
-
744
-        // Check again that the lesson is complete
745
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
-        $user_lesson_complete = false;
747
-        if ( $user_lesson_end ) {
748
-            $user_lesson_complete = true;
749
-        }
750
-
751
-        //setup the question data
752
-        $data[ 'ID' ]                     = $question_id;
753
-        $data[ 'title' ]                  = get_the_title( $question_id );
754
-        $data[ 'content' ]                = get_post( $question_id )->post_content;
755
-        $data[ 'quiz_id' ]                = $quiz_id;
756
-        $data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
-        $data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
-        $data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
-        $data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
-        $data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
-        $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
-        $data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
-        $data[ 'lesson_completed' ]       = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
-        $data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
-        $data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
-        $data[ 'lesson_complete' ]        = $user_lesson_complete;
767
-
768
-        /**
769
-         * Filter the question template data. This filter fires  in
770
-         * the get_template_data function
771
-         *
772
-         * @hooked self::boolean_load_question_data
773
-         *
774
-         * @since 1.9.0
775
-         *
776
-         * @param array $data
777
-         * @param string $question_id
778
-         * @param string $quiz_id
779
-         */
780
-        return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
721
+		} // end if user can see all the goodies
781 722
 
782
-    }
723
+	}// end the_answer_result_indication
783 724
 
784
-    /**
785
-     * Load multiple choice question data on the sensei_get_question_template_data
786
-     * filter.
787
-     *
788
-     * @since 1.9.0
789
-     *
790
-     * @param $question_data
791
-     * @param $question_id
792
-     * @param $quiz_id
793
-     *
794
-     * @return array()
795
-     */
796
-    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
725
+	/**
726
+	 * Generate the question template data and return it as an array.
727
+	 *
728
+	 * @since 1.9.0
729
+	 *
730
+	 * @param string $question_id
731
+	 * @param $quiz_id
732
+	 * @return array $question_data
733
+	 */
734
+	public static function get_template_data( $question_id, $quiz_id ){
797 735
 
736
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
798 737
 
799
-        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
738
+		$reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
+		//backwards compatibility
740
+		if( 'on' == $reset_allowed ) {
741
+			$reset_allowed = 1;
742
+		}
800 743
 
801
-            // Get uploaded file
802
-            $attachment_id = $question_data[ 'user_answer_entry' ];
803
-            $answer_media_url = $answer_media_filename = '';
744
+		// Check again that the lesson is complete
745
+		$user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
+		$user_lesson_complete = false;
747
+		if ( $user_lesson_end ) {
748
+			$user_lesson_complete = true;
749
+		}
804 750
 
751
+		//setup the question data
752
+		$data[ 'ID' ]                     = $question_id;
753
+		$data[ 'title' ]                  = get_the_title( $question_id );
754
+		$data[ 'content' ]                = get_post( $question_id )->post_content;
755
+		$data[ 'quiz_id' ]                = $quiz_id;
756
+		$data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
+		$data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
+		$data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
+		$data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
+		$data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
+		$data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
+		$data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
+		$data[ 'lesson_completed' ]       = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
+		$data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
+		$data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
+		$data[ 'lesson_complete' ]        = $user_lesson_complete;
767
+
768
+		/**
769
+		 * Filter the question template data. This filter fires  in
770
+		 * the get_template_data function
771
+		 *
772
+		 * @hooked self::boolean_load_question_data
773
+		 *
774
+		 * @since 1.9.0
775
+		 *
776
+		 * @param array $data
777
+		 * @param string $question_id
778
+		 * @param string $quiz_id
779
+		 */
780
+		return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
805 781
 
806
-            $question_helptext = '';
807
-            if( isset( $question_data['question_wrong_answers'][0] ) ) {
782
+	}
808 783
 
809
-                $question_helptext =  $question_data['question_wrong_answers'][0];
784
+	/**
785
+	 * Load multiple choice question data on the sensei_get_question_template_data
786
+	 * filter.
787
+	 *
788
+	 * @since 1.9.0
789
+	 *
790
+	 * @param $question_data
791
+	 * @param $question_id
792
+	 * @param $quiz_id
793
+	 *
794
+	 * @return array()
795
+	 */
796
+	public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
810 797
 
811
-            }
812 798
 
799
+		if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
813 800
 
814
-            if( 0 < intval( $attachment_id ) ) {
801
+			// Get uploaded file
802
+			$attachment_id = $question_data[ 'user_answer_entry' ];
803
+			$answer_media_url = $answer_media_filename = '';
815 804
 
816
-                $answer_media_url = wp_get_attachment_url( $attachment_id );
817
-                $answer_media_filename = basename( $answer_media_url );
818 805
 
819
-            }
806
+			$question_helptext = '';
807
+			if( isset( $question_data['question_wrong_answers'][0] ) ) {
820 808
 
809
+				$question_helptext =  $question_data['question_wrong_answers'][0];
821 810
 
822
-            // Get max upload file size, formatted for display
823
-            // Code copied from wp-admin/includes/media.php:1515
824
-            $upload_size_unit = $max_upload_size = wp_max_upload_size();
825
-            $sizes = array( 'KB', 'MB', 'GB' );
826
-            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
-                $upload_size_unit /= 1024;
828
-            }
829
-            if ( $u < 0 ) {
811
+			}
830 812
 
831
-                $upload_size_unit = 0;
832
-                $u = 0;
833 813
 
834
-            } else {
814
+			if( 0 < intval( $attachment_id ) ) {
835 815
 
836
-                $upload_size_unit = (int) $upload_size_unit;
816
+				$answer_media_url = wp_get_attachment_url( $attachment_id );
817
+				$answer_media_filename = basename( $answer_media_url );
837 818
 
838
-            }
839
-            $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
819
+			}
840 820
 
841
-            // Assemble all the data needed by the file upload template
842
-            $question_data[ 'answer_media_url' ]      = $answer_media_url;
843
-            $question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
-            $question_data[ 'max_upload_size' ]       = $max_upload_size;
845 821
 
846
-            $question_data[ 'question_helptext' ]     = $question_helptext;
822
+			// Get max upload file size, formatted for display
823
+			// Code copied from wp-admin/includes/media.php:1515
824
+			$upload_size_unit = $max_upload_size = wp_max_upload_size();
825
+			$sizes = array( 'KB', 'MB', 'GB' );
826
+			for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
+				$upload_size_unit /= 1024;
828
+			}
829
+			if ( $u < 0 ) {
847 830
 
848
-        }// end if is file upload type
831
+				$upload_size_unit = 0;
832
+				$u = 0;
849 833
 
850
-        return $question_data;
834
+			} else {
851 835
 
852
-    }// end file_upload_load_question_data
836
+				$upload_size_unit = (int) $upload_size_unit;
853 837
 
854
-    /**
855
-     * Load multiple choice question data on the sensei_get_question_template_data
856
-     * filter.
857
-     *
858
-     * @since 1.9.0
859
-     *
860
-     * @param $question_data
861
-     * @param $question_id
862
-     * @param $quiz_id
863
-     *
864
-     * @return array()
865
-     */
866
-    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
838
+			}
839
+			$max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
867 840
 
868
-        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
841
+			// Assemble all the data needed by the file upload template
842
+			$question_data[ 'answer_media_url' ]      = $answer_media_url;
843
+			$question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
+			$question_data[ 'max_upload_size' ]       = $max_upload_size;
869 845
 
846
+			$question_data[ 'question_helptext' ]     = $question_helptext;
870 847
 
871
-            $answer_type = 'radio';
872
-            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
848
+		}// end if is file upload type
873 849
 
874
-                $answer_type = 'checkbox';
850
+		return $question_data;
875 851
 
876
-            }
852
+	}// end file_upload_load_question_data
877 853
 
878
-            // Merge right and wrong answers
879
-            if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
854
+	/**
855
+	 * Load multiple choice question data on the sensei_get_question_template_data
856
+	 * filter.
857
+	 *
858
+	 * @since 1.9.0
859
+	 *
860
+	 * @param $question_data
861
+	 * @param $question_id
862
+	 * @param $quiz_id
863
+	 *
864
+	 * @return array()
865
+	 */
866
+	public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
880 867
 
881
-                $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
868
+		if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
882 869
 
883
-            }  else {
884 870
 
885
-                array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
-                $merged_options = $question_data[ 'question_wrong_answers' ];
871
+			$answer_type = 'radio';
872
+			if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
887 873
 
888
-            }
874
+				$answer_type = 'checkbox';
889 875
 
890
-            // Setup answer options array.
891
-            $question_answers_options = array();
892
-            $count = 0;
876
+			}
893 877
 
894
-            foreach( $merged_options as $answer ) {
878
+			// Merge right and wrong answers
879
+			if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
895 880
 
896
-                $count++;
897
-                $question_option = array();
881
+				$merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
898 882
 
899
-                if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
-                    || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
-                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
883
+			}  else {
902 884
 
903
-                    $user_correct = false;
885
+				array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
+				$merged_options = $question_data[ 'question_wrong_answers' ];
904 887
 
888
+			}
905 889
 
906
-                    // For zero grade mark as 'correct' but add no classes
907
-                    if ( 0 == $question_data[ 'question_grade' ] ) {
890
+			// Setup answer options array.
891
+			$question_answers_options = array();
892
+			$count = 0;
908 893
 
909
-                        $user_correct = true;
894
+			foreach( $merged_options as $answer ) {
910 895
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
896
+				$count++;
897
+				$question_option = array();
912 898
 
913
-                        $user_correct = true;
899
+				if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
+					|| ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
+					|| ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
914 902
 
915
-                    }
903
+					$user_correct = false;
916 904
 
917
-                }
918 905
 
919
-                // setup the option specific classes
920
-                $answer_class = '';
921
-                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
-                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
906
+					// For zero grade mark as 'correct' but add no classes
907
+					if ( 0 == $question_data[ 'question_grade' ] ) {
923 908
 
924
-                        $answer_class .= ' right_answer';
909
+						$user_correct = true;
925 910
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
911
+					}  else if( $question_data[ 'user_question_grade' ] > 0 ) {
927 912
 
928
-                        $answer_class .= ' right_answer';
913
+						$user_correct = true;
929 914
 
930
-                    } elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
-                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
915
+					}
932 916
 
933
-                        $answer_class = 'user_wrong';
934
-                        if( $user_correct ) {
917
+				}
935 918
 
936
-                            $answer_class = 'user_right';
919
+				// setup the option specific classes
920
+				$answer_class = '';
921
+				if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
+					if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
937 923
 
938
-                        }
924
+						$answer_class .= ' right_answer';
939 925
 
940
-                    }
926
+					}  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
941 927
 
942
-                }
928
+						$answer_class .= ' right_answer';
943 929
 
944
-                // determine if the current option must be checked
945
-                $checked = '';
946
-                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
-                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
930
+					} elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
+						||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
948 932
 
949
-                        $checked = 'checked="checked"';
933
+						$answer_class = 'user_wrong';
934
+						if( $user_correct ) {
950 935
 
951
-                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
936
+							$answer_class = 'user_right';
952 937
 
953
-                        $checked = checked( $answer, $question_data['user_answer_entry'] , false );
938
+						}
954 939
 
955
-                    }
940
+					}
956 941
 
957
-                } // End If Statement
942
+				}
958 943
 
959
-                //Load the answer option data
960
-                $question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
-                $question_option[ 'answer' ]      = $answer;
962
-                $question_option[ 'option_class'] = $answer_class;
963
-                $question_option[ 'checked']      = $checked;
964
-                $question_option[ 'count' ]       = $count;
965
-                $question_option[ 'type' ] = $answer_type;
944
+				// determine if the current option must be checked
945
+				$checked = '';
946
+				if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
+					if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
966 948
 
967
-                // add the speci  fic option to the list of options for this question
968
-                $question_answers_options[$question_option[ 'ID' ]] = $question_option;
949
+						$checked = 'checked="checked"';
969 950
 
970
-            } // end for each option
951
+					} elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
971 952
 
953
+						$checked = checked( $answer, $question_data['user_answer_entry'] , false );
972 954
 
973
-            // Shuffle the array depending on the settings
974
-            $answer_options_sorted = array();
975
-            $random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
-            if(  $random_order && $random_order == 'yes' ) {
955
+					}
977 956
 
978
-                $answer_options_sorted = $question_answers_options;
979
-                shuffle( $answer_options_sorted );
957
+				} // End If Statement
980 958
 
981
-            } else {
959
+				//Load the answer option data
960
+				$question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
+				$question_option[ 'answer' ]      = $answer;
962
+				$question_option[ 'option_class'] = $answer_class;
963
+				$question_option[ 'checked']      = $checked;
964
+				$question_option[ 'count' ]       = $count;
965
+				$question_option[ 'type' ] = $answer_type;
982 966
 
983
-                $answer_order = array();
984
-                $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
-                if( $answer_order_string ) {
967
+				// add the speci  fic option to the list of options for this question
968
+				$question_answers_options[$question_option[ 'ID' ]] = $question_option;
986 969
 
987
-                    $answer_order = array_filter( explode( ',', $answer_order_string ) );
988
-                    if( count( $answer_order ) > 0 ) {
970
+			} // end for each option
989 971
 
990
-                        foreach( $answer_order as $answer_id ) {
991 972
 
992
-                            if( isset( $question_answers_options[ $answer_id ] ) ) {
973
+			// Shuffle the array depending on the settings
974
+			$answer_options_sorted = array();
975
+			$random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
+			if(  $random_order && $random_order == 'yes' ) {
993 977
 
994
-                                $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
-                                unset( $question_answers_options[ $answer_id ] );
978
+				$answer_options_sorted = $question_answers_options;
979
+				shuffle( $answer_options_sorted );
996 980
 
997
-                            }
981
+			} else {
998 982
 
999
-                        }
983
+				$answer_order = array();
984
+				$answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
+				if( $answer_order_string ) {
1000 986
 
1001
-                        if( count( $question_answers_options ) > 0 ) {
1002
-                            foreach( $question_answers_options as $id => $answer ) {
987
+					$answer_order = array_filter( explode( ',', $answer_order_string ) );
988
+					if( count( $answer_order ) > 0 ) {
1003 989
 
1004
-                                $answer_options_sorted[ $id ] = $answer;
990
+						foreach( $answer_order as $answer_id ) {
1005 991
 
1006
-                            }
1007
-                        }
992
+							if( isset( $question_answers_options[ $answer_id ] ) ) {
1008 993
 
1009
-                    }else{
994
+								$answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
+								unset( $question_answers_options[ $answer_id ] );
1010 996
 
1011
-                        $answer_options_sorted = $question_answers_options;
997
+							}
1012 998
 
1013
-                    }
999
+						}
1014 1000
 
1015
-                }else{
1001
+						if( count( $question_answers_options ) > 0 ) {
1002
+							foreach( $question_answers_options as $id => $answer ) {
1016 1003
 
1017
-                    $answer_options_sorted = $question_answers_options;
1004
+								$answer_options_sorted[ $id ] = $answer;
1018 1005
 
1019
-                } // end if $answer_order_string
1006
+							}
1007
+						}
1020 1008
 
1021
-            } // end if random order
1009
+					}else{
1022 1010
 
1011
+						$answer_options_sorted = $question_answers_options;
1023 1012
 
1024
-            // assemble and setup the data for the templates data array
1025
-            $question_data[ 'answer_options' ]    =  $answer_options_sorted;
1013
+					}
1026 1014
 
1027
-        }
1015
+				}else{
1028 1016
 
1029
-        return $question_data;
1017
+					$answer_options_sorted = $question_answers_options;
1030 1018
 
1031
-    }//  end multiple_choice_load_question_data
1019
+				} // end if $answer_order_string
1032 1020
 
1033
-    /**
1034
-     * Load the gap fill question data on the sensei_get_question_template_data
1035
-     * filter.
1036
-     *
1037
-     * @since 1.9.0
1038
-     *
1039
-     * @param $question_data
1040
-     * @param $question_id
1041
-     * @param $quiz_id
1042
-     *
1043
-     * @return array()
1044
-     */
1045
-    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1021
+			} // end if random order
1046 1022
 
1047
-        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048 1023
 
1049
-            $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
-            $question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
-            $question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
-            $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1024
+			// assemble and setup the data for the templates data array
1025
+			$question_data[ 'answer_options' ]    =  $answer_options_sorted;
1053 1026
 
1054
-        }
1027
+		}
1055 1028
 
1056
-        return $question_data;
1029
+		return $question_data;
1057 1030
 
1058
-    }//  end gap_fill_load_question_data
1031
+	}//  end multiple_choice_load_question_data
1032
+
1033
+	/**
1034
+	 * Load the gap fill question data on the sensei_get_question_template_data
1035
+	 * filter.
1036
+	 *
1037
+	 * @since 1.9.0
1038
+	 *
1039
+	 * @param $question_data
1040
+	 * @param $question_id
1041
+	 * @param $quiz_id
1042
+	 *
1043
+	 * @return array()
1044
+	 */
1045
+	public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1046
+
1047
+		if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048
+
1049
+			$gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
+			$question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
+			$question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
+			$question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1053
+
1054
+		}
1055
+
1056
+		return $question_data;
1057
+
1058
+	}//  end gap_fill_load_question_data
1059 1059
 
1060 1060
 
1061
-    /**
1062
-     * Get the correct answer for a question
1063
-     *
1064
-     * @param $question_id
1065
-     * @return string $correct_answer or empty
1066
-     */
1067
-    public static function get_correct_answer( $question_id ){
1061
+	/**
1062
+	 * Get the correct answer for a question
1063
+	 *
1064
+	 * @param $question_id
1065
+	 * @return string $correct_answer or empty
1066
+	 */
1067
+	public static function get_correct_answer( $question_id ){
1068 1068
 
1069
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
-        $type = Sensei()->question->get_question_type( $question_id );
1071
-        $type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
-        $grade_type = 'manual-grade';
1069
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
+		$type = Sensei()->question->get_question_type( $question_id );
1071
+		$type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
+		$grade_type = 'manual-grade';
1073 1073
 
1074
-        if ('boolean'== $type ) {
1074
+		if ('boolean'== $type ) {
1075 1075
 
1076
-            $right_answer = ucfirst($right_answer);
1076
+			$right_answer = ucfirst($right_answer);
1077 1077
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1078
+		}elseif( 'multiple-choice' == $type ) {
1079 1079
 
1080
-            $right_answer = (array) $right_answer;
1081
-            $right_answer = implode( ', ', $right_answer );
1080
+			$right_answer = (array) $right_answer;
1081
+			$right_answer = implode( ', ', $right_answer );
1082 1082
 
1083
-        }elseif( 'gap-fill' == $type ) {
1083
+		}elseif( 'gap-fill' == $type ) {
1084 1084
 
1085
-            $right_answer_array = explode( '||', $right_answer );
1086
-            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
-            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
-            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1085
+			$right_answer_array = explode( '||', $right_answer );
1086
+			if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
+			if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
+			if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1089 1089
 
1090
-            $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1090
+			$right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1091 1091
 
1092
-        }else{
1092
+		}else{
1093 1093
 
1094
-            // for non auto gradable question types no answer should be returned.
1095
-            $right_answer = '';
1094
+			// for non auto gradable question types no answer should be returned.
1095
+			$right_answer = '';
1096 1096
 
1097
-        }
1097
+		}
1098 1098
 
1099
-        return $right_answer;
1099
+		return $right_answer;
1100 1100
 
1101
-    } // get_correct_answer
1101
+	} // get_correct_answer
1102 1102
 
1103 1103
 } // End Class
1104 1104
 
Please login to merge, or discard this patch.