Completed
Push — master ( 80c0ca...82d23b )
by Dwain
04:32
created
includes/class-sensei-teacher.php 4 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      *
364 364
      * @param $course_id
365 365
      * @param $new_teacher_id
366
-     * @return void
366
+     * @return false|null
367 367
      */
368 368
     public static function update_course_modules_author( $course_id ,$new_teacher_id ){
369 369
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
      * @since 1.8.0
455 455
      * @access public
456 456
      * @parameters
457
-     * @return array $users user id array
457
+     * @return boolean $users user id array
458 458
      */
459 459
     public function update_course_lessons_author ( $course_id, $new_author  ){
460 460
 
@@ -843,8 +843,7 @@  discard block
 block discarded – undo
843 843
      * This function hooks into wp_insert_post
844 844
      *
845 845
      * @since 1.8.0
846
-     * @param int $course_id
847
-     * @return bool
846
+     * @return false|null
848 847
      */
849 848
     public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850 849
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Teacher class
@@ -414,7 +417,7 @@  discard block
 block discarded – undo
414 417
                     $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415 418
                     $term_id = $existing_term->term_id;
416 419
 
417
-                }else{
420
+                } else{
418 421
 
419 422
                     // for a new term simply get the term from the returned value
420 423
                     $term_id = $new_term['term_id'];
@@ -495,7 +498,7 @@  discard block
 block discarded – undo
495 498
                         'post_author' =>  $new_author
496 499
                     ) );
497 500
                 }
498
-            }else{
501
+            } else{
499 502
                 wp_update_post( array(
500 503
                     'ID'           => $lesson_quizzes,
501 504
                     'post_author' =>  $new_author
@@ -789,7 +792,7 @@  discard block
 block discarded – undo
789 792
             // merge the post types instead of overwriting it
790 793
             $new_post_types = array_merge( $current_post_types, array( 'course' ) );
791 794
 
792
-        }else{
795
+        } else{
793 796
 
794 797
             // in this instance it is probably just one post type in string format
795 798
             $new_post_types =  array( $current_post_types , 'course');
@@ -979,7 +982,7 @@  discard block
 block discarded – undo
979 982
                     $course_learner_ids[] = $user->ID;
980 983
                 }
981 984
 
982
-            }else{
985
+            } else{
983 986
 
984 987
                 $user = get_userdata( $activity_comments->user_id );
985 988
                 $course_learner_ids[] = $user->ID;
@@ -996,7 +999,7 @@  discard block
 block discarded – undo
996 999
 
997 1000
             $args[ 'include'] = array( 0 );
998 1001
 
999
-        }else{
1002
+        } else{
1000 1003
 
1001 1004
             $args[ 'include'] = $learner_ids_for_teacher_courses;
1002 1005
 
@@ -1164,7 +1167,7 @@  discard block
 block discarded – undo
1164 1167
 
1165 1168
                 $teachers_courses[] = $course->ID;
1166 1169
 
1167
-            }else{
1170
+            } else{
1168 1171
 
1169 1172
                 $teachers_courses[] = $course;
1170 1173
 
@@ -1534,7 +1537,7 @@  discard block
 block discarded – undo
1534 1537
 
1535 1538
             return true;
1536 1539
 
1537
-        }else{
1540
+        } else{
1538 1541
 
1539 1542
             return false;
1540 1543
 
Please login to merge, or discard this patch.
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -14,251 +14,251 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Teacher {
16 16
 
17
-    /**
18
-     * $teacher_role
19
-     *
20
-     * Keeps a reference to the teacher role object
21
-     *
22
-     * @access protected
23
-     * @since 1.8.0
24
-     */
25
-    protected $teacher_role;
26
-
27
-    /**
28
-     * $token
29
-     *
30
-     * Keeps a reference to the global sensei token
31
-     *
32
-     * @access protected
33
-     * @since 1.8.0
34
-     */
35
-    public  $token;
36
-
37
-    /**
38
-     * Sensei_Teacher::__constructor
39
-     *
40
-     * Constructor Function
41
-     *
42
-     * @since 1.8.0
43
-     * @access public
44
-     */
45
-    public function __construct ( ) {
46
-
47
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
52
-
53
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
54
-
55
-        //filter the quiz submissions
56
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
57
-
58
-        //grading totals count only those belonging to the teacher
59
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
60
-
61
-        // show the courses owned by a user on his author archive page
62
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
63
-
64
-        // notify admin when a teacher creates a course
65
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
66
-
67
-        // limit the analysis view to only the users taking courses belong to this teacher
68
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
69
-
70
-        // give teacher access to question post type
71
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
72
-
73
-        // Teacher column on the courses list on the admin edit screen
74
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
76
-
77
-        //admin edit messages query limit teacher
78
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
79
-
80
-        //add filter by teacher on courses list
81
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
83
-
84
-        // Handle media library restrictions
85
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
87
-
88
-        // update lesson owner to course teacher when saved
89
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
90
-
91
-        // If a Teacher logs in, redirect to /wp-admin/
92
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
93
-
94
-
95
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
97
-
98
-
99
-    } // end __constructor()
100
-
101
-    /**
102
-     * Sensei_Teacher::create_teacher_role
103
-     *
104
-     * This function checks if the role exist, if not it creates it.
105
-     * for the teacher role
106
-     *
107
-     * @since 1.8.0
108
-     * @access public
109
-     * @return void
110
-     */
111
-    public function create_role ( ) {
112
-
113
-        // check if the role exists
114
-        $this->teacher_role = get_role( 'teacher' );
115
-
116
-        // if the the teacher is not a valid WordPress role create it
117
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
118
-           // create the role
119
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
120
-       }
121
-
122
-       // add the capabilities before returning
123
-        $this->add_capabilities();
124
-
125
-    }// end create_teacher_role
126
-
127
-    /**
128
-     * Sensei_Teacher::add_capabilities
129
-     *
130
-     * @since 1.8.0
131
-     * @access protected
132
-     */
133
-    protected function add_capabilities ( ) {
134
-
135
-        // if this is not a valid WP_Role object exit without adding anything
136
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
137
-            return;
138
-        }
139
-
140
-        /**
141
-         * Sensei teachers capabilities array filter
142
-         *
143
-         * These capabilities will be applied to the teacher role
144
-         * @param array $capabilities
145
-         * keys: (string) $cap_name => (bool) $grant
146
-         */
147
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
148
-            // General access rules
149
-            'read' => true,
150
-            'manage_sensei_grades' => true,
151
-            'moderate_comments'=> true,
152
-            'upload_files'	=> true,
153
-            'edit_files'	=> true,
154
-
155
-            //Lessons
156
-            'publish_lessons'	 => true,
157
-            'manage_lesson_categories'	 => true,
158
-            'edit_lessons'	 => true,
159
-            'edit_published_lessons'  => true,
160
-            'edit_private_lessons' => true,
161
-            'read_private_lessons' => true,
162
-            'delete_published_lessons' => true,
163
-
164
-            // Courses
165
-            'create_courses' => true,
166
-            'publish_courses'	 => false,
167
-            'manage_course_categories'	 => true,
168
-            'edit_courses'	 => true,
169
-            'edit_published_courses'  => true,
170
-            'edit_private_courses' => true,
171
-            'read_private_courses' => true,
172
-            'delete_published_courses' => true,
173
-
174
-            // Quiz
175
-            'publish_quizzes'	 => true,
176
-            'edit_quizzes'	 => true,
177
-            'edit_published_quizzes'  => true,
178
-            'edit_private_quizzes' => true,
179
-            'read_private_quizzes' => true,
180
-
181
-            // Questions
182
-            'publish_questions'	 => true,
183
-            'edit_questions'	 => true,
184
-            'edit_published_questions'  => true,
185
-            'edit_private_questions' => true,
186
-            'read_private_questions' => true,
187
-
188
-            //messages
189
-            'publish_sensei_messages'	 => true,
190
-            'edit_sensei_messages'	 => true,
191
-            'edit_published_sensei_messages'  => true,
192
-            'edit_private_sensei_messages' => true,
193
-            'read_private_sensei_messages' => true,
194
-
195
-            // Comments -
196
-            // Necessary cap so Teachers can moderate comments
197
-            // on their own lessons. We restrict access to other
198
-            // post types in $this->restrict_posts_menu_page()
199
-
200
-            'edit_posts' => true,
201
-
202
-        ));
203
-
204
-        foreach ( $caps as $cap => $grant ) {
205
-
206
-            // load the capability on to the teacher role
207
-            $this->teacher_role->add_cap($cap, $grant);
208
-
209
-        } // end for each
210
-
211
-    }// end add_cap
212
-
213
-    /**
214
-     * Sensei_Teacher::teacher_meta_box
215
-     *
216
-     * Add the teacher metabox to the course post type edit screen
217
-     *
218
-     * @since 1.8.0
219
-     * @access public
220
-     * @parameter string $post_type
221
-     * @parameter WP_Post $post
222
-     * @return void
223
-     */
224
-    public function add_teacher_meta_boxes ( $post ) {
225
-
226
-        if( !current_user_can('manage_options') ){
227
-            return;
228
-        }
229
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
230
-            'course',
231
-            'side',
232
-            'core'
233
-        );
234
-
235
-    } // end teacher_meta_box()
236
-
237
-    /**
238
-     * Sensei_Teacher::teacher_meta_box_content
239
-     *
240
-     * Render the teacher meta box markup
241
-     *
242
-     * @since 1.8.0
243
-     * @access public
244
-     * @parameters
245
-     */
246
-    public function teacher_meta_box_content ( $post ) {
247
-
248
-        // get the current author
249
-        $current_author = $post->post_author;
250
-
251
-        //get the users authorised to author courses
252
-        $users = $this->get_teachers_and_authors();
253
-
254
-    ?>
17
+	/**
18
+	 * $teacher_role
19
+	 *
20
+	 * Keeps a reference to the teacher role object
21
+	 *
22
+	 * @access protected
23
+	 * @since 1.8.0
24
+	 */
25
+	protected $teacher_role;
26
+
27
+	/**
28
+	 * $token
29
+	 *
30
+	 * Keeps a reference to the global sensei token
31
+	 *
32
+	 * @access protected
33
+	 * @since 1.8.0
34
+	 */
35
+	public  $token;
36
+
37
+	/**
38
+	 * Sensei_Teacher::__constructor
39
+	 *
40
+	 * Constructor Function
41
+	 *
42
+	 * @since 1.8.0
43
+	 * @access public
44
+	 */
45
+	public function __construct ( ) {
46
+
47
+		add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
+		add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
+		add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
+		add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
+		add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
52
+
53
+		add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
54
+
55
+		//filter the quiz submissions
56
+		add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
57
+
58
+		//grading totals count only those belonging to the teacher
59
+		add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
60
+
61
+		// show the courses owned by a user on his author archive page
62
+		add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
63
+
64
+		// notify admin when a teacher creates a course
65
+		add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
66
+
67
+		// limit the analysis view to only the users taking courses belong to this teacher
68
+		add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
69
+
70
+		// give teacher access to question post type
71
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
72
+
73
+		// Teacher column on the courses list on the admin edit screen
74
+		add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
+		add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
76
+
77
+		//admin edit messages query limit teacher
78
+		add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
79
+
80
+		//add filter by teacher on courses list
81
+		add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
+		add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
83
+
84
+		// Handle media library restrictions
85
+		add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
+		add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
87
+
88
+		// update lesson owner to course teacher when saved
89
+		add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
90
+
91
+		// If a Teacher logs in, redirect to /wp-admin/
92
+		add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
93
+
94
+
95
+		add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
+		add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
97
+
98
+
99
+	} // end __constructor()
100
+
101
+	/**
102
+	 * Sensei_Teacher::create_teacher_role
103
+	 *
104
+	 * This function checks if the role exist, if not it creates it.
105
+	 * for the teacher role
106
+	 *
107
+	 * @since 1.8.0
108
+	 * @access public
109
+	 * @return void
110
+	 */
111
+	public function create_role ( ) {
112
+
113
+		// check if the role exists
114
+		$this->teacher_role = get_role( 'teacher' );
115
+
116
+		// if the the teacher is not a valid WordPress role create it
117
+	   if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
118
+		   // create the role
119
+		   $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
120
+	   }
121
+
122
+	   // add the capabilities before returning
123
+		$this->add_capabilities();
124
+
125
+	}// end create_teacher_role
126
+
127
+	/**
128
+	 * Sensei_Teacher::add_capabilities
129
+	 *
130
+	 * @since 1.8.0
131
+	 * @access protected
132
+	 */
133
+	protected function add_capabilities ( ) {
134
+
135
+		// if this is not a valid WP_Role object exit without adding anything
136
+		if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
137
+			return;
138
+		}
139
+
140
+		/**
141
+		 * Sensei teachers capabilities array filter
142
+		 *
143
+		 * These capabilities will be applied to the teacher role
144
+		 * @param array $capabilities
145
+		 * keys: (string) $cap_name => (bool) $grant
146
+		 */
147
+		$caps = apply_filters( 'sensei_teacher_role_capabilities', array(
148
+			// General access rules
149
+			'read' => true,
150
+			'manage_sensei_grades' => true,
151
+			'moderate_comments'=> true,
152
+			'upload_files'	=> true,
153
+			'edit_files'	=> true,
154
+
155
+			//Lessons
156
+			'publish_lessons'	 => true,
157
+			'manage_lesson_categories'	 => true,
158
+			'edit_lessons'	 => true,
159
+			'edit_published_lessons'  => true,
160
+			'edit_private_lessons' => true,
161
+			'read_private_lessons' => true,
162
+			'delete_published_lessons' => true,
163
+
164
+			// Courses
165
+			'create_courses' => true,
166
+			'publish_courses'	 => false,
167
+			'manage_course_categories'	 => true,
168
+			'edit_courses'	 => true,
169
+			'edit_published_courses'  => true,
170
+			'edit_private_courses' => true,
171
+			'read_private_courses' => true,
172
+			'delete_published_courses' => true,
173
+
174
+			// Quiz
175
+			'publish_quizzes'	 => true,
176
+			'edit_quizzes'	 => true,
177
+			'edit_published_quizzes'  => true,
178
+			'edit_private_quizzes' => true,
179
+			'read_private_quizzes' => true,
180
+
181
+			// Questions
182
+			'publish_questions'	 => true,
183
+			'edit_questions'	 => true,
184
+			'edit_published_questions'  => true,
185
+			'edit_private_questions' => true,
186
+			'read_private_questions' => true,
187
+
188
+			//messages
189
+			'publish_sensei_messages'	 => true,
190
+			'edit_sensei_messages'	 => true,
191
+			'edit_published_sensei_messages'  => true,
192
+			'edit_private_sensei_messages' => true,
193
+			'read_private_sensei_messages' => true,
194
+
195
+			// Comments -
196
+			// Necessary cap so Teachers can moderate comments
197
+			// on their own lessons. We restrict access to other
198
+			// post types in $this->restrict_posts_menu_page()
199
+
200
+			'edit_posts' => true,
201
+
202
+		));
203
+
204
+		foreach ( $caps as $cap => $grant ) {
205
+
206
+			// load the capability on to the teacher role
207
+			$this->teacher_role->add_cap($cap, $grant);
208
+
209
+		} // end for each
210
+
211
+	}// end add_cap
212
+
213
+	/**
214
+	 * Sensei_Teacher::teacher_meta_box
215
+	 *
216
+	 * Add the teacher metabox to the course post type edit screen
217
+	 *
218
+	 * @since 1.8.0
219
+	 * @access public
220
+	 * @parameter string $post_type
221
+	 * @parameter WP_Post $post
222
+	 * @return void
223
+	 */
224
+	public function add_teacher_meta_boxes ( $post ) {
225
+
226
+		if( !current_user_can('manage_options') ){
227
+			return;
228
+		}
229
+		add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
230
+			'course',
231
+			'side',
232
+			'core'
233
+		);
234
+
235
+	} // end teacher_meta_box()
236
+
237
+	/**
238
+	 * Sensei_Teacher::teacher_meta_box_content
239
+	 *
240
+	 * Render the teacher meta box markup
241
+	 *
242
+	 * @since 1.8.0
243
+	 * @access public
244
+	 * @parameters
245
+	 */
246
+	public function teacher_meta_box_content ( $post ) {
247
+
248
+		// get the current author
249
+		$current_author = $post->post_author;
250
+
251
+		//get the users authorised to author courses
252
+		$users = $this->get_teachers_and_authors();
253
+
254
+	?>
255 255
         <select name="sensei-course-teacher-author" class="sensei course teacher">
256 256
 
257 257
             <?php foreach ( $users as $user_id ) { ?>
258 258
 
259 259
                     <?php
260
-                        $user = get_user_by('id', $user_id);
261
-                    ?>
260
+						$user = get_user_by('id', $user_id);
261
+					?>
262 262
                     <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
263 263
                         <?php echo  $user->display_name; ?>
264 264
                     </option>
@@ -269,1289 +269,1289 @@  discard block
 block discarded – undo
269 269
 
270 270
         <?php
271 271
 
272
-    } // end render_teacher_meta_box()
273
-
274
-    /**
275
-     * Sensei_Teacher::get_teachers_and_authors
276
-     *
277
-     * Get a list of users who can author courses, lessons and quizes.
278
-     *
279
-     * @since 1.8.0
280
-     * @access public
281
-     * @parameters
282
-     * @return array $users user id array
283
-     */
284
-    public function get_teachers_and_authors ( ){
285
-
286
-        $author_query_args = array(
287
-            'blog_id'      => $GLOBALS['blog_id'],
288
-            'fields'       => 'any',
289
-            'who'          => 'authors'
290
-        );
291
-
292
-        $authors = get_users( $author_query_args );
293
-
294
-        $teacher_query_args = array(
295
-            'blog_id'      => $GLOBALS['blog_id'],
296
-            'fields'       => 'any',
297
-            'role'         => 'teacher',
298
-        );
299
-
300
-        $teachers = get_users( $teacher_query_args );
301
-
302
-        return  array_unique( array_merge( $teachers, $authors ) );
303
-
304
-    }// end get_teachers_and_authors
305
-
306
-    /**
307
-     * Sensei_Teacher::save_teacher_meta_box
308
-     *
309
-     * Save the new teacher / author to course and all lessons
310
-     *
311
-     * Hooked into admin_init
312
-     *
313
-     * @since 1.8.0
314
-     * @access public
315
-     * @parameters
316
-     * @return array $users user id array
317
-     */
318
-    public function save_teacher_meta_box ( $course_id ){
272
+	} // end render_teacher_meta_box()
273
+
274
+	/**
275
+	 * Sensei_Teacher::get_teachers_and_authors
276
+	 *
277
+	 * Get a list of users who can author courses, lessons and quizes.
278
+	 *
279
+	 * @since 1.8.0
280
+	 * @access public
281
+	 * @parameters
282
+	 * @return array $users user id array
283
+	 */
284
+	public function get_teachers_and_authors ( ){
285
+
286
+		$author_query_args = array(
287
+			'blog_id'      => $GLOBALS['blog_id'],
288
+			'fields'       => 'any',
289
+			'who'          => 'authors'
290
+		);
291
+
292
+		$authors = get_users( $author_query_args );
293
+
294
+		$teacher_query_args = array(
295
+			'blog_id'      => $GLOBALS['blog_id'],
296
+			'fields'       => 'any',
297
+			'role'         => 'teacher',
298
+		);
299
+
300
+		$teachers = get_users( $teacher_query_args );
301
+
302
+		return  array_unique( array_merge( $teachers, $authors ) );
303
+
304
+	}// end get_teachers_and_authors
305
+
306
+	/**
307
+	 * Sensei_Teacher::save_teacher_meta_box
308
+	 *
309
+	 * Save the new teacher / author to course and all lessons
310
+	 *
311
+	 * Hooked into admin_init
312
+	 *
313
+	 * @since 1.8.0
314
+	 * @access public
315
+	 * @parameters
316
+	 * @return array $users user id array
317
+	 */
318
+	public function save_teacher_meta_box ( $course_id ){
319 319
 
320
-        // check if this is a post from saving the teacher, if not exit early
321
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
322
-            return;
323
-        }
320
+		// check if this is a post from saving the teacher, if not exit early
321
+		if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
322
+			return;
323
+		}
324 324
 
325
-        //don't fire this hook again
326
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
325
+		//don't fire this hook again
326
+		remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
327 327
 
328
-        // get the current post object
329
-        $post = get_post( $course_id );
328
+		// get the current post object
329
+		$post = get_post( $course_id );
330 330
 
331
-        // get the current teacher/author
332
-        $current_author = absint( $post->post_author );
333
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
331
+		// get the current teacher/author
332
+		$current_author = absint( $post->post_author );
333
+		$new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
334 334
 
335
-        // loop through all post lessons to update their authors as well
336
-        $this->update_course_lessons_author( $course_id , $new_author );
335
+		// loop through all post lessons to update their authors as well
336
+		$this->update_course_lessons_author( $course_id , $new_author );
337 337
 
338
-        // do not do any processing if the selected author is the same as the current author
339
-        if( $current_author == $new_author ){
340
-            return;
341
-        }
338
+		// do not do any processing if the selected author is the same as the current author
339
+		if( $current_author == $new_author ){
340
+			return;
341
+		}
342 342
 
343
-        // save the course  author
344
-        $post_updates = array(
345
-            'ID' => $post->ID ,
346
-            'post_author' => $new_author
347
-        );
348
-        wp_update_post( $post_updates );
343
+		// save the course  author
344
+		$post_updates = array(
345
+			'ID' => $post->ID ,
346
+			'post_author' => $new_author
347
+		);
348
+		wp_update_post( $post_updates );
349 349
 
350
-        // ensure the the modules are update so that then new teacher has access to them
351
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
350
+		// ensure the the modules are update so that then new teacher has access to them
351
+		Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
352 352
 
353
-        // notify the new teacher
354
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
353
+		// notify the new teacher
354
+		$this->teacher_course_assigned_notification( $new_author, $course_id );
355 355
 
356
-    } // end save_teacher_meta_box
356
+	} // end save_teacher_meta_box
357 357
 
358
-    /**
359
-     * Update all the course terms set(selected) on the given course. Moving course term ownership to
360
-     * the new author. Making sure the course terms are maintained.
361
-     *
362
-     * This function also checks if terms are shared, with other courses
363
-     *
364
-     * @param $course_id
365
-     * @param $new_teacher_id
366
-     * @return void
367
-     */
368
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
358
+	/**
359
+	 * Update all the course terms set(selected) on the given course. Moving course term ownership to
360
+	 * the new author. Making sure the course terms are maintained.
361
+	 *
362
+	 * This function also checks if terms are shared, with other courses
363
+	 *
364
+	 * @param $course_id
365
+	 * @param $new_teacher_id
366
+	 * @return void
367
+	 */
368
+	public static function update_course_modules_author( $course_id ,$new_teacher_id ){
369 369
 
370
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
371
-            return false;
372
-        }
370
+		if( empty( $course_id ) || empty( $new_teacher_id ) ){
371
+			return false;
372
+		}
373 373
 
374
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
374
+		$terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
375 375
 
376
-        if( empty( $terms_selected_on_course ) ){
377
-            return;
378
-        }
376
+		if( empty( $terms_selected_on_course ) ){
377
+			return;
378
+		}
379 379
 
380
-        foreach( $terms_selected_on_course as $term ){
380
+		foreach( $terms_selected_on_course as $term ){
381 381
 
382
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
-            if( $new_teacher_id != $term_author->ID  ){
382
+			$term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
+			if( $new_teacher_id != $term_author->ID  ){
384 384
 
385
-                $new_term = '';
385
+				$new_term = '';
386 386
 
387
-                //if the new teacher is admin first check to see if the term with this name already exists
388
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
387
+				//if the new teacher is admin first check to see if the term with this name already exists
388
+				if( user_can( $new_teacher_id, 'manage_options' ) ){
389 389
 
390
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
-                    $existing_admin_terms = get_terms( 'module', $term_args );
393
-                    if( !empty( $existing_admin_terms ) ){
394
-                        // insert it even if it exists
395
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
396
-                    }
397
-                }
390
+					$slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
+					$term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
+					$existing_admin_terms = get_terms( 'module', $term_args );
393
+					if( !empty( $existing_admin_terms ) ){
394
+						// insert it even if it exists
395
+						$new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
396
+					}
397
+				}
398 398
 
399
-                if( empty ( $new_term ) ){
399
+				if( empty ( $new_term ) ){
400 400
 
401
-                   //setup the new slug
402
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
403
-
404
-                   // create new term and set it
405
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
406
-
407
-                }
401
+				   //setup the new slug
402
+				   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
403
+
404
+				   // create new term and set it
405
+				   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
406
+
407
+				}
408 408
 
409 409
 
410 410
 
411
-                // if term exists
412
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
411
+				// if term exists
412
+				if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
413 413
 
414
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415
-                    $term_id = $existing_term->term_id;
414
+					$existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415
+					$term_id = $existing_term->term_id;
416 416
 
417
-                }else{
417
+				}else{
418 418
 
419
-                    // for a new term simply get the term from the returned value
420
-                    $term_id = $new_term['term_id'];
419
+					// for a new term simply get the term from the returned value
420
+					$term_id = $new_term['term_id'];
421 421
 
422
-                } // end if term exist
422
+				} // end if term exist
423 423
 
424
-                // set the terms selected on the course
425
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
424
+				// set the terms selected on the course
425
+				wp_set_object_terms( $course_id, $term_id , 'module', true );
426 426
 
427
-                // remove old term
428
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
427
+				// remove old term
428
+				wp_remove_object_terms( $course_id, $term->term_id, 'module' );
429 429
 
430
-                // update the lessons within the current module term
431
-                $lessons = Sensei()->course->course_lessons( $course_id );
432
-                foreach( $lessons as $lesson  ){
430
+				// update the lessons within the current module term
431
+				$lessons = Sensei()->course->course_lessons( $course_id );
432
+				foreach( $lessons as $lesson  ){
433 433
 
434
-                    if( has_term( $term->slug, 'module', $lesson ) ){
434
+					if( has_term( $term->slug, 'module', $lesson ) ){
435 435
 
436
-                        // add the new term, the false at the end says to replace all terms on this module
437
-                        // with the new term.
438
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
440
-                    }
436
+						// add the new term, the false at the end says to replace all terms on this module
437
+						// with the new term.
438
+						wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
+						update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
440
+					}
441 441
 
442
-                }// end for each
442
+				}// end for each
443 443
 
444
-            }
445
-        }
444
+			}
445
+		}
446 446
 
447
-    }// end update_course_module_terms_author
447
+	}// end update_course_module_terms_author
448 448
 
449
-    /**
450
-     * Sensei_Teacher::update_course_lessons_author
451
-     *
452
-     * Update all course lessons and their quiz with a new author
453
-     *
454
-     * @since 1.8.0
455
-     * @access public
456
-     * @parameters
457
-     * @return array $users user id array
458
-     */
459
-    public function update_course_lessons_author ( $course_id, $new_author  ){
449
+	/**
450
+	 * Sensei_Teacher::update_course_lessons_author
451
+	 *
452
+	 * Update all course lessons and their quiz with a new author
453
+	 *
454
+	 * @since 1.8.0
455
+	 * @access public
456
+	 * @parameters
457
+	 * @return array $users user id array
458
+	 */
459
+	public function update_course_lessons_author ( $course_id, $new_author  ){
460 460
 
461 461
 
462
-        if( empty( $course_id ) || empty( $new_author ) ){
463
-            return false;
464
-        }
462
+		if( empty( $course_id ) || empty( $new_author ) ){
463
+			return false;
464
+		}
465 465
 
466
-        //get a list of course lessons
467
-        $lessons = Sensei()->course->course_lessons( $course_id );
466
+		//get a list of course lessons
467
+		$lessons = Sensei()->course->course_lessons( $course_id );
468 468
 
469
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
470
-            return false;
471
-        }
469
+		if( empty( $lessons )  ||  ! is_array( $lessons )  ){
470
+			return false;
471
+		}
472 472
 
473
-        // update each lesson and quiz author
474
-        foreach( $lessons as $lesson ){
473
+		// update each lesson and quiz author
474
+		foreach( $lessons as $lesson ){
475 475
 
476
-            // don't update if the author is tha same as the new author
477
-            if( $new_author == $lesson->post_author ){
478
-                continue;
479
-            }
476
+			// don't update if the author is tha same as the new author
477
+			if( $new_author == $lesson->post_author ){
478
+				continue;
479
+			}
480 480
 
481
-            // update lesson author
482
-            wp_update_post( array(
483
-                'ID'=> $lesson->ID,
484
-                'post_author' => $new_author
485
-                ) );
481
+			// update lesson author
482
+			wp_update_post( array(
483
+				'ID'=> $lesson->ID,
484
+				'post_author' => $new_author
485
+				) );
486 486
 
487
-            // update quiz author
488
-            //get the lessons quiz
489
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
-            if( is_array( $lesson_quizzes ) ){
491
-                foreach ( $lesson_quizzes as $quiz_id ) {
492
-                    // update quiz with new author
493
-                    wp_update_post( array(
494
-                        'ID'           => $quiz_id,
495
-                        'post_author' =>  $new_author
496
-                    ) );
497
-                }
498
-            }else{
499
-                wp_update_post( array(
500
-                    'ID'           => $lesson_quizzes,
501
-                    'post_author' =>  $new_author
502
-                ) );
503
-            }
487
+			// update quiz author
488
+			//get the lessons quiz
489
+			$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
+			if( is_array( $lesson_quizzes ) ){
491
+				foreach ( $lesson_quizzes as $quiz_id ) {
492
+					// update quiz with new author
493
+					wp_update_post( array(
494
+						'ID'           => $quiz_id,
495
+						'post_author' =>  $new_author
496
+					) );
497
+				}
498
+			}else{
499
+				wp_update_post( array(
500
+					'ID'           => $lesson_quizzes,
501
+					'post_author' =>  $new_author
502
+				) );
503
+			}
504 504
 
505
-        } // end for each lessons
505
+		} // end for each lessons
506 506
 
507
-        return true;
507
+		return true;
508 508
 
509
-    }// end update_course_lessons_author
510
-
511
-
512
-
513
-    /**
514
-     * Sensei_Teacher::course_analysis_teacher_access_limit
515
-     *
516
-     * Alter the query so that users can only see their courses on the analysis page
517
-     *
518
-     * @since 1.8.0
519
-     * @access public
520
-     * @parameters $query
521
-     * @return array $users user id array
522
-     */
523
-    public function course_analysis_teacher_access_limit ( $query ) {
524
-
525
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
526
-            return $query;
527
-        }
528
-
529
-        if ( ! function_exists( 'get_current_screen' ) ) {
530
-            return $query;
531
-        }
532
-
533
-        $screen = get_current_screen();
534
-        $sensei_post_types = array('course', 'lesson', 'question' );
535
-
536
-        // exit early for the following conditions
537
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
538
-
539
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
541
-            return $query;
542
-        }
543
-
544
-        global $current_user;
545
-        // set the query author to the current user to only show those those posts
546
-        $query->set( 'author', $current_user->ID );
547
-        return $query;
548
-
549
-    }// end course_analysis_teacher_access_limit
550
-
551
-
552
-    /**
553
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
554
-     *
555
-     * Determine if we're in admin and the current logged in use is a teacher
556
-     *
557
-     * @since 1.8.0
558
-     * @access public
559
-     * @parameters array $wp_query
560
-     * @return bool $is_admin_teacher
561
-     */
562
-    public function is_admin_teacher ( ){
563
-
564
-        if( ! is_user_logged_in()){
565
-            return false;
566
-        }
567
-        $is_admin_teacher = false;
568
-
569
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
570
-
571
-            $is_admin_teacher = true;
572
-
573
-        }
574
-
575
-        return $is_admin_teacher;
576
-
577
-    } // end is_admin_teacher
578
-
579
-    /**
580
-     * Show correct post counts on list table for Sensei post types
581
-     *
582
-     * @since 1.8.0
583
-     *
584
-     * @param  object $counts Default status counts
585
-     * @param  string $type   Current post type
586
-     * @param  string $perm   User permission level
587
-     * @return object         Modified status counts
588
-     */
589
-    public function list_table_counts( $counts, $type, $perm ) {
590
-        global $current_user;
591
-
592
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
593
-            return $counts;
594
-        }
595
-
596
-        if( ! $this->is_admin_teacher() ) {
597
-            return $counts;
598
-        }
599
-
600
-        $args = array(
601
-            'post_type' => $type,
602
-            'author' => $current_user->ID,
603
-            'posts_per_page' => -1
604
-        );
605
-
606
-         // Get all available statuses
607
-        $stati = get_post_stati();
608
-
609
-        // Update count object
610
-        foreach( $stati as $status ) {
611
-            $args['post_status'] = $status;
612
-            $posts = get_posts( $args );
613
-            $counts->$status = count( $posts );
614
-        }
615
-
616
-        return $counts;
617
-    }
618
-
619
-    /**
620
-     * Filter the post queries to show
621
-     * only lesson /course and users that belong
622
-     * to the current logged teacher.
623
-     *
624
-     * @since 1.8.0
625
-     *
626
-     */
627
-    public function filter_queries ( $query ) {
628
-        global $current_user;
629
-
630
-        if( ! $this->is_admin_teacher() ) {
631
-            return;
632
-        }
633
-
634
-        if ( ! function_exists( 'get_current_screen' ) ) {
635
-            return;
636
-        }
637
-
638
-        $screen = get_current_screen();
639
-        if( empty( $screen ) ) {
640
-            return $query;
641
-        }
642
-        switch( $screen->id ) {
643
-            case 'sensei_page_sensei_grading':
644
-            case 'sensei_page_sensei_analysis':
645
-            case 'sensei_page_sensei_learners':
646
-            case 'lesson':
647
-            case 'course':
648
-            case 'question':
649
-            case 'lesson_page_module-order':
650
-
651
-            /**
652
-             * sensei_filter_queries_set_author
653
-             * Filter the author Sensei set for queries
654
-             *
655
-             * @since 1.8.0
656
-             *
657
-             * @param int $user_id
658
-             * @param string $screen_id
659
-             *
660
-             */
661
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
662
-            break;
663
-        }
664
-    }
665
-
666
-    /**
667
-     * Limit grading quizzes to only those within courses belonging to the current teacher
668
-     * . This excludes the admin user.
669
-     *
670
-     * @since 1.8.0
671
-     * @hooked into the_comments
672
-     * @param array  $comments
673
-     *
674
-     * @return array $comments
675
-     */
676
-    public function filter_grading_activity_queries( $comments ){
677
-
678
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
-            return $comments ;
680
-        }
681
-
682
-        //check if we're on the grading screen
683
-        $screen = get_current_screen();
684
-
685
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
686
-            return $comments;
687
-        }
688
-
689
-        // get the course and determine if the current teacher is the owner
690
-        // if not remove it from the list of comments to be returned
691
-        foreach( $comments as $key => $comment){
692
-            $lesson = get_post( $comment->comment_post_ID );
693
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
-            $course = get_post( $course_id );
695
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
696
-                //remove this as the teacher should see this.
697
-                unset( $comments[ $key ] );
698
-            }
699
-        }
700
-        return $comments ;
701
-
702
-    }// end function filter grading
703
-
704
-    /**
705
-     * Limit the grading screen totals to only show lessons in the course
706
-     * belonging to the currently logged in teacher. This only applies to
707
-     * the teacher role.
708
-     *
709
-     * @since 1.8.0
710
-     *
711
-     * @hooked into sensei_count_statuses_args
712
-     * @param array $args
713
-     *
714
-     * @return array  $args
715
-     */
716
-    public function limit_grading_totals( $args ){
717
-
718
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
-            return $args ;
720
-        }
721
-
722
-        //get the teachers courses
723
-        // the query is already filtered to only the teacher
724
-        $courses =  Sensei()->course->get_all_courses();
725
-
726
-        if( empty(  $courses ) || ! is_array( $courses ) ){
727
-            return $args;
728
-        }
729
-
730
-        //setup the lessons quizzes  to limit the grading totals to
731
-        $quiz_scope = array();
732
-        foreach( $courses as $course ){
733
-
734
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
735
-
736
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
737
-
738
-                foreach(  $course_lessons as $lesson ){
739
-
740
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
-                    if( !empty( $quiz_id ) ) {
742
-
743
-                        array_push( $quiz_scope, $quiz_id );
744
-
745
-                    }
746
-
747
-                }
748
-
749
-            }
750
-
751
-        }
752
-
753
-        $args['post__in'] = $quiz_scope;
754
-
755
-        return $args;
756
-    }
757
-
758
-    /**
759
-     * It ensures that the author archive shows course by the current user.
760
-     *
761
-     * This function is hooked into the pre_get_posts filter
762
-     *
763
-     * @param WP_Query $query
764
-     * @return WP_Query $query
765
-     */
766
-    public function add_courses_to_author_archive( $query ) {
767
-
768
-        if ( is_admin() || ! $query->is_author() ){
769
-            return $query;
770
-        }
771
-
772
-        // this should only apply to users with the teacher role
773
-        $current_page_user = get_user_by('login', $query->get('author_name') );
774
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
775
-
776
-            return $query;
777
-
778
-        }
779
-
780
-        // Change post types depending on what is set already
781
-        $current_post_types = $query->get( 'post_type' );
782
-        if( empty( $current_post_types  ) ){
783
-
784
-            // if empty it means post by default, so add post so that it also includes that for now
785
-            $new_post_types = array( 'post', 'course' );
786
-
787
-        } elseif( is_array( $current_post_types  ) ) {
788
-
789
-            // merge the post types instead of overwriting it
790
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
791
-
792
-        }else{
793
-
794
-            // in this instance it is probably just one post type in string format
795
-            $new_post_types =  array( $current_post_types , 'course');
796
-
797
-        }
798
-
799
-        // change the query before returning it
800
-        $query->set('post_type', $new_post_types );
801
-
802
-        /**
803
-         * Change the query on the teacher author archive template
804
-         *
805
-         * @since 1.8.4
806
-         * @param WP_Query $query
807
-         */
808
-        return apply_filters( 'sensei_teacher_archive_query', $query );
809
-
810
-    }
811
-
812
-    /**
813
-     * Notify teacher when someone assigns a course to their account.
814
-     *
815
-     * @since 1.8.0
816
-     *
817
-     * @param $teacher_id
818
-     * @param $course_id
819
-     * @return bool
820
-     */
821
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
822
-
823
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
824
-            return false;
825
-        }
826
-
827
-        // if new user is the same as the current logged user, they don't need an email
828
-        if( $teacher_id == get_current_user_id() ){
829
-            return true;
830
-        }
831
-
832
-        // load the email class
833
-        include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834
-        $email = new Teacher_New_Course_Assignment();
835
-        $email->trigger( $teacher_id, $course_id );
836
-
837
-        return true;
838
-    } // end  teacher_course_assigned_notification
839
-
840
-    /**
841
-     * Email the admin when a teacher creates a new course
842
-     *
843
-     * This function hooks into wp_insert_post
844
-     *
845
-     * @since 1.8.0
846
-     * @param int $course_id
847
-     * @return bool
848
-     */
849
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850
-
851
-        $course_id = $post->ID;
852
-
853
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
855
-
856
-            return false;
857
-
858
-        }
859
-
860
-        /**
861
-         * Filter the option to send admin notification emails when teachers creation
862
-         * course.
863
-         *
864
-         * @since 1.8.0
865
-         *
866
-         * @param bool $on default true
867
-         */
868
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
869
-            return false;
870
-        }
871
-
872
-        // setting up the data needed by the email template
873
-        global $sensei_email_data;
874
-        $template = 'admin-teacher-new-course-created';
875
-        $course = get_post( $course_id );
876
-        $teacher = new WP_User( $course->post_author );
877
-        $recipient = get_option('admin_email', true);
878
-
879
-        // don't send if the course is created by admin
880
-        if( $recipient == $teacher->user_email ){
881
-            return;
882
-        }
883
-
884
-        /**
885
-         * Filter the email Header for the admin-teacher-new-course-created template
886
-         *
887
-         * @since 1.8.0
888
-         * @param string $template
889
-         */
890
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
891
-
892
-        /**
893
-         * Filter the email subject for the the
894
-         * admin-teacher-new-course-created template
895
-         *
896
-         * @since 1.8.0
897
-         * @param string $subject default New course assigned to you
898
-         * @param string $template
899
-         */
900
-        $subject = apply_filters('sensei_email_subject',
901
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
-                                $template );
903
-
904
-        //course edit link
905
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
906
-
907
-        // Construct data array
908
-        $email_data = array(
909
-            'template'			=> $template,
910
-            'heading' =>  $heading,
911
-            'teacher'		=> $teacher,
912
-            'course_id'			=> $course_id,
913
-            'course_name'			=> $course->post_title,
914
-            'course_edit_link' => $course_edit_link,
915
-        );
916
-
917
-        /**
918
-         * Filter the sensei email data for the admin-teacher-new-course-created template
919
-         *
920
-         * @since 1.8.0
921
-         * @param array $email_data
922
-         * @param string $template
923
-         */
924
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
925
-
926
-        // Send mail
927
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
928
-
929
-    }// end notify admin of course creation
930
-
931
-    /**
932
-     * Limit the analysis view to only the users taking courses belong to this teacher
933
-     *
934
-     * Hooked into sensei_analysis_get_learners
935
-     * @param array $args WP_User_Query arguments
936
-     * @return array $learners_query_results
937
-     */
938
-    public function limit_analysis_learners( $args ){
939
-
940
-        // show default for none teachers
941
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
942
-                return $args;
943
-        }
944
-
945
-        // for teachers all courses only return those which belong to the teacher
946
-        // as they don't have access to course belonging to other users
947
-        $teacher_courses = Sensei()->course->get_all_courses();
509
+	}// end update_course_lessons_author
510
+
511
+
512
+
513
+	/**
514
+	 * Sensei_Teacher::course_analysis_teacher_access_limit
515
+	 *
516
+	 * Alter the query so that users can only see their courses on the analysis page
517
+	 *
518
+	 * @since 1.8.0
519
+	 * @access public
520
+	 * @parameters $query
521
+	 * @return array $users user id array
522
+	 */
523
+	public function course_analysis_teacher_access_limit ( $query ) {
524
+
525
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
526
+			return $query;
527
+		}
528
+
529
+		if ( ! function_exists( 'get_current_screen' ) ) {
530
+			return $query;
531
+		}
532
+
533
+		$screen = get_current_screen();
534
+		$sensei_post_types = array('course', 'lesson', 'question' );
535
+
536
+		// exit early for the following conditions
537
+		$limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
538
+
539
+		if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
+			|| ! in_array( $query->query['post_type'], $sensei_post_types ) ){
541
+			return $query;
542
+		}
543
+
544
+		global $current_user;
545
+		// set the query author to the current user to only show those those posts
546
+		$query->set( 'author', $current_user->ID );
547
+		return $query;
548
+
549
+	}// end course_analysis_teacher_access_limit
550
+
551
+
552
+	/**
553
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
554
+	 *
555
+	 * Determine if we're in admin and the current logged in use is a teacher
556
+	 *
557
+	 * @since 1.8.0
558
+	 * @access public
559
+	 * @parameters array $wp_query
560
+	 * @return bool $is_admin_teacher
561
+	 */
562
+	public function is_admin_teacher ( ){
563
+
564
+		if( ! is_user_logged_in()){
565
+			return false;
566
+		}
567
+		$is_admin_teacher = false;
568
+
569
+		if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
570
+
571
+			$is_admin_teacher = true;
572
+
573
+		}
574
+
575
+		return $is_admin_teacher;
576
+
577
+	} // end is_admin_teacher
578
+
579
+	/**
580
+	 * Show correct post counts on list table for Sensei post types
581
+	 *
582
+	 * @since 1.8.0
583
+	 *
584
+	 * @param  object $counts Default status counts
585
+	 * @param  string $type   Current post type
586
+	 * @param  string $perm   User permission level
587
+	 * @return object         Modified status counts
588
+	 */
589
+	public function list_table_counts( $counts, $type, $perm ) {
590
+		global $current_user;
591
+
592
+		if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
593
+			return $counts;
594
+		}
595
+
596
+		if( ! $this->is_admin_teacher() ) {
597
+			return $counts;
598
+		}
599
+
600
+		$args = array(
601
+			'post_type' => $type,
602
+			'author' => $current_user->ID,
603
+			'posts_per_page' => -1
604
+		);
605
+
606
+		 // Get all available statuses
607
+		$stati = get_post_stati();
608
+
609
+		// Update count object
610
+		foreach( $stati as $status ) {
611
+			$args['post_status'] = $status;
612
+			$posts = get_posts( $args );
613
+			$counts->$status = count( $posts );
614
+		}
615
+
616
+		return $counts;
617
+	}
618
+
619
+	/**
620
+	 * Filter the post queries to show
621
+	 * only lesson /course and users that belong
622
+	 * to the current logged teacher.
623
+	 *
624
+	 * @since 1.8.0
625
+	 *
626
+	 */
627
+	public function filter_queries ( $query ) {
628
+		global $current_user;
629
+
630
+		if( ! $this->is_admin_teacher() ) {
631
+			return;
632
+		}
633
+
634
+		if ( ! function_exists( 'get_current_screen' ) ) {
635
+			return;
636
+		}
637
+
638
+		$screen = get_current_screen();
639
+		if( empty( $screen ) ) {
640
+			return $query;
641
+		}
642
+		switch( $screen->id ) {
643
+			case 'sensei_page_sensei_grading':
644
+			case 'sensei_page_sensei_analysis':
645
+			case 'sensei_page_sensei_learners':
646
+			case 'lesson':
647
+			case 'course':
648
+			case 'question':
649
+			case 'lesson_page_module-order':
650
+
651
+			/**
652
+			 * sensei_filter_queries_set_author
653
+			 * Filter the author Sensei set for queries
654
+			 *
655
+			 * @since 1.8.0
656
+			 *
657
+			 * @param int $user_id
658
+			 * @param string $screen_id
659
+			 *
660
+			 */
661
+			$query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
662
+			break;
663
+		}
664
+	}
665
+
666
+	/**
667
+	 * Limit grading quizzes to only those within courses belonging to the current teacher
668
+	 * . This excludes the admin user.
669
+	 *
670
+	 * @since 1.8.0
671
+	 * @hooked into the_comments
672
+	 * @param array  $comments
673
+	 *
674
+	 * @return array $comments
675
+	 */
676
+	public function filter_grading_activity_queries( $comments ){
677
+
678
+		if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
+			return $comments ;
680
+		}
681
+
682
+		//check if we're on the grading screen
683
+		$screen = get_current_screen();
684
+
685
+		if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
686
+			return $comments;
687
+		}
688
+
689
+		// get the course and determine if the current teacher is the owner
690
+		// if not remove it from the list of comments to be returned
691
+		foreach( $comments as $key => $comment){
692
+			$lesson = get_post( $comment->comment_post_ID );
693
+			$course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
+			$course = get_post( $course_id );
695
+			if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
696
+				//remove this as the teacher should see this.
697
+				unset( $comments[ $key ] );
698
+			}
699
+		}
700
+		return $comments ;
701
+
702
+	}// end function filter grading
703
+
704
+	/**
705
+	 * Limit the grading screen totals to only show lessons in the course
706
+	 * belonging to the currently logged in teacher. This only applies to
707
+	 * the teacher role.
708
+	 *
709
+	 * @since 1.8.0
710
+	 *
711
+	 * @hooked into sensei_count_statuses_args
712
+	 * @param array $args
713
+	 *
714
+	 * @return array  $args
715
+	 */
716
+	public function limit_grading_totals( $args ){
717
+
718
+		if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
+			return $args ;
720
+		}
721
+
722
+		//get the teachers courses
723
+		// the query is already filtered to only the teacher
724
+		$courses =  Sensei()->course->get_all_courses();
725
+
726
+		if( empty(  $courses ) || ! is_array( $courses ) ){
727
+			return $args;
728
+		}
729
+
730
+		//setup the lessons quizzes  to limit the grading totals to
731
+		$quiz_scope = array();
732
+		foreach( $courses as $course ){
733
+
734
+			$course_lessons = Sensei()->course->course_lessons( $course->ID );
735
+
736
+			if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
737
+
738
+				foreach(  $course_lessons as $lesson ){
739
+
740
+					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
+					if( !empty( $quiz_id ) ) {
742
+
743
+						array_push( $quiz_scope, $quiz_id );
744
+
745
+					}
746
+
747
+				}
748
+
749
+			}
750
+
751
+		}
752
+
753
+		$args['post__in'] = $quiz_scope;
754
+
755
+		return $args;
756
+	}
757
+
758
+	/**
759
+	 * It ensures that the author archive shows course by the current user.
760
+	 *
761
+	 * This function is hooked into the pre_get_posts filter
762
+	 *
763
+	 * @param WP_Query $query
764
+	 * @return WP_Query $query
765
+	 */
766
+	public function add_courses_to_author_archive( $query ) {
767
+
768
+		if ( is_admin() || ! $query->is_author() ){
769
+			return $query;
770
+		}
771
+
772
+		// this should only apply to users with the teacher role
773
+		$current_page_user = get_user_by('login', $query->get('author_name') );
774
+		if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
775
+
776
+			return $query;
777
+
778
+		}
779
+
780
+		// Change post types depending on what is set already
781
+		$current_post_types = $query->get( 'post_type' );
782
+		if( empty( $current_post_types  ) ){
783
+
784
+			// if empty it means post by default, so add post so that it also includes that for now
785
+			$new_post_types = array( 'post', 'course' );
786
+
787
+		} elseif( is_array( $current_post_types  ) ) {
788
+
789
+			// merge the post types instead of overwriting it
790
+			$new_post_types = array_merge( $current_post_types, array( 'course' ) );
791
+
792
+		}else{
793
+
794
+			// in this instance it is probably just one post type in string format
795
+			$new_post_types =  array( $current_post_types , 'course');
796
+
797
+		}
798
+
799
+		// change the query before returning it
800
+		$query->set('post_type', $new_post_types );
801
+
802
+		/**
803
+		 * Change the query on the teacher author archive template
804
+		 *
805
+		 * @since 1.8.4
806
+		 * @param WP_Query $query
807
+		 */
808
+		return apply_filters( 'sensei_teacher_archive_query', $query );
809
+
810
+	}
811
+
812
+	/**
813
+	 * Notify teacher when someone assigns a course to their account.
814
+	 *
815
+	 * @since 1.8.0
816
+	 *
817
+	 * @param $teacher_id
818
+	 * @param $course_id
819
+	 * @return bool
820
+	 */
821
+	public function teacher_course_assigned_notification( $teacher_id, $course_id ){
822
+
823
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
824
+			return false;
825
+		}
826
+
827
+		// if new user is the same as the current logged user, they don't need an email
828
+		if( $teacher_id == get_current_user_id() ){
829
+			return true;
830
+		}
831
+
832
+		// load the email class
833
+		include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834
+		$email = new Teacher_New_Course_Assignment();
835
+		$email->trigger( $teacher_id, $course_id );
836
+
837
+		return true;
838
+	} // end  teacher_course_assigned_notification
839
+
840
+	/**
841
+	 * Email the admin when a teacher creates a new course
842
+	 *
843
+	 * This function hooks into wp_insert_post
844
+	 *
845
+	 * @since 1.8.0
846
+	 * @param int $course_id
847
+	 * @return bool
848
+	 */
849
+	public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850
+
851
+		$course_id = $post->ID;
852
+
853
+		if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
+			|| 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
855
+
856
+			return false;
857
+
858
+		}
859
+
860
+		/**
861
+		 * Filter the option to send admin notification emails when teachers creation
862
+		 * course.
863
+		 *
864
+		 * @since 1.8.0
865
+		 *
866
+		 * @param bool $on default true
867
+		 */
868
+		if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
869
+			return false;
870
+		}
871
+
872
+		// setting up the data needed by the email template
873
+		global $sensei_email_data;
874
+		$template = 'admin-teacher-new-course-created';
875
+		$course = get_post( $course_id );
876
+		$teacher = new WP_User( $course->post_author );
877
+		$recipient = get_option('admin_email', true);
878
+
879
+		// don't send if the course is created by admin
880
+		if( $recipient == $teacher->user_email ){
881
+			return;
882
+		}
883
+
884
+		/**
885
+		 * Filter the email Header for the admin-teacher-new-course-created template
886
+		 *
887
+		 * @since 1.8.0
888
+		 * @param string $template
889
+		 */
890
+		$heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
891
+
892
+		/**
893
+		 * Filter the email subject for the the
894
+		 * admin-teacher-new-course-created template
895
+		 *
896
+		 * @since 1.8.0
897
+		 * @param string $subject default New course assigned to you
898
+		 * @param string $template
899
+		 */
900
+		$subject = apply_filters('sensei_email_subject',
901
+								'['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
+								$template );
903
+
904
+		//course edit link
905
+		$course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
906
+
907
+		// Construct data array
908
+		$email_data = array(
909
+			'template'			=> $template,
910
+			'heading' =>  $heading,
911
+			'teacher'		=> $teacher,
912
+			'course_id'			=> $course_id,
913
+			'course_name'			=> $course->post_title,
914
+			'course_edit_link' => $course_edit_link,
915
+		);
916
+
917
+		/**
918
+		 * Filter the sensei email data for the admin-teacher-new-course-created template
919
+		 *
920
+		 * @since 1.8.0
921
+		 * @param array $email_data
922
+		 * @param string $template
923
+		 */
924
+		$sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
925
+
926
+		// Send mail
927
+		Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
928
+
929
+	}// end notify admin of course creation
930
+
931
+	/**
932
+	 * Limit the analysis view to only the users taking courses belong to this teacher
933
+	 *
934
+	 * Hooked into sensei_analysis_get_learners
935
+	 * @param array $args WP_User_Query arguments
936
+	 * @return array $learners_query_results
937
+	 */
938
+	public function limit_analysis_learners( $args ){
939
+
940
+		// show default for none teachers
941
+		if( ! Sensei()->teacher->is_admin_teacher() ) {
942
+				return $args;
943
+		}
944
+
945
+		// for teachers all courses only return those which belong to the teacher
946
+		// as they don't have access to course belonging to other users
947
+		$teacher_courses = Sensei()->course->get_all_courses();
948 948
 
949
-        // if the user has no courses they should see no users
950
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
951
-            // tell the query to return 0 students
952
-            $args[ 'include'] = array( 0 );
953
-            return $args;
954
-
955
-        }
956
-
957
-        $learner_ids_for_teacher_courses = array();
958
-        foreach( $teacher_courses as $course ){
959
-
960
-            $course_learner_ids = array();
961
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
962
-
963
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
964
-                continue; // skip to the next course as there are no users on this course
965
-            }
966
-
967
-            // it could be an array of comments or a single comment
968
-            if( is_array( $activity_comments ) ){
949
+		// if the user has no courses they should see no users
950
+		if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
951
+			// tell the query to return 0 students
952
+			$args[ 'include'] = array( 0 );
953
+			return $args;
954
+
955
+		}
956
+
957
+		$learner_ids_for_teacher_courses = array();
958
+		foreach( $teacher_courses as $course ){
959
+
960
+			$course_learner_ids = array();
961
+			$activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
962
+
963
+			if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
964
+				continue; // skip to the next course as there are no users on this course
965
+			}
966
+
967
+			// it could be an array of comments or a single comment
968
+			if( is_array( $activity_comments ) ){
969 969
 
970
-                foreach( $activity_comments as $comment ){
970
+				foreach( $activity_comments as $comment ){
971 971
 
972
-                    $user = get_userdata( $comment->user_id );
972
+					$user = get_userdata( $comment->user_id );
973 973
 
974
-                    if( empty( $user ) ){
975
-                        // next comment in this array
976
-                        continue;
977
-                    }
974
+					if( empty( $user ) ){
975
+						// next comment in this array
976
+						continue;
977
+					}
978 978
 
979
-                    $course_learner_ids[] = $user->ID;
980
-                }
979
+					$course_learner_ids[] = $user->ID;
980
+				}
981 981
 
982
-            }else{
982
+			}else{
983 983
 
984
-                $user = get_userdata( $activity_comments->user_id );
985
-                $course_learner_ids[] = $user->ID;
984
+				$user = get_userdata( $activity_comments->user_id );
985
+				$course_learner_ids[] = $user->ID;
986 986
 
987
-            }
987
+			}
988 988
 
989
-            // add learners on this course to the all courses learner list
990
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
989
+			// add learners on this course to the all courses learner list
990
+			$learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
991 991
 
992
-        }
992
+		}
993 993
 
994
-        // if there are no students taking the courses by this teacher don't show them any of the other users
995
-        if( empty( $learner_ids_for_teacher_courses ) ){
994
+		// if there are no students taking the courses by this teacher don't show them any of the other users
995
+		if( empty( $learner_ids_for_teacher_courses ) ){
996 996
 
997
-            $args[ 'include'] = array( 0 );
997
+			$args[ 'include'] = array( 0 );
998 998
 
999
-        }else{
999
+		}else{
1000 1000
 
1001
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
1001
+			$args[ 'include'] = $learner_ids_for_teacher_courses;
1002 1002
 
1003
-        }
1003
+		}
1004 1004
 
1005
-        // return the WP_Use_Query arguments
1006
-        return $args;
1005
+		// return the WP_Use_Query arguments
1006
+		return $args;
1007 1007
 
1008
-    }// end limit_analysis_learners
1008
+	}// end limit_analysis_learners
1009 1009
 
1010
-    /**
1011
-     * Give teacher full admin access to the question post type
1012
-     * in certain cases.
1013
-     *
1014
-     * @since 1.8.0
1015
-     * @param $questions
1016
-     * @return mixed
1017
-     */
1018
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1010
+	/**
1011
+	 * Give teacher full admin access to the question post type
1012
+	 * in certain cases.
1013
+	 *
1014
+	 * @since 1.8.0
1015
+	 * @param $questions
1016
+	 * @return mixed
1017
+	 */
1018
+	public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1019 1019
 
1020
-        if( ! $this->is_admin_teacher() ){
1021
-            return $questions;
1022
-        }
1020
+		if( ! $this->is_admin_teacher() ){
1021
+			return $questions;
1022
+		}
1023 1023
 
1024
-        $screen = get_current_screen();
1024
+		$screen = get_current_screen();
1025 1025
 
1026
-        // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1026
+		// don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
+		remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1028 1028
 
1029
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1029
+		if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1030 1030
 
1031
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
-            if( ! empty($admin_user) ){
1031
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
+			if( ! empty($admin_user) ){
1033 1033
 
1034
-                $current_teacher_id = get_current_user_id();
1034
+				$current_teacher_id = get_current_user_id();
1035 1035
 
1036
-                // set current user to admin so teacher can view all questions
1037
-                wp_set_current_user( $admin_user->ID  );
1038
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1036
+				// set current user to admin so teacher can view all questions
1037
+				wp_set_current_user( $admin_user->ID  );
1038
+				$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1039 1039
 
1040
-                // set the teacher as the current use again
1041
-                wp_set_current_user( $current_teacher_id );
1042
-            }
1040
+				// set the teacher as the current use again
1041
+				wp_set_current_user( $current_teacher_id );
1042
+			}
1043 1043
 
1044
-        }
1045
-        // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1044
+		}
1045
+		// attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1047 1047
 
1048
-        return $questions;
1049
-    }
1048
+		return $questions;
1049
+	}
1050 1050
 
1051
-    /**
1052
-     * Give the teacher role access to questions from the question bank
1053
-     *
1054
-     * @since 1.8.0
1055
-     * @param $wp_query
1056
-     * @return mixed
1057
-     */
1058
-    public function give_access_to_all_questions( $wp_query ){
1051
+	/**
1052
+	 * Give the teacher role access to questions from the question bank
1053
+	 *
1054
+	 * @since 1.8.0
1055
+	 * @param $wp_query
1056
+	 * @return mixed
1057
+	 */
1058
+	public function give_access_to_all_questions( $wp_query ){
1059 1059
 
1060
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1060
+		if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1061 1061
 
1062
-            return $wp_query;
1063
-        }
1062
+			return $wp_query;
1063
+		}
1064 1064
 
1065
-        $screen = get_current_screen();
1066
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1065
+		$screen = get_current_screen();
1066
+		if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
+			|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1068 1068
 
1069
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
-            if( ! empty($admin_user) ){
1069
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
+			if( ! empty($admin_user) ){
1071 1071
 
1072
-                $current_teacher_id = get_current_user_id();
1072
+				$current_teacher_id = get_current_user_id();
1073 1073
 
1074
-                // set current user to admin so teacher can view all questions
1075
-                wp_set_current_user( $admin_user->ID  );
1074
+				// set current user to admin so teacher can view all questions
1075
+				wp_set_current_user( $admin_user->ID  );
1076 1076
 
1077
-                //run new query as admin
1078
-                $wp_query = new WP_Query( $wp_query->query );
1077
+				//run new query as admin
1078
+				$wp_query = new WP_Query( $wp_query->query );
1079 1079
 
1080
-                //set the teache as current use again
1081
-                wp_set_current_user( $current_teacher_id );
1080
+				//set the teache as current use again
1081
+				wp_set_current_user( $current_teacher_id );
1082 1082
 
1083
-            }
1084
-        }
1083
+			}
1084
+		}
1085 1085
 
1086
-        return $wp_query;
1087
-    }// end give_access_to_all_questions
1086
+		return $wp_query;
1087
+	}// end give_access_to_all_questions
1088 1088
 
1089
-    /**
1090
-     * Add new column heading to the course admin edit list
1091
-     *
1092
-     * @since 1.8.0
1093
-     * @param $columns
1094
-     * @return array
1095
-     */
1096
-    public function course_column_heading($columns) {
1089
+	/**
1090
+	 * Add new column heading to the course admin edit list
1091
+	 *
1092
+	 * @since 1.8.0
1093
+	 * @param $columns
1094
+	 * @return array
1095
+	 */
1096
+	public function course_column_heading($columns) {
1097 1097
 
1098
-        if( $this->is_admin_teacher() ){
1099
-            return $columns;
1100
-        }
1101
-        $new_columns = array(
1102
-            'teacher' => __('Teacher', 'woothemes-sensei'),
1103
-        );
1104
-        return array_merge($columns, $new_columns);
1098
+		if( $this->is_admin_teacher() ){
1099
+			return $columns;
1100
+		}
1101
+		$new_columns = array(
1102
+			'teacher' => __('Teacher', 'woothemes-sensei'),
1103
+		);
1104
+		return array_merge($columns, $new_columns);
1105 1105
 
1106
-    }// end teacher column add
1106
+	}// end teacher column add
1107 1107
 
1108
-    /**
1109
-     * Print out  teacher column data
1110
-     *
1111
-     * @since 1.8.0
1112
-     * @param $column
1113
-     * @param $course_id
1114
-     */
1115
-    public function course_column_data( $column, $course_id  ){
1108
+	/**
1109
+	 * Print out  teacher column data
1110
+	 *
1111
+	 * @since 1.8.0
1112
+	 * @param $column
1113
+	 * @param $course_id
1114
+	 */
1115
+	public function course_column_data( $column, $course_id  ){
1116 1116
 
1117
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1118
-            return;
1119
-        }
1117
+		if( $this->is_admin_teacher() || 'teacher' != $column  ){
1118
+			return;
1119
+		}
1120 1120
 
1121
-        $course = get_post( $course_id );
1122
-        $teacher = get_userdata( $course->post_author );
1121
+		$course = get_post( $course_id );
1122
+		$teacher = get_userdata( $course->post_author );
1123 1123
 
1124
-        if( !$teacher ){
1125
-            return;
1126
-        }
1124
+		if( !$teacher ){
1125
+			return;
1126
+		}
1127 1127
 
1128
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1128
+		echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1129 1129
 
1130
-    }// end course_column_ data
1130
+	}// end course_column_ data
1131 1131
 
1132
-    /**
1133
-     * Return only courses belonging to the given teacher.
1134
-     *
1135
-     *
1136
-     * @since 1.8.0
1137
-     *
1138
-     * @param int $teacher_id
1139
-     * @param bool $return_ids_only
1140
-     *
1141
-     * @return array $teachers_courses
1142
-     */
1143
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1132
+	/**
1133
+	 * Return only courses belonging to the given teacher.
1134
+	 *
1135
+	 *
1136
+	 * @since 1.8.0
1137
+	 *
1138
+	 * @param int $teacher_id
1139
+	 * @param bool $return_ids_only
1140
+	 *
1141
+	 * @return array $teachers_courses
1142
+	 */
1143
+	public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1144 1144
 
1145
-        $teachers_courses = array();
1145
+		$teachers_courses = array();
1146 1146
 
1147
-        if( empty( $teacher_id  ) ){
1148
-            $teacher_id = get_current_user_id();
1149
-        }
1147
+		if( empty( $teacher_id  ) ){
1148
+			$teacher_id = get_current_user_id();
1149
+		}
1150 1150
 
1151
-        $all_courses = Sensei()->course->get_all_courses();
1151
+		$all_courses = Sensei()->course->get_all_courses();
1152 1152
 
1153
-        if( empty( $all_courses ) ){
1154
-            return $all_courses;
1155
-        }
1153
+		if( empty( $all_courses ) ){
1154
+			return $all_courses;
1155
+		}
1156 1156
 
1157
-        foreach( $all_courses as $course ){
1157
+		foreach( $all_courses as $course ){
1158 1158
 
1159
-            if( $course->post_author != $teacher_id  ){
1160
-                continue;
1161
-            }
1159
+			if( $course->post_author != $teacher_id  ){
1160
+				continue;
1161
+			}
1162 1162
 
1163
-            if( $return_ids_only ){
1163
+			if( $return_ids_only ){
1164 1164
 
1165
-                $teachers_courses[] = $course->ID;
1165
+				$teachers_courses[] = $course->ID;
1166 1166
 
1167
-            }else{
1167
+			}else{
1168 1168
 
1169
-                $teachers_courses[] = $course;
1169
+				$teachers_courses[] = $course;
1170 1170
 
1171
-            }
1171
+			}
1172 1172
 
1173
-        }
1173
+		}
1174 1174
 
1175
-        return $teachers_courses;
1175
+		return $teachers_courses;
1176 1176
 
1177
-    }
1177
+	}
1178 1178
 
1179
-    /**
1180
-     * Limit the message display to only those sent to the current teacher
1181
-     *
1182
-     * @since 1.8.0
1183
-     *
1184
-     * @param $query
1185
-     * @return mixed
1186
-     */
1187
-    public function limit_edit_messages_query( $query ){
1188
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1189
-            return $query;
1190
-        }
1191
-
1192
-        $teacher = wp_get_current_user();
1193
-
1194
-        $query->set( 'meta_key', '_receiver' );
1195
-        $meta_query_args = array(
1196
-            'key'     => '_receiver',
1197
-            'value'   => $teacher->get('user_login') ,
1198
-            'compare' => '='
1199
-        );
1179
+	/**
1180
+	 * Limit the message display to only those sent to the current teacher
1181
+	 *
1182
+	 * @since 1.8.0
1183
+	 *
1184
+	 * @param $query
1185
+	 * @return mixed
1186
+	 */
1187
+	public function limit_edit_messages_query( $query ){
1188
+		if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1189
+			return $query;
1190
+		}
1191
+
1192
+		$teacher = wp_get_current_user();
1193
+
1194
+		$query->set( 'meta_key', '_receiver' );
1195
+		$meta_query_args = array(
1196
+			'key'     => '_receiver',
1197
+			'value'   => $teacher->get('user_login') ,
1198
+			'compare' => '='
1199
+		);
1200 1200
 
1201
-        $query->set('meta_query', $meta_query_args  );
1201
+		$query->set('meta_query', $meta_query_args  );
1202 1202
 
1203
-        return $query;
1204
-    }
1203
+		return $query;
1204
+	}
1205 1205
 
1206 1206
 
1207
-    /**
1208
-     * Add options to filter courses by teacher
1209
-     *
1210
-     * @since 1.8.0
1211
-     *
1212
-     * @return void
1213
-     */
1214
-    public function course_teacher_filter_options() {
1215
-        global $typenow;
1207
+	/**
1208
+	 * Add options to filter courses by teacher
1209
+	 *
1210
+	 * @since 1.8.0
1211
+	 *
1212
+	 * @return void
1213
+	 */
1214
+	public function course_teacher_filter_options() {
1215
+		global $typenow;
1216 1216
 
1217
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1218
-            return;
1219
-        }
1217
+		if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1218
+			return;
1219
+		}
1220 1220
 
1221
-        // get all roles
1222
-        $roles = get_editable_roles();
1221
+		// get all roles
1222
+		$roles = get_editable_roles();
1223 1223
 
1224
-        // get roles with the course edit capability
1225
-        // and then get the users with those roles
1226
-        $users_who_can_edit_courses = array();
1227
-        foreach( $roles as $role_item ){
1224
+		// get roles with the course edit capability
1225
+		// and then get the users with those roles
1226
+		$users_who_can_edit_courses = array();
1227
+		foreach( $roles as $role_item ){
1228 1228
 
1229
-            $role = get_role( strtolower( $role_item['name'] ) );
1229
+			$role = get_role( strtolower( $role_item['name'] ) );
1230 1230
 
1231
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1231
+			if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1232 1232
 
1233
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1233
+				$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
+				$role_users_who_can_edit_courses = get_users( $user_query_args );
1235 1235
 
1236
-                // add user from the current $user_role to all users
1237
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1236
+				// add user from the current $user_role to all users
1237
+				$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1238 1238
 
1239
-            }
1239
+			}
1240 1240
 
1241
-        }
1241
+		}
1242 1242
 
1243
-        // Create the select element with the given users who can edit course
1244
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1245
-        $course_options = '';
1246
-        foreach( $users_who_can_edit_courses as $user ) {
1247
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1248
-        }
1243
+		// Create the select element with the given users who can edit course
1244
+		$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1245
+		$course_options = '';
1246
+		foreach( $users_who_can_edit_courses as $user ) {
1247
+			$course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1248
+		}
1249 1249
 
1250
-        $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1252
-        $output .= $course_options;
1253
-        $output .= '</select>';
1250
+		$output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
+		$output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1252
+		$output .= $course_options;
1253
+		$output .= '</select>';
1254 1254
 
1255
-        echo $output;
1256
-    }
1255
+		echo $output;
1256
+	}
1257 1257
 
1258
-    /**
1259
-     * Modify the main query on the admin course list screen
1260
-     *
1261
-     * @since 1.8.0
1262
-     *
1263
-     * @param $query
1264
-     * @return $query
1265
-     */
1266
-    public function teacher_filter_query_modify( $query ){
1267
-        global $typenow;
1258
+	/**
1259
+	 * Modify the main query on the admin course list screen
1260
+	 *
1261
+	 * @since 1.8.0
1262
+	 *
1263
+	 * @param $query
1264
+	 * @return $query
1265
+	 */
1266
+	public function teacher_filter_query_modify( $query ){
1267
+		global $typenow;
1268 1268
 
1269
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1270
-            return $query;
1271
-        }
1272
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1273
-
1274
-        if( empty( $course_teacher ) ) {
1275
-            return $query;
1276
-        }
1277
-
1278
-        $query['author'] = $course_teacher;
1279
-        return $query;
1280
-    }
1281
-
1282
-    /**
1283
-     * Only show current teacher's media in the media library
1284
-     * @param  array $request Default request arguments
1285
-     * @return array          Modified request arguments
1286
-     */
1287
-    public function restrict_media_library( $request = array() ) {
1288
-
1289
-        if( ! is_admin() ) {
1290
-            return $request;
1291
-        }
1292
-
1293
-        if( ! $this->is_admin_teacher() ) {
1294
-            return $request;
1295
-        }
1296
-
1297
-        $screen = get_current_screen();
1298
-
1299
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
-            $teacher = intval( get_current_user_id() );
1301
-
1302
-            if( $teacher ) {
1303
-                $request['author__in'] = array( $teacher );
1304
-            }
1305
-        }
1306
-
1307
-        return $request;
1308
-    } // End restrict_media_library()
1309
-
1310
-    /**
1311
-     * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1312
-     * @param  array $query Default query arguments
1313
-     * @return array        Modified query arguments
1314
-     */
1315
-    public function restrict_media_library_modal( $query = array() ) {
1316
-
1317
-        if( ! is_admin() ) {
1318
-            return $query;
1319
-        }
1320
-
1321
-        if( ! $this->is_admin_teacher() ) {
1322
-            return $query;
1323
-        }
1324
-
1325
-        $teacher = intval( get_current_user_id() );
1326
-
1327
-        if( $teacher ) {
1328
-            $query['author__in'] = array( $teacher );
1329
-        }
1330
-
1331
-        return $query;
1332
-    } // End restrict_media_library_modal()
1333
-
1334
-    /**
1335
-     * When saving the lesson, update the teacher if the lesson belongs to a course
1336
-     *
1337
-     * @since 1.8.0
1338
-     *
1339
-     * @param int $lesson_id
1340
-     */
1341
-    public function update_lesson_teacher( $lesson_id ){
1342
-
1343
-        if( 'lesson'!= get_post_type() ){
1344
-            return;
1345
-        }
1269
+		if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1270
+			return $query;
1271
+		}
1272
+		$course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1273
+
1274
+		if( empty( $course_teacher ) ) {
1275
+			return $query;
1276
+		}
1277
+
1278
+		$query['author'] = $course_teacher;
1279
+		return $query;
1280
+	}
1281
+
1282
+	/**
1283
+	 * Only show current teacher's media in the media library
1284
+	 * @param  array $request Default request arguments
1285
+	 * @return array          Modified request arguments
1286
+	 */
1287
+	public function restrict_media_library( $request = array() ) {
1288
+
1289
+		if( ! is_admin() ) {
1290
+			return $request;
1291
+		}
1292
+
1293
+		if( ! $this->is_admin_teacher() ) {
1294
+			return $request;
1295
+		}
1296
+
1297
+		$screen = get_current_screen();
1298
+
1299
+		if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
+			$teacher = intval( get_current_user_id() );
1301
+
1302
+			if( $teacher ) {
1303
+				$request['author__in'] = array( $teacher );
1304
+			}
1305
+		}
1306
+
1307
+		return $request;
1308
+	} // End restrict_media_library()
1309
+
1310
+	/**
1311
+	 * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1312
+	 * @param  array $query Default query arguments
1313
+	 * @return array        Modified query arguments
1314
+	 */
1315
+	public function restrict_media_library_modal( $query = array() ) {
1316
+
1317
+		if( ! is_admin() ) {
1318
+			return $query;
1319
+		}
1320
+
1321
+		if( ! $this->is_admin_teacher() ) {
1322
+			return $query;
1323
+		}
1324
+
1325
+		$teacher = intval( get_current_user_id() );
1326
+
1327
+		if( $teacher ) {
1328
+			$query['author__in'] = array( $teacher );
1329
+		}
1330
+
1331
+		return $query;
1332
+	} // End restrict_media_library_modal()
1333
+
1334
+	/**
1335
+	 * When saving the lesson, update the teacher if the lesson belongs to a course
1336
+	 *
1337
+	 * @since 1.8.0
1338
+	 *
1339
+	 * @param int $lesson_id
1340
+	 */
1341
+	public function update_lesson_teacher( $lesson_id ){
1342
+
1343
+		if( 'lesson'!= get_post_type() ){
1344
+			return;
1345
+		}
1346 1346
 
1347
-        // this should only run once per request cycle
1348
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1347
+		// this should only run once per request cycle
1348
+		remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1349 1349
 
1350
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1350
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1351 1351
 
1352
-        if(  empty( $course_id ) || ! $course_id ){
1353
-            return;
1354
-        }
1352
+		if(  empty( $course_id ) || ! $course_id ){
1353
+			return;
1354
+		}
1355 1355
 
1356
-        $course = get_post( $course_id );
1356
+		$course = get_post( $course_id );
1357 1357
 
1358
-        $lesson_update_args= array(
1359
-            'ID' => $lesson_id ,
1360
-            'post_author' => $course->post_author
1361
-        );
1362
-        wp_update_post( $lesson_update_args );
1358
+		$lesson_update_args= array(
1359
+			'ID' => $lesson_id ,
1360
+			'post_author' => $course->post_author
1361
+		);
1362
+		wp_update_post( $lesson_update_args );
1363 1363
 
1364
-    } // end update_lesson_teacher
1364
+	} // end update_lesson_teacher
1365 1365
 
1366
-    /**
1367
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
1368
-     *
1369
-     * Limit teachers to only see their courses, lessons and questions
1370
-     *
1371
-     * @since 1.8.0
1372
-     * @access public
1373
-     * @parameters array $wp_query
1374
-     * @return WP_Query $wp_query
1375
-     */
1376
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1377
-        global $current_user;
1366
+	/**
1367
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
1368
+	 *
1369
+	 * Limit teachers to only see their courses, lessons and questions
1370
+	 *
1371
+	 * @since 1.8.0
1372
+	 * @access public
1373
+	 * @parameters array $wp_query
1374
+	 * @return WP_Query $wp_query
1375
+	 */
1376
+	public function limit_teacher_edit_screen_post_types( $wp_query ) {
1377
+		global $current_user;
1378 1378
 
1379
-        //exit early
1380
-        if( ! $this->is_admin_teacher() ){
1381
-            return $wp_query;
1382
-        }
1379
+		//exit early
1380
+		if( ! $this->is_admin_teacher() ){
1381
+			return $wp_query;
1382
+		}
1383 1383
 
1384
-        if ( ! function_exists( 'get_current_screen' ) ) {
1385
-            return $wp_query;
1386
-        }
1384
+		if ( ! function_exists( 'get_current_screen' ) ) {
1385
+			return $wp_query;
1386
+		}
1387 1387
 
1388
-        $screen = get_current_screen();
1388
+		$screen = get_current_screen();
1389 1389
 
1390
-        if( empty( $screen ) ){
1391
-            return $wp_query;
1392
-        }
1390
+		if( empty( $screen ) ){
1391
+			return $wp_query;
1392
+		}
1393 1393
 
1394
-        // for any of these conditions limit what the teacher will see
1395
-        $limit_screens = array(
1396
-            'edit-lesson',
1397
-            'edit-course',
1398
-            'edit-question',
1399
-            'course_page_course-order',
1400
-            'lesson_page_lesson-order',
1401
-        );
1394
+		// for any of these conditions limit what the teacher will see
1395
+		$limit_screens = array(
1396
+			'edit-lesson',
1397
+			'edit-course',
1398
+			'edit-question',
1399
+			'course_page_course-order',
1400
+			'lesson_page_lesson-order',
1401
+		);
1402 1402
 
1403
-        if(  in_array($screen->id  , $limit_screens ) ) {
1403
+		if(  in_array($screen->id  , $limit_screens ) ) {
1404 1404
 
1405
-            // set the query author to the current user to only show those those posts
1406
-            $wp_query->set( 'author', $current_user->ID );
1407
-        }
1405
+			// set the query author to the current user to only show those those posts
1406
+			$wp_query->set( 'author', $current_user->ID );
1407
+		}
1408 1408
 
1409
-        return $wp_query;
1409
+		return $wp_query;
1410 1410
 
1411
-    } // end limit_teacher_edit_screen_post_types()
1411
+	} // end limit_teacher_edit_screen_post_types()
1412 1412
 
1413 1413
 
1414
-    /**
1415
-     * Sensei_Teacher::teacher_login_redirect
1416
-     *
1417
-     * Redirect teachers to /wp-admin/ after login
1418
-     *
1419
-     * @since 1.8.7
1420
-     * @access public
1421
-     * @param string $user_login
1422
-     * @param object $user
1423
-     * @return void
1424
-     */
1414
+	/**
1415
+	 * Sensei_Teacher::teacher_login_redirect
1416
+	 *
1417
+	 * Redirect teachers to /wp-admin/ after login
1418
+	 *
1419
+	 * @since 1.8.7
1420
+	 * @access public
1421
+	 * @param string $user_login
1422
+	 * @param object $user
1423
+	 * @return void
1424
+	 */
1425 1425
 
1426
-    public function teacher_login_redirect( $user_login, $user  ) {
1426
+	public function teacher_login_redirect( $user_login, $user  ) {
1427 1427
 
1428
-        if (user_can($user, 'edit_courses')) {
1428
+		if (user_can($user, 'edit_courses')) {
1429 1429
 
1430
-            if (isset($_POST['redirect_to'])) {
1430
+			if (isset($_POST['redirect_to'])) {
1431 1431
 
1432
-                wp_redirect($_POST['redirect_to'], 303);
1432
+				wp_redirect($_POST['redirect_to'], 303);
1433 1433
 
1434
-                exit;
1434
+				exit;
1435 1435
 
1436
-            } else {
1436
+			} else {
1437 1437
 
1438
-                wp_redirect(admin_url(), 303);
1438
+				wp_redirect(admin_url(), 303);
1439 1439
 
1440
-                exit;
1440
+				exit;
1441 1441
 
1442
-            }
1443
-        }
1442
+			}
1443
+		}
1444 1444
 
1445
-    } // end teacher_login_redirect()
1445
+	} // end teacher_login_redirect()
1446 1446
 
1447 1447
 
1448 1448
 
1449
-    /**
1450
-     * Sensei_Teacher::restrict_posts_menu_page()
1451
-     *
1452
-     * Remove the Posts menu page for teachers and restrict access to it.
1453
-     * We have to do this because we give teachers the 'edit_posts' cap
1454
-     * so they can 'moderate_comments' as well.
1455
-     *
1456
-     * @since 1.8.7
1457
-     * @access public
1458
-     * @parameters void
1459
-     * @return void
1460
-     */
1449
+	/**
1450
+	 * Sensei_Teacher::restrict_posts_menu_page()
1451
+	 *
1452
+	 * Remove the Posts menu page for teachers and restrict access to it.
1453
+	 * We have to do this because we give teachers the 'edit_posts' cap
1454
+	 * so they can 'moderate_comments' as well.
1455
+	 *
1456
+	 * @since 1.8.7
1457
+	 * @access public
1458
+	 * @parameters void
1459
+	 * @return void
1460
+	 */
1461 1461
 
1462
-    public function restrict_posts_menu_page() {
1462
+	public function restrict_posts_menu_page() {
1463 1463
 
1464
-        global $pagenow, $typenow;
1464
+		global $pagenow, $typenow;
1465 1465
 
1466
-        $user = wp_get_current_user();
1466
+		$user = wp_get_current_user();
1467 1467
 
1468
-        /**
1469
-         * Filter the option to hide the Posts menu page.
1470
-         *
1471
-         * @since 1.8.7
1472
-         *
1473
-         * @param bool $restrict default true
1474
-         */
1468
+		/**
1469
+		 * Filter the option to hide the Posts menu page.
1470
+		 *
1471
+		 * @since 1.8.7
1472
+		 *
1473
+		 * @param bool $restrict default true
1474
+		 */
1475 1475
 
1476
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1476
+		$restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1477 1477
 
1478
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1478
+		if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1479 1479
 
1480
-            remove_menu_page('edit.php');
1480
+			remove_menu_page('edit.php');
1481 1481
 
1482
-            if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1482
+			if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1483 1483
 
1484
-                if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1484
+				if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1485 1485
 
1486
-                    wp_die('You do not have sufficient permissions to access this page.');
1486
+					wp_die('You do not have sufficient permissions to access this page.');
1487 1487
 
1488
-                }
1488
+				}
1489 1489
 
1490
-            }
1490
+			}
1491 1491
 
1492
-        }
1492
+		}
1493 1493
 
1494
-    } // end restrict_posts_menu_page()
1494
+	} // end restrict_posts_menu_page()
1495 1495
 
1496
-    /**
1497
-     * Sensei_Teacher::restrict_comment_moderation()
1498
-     *
1499
-     * Restrict commendation moderation for teachers
1500
-     * so they can only moderate comments made to posts they own.
1501
-     *
1502
-     * @since 1.8.7
1503
-     * @access public
1504
-     * @parameters obj $clauses
1505
-     * @return obj $clauses
1506
-     */
1496
+	/**
1497
+	 * Sensei_Teacher::restrict_comment_moderation()
1498
+	 *
1499
+	 * Restrict commendation moderation for teachers
1500
+	 * so they can only moderate comments made to posts they own.
1501
+	 *
1502
+	 * @since 1.8.7
1503
+	 * @access public
1504
+	 * @parameters obj $clauses
1505
+	 * @return obj $clauses
1506
+	 */
1507 1507
 
1508
-    public function restrict_comment_moderation($clauses) {
1508
+	public function restrict_comment_moderation($clauses) {
1509 1509
 
1510
-        global $pagenow;
1510
+		global $pagenow;
1511 1511
 
1512
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1512
+		if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1513 1513
 
1514
-            $clauses->query_vars['post_author'] = get_current_user_id();
1514
+			$clauses->query_vars['post_author'] = get_current_user_id();
1515 1515
 
1516
-        }
1516
+		}
1517 1517
 
1518
-        return $clauses;
1518
+		return $clauses;
1519 1519
 
1520
-    }   // end restrict_comment_moderation()
1520
+	}   // end restrict_comment_moderation()
1521 1521
 
1522
-    /**
1523
-     * Determine if a user is a teacher by ID
1524
-     *
1525
-     * @param int $user_id
1526
-     *
1527
-     * @return bool
1528
-     */
1529
-    public static function is_a_teacher( $user_id ){
1522
+	/**
1523
+	 * Determine if a user is a teacher by ID
1524
+	 *
1525
+	 * @param int $user_id
1526
+	 *
1527
+	 * @return bool
1528
+	 */
1529
+	public static function is_a_teacher( $user_id ){
1530 1530
 
1531
-        $user = get_user_by('id', $user_id);
1531
+		$user = get_user_by('id', $user_id);
1532 1532
 
1533
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1533
+		if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1534 1534
 
1535
-            return true;
1535
+			return true;
1536 1536
 
1537
-        }else{
1537
+		}else{
1538 1538
 
1539
-            return false;
1539
+			return false;
1540 1540
 
1541
-        }
1541
+		}
1542 1542
 
1543
-    }// end is_a_teacher
1543
+	}// end is_a_teacher
1544 1544
 
1545
-    /**
1546
-     * The archive title on the teacher archive filter
1547
-     *
1548
-     * @since 1.9.0
1549
-     */
1550
-    public static function archive_title(){
1545
+	/**
1546
+	 * The archive title on the teacher archive filter
1547
+	 *
1548
+	 * @since 1.9.0
1549
+	 */
1550
+	public static function archive_title(){
1551 1551
 
1552
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1553
-        $author_name = $author->display_name;
1554
-        ?>
1552
+		$author = get_user_by( 'id', get_query_var( 'author' ) );
1553
+		$author_name = $author->display_name;
1554
+		?>
1555 1555
             <h2 class="teacher-archive-title">
1556 1556
 
1557 1557
                 <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
@@ -1559,17 +1559,17 @@  discard block
 block discarded – undo
1559 1559
             </h2>
1560 1560
         <?php
1561 1561
 
1562
-    }// archive title
1562
+	}// archive title
1563 1563
 
1564
-    /**
1565
-     * Removing course meta on the teacher archive page
1566
-     *
1567
-     * @since 1.9.0
1568
-     */
1569
-    public static function remove_course_meta_on_teacher_archive(){
1564
+	/**
1565
+	 * Removing course meta on the teacher archive page
1566
+	 *
1567
+	 * @since 1.9.0
1568
+	 */
1569
+	public static function remove_course_meta_on_teacher_archive(){
1570 1570
 
1571
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1571
+		remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1572 1572
 
1573
-    }
1573
+	}
1574 1574
 
1575 1575
 } // End Class
Please login to merge, or discard this patch.
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Teacher class
@@ -42,58 +42,58 @@  discard block
 block discarded – undo
42 42
      * @since 1.8.0
43 43
      * @access public
44 44
      */
45
-    public function __construct ( ) {
45
+    public function __construct( ) {
46 46
 
47
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
47
+        add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2);
48
+        add_action('save_post', array($this, 'save_teacher_meta_box'));
49
+        add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types'));
50
+        add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit'));
51
+        add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3);
52 52
 
53
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
53
+        add_action('pre_get_posts', array($this, 'filter_queries'));
54 54
 
55 55
         //filter the quiz submissions
56
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
56
+        add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries'));
57 57
 
58 58
         //grading totals count only those belonging to the teacher
59
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
59
+        add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals'));
60 60
 
61 61
         // show the courses owned by a user on his author archive page
62
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
62
+        add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive'));
63 63
 
64 64
         // notify admin when a teacher creates a course
65
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
65
+        add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3);
66 66
 
67 67
         // limit the analysis view to only the users taking courses belong to this teacher
68
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
68
+        add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1);
69 69
 
70 70
         // give teacher access to question post type
71
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
71
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
72 72
 
73 73
         // Teacher column on the courses list on the admin edit screen
74
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
+        add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1);
75
+        add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2);
76 76
 
77 77
         //admin edit messages query limit teacher
78
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
78
+        add_filter('pre_get_posts', array($this, 'limit_edit_messages_query'));
79 79
 
80 80
         //add filter by teacher on courses list
81
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
+        add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options'));
82
+        add_filter('request', array($this, 'teacher_filter_query_modify'));
83 83
 
84 84
         // Handle media library restrictions
85
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
+        add_filter('request', array($this, 'restrict_media_library'), 10, 1);
86
+        add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1);
87 87
 
88 88
         // update lesson owner to course teacher when saved
89
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
89
+        add_action('save_post', array($this, 'update_lesson_teacher'));
90 90
 
91 91
         // If a Teacher logs in, redirect to /wp-admin/
92
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
92
+        add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2);
93 93
 
94 94
 
95
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
+        add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10);
96
+        add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1);
97 97
 
98 98
 
99 99
     } // end __constructor()
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
      * @access public
109 109
      * @return void
110 110
      */
111
-    public function create_role ( ) {
111
+    public function create_role( ) {
112 112
 
113 113
         // check if the role exists
114
-        $this->teacher_role = get_role( 'teacher' );
114
+        $this->teacher_role = get_role('teacher');
115 115
 
116 116
         // if the the teacher is not a valid WordPress role create it
117
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
117
+       if ( ! is_a($this->teacher_role, 'WP_Role')) {
118 118
            // create the role
119
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
119
+           $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei'));
120 120
        }
121 121
 
122 122
        // add the capabilities before returning
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
      * @since 1.8.0
131 131
      * @access protected
132 132
      */
133
-    protected function add_capabilities ( ) {
133
+    protected function add_capabilities( ) {
134 134
 
135 135
         // if this is not a valid WP_Role object exit without adding anything
136
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
136
+        if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) {
137 137
             return;
138 138
         }
139 139
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
          * @param array $capabilities
145 145
          * keys: (string) $cap_name => (bool) $grant
146 146
          */
147
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
147
+        $caps = apply_filters('sensei_teacher_role_capabilities', array(
148 148
             // General access rules
149 149
             'read' => true,
150 150
             'manage_sensei_grades' => true,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
         ));
203 203
 
204
-        foreach ( $caps as $cap => $grant ) {
204
+        foreach ($caps as $cap => $grant) {
205 205
 
206 206
             // load the capability on to the teacher role
207 207
             $this->teacher_role->add_cap($cap, $grant);
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
      * @parameter WP_Post $post
222 222
      * @return void
223 223
      */
224
-    public function add_teacher_meta_boxes ( $post ) {
224
+    public function add_teacher_meta_boxes($post) {
225 225
 
226
-        if( !current_user_can('manage_options') ){
226
+        if ( ! current_user_can('manage_options')) {
227 227
             return;
228 228
         }
229
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
229
+        add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'),
230 230
             'course',
231 231
             'side',
232 232
             'core'
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      * @access public
244 244
      * @parameters
245 245
      */
246
-    public function teacher_meta_box_content ( $post ) {
246
+    public function teacher_meta_box_content($post) {
247 247
 
248 248
         // get the current author
249 249
         $current_author = $post->post_author;
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
     ?>
255 255
         <select name="sensei-course-teacher-author" class="sensei course teacher">
256 256
 
257
-            <?php foreach ( $users as $user_id ) { ?>
257
+            <?php foreach ($users as $user_id) { ?>
258 258
 
259 259
                     <?php
260 260
                         $user = get_user_by('id', $user_id);
261 261
                     ?>
262
-                    <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
262
+                    <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" >
263 263
                         <?php echo  $user->display_name; ?>
264 264
                     </option>
265 265
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
      * @parameters
282 282
      * @return array $users user id array
283 283
      */
284
-    public function get_teachers_and_authors ( ){
284
+    public function get_teachers_and_authors( ) {
285 285
 
286 286
         $author_query_args = array(
287 287
             'blog_id'      => $GLOBALS['blog_id'],
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
             'who'          => 'authors'
290 290
         );
291 291
 
292
-        $authors = get_users( $author_query_args );
292
+        $authors = get_users($author_query_args);
293 293
 
294 294
         $teacher_query_args = array(
295 295
             'blog_id'      => $GLOBALS['blog_id'],
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
             'role'         => 'teacher',
298 298
         );
299 299
 
300
-        $teachers = get_users( $teacher_query_args );
300
+        $teachers = get_users($teacher_query_args);
301 301
 
302
-        return  array_unique( array_merge( $teachers, $authors ) );
302
+        return  array_unique(array_merge($teachers, $authors));
303 303
 
304 304
     }// end get_teachers_and_authors
305 305
 
@@ -315,43 +315,43 @@  discard block
 block discarded – undo
315 315
      * @parameters
316 316
      * @return array $users user id array
317 317
      */
318
-    public function save_teacher_meta_box ( $course_id ){
318
+    public function save_teacher_meta_box($course_id) {
319 319
 
320 320
         // check if this is a post from saving the teacher, if not exit early
321
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
321
+        if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) {
322 322
             return;
323 323
         }
324 324
 
325 325
         //don't fire this hook again
326
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
326
+        remove_action('save_post', array($this, 'save_teacher_meta_box'));
327 327
 
328 328
         // get the current post object
329
-        $post = get_post( $course_id );
329
+        $post = get_post($course_id);
330 330
 
331 331
         // get the current teacher/author
332
-        $current_author = absint( $post->post_author );
333
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
332
+        $current_author = absint($post->post_author);
333
+        $new_author = absint($_POST['sensei-course-teacher-author']);
334 334
 
335 335
         // loop through all post lessons to update their authors as well
336
-        $this->update_course_lessons_author( $course_id , $new_author );
336
+        $this->update_course_lessons_author($course_id, $new_author);
337 337
 
338 338
         // do not do any processing if the selected author is the same as the current author
339
-        if( $current_author == $new_author ){
339
+        if ($current_author == $new_author) {
340 340
             return;
341 341
         }
342 342
 
343 343
         // save the course  author
344 344
         $post_updates = array(
345
-            'ID' => $post->ID ,
345
+            'ID' => $post->ID,
346 346
             'post_author' => $new_author
347 347
         );
348
-        wp_update_post( $post_updates );
348
+        wp_update_post($post_updates);
349 349
 
350 350
         // ensure the the modules are update so that then new teacher has access to them
351
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
351
+        Sensei_Teacher::update_course_modules_author($course_id, $new_author);
352 352
 
353 353
         // notify the new teacher
354
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
354
+        $this->teacher_course_assigned_notification($new_author, $course_id);
355 355
 
356 356
     } // end save_teacher_meta_box
357 357
 
@@ -365,56 +365,56 @@  discard block
 block discarded – undo
365 365
      * @param $new_teacher_id
366 366
      * @return void
367 367
      */
368
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
368
+    public static function update_course_modules_author($course_id, $new_teacher_id) {
369 369
 
370
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
370
+        if (empty($course_id) || empty($new_teacher_id)) {
371 371
             return false;
372 372
         }
373 373
 
374
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
374
+        $terms_selected_on_course = wp_get_object_terms($course_id, 'module');
375 375
 
376
-        if( empty( $terms_selected_on_course ) ){
376
+        if (empty($terms_selected_on_course)) {
377 377
             return;
378 378
         }
379 379
 
380
-        foreach( $terms_selected_on_course as $term ){
380
+        foreach ($terms_selected_on_course as $term) {
381 381
 
382
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
-            if( $new_teacher_id != $term_author->ID  ){
382
+            $term_author = Sensei_Core_Modules::get_term_author($term->slug);
383
+            if ($new_teacher_id != $term_author->ID) {
384 384
 
385 385
                 $new_term = '';
386 386
 
387 387
                 //if the new teacher is admin first check to see if the term with this name already exists
388
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
388
+                if (user_can($new_teacher_id, 'manage_options')) {
389 389
 
390
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
-                    $existing_admin_terms = get_terms( 'module', $term_args );
393
-                    if( !empty( $existing_admin_terms ) ){
390
+                    $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name));
391
+                    $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,);
392
+                    $existing_admin_terms = get_terms('module', $term_args);
393
+                    if ( ! empty($existing_admin_terms)) {
394 394
                         // insert it even if it exists
395
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
395
+                        $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A);
396 396
                     }
397 397
                 }
398 398
 
399
-                if( empty ( $new_term ) ){
399
+                if (empty ($new_term)) {
400 400
 
401 401
                    //setup the new slug
402
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
402
+                   $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name));
403 403
 
404 404
                    // create new term and set it
405
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
405
+                   $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug));
406 406
 
407 407
                 }
408 408
 
409 409
 
410 410
 
411 411
                 // if term exists
412
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
412
+                if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) {
413 413
 
414
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
414
+                    $existing_term = get_term_by('slug', $new_author_term_slug, 'module');
415 415
                     $term_id = $existing_term->term_id;
416 416
 
417
-                }else{
417
+                } else {
418 418
 
419 419
                     // for a new term simply get the term from the returned value
420 420
                     $term_id = $new_term['term_id'];
@@ -422,21 +422,21 @@  discard block
 block discarded – undo
422 422
                 } // end if term exist
423 423
 
424 424
                 // set the terms selected on the course
425
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
425
+                wp_set_object_terms($course_id, $term_id, 'module', true);
426 426
 
427 427
                 // remove old term
428
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
428
+                wp_remove_object_terms($course_id, $term->term_id, 'module');
429 429
 
430 430
                 // update the lessons within the current module term
431
-                $lessons = Sensei()->course->course_lessons( $course_id );
432
-                foreach( $lessons as $lesson  ){
431
+                $lessons = Sensei()->course->course_lessons($course_id);
432
+                foreach ($lessons as $lesson) {
433 433
 
434
-                    if( has_term( $term->slug, 'module', $lesson ) ){
434
+                    if (has_term($term->slug, 'module', $lesson)) {
435 435
 
436 436
                         // add the new term, the false at the end says to replace all terms on this module
437 437
                         // with the new term.
438
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
+                        wp_set_object_terms($lesson->ID, $term_id, 'module', false);
439
+                        update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0);
440 440
                     }
441 441
 
442 442
                 }// end for each
@@ -456,50 +456,50 @@  discard block
 block discarded – undo
456 456
      * @parameters
457 457
      * @return array $users user id array
458 458
      */
459
-    public function update_course_lessons_author ( $course_id, $new_author  ){
459
+    public function update_course_lessons_author($course_id, $new_author) {
460 460
 
461 461
 
462
-        if( empty( $course_id ) || empty( $new_author ) ){
462
+        if (empty($course_id) || empty($new_author)) {
463 463
             return false;
464 464
         }
465 465
 
466 466
         //get a list of course lessons
467
-        $lessons = Sensei()->course->course_lessons( $course_id );
467
+        $lessons = Sensei()->course->course_lessons($course_id);
468 468
 
469
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
469
+        if (empty($lessons) || ! is_array($lessons)) {
470 470
             return false;
471 471
         }
472 472
 
473 473
         // update each lesson and quiz author
474
-        foreach( $lessons as $lesson ){
474
+        foreach ($lessons as $lesson) {
475 475
 
476 476
             // don't update if the author is tha same as the new author
477
-            if( $new_author == $lesson->post_author ){
477
+            if ($new_author == $lesson->post_author) {
478 478
                 continue;
479 479
             }
480 480
 
481 481
             // update lesson author
482
-            wp_update_post( array(
482
+            wp_update_post(array(
483 483
                 'ID'=> $lesson->ID,
484 484
                 'post_author' => $new_author
485
-                ) );
485
+                ));
486 486
 
487 487
             // update quiz author
488 488
             //get the lessons quiz
489
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
-            if( is_array( $lesson_quizzes ) ){
491
-                foreach ( $lesson_quizzes as $quiz_id ) {
489
+            $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID);
490
+            if (is_array($lesson_quizzes)) {
491
+                foreach ($lesson_quizzes as $quiz_id) {
492 492
                     // update quiz with new author
493
-                    wp_update_post( array(
493
+                    wp_update_post(array(
494 494
                         'ID'           => $quiz_id,
495 495
                         'post_author' =>  $new_author
496
-                    ) );
496
+                    ));
497 497
                 }
498
-            }else{
499
-                wp_update_post( array(
498
+            } else {
499
+                wp_update_post(array(
500 500
                     'ID'           => $lesson_quizzes,
501 501
                     'post_author' =>  $new_author
502
-                ) );
502
+                ));
503 503
             }
504 504
 
505 505
         } // end for each lessons
@@ -520,30 +520,30 @@  discard block
 block discarded – undo
520 520
      * @parameters $query
521 521
      * @return array $users user id array
522 522
      */
523
-    public function course_analysis_teacher_access_limit ( $query ) {
523
+    public function course_analysis_teacher_access_limit($query) {
524 524
 
525
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
525
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
526 526
             return $query;
527 527
         }
528 528
 
529
-        if ( ! function_exists( 'get_current_screen' ) ) {
529
+        if ( ! function_exists('get_current_screen')) {
530 530
             return $query;
531 531
         }
532 532
 
533 533
         $screen = get_current_screen();
534
-        $sensei_post_types = array('course', 'lesson', 'question' );
534
+        $sensei_post_types = array('course', 'lesson', 'question');
535 535
 
536 536
         // exit early for the following conditions
537
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
537
+        $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order');
538 538
 
539
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
+        if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids)
540
+            || ! in_array($query->query['post_type'], $sensei_post_types)) {
541 541
             return $query;
542 542
         }
543 543
 
544 544
         global $current_user;
545 545
         // set the query author to the current user to only show those those posts
546
-        $query->set( 'author', $current_user->ID );
546
+        $query->set('author', $current_user->ID);
547 547
         return $query;
548 548
 
549 549
     }// end course_analysis_teacher_access_limit
@@ -559,14 +559,14 @@  discard block
 block discarded – undo
559 559
      * @parameters array $wp_query
560 560
      * @return bool $is_admin_teacher
561 561
      */
562
-    public function is_admin_teacher ( ){
562
+    public function is_admin_teacher( ) {
563 563
 
564
-        if( ! is_user_logged_in()){
564
+        if ( ! is_user_logged_in()) {
565 565
             return false;
566 566
         }
567 567
         $is_admin_teacher = false;
568 568
 
569
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
569
+        if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) {
570 570
 
571 571
             $is_admin_teacher = true;
572 572
 
@@ -586,14 +586,14 @@  discard block
 block discarded – undo
586 586
      * @param  string $perm   User permission level
587 587
      * @return object         Modified status counts
588 588
      */
589
-    public function list_table_counts( $counts, $type, $perm ) {
589
+    public function list_table_counts($counts, $type, $perm) {
590 590
         global $current_user;
591 591
 
592
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
592
+        if ( ! in_array($type, array('course', 'lesson', 'question'))) {
593 593
             return $counts;
594 594
         }
595 595
 
596
-        if( ! $this->is_admin_teacher() ) {
596
+        if ( ! $this->is_admin_teacher()) {
597 597
             return $counts;
598 598
         }
599 599
 
@@ -607,10 +607,10 @@  discard block
 block discarded – undo
607 607
         $stati = get_post_stati();
608 608
 
609 609
         // Update count object
610
-        foreach( $stati as $status ) {
610
+        foreach ($stati as $status) {
611 611
             $args['post_status'] = $status;
612
-            $posts = get_posts( $args );
613
-            $counts->$status = count( $posts );
612
+            $posts = get_posts($args);
613
+            $counts->$status = count($posts);
614 614
         }
615 615
 
616 616
         return $counts;
@@ -624,22 +624,22 @@  discard block
 block discarded – undo
624 624
      * @since 1.8.0
625 625
      *
626 626
      */
627
-    public function filter_queries ( $query ) {
627
+    public function filter_queries($query) {
628 628
         global $current_user;
629 629
 
630
-        if( ! $this->is_admin_teacher() ) {
630
+        if ( ! $this->is_admin_teacher()) {
631 631
             return;
632 632
         }
633 633
 
634
-        if ( ! function_exists( 'get_current_screen' ) ) {
634
+        if ( ! function_exists('get_current_screen')) {
635 635
             return;
636 636
         }
637 637
 
638 638
         $screen = get_current_screen();
639
-        if( empty( $screen ) ) {
639
+        if (empty($screen)) {
640 640
             return $query;
641 641
         }
642
-        switch( $screen->id ) {
642
+        switch ($screen->id) {
643 643
             case 'sensei_page_sensei_grading':
644 644
             case 'sensei_page_sensei_analysis':
645 645
             case 'sensei_page_sensei_learners':
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
              * @param string $screen_id
659 659
              *
660 660
              */
661
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
661
+            $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id));
662 662
             break;
663 663
         }
664 664
     }
@@ -673,31 +673,31 @@  discard block
 block discarded – undo
673 673
      *
674 674
      * @return array $comments
675 675
      */
676
-    public function filter_grading_activity_queries( $comments ){
676
+    public function filter_grading_activity_queries($comments) {
677 677
 
678
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
-            return $comments ;
678
+        if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) {
679
+            return $comments;
680 680
         }
681 681
 
682 682
         //check if we're on the grading screen
683 683
         $screen = get_current_screen();
684 684
 
685
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
685
+        if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) {
686 686
             return $comments;
687 687
         }
688 688
 
689 689
         // get the course and determine if the current teacher is the owner
690 690
         // if not remove it from the list of comments to be returned
691
-        foreach( $comments as $key => $comment){
692
-            $lesson = get_post( $comment->comment_post_ID );
693
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
-            $course = get_post( $course_id );
695
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
691
+        foreach ($comments as $key => $comment) {
692
+            $lesson = get_post($comment->comment_post_ID);
693
+            $course_id = Sensei()->lesson->get_course_id($lesson->ID);
694
+            $course = get_post($course_id);
695
+            if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) {
696 696
                 //remove this as the teacher should see this.
697
-                unset( $comments[ $key ] );
697
+                unset($comments[$key]);
698 698
             }
699 699
         }
700
-        return $comments ;
700
+        return $comments;
701 701
 
702 702
     }// end function filter grading
703 703
 
@@ -713,34 +713,34 @@  discard block
 block discarded – undo
713 713
      *
714 714
      * @return array  $args
715 715
      */
716
-    public function limit_grading_totals( $args ){
716
+    public function limit_grading_totals($args) {
717 717
 
718
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
-            return $args ;
718
+        if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) {
719
+            return $args;
720 720
         }
721 721
 
722 722
         //get the teachers courses
723 723
         // the query is already filtered to only the teacher
724
-        $courses =  Sensei()->course->get_all_courses();
724
+        $courses = Sensei()->course->get_all_courses();
725 725
 
726
-        if( empty(  $courses ) || ! is_array( $courses ) ){
726
+        if (empty($courses) || ! is_array($courses)) {
727 727
             return $args;
728 728
         }
729 729
 
730 730
         //setup the lessons quizzes  to limit the grading totals to
731 731
         $quiz_scope = array();
732
-        foreach( $courses as $course ){
732
+        foreach ($courses as $course) {
733 733
 
734
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
734
+            $course_lessons = Sensei()->course->course_lessons($course->ID);
735 735
 
736
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
736
+            if ( ! empty($course_lessons) && is_array($course_lessons)) {
737 737
 
738
-                foreach(  $course_lessons as $lesson ){
738
+                foreach ($course_lessons as $lesson) {
739 739
 
740
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
-                    if( !empty( $quiz_id ) ) {
740
+                    $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
741
+                    if ( ! empty($quiz_id)) {
742 742
 
743
-                        array_push( $quiz_scope, $quiz_id );
743
+                        array_push($quiz_scope, $quiz_id);
744 744
 
745 745
                     }
746 746
 
@@ -763,41 +763,41 @@  discard block
 block discarded – undo
763 763
      * @param WP_Query $query
764 764
      * @return WP_Query $query
765 765
      */
766
-    public function add_courses_to_author_archive( $query ) {
766
+    public function add_courses_to_author_archive($query) {
767 767
 
768
-        if ( is_admin() || ! $query->is_author() ){
768
+        if (is_admin() || ! $query->is_author()) {
769 769
             return $query;
770 770
         }
771 771
 
772 772
         // this should only apply to users with the teacher role
773
-        $current_page_user = get_user_by('login', $query->get('author_name') );
774
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
+        $current_page_user = get_user_by('login', $query->get('author_name'));
774
+        if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) {
775 775
 
776 776
             return $query;
777 777
 
778 778
         }
779 779
 
780 780
         // Change post types depending on what is set already
781
-        $current_post_types = $query->get( 'post_type' );
782
-        if( empty( $current_post_types  ) ){
781
+        $current_post_types = $query->get('post_type');
782
+        if (empty($current_post_types)) {
783 783
 
784 784
             // if empty it means post by default, so add post so that it also includes that for now
785
-            $new_post_types = array( 'post', 'course' );
785
+            $new_post_types = array('post', 'course');
786 786
 
787
-        } elseif( is_array( $current_post_types  ) ) {
787
+        } elseif (is_array($current_post_types)) {
788 788
 
789 789
             // merge the post types instead of overwriting it
790
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
790
+            $new_post_types = array_merge($current_post_types, array('course'));
791 791
 
792
-        }else{
792
+        } else {
793 793
 
794 794
             // in this instance it is probably just one post type in string format
795
-            $new_post_types =  array( $current_post_types , 'course');
795
+            $new_post_types = array($current_post_types, 'course');
796 796
 
797 797
         }
798 798
 
799 799
         // change the query before returning it
800
-        $query->set('post_type', $new_post_types );
800
+        $query->set('post_type', $new_post_types);
801 801
 
802 802
         /**
803 803
          * Change the query on the teacher author archive template
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
          * @since 1.8.4
806 806
          * @param WP_Query $query
807 807
          */
808
-        return apply_filters( 'sensei_teacher_archive_query', $query );
808
+        return apply_filters('sensei_teacher_archive_query', $query);
809 809
 
810 810
     }
811 811
 
@@ -818,21 +818,21 @@  discard block
 block discarded – undo
818 818
      * @param $course_id
819 819
      * @return bool
820 820
      */
821
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
821
+    public function teacher_course_assigned_notification($teacher_id, $course_id) {
822 822
 
823
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
823
+        if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) {
824 824
             return false;
825 825
         }
826 826
 
827 827
         // if new user is the same as the current logged user, they don't need an email
828
-        if( $teacher_id == get_current_user_id() ){
828
+        if ($teacher_id == get_current_user_id()) {
829 829
             return true;
830 830
         }
831 831
 
832 832
         // load the email class
833 833
         include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834 834
         $email = new Teacher_New_Course_Assignment();
835
-        $email->trigger( $teacher_id, $course_id );
835
+        $email->trigger($teacher_id, $course_id);
836 836
 
837 837
         return true;
838 838
     } // end  teacher_course_assigned_notification
@@ -846,12 +846,12 @@  discard block
 block discarded – undo
846 846
      * @param int $course_id
847 847
      * @return bool
848 848
      */
849
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
849
+    public function notify_admin_teacher_course_creation($new_status, $old_status, $post) {
850 850
 
851 851
         $course_id = $post->ID;
852 852
 
853
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
+        if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id)
854
+            || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) {
855 855
 
856 856
             return false;
857 857
 
@@ -865,19 +865,19 @@  discard block
 block discarded – undo
865 865
          *
866 866
          * @param bool $on default true
867 867
          */
868
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
868
+        if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) {
869 869
             return false;
870 870
         }
871 871
 
872 872
         // setting up the data needed by the email template
873 873
         global $sensei_email_data;
874 874
         $template = 'admin-teacher-new-course-created';
875
-        $course = get_post( $course_id );
876
-        $teacher = new WP_User( $course->post_author );
875
+        $course = get_post($course_id);
876
+        $teacher = new WP_User($course->post_author);
877 877
         $recipient = get_option('admin_email', true);
878 878
 
879 879
         // don't send if the course is created by admin
880
-        if( $recipient == $teacher->user_email ){
880
+        if ($recipient == $teacher->user_email) {
881 881
             return;
882 882
         }
883 883
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
          * @since 1.8.0
888 888
          * @param string $template
889 889
          */
890
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
890
+        $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template);
891 891
 
892 892
         /**
893 893
          * Filter the email subject for the the
@@ -898,11 +898,11 @@  discard block
 block discarded – undo
898 898
          * @param string $template
899 899
          */
900 900
         $subject = apply_filters('sensei_email_subject',
901
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
-                                $template );
901
+                                '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name,
902
+                                $template);
903 903
 
904 904
         //course edit link
905
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
905
+        $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit');
906 906
 
907 907
         // Construct data array
908 908
         $email_data = array(
@@ -921,10 +921,10 @@  discard block
 block discarded – undo
921 921
          * @param array $email_data
922 922
          * @param string $template
923 923
          */
924
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
924
+        $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template);
925 925
 
926 926
         // Send mail
927
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
927
+        Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template));
928 928
 
929 929
     }// end notify admin of course creation
930 930
 
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
      * @param array $args WP_User_Query arguments
936 936
      * @return array $learners_query_results
937 937
      */
938
-    public function limit_analysis_learners( $args ){
938
+    public function limit_analysis_learners($args) {
939 939
 
940 940
         // show default for none teachers
941
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
941
+        if ( ! Sensei()->teacher->is_admin_teacher()) {
942 942
                 return $args;
943 943
         }
944 944
 
@@ -947,31 +947,31 @@  discard block
 block discarded – undo
947 947
         $teacher_courses = Sensei()->course->get_all_courses();
948 948
 
949 949
         // if the user has no courses they should see no users
950
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
950
+        if (empty($teacher_courses) || ! is_array($teacher_courses)) {
951 951
             // tell the query to return 0 students
952
-            $args[ 'include'] = array( 0 );
952
+            $args['include'] = array(0);
953 953
             return $args;
954 954
 
955 955
         }
956 956
 
957 957
         $learner_ids_for_teacher_courses = array();
958
-        foreach( $teacher_courses as $course ){
958
+        foreach ($teacher_courses as $course) {
959 959
 
960 960
             $course_learner_ids = array();
961
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
961
+            $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true);
962 962
 
963
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
963
+            if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) {
964 964
                 continue; // skip to the next course as there are no users on this course
965 965
             }
966 966
 
967 967
             // it could be an array of comments or a single comment
968
-            if( is_array( $activity_comments ) ){
968
+            if (is_array($activity_comments)) {
969 969
 
970
-                foreach( $activity_comments as $comment ){
970
+                foreach ($activity_comments as $comment) {
971 971
 
972
-                    $user = get_userdata( $comment->user_id );
972
+                    $user = get_userdata($comment->user_id);
973 973
 
974
-                    if( empty( $user ) ){
974
+                    if (empty($user)) {
975 975
                         // next comment in this array
976 976
                         continue;
977 977
                     }
@@ -979,26 +979,26 @@  discard block
 block discarded – undo
979 979
                     $course_learner_ids[] = $user->ID;
980 980
                 }
981 981
 
982
-            }else{
982
+            } else {
983 983
 
984
-                $user = get_userdata( $activity_comments->user_id );
984
+                $user = get_userdata($activity_comments->user_id);
985 985
                 $course_learner_ids[] = $user->ID;
986 986
 
987 987
             }
988 988
 
989 989
             // add learners on this course to the all courses learner list
990
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
990
+            $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids);
991 991
 
992 992
         }
993 993
 
994 994
         // if there are no students taking the courses by this teacher don't show them any of the other users
995
-        if( empty( $learner_ids_for_teacher_courses ) ){
995
+        if (empty($learner_ids_for_teacher_courses)) {
996 996
 
997
-            $args[ 'include'] = array( 0 );
997
+            $args['include'] = array(0);
998 998
 
999
-        }else{
999
+        } else {
1000 1000
 
1001
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
1001
+            $args['include'] = $learner_ids_for_teacher_courses;
1002 1002
 
1003 1003
         }
1004 1004
 
@@ -1015,35 +1015,35 @@  discard block
 block discarded – undo
1015 1015
      * @param $questions
1016 1016
      * @return mixed
1017 1017
      */
1018
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1018
+    public function allow_teacher_access_to_questions($questions, $quiz_id) {
1019 1019
 
1020
-        if( ! $this->is_admin_teacher() ){
1020
+        if ( ! $this->is_admin_teacher()) {
1021 1021
             return $questions;
1022 1022
         }
1023 1023
 
1024 1024
         $screen = get_current_screen();
1025 1025
 
1026 1026
         // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1027
+        remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20);
1028 1028
 
1029
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1029
+        if ( ! empty($screen) && 'lesson' == $screen->post_type) {
1030 1030
 
1031 1031
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
-            if( ! empty($admin_user) ){
1032
+            if ( ! empty($admin_user)) {
1033 1033
 
1034 1034
                 $current_teacher_id = get_current_user_id();
1035 1035
 
1036 1036
                 // set current user to admin so teacher can view all questions
1037
-                wp_set_current_user( $admin_user->ID  );
1038
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1037
+                wp_set_current_user($admin_user->ID);
1038
+                $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
1039 1039
 
1040 1040
                 // set the teacher as the current use again
1041
-                wp_set_current_user( $current_teacher_id );
1041
+                wp_set_current_user($current_teacher_id);
1042 1042
             }
1043 1043
 
1044 1044
         }
1045 1045
         // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1046
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
1047 1047
 
1048 1048
         return $questions;
1049 1049
     }
@@ -1055,30 +1055,30 @@  discard block
 block discarded – undo
1055 1055
      * @param $wp_query
1056 1056
      * @return mixed
1057 1057
      */
1058
-    public function give_access_to_all_questions( $wp_query ){
1058
+    public function give_access_to_all_questions($wp_query) {
1059 1059
 
1060
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1060
+        if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) {
1061 1061
 
1062 1062
             return $wp_query;
1063 1063
         }
1064 1064
 
1065 1065
         $screen = get_current_screen();
1066
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1066
+        if ((isset($screen->id) && 'lesson' == $screen->id)
1067
+            || (defined('DOING_AJAX') && DOING_AJAX)) {
1068 1068
 
1069 1069
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
-            if( ! empty($admin_user) ){
1070
+            if ( ! empty($admin_user)) {
1071 1071
 
1072 1072
                 $current_teacher_id = get_current_user_id();
1073 1073
 
1074 1074
                 // set current user to admin so teacher can view all questions
1075
-                wp_set_current_user( $admin_user->ID  );
1075
+                wp_set_current_user($admin_user->ID);
1076 1076
 
1077 1077
                 //run new query as admin
1078
-                $wp_query = new WP_Query( $wp_query->query );
1078
+                $wp_query = new WP_Query($wp_query->query);
1079 1079
 
1080 1080
                 //set the teache as current use again
1081
-                wp_set_current_user( $current_teacher_id );
1081
+                wp_set_current_user($current_teacher_id);
1082 1082
 
1083 1083
             }
1084 1084
         }
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
      */
1096 1096
     public function course_column_heading($columns) {
1097 1097
 
1098
-        if( $this->is_admin_teacher() ){
1098
+        if ($this->is_admin_teacher()) {
1099 1099
             return $columns;
1100 1100
         }
1101 1101
         $new_columns = array(
@@ -1112,20 +1112,20 @@  discard block
 block discarded – undo
1112 1112
      * @param $column
1113 1113
      * @param $course_id
1114 1114
      */
1115
-    public function course_column_data( $column, $course_id  ){
1115
+    public function course_column_data($column, $course_id) {
1116 1116
 
1117
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1117
+        if ($this->is_admin_teacher() || 'teacher' != $column) {
1118 1118
             return;
1119 1119
         }
1120 1120
 
1121
-        $course = get_post( $course_id );
1122
-        $teacher = get_userdata( $course->post_author );
1121
+        $course = get_post($course_id);
1122
+        $teacher = get_userdata($course->post_author);
1123 1123
 
1124
-        if( !$teacher ){
1124
+        if ( ! $teacher) {
1125 1125
             return;
1126 1126
         }
1127 1127
 
1128
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1128
+        echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>';
1129 1129
 
1130 1130
     }// end course_column_ data
1131 1131
 
@@ -1140,31 +1140,31 @@  discard block
 block discarded – undo
1140 1140
      *
1141 1141
      * @return array $teachers_courses
1142 1142
      */
1143
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1143
+    public function get_teacher_courses($teacher_id, $return_ids_only = false) {
1144 1144
 
1145 1145
         $teachers_courses = array();
1146 1146
 
1147
-        if( empty( $teacher_id  ) ){
1147
+        if (empty($teacher_id)) {
1148 1148
             $teacher_id = get_current_user_id();
1149 1149
         }
1150 1150
 
1151 1151
         $all_courses = Sensei()->course->get_all_courses();
1152 1152
 
1153
-        if( empty( $all_courses ) ){
1153
+        if (empty($all_courses)) {
1154 1154
             return $all_courses;
1155 1155
         }
1156 1156
 
1157
-        foreach( $all_courses as $course ){
1157
+        foreach ($all_courses as $course) {
1158 1158
 
1159
-            if( $course->post_author != $teacher_id  ){
1159
+            if ($course->post_author != $teacher_id) {
1160 1160
                 continue;
1161 1161
             }
1162 1162
 
1163
-            if( $return_ids_only ){
1163
+            if ($return_ids_only) {
1164 1164
 
1165 1165
                 $teachers_courses[] = $course->ID;
1166 1166
 
1167
-            }else{
1167
+            } else {
1168 1168
 
1169 1169
                 $teachers_courses[] = $course;
1170 1170
 
@@ -1184,21 +1184,21 @@  discard block
 block discarded – undo
1184 1184
      * @param $query
1185 1185
      * @return mixed
1186 1186
      */
1187
-    public function limit_edit_messages_query( $query ){
1188
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
+    public function limit_edit_messages_query($query) {
1188
+        if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) {
1189 1189
             return $query;
1190 1190
         }
1191 1191
 
1192 1192
         $teacher = wp_get_current_user();
1193 1193
 
1194
-        $query->set( 'meta_key', '_receiver' );
1194
+        $query->set('meta_key', '_receiver');
1195 1195
         $meta_query_args = array(
1196 1196
             'key'     => '_receiver',
1197
-            'value'   => $teacher->get('user_login') ,
1197
+            'value'   => $teacher->get('user_login'),
1198 1198
             'compare' => '='
1199 1199
         );
1200 1200
 
1201
-        $query->set('meta_query', $meta_query_args  );
1201
+        $query->set('meta_query', $meta_query_args);
1202 1202
 
1203 1203
         return $query;
1204 1204
     }
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
     public function course_teacher_filter_options() {
1215 1215
         global $typenow;
1216 1216
 
1217
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1217
+        if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) {
1218 1218
             return;
1219 1219
         }
1220 1220
 
@@ -1224,31 +1224,31 @@  discard block
 block discarded – undo
1224 1224
         // get roles with the course edit capability
1225 1225
         // and then get the users with those roles
1226 1226
         $users_who_can_edit_courses = array();
1227
-        foreach( $roles as $role_item ){
1227
+        foreach ($roles as $role_item) {
1228 1228
 
1229
-            $role = get_role( strtolower( $role_item['name'] ) );
1229
+            $role = get_role(strtolower($role_item['name']));
1230 1230
 
1231
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1231
+            if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) {
1232 1232
 
1233
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1233
+                $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name'));
1234
+                $role_users_who_can_edit_courses = get_users($user_query_args);
1235 1235
 
1236 1236
                 // add user from the current $user_role to all users
1237
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1237
+                $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses);
1238 1238
 
1239 1239
             }
1240 1240
 
1241 1241
         }
1242 1242
 
1243 1243
         // Create the select element with the given users who can edit course
1244
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1244
+        $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1245 1245
         $course_options = '';
1246
-        foreach( $users_who_can_edit_courses as $user ) {
1247
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
+        foreach ($users_who_can_edit_courses as $user) {
1247
+            $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>';
1248 1248
         }
1249 1249
 
1250 1250
         $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1251
+        $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>';
1252 1252
         $output .= $course_options;
1253 1253
         $output .= '</select>';
1254 1254
 
@@ -1263,15 +1263,15 @@  discard block
 block discarded – undo
1263 1263
      * @param $query
1264 1264
      * @return $query
1265 1265
      */
1266
-    public function teacher_filter_query_modify( $query ){
1266
+    public function teacher_filter_query_modify($query) {
1267 1267
         global $typenow;
1268 1268
 
1269
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1269
+        if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) {
1270 1270
             return $query;
1271 1271
         }
1272
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1272
+        $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1273 1273
 
1274
-        if( empty( $course_teacher ) ) {
1274
+        if (empty($course_teacher)) {
1275 1275
             return $query;
1276 1276
         }
1277 1277
 
@@ -1284,23 +1284,23 @@  discard block
 block discarded – undo
1284 1284
      * @param  array $request Default request arguments
1285 1285
      * @return array          Modified request arguments
1286 1286
      */
1287
-    public function restrict_media_library( $request = array() ) {
1287
+    public function restrict_media_library($request = array()) {
1288 1288
 
1289
-        if( ! is_admin() ) {
1289
+        if ( ! is_admin()) {
1290 1290
             return $request;
1291 1291
         }
1292 1292
 
1293
-        if( ! $this->is_admin_teacher() ) {
1293
+        if ( ! $this->is_admin_teacher()) {
1294 1294
             return $request;
1295 1295
         }
1296 1296
 
1297 1297
         $screen = get_current_screen();
1298 1298
 
1299
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
-            $teacher = intval( get_current_user_id() );
1299
+        if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) {
1300
+            $teacher = intval(get_current_user_id());
1301 1301
 
1302
-            if( $teacher ) {
1303
-                $request['author__in'] = array( $teacher );
1302
+            if ($teacher) {
1303
+                $request['author__in'] = array($teacher);
1304 1304
             }
1305 1305
         }
1306 1306
 
@@ -1312,20 +1312,20 @@  discard block
 block discarded – undo
1312 1312
      * @param  array $query Default query arguments
1313 1313
      * @return array        Modified query arguments
1314 1314
      */
1315
-    public function restrict_media_library_modal( $query = array() ) {
1315
+    public function restrict_media_library_modal($query = array()) {
1316 1316
 
1317
-        if( ! is_admin() ) {
1317
+        if ( ! is_admin()) {
1318 1318
             return $query;
1319 1319
         }
1320 1320
 
1321
-        if( ! $this->is_admin_teacher() ) {
1321
+        if ( ! $this->is_admin_teacher()) {
1322 1322
             return $query;
1323 1323
         }
1324 1324
 
1325
-        $teacher = intval( get_current_user_id() );
1325
+        $teacher = intval(get_current_user_id());
1326 1326
 
1327
-        if( $teacher ) {
1328
-            $query['author__in'] = array( $teacher );
1327
+        if ($teacher) {
1328
+            $query['author__in'] = array($teacher);
1329 1329
         }
1330 1330
 
1331 1331
         return $query;
@@ -1338,28 +1338,28 @@  discard block
 block discarded – undo
1338 1338
      *
1339 1339
      * @param int $lesson_id
1340 1340
      */
1341
-    public function update_lesson_teacher( $lesson_id ){
1341
+    public function update_lesson_teacher($lesson_id) {
1342 1342
 
1343
-        if( 'lesson'!= get_post_type() ){
1343
+        if ('lesson' != get_post_type()) {
1344 1344
             return;
1345 1345
         }
1346 1346
 
1347 1347
         // this should only run once per request cycle
1348
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1348
+        remove_action('save_post', array($this, 'update_lesson_teacher'));
1349 1349
 
1350
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1350
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
1351 1351
 
1352
-        if(  empty( $course_id ) || ! $course_id ){
1352
+        if (empty($course_id) || ! $course_id) {
1353 1353
             return;
1354 1354
         }
1355 1355
 
1356
-        $course = get_post( $course_id );
1356
+        $course = get_post($course_id);
1357 1357
 
1358
-        $lesson_update_args= array(
1359
-            'ID' => $lesson_id ,
1358
+        $lesson_update_args = array(
1359
+            'ID' => $lesson_id,
1360 1360
             'post_author' => $course->post_author
1361 1361
         );
1362
-        wp_update_post( $lesson_update_args );
1362
+        wp_update_post($lesson_update_args);
1363 1363
 
1364 1364
     } // end update_lesson_teacher
1365 1365
 
@@ -1373,21 +1373,21 @@  discard block
 block discarded – undo
1373 1373
      * @parameters array $wp_query
1374 1374
      * @return WP_Query $wp_query
1375 1375
      */
1376
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1376
+    public function limit_teacher_edit_screen_post_types($wp_query) {
1377 1377
         global $current_user;
1378 1378
 
1379 1379
         //exit early
1380
-        if( ! $this->is_admin_teacher() ){
1380
+        if ( ! $this->is_admin_teacher()) {
1381 1381
             return $wp_query;
1382 1382
         }
1383 1383
 
1384
-        if ( ! function_exists( 'get_current_screen' ) ) {
1384
+        if ( ! function_exists('get_current_screen')) {
1385 1385
             return $wp_query;
1386 1386
         }
1387 1387
 
1388 1388
         $screen = get_current_screen();
1389 1389
 
1390
-        if( empty( $screen ) ){
1390
+        if (empty($screen)) {
1391 1391
             return $wp_query;
1392 1392
         }
1393 1393
 
@@ -1400,10 +1400,10 @@  discard block
 block discarded – undo
1400 1400
             'lesson_page_lesson-order',
1401 1401
         );
1402 1402
 
1403
-        if(  in_array($screen->id  , $limit_screens ) ) {
1403
+        if (in_array($screen->id, $limit_screens)) {
1404 1404
 
1405 1405
             // set the query author to the current user to only show those those posts
1406
-            $wp_query->set( 'author', $current_user->ID );
1406
+            $wp_query->set('author', $current_user->ID);
1407 1407
         }
1408 1408
 
1409 1409
         return $wp_query;
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
      * @return void
1424 1424
      */
1425 1425
 
1426
-    public function teacher_login_redirect( $user_login, $user  ) {
1426
+    public function teacher_login_redirect($user_login, $user) {
1427 1427
 
1428 1428
         if (user_can($user, 'edit_courses')) {
1429 1429
 
@@ -1473,9 +1473,9 @@  discard block
 block discarded – undo
1473 1473
          * @param bool $restrict default true
1474 1474
          */
1475 1475
 
1476
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1476
+        $restrict = apply_filters('sensei_restrict_posts_menu_page', true);
1477 1477
 
1478
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1478
+        if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) {
1479 1479
 
1480 1480
             remove_menu_page('edit.php');
1481 1481
 
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
 
1510 1510
         global $pagenow;
1511 1511
 
1512
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1512
+        if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") {
1513 1513
 
1514 1514
             $clauses->query_vars['post_author'] = get_current_user_id();
1515 1515
 
@@ -1526,15 +1526,15 @@  discard block
 block discarded – undo
1526 1526
      *
1527 1527
      * @return bool
1528 1528
      */
1529
-    public static function is_a_teacher( $user_id ){
1529
+    public static function is_a_teacher($user_id) {
1530 1530
 
1531 1531
         $user = get_user_by('id', $user_id);
1532 1532
 
1533
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1533
+        if (isset($user->roles) && in_array('teacher', $user->roles)) {
1534 1534
 
1535 1535
             return true;
1536 1536
 
1537
-        }else{
1537
+        } else {
1538 1538
 
1539 1539
             return false;
1540 1540
 
@@ -1547,14 +1547,14 @@  discard block
 block discarded – undo
1547 1547
      *
1548 1548
      * @since 1.9.0
1549 1549
      */
1550
-    public static function archive_title(){
1550
+    public static function archive_title() {
1551 1551
 
1552
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1552
+        $author = get_user_by('id', get_query_var('author'));
1553 1553
         $author_name = $author->display_name;
1554 1554
         ?>
1555 1555
             <h2 class="teacher-archive-title">
1556 1556
 
1557
-                <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
1557
+                <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?>
1558 1558
 
1559 1559
             </h2>
1560 1560
         <?php
@@ -1566,9 +1566,9 @@  discard block
 block discarded – undo
1566 1566
      *
1567 1567
      * @since 1.9.0
1568 1568
      */
1569
-    public static function remove_course_meta_on_teacher_archive(){
1569
+    public static function remove_course_meta_on_teacher_archive() {
1570 1570
 
1571
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1571
+        remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta'));
1572 1572
 
1573 1573
     }
1574 1574
 
Please login to merge, or discard this patch.
includes/class-sensei-updates.php 4 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 	 *
456 456
 	 * @since  1.1.0
457 457
 	 * @access public
458
-	 * @return void
458
+	 * @return boolean
459 459
 	 */
460 460
 	public function assign_role_caps() {
461 461
 		foreach ( $this->parent->post_types->role_caps as $role_cap_set  ) {
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 *
481 481
 	 * @since 1.3.0
482 482
 	 * @access public
483
-	 * @return void
483
+	 * @return boolean
484 484
 	 */
485 485
 	public function set_default_quiz_grade_type() {
486 486
 		$args = array(	'post_type' 		=> 'quiz',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 	 *
503 503
 	 * @since 1.3.0
504 504
 	 * @access public
505
-	 * @return void
505
+	 * @return boolean
506 506
 	 */
507 507
 	public function set_default_question_type() {
508 508
 		$args = array(	'post_type' 		=> 'question',
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 	 *
533 533
 	 * @since 1.3.0
534 534
 	 * @access public
535
-	 * @return void
535
+	 * @return boolean
536 536
 	 */
537 537
 	public function update_question_answer_data( $n = 50, $offset = 0 ) {
538 538
 
@@ -1429,8 +1429,8 @@  discard block
 block discarded – undo
1429 1429
 	 *
1430 1430
 	 * @global type $woothemes_sensei
1431 1431
 	 * @global type $wpdb
1432
-	 * @param type $n
1433
-	 * @param type $offset
1432
+	 * @param integer $n
1433
+	 * @param integer $offset
1434 1434
 	 * @return boolean
1435 1435
 	 */
1436 1436
 	function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) {
@@ -1674,8 +1674,8 @@  discard block
 block discarded – undo
1674 1674
 	 * Update the comment counts for all Courses and Lessons now that sensei comments will no longer be counted.
1675 1675
 	 *
1676 1676
 	 * @global type $wpdb
1677
-	 * @param type $n
1678
-	 * @param type $offset
1677
+	 * @param integer $n
1678
+	 * @param integer $offset
1679 1679
 	 * @return boolean
1680 1680
 	 */
1681 1681
 	public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) {
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 								'1.7.2' => array( 	'auto' 		=> array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ),
71 71
 													/*'manual' 		=> array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/
72 72
 												),
73
-                                '1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
74
-                            						'manual' 	=> array()
75
-                    							),
73
+								'1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
74
+													'manual' 	=> array()
75
+												),
76 76
 							);
77 77
 
78 78
 		$this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates );
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 				} // End For Loop
330 330
 			} // End For Loop
331 331
 
332
-            $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
332
+			$this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
333 333
 			update_option( $this->token . '-upgrades', $this->updates_run );
334 334
 			return true;
335 335
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 */
447 447
 	private function set_update_run( $update ) {
448 448
 		array_push( $this->updates_run, $update );
449
-        $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
449
+		$this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
450 450
 		update_option( $this->token . '-upgrades', $this->updates_run );
451 451
 	}
452 452
 
@@ -918,11 +918,11 @@  discard block
 block discarded – undo
918 918
 				update_post_meta( $lesson->ID, '_order_' . $course_id, 0 );
919 919
 			}
920 920
 
921
-            $module = Sensei()->modules->get_lesson_module( $lesson->ID );
921
+			$module = Sensei()->modules->get_lesson_module( $lesson->ID );
922 922
 
923
-            if( $module ) {
924
-                update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
925
-            }
923
+			if( $module ) {
924
+				update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
925
+			}
926 926
 
927 927
 		}
928 928
 
@@ -1732,22 +1732,22 @@  discard block
 block discarded – undo
1732 1732
 
1733 1733
 	}
1734 1734
 
1735
-     /**
1736
-     * WooThemes_Sensei_Updates::enhance_teacher_role
1737
-     *
1738
-     * This runs the update to create the teacher role
1739
-     * @access public
1740
-     * @since 1.8.0
1741
-     * @return bool;
1742
-     */
1743
-    public  function enhance_teacher_role ( ) {
1744
-
1745
-        require_once('class-sensei-teacher.php');
1746
-        $teacher = new Sensei_Teacher();
1747
-        $teacher->create_role();
1748
-        return true;
1749
-
1750
-    }// end enhance_teacher_role
1735
+	 /**
1736
+	  * WooThemes_Sensei_Updates::enhance_teacher_role
1737
+	  *
1738
+	  * This runs the update to create the teacher role
1739
+	  * @access public
1740
+	  * @since 1.8.0
1741
+	  * @return bool;
1742
+	  */
1743
+	public  function enhance_teacher_role ( ) {
1744
+
1745
+		require_once('class-sensei-teacher.php');
1746
+		$teacher = new Sensei_Teacher();
1747
+		$teacher->create_role();
1748
+		return true;
1749
+
1750
+	}// end enhance_teacher_role
1751 1751
 
1752 1752
 } // End Class
1753 1753
 
Please login to merge, or discard this patch.
Braces   +44 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Updates Class
@@ -769,9 +772,15 @@  discard block
 block discarded – undo
769 772
 		$all_activity = get_comments( array( 'status' => 'approve' ) );
770 773
 		$activity_count = array();
771 774
 		foreach( $all_activity as $activity ) {
772
-			if( '' == $activity->comment_type ) continue;
773
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
774
-			if( 0 == $activity->user_id ) continue;
775
+			if( '' == $activity->comment_type ) {
776
+				continue;
777
+			}
778
+			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) {
779
+				continue;
780
+			}
781
+			if( 0 == $activity->user_id ) {
782
+				continue;
783
+			}
775 784
 			$activity_count[] = $activity->comment_ID;
776 785
 		}
777 786
 
@@ -784,9 +793,15 @@  discard block
 block discarded – undo
784 793
 		$activities = get_comments( $args );
785 794
 
786 795
 		foreach( $activities as $activity ) {
787
-			if( '' == $activity->comment_type ) continue;
788
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
789
-			if( 0 == $activity->user_id ) continue;
796
+			if( '' == $activity->comment_type ) {
797
+				continue;
798
+			}
799
+			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) {
800
+				continue;
801
+			}
802
+			if( 0 == $activity->user_id ) {
803
+				continue;
804
+			}
790 805
 
791 806
 			$user_exists = get_userdata( $activity->user_id );
792 807
 
@@ -845,7 +860,9 @@  discard block
 block discarded – undo
845 860
 
846 861
 		foreach( $questions as $question ) {
847 862
 
848
-			if( ! isset( $question->ID ) ) continue;
863
+			if( ! isset( $question->ID ) ) {
864
+				continue;
865
+			}
849 866
 
850 867
 			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
851 868
 
@@ -882,7 +899,9 @@  discard block
 block discarded – undo
882 899
 
883 900
 		foreach( $quizzes as $quiz ) {
884 901
 
885
-			if( ! isset( $quiz->ID ) ) continue;
902
+			if( ! isset( $quiz->ID ) ) {
903
+				continue;
904
+			}
886 905
 
887 906
 			if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) {
888 907
 				update_post_meta( $quiz->ID, '_pass_required', 'on' );
@@ -910,7 +929,9 @@  discard block
 block discarded – undo
910 929
 
911 930
 		foreach( $lessons as $lesson ) {
912 931
 
913
-			if( ! isset( $lesson->ID ) ) continue;
932
+			if( ! isset( $lesson->ID ) ) {
933
+				continue;
934
+			}
914 935
 
915 936
 			$course_id = get_post_meta( $lesson->ID, '_lesson_course', true);
916 937
 
@@ -984,11 +1005,15 @@  discard block
 block discarded – undo
984 1005
 
985 1006
 		foreach( $quizzes as $quiz ) {
986 1007
 
987
-			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue;
1008
+			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) {
1009
+				continue;
1010
+			}
988 1011
 
989 1012
 			$lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true );
990 1013
 
991
-			if( empty( $lesson_id ) ) continue;
1014
+			if( empty( $lesson_id ) ) {
1015
+				continue;
1016
+			}
992 1017
 
993 1018
 			$data = array(
994 1019
 				'ID' => $quiz->ID,
@@ -1071,8 +1096,7 @@  discard block
 block discarded – undo
1071 1096
 				delete_post_meta( $quiz_id, '_quiz_passmark' );
1072 1097
 				delete_post_meta( $lesson_id, '_quiz_has_questions' );
1073 1098
 				$d_count++;
1074
-			}
1075
-			else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1099
+			} else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1076 1100
 
1077 1101
 				// Quiz has no questions, drop the corresponding data
1078 1102
 				update_post_meta( $lesson_id, '_quiz_has_questions', true );
@@ -1222,20 +1246,16 @@  discard block
 block discarded – undo
1222 1246
 							// Check if the user has to get the passmark and has or not
1223 1247
 							if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) {
1224 1248
 								$status = 'passed';
1225
-							}
1226
-							elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1249
+							} elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1227 1250
 								$status = 'failed';
1228
-							}
1229
-							else {
1251
+							} else {
1230 1252
 								$status = 'graded';
1231 1253
 							}
1232
-						}
1233
-						else {
1254
+						} else {
1234 1255
 							// If the lesson has a quiz, but the user doesn't have a grade, it's not yet been graded
1235 1256
 							$status = 'ungraded';
1236 1257
 						}
1237
-					}
1238
-					else {
1258
+					} else {
1239 1259
 						// Lesson has no quiz, so it can only ever be this status
1240 1260
 						$status = 'complete';
1241 1261
 					}
@@ -1374,8 +1394,7 @@  discard block
 block discarded – undo
1374 1394
 					}
1375 1395
 					$meta_data['complete'] = $lessons_completed;
1376 1396
 					$meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1377
-				}
1378
-				else {
1397
+				} else {
1379 1398
 					// Course has no lessons, therefore cannot be 'complete'
1380 1399
 					$status = 'in-progress';
1381 1400
 				}
@@ -1506,8 +1525,7 @@  discard block
 block discarded – undo
1506 1525
 									$lessons_completed++;
1507 1526
 									break;
1508 1527
 							}
1509
-						}
1510
-						else {
1528
+						} else {
1511 1529
 							switch ( $lesson_status ) {
1512 1530
 								case 'complete': // Lesson has no quiz/questions
1513 1531
 								case 'graded': // Lesson has quiz, but it's not important what the grade was
Please login to merge, or discard this patch.
Spacing   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Updates Class
@@ -27,59 +27,59 @@  discard block
 block discarded – undo
27 27
 	 * @param   string $parent The main Sensei object by Ref.
28 28
 	 * @return  void
29 29
 	 */
30
-	public function __construct ( $parent ) {
30
+	public function __construct($parent) {
31 31
 
32 32
 		// Setup object data
33 33
 		$this->parent = $parent;
34
-		$this->updates_run = get_option( 'woothemes-sensei-upgrades', array() );
34
+		$this->updates_run = get_option('woothemes-sensei-upgrades', array());
35 35
 
36 36
 		// The list of upgrades to run
37
-		$this->updates = array( '1.1.0' => array( 	'auto' 		=> array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ),
37
+		$this->updates = array('1.1.0' => array('auto' 		=> array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')),
38 38
 													'manual' 	=> array()
39 39
 												),
40
-								'1.3.0' => array( 	'auto' 		=> array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ),
41
-																		  'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) )
40
+								'1.3.0' => array('auto' 		=> array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')),
41
+																		  'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei'))
42 42
 													),
43
-													'manual' 	=> array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) )
43
+													'manual' 	=> array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei')))
44 44
 												),
45
-								'1.4.0' => array( 	'auto' 		=> array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ),
45
+								'1.4.0' => array('auto' 		=> array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))),
46 46
 													'manual' 	=> array()
47 47
 												),
48
-								'1.5.0' => array( 	'auto' 		=> array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ),
49
-													'manual' 	=> array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ),
50
-																		  'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ),
51
-																		  'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) )
48
+								'1.5.0' => array('auto' 		=> array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))),
49
+													'manual' 	=> array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')),
50
+																		  'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')),
51
+																		  'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei')))
52 52
 												),
53
-								'1.6.0' => array( 	'auto' 		=> array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ),
54
-																		  'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ),
55
-																		  'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ),
56
-																		  'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ),
57
-																		  'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ),
53
+								'1.6.0' => array('auto' 		=> array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')),
54
+																		  'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')),
55
+																		  'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')),
56
+																		  'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')),
57
+																		  'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),),
58 58
 													'manual' 	=> array()
59 59
 												),
60
-								'1.7.0' => array( 	'auto' 		=> array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ),
61
-													'forced' 	=> array(  'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ),
62
-																		  'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ),
63
-																		  'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ),
64
-																		  'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ),
65
-																		  'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ),
66
-																		  'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ),
67
-																		  'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ),
68
-																		  'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ),
60
+								'1.7.0' => array('auto' 		=> array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),),
61
+													'forced' 	=> array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')),
62
+																		  'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')),
63
+																		  'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')),
64
+																		  'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')),
65
+																		  'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')),
66
+																		  'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')),
67
+																		  'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')),
68
+																		  'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),),
69 69
 												),
70
-								'1.7.2' => array( 	'auto' 		=> array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ),
70
+								'1.7.2' => array('auto' 		=> array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),),
71 71
 													/*'manual' 		=> array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/
72 72
 												),
73
-                                '1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
73
+                                '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),),
74 74
                             						'manual' 	=> array()
75 75
                     							),
76 76
 							);
77 77
 
78
-		$this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates );
79
-		$this->version = get_option( 'woothemes-sensei-version' );
78
+		$this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates);
79
+		$this->version = get_option('woothemes-sensei-version');
80 80
 
81 81
 		// Manual Update Screen
82
-		add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 );
82
+		add_action('admin_menu', array($this, 'add_update_admin_screen'), 50);
83 83
 
84 84
 	} // End __construct()
85 85
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 * @return void
92 92
 	 */
93 93
 	public function add_update_admin_screen() {
94
-		if ( current_user_can( 'manage_options' ) ) {
95
-			add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) );
94
+		if (current_user_can('manage_options')) {
95
+			add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page'));
96 96
 		}
97 97
 	} // End add_update_admin_screen()
98 98
 
@@ -106,80 +106,80 @@  discard block
 block discarded – undo
106 106
 	public function sensei_updates_page() {
107 107
 
108 108
 		// Only allow admins to load this page and run the update functions
109
-		if( current_user_can( 'manage_options' ) ) {
109
+		if (current_user_can('manage_options')) {
110 110
 			?>
111 111
 			<div class="wrap">
112 112
 
113 113
 				<div id="icon-woothemes-sensei" class="icon32"><br></div>
114
-				<h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2>
114
+				<h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2>
115 115
 
116 116
 				<?php
117
-				if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) {
117
+				if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) {
118 118
 
119 119
 					// Setup the data variables
120
-					$n = intval( $_GET['n'] );
120
+					$n = intval($_GET['n']);
121 121
 					$functions_list = '';
122 122
 					$done_processing = false;
123 123
 
124 124
 					// Check for updates to run
125
-					if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) {
125
+					if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) {
126 126
 
127
-						foreach ( $_POST['checked'] as $key => $value ) {
127
+						foreach ($_POST['checked'] as $key => $value) {
128 128
 
129 129
 							// Dynamic function call
130
-							if ( method_exists( $this, $value) ) {
131
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
130
+							if (method_exists($this, $value)) {
131
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
132 132
 							} else {
133
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
133
+								$done_processing = call_user_func_array($value, array(50, $n));
134 134
 							} // End If Statement
135 135
 
136 136
 							// Add to functions list get args
137
-							if ( '' == $functions_list ) {
137
+							if ('' == $functions_list) {
138 138
 								$functions_list .= $value;
139 139
 							} else {
140
-								$functions_list .= '+' . $value;
140
+								$functions_list .= '+'.$value;
141 141
 							} // End If Statement
142 142
 
143 143
 							// Mark update has having been run
144
-							$this->set_update_run( $value );
144
+							$this->set_update_run($value);
145 145
 
146 146
 						} // End For Loop
147 147
 
148 148
 					} // End If Statement
149 149
 
150 150
 					// Check for updates to run
151
-					if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) {
151
+					if (isset($_GET['functions']) && '' != $_GET['functions']) {
152 152
 
153 153
 						// Existing functions from GET variables instead of POST
154 154
 						$functions_array = $_GET['functions'];
155 155
 
156
-						foreach ( $functions_array as $key => $value ) {
156
+						foreach ($functions_array as $key => $value) {
157 157
 
158 158
 							// Dynamic function call
159
-							if ( method_exists( $this, $value) ) {
160
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
159
+							if (method_exists($this, $value)) {
160
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
161 161
 							} else {
162
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
162
+								$done_processing = call_user_func_array($value, array(50, $n));
163 163
 							} // End If Statement
164 164
 
165 165
 							// Add to functions list get args
166
-							if ( '' == $functions_list ) {
166
+							if ('' == $functions_list) {
167 167
 								$functions_list .= $value;
168 168
 							} else {
169
-								$functions_list .= '+' . $value;
169
+								$functions_list .= '+'.$value;
170 170
 							} // End If Statement
171 171
 
172
-							$this->set_update_run( $value );
172
+							$this->set_update_run($value);
173 173
 
174 174
 						} // End For Loop
175 175
 
176 176
 					} // End If Statement
177 177
 
178
-					if ( ! $done_processing ) { ?>
178
+					if ( ! $done_processing) { ?>
179 179
 
180
-						<h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3>
180
+						<h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3>
181 181
 
182
-						<p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p>
182
+						<p><?php _e('If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p>
183 183
 						<script type='text/javascript'>
184 184
 						<!--
185 185
 						function sensei_nextpage() {
@@ -191,48 +191,48 @@  discard block
 block discarded – undo
191 191
 
192 192
 					} else { ?>
193 193
 
194
-						<p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p>
195
-						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p>
194
+						<p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p>
195
+						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p>
196 196
 
197 197
 					<?php } // End If Statement
198 198
 
199 199
 				} else { ?>
200 200
 
201
-					<h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3>
202
-					<p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p>
201
+					<h3><?php _e('Updates', 'woothemes-sensei'); ?></h3>
202
+					<p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p>
203 203
 
204
-					<div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div>
204
+					<div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div>
205 205
 
206 206
 					<table class="widefat" cellspacing="0" id="update-plugins-table">
207 207
 
208 208
 						<thead>
209 209
 							<tr>
210
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
211
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
212
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
210
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
211
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
212
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
213 213
 							</tr>
214 214
 						</thead>
215 215
 
216 216
 						<tfoot>
217 217
 							<tr>
218
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
219
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
220
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
218
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
219
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
220
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
221 221
 							</tr>
222 222
 						</tfoot>
223 223
 
224 224
 						<tbody class="updates">
225 225
 							<?php
226 226
 							// Sort updates with the latest at the top
227
-							uksort( $this->updates, array( $this, 'sort_updates' ) );
228
-							$this->updates = array_reverse( $this->updates, true );
227
+							uksort($this->updates, array($this, 'sort_updates'));
228
+							$this->updates = array_reverse($this->updates, true);
229 229
 							$class = 'alternate';
230
-							foreach( $this->updates as $version => $version_updates ) {
231
-								foreach( $version_updates as $type => $updates ) {
232
-									foreach( $updates as $update => $data ) {
233
-										$update_run = $this->has_update_run( $update );
230
+							foreach ($this->updates as $version => $version_updates) {
231
+								foreach ($version_updates as $type => $updates) {
232
+									foreach ($updates as $update => $data) {
233
+										$update_run = $this->has_update_run($update);
234 234
 										$product = 'Sensei';
235
-										if ( isset( $data['product'] ) && '' != $data['product'] ) {
235
+										if (isset($data['product']) && '' != $data['product']) {
236 236
 											$product = $data['product'];
237 237
 										} // End If Statement
238 238
 										?>
@@ -242,21 +242,21 @@  discard block
 block discarded – undo
242 242
 													<p>
243 243
 														<input type="hidden" name="checked[]" value="<?php echo $update; ?>">
244 244
 														<strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br>
245
-														<em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em>
245
+														<em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em>
246 246
 													</p>
247 247
 												</td>
248 248
 												<?php
249
-												$type_label = __( 'Auto', 'woothemes-sensei' );
250
-												if( $type != 'auto' ) {
251
-													$type_label = __( 'Manual', 'woothemes-sensei' );
249
+												$type_label = __('Auto', 'woothemes-sensei');
250
+												if ($type != 'auto') {
251
+													$type_label = __('Manual', 'woothemes-sensei');
252 252
 												}
253 253
 												?>
254 254
 												<td><p><?php echo $type_label; ?></p></td>
255
-												<td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td>
255
+												<td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td>
256 256
 											</tr>
257 257
 										</form>
258 258
 										<?php
259
-										if( 'alternate' == $class ) {
259
+										if ('alternate' == $class) {
260 260
 											$class = '';
261 261
 										} else {
262 262
 											$class = 'alternate';
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 	 * @param  string $b Second key
284 284
 	 * @return integer
285 285
 	 */
286
-	private function sort_updates( $a, $b ) {
287
-		return strcmp( $a, $b );
286
+	private function sort_updates($a, $b) {
287
+		return strcmp($a, $b);
288 288
 	}
289 289
 
290 290
 	/**
@@ -295,32 +295,32 @@  discard block
 block discarded – undo
295 295
 	 * @access public
296 296
 	 * @return boolean
297 297
 	 */
298
-	public function update ( $type = 'auto' ) {
298
+	public function update($type = 'auto') {
299 299
 
300 300
 		// Only allow admins to run update functions
301
-		if( current_user_can( 'manage_options' ) ) {
301
+		if (current_user_can('manage_options')) {
302 302
 
303 303
 			$this->force_updates();
304 304
 
305 305
 			// Run through all functions
306
-			foreach ( $this->updates as $version => $value ) {
307
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
308
-					if ( $upgrade_type == $type ) {
306
+			foreach ($this->updates as $version => $value) {
307
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
308
+					if ($upgrade_type == $type) {
309 309
 						$updated = false;
310 310
 						// Run the update function
311
-						foreach ( $function_to_run as $function_name => $update_data ) {
312
-							if ( isset( $function_name ) && '' != $function_name ) {
313
-								if ( ! in_array( $function_name, $this->updates_run ) ) {
311
+						foreach ($function_to_run as $function_name => $update_data) {
312
+							if (isset($function_name) && '' != $function_name) {
313
+								if ( ! in_array($function_name, $this->updates_run)) {
314 314
 									$updated = false;
315
-									if ( method_exists( $this, $function_name ) ) {
316
-										$updated = call_user_func( array( $this, $function_name ) );
317
-									} elseif( function_exists( $function_name ) ) {
318
-										$updated = call_user_func( $function_name );
315
+									if (method_exists($this, $function_name)) {
316
+										$updated = call_user_func(array($this, $function_name));
317
+									} elseif (function_exists($function_name)) {
318
+										$updated = call_user_func($function_name);
319 319
 									} else {
320 320
 										// Nothing to see here...
321 321
 									} // End If Statement
322
-									if ( $updated ) {
323
-										array_push( $this->updates_run, $function_name );
322
+									if ($updated) {
323
+										array_push($this->updates_run, $function_name);
324 324
 									} // End If Statement
325 325
 								}
326 326
 							} // End If Statement
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 				} // End For Loop
330 330
 			} // End For Loop
331 331
 
332
-            $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
333
-			update_option( Sensei()->token . '-upgrades', $this->updates_run );
332
+            $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
333
+			update_option(Sensei()->token.'-upgrades', $this->updates_run);
334 334
 			return true;
335 335
 
336 336
 		}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 
340 340
 	private function force_updates() {
341 341
 
342
-		if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) {
342
+		if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) {
343 343
 
344 344
 			// $skip_forced_updates = false;
345 345
 			// if( ! get_option( 'woothemes-sensei-force-updates', false ) ) {
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 
349 349
 			// Force critical updates if only if lessons already exist
350 350
 			$skip_forced_updates = false;
351
-			$lesson_posts = wp_count_posts( 'lesson' );
352
-			if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) {
351
+			$lesson_posts = wp_count_posts('lesson');
352
+			if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) {
353 353
 				$skip_forced_updates = true;
354 354
 			}
355 355
 
@@ -357,69 +357,69 @@  discard block
 block discarded – undo
357 357
 
358 358
 			$updates_to_run = array();
359 359
 
360
-			foreach ( $this->updates as $version => $value ) {
361
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
362
-					if ( $upgrade_type == 'forced' ) {
363
-						foreach ( $function_to_run as $function_name => $update_data ) {
360
+			foreach ($this->updates as $version => $value) {
361
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
362
+					if ($upgrade_type == 'forced') {
363
+						foreach ($function_to_run as $function_name => $update_data) {
364 364
 
365
-							if( $skip_forced_updates ) {
366
-								$this->set_update_run( $function_name );
365
+							if ($skip_forced_updates) {
366
+								$this->set_update_run($function_name);
367 367
 								continue;
368 368
 							}
369 369
 
370
-							$update_run = $this->has_update_run( $function_name );
370
+							$update_run = $this->has_update_run($function_name);
371 371
 
372
-							if( ! $update_run ) {
372
+							if ( ! $update_run) {
373 373
 								$use_the_force = true;
374
-								$updates_to_run[ $function_name ] = $update_data;
374
+								$updates_to_run[$function_name] = $update_data;
375 375
 							}
376 376
 						}
377 377
 					}
378 378
 				}
379 379
 			}
380 380
 
381
-			if( $skip_forced_updates ) {
381
+			if ($skip_forced_updates) {
382 382
 				return;
383 383
 			}
384 384
 
385
-			if( $use_the_force && 0 < count( $updates_to_run ) ) {
385
+			if ($use_the_force && 0 < count($updates_to_run)) {
386 386
 
387
-				$update_title = __( 'Important Sensei updates required', 'woothemes-sensei' );
387
+				$update_title = __('Important Sensei updates required', 'woothemes-sensei');
388 388
 
389
-				$update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n";
389
+				$update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n";
390 390
 
391 391
 				// $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n";
392 392
 
393
-				$update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n";
393
+				$update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n";
394 394
 
395
-				$update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n";
395
+				$update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n";
396 396
 
397
-				$update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n";
397
+				$update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n";
398 398
 
399
-				$update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n";
399
+				$update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n";
400 400
 
401
-				$update_message .= '<ol>' . "\n";
401
+				$update_message .= '<ol>'."\n";
402 402
 
403
-					foreach( $updates_to_run as $function => $data ) {
403
+					foreach ($updates_to_run as $function => $data) {
404 404
 
405
-						if( ! isset( $data['title'] ) ) {
405
+						if ( ! isset($data['title'])) {
406 406
 							break;
407 407
 						}
408 408
 
409
-						$update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>';
409
+						$update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>';
410 410
 					}
411 411
 
412
-				$update_message .= '</ol>' . "\n";
412
+				$update_message .= '</ol>'."\n";
413 413
 
414
-				switch( $version ) {
414
+				switch ($version) {
415 415
 
416 416
 					case '1.7.0':
417
-						$update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n";
417
+						$update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n";
418 418
 					break;
419 419
 
420 420
 				}
421 421
 
422
-				wp_die( $update_message, $update_title );
422
+				wp_die($update_message, $update_title);
423 423
 			}
424 424
 		}
425 425
 	}
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @since  1.4.0
432 432
 	 * @return boolean
433 433
 	 */
434
-	private function has_update_run( $update ) {
435
-		if ( in_array( $update, $this->updates_run ) ) {
434
+	private function has_update_run($update) {
435
+		if (in_array($update, $this->updates_run)) {
436 436
 			return true;
437 437
 		}
438 438
 		return false;
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
 	 * @param string $update Update to process
445 445
 	 * @since  1.4.0
446 446
 	 */
447
-	private function set_update_run( $update ) {
448
-		array_push( $this->updates_run, $update );
449
-        $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
450
-		update_option( Sensei()->token . '-upgrades', $this->updates_run );
447
+	private function set_update_run($update) {
448
+		array_push($this->updates_run, $update);
449
+        $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
450
+		update_option(Sensei()->token.'-upgrades', $this->updates_run);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
 	 * @return void
459 459
 	 */
460 460
 	public function assign_role_caps() {
461
-		foreach ( $this->parent->post_types->role_caps as $role_cap_set  ) {
462
-			foreach ( $role_cap_set as $role_key => $capabilities_array ) {
461
+		foreach ($this->parent->post_types->role_caps as $role_cap_set) {
462
+			foreach ($role_cap_set as $role_key => $capabilities_array) {
463 463
 				/* Get the role. */
464
-				$role = get_role( $role_key );
465
-				foreach ( $capabilities_array as $cap_name  ) {
464
+				$role = get_role($role_key);
465
+				foreach ($capabilities_array as $cap_name) {
466 466
 					/* If the role exists, add required capabilities for the plugin. */
467
-					if ( !empty( $role ) ) {
468
-						if ( !$role->has_cap( $cap_name ) ) {
469
-							$role->add_cap( $cap_name );
467
+					if ( ! empty($role)) {
468
+						if ( ! $role->has_cap($cap_name)) {
469
+							$role->add_cap($cap_name);
470 470
 						} // End If Statement
471 471
 					} // End If Statement
472 472
 				} // End For Loop
@@ -483,16 +483,16 @@  discard block
 block discarded – undo
483 483
 	 * @return void
484 484
 	 */
485 485
 	public function set_default_quiz_grade_type() {
486
-		$args = array(	'post_type' 		=> 'quiz',
486
+		$args = array('post_type' 		=> 'quiz',
487 487
 						'posts_per_page' 		=> -1,
488 488
 						'post_status'		=> 'publish',
489 489
 						'suppress_filters' 	=> 0
490 490
 						);
491
-		$quizzes = get_posts( $args );
491
+		$quizzes = get_posts($args);
492 492
 
493
-		foreach( $quizzes as $quiz ) {
494
-			update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' );
495
-			update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' );
493
+		foreach ($quizzes as $quiz) {
494
+			update_post_meta($quiz->ID, '_quiz_grade_type', 'auto');
495
+			update_post_meta($quiz->ID, '_quiz_grade_type_disabled', '');
496 496
 		}
497 497
 		return true;
498 498
 	} // End set_default_quiz_grade_type
@@ -505,23 +505,23 @@  discard block
 block discarded – undo
505 505
 	 * @return void
506 506
 	 */
507 507
 	public function set_default_question_type() {
508
-		$args = array(	'post_type' 		=> 'question',
508
+		$args = array('post_type' 		=> 'question',
509 509
 						'posts_per_page' 		=> -1,
510 510
 						'post_status'		=> 'publish',
511 511
 						'suppress_filters' 	=> 0
512 512
 						);
513
-		$questions = get_posts( $args );
513
+		$questions = get_posts($args);
514 514
 
515 515
 		$already_run = true;
516
-		foreach( $questions as $question ) {
517
-			if( $already_run ) {
518
-				$terms = wp_get_post_terms( $question->ID, 'question-type' );
519
-				if( is_array( $terms ) && count( $terms ) > 0 ) {
516
+		foreach ($questions as $question) {
517
+			if ($already_run) {
518
+				$terms = wp_get_post_terms($question->ID, 'question-type');
519
+				if (is_array($terms) && count($terms) > 0) {
520 520
 					break;
521 521
 				}
522 522
 			}
523 523
 			$already_run = false;
524
-			wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' );
524
+			wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type');
525 525
 		}
526 526
 
527 527
 		return true;
@@ -534,90 +534,90 @@  discard block
 block discarded – undo
534 534
 	 * @access public
535 535
 	 * @return void
536 536
 	 */
537
-	public function update_question_answer_data( $n = 50, $offset = 0 ) {
537
+	public function update_question_answer_data($n = 50, $offset = 0) {
538 538
 
539 539
 		// Get Total Number of Updates to run
540
-		$quiz_count_object = wp_count_posts( 'quiz' );
540
+		$quiz_count_object = wp_count_posts('quiz');
541 541
 		$quiz_count_published = $quiz_count_object->publish;
542 542
 
543 543
 		// Calculate if this is the last page
544
-		if ( 0 == $offset ) {
544
+		if (0 == $offset) {
545 545
 			$current_page = 1;
546 546
 		} else {
547
-			$current_page = intval( $offset / $n );
547
+			$current_page = intval($offset / $n);
548 548
 		} // End If Statement
549
-		$total_pages = intval( $quiz_count_published / $n );
549
+		$total_pages = intval($quiz_count_published / $n);
550 550
 
551 551
 
552
-		$args = array(	'post_type' 		=> 'quiz',
552
+		$args = array('post_type' 		=> 'quiz',
553 553
 						'posts_per_page' 		=> $n,
554 554
 						'offset'			=> $offset,
555 555
 						'post_status'		=> 'publish',
556 556
 						'suppress_filters' 	=> 0
557 557
 						);
558
-		$quizzes = get_posts( $args );
558
+		$quizzes = get_posts($args);
559 559
 
560 560
 		$old_answers = array();
561 561
 		$right_answers = array();
562 562
 		$old_user_answers = array();
563 563
 
564
-		if( is_array( $quizzes ) ) {
565
-			foreach( $quizzes as $quiz ) {
564
+		if (is_array($quizzes)) {
565
+			foreach ($quizzes as $quiz) {
566 566
 				$quiz_id = $quiz->ID;
567 567
 
568 568
 				// Get current user answers
569
-				$comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true  );
569
+				$comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true);
570 570
 				// Need to always return an array, even with only 1 item
571
-				if ( !is_array($comments) ) {
572
-					$comments = array( $comments );
571
+				if ( ! is_array($comments)) {
572
+					$comments = array($comments);
573 573
 				}
574
-				foreach ( $comments as $comment ) {
574
+				foreach ($comments as $comment) {
575 575
 					$user_id = $comment->user_id;
576
-					$content = maybe_unserialize( base64_decode( $comment->comment_content ) );
577
-					$old_user_answers[ $quiz_id ][ $user_id ] = $content;
576
+					$content = maybe_unserialize(base64_decode($comment->comment_content));
577
+					$old_user_answers[$quiz_id][$user_id] = $content;
578 578
 				}
579 579
 
580 580
 				// Get correct answers
581
-				$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
582
-				if( is_array( $questions ) ) {
583
-					foreach( $questions as $question ) {
584
-						$right_answer = get_post_meta( $question->ID, '_question_right_answer', true );
585
-						$right_answers[ $quiz_id ][ $question->ID ] = $right_answer;
581
+				$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
582
+				if (is_array($questions)) {
583
+					foreach ($questions as $question) {
584
+						$right_answer = get_post_meta($question->ID, '_question_right_answer', true);
585
+						$right_answers[$quiz_id][$question->ID] = $right_answer;
586 586
 					}
587 587
 				}
588 588
 			}
589 589
 		}
590 590
 
591
-		if( is_array( $right_answers ) ) {
592
-			foreach( $right_answers as $quiz_id => $question ) {
591
+		if (is_array($right_answers)) {
592
+			foreach ($right_answers as $quiz_id => $question) {
593 593
 				$count = 0;
594
-				if( is_array( $question ) ) {
595
-					foreach( $question as $question_id => $answer ) {
594
+				if (is_array($question)) {
595
+					foreach ($question as $question_id => $answer) {
596 596
 						++$count;
597
-						if( isset( $old_user_answers[ $quiz_id ] ) ) {
598
-							$answers_linkup[ $quiz_id ][ $count ] = $question_id;
597
+						if (isset($old_user_answers[$quiz_id])) {
598
+							$answers_linkup[$quiz_id][$count] = $question_id;
599 599
 						}
600 600
 					}
601 601
 				}
602 602
 			}
603 603
 		}
604 604
 
605
-		if( is_array( $old_user_answers ) ) {
606
-			foreach( $old_user_answers as $quiz_id => $user_answers ) {
607
-				foreach( $user_answers as $user_id => $answers ) {
608
-					foreach( $answers as $answer_id => $user_answer ) {
609
-						$question_id = $answers_linkup[ $quiz_id ][ $answer_id ];
610
-						$new_user_answers[ $question_id ] = $user_answer;
611
-						Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id );
605
+		if (is_array($old_user_answers)) {
606
+			foreach ($old_user_answers as $quiz_id => $user_answers) {
607
+				foreach ($user_answers as $user_id => $answers) {
608
+					foreach ($answers as $answer_id => $user_answer) {
609
+						$question_id = $answers_linkup[$quiz_id][$answer_id];
610
+						$new_user_answers[$question_id] = $user_answer;
611
+						Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id);
612 612
 					}
613
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
614
-					Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
615
-					Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id );
613
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
614
+					Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
615
+					Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id);
616 616
 				}
617 617
 			}
618 618
 		}
619 619
 
620
-		if ( $current_page == $total_pages ) {
620
+		if ($current_page == $total_pages) {
621 621
 			return true;
622 622
 		} else {
623 623
 			return false;
@@ -632,15 +632,15 @@  discard block
 block discarded – undo
632 632
 	 * @return boolean
633 633
 	 */
634 634
 	public function update_question_grade_points() {
635
-		$args = array(	'post_type' 		=> 'question',
635
+		$args = array('post_type' 		=> 'question',
636 636
 						'posts_per_page' 		=> -1,
637 637
 						'post_status'		=> 'publish',
638 638
 						'suppress_filters' 	=> 0
639 639
 						);
640
-		$questions = get_posts( $args );
640
+		$questions = get_posts($args);
641 641
 
642
-		foreach( $questions as $question ) {
643
-			update_post_meta( $question->ID, '_question_grade', '1' );
642
+		foreach ($questions as $question) {
643
+			update_post_meta($question->ID, '_question_grade', '1');
644 644
 		}
645 645
 		return true;
646 646
 	} // End update_question_grade_points
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * @return boolean
653 653
 	 */
654 654
 	public function convert_essay_paste_questions() {
655
-		$args = array(	'post_type' 		=> 'question',
655
+		$args = array('post_type' 		=> 'question',
656 656
 						'posts_per_page' 		=> -1,
657 657
 						'post_status'		=> 'publish',
658 658
 						'tax_query'			=> array(
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 						),
665 665
 						'suppress_filters' 	=> 0
666 666
 						);
667
-		$questions = get_posts( $args );
667
+		$questions = get_posts($args);
668 668
 
669
-		foreach( $questions as $question ) {
670
-			wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false );
669
+		foreach ($questions as $question) {
670
+			wp_set_object_terms($question->ID, 'multi-line', 'question-type', false);
671 671
 
672
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
673
-			if( 0 < intval( $quiz_id ) ) {
674
-				add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true );
672
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
673
+			if (0 < intval($quiz_id)) {
674
+				add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true);
675 675
 			}
676 676
 		}
677 677
 		return true;
@@ -683,33 +683,33 @@  discard block
 block discarded – undo
683 683
 	 * @since  1.5.0
684 684
 	 * @return boolean
685 685
 	 */
686
-	public function set_random_question_order( $n = 50, $offset = 0 ) {
686
+	public function set_random_question_order($n = 50, $offset = 0) {
687 687
 
688 688
 		// Get Total Number of Updates to run
689
-		$quiz_count_object = wp_count_posts( 'quiz' );
689
+		$quiz_count_object = wp_count_posts('quiz');
690 690
 		$quiz_count_published = $quiz_count_object->publish;
691 691
 
692 692
 		// Calculate if this is the last page
693
-		if ( 0 == $offset ) {
693
+		if (0 == $offset) {
694 694
 			$current_page = 1;
695 695
 		} else {
696
-			$current_page = intval( $offset / $n );
696
+			$current_page = intval($offset / $n);
697 697
 		} // End If Statement
698
-		$total_pages = intval( $quiz_count_published / $n );
698
+		$total_pages = intval($quiz_count_published / $n);
699 699
 
700
-		$args = array(	'post_type' 		=> 'quiz',
700
+		$args = array('post_type' 		=> 'quiz',
701 701
 						'post_status'		=> 'any',
702 702
 						'posts_per_page' 		=> $n,
703 703
 						'offset'			=> $offset,
704 704
 						'suppress_filters' 	=> 0
705 705
 						);
706
-		$quizzes = get_posts( $args );
706
+		$quizzes = get_posts($args);
707 707
 
708
-		foreach( $quizzes as $quiz ) {
709
-			update_post_meta( $quiz->ID, '_random_question_order', 'yes' );
708
+		foreach ($quizzes as $quiz) {
709
+			update_post_meta($quiz->ID, '_random_question_order', 'yes');
710 710
 		}
711 711
 
712
-		if ( $current_page == $total_pages ) {
712
+		if ($current_page == $total_pages) {
713 713
 			return true;
714 714
 		} else {
715 715
 			return false;
@@ -723,37 +723,37 @@  discard block
 block discarded – undo
723 723
 	 * @since  1.5.0
724 724
 	 * @return boolean
725 725
 	 */
726
-	public function set_default_show_question_count( $n = 50, $offset = 0 ) {
726
+	public function set_default_show_question_count($n = 50, $offset = 0) {
727 727
 
728
-		$args = array(	'post_type' 		=> 'quiz',
728
+		$args = array('post_type' 		=> 'quiz',
729 729
 						'post_status'		=> 'any',
730 730
 						'posts_per_page' 		=> $n,
731 731
 						'offset'			=> $offset,
732 732
 						'meta_key'			=> '_show_questions',
733 733
 						'suppress_filters' 	=> 0
734 734
 						);
735
-		$quizzes = get_posts( $args );
735
+		$quizzes = get_posts($args);
736 736
 
737
-		$total_quizzes = count( $quizzes );
737
+		$total_quizzes = count($quizzes);
738 738
 
739
-		if( 0 == intval( $total_quizzes ) ) {
739
+		if (0 == intval($total_quizzes)) {
740 740
 			return true;
741 741
 		}
742 742
 
743
-		foreach( $quizzes as $quiz ) {
744
-			delete_post_meta( $quiz->ID, '_show_questions' );
743
+		foreach ($quizzes as $quiz) {
744
+			delete_post_meta($quiz->ID, '_show_questions');
745 745
 		}
746 746
 
747
-		$total_pages = intval( $total_quizzes / $n );
747
+		$total_pages = intval($total_quizzes / $n);
748 748
 
749 749
 		// Calculate if this is the last page
750
-		if ( 0 == $offset ) {
750
+		if (0 == $offset) {
751 751
 			$current_page = 1;
752 752
 		} else {
753
-			$current_page = intval( $offset / $n );
753
+			$current_page = intval($offset / $n);
754 754
 		} // End If Statement
755 755
 
756
-		if ( $current_page == $total_pages ) {
756
+		if ($current_page == $total_pages) {
757 757
 			return true;
758 758
 		} else {
759 759
 			return false;
@@ -761,17 +761,17 @@  discard block
 block discarded – undo
761 761
 
762 762
 	}
763 763
 
764
-	public function remove_deleted_user_activity( $n = 50, $offset = 0 ) {
764
+	public function remove_deleted_user_activity($n = 50, $offset = 0) {
765 765
 
766 766
 
767 767
 //		remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
768 768
 
769
-		$all_activity = get_comments( array( 'status' => 'approve' ) );
769
+		$all_activity = get_comments(array('status' => 'approve'));
770 770
 		$activity_count = array();
771
-		foreach( $all_activity as $activity ) {
772
-			if( '' == $activity->comment_type ) continue;
773
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
774
-			if( 0 == $activity->user_id ) continue;
771
+		foreach ($all_activity as $activity) {
772
+			if ('' == $activity->comment_type) continue;
773
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
774
+			if (0 == $activity->user_id) continue;
775 775
 			$activity_count[] = $activity->comment_ID;
776 776
 		}
777 777
 
@@ -781,35 +781,35 @@  discard block
 block discarded – undo
781 781
 			'status' => 'approve'
782 782
 		);
783 783
 
784
-		$activities = get_comments( $args );
784
+		$activities = get_comments($args);
785 785
 
786
-		foreach( $activities as $activity ) {
787
-			if( '' == $activity->comment_type ) continue;
788
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
789
-			if( 0 == $activity->user_id ) continue;
786
+		foreach ($activities as $activity) {
787
+			if ('' == $activity->comment_type) continue;
788
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
789
+			if (0 == $activity->user_id) continue;
790 790
 
791
-			$user_exists = get_userdata( $activity->user_id );
791
+			$user_exists = get_userdata($activity->user_id);
792 792
 
793
-			if( ! $user_exists ) {
794
-				wp_delete_comment( intval( $activity->comment_ID ), true );
793
+			if ( ! $user_exists) {
794
+				wp_delete_comment(intval($activity->comment_ID), true);
795 795
 				wp_cache_flush();
796 796
 			}
797 797
 		}
798 798
 
799
-		$total_activities = count( $activity_count );
799
+		$total_activities = count($activity_count);
800 800
 
801
-		$total_pages = intval( $total_activities / $n );
801
+		$total_pages = intval($total_activities / $n);
802 802
 
803 803
 		// Calculate if this is the last page
804
-		if ( 0 == $offset ) {
804
+		if (0 == $offset) {
805 805
 			$current_page = 1;
806 806
 		} else {
807
-			$current_page = intval( $offset / $n );
807
+			$current_page = intval($offset / $n);
808 808
 		} // End If Statement
809 809
 
810 810
 //		add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
811 811
 
812
-		if ( $current_page >= $total_pages ) {
812
+		if ($current_page >= $total_pages) {
813 813
 			return true;
814 814
 		} else {
815 815
 			return false;
@@ -818,16 +818,16 @@  discard block
 block discarded – undo
818 818
 	}
819 819
 
820 820
 	public function add_teacher_role() {
821
-		add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) );
821
+		add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true));
822 822
 		return true;
823 823
 	}
824 824
 
825 825
 	public function add_sensei_caps() {
826
-		$role = get_role( 'administrator' );
826
+		$role = get_role('administrator');
827 827
 
828
-		if( ! is_null( $role ) ) {
829
-			$role->add_cap( 'manage_sensei' );
830
-			$role->add_cap( 'manage_sensei_grades' );
828
+		if ( ! is_null($role)) {
829
+			$role->add_cap('manage_sensei');
830
+			$role->add_cap('manage_sensei_grades');
831 831
 		}
832 832
 
833 833
 		return true;
@@ -841,16 +841,16 @@  discard block
 block discarded – undo
841 841
 			'suppress_filters' 	=> 0
842 842
 		);
843 843
 
844
-		$questions = get_posts( $args );
844
+		$questions = get_posts($args);
845 845
 
846
-		foreach( $questions as $question ) {
846
+		foreach ($questions as $question) {
847 847
 
848
-			if( ! isset( $question->ID ) ) continue;
848
+			if ( ! isset($question->ID)) continue;
849 849
 
850
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
850
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
851 851
 
852
-			$question_order = get_post_meta( $question->ID, '_quiz_question_order', true );
853
-			update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order );
852
+			$question_order = get_post_meta($question->ID, '_quiz_question_order', true);
853
+			update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order);
854 854
 
855 855
 		}
856 856
 
@@ -859,15 +859,15 @@  discard block
 block discarded – undo
859 859
 
860 860
 	public function update_quiz_settings() {
861 861
 
862
-		$settings = get_option( 'woothemes-sensei-settings', array() );
862
+		$settings = get_option('woothemes-sensei-settings', array());
863 863
 
864 864
 		$lesson_completion = false;
865
-		if( isset( $settings['lesson_completion'] ) ) {
865
+		if (isset($settings['lesson_completion'])) {
866 866
 			$lesson_completion = $settings['lesson_completion'];
867 867
 		}
868 868
 
869 869
 		$reset_quiz_allowed = false;
870
-		if( isset( $settings['quiz_reset_allowed'] ) ) {
870
+		if (isset($settings['quiz_reset_allowed'])) {
871 871
 			$reset_quiz_allowed = $settings['quiz_reset_allowed'];
872 872
 		}
873 873
 
@@ -878,20 +878,20 @@  discard block
 block discarded – undo
878 878
 			'suppress_filters' 	=> 0
879 879
 		);
880 880
 
881
-		$quizzes = get_posts( $args );
881
+		$quizzes = get_posts($args);
882 882
 
883
-		foreach( $quizzes as $quiz ) {
883
+		foreach ($quizzes as $quiz) {
884 884
 
885
-			if( ! isset( $quiz->ID ) ) continue;
885
+			if ( ! isset($quiz->ID)) continue;
886 886
 
887
-			if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) {
888
-				update_post_meta( $quiz->ID, '_pass_required', 'on' );
887
+			if (isset($lesson_completion) && 'passed' == $lesson_completion) {
888
+				update_post_meta($quiz->ID, '_pass_required', 'on');
889 889
 			} else {
890
-				update_post_meta( $quiz->ID, '_quiz_passmark', 0 );
890
+				update_post_meta($quiz->ID, '_quiz_passmark', 0);
891 891
 			}
892 892
 
893
-			if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) {
894
-				update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' );
893
+			if (isset($reset_quiz_allowed) && $reset_quiz_allowed) {
894
+				update_post_meta($quiz->ID, '_enable_quiz_reset', 'on');
895 895
 			}
896 896
 		}
897 897
 
@@ -906,22 +906,22 @@  discard block
 block discarded – undo
906 906
 			'suppress_filters' 	=> 0
907 907
 		);
908 908
 
909
-		$lessons = get_posts( $args );
909
+		$lessons = get_posts($args);
910 910
 
911
-		foreach( $lessons as $lesson ) {
911
+		foreach ($lessons as $lesson) {
912 912
 
913
-			if( ! isset( $lesson->ID ) ) continue;
913
+			if ( ! isset($lesson->ID)) continue;
914 914
 
915
-			$course_id = get_post_meta( $lesson->ID, '_lesson_course', true);
915
+			$course_id = get_post_meta($lesson->ID, '_lesson_course', true);
916 916
 
917
-			if( $course_id ) {
918
-				update_post_meta( $lesson->ID, '_order_' . $course_id, 0 );
917
+			if ($course_id) {
918
+				update_post_meta($lesson->ID, '_order_'.$course_id, 0);
919 919
 			}
920 920
 
921
-            $module = Sensei()->modules->get_lesson_module( $lesson->ID );
921
+            $module = Sensei()->modules->get_lesson_module($lesson->ID);
922 922
 
923
-            if( $module ) {
924
-                update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
923
+            if ($module) {
924
+                update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0);
925 925
             }
926 926
 
927 927
 		}
@@ -930,10 +930,10 @@  discard block
 block discarded – undo
930 930
 	}
931 931
 
932 932
 	public function add_editor_caps() {
933
-		$role = get_role( 'editor' );
933
+		$role = get_role('editor');
934 934
 
935
-		if( ! is_null( $role ) ) {
936
-			$role->add_cap( 'manage_sensei_grades' );
935
+		if ( ! is_null($role)) {
936
+			$role->add_cap('manage_sensei_grades');
937 937
 		}
938 938
 
939 939
 		return true;
@@ -952,26 +952,26 @@  discard block
 block discarded – undo
952 952
 					WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%'
953 953
 						AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id
954 954
 						AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'";
955
-		$wpdb->query( $sql );
955
+		$wpdb->query($sql);
956 956
 
957 957
 		return true;
958 958
 	}
959 959
 
960
-	public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) {
961
-		$count_object = wp_count_posts( 'quiz' );
960
+	public function update_quiz_lesson_relationship($n = 50, $offset = 0) {
961
+		$count_object = wp_count_posts('quiz');
962 962
 
963 963
 		$count_published = 0;
964
-		foreach ( $count_object AS $status => $count ) {
964
+		foreach ($count_object AS $status => $count) {
965 965
 			$count_published += $count;
966 966
 		}
967 967
 
968 968
 		// Calculate if this is the last page
969
-		if ( 0 == $offset ) {
969
+		if (0 == $offset) {
970 970
 			$current_page = 1;
971 971
 		} else {
972
-			$current_page = intval( $offset / $n );
972
+			$current_page = intval($offset / $n);
973 973
 		}
974
-		$total_pages = ceil( $count_published / $n );
974
+		$total_pages = ceil($count_published / $n);
975 975
 
976 976
 		$args = array(
977 977
 			'post_type' => 'quiz',
@@ -980,52 +980,52 @@  discard block
 block discarded – undo
980 980
 			'post_status' => 'any'
981 981
 		);
982 982
 
983
-		$quizzes = get_posts( $args );
983
+		$quizzes = get_posts($args);
984 984
 
985
-		foreach( $quizzes as $quiz ) {
985
+		foreach ($quizzes as $quiz) {
986 986
 
987
-			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue;
987
+			if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue;
988 988
 
989
-			$lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true );
989
+			$lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true);
990 990
 
991
-			if( empty( $lesson_id ) ) continue;
991
+			if (empty($lesson_id)) continue;
992 992
 
993 993
 			$data = array(
994 994
 				'ID' => $quiz->ID,
995 995
 				'post_parent' => $lesson_id,
996 996
 			);
997
-			wp_update_post( $data );
997
+			wp_update_post($data);
998 998
 
999
-			update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID );
999
+			update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID);
1000 1000
 		}
1001 1001
 
1002
-		if ( $current_page == $total_pages || 0 == $total_pages ) {
1002
+		if ($current_page == $total_pages || 0 == $total_pages) {
1003 1003
 			return true;
1004 1004
 		} else {
1005 1005
 			return false;
1006 1006
 		}
1007 1007
 	}
1008 1008
 
1009
-	function status_changes_fix_lessons( $n = 50, $offset = 0 ) {
1009
+	function status_changes_fix_lessons($n = 50, $offset = 0) {
1010 1010
 		global $wpdb;
1011 1011
 
1012
-		$count_object = wp_count_posts( 'lesson' );
1012
+		$count_object = wp_count_posts('lesson');
1013 1013
 		$count_published = 0;
1014
-		foreach ( $count_object AS $status => $count ) {
1014
+		foreach ($count_object AS $status => $count) {
1015 1015
 			$count_published += $count;
1016 1016
 		}
1017 1017
 
1018
-		if ( 0 == $count_published ) {
1018
+		if (0 == $count_published) {
1019 1019
 			return true;
1020 1020
 		}
1021 1021
 
1022 1022
 		// Calculate if this is the last page
1023
-		if ( 0 == $offset ) {
1023
+		if (0 == $offset) {
1024 1024
 			$current_page = 1;
1025 1025
 		} else {
1026
-			$current_page = intval( $offset / $n );
1026
+			$current_page = intval($offset / $n);
1027 1027
 		}
1028
-		$total_pages = ceil( $count_published / $n );
1028
+		$total_pages = ceil($count_published / $n);
1029 1029
 
1030 1030
 		// Get all Lessons with (and without) Quizzes...
1031 1031
 		$args = array(
@@ -1035,26 +1035,26 @@  discard block
 block discarded – undo
1035 1035
 			'offset' => $offset,
1036 1036
 			'fields' => 'ids'
1037 1037
 		);
1038
-		$lesson_ids = get_posts( $args );
1038
+		$lesson_ids = get_posts($args);
1039 1039
 
1040 1040
 		// ...get all Quiz IDs for the above Lessons
1041
-		$id_list = join( ',', $lesson_ids );
1042
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1041
+		$id_list = join(',', $lesson_ids);
1042
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1043 1043
 		$lesson_quiz_ids = array();
1044
-		if ( !empty($meta_list) ) {
1045
-			foreach ( $meta_list as $metarow ) {
1044
+		if ( ! empty($meta_list)) {
1045
+			foreach ($meta_list as $metarow) {
1046 1046
 				$lesson_id = $metarow['meta_value'];
1047 1047
 				$quiz_id = $metarow['post_id'];
1048
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1048
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1049 1049
 			}
1050 1050
 		}
1051 1051
 
1052 1052
 		// ...check all Quiz IDs for questions
1053
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1054
-		$meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A );
1053
+		$id_list = join(',', array_values($lesson_quiz_ids));
1054
+		$meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A);
1055 1055
 		$lesson_quiz_ids_with_questions = array();
1056
-		if ( !empty($meta_list) ) {
1057
-			foreach ( $meta_list as $metarow ) {
1056
+		if ( ! empty($meta_list)) {
1057
+			foreach ($meta_list as $metarow) {
1058 1058
 				$quiz_id = $metarow['meta_value'];
1059 1059
 				$lesson_quiz_ids_with_questions[] = $quiz_id;
1060 1060
 			}
@@ -1062,49 +1062,49 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 		// For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons
1064 1064
 		// if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons
1065
-		$d_count = $a_count =0;
1066
-		foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) {
1067
-			if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1065
+		$d_count = $a_count = 0;
1066
+		foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) {
1067
+			if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1068 1068
 
1069 1069
 				// Quiz has no questions, drop the corresponding data
1070
-				delete_post_meta( $quiz_id, '_pass_required' );
1071
-				delete_post_meta( $quiz_id, '_quiz_passmark' );
1072
-				delete_post_meta( $lesson_id, '_quiz_has_questions' );
1070
+				delete_post_meta($quiz_id, '_pass_required');
1071
+				delete_post_meta($quiz_id, '_quiz_passmark');
1072
+				delete_post_meta($lesson_id, '_quiz_has_questions');
1073 1073
 				$d_count++;
1074 1074
 			}
1075
-			else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1075
+			else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1076 1076
 
1077 1077
 				// Quiz has no questions, drop the corresponding data
1078
-				update_post_meta( $lesson_id, '_quiz_has_questions', true );
1078
+				update_post_meta($lesson_id, '_quiz_has_questions', true);
1079 1079
 				$a_count++;
1080 1080
 			}
1081 1081
 		}
1082 1082
 
1083
-		if ( $current_page == $total_pages ) {
1083
+		if ($current_page == $total_pages) {
1084 1084
 			return true;
1085 1085
 		} else {
1086 1086
 			return false;
1087 1087
 		}
1088 1088
 	}
1089 1089
 
1090
-	function status_changes_convert_lessons( $n = 50, $offset = 0 ) {
1090
+	function status_changes_convert_lessons($n = 50, $offset = 0) {
1091 1091
 		global $wpdb;
1092 1092
 
1093
-		wp_defer_comment_counting( true );
1093
+		wp_defer_comment_counting(true);
1094 1094
 
1095
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1095
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1096 1096
 
1097
-		if ( 0 == $user_count_result ) {
1097
+		if (0 == $user_count_result) {
1098 1098
 			return true;
1099 1099
 		}
1100 1100
 
1101
-		if ( 0 == $offset ) {
1101
+		if (0 == $offset) {
1102 1102
 			$current_page = 1;
1103 1103
 		} else {
1104
-			$current_page = intval( $offset / $n );
1104
+			$current_page = intval($offset / $n);
1105 1105
 		}
1106 1106
 
1107
-		$total_pages = ceil( $user_count_result / $n );
1107
+		$total_pages = ceil($user_count_result / $n);
1108 1108
 
1109 1109
 		// Get all Lessons with Quizzes...
1110 1110
 		$args = array(
@@ -1119,34 +1119,34 @@  discard block
 block discarded – undo
1119 1119
 			),
1120 1120
 			'fields' => 'ids'
1121 1121
 		);
1122
-		$lesson_ids_with_quizzes = get_posts( $args );
1122
+		$lesson_ids_with_quizzes = get_posts($args);
1123 1123
 		// ...get all Quiz IDs for the above Lessons
1124
-		$id_list = join( ',', $lesson_ids_with_quizzes );
1125
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1124
+		$id_list = join(',', $lesson_ids_with_quizzes);
1125
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1126 1126
 		$lesson_quiz_ids = array();
1127
-		if ( !empty($meta_list) ) {
1128
-			foreach ( $meta_list as $metarow ) {
1127
+		if ( ! empty($meta_list)) {
1128
+			foreach ($meta_list as $metarow) {
1129 1129
 				$lesson_id = $metarow['meta_value'];
1130 1130
 				$quiz_id = $metarow['post_id'];
1131
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1131
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1132 1132
 			}
1133 1133
 		}
1134 1134
 
1135 1135
 		// ...get all Pass Required & Passmarks for the above Lesson/Quizzes
1136
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1137
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A );
1136
+		$id_list = join(',', array_values($lesson_quiz_ids));
1137
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A);
1138 1138
 		$quizzes_pass_required = $quizzes_passmarks = array();
1139
-		if ( !empty($meta_list) ) {
1140
-			foreach ( $meta_list as $metarow ) {
1141
-				if ( !empty($metarow['meta_value']) ) {
1139
+		if ( ! empty($meta_list)) {
1140
+			foreach ($meta_list as $metarow) {
1141
+				if ( ! empty($metarow['meta_value'])) {
1142 1142
 					$quiz_id = $metarow['post_id'];
1143 1143
 					$key = $metarow['meta_key'];
1144 1144
 					$value = $metarow['meta_value'];
1145
-					if ( '_pass_required' == $key ) {
1146
-						$quizzes_pass_required[ $quiz_id ] = $value;
1145
+					if ('_pass_required' == $key) {
1146
+						$quizzes_pass_required[$quiz_id] = $value;
1147 1147
 					}
1148
-					if ( '_quiz_passmark' == $key ) {
1149
-						$quizzes_passmarks[ $quiz_id ] = $value;
1148
+					if ('_quiz_passmark' == $key) {
1149
+						$quizzes_passmarks[$quiz_id] = $value;
1150 1150
 					}
1151 1151
 				}
1152 1152
 			}
@@ -1160,41 +1160,41 @@  discard block
 block discarded – undo
1160 1160
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' ";
1161 1161
 
1162 1162
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1163
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1163
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1164 1164
 
1165
-		foreach ( $user_ids AS $user_id ) {
1165
+		foreach ($user_ids AS $user_id) {
1166 1166
 
1167 1167
 			$lesson_ends = $lesson_grades = $lesson_answers = array();
1168 1168
 
1169 1169
 			// Pre-process the lesson ends
1170
-			$_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A );
1171
-			foreach ( $_lesson_ends as $lesson_end ) {
1170
+			$_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A);
1171
+			foreach ($_lesson_ends as $lesson_end) {
1172 1172
 				// This will overwrite existing entries with the newer ones
1173
-				$lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date'];
1173
+				$lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date'];
1174 1174
 			}
1175
-			unset( $_lesson_ends );
1175
+			unset($_lesson_ends);
1176 1176
 
1177 1177
 			// Pre-process the lesson grades
1178
-			$_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A );
1179
-			foreach ( $_lesson_grades as $lesson_grade ) {
1178
+			$_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A);
1179
+			foreach ($_lesson_grades as $lesson_grade) {
1180 1180
 				// This will overwrite existing entries with the newer ones (assuming the grade is higher)
1181
-				if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) {
1182
-					$lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content'];
1181
+				if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) {
1182
+					$lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content'];
1183 1183
 				}
1184 1184
 			}
1185
-			unset( $_lesson_grades );
1185
+			unset($_lesson_grades);
1186 1186
 
1187 1187
 			// Pre-process the lesson answers
1188
-			$_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A );
1189
-			foreach ( $_lesson_answers as $lesson_answer ) {
1188
+			$_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A);
1189
+			foreach ($_lesson_answers as $lesson_answer) {
1190 1190
 				// This will overwrite existing entries with the newer ones
1191
-				$lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content'];
1191
+				$lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content'];
1192 1192
 			}
1193
-			unset( $_lesson_answers );
1193
+			unset($_lesson_answers);
1194 1194
 
1195 1195
 			// Grab all the lesson starts for the user
1196
-			$lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1197
-			foreach ( $lesson_starts as $lesson_log ) {
1196
+			$lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1197
+			foreach ($lesson_starts as $lesson_log) {
1198 1198
 
1199 1199
 				$lesson_id = $lesson_log['comment_post_ID'];
1200 1200
 
@@ -1207,23 +1207,23 @@  discard block
 block discarded – undo
1207 1207
 					'start' => $status_date,
1208 1208
 				);
1209 1209
 				// Check if there is a lesson end
1210
-				if ( !empty($lesson_ends[$lesson_id]) ) {
1210
+				if ( ! empty($lesson_ends[$lesson_id])) {
1211 1211
 					$status_date = $lesson_ends[$lesson_id];
1212 1212
 					// Check lesson has quiz
1213
-					if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) {
1213
+					if ( ! empty($lesson_quiz_ids[$lesson_id])) {
1214 1214
 						// Check for the quiz answers
1215
-						if ( !empty($lesson_answers[$quiz_id]) ) {
1215
+						if ( ! empty($lesson_answers[$quiz_id])) {
1216 1216
 							$meta_data['questions_asked'] = $lesson_answers[$quiz_id];
1217 1217
 						}
1218 1218
 						// Check if there is a quiz grade
1219 1219
 						$quiz_id = $lesson_quiz_ids[$lesson_id];
1220
-						if ( !empty($lesson_grades[$quiz_id]) ) {
1220
+						if ( ! empty($lesson_grades[$quiz_id])) {
1221 1221
 							$meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id];
1222 1222
 							// Check if the user has to get the passmark and has or not
1223
-							if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) {
1223
+							if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) {
1224 1224
 								$status = 'passed';
1225 1225
 							}
1226
-							elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1226
+							elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) {
1227 1227
 								$status = 'failed';
1228 1228
 							}
1229 1229
 							else {
@@ -1251,26 +1251,26 @@  discard block
 block discarded – undo
1251 1251
 						'comment_author' => '',
1252 1252
 					);
1253 1253
 				// Check it doesn't already exist
1254
-				$sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id );
1255
-				$comment_ID = $wpdb->get_var( $sql );
1256
-				if ( !$comment_ID ) {
1254
+				$sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id);
1255
+				$comment_ID = $wpdb->get_var($sql);
1256
+				if ( ! $comment_ID) {
1257 1257
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1258 1258
 					$wpdb->insert($wpdb->comments, $data);
1259 1259
 					$comment_ID = (int) $wpdb->insert_id;
1260 1260
 
1261
-					if ( $comment_ID && !empty($meta_data) ) {
1262
-						foreach ( $meta_data as $key => $value ) {
1261
+					if ($comment_ID && ! empty($meta_data)) {
1262
+						foreach ($meta_data as $key => $value) {
1263 1263
 							// Bypassing WP add_comment_meta(() so no actions/filters are run
1264
-							if ( $wpdb->get_var( $wpdb->prepare(
1264
+							if ($wpdb->get_var($wpdb->prepare(
1265 1265
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1266
-									$comment_ID, $key ) ) ) {
1266
+									$comment_ID, $key ))) {
1267 1267
 									continue; // Found the meta data already
1268 1268
 							}
1269
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1269
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1270 1270
 								'comment_id' => $comment_ID,
1271 1271
 								'meta_key' => $key,
1272 1272
 								'meta_value' => $value
1273
-							) );
1273
+							));
1274 1274
 						}
1275 1275
 					}
1276 1276
 				}
@@ -1278,40 +1278,40 @@  discard block
 block discarded – undo
1278 1278
 		}
1279 1279
 		$wpdb->flush();
1280 1280
 
1281
-		if ( $current_page == $total_pages ) {
1281
+		if ($current_page == $total_pages) {
1282 1282
 			return true;
1283 1283
 		} else {
1284 1284
 			return false;
1285 1285
 		}
1286 1286
 	}
1287 1287
 
1288
-	function status_changes_convert_courses( $n = 50, $offset = 0 ) {
1288
+	function status_changes_convert_courses($n = 50, $offset = 0) {
1289 1289
 		global $wpdb;
1290 1290
 
1291
-		wp_defer_comment_counting( true );
1291
+		wp_defer_comment_counting(true);
1292 1292
 
1293
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1293
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1294 1294
 
1295
-		if ( 0 == $user_count_result ) {
1295
+		if (0 == $user_count_result) {
1296 1296
 			return true;
1297 1297
 		}
1298 1298
 
1299
-		if ( 0 == $offset ) {
1299
+		if (0 == $offset) {
1300 1300
 			$current_page = 1;
1301 1301
 		} else {
1302
-			$current_page = intval( $offset / $n );
1302
+			$current_page = intval($offset / $n);
1303 1303
 		}
1304 1304
 
1305
-		$total_pages = ceil( $user_count_result / $n );
1305
+		$total_pages = ceil($user_count_result / $n);
1306 1306
 
1307 1307
 		// Get all Lesson => Course relationships
1308
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A );
1308
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A);
1309 1309
 		$course_lesson_ids = array();
1310
-		if ( !empty($meta_list) ) {
1311
-			foreach ( $meta_list as $metarow ) {
1310
+		if ( ! empty($meta_list)) {
1311
+			foreach ($meta_list as $metarow) {
1312 1312
 				$lesson_id = $metarow['post_id'];
1313 1313
 				$course_id = $metarow['meta_value'];
1314
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1314
+				$course_lesson_ids[$course_id][] = $lesson_id;
1315 1315
 			}
1316 1316
 		}
1317 1317
 
@@ -1321,13 +1321,13 @@  discard block
 block discarded – undo
1321 1321
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' ";
1322 1322
 
1323 1323
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1324
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1324
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1325 1325
 
1326
-		foreach ( $user_ids AS $user_id ) {
1326
+		foreach ($user_ids AS $user_id) {
1327 1327
 
1328 1328
 			// Grab all the course starts for the user
1329
-			$course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1330
-			foreach ( $course_starts as $course_log ) {
1329
+			$course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1330
+			foreach ($course_starts as $course_log) {
1331 1331
 
1332 1332
 				$course_id = $course_log['comment_post_ID'];
1333 1333
 
@@ -1342,23 +1342,23 @@  discard block
 block discarded – undo
1342 1342
 					'percent' => 0,
1343 1343
 				);
1344 1344
 				// Check if the course has lessons
1345
-				if ( !empty( $course_lesson_ids[$course_id] ) ) {
1345
+				if ( ! empty($course_lesson_ids[$course_id])) {
1346 1346
 
1347 1347
 					$lessons_completed = 0;
1348
-					$total_lessons = count( $course_lesson_ids[ $course_id ] );
1348
+					$total_lessons = count($course_lesson_ids[$course_id]);
1349 1349
 
1350 1350
 					// Don't use prepare as we need to provide the id join
1351
-					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) );
1351
+					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id]));
1352 1352
 					// Get all lesson statuses for this Courses' lessons
1353
-					$lesson_statuses = $wpdb->get_results( $sql, ARRAY_A );
1353
+					$lesson_statuses = $wpdb->get_results($sql, ARRAY_A);
1354 1354
 					// Not enough lesson statuses, thus cannot be complete
1355
-					if ( $total_lessons > count($lesson_statuses) ) {
1355
+					if ($total_lessons > count($lesson_statuses)) {
1356 1356
 						$status = 'in-progress';
1357 1357
 					}
1358 1358
 					// Count each lesson to work out the overall percentage
1359
-					foreach ( $lesson_statuses as $lesson_status ) {
1359
+					foreach ($lesson_statuses as $lesson_status) {
1360 1360
 						$status_date = $lesson_status['comment_date'];
1361
-						switch ( $lesson_status['status'] ) {
1361
+						switch ($lesson_status['status']) {
1362 1362
 							case 'complete': // Lesson has no quiz/questions
1363 1363
 							case 'graded': // Lesson has quiz, but it's not important what the grade was
1364 1364
 							case 'passed':
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 						}
1374 1374
 					}
1375 1375
 					$meta_data['complete'] = $lessons_completed;
1376
-					$meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1376
+					$meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1377 1377
 				}
1378 1378
 				else {
1379 1379
 					// Course has no lessons, therefore cannot be 'complete'
@@ -1390,26 +1390,26 @@  discard block
 block discarded – undo
1390 1390
 						'comment_author' => '',
1391 1391
 					);
1392 1392
 				// Check it doesn't already exist
1393
-				$sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id );
1394
-				$comment_ID = $wpdb->get_var( $sql );
1395
-				if ( !$comment_ID ) {
1393
+				$sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id);
1394
+				$comment_ID = $wpdb->get_var($sql);
1395
+				if ( ! $comment_ID) {
1396 1396
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1397 1397
 					$wpdb->insert($wpdb->comments, $data);
1398 1398
 					$comment_ID = (int) $wpdb->insert_id;
1399 1399
 
1400
-					if ( $comment_ID && !empty($meta_data) ) {
1401
-						foreach ( $meta_data as $key => $value ) {
1400
+					if ($comment_ID && ! empty($meta_data)) {
1401
+						foreach ($meta_data as $key => $value) {
1402 1402
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1403
-							if ( $wpdb->get_var( $wpdb->prepare(
1403
+							if ($wpdb->get_var($wpdb->prepare(
1404 1404
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1405
-									$comment_ID, $key ) ) ) {
1405
+									$comment_ID, $key ))) {
1406 1406
 									continue; // Found the meta data already
1407 1407
 							}
1408
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1408
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1409 1409
 								'comment_id' => $comment_ID,
1410 1410
 								'meta_key' => $key,
1411 1411
 								'meta_value' => $value
1412
-							) );
1412
+							));
1413 1413
 						}
1414 1414
 					}
1415 1415
 				}
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 		}
1418 1418
 		$wpdb->flush();
1419 1419
 
1420
-		if ( $current_page == $total_pages ) {
1420
+		if ($current_page == $total_pages) {
1421 1421
 			return true;
1422 1422
 		} else {
1423 1423
 			return false;
@@ -1433,70 +1433,70 @@  discard block
 block discarded – undo
1433 1433
 	 * @param type $offset
1434 1434
 	 * @return boolean
1435 1435
 	 */
1436
-	function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) {
1436
+	function status_changes_repair_course_statuses($n = 50, $offset = 0) {
1437 1437
 		global $wpdb;
1438 1438
 
1439
-		$count_object = wp_count_posts( 'lesson' );
1439
+		$count_object = wp_count_posts('lesson');
1440 1440
 		$count_published = $count_object->publish;
1441 1441
 
1442
-		if ( 0 == $count_published ) {
1442
+		if (0 == $count_published) {
1443 1443
 			return true;
1444 1444
 		}
1445 1445
 
1446 1446
 		// Calculate if this is the last page
1447
-		if ( 0 == $offset ) {
1447
+		if (0 == $offset) {
1448 1448
 			$current_page = 1;
1449 1449
 		} else {
1450
-			$current_page = intval( $offset / $n );
1450
+			$current_page = intval($offset / $n);
1451 1451
 		}
1452
-		$total_pages = ceil( $count_published / $n );
1452
+		$total_pages = ceil($count_published / $n);
1453 1453
 
1454 1454
 		$course_lesson_ids = $lesson_user_statuses = array();
1455 1455
 
1456 1456
 		// Get all Lesson => Course relationships
1457
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A );
1458
-		if ( !empty($meta_list) ) {
1459
-			foreach ( $meta_list as $metarow ) {
1457
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A);
1458
+		if ( ! empty($meta_list)) {
1459
+			foreach ($meta_list as $metarow) {
1460 1460
 				$lesson_id = $metarow['post_id'];
1461 1461
 				$course_id = $metarow['meta_value'];
1462
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1462
+				$course_lesson_ids[$course_id][] = $lesson_id;
1463 1463
 			}
1464 1464
 		}
1465 1465
 
1466 1466
 		// Get all Lesson => Course relationships
1467
-		$status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A );
1468
-		if ( !empty($status_list) ) {
1469
-			foreach ( $status_list as $status ) {
1470
-				$lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved'];
1467
+		$status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A);
1468
+		if ( ! empty($status_list)) {
1469
+			foreach ($status_list as $status) {
1470
+				$lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved'];
1471 1471
 			}
1472 1472
 		}
1473 1473
 
1474
-		$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1474
+		$course_completion = Sensei()->settings->settings['course_completion'];
1475 1475
 
1476 1476
 		$per_page = 40;
1477 1477
 		$comment_id_offset = $count = 0;
1478 1478
 
1479 1479
 		$course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page";
1480 1480
 		// $per_page users at a time
1481
-		while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) {
1481
+		while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) {
1482 1482
 
1483
-			foreach ( $course_statuses AS $course_status ) {
1483
+			foreach ($course_statuses AS $course_status) {
1484 1484
 				$user_id = $course_status->user_id;
1485 1485
 				$course_id = $course_status->comment_post_ID;
1486
-				$total_lessons = count( $course_lesson_ids[ $course_id ] );
1487
-				if ( $total_lessons <= 0 ) {
1486
+				$total_lessons = count($course_lesson_ids[$course_id]);
1487
+				if ($total_lessons <= 0) {
1488 1488
 					$total_lessons = 1; // Fix division of zero error, some courses have no lessons
1489 1489
 				}
1490 1490
 				$lessons_completed = 0;
1491 1491
 				$status = 'in-progress';
1492 1492
 
1493 1493
 				// Some Courses have no lessons... (can they ever be complete?)
1494
-				if ( !empty($course_lesson_ids[ $course_id ]) ) {
1495
-					foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) {
1496
-						$lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ];
1494
+				if ( ! empty($course_lesson_ids[$course_id])) {
1495
+					foreach ($course_lesson_ids[$course_id] AS $lesson_id) {
1496
+						$lesson_status = $lesson_user_statuses[$lesson_id][$user_id];
1497 1497
 						// If lessons are complete without needing quizzes to be passed
1498
-						if ( 'passed' != $course_completion ) {
1499
-							switch ( $lesson_status ) {
1498
+						if ('passed' != $course_completion) {
1499
+							switch ($lesson_status) {
1500 1500
 								// A user cannot 'complete' a course if a lesson...
1501 1501
 								case 'in-progress': // ...is still in progress
1502 1502
 								case 'ungraded': // ...hasn't yet been graded
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 							}
1509 1509
 						}
1510 1510
 						else {
1511
-							switch ( $lesson_status ) {
1511
+							switch ($lesson_status) {
1512 1512
 								case 'complete': // Lesson has no quiz/questions
1513 1513
 								case 'graded': // Lesson has quiz, but it's not important what the grade was
1514 1514
 								case 'passed': // Lesson has quiz and the user passed
@@ -1523,79 +1523,79 @@  discard block
 block discarded – undo
1523 1523
 						}
1524 1524
 					} // Each lesson
1525 1525
 				} // Check for lessons
1526
-				if ( $lessons_completed == $total_lessons ) {
1526
+				if ($lessons_completed == $total_lessons) {
1527 1527
 					$status = 'complete';
1528 1528
 				}
1529 1529
 				// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1530 1530
 				$metadata = array(
1531 1531
 					'complete' => $lessons_completed,
1532
-					'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ),
1532
+					'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)),
1533 1533
 				);
1534
-				Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata );
1534
+				Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata);
1535 1535
 				$count++;
1536 1536
 
1537 1537
 			} // per course status
1538 1538
 			$comment_id_offset = $course_status->comment_ID;
1539 1539
 		} // all course statuses
1540 1540
 
1541
-		if ( $current_page == $total_pages ) {
1541
+		if ($current_page == $total_pages) {
1542 1542
 			return true;
1543 1543
 		} else {
1544 1544
 			return false;
1545 1545
 		}
1546 1546
 	}
1547 1547
 
1548
-	function status_changes_convert_questions( $n = 50, $offset = 0 ) {
1548
+	function status_changes_convert_questions($n = 50, $offset = 0) {
1549 1549
 		global $wpdb;
1550 1550
 
1551
-		wp_defer_comment_counting( true );
1551
+		wp_defer_comment_counting(true);
1552 1552
 
1553
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1553
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1554 1554
 
1555
-		if ( 0 == $user_count_result ) {
1555
+		if (0 == $user_count_result) {
1556 1556
 			return true;
1557 1557
 		}
1558 1558
 
1559 1559
 		// Calculate if this is the last page
1560
-		if ( 0 == $offset ) {
1560
+		if (0 == $offset) {
1561 1561
 			$current_page = 1;
1562 1562
 		} else {
1563
-			$current_page = intval( $offset / $n );
1563
+			$current_page = intval($offset / $n);
1564 1564
 		}
1565 1565
 
1566
-		$total_pages = ceil( $user_count_result / $n );
1566
+		$total_pages = ceil($user_count_result / $n);
1567 1567
 
1568 1568
 		$users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d";
1569 1569
 		$answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID ";
1570 1570
 		$grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID ";
1571 1571
 		$notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID ";
1572 1572
 
1573
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1573
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1574 1574
 
1575
-		foreach ( $user_ids AS $user_id ) {
1575
+		foreach ($user_ids AS $user_id) {
1576 1576
 
1577 1577
 			$answer_grades = $answer_notes = array();
1578 1578
 
1579 1579
 			// Pre-process the answer grades
1580
-			$_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A );
1581
-			foreach ( $_answer_grades as $answer_grade ) {
1580
+			$_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A);
1581
+			foreach ($_answer_grades as $answer_grade) {
1582 1582
 				// This will overwrite existing entries with the newer ones
1583
-				$answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content'];
1583
+				$answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content'];
1584 1584
 			}
1585
-			unset( $_answer_grades );
1585
+			unset($_answer_grades);
1586 1586
 
1587 1587
 			// Pre-process the answer notes
1588
-			$_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A );
1589
-			foreach ( $_answer_notes as $answer_note ) {
1588
+			$_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A);
1589
+			foreach ($_answer_notes as $answer_note) {
1590 1590
 				// This will overwrite existing entries with the newer ones
1591
-				$answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content'];
1591
+				$answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content'];
1592 1592
 			}
1593
-			unset( $_answer_notes );
1593
+			unset($_answer_notes);
1594 1594
 
1595 1595
 			// Grab all the questions for the user
1596 1596
 			$sql = $wpdb->prepare($answers_sql, $user_id);
1597
-			$answers = $wpdb->get_results( $sql, ARRAY_A );
1598
-			foreach ( $answers as $answer ) {
1597
+			$answers = $wpdb->get_results($sql, ARRAY_A);
1598
+			foreach ($answers as $answer) {
1599 1599
 
1600 1600
 				// Excape data
1601 1601
 				$answer = wp_slash($answer);
@@ -1605,12 +1605,12 @@  discard block
 block discarded – undo
1605 1605
 				$meta_data = array();
1606 1606
 
1607 1607
 				// Check if the question has been graded, add as meta
1608
-				if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) {
1609
-					$meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ];
1608
+				if ( ! empty($answer_grades[$answer['comment_post_ID']])) {
1609
+					$meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']];
1610 1610
 				}
1611 1611
 				// Check if there is an answer note, add as meta
1612
-				if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) {
1613
-					$meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ];
1612
+				if ( ! empty($answer_notes[$answer['comment_post_ID']])) {
1613
+					$meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']];
1614 1614
 				}
1615 1615
 
1616 1616
 				// Wipe the unnessary data from the main comment
@@ -1623,21 +1623,21 @@  discard block
 block discarded – undo
1623 1623
 					);
1624 1624
 				$data = array_merge($answer, $data);
1625 1625
 
1626
-				$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
1627
-				if ( $rval ) {
1628
-					if ( !empty($meta_data) ) {
1629
-						foreach ( $meta_data as $key => $value ) {
1626
+				$rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID'));
1627
+				if ($rval) {
1628
+					if ( ! empty($meta_data)) {
1629
+						foreach ($meta_data as $key => $value) {
1630 1630
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1631
-							if ( $wpdb->get_var( $wpdb->prepare(
1631
+							if ($wpdb->get_var($wpdb->prepare(
1632 1632
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1633
-									$comment_ID, $key ) ) ) {
1633
+									$comment_ID, $key ))) {
1634 1634
 									continue; // Found the meta data already
1635 1635
 							}
1636
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1636
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1637 1637
 								'comment_id' => $comment_ID,
1638 1638
 								'meta_key' => $key,
1639 1639
 								'meta_value' => $value
1640
-							) );
1640
+							));
1641 1641
 						}
1642 1642
 					}
1643 1643
 				}
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
 		}
1646 1646
 		$wpdb->flush();
1647 1647
 
1648
-		if ( $current_page == $total_pages ) {
1648
+		if ($current_page == $total_pages) {
1649 1649
 			return true;
1650 1650
 		} else {
1651 1651
 			return false;
@@ -1662,10 +1662,10 @@  discard block
 block discarded – undo
1662 1662
 		global $wpdb;
1663 1663
 
1664 1664
 		// Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts
1665
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " );
1665
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' ");
1666 1666
 
1667 1667
 		// Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required
1668
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " );
1668
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') ");
1669 1669
 
1670 1670
 		return true;
1671 1671
 	}
@@ -1678,50 +1678,50 @@  discard block
 block discarded – undo
1678 1678
 	 * @param type $offset
1679 1679
 	 * @return boolean
1680 1680
 	 */
1681
-	public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) {
1681
+	public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) {
1682 1682
 		global $wpdb;
1683 1683
 
1684
-		$item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " );
1684
+		$item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') ");
1685 1685
 
1686
-		if ( 0 == $item_count_result ) {
1686
+		if (0 == $item_count_result) {
1687 1687
 			return true;
1688 1688
 		}
1689 1689
 
1690 1690
 		// Calculate if this is the last page
1691
-		if ( 0 == $offset ) {
1691
+		if (0 == $offset) {
1692 1692
 			$current_page = 1;
1693 1693
 		} else {
1694
-			$current_page = intval( $offset / $n );
1694
+			$current_page = intval($offset / $n);
1695 1695
 		}
1696 1696
 
1697
-		$total_pages = ceil( $item_count_result / $n );
1697
+		$total_pages = ceil($item_count_result / $n);
1698 1698
 
1699 1699
 		// Recalculate all counts
1700
-		$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) );
1701
-		foreach ( (array) $items as $post ) {
1700
+		$items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset));
1701
+		foreach ((array) $items as $post) {
1702 1702
 			// Code copied from wp_update_comment_count_now()
1703
-			$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) );
1704
-			$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) );
1703
+			$new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID));
1704
+			$wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID));
1705 1705
 
1706
-			clean_post_cache( $post->ID );
1706
+			clean_post_cache($post->ID);
1707 1707
 		}
1708 1708
 
1709
-		if ( $current_page == $total_pages ) {
1709
+		if ($current_page == $total_pages) {
1710 1710
 			return true;
1711 1711
 		} else {
1712 1712
 			return false;
1713 1713
 		}
1714 1714
 	}
1715 1715
 
1716
-	public function remove_legacy_comments () {
1716
+	public function remove_legacy_comments() {
1717 1717
 		global $wpdb;
1718 1718
 
1719
-		$result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) );
1719
+		$result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy'));
1720 1720
 
1721 1721
 		return true;
1722 1722
 	}
1723 1723
 
1724
-	public function index_comment_status_field () {
1724
+	public function index_comment_status_field() {
1725 1725
 		global $wpdb;
1726 1726
 
1727 1727
 		$wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )");
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
      * @since 1.8.0
1741 1741
      * @return bool;
1742 1742
      */
1743
-    public  function enhance_teacher_role ( ) {
1743
+    public  function enhance_teacher_role( ) {
1744 1744
 
1745 1745
         require_once('class-sensei-teacher.php');
1746 1746
         $teacher = new Sensei_Teacher();
Please login to merge, or discard this patch.
includes/sensei-functions.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -178,8 +178,8 @@
 block discarded – undo
178 178
  *
179 179
  * @since 1.9.0
180 180
  *
181
- * @param $hook_tag
182
- * @param $version
181
+ * @param string $hook_tag
182
+ * @param string $version
183 183
  * @param $alternative
184 184
  * @param array $args
185 185
  */
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5 5
 /**
6 6
  * Global Sensei functions
@@ -11,24 +11,24 @@  discard block
 block discarded – undo
11 11
 
12 12
 	$is_sensei = false;
13 13
 
14
-	$post_types = array( 'lesson', 'course', 'quiz', 'question' );
15
-	$taxonomies = array( 'course-category', 'quiz-type', 'question-type', 'lesson-tag' );
14
+	$post_types = array('lesson', 'course', 'quiz', 'question');
15
+	$taxonomies = array('course-category', 'quiz-type', 'question-type', 'lesson-tag');
16 16
 
17
-	if( is_post_type_archive( $post_types ) || is_singular( $post_types ) || is_tax( $taxonomies ) ) {
17
+	if (is_post_type_archive($post_types) || is_singular($post_types) || is_tax($taxonomies)) {
18 18
 		$is_sensei = true;
19 19
 	}
20 20
 
21
-	if( is_object( $post ) && ! is_wp_error( $post ) ) {
21
+	if (is_object($post) && ! is_wp_error($post)) {
22 22
 
23
-		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
24
-		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
23
+		$course_page_id = intval(Sensei()->settings->settings['course_page']);
24
+		$my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
25 25
 
26
-		if( in_array( $post->ID, array( $course_page_id, $my_courses_page_id ) ) ) {
26
+		if (in_array($post->ID, array($course_page_id, $my_courses_page_id))) {
27 27
 			$is_sensei = true;
28 28
 		}
29 29
 	}
30 30
 
31
-	return apply_filters( 'is_sensei', $is_sensei, $post );
31
+	return apply_filters('is_sensei', $is_sensei, $post);
32 32
 }
33 33
 
34 34
 /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function sensei_all_access() {
42 42
 
43
-    $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
43
+    $access = current_user_can('manage_sensei') || current_user_can('manage_sensei_grades');
44 44
 
45 45
     /**
46 46
      * Filter sensei_all_access function result
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
      * @since 1.4.0
51 51
      * @param bool $access
52 52
      */
53
-	return apply_filters( 'sensei_all_access', $access );
53
+	return apply_filters('sensei_all_access', $access);
54 54
 
55 55
 } // End sensei_all_access()
56 56
 
57
-if ( ! function_exists( 'sensei_light_or_dark' ) ) {
57
+if ( ! function_exists('sensei_light_or_dark')) {
58 58
 
59 59
 	/**
60 60
 	 * Detect if we should use a light or dark colour on a background colour
@@ -65,20 +65,20 @@  discard block
 block discarded – undo
65 65
 	 * @param string $light (default: '#FFFFFF')
66 66
 	 * @return string
67 67
 	 */
68
-	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
68
+	function sensei_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
69 69
 
70
-	    $hex = str_replace( '#', '', $color );
70
+	    $hex = str_replace('#', '', $color);
71 71
 
72
-		$c_r = hexdec( substr( $hex, 0, 2 ) );
73
-		$c_g = hexdec( substr( $hex, 2, 2 ) );
74
-		$c_b = hexdec( substr( $hex, 4, 2 ) );
75
-		$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
72
+		$c_r = hexdec(substr($hex, 0, 2));
73
+		$c_g = hexdec(substr($hex, 2, 2));
74
+		$c_b = hexdec(substr($hex, 4, 2));
75
+		$brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
76 76
 
77 77
 		return $brightness > 155 ? $dark : $light;
78 78
 	}
79 79
 }
80 80
 
81
-if ( ! function_exists( 'sensei_rgb_from_hex' ) ) {
81
+if ( ! function_exists('sensei_rgb_from_hex')) {
82 82
 
83 83
 	/**
84 84
 	 * Hex darker/lighter/contrast functions for colours
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 	 * @param mixed $color
88 88
 	 * @return string
89 89
 	 */
90
-	function sensei_rgb_from_hex( $color ) {
91
-		$color = str_replace( '#', '', $color );
90
+	function sensei_rgb_from_hex($color) {
91
+		$color = str_replace('#', '', $color);
92 92
 		// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
93
-		$color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
93
+		$color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
94 94
 
95
-		$rgb['R'] = hexdec( $color{0}.$color{1} );
96
-		$rgb['G'] = hexdec( $color{2}.$color{3} );
97
-		$rgb['B'] = hexdec( $color{4}.$color{5} );
95
+		$rgb['R'] = hexdec($color{0}.$color{1} );
96
+		$rgb['G'] = hexdec($color{2}.$color{3} );
97
+		$rgb['B'] = hexdec($color{4}.$color{5} );
98 98
 		return $rgb;
99 99
 	}
100 100
 }
101 101
 
102
-if ( ! function_exists( 'sensei_hex_darker' ) ) {
102
+if ( ! function_exists('sensei_hex_darker')) {
103 103
 
104 104
 	/**
105 105
 	 * Hex darker/lighter/contrast functions for colours
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $factor (default: 30)
110 110
 	 * @return string
111 111
 	 */
112
-	function sensei_hex_darker( $color, $factor = 30 ) {
113
-		$base = sensei_rgb_from_hex( $color );
112
+	function sensei_hex_darker($color, $factor = 30) {
113
+		$base = sensei_rgb_from_hex($color);
114 114
 		$color = '#';
115 115
 
116 116
 		foreach ($base as $k => $v) :
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	        $new_decimal = $v - $amount;
120 120
 
121 121
 	        $new_hex_component = dechex($new_decimal);
122
-	        if(strlen($new_hex_component) < 2) :
122
+	        if (strlen($new_hex_component) < 2) :
123 123
 	        	$new_hex_component = "0".$new_hex_component;
124 124
 	        endif;
125 125
 	        $color .= $new_hex_component;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	}
130 130
 }
131 131
 
132
-if ( ! function_exists( 'sensei_hex_lighter' ) ) {
132
+if ( ! function_exists('sensei_hex_lighter')) {
133 133
 
134 134
 	/**
135 135
 	 * Hex darker/lighter/contrast functions for colours
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param int $factor (default: 30)
140 140
 	 * @return string
141 141
 	 */
142
-	function sensei_hex_lighter( $color, $factor = 30 ) {
143
-		$base = sensei_rgb_from_hex( $color );
142
+	function sensei_hex_lighter($color, $factor = 30) {
143
+		$base = sensei_rgb_from_hex($color);
144 144
 		$color = '#';
145 145
 
146 146
 	    foreach ($base as $k => $v) :
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	        $new_decimal = $v + $amount;
151 151
 
152 152
 	        $new_hex_component = dechex($new_decimal);
153
-	        if(strlen($new_hex_component) < 2) :
153
+	        if (strlen($new_hex_component) < 2) :
154 154
 	        	$new_hex_component = "0".$new_hex_component;
155 155
 	        endif;
156 156
 	        $color .= $new_hex_component;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
  * @since 1.9.0
167 167
  * @deprecated since 1.9.0 * It is better to call the Sensei_WC::is_woocommerce_active() directly
168 168
  */
169
-if ( ! function_exists( 'is_woocommerce_active' ) ) {
169
+if ( ! function_exists('is_woocommerce_active')) {
170 170
     function is_woocommerce_active() {
171 171
         return Sensei_WC::is_woocommerce_active();
172 172
     }
@@ -183,20 +183,20 @@  discard block
 block discarded – undo
183 183
  * @param $alternative
184 184
  * @param array $args
185 185
  */
186
-function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){
186
+function sensei_do_deprecated_action($hook_tag, $version, $alternative = "", $args = array()) {
187 187
 
188
-    if( has_action( $hook_tag ) ){
188
+    if (has_action($hook_tag)) {
189 189
 
190
-        $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
190
+        $error_message = sprintf(__("SENSEI: The hook '%s', has been deprecated since '%s'.", 'woothemes-sensei'), $hook_tag, $version);
191 191
 
192
-        if( !empty( $alternative ) ){
192
+        if ( ! empty($alternative)) {
193 193
 
194
-            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
194
+            $error_message .= sprintf(__("Please use '%s' instead.", 'woothemes-sensei'), $alternative);
195 195
 
196 196
         }
197 197
 
198
-        trigger_error( $error_message );
199
-        do_action( $hook_tag , $args );
198
+        trigger_error($error_message);
199
+        do_action($hook_tag, $args);
200 200
 
201 201
     }
202 202
 
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
  * @param $post_id
212 212
  * @return bool
213 213
  */
214
-function sensei_is_a_course( $post ){
214
+function sensei_is_a_course($post) {
215 215
 
216
-	return "course" == get_post_type( $post );
216
+	return "course" == get_post_type($post);
217 217
 
218 218
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function sensei_all_access() {
42 42
 
43
-    $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
44
-
45
-    /**
46
-     * Filter sensei_all_access function result
47
-     * which determinse if the current user
48
-     * can access all of Sensei without restrictions
49
-     *
50
-     * @since 1.4.0
51
-     * @param bool $access
52
-     */
43
+	$access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
44
+
45
+	/**
46
+	 * Filter sensei_all_access function result
47
+	 * which determinse if the current user
48
+	 * can access all of Sensei without restrictions
49
+	 *
50
+	 * @since 1.4.0
51
+	 * @param bool $access
52
+	 */
53 53
 	return apply_filters( 'sensei_all_access', $access );
54 54
 
55 55
 } // End sensei_all_access()
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
69 69
 
70
-	    $hex = str_replace( '#', '', $color );
70
+		$hex = str_replace( '#', '', $color );
71 71
 
72 72
 		$c_r = hexdec( substr( $hex, 0, 2 ) );
73 73
 		$c_g = hexdec( substr( $hex, 2, 2 ) );
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
 		$color = '#';
115 115
 
116 116
 		foreach ($base as $k => $v) :
117
-	        $amount = $v / 100;
118
-	        $amount = round($amount * $factor);
119
-	        $new_decimal = $v - $amount;
120
-
121
-	        $new_hex_component = dechex($new_decimal);
122
-	        if(strlen($new_hex_component) < 2) :
123
-	        	$new_hex_component = "0".$new_hex_component;
124
-	        endif;
125
-	        $color .= $new_hex_component;
117
+			$amount = $v / 100;
118
+			$amount = round($amount * $factor);
119
+			$new_decimal = $v - $amount;
120
+
121
+			$new_hex_component = dechex($new_decimal);
122
+			if(strlen($new_hex_component) < 2) :
123
+				$new_hex_component = "0".$new_hex_component;
124
+			endif;
125
+			$color .= $new_hex_component;
126 126
 		endforeach;
127 127
 
128 128
 		return $color;
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
 		$base = sensei_rgb_from_hex( $color );
144 144
 		$color = '#';
145 145
 
146
-	    foreach ($base as $k => $v) :
147
-	        $amount = 255 - $v;
148
-	        $amount = $amount / 100;
149
-	        $amount = round($amount * $factor);
150
-	        $new_decimal = $v + $amount;
151
-
152
-	        $new_hex_component = dechex($new_decimal);
153
-	        if(strlen($new_hex_component) < 2) :
154
-	        	$new_hex_component = "0".$new_hex_component;
155
-	        endif;
156
-	        $color .= $new_hex_component;
146
+		foreach ($base as $k => $v) :
147
+			$amount = 255 - $v;
148
+			$amount = $amount / 100;
149
+			$amount = round($amount * $factor);
150
+			$new_decimal = $v + $amount;
151
+
152
+			$new_hex_component = dechex($new_decimal);
153
+			if(strlen($new_hex_component) < 2) :
154
+				$new_hex_component = "0".$new_hex_component;
155
+			endif;
156
+			$color .= $new_hex_component;
157 157
 	   	endforeach;
158 158
 
159 159
 	   	return $color;
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
  * @deprecated since 1.9.0 use  Sensei_WC::is_woocommerce_active()
168 168
  */
169 169
 if ( ! function_exists( 'is_woocommerce_active' ) ) {
170
-    function is_woocommerce_active() {
171
-        // calling is present instead of is active here
172
-        // as this function can override other is_woocommerce_active
173
-        // function in other woo plugins and Sensei_WC::is_woocommerce_active
174
-        // also check the sensei settings for enable WooCommerce support, which
175
-        // other plugins should not check against.
176
-        return Sensei_WC::is_woocommerce_present();
177
-    }
170
+	function is_woocommerce_active() {
171
+		// calling is present instead of is active here
172
+		// as this function can override other is_woocommerce_active
173
+		// function in other woo plugins and Sensei_WC::is_woocommerce_active
174
+		// also check the sensei settings for enable WooCommerce support, which
175
+		// other plugins should not check against.
176
+		return Sensei_WC::is_woocommerce_present();
177
+	}
178 178
 }
179 179
 
180 180
 /**
@@ -190,20 +190,20 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){
192 192
 
193
-    if( has_action( $hook_tag ) ){
193
+	if( has_action( $hook_tag ) ){
194 194
 
195
-        $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
195
+		$error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
196 196
 
197
-        if( !empty( $alternative ) ){
197
+		if( !empty( $alternative ) ){
198 198
 
199
-            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
199
+			$error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
200 200
 
201
-        }
201
+		}
202 202
 
203
-        trigger_error( $error_message );
204
-        do_action( $hook_tag , $args );
203
+		trigger_error( $error_message );
204
+		do_action( $hook_tag , $args );
205 205
 
206
-    }
206
+	}
207 207
 
208 208
 }// end sensei_do_deprecated_action
209 209
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-legacy-shortcodes.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,8 +103,8 @@
 block discarded – undo
103 103
      *
104 104
      * @since 1.9.0
105 105
      *
106
-     * @param $title
107
-     * @param $shortcode_specific_override
106
+     * @param string $title
107
+     * @param string $shortcode_specific_override
108 108
      * @return string
109 109
      */
110 110
     public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@
 block discarded – undo
166 166
 
167 167
             Sensei_Templates::get_template( 'user/my-courses.php' );
168 168
 
169
-        }else{
169
+        } else{
170 170
 
171 171
             Sensei()->frontend->sensei_login_form();
172 172
 
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -10,323 +10,323 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Sensei_Legacy_Shortcodes {
12 12
 
13
-    /**
14
-     * Add the legacy shortcodes to WordPress
15
-     *
16
-     * @since 1.9.0
17
-     */
18
-    public static function init(){
19
-
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
-
27
-    }
28
-    /**
29
-     * all_courses shortcode output function.
30
-     *
31
-     * The function should only be called indirectly through do_shortcode()
32
-     *
33
-     * @access public
34
-     * @param mixed $atts
35
-     * @param mixed $content (default: null)
36
-     * @return string
37
-     */
38
-    public static function all_courses( $atts, $content = null ) {
39
-
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
-
42
-    } // all_courses()
43
-
44
-    /**
45
-     * paid_courses function.
46
-     *
47
-     * @access public
48
-     * @param mixed $atts
49
-     * @param mixed $content (default: null)
50
-     * @return string
51
-     */
52
-    public static function paid_courses( $atts, $content = null ) {
53
-
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
-
56
-    } // End paid_courses()
57
-
58
-
59
-    /**
60
-     * featured_courses function.
61
-     *
62
-     * @access public
63
-     * @param mixed $atts
64
-     * @param mixed $content (default: null)
65
-     * @return string
66
-     */
67
-    public static function featured_courses( $atts, $content = null ) {
68
-
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
13
+	/**
14
+	 * Add the legacy shortcodes to WordPress
15
+	 *
16
+	 * @since 1.9.0
17
+	 */
18
+	public static function init(){
19
+
20
+		add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
+		add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
+		add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
+		add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
+		add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
+		add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
+
27
+	}
28
+	/**
29
+	 * all_courses shortcode output function.
30
+	 *
31
+	 * The function should only be called indirectly through do_shortcode()
32
+	 *
33
+	 * @access public
34
+	 * @param mixed $atts
35
+	 * @param mixed $content (default: null)
36
+	 * @return string
37
+	 */
38
+	public static function all_courses( $atts, $content = null ) {
39
+
40
+		return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
+
42
+	} // all_courses()
43
+
44
+	/**
45
+	 * paid_courses function.
46
+	 *
47
+	 * @access public
48
+	 * @param mixed $atts
49
+	 * @param mixed $content (default: null)
50
+	 * @return string
51
+	 */
52
+	public static function paid_courses( $atts, $content = null ) {
53
+
54
+		return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
+
56
+	} // End paid_courses()
57
+
58
+
59
+	/**
60
+	 * featured_courses function.
61
+	 *
62
+	 * @access public
63
+	 * @param mixed $atts
64
+	 * @param mixed $content (default: null)
65
+	 * @return string
66
+	 */
67
+	public static function featured_courses( $atts, $content = null ) {
68
+
69
+		return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
70 70
 
71
-    } // End featured_courses()
71
+	} // End featured_courses()
72 72
 
73
-    /**
74
-     * shortcode_free_courses function.
75
-     *
76
-     * @access public
77
-     * @param mixed $atts
78
-     * @param mixed $content (default: null)
79
-     * @return string
80
-     */
81
-    public static function free_courses( $atts, $content = null ) {
73
+	/**
74
+	 * shortcode_free_courses function.
75
+	 *
76
+	 * @access public
77
+	 * @param mixed $atts
78
+	 * @param mixed $content (default: null)
79
+	 * @return string
80
+	 */
81
+	public static function free_courses( $atts, $content = null ) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+		return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
84 84
 
85
-    } // End free_courses()
85
+	} // End free_courses()
86 86
 
87
-    /**
88
-     * shortcode_new_courses function.
89
-     *
90
-     * @access public
91
-     * @param mixed $atts
92
-     * @param mixed $content (default: null)
93
-     * @return string
94
-     */
95
-    public static function new_courses( $atts, $content = null ) {
87
+	/**
88
+	 * shortcode_new_courses function.
89
+	 *
90
+	 * @access public
91
+	 * @param mixed $atts
92
+	 * @param mixed $content (default: null)
93
+	 * @return string
94
+	 */
95
+	public static function new_courses( $atts, $content = null ) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+		return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
98 98
 
99
-    } // End new_courses()
99
+	} // End new_courses()
100 100
 
101
-    /**
102
-     * Generate courses adding a title.
103
-     *
104
-     * @since 1.9.0
105
-     *
106
-     * @param $title
107
-     * @param $shortcode_specific_override
108
-     * @return string
109
-     */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
101
+	/**
102
+	 * Generate courses adding a title.
103
+	 *
104
+	 * @since 1.9.0
105
+	 *
106
+	 * @param $title
107
+	 * @param $shortcode_specific_override
108
+	 * @return string
109
+	 */
110
+	public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
111 111
 
112
-        global  $shortcode_override, $posts_array;
112
+		global  $shortcode_override, $posts_array;
113 113
 
114
-        $shortcode_override = $shortcode_specific_override;
114
+		$shortcode_override = $shortcode_specific_override;
115 115
 
116
-        // do not show this short code if there is a shortcode int he url and
117
-        // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
116
+		// do not show this short code if there is a shortcode int he url and
117
+		// this specific shortcode is not the one requested in the ur.
118
+		$specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
+		if( ! empty( $specific_shortcode_requested) &&
120
+			$specific_shortcode_requested != $shortcode_override ){
121 121
 
122
-            return '';
122
+			return '';
123 123
 
124
-        }
124
+		}
125 125
 
126
-        // loop and get all courses html
127
-        ob_start();
128
-        self::initialise_legacy_course_loop();
129
-        $courses = ob_get_clean();
126
+		// loop and get all courses html
127
+		ob_start();
128
+		self::initialise_legacy_course_loop();
129
+		$courses = ob_get_clean();
130 130
 
131
-        $content = '';
132
-        if( count( $posts_array ) > 0 ){
131
+		$content = '';
132
+		if( count( $posts_array ) > 0 ){
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
-            $before .= '<section id="main-course" class="course-container">';
134
+			$before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
+			$before .= '<section id="main-course" class="course-container">';
136 136
 
137
-            $after = '</section>';
137
+			$after = '</section>';
138 138
 
139
-            //assemble
140
-            $content = $before . $courses . $after;
139
+			//assemble
140
+			$content = $before . $courses . $after;
141 141
 
142
-        }
142
+		}
143 143
 
144
-        return $content;
144
+		return $content;
145 145
 
146
-    }// end generate_shortcode_courses
146
+	}// end generate_shortcode_courses
147 147
 
148 148
 
149
-    /**
150
-     * user_courses function.
151
-     *
152
-     * @access public
153
-     * @param mixed $atts
154
-     * @param mixed $content (default: null)
155
-     * @return string
156
-     */
157
-    public static function user_courses( $atts, $content = null ) {
158
-        global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
149
+	/**
150
+	 * user_courses function.
151
+	 *
152
+	 * @access public
153
+	 * @param mixed $atts
154
+	 * @param mixed $content (default: null)
155
+	 * @return string
156
+	 */
157
+	public static function user_courses( $atts, $content = null ) {
158
+		global $shortcode_override;
159
+		extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
160 160
 
161
-        $shortcode_override = 'usercourses';
161
+		$shortcode_override = 'usercourses';
162 162
 
163
-        ob_start();
163
+		ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+		if( is_user_logged_in() ){
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+			Sensei_Templates::get_template( 'user/my-courses.php' );
168 168
 
169
-        }else{
169
+		}else{
170 170
 
171
-            Sensei()->frontend->sensei_login_form();
171
+			Sensei()->frontend->sensei_login_form();
172 172
 
173
-        }
173
+		}
174 174
 
175
-        $content = ob_get_clean();
176
-        return $content;
175
+		$content = ob_get_clean();
176
+		return $content;
177 177
 
178
-    } // End user_courses()
178
+	} // End user_courses()
179 179
 
180
-    /**
181
-     * This function is simply to honor the legacy
182
-     * loop-course.php for the old shortcodes.
183
-     * @since 1.9.0
184
-     */
185
-    public static function initialise_legacy_course_loop(){
180
+	/**
181
+	 * This function is simply to honor the legacy
182
+	 * loop-course.php for the old shortcodes.
183
+	 * @since 1.9.0
184
+	 */
185
+	public static function initialise_legacy_course_loop(){
186 186
 
187
-        global  $post, $wp_query, $shortcode_override, $course_excludes;
187
+		global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189
-        // Handle Query Type
190
-        $query_type = '';
189
+		// Handle Query Type
190
+		$query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
194
-        } // End If Statement
192
+		if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
+			$query_type = esc_html( $_GET[ 'action' ] );
194
+		} // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
197
-            $query_type = $shortcode_override;
198
-        } // End If Statement
196
+		if ( '' != $shortcode_override ) {
197
+			$query_type = $shortcode_override;
198
+		} // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+		if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
201 201
 
202
-        // Check that query returns results
203
-        // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
202
+		// Check that query returns results
203
+		// Handle Pagination
204
+		$paged = $wp_query->get( 'paged' );
205
+		$paged = empty( $paged ) ? 1 : $paged;
206 206
 
207 207
 
208
-        // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
208
+		// Check for pagination settings
209
+		if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
212 212
 
213
-        } else {
213
+		} else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+			$amount = $wp_query->get( 'posts_per_page' );
216 216
 
217
-        } // End If Statement
217
+		} // End If Statement
218 218
 
219
-        // This is not a paginated page (or it's simply the first page of a paginated page/post)
219
+		// This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221
-        global $posts_array;
222
-        $course_includes   = array();
221
+		global $posts_array;
222
+		$course_includes   = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
226
-        $posts_array = $course_query->get_posts();
224
+		$query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
+		$course_query = new WP_Query( $query_args );
226
+		$posts_array = $course_query->get_posts();
227 227
 
228
-        // output the courses
229
-        if( ! empty( $posts_array ) ) {
228
+		// output the courses
229
+		if( ! empty( $posts_array ) ) {
230 230
 
231
-            //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
231
+			//output all courses for current query
232
+			self::loop_courses( $course_query, $amount );
233 233
 
234
-        }
234
+		}
235 235
 
236
-    }
236
+	}
237 237
 
238
-    /**
239
-     * Loop through courses in the query and output the infomration needed
240
-     *
241
-     * @since 1.9.0
242
-     *
243
-     * @param WP_Query $course_query
244
-     */
245
-    public static function loop_courses( $course_query, $amount ){
238
+	/**
239
+	 * Loop through courses in the query and output the infomration needed
240
+	 *
241
+	 * @since 1.9.0
242
+	 *
243
+	 * @param WP_Query $course_query
244
+	 */
245
+	public static function loop_courses( $course_query, $amount ){
246 246
 
247
-        global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
247
+		global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+		if ( count( $course_query->get_posts() ) > 0 ) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+			do_action( 'sensei_course_archive_header', $shortcode_override );
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+			foreach ( $course_query->get_posts() as $course){
254 254
 
255
-                // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
255
+				// Make sure the other loops dont include the same post twice!
256
+				array_push( $course_excludes, $course->ID );
257 257
 
258
-                // output the course markup
259
-                self::the_course( $course->ID );
258
+				// output the course markup
259
+				self::the_course( $course->ID );
260 260
 
261
-            } // End For Loop
261
+			} // End For Loop
262 262
 
263
-            // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
-            $posts_array       = $posts_array_query->get_posts();
266
-            $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
263
+			// More and Prev links
264
+			$posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
+			$posts_array       = $posts_array_query->get_posts();
266
+			$max_pages = $course_query->found_posts / $amount;
267
+			if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
268 268
 
269
-                switch( $shortcode_override ){
270
-                    case 'paidcourses':
271
-                        $filter = 'paid';
272
-                        break;
273
-                    case 'featuredcourses':
274
-                        $filter = 'featured';
275
-                        break;
276
-                    case 'freecourses':
277
-                        $filter = 'free';
278
-                        break;
279
-                    default:
280
-                        $filter = '';
281
-                        break;
282
-                }
269
+				switch( $shortcode_override ){
270
+					case 'paidcourses':
271
+						$filter = 'paid';
272
+						break;
273
+					case 'featuredcourses':
274
+						$filter = 'featured';
275
+						break;
276
+					case 'freecourses':
277
+						$filter = 'free';
278
+						break;
279
+					default:
280
+						$filter = '';
281
+						break;
282
+				}
283 283
 
284
-                $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
288
-                }
284
+				$quer_args = array();
285
+				$quer_args[ 'paged' ] = '2';
286
+				if( !empty( $filter ) ){
287
+					$quer_args[ 'course_filter' ] = $filter;
288
+				}
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+				$course_pagination_link = get_post_type_archive_link( 'course' );
291
+				$more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
+				$more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
293 293
 
294
-                // next/more
295
-                $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
297
-                $html .= $more_link_text;
298
-                $html .= '<span class="meta-nav"></span></a></div>';
294
+				// next/more
295
+				$html  = '<div class="navigation"><div class="nav-next">';
296
+				$html .= '<a href="' . $more_link_url . '">';
297
+				$html .= $more_link_text;
298
+				$html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+				echo apply_filters( 'course_archive_next_link', $html );
301 301
 
302
-            } // End If Statement
302
+			} // End If Statement
303 303
 
304
-        } // End If Statement
305
-    }
304
+		} // End If Statement
305
+	}
306 306
 
307
-    /**
308
-     * Print a single course markup
309
-     *
310
-     * @param $course_id
311
-     */
312
-    public static function the_course( $course_id ){
307
+	/**
308
+	 * Print a single course markup
309
+	 *
310
+	 * @param $course_id
311
+	 */
312
+	public static function the_course( $course_id ){
313 313
 
314
-        // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
318
-        $author_display_name = $user_info->display_name;
319
-        $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
-        ?>
314
+		// Get meta data
315
+		$course =  get_post( $course_id );
316
+		$user_info = get_userdata( absint( $course->post_author ) );
317
+		$author_link = get_author_posts_url( absint( $course->post_author ) );
318
+		$author_display_name = $user_info->display_name;
319
+		$author_id = $course->post_author;
320
+		$category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
+		?>
324 324
 
325 325
         <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
326 326
             <?php
327
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
329
-            ?>
327
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
328
+			do_action('sensei_course_content_before',$course );
329
+			?>
330 330
             <div class="course-content">
331 331
 
332 332
                 <?php Sensei()->course->course_image($course_id); ?>
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                     </p>
363 363
 
364 364
                     <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
365
+						$preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
366 366
                         <p class="sensei-free-lessons">
367 367
                             <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
@@ -373,15 +373,15 @@  discard block
 block discarded – undo
373 373
 
374 374
             </div>
375 375
             <?php
376
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
377
-            do_action('sensei_course_content_after', $course);
378
-            ?>
376
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
377
+			do_action('sensei_course_content_after', $course);
378
+			?>
379 379
 
380 380
         </article>
381 381
 
382 382
         <?php
383 383
 
384 384
 
385
-    } // end the_course
385
+	} // end the_course
386 386
 
387 387
 }// end class legacy shortcodes
388 388
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
      *
16 16
      * @since 1.9.0
17 17
      */
18
-    public static function init(){
18
+    public static function init() {
19 19
 
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
20
+        add_shortcode('allcourses', array(__CLASS__, 'all_courses'));
21
+        add_shortcode('newcourses', array(__CLASS__, 'new_courses'));
22
+        add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses'));
23
+        add_shortcode('freecourses', array(__CLASS__, 'free_courses'));
24
+        add_shortcode('paidcourses', array(__CLASS__, 'paid_courses'));
25
+        add_shortcode('usercourses', array(__CLASS__, 'user_courses'));
26 26
 
27 27
     }
28 28
     /**
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
      * @param mixed $content (default: null)
36 36
      * @return string
37 37
      */
38
-    public static function all_courses( $atts, $content = null ) {
38
+    public static function all_courses($atts, $content = null) {
39 39
 
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
40
+        return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title
41 41
 
42 42
     } // all_courses()
43 43
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
      * @param mixed $content (default: null)
50 50
      * @return string
51 51
      */
52
-    public static function paid_courses( $atts, $content = null ) {
52
+    public static function paid_courses($atts, $content = null) {
53 53
 
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
54
+        return self::generate_shortcode_courses('Paid Courses', 'paidcourses');
55 55
 
56 56
     } // End paid_courses()
57 57
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
      * @param mixed $content (default: null)
65 65
      * @return string
66 66
      */
67
-    public static function featured_courses( $atts, $content = null ) {
67
+    public static function featured_courses($atts, $content = null) {
68 68
 
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
69
+        return self::generate_shortcode_courses('Featured Courses', 'featuredcourses');
70 70
 
71 71
     } // End featured_courses()
72 72
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
      * @param mixed $content (default: null)
79 79
      * @return string
80 80
      */
81
-    public static function free_courses( $atts, $content = null ) {
81
+    public static function free_courses($atts, $content = null) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+        return self::generate_shortcode_courses('Free Courses', 'freecourses');
84 84
 
85 85
     } // End free_courses()
86 86
 
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
      * @param mixed $content (default: null)
93 93
      * @return string
94 94
      */
95
-    public static function new_courses( $atts, $content = null ) {
95
+    public static function new_courses($atts, $content = null) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+        return self::generate_shortcode_courses('New Courses', 'newcourses');
98 98
 
99 99
     } // End new_courses()
100 100
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param $shortcode_specific_override
108 108
      * @return string
109 109
      */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
110
+    public static function generate_shortcode_courses($title, $shortcode_specific_override) {
111 111
 
112 112
         global  $shortcode_override, $posts_array;
113 113
 
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 
116 116
         // do not show this short code if there is a shortcode int he url and
117 117
         // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
118
+        $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
119
+        if ( ! empty($specific_shortcode_requested) &&
120
+            $specific_shortcode_requested != $shortcode_override) {
121 121
 
122 122
             return '';
123 123
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
         $courses = ob_get_clean();
130 130
 
131 131
         $content = '';
132
-        if( count( $posts_array ) > 0 ){
132
+        if (count($posts_array) > 0) {
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
134
+            $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>';
135 135
             $before .= '<section id="main-course" class="course-container">';
136 136
 
137 137
             $after = '</section>';
138 138
 
139 139
             //assemble
140
-            $content = $before . $courses . $after;
140
+            $content = $before.$courses.$after;
141 141
 
142 142
         }
143 143
 
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
      * @param mixed $content (default: null)
155 155
      * @return string
156 156
      */
157
-    public static function user_courses( $atts, $content = null ) {
157
+    public static function user_courses($atts, $content = null) {
158 158
         global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
159
+        extract(shortcode_atts(array('amount' => 0), $atts));
160 160
 
161 161
         $shortcode_override = 'usercourses';
162 162
 
163 163
         ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+        if (is_user_logged_in()) {
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+            Sensei_Templates::get_template('user/my-courses.php');
168 168
 
169
-        }else{
169
+        } else {
170 170
 
171 171
             Sensei()->frontend->sensei_login_form();
172 172
 
@@ -182,54 +182,54 @@  discard block
 block discarded – undo
182 182
      * loop-course.php for the old shortcodes.
183 183
      * @since 1.9.0
184 184
      */
185
-    public static function initialise_legacy_course_loop(){
185
+    public static function initialise_legacy_course_loop() {
186 186
 
187 187
         global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189 189
         // Handle Query Type
190 190
         $query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
192
+        if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) {
193
+            $query_type = esc_html($_GET['action']);
194 194
         } // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
196
+        if ('' != $shortcode_override) {
197 197
             $query_type = $shortcode_override;
198 198
         } // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+        if ( ! is_array($course_excludes)) { $course_excludes = array(); }
201 201
 
202 202
         // Check that query returns results
203 203
         // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
204
+        $paged = $wp_query->get('paged');
205
+        $paged = empty($paged) ? 1 : $paged;
206 206
 
207 207
 
208 208
         // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
209
+        if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+            $amount = absint(Sensei()->settings->settings['course_archive_amount']);
212 212
 
213 213
         } else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+            $amount = $wp_query->get('posts_per_page');
216 216
 
217 217
         } // End If Statement
218 218
 
219 219
         // This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221 221
         global $posts_array;
222
-        $course_includes   = array();
222
+        $course_includes = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
224
+        $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes);
225
+        $course_query = new WP_Query($query_args);
226 226
         $posts_array = $course_query->get_posts();
227 227
 
228 228
         // output the courses
229
-        if( ! empty( $posts_array ) ) {
229
+        if ( ! empty($posts_array)) {
230 230
 
231 231
             //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
232
+            self::loop_courses($course_query, $amount);
233 233
 
234 234
         }
235 235
 
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @param WP_Query $course_query
244 244
      */
245
-    public static function loop_courses( $course_query, $amount ){
245
+    public static function loop_courses($course_query, $amount) {
246 246
 
247 247
         global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+        if (count($course_query->get_posts()) > 0) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+            do_action('sensei_course_archive_header', $shortcode_override);
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+            foreach ($course_query->get_posts() as $course) {
254 254
 
255 255
                 // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
256
+                array_push($course_excludes, $course->ID);
257 257
 
258 258
                 // output the course markup
259
-                self::the_course( $course->ID );
259
+                self::the_course($course->ID);
260 260
 
261 261
             } // End For Loop
262 262
 
263 263
             // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
264
+            $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes));
265 265
             $posts_array       = $posts_array_query->get_posts();
266 266
             $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
267
+            if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) {
268 268
 
269
-                switch( $shortcode_override ){
269
+                switch ($shortcode_override) {
270 270
                     case 'paidcourses':
271 271
                         $filter = 'paid';
272 272
                         break;
@@ -282,22 +282,22 @@  discard block
 block discarded – undo
282 282
                 }
283 283
 
284 284
                 $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
285
+                $quer_args['paged'] = '2';
286
+                if ( ! empty($filter)) {
287
+                    $quer_args['course_filter'] = $filter;
288 288
                 }
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+                $course_pagination_link = get_post_type_archive_link('course');
291
+                $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']);
292
+                $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link));
293 293
 
294 294
                 // next/more
295 295
                 $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
296
+                $html .= '<a href="'.$more_link_url.'">';
297 297
                 $html .= $more_link_text;
298 298
                 $html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+                echo apply_filters('course_archive_next_link', $html);
301 301
 
302 302
             } // End If Statement
303 303
 
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
      *
310 310
      * @param $course_id
311 311
      */
312
-    public static function the_course( $course_id ){
312
+    public static function the_course($course_id) {
313 313
 
314 314
         // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
315
+        $course = get_post($course_id);
316
+        $user_info = get_userdata(absint($course->post_author));
317
+        $author_link = get_author_posts_url(absint($course->post_author));
318 318
         $author_display_name = $user_info->display_name;
319 319
         $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
320
+        $category_output = get_the_term_list($course_id, 'course-category', '', ', ', '');
321
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id));
322
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
323 323
         ?>
324 324
 
325
-        <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
325
+        <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>">
326 326
             <?php
327 327
             // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
328
+            do_action('sensei_course_content_before', $course);
329 329
             ?>
330 330
             <div class="course-content">
331 331
 
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
 
342 342
                     <p class="sensei-course-meta">
343 343
 
344
-                        <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
345
-                            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name   ); ?></a></span>
344
+                        <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
345
+                            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
346 346
                         <?php } // End If Statement ?>
347 347
 
348 348
                         <span class="course-lesson-count">
349
-                                    <?php echo Sensei()->course->course_lesson_count( $course_id ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?>
349
+                                    <?php echo Sensei()->course->course_lesson_count($course_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?>
350 350
                                 </span>
351 351
 
352
-                        <?php if ( '' != $category_output ) { ?>
353
-                            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
352
+                        <?php if ('' != $category_output) { ?>
353
+                            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
354 354
                         <?php } // End If Statement ?>
355 355
 
356
-                        <?php sensei_simple_course_price( $course_id ); ?>
356
+                        <?php sensei_simple_course_price($course_id); ?>
357 357
 
358 358
                     </p>
359 359
 
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
 
362 362
                     </p>
363 363
 
364
-                    <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
364
+                    <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) {
365
+                        $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
366 366
                         <p class="sensei-free-lessons">
367
-                            <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
367
+                            <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
369 369
                         </p>
370 370
                     <?php } ?>
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-course-categories.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@
 block discarded – undo
114 114
      *
115 115
      * @since 1.9.0
116 116
      *
117
-     * @param array $category_ids
117
+     * @param array $categories
118 118
      * @return array
119 119
      */
120 120
     public function generate_term_ids( $categories = array() ){
Please login to merge, or discard this patch.
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -24,135 +24,135 @@
 block discarded – undo
24 24
  */
25 25
 class Sensei_Shortcode_Course_Categories implements Sensei_Shortcode_Interface {
26 26
 
27
-    /**
28
-     * @var array list of taxonomy terms.
29
-     */
30
-    protected $sensei_course_taxonomy_terms;
27
+	/**
28
+	 * @var array list of taxonomy terms.
29
+	 */
30
+	protected $sensei_course_taxonomy_terms;
31 31
 
32
-    /**
33
-     * Setup the shortcode object
34
-     *
35
-     * @since 1.9.0
36
-     * @param array $attributes
37
-     * @param string $content
38
-     * @param string $shortcode the shortcode that was called for this instance
39
-     */
40
-    public function __construct( $attributes, $content, $shortcode ){
32
+	/**
33
+	 * Setup the shortcode object
34
+	 *
35
+	 * @since 1.9.0
36
+	 * @param array $attributes
37
+	 * @param string $content
38
+	 * @param string $shortcode the shortcode that was called for this instance
39
+	 */
40
+	public function __construct( $attributes, $content, $shortcode ){
41 41
 
42
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name';
43
-        $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC';
44
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100';
45
-        $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : '';
42
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name';
43
+		$this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC';
44
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100';
45
+		$this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : '';
46 46
 
47
-        $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : '';
48
-        $this->include = $this->generate_term_ids( $include );
47
+		$include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : '';
48
+		$this->include = $this->generate_term_ids( $include );
49 49
 
50
-        $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : '';
51
-        $this->exclude = $this->generate_term_ids( $exclude );
50
+		$exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : '';
51
+		$this->exclude = $this->generate_term_ids( $exclude );
52 52
 
53
-        // make sure we handle string true/false values correctly with respective defaults
54
-        $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false';
55
-        $this->hide_empty = 'true' == $hide_empty ? true: false;
53
+		// make sure we handle string true/false values correctly with respective defaults
54
+		$hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false';
55
+		$this->hide_empty = 'true' == $hide_empty ? true: false;
56 56
 
57
-        $this->setup_course_categories();
57
+		$this->setup_course_categories();
58 58
 
59
-    }
59
+	}
60 60
 
61
-    /**
62
-     * create the messages query .
63
-     *
64
-     * @return mixed
65
-     */
66
-    public function setup_course_categories(){
61
+	/**
62
+	 * create the messages query .
63
+	 *
64
+	 * @return mixed
65
+	 */
66
+	public function setup_course_categories(){
67 67
 
68
-        $args = array(
69
-            'orderby'       => $this->orderby,
70
-            'order'         => $this->order,
71
-            'exclude'       => $this->exclude,
72
-            'include'       => $this->include,
73
-            'number'        => $this->number,
74
-            'parent'        => $this->parent,
75
-            'hide_empty'    => $this->hide_empty,
76
-            'fields'        => 'all',
77
-        );
68
+		$args = array(
69
+			'orderby'       => $this->orderby,
70
+			'order'         => $this->order,
71
+			'exclude'       => $this->exclude,
72
+			'include'       => $this->include,
73
+			'number'        => $this->number,
74
+			'parent'        => $this->parent,
75
+			'hide_empty'    => $this->hide_empty,
76
+			'fields'        => 'all',
77
+		);
78 78
 
79
-        $this->sensei_course_taxonomy_terms = get_terms('course-category', $args);
79
+		$this->sensei_course_taxonomy_terms = get_terms('course-category', $args);
80 80
 
81
-    }
81
+	}
82 82
 
83
-    /**
84
-     * Rendering the shortcode this class is responsible for.
85
-     *
86
-     * @return string $content
87
-     */
88
-    public function render(){
83
+	/**
84
+	 * Rendering the shortcode this class is responsible for.
85
+	 *
86
+	 * @return string $content
87
+	 */
88
+	public function render(){
89 89
 
90
-        if( empty(  $this->sensei_course_taxonomy_terms  ) ){
90
+		if( empty(  $this->sensei_course_taxonomy_terms  ) ){
91 91
 
92
-            return __( 'No course categories found.', 'woothemes-sensei' );
92
+			return __( 'No course categories found.', 'woothemes-sensei' );
93 93
 
94
-        }
94
+		}
95 95
 
96
-        $terms_html = '';
96
+		$terms_html = '';
97 97
 
98
-        //set the wp_query to the current messages query
99
-        $terms_html .= '<ul class="sensei course-categories">';
100
-        foreach( $this->sensei_course_taxonomy_terms as $category ){
98
+		//set the wp_query to the current messages query
99
+		$terms_html .= '<ul class="sensei course-categories">';
100
+		foreach( $this->sensei_course_taxonomy_terms as $category ){
101 101
 
102
-            $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name  . '</a>';
103
-            $terms_html .=  '<li class="sensei course-category" >' . $category_link . '</li>';
102
+			$category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name  . '</a>';
103
+			$terms_html .=  '<li class="sensei course-category" >' . $category_link . '</li>';
104 104
 
105
-        }
106
-        $terms_html .= '<ul>';
105
+		}
106
+		$terms_html .= '<ul>';
107 107
 
108
-        return $terms_html;
108
+		return $terms_html;
109 109
 
110
-    }// end render
110
+	}// end render
111 111
 
112
-    /**
113
-     * Convert an array of mixed ids, slugs or names to only the id's of those terms
114
-     *
115
-     * @since 1.9.0
116
-     *
117
-     * @param array $category_ids
118
-     * @return array
119
-     */
120
-    public function generate_term_ids( $categories = array() ){
112
+	/**
113
+	 * Convert an array of mixed ids, slugs or names to only the id's of those terms
114
+	 *
115
+	 * @since 1.9.0
116
+	 *
117
+	 * @param array $category_ids
118
+	 * @return array
119
+	 */
120
+	public function generate_term_ids( $categories = array() ){
121 121
 
122
-        $cat_ids = array();
122
+		$cat_ids = array();
123 123
 
124
-        if ( is_array($categories) ) {
125
-            foreach ($categories as $cat) {
124
+		if ( is_array($categories) ) {
125
+			foreach ($categories as $cat) {
126 126
 
127
-                if (!is_numeric($cat)) {
127
+				if (!is_numeric($cat)) {
128 128
 
129
-                    // try the slug
130
-                    $term = get_term_by('slug', $cat, 'course-category');
129
+					// try the slug
130
+					$term = get_term_by('slug', $cat, 'course-category');
131 131
 
132
-                    // if the slug didn't work try the name
133
-                    if (!$term) {
132
+					// if the slug didn't work try the name
133
+					if (!$term) {
134 134
 
135
-                        $term = get_term_by('name', $cat, 'course-category');
135
+						$term = get_term_by('name', $cat, 'course-category');
136 136
 
137
-                    }
137
+					}
138 138
 
139
-                    if ($term) {
140
-                        $cat_ids[] = $term->term_id;
141
-                    }
139
+					if ($term) {
140
+						$cat_ids[] = $term->term_id;
141
+					}
142 142
 
143
-                } else {
143
+				} else {
144 144
 
145
-                    $cat_ids[] = $cat;
145
+					$cat_ids[] = $cat;
146 146
 
147
-                }
147
+				}
148 148
 
149
-            }
149
+			}
150 150
 
151
-        }
151
+		}
152 152
 
153
-        return $cat_ids;
153
+		return $cat_ids;
154 154
 
155
-    }// end generate_term_ids
155
+	}// end generate_term_ids
156 156
 
157 157
 }// end class
158 158
 
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_course_categories] shortcode. Show the list or course categories as links to their archive
@@ -37,22 +37,22 @@  discard block
 block discarded – undo
37 37
      * @param string $content
38 38
      * @param string $shortcode the shortcode that was called for this instance
39 39
      */
40
-    public function __construct( $attributes, $content, $shortcode ){
40
+    public function __construct($attributes, $content, $shortcode) {
41 41
 
42
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name';
43
-        $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC';
44
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100';
45
-        $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : '';
42
+        $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'name';
43
+        $this->order = isset($attributes['order']) ? $attributes['order'] : 'ASC';
44
+        $this->number = isset($attributes['number']) ? $attributes['number'] : '100';
45
+        $this->parent = isset($attributes['parent']) ? $attributes['parent'] : '';
46 46
 
47
-        $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : '';
48
-        $this->include = $this->generate_term_ids( $include );
47
+        $include = isset($attributes['include']) ? explode(',', $attributes['include']) : '';
48
+        $this->include = $this->generate_term_ids($include);
49 49
 
50
-        $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : '';
51
-        $this->exclude = $this->generate_term_ids( $exclude );
50
+        $exclude = isset($attributes['exclude']) ? explode(',', $attributes['exclude']) : '';
51
+        $this->exclude = $this->generate_term_ids($exclude);
52 52
 
53 53
         // make sure we handle string true/false values correctly with respective defaults
54
-        $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false';
55
-        $this->hide_empty = 'true' == $hide_empty ? true: false;
54
+        $hide_empty = isset($attributes['hide_empty']) ? $attributes['hide_empty'] : 'false';
55
+        $this->hide_empty = 'true' == $hide_empty ? true : false;
56 56
 
57 57
         $this->setup_course_categories();
58 58
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @return mixed
65 65
      */
66
-    public function setup_course_categories(){
66
+    public function setup_course_categories() {
67 67
 
68 68
         $args = array(
69 69
             'orderby'       => $this->orderby,
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @return string $content
87 87
      */
88
-    public function render(){
88
+    public function render() {
89 89
 
90
-        if( empty(  $this->sensei_course_taxonomy_terms  ) ){
90
+        if (empty($this->sensei_course_taxonomy_terms)) {
91 91
 
92
-            return __( 'No course categories found.', 'woothemes-sensei' );
92
+            return __('No course categories found.', 'woothemes-sensei');
93 93
 
94 94
         }
95 95
 
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 
98 98
         //set the wp_query to the current messages query
99 99
         $terms_html .= '<ul class="sensei course-categories">';
100
-        foreach( $this->sensei_course_taxonomy_terms as $category ){
100
+        foreach ($this->sensei_course_taxonomy_terms as $category) {
101 101
 
102
-            $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name  . '</a>';
103
-            $terms_html .=  '<li class="sensei course-category" >' . $category_link . '</li>';
102
+            $category_link = '<a href="'.get_term_link($category).'">'.$category->name.'</a>';
103
+            $terms_html .= '<li class="sensei course-category" >'.$category_link.'</li>';
104 104
 
105 105
         }
106 106
         $terms_html .= '<ul>';
@@ -117,20 +117,20 @@  discard block
 block discarded – undo
117 117
      * @param array $category_ids
118 118
      * @return array
119 119
      */
120
-    public function generate_term_ids( $categories = array() ){
120
+    public function generate_term_ids($categories = array()) {
121 121
 
122 122
         $cat_ids = array();
123 123
 
124
-        if ( is_array($categories) ) {
124
+        if (is_array($categories)) {
125 125
             foreach ($categories as $cat) {
126 126
 
127
-                if (!is_numeric($cat)) {
127
+                if ( ! is_numeric($cat)) {
128 128
 
129 129
                     // try the slug
130 130
                     $term = get_term_by('slug', $cat, 'course-category');
131 131
 
132 132
                     // if the slug didn't work try the name
133
-                    if (!$term) {
133
+                    if ( ! $term) {
134 134
 
135 135
                         $term = get_term_by('name', $cat, 'course-category');
136 136
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-user-courses.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
      *
326 326
      * @param array $classes
327 327
      * @param WP_Post $course
328
-     * @return array $classes
328
+     * @return string[] $classes
329 329
      */
330 330
     public function course_status_class_tagging($classes, $course){
331 331
 
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  * This class is loaded int WP by the shortcode loader class.
5 5
  *
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
      * @param string $content
60 60
      * @param string $shortcode the shortcode that was called for this instance
61 61
      */
62
-    public function __construct( $attributes, $content, $shortcode ){
62
+    public function __construct($attributes, $content, $shortcode) {
63 63
 
64
-        if(!  is_user_logged_in() ) {
64
+        if ( ! is_user_logged_in()) {
65 65
             return;
66 66
         }
67 67
 
68 68
         // set up all argument need for constructing the course query
69
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
70
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
71
-        $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all';
69
+        $this->number = isset($attributes['number']) ? $attributes['number'] : '10';
70
+        $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title';
71
+        $this->status = isset($attributes['status']) ? $attributes['status'] : 'all';
72 72
 
73 73
         // set the default for menu_order to be ASC
74
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
74
+        if ('menu_order' == $this->orderby && ! isset($attributes['order'])) {
75 75
 
76
-            $this->order =  'ASC';
76
+            $this->order = 'ASC';
77 77
 
78
-        }else{
78
+        } else {
79 79
 
80 80
             // for everything else use the value passed or the default DESC
81
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
81
+            $this->order = isset($attributes['order']) ? $attributes['order'] : 'ASC';
82 82
 
83 83
         }
84 84
 
@@ -92,20 +92,20 @@  discard block
 block discarded – undo
92 92
      *
93 93
      * @since 1.9.0
94 94
      */
95
-    protected function setup_course_query(){
95
+    protected function setup_course_query() {
96 96
 
97
-        $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' );
98
-        $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true );
99
-        if ( !is_array($user_courses_logs) ) {
97
+        $status_query = array('user_id' => get_current_user_id(), 'type' => 'sensei_course_status');
98
+        $user_courses_logs = Sensei_Utils::sensei_check_for_activity($status_query, true);
99
+        if ( ! is_array($user_courses_logs)) {
100 100
 
101
-            $user_courses_logs = array( $user_courses_logs );
101
+            $user_courses_logs = array($user_courses_logs);
102 102
 
103 103
         }
104 104
 
105 105
         $completed_ids = $active_ids = array();
106
-        foreach( $user_courses_logs as $course_status ) {
106
+        foreach ($user_courses_logs as $course_status) {
107 107
 
108
-            if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) {
108
+            if (Sensei_Utils::user_completed_course($course_status, get_current_user_id())) {
109 109
 
110 110
                 $completed_ids[] = $course_status->comment_post_ID;
111 111
 
@@ -116,34 +116,34 @@  discard block
 block discarded – undo
116 116
             }
117 117
         }
118 118
 
119
-        if( 'completed' == $this->status ){
119
+        if ('completed' == $this->status) {
120 120
 
121
-            $included_courses =  $completed_ids;
121
+            $included_courses = $completed_ids;
122 122
 
123 123
 
124
-        }elseif( 'active'==$this->status ){
124
+        }elseif ('active' == $this->status) {
125 125
 
126
-            $included_courses =  $active_ids;
126
+            $included_courses = $active_ids;
127 127
 
128
-        }else{ // all courses
128
+        } else { // all courses
129 129
 
130
-            if( empty( $completed_ids ) ){
130
+            if (empty($completed_ids)) {
131 131
 
132
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) );
132
+                add_action('sensei_loop_course_inside_before', array($this, 'completed_no_course_message_output'));
133 133
             }
134 134
 
135
-            if( empty( $active_ids ) ){
135
+            if (empty($active_ids)) {
136 136
 
137
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
137
+                add_action('sensei_loop_course_inside_before', array($this, 'active_no_course_message_output'));
138 138
 
139 139
             }
140 140
 
141
-            if( empty( $completed_ids ) &&  empty( $active_ids )  ){
141
+            if (empty($completed_ids) && empty($active_ids)) {
142 142
 
143 143
                 $included_courses = array('-1000'); // don't show any courses
144 144
 
145
-            }else{
146
-                $included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids );
145
+            } else {
146
+                $included_courses = Sensei_Utils::array_zip_merge($active_ids, $completed_ids);
147 147
             }
148 148
 
149 149
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         // if the shortcode is not active or in active and the active and completed
155 155
         // tabs show up.
156 156
         $number_of_posts = $this->number;
157
-        if( 'active' != $this->status && 'complete' != $this->status  ){
157
+        if ('active' != $this->status && 'complete' != $this->status) {
158 158
             $number_of_posts = 1000;
159 159
         }
160 160
 
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
             'post_status'      => 'publish',
166 166
             'orderby'          => $this->orderby,
167 167
             'order'            => $this->order,
168
-            'paged' => empty( $query_var_paged )? 1 : $query_var_paged,
168
+            'paged' => empty($query_var_paged) ? 1 : $query_var_paged,
169 169
             'posts_per_page'   => $number_of_posts,
170 170
             'post__in'         => $included_courses,
171 171
         );
172 172
 
173
-        $this->query = new WP_Query( $query_args );
173
+        $this->query = new WP_Query($query_args);
174 174
 
175 175
     }// end setup _course_query
176 176
 
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
      *
181 181
      * @since 1.9.0
182 182
      */
183
-    public function completed_no_course_message_output(){
183
+    public function completed_no_course_message_output() {
184 184
         ?>
185 185
         <li class="user-completed">
186 186
             <div class="sensei-message info">
187 187
 
188
-                <?php _e( 'You have not completed any courses yet.', 'woothemes-sensei' ); ?>
188
+                <?php _e('You have not completed any courses yet.', 'woothemes-sensei'); ?>
189 189
 
190 190
             </div>
191 191
         </li>
@@ -198,17 +198,17 @@  discard block
 block discarded – undo
198 198
      *
199 199
      * @since 1.9.0
200 200
      */
201
-    public function active_no_course_message_output(){
201
+    public function active_no_course_message_output() {
202 202
         ?>
203 203
 
204 204
         <li class="user-active">
205 205
             <div class="sensei-message info">
206 206
 
207
-                <?php _e( 'You have no active courses.', 'woothemes-sensei' ); ?>
207
+                <?php _e('You have no active courses.', 'woothemes-sensei'); ?>
208 208
 
209
-                <a href="<?php esc_attr_e( Sensei_Course::get_courses_page_url() ); ?>">
209
+                <a href="<?php esc_attr_e(Sensei_Course::get_courses_page_url()); ?>">
210 210
 
211
-                    <?php  _e( 'Start a Course!', 'woothemes-sensei' ); ?>
211
+                    <?php  _e('Start a Course!', 'woothemes-sensei'); ?>
212 212
 
213 213
                 </a>
214 214
 
@@ -222,11 +222,11 @@  discard block
 block discarded – undo
222 222
      *
223 223
      * @return string $content
224 224
      */
225
-    public function render(){
225
+    public function render() {
226 226
 
227 227
         global $wp_query;
228 228
 
229
-        if(!  is_user_logged_in() ) {
229
+        if ( ! is_user_logged_in()) {
230 230
             return '';
231 231
         }
232 232
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         Sensei_Messages::the_my_messages_link();
243 243
         Sensei_Templates::get_template('loop-course.php');
244 244
         Sensei_Templates::get_template('globals/pagination.php');
245
-        $shortcode_output =  ob_get_clean();
245
+        $shortcode_output = ob_get_clean();
246 246
 
247 247
         $this->detach_shortcode_hooks();
248 248
 
@@ -258,23 +258,23 @@  discard block
 block discarded – undo
258 258
      *
259 259
      * @since 1.9.0
260 260
      */
261
-    public function attach_shortcode_hooks(){
261
+    public function attach_shortcode_hooks() {
262 262
 
263 263
         // attach the toggle functionality
264 264
         // don't show the toggle action if the user specified complete or active for this shortcode
265
-        if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){
265
+        if ( ! in_array($this->status, array('active', 'complete'))) {
266 266
 
267
-            add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
268
-            add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 );
267
+            add_action('sensei_loop_course_before', array($this, 'course_toggle_actions'));
268
+            add_action('wp_footer', array($this, 'print_course_toggle_actions_inline_script'), 90);
269 269
 
270 270
         }
271 271
 
272 272
         // add extra classes to distinguish the course based on user completed or active
273
-        add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
273
+        add_filter('sensei_course_loop_content_class', array($this, 'course_status_class_tagging'), 20, 2);
274 274
 
275 275
         // attach progress meter below course
276
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
277
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
276
+        add_action('sensei_course_content_inside_after', array($this, 'attach_course_progress'));
277
+        add_action('sensei_course_content_inside_after', array($this, 'attach_course_buttons'));
278 278
 
279 279
     }
280 280
 
@@ -283,13 +283,13 @@  discard block
 block discarded – undo
283 283
      *
284 284
      * @since 1.9.0
285 285
      */
286
-    public function detach_shortcode_hooks(){
286
+    public function detach_shortcode_hooks() {
287 287
 
288 288
         //remove all hooks after the output is generated
289
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
290
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
291
-        remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
292
-        remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
289
+        remove_action('sensei_course_content_inside_after', array($this, 'attach_course_progress'));
290
+        remove_action('sensei_course_content_inside_after', array($this, 'attach_course_buttons'));
291
+        remove_filter('sensei_course_loop_content_class', array($this, 'course_status_class_tagging'), 20, 2);
292
+        remove_action('sensei_loop_course_before', array($this, 'course_toggle_actions'));
293 293
     }
294 294
 
295 295
     /**
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
      *
298 298
      * @param $course
299 299
      */
300
-    public function attach_course_progress( $course ){
300
+    public function attach_course_progress($course) {
301 301
 
302
-        $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() );
303
-        echo Sensei()->course->get_progress_meter( $percentage );
302
+        $percentage = Sensei()->course->get_completion_percentage($course->ID, get_current_user_id());
303
+        echo Sensei()->course->get_progress_meter($percentage);
304 304
 
305 305
     }// attach_course_progress
306 306
 
@@ -312,9 +312,9 @@  discard block
 block discarded – undo
312 312
      *
313 313
      * @param $course
314 314
      */
315
-    public function attach_course_buttons( $course ){
315
+    public function attach_course_buttons($course) {
316 316
 
317
-        Sensei()->course->the_course_action_buttons( $course );
317
+        Sensei()->course->the_course_action_buttons($course);
318 318
 
319 319
     }// attach_course_buttons
320 320
 
@@ -327,9 +327,9 @@  discard block
 block discarded – undo
327 327
      * @param WP_Post $course
328 328
      * @return array $classes
329 329
      */
330
-    public function course_status_class_tagging($classes, $course){
330
+    public function course_status_class_tagging($classes, $course) {
331 331
 
332
-        if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) {
332
+        if (Sensei_Utils::user_completed_course($course, get_current_user_id())) {
333 333
 
334 334
             $classes[] = 'user-completed';
335 335
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
     /**
347 347
      * Output the course toggle functionality
348 348
      */
349
-    public function course_toggle_actions(){ ?>
349
+    public function course_toggle_actions() { ?>
350 350
 
351 351
         <section id="user-course-status-toggle">
352 352
             <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a>
Please login to merge, or discard this patch.
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 /**
4 7
  * This class is loaded int WP by the shortcode loader class.
5 8
  *
@@ -75,7 +78,7 @@  discard block
 block discarded – undo
75 78
 
76 79
             $this->order =  'ASC';
77 80
 
78
-        }else{
81
+        } else{
79 82
 
80 83
             // for everything else use the value passed or the default DESC
81 84
             $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
@@ -121,11 +124,11 @@  discard block
 block discarded – undo
121 124
             $included_courses =  $completed_ids;
122 125
 
123 126
 
124
-        }elseif( 'active'==$this->status ){
127
+        } elseif( 'active'==$this->status ){
125 128
 
126 129
             $included_courses =  $active_ids;
127 130
 
128
-        }else{ // all courses
131
+        } else{ // all courses
129 132
 
130 133
             if( empty( $completed_ids ) ){
131 134
 
@@ -142,7 +145,7 @@  discard block
 block discarded – undo
142 145
 
143 146
                 $included_courses = array('-1000'); // don't show any courses
144 147
 
145
-            }else{
148
+            } else{
146 149
                 $included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids );
147 150
             }
148 151
 
Please login to merge, or discard this patch.
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -23,165 +23,165 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface {
25 25
 
26
-    /**
27
-     * @var WP_Query to help setup the query needed by the render method.
28
-     */
29
-    protected $query;
26
+	/**
27
+	 * @var WP_Query to help setup the query needed by the render method.
28
+	 */
29
+	protected $query;
30 30
 
31
-    /**
32
-     * @var string number of items to show on the current page
33
-     * Default: -1.
34
-     */
35
-    protected $number;
31
+	/**
32
+	 * @var string number of items to show on the current page
33
+	 * Default: -1.
34
+	 */
35
+	protected $number;
36 36
 
37
-    /**
38
-     * @var string ordery by course field
39
-     * Default: date
40
-     */
41
-    protected $orderby;
37
+	/**
38
+	 * @var string ordery by course field
39
+	 * Default: date
40
+	 */
41
+	protected $orderby;
42 42
 
43
-    /**
44
-     * @var string ASC or DESC
45
-     * Default: 'DESC'
46
-     */
47
-    protected  $order;
43
+	/**
44
+	 * @var string ASC or DESC
45
+	 * Default: 'DESC'
46
+	 */
47
+	protected  $order;
48 48
 
49
-    /**
50
-     * @var status can be completed or active. If none is specified all will be shown
51
-     */
52
-    protected $status;
49
+	/**
50
+	 * @var status can be completed or active. If none is specified all will be shown
51
+	 */
52
+	protected $status;
53 53
 
54
-    /**
55
-     * Setup the shortcode object
56
-     *
57
-     * @since 1.9.0
58
-     * @param array $attributes
59
-     * @param string $content
60
-     * @param string $shortcode the shortcode that was called for this instance
61
-     */
62
-    public function __construct( $attributes, $content, $shortcode ){
54
+	/**
55
+	 * Setup the shortcode object
56
+	 *
57
+	 * @since 1.9.0
58
+	 * @param array $attributes
59
+	 * @param string $content
60
+	 * @param string $shortcode the shortcode that was called for this instance
61
+	 */
62
+	public function __construct( $attributes, $content, $shortcode ){
63 63
 
64
-        if(!  is_user_logged_in() ) {
65
-            return;
66
-        }
64
+		if(!  is_user_logged_in() ) {
65
+			return;
66
+		}
67 67
 
68
-        // set up all argument need for constructing the course query
69
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
70
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
71
-        $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all';
68
+		// set up all argument need for constructing the course query
69
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
70
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
71
+		$this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all';
72 72
 
73
-        // set the default for menu_order to be ASC
74
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
73
+		// set the default for menu_order to be ASC
74
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
75 75
 
76
-            $this->order =  'ASC';
76
+			$this->order =  'ASC';
77 77
 
78
-        }else{
78
+		}else{
79 79
 
80
-            // for everything else use the value passed or the default DESC
81
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
80
+			// for everything else use the value passed or the default DESC
81
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
82 82
 
83
-        }
83
+		}
84 84
 
85
-        // setup the course query that will be used when rendering
86
-        $this->setup_course_query();
87
-    }
85
+		// setup the course query that will be used when rendering
86
+		$this->setup_course_query();
87
+	}
88 88
 
89
-    /**
90
-     * Sets up the object course query
91
-     * that will be used in the render method.
92
-     *
93
-     * @since 1.9.0
94
-     */
95
-    protected function setup_course_query(){
89
+	/**
90
+	 * Sets up the object course query
91
+	 * that will be used in the render method.
92
+	 *
93
+	 * @since 1.9.0
94
+	 */
95
+	protected function setup_course_query(){
96 96
 
97
-        $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' );
98
-        $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true );
99
-        if ( !is_array($user_courses_logs) ) {
97
+		$status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' );
98
+		$user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true );
99
+		if ( !is_array($user_courses_logs) ) {
100 100
 
101
-            $user_courses_logs = array( $user_courses_logs );
101
+			$user_courses_logs = array( $user_courses_logs );
102 102
 
103
-        }
103
+		}
104 104
 
105
-        $completed_ids = $active_ids = array();
106
-        foreach( $user_courses_logs as $course_status ) {
105
+		$completed_ids = $active_ids = array();
106
+		foreach( $user_courses_logs as $course_status ) {
107 107
 
108
-            if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) {
108
+			if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) {
109 109
 
110
-                $completed_ids[] = $course_status->comment_post_ID;
110
+				$completed_ids[] = $course_status->comment_post_ID;
111 111
 
112
-            } else {
112
+			} else {
113 113
 
114
-                $active_ids[] = $course_status->comment_post_ID;
114
+				$active_ids[] = $course_status->comment_post_ID;
115 115
 
116
-            }
117
-        }
116
+			}
117
+		}
118 118
 
119
-        if( 'completed' == $this->status ){
119
+		if( 'completed' == $this->status ){
120 120
 
121
-            $included_courses =  $completed_ids;
121
+			$included_courses =  $completed_ids;
122 122
 
123 123
 
124
-        }elseif( 'active'==$this->status ){
124
+		}elseif( 'active'==$this->status ){
125 125
 
126
-            $included_courses =  $active_ids;
126
+			$included_courses =  $active_ids;
127 127
 
128
-        }else{ // all courses
128
+		}else{ // all courses
129 129
 
130
-            if( empty( $completed_ids ) ){
130
+			if( empty( $completed_ids ) ){
131 131
 
132
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) );
133
-            }
132
+				add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) );
133
+			}
134 134
 
135
-            if( empty( $active_ids ) ){
135
+			if( empty( $active_ids ) ){
136 136
 
137
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
137
+				add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
138 138
 
139
-            }
139
+			}
140 140
 
141
-            if( empty( $completed_ids ) &&  empty( $active_ids )  ){
141
+			if( empty( $completed_ids ) &&  empty( $active_ids )  ){
142 142
 
143
-                $included_courses = array('-1000'); // don't show any courses
143
+				$included_courses = array('-1000'); // don't show any courses
144 144
 
145
-            }else{
146
-                $included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids );
147
-            }
145
+			}else{
146
+				$included_courses = Sensei_Utils::array_zip_merge( $active_ids, $completed_ids );
147
+			}
148
+
149
+
150
+		}
151
+
152
+		// temporary work around to hide pagination on the courses page
153
+		// this is in place until we can load the course for each tab via ajax
154
+		// if the shortcode is not active or in active and the active and completed
155
+		// tabs show up.
156
+		$number_of_posts = $this->number;
157
+		if( 'active' != $this->status && 'complete' != $this->status  ){
158
+			$number_of_posts = 1000;
159
+		}
160
+
161
+		// course query parameters
162
+		$query_var_paged = get_query_var('paged');
163
+		$query_args = array(
164
+			'post_type'        => 'course',
165
+			'post_status'      => 'publish',
166
+			'orderby'          => $this->orderby,
167
+			'order'            => $this->order,
168
+			'paged' => empty( $query_var_paged )? 1 : $query_var_paged,
169
+			'posts_per_page'   => $number_of_posts,
170
+			'post__in'         => $included_courses,
171
+		);
172
+
173
+		$this->query = new WP_Query( $query_args );
148 174
 
175
+	}// end setup _course_query
149 176
 
150
-        }
151
-
152
-        // temporary work around to hide pagination on the courses page
153
-        // this is in place until we can load the course for each tab via ajax
154
-        // if the shortcode is not active or in active and the active and completed
155
-        // tabs show up.
156
-        $number_of_posts = $this->number;
157
-        if( 'active' != $this->status && 'complete' != $this->status  ){
158
-            $number_of_posts = 1000;
159
-        }
160
-
161
-        // course query parameters
162
-        $query_var_paged = get_query_var('paged');
163
-        $query_args = array(
164
-            'post_type'        => 'course',
165
-            'post_status'      => 'publish',
166
-            'orderby'          => $this->orderby,
167
-            'order'            => $this->order,
168
-            'paged' => empty( $query_var_paged )? 1 : $query_var_paged,
169
-            'posts_per_page'   => $number_of_posts,
170
-            'post__in'         => $included_courses,
171
-        );
172
-
173
-        $this->query = new WP_Query( $query_args );
174
-
175
-    }// end setup _course_query
176
-
177
-    /**
178
-     * Output the message that tells the user they have
179
-     * no completed courses.
180
-     *
181
-     * @since 1.9.0
182
-     */
183
-    public function completed_no_course_message_output(){
184
-        ?>
177
+	/**
178
+	 * Output the message that tells the user they have
179
+	 * no completed courses.
180
+	 *
181
+	 * @since 1.9.0
182
+	 */
183
+	public function completed_no_course_message_output(){
184
+		?>
185 185
         <li class="user-completed">
186 186
             <div class="sensei-message info">
187 187
 
@@ -190,16 +190,16 @@  discard block
 block discarded – undo
190 190
             </div>
191 191
         </li>
192 192
         <?php
193
-    }
193
+	}
194 194
 
195
-    /**
196
-     * Output the message that tells the user they have
197
-     * no active courses.
198
-     *
199
-     * @since 1.9.0
200
-     */
201
-    public function active_no_course_message_output(){
202
-        ?>
195
+	/**
196
+	 * Output the message that tells the user they have
197
+	 * no active courses.
198
+	 *
199
+	 * @since 1.9.0
200
+	 */
201
+	public function active_no_course_message_output(){
202
+		?>
203 203
 
204 204
         <li class="user-active">
205 205
             <div class="sensei-message info">
@@ -215,141 +215,141 @@  discard block
 block discarded – undo
215 215
             </div>
216 216
         </li>
217 217
         <?php
218
-    }
218
+	}
219 219
 
220
-    /**
221
-     * Rendering the shortcode this class is responsible for.
222
-     *
223
-     * @return string $content
224
-     */
225
-    public function render(){
220
+	/**
221
+	 * Rendering the shortcode this class is responsible for.
222
+	 *
223
+	 * @return string $content
224
+	 */
225
+	public function render(){
226 226
 
227
-        global $wp_query;
227
+		global $wp_query;
228 228
 
229
-        if(!  is_user_logged_in() ) {
230
-            return '';
231
-        }
229
+		if(!  is_user_logged_in() ) {
230
+			return '';
231
+		}
232 232
 
233
-        // keep a reference to old query
234
-        $current_global_query = $wp_query;
233
+		// keep a reference to old query
234
+		$current_global_query = $wp_query;
235 235
 
236
-        // assign the query setup in $this-> setup_course_query
237
-        $wp_query = $this->query;
236
+		// assign the query setup in $this-> setup_course_query
237
+		$wp_query = $this->query;
238 238
 
239
-        $this->attach_shortcode_hooks();
239
+		$this->attach_shortcode_hooks();
240 240
 
241
-        ob_start();
242
-        echo '<section id="sensei-user-courses">';
243
-        Sensei_Messages::the_my_messages_link();
244
-        Sensei_Templates::get_template('loop-course.php');
245
-        Sensei_Templates::get_template('globals/pagination.php');
246
-        echo '</section>';
241
+		ob_start();
242
+		echo '<section id="sensei-user-courses">';
243
+		Sensei_Messages::the_my_messages_link();
244
+		Sensei_Templates::get_template('loop-course.php');
245
+		Sensei_Templates::get_template('globals/pagination.php');
246
+		echo '</section>';
247 247
 
248
-        $shortcode_output =  ob_get_clean();
248
+		$shortcode_output =  ob_get_clean();
249 249
 
250
-        $this->detach_shortcode_hooks();
250
+		$this->detach_shortcode_hooks();
251 251
 
252
-        //restore old query
253
-        $wp_query = $current_global_query;
252
+		//restore old query
253
+		$wp_query = $current_global_query;
254 254
 
255
-        return $shortcode_output;
255
+		return $shortcode_output;
256 256
 
257
-    }// end render
257
+	}// end render
258 258
 
259
-    /**
260
-     * Add hooks for the shortcode
261
-     *
262
-     * @since 1.9.0
263
-     */
264
-    public function attach_shortcode_hooks(){
259
+	/**
260
+	 * Add hooks for the shortcode
261
+	 *
262
+	 * @since 1.9.0
263
+	 */
264
+	public function attach_shortcode_hooks(){
265 265
 
266
-        // attach the toggle functionality
267
-        // don't show the toggle action if the user specified complete or active for this shortcode
268
-        if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){
266
+		// attach the toggle functionality
267
+		// don't show the toggle action if the user specified complete or active for this shortcode
268
+		if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){
269 269
 
270
-            add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
271
-            add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 );
270
+			add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
271
+			add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 );
272 272
 
273
-        }
273
+		}
274 274
 
275
-        // add extra classes to distinguish the course based on user completed or active
276
-        add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
275
+		// add extra classes to distinguish the course based on user completed or active
276
+		add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
277 277
 
278
-        // attach progress meter below course
279
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
280
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
278
+		// attach progress meter below course
279
+		add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
280
+		add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
281 281
 
282
-    }
282
+	}
283 283
 
284
-    /**
285
-     * Remove hooks for the shortcode
286
-     *
287
-     * @since 1.9.0
288
-     */
289
-    public function detach_shortcode_hooks(){
284
+	/**
285
+	 * Remove hooks for the shortcode
286
+	 *
287
+	 * @since 1.9.0
288
+	 */
289
+	public function detach_shortcode_hooks(){
290 290
 
291
-        //remove all hooks after the output is generated
292
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
293
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
294
-        remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
295
-        remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
296
-    }
291
+		//remove all hooks after the output is generated
292
+		remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
293
+		remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
294
+		remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
295
+		remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
296
+	}
297 297
 
298
-    /**
299
-     * Hooks into sensei_course_content_inside_after
300
-     *
301
-     * @param $course
302
-     */
303
-    public function attach_course_progress( $course ){
298
+	/**
299
+	 * Hooks into sensei_course_content_inside_after
300
+	 *
301
+	 * @param $course
302
+	 */
303
+	public function attach_course_progress( $course ){
304 304
 
305
-        $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() );
306
-        echo Sensei()->course->get_progress_meter( $percentage );
305
+		$percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() );
306
+		echo Sensei()->course->get_progress_meter( $percentage );
307 307
 
308
-    }// attach_course_progress
308
+	}// attach_course_progress
309 309
 
310 310
 
311
-    /**
312
-     * Hooked into sensei_course_content_inside_after
313
-     *
314
-     * Prints out the course action buttons
315
-     *
316
-     * @param $course
317
-     */
318
-    public function attach_course_buttons( $course ){
311
+	/**
312
+	 * Hooked into sensei_course_content_inside_after
313
+	 *
314
+	 * Prints out the course action buttons
315
+	 *
316
+	 * @param $course
317
+	 */
318
+	public function attach_course_buttons( $course ){
319 319
 
320
-        Sensei()->course->the_course_action_buttons( $course );
320
+		Sensei()->course->the_course_action_buttons( $course );
321 321
 
322
-    }// attach_course_buttons
322
+	}// attach_course_buttons
323 323
 
324
-    /**
325
-     * Add a the user status class for the given course.
326
-     *
327
-     * @since 1.9
328
-     *
329
-     * @param array $classes
330
-     * @param WP_Post $course
331
-     * @return array $classes
332
-     */
333
-    public function course_status_class_tagging($classes, $course){
324
+	/**
325
+	 * Add a the user status class for the given course.
326
+	 *
327
+	 * @since 1.9
328
+	 *
329
+	 * @param array $classes
330
+	 * @param WP_Post $course
331
+	 * @return array $classes
332
+	 */
333
+	public function course_status_class_tagging($classes, $course){
334 334
 
335
-        if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) {
335
+		if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) {
336 336
 
337
-            $classes[] = 'user-completed';
337
+			$classes[] = 'user-completed';
338 338
 
339
-        } else {
339
+		} else {
340 340
 
341
-            $classes[] = 'user-active';
341
+			$classes[] = 'user-active';
342 342
 
343
-        }
343
+		}
344 344
 
345
-        return $classes;
345
+		return $classes;
346 346
 
347
-    }// end course_status_class_tagging
347
+	}// end course_status_class_tagging
348 348
 
349
-    /**
350
-     * Output the course toggle functionality
351
-     */
352
-    public function course_toggle_actions(){ ?>
349
+	/**
350
+	 * Output the course toggle functionality
351
+	 */
352
+	public function course_toggle_actions(){ ?>
353 353
 
354 354
         <section id="user-course-status-toggle">
355 355
             <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a>
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 
360 360
     <?php }
361 361
 
362
-    /**
363
-     * Load the javascript for the toggle functionality
364
-     *
365
-     * @since 1.9.0
366
-     */
367
-    function print_course_toggle_actions_inline_script() { ?>
362
+	/**
363
+	 * Load the javascript for the toggle functionality
364
+	 *
365
+	 * @since 1.9.0
366
+	 */
367
+	function print_course_toggle_actions_inline_script() { ?>
368 368
 
369 369
         <script type="text/javascript">
370 370
             var buttonContainer = jQuery('#user-course-status-toggle');
Please login to merge, or discard this patch.
widgets/widget-woothemes-sensei-course-component.php 4 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -167,8 +167,6 @@
 block discarded – undo
167 167
 
168 168
 	/**
169 169
 	 * Load the desired component, if a method is available for it.
170
-	 * @param  string $component The component to potentially be loaded.
171
-     *
172 170
 	 * @since  1.0.0
173 171
 	 * @return void
174 172
 	 */
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 		remove_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
65 65
 
66 66
 		if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) )
67
-            && ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] )
68
-            && !is_user_logged_in() ) {
67
+			&& ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] )
68
+			&& !is_user_logged_in() ) {
69 69
 
70 70
 			// No Output
71
-            return;
71
+			return;
72 72
 
73 73
 		} else {
74 74
 			/* Our variables from the widget settings. */
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @param  array $instance The settings for this instance.
131 131
 	 * @return void
132 132
 	 */
133
-    public function form( $instance ) {
133
+	public function form( $instance ) {
134 134
 
135 135
 		/* Set up some default widget settings. */
136 136
 		/* Make sure all keys are added here, even with empty string values. */
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	/**
169 169
 	 * Load the desired component, if a method is available for it.
170 170
 	 * @param  string $component The component to potentially be loaded.
171
-     *
171
+	 *
172 172
 	 * @since  1.0.0
173 173
 	 * @return void
174 174
 	 */
@@ -207,24 +207,24 @@  discard block
 block discarded – undo
207 207
 
208 208
 		}
209 209
 
210
-        if ( ! empty( $course_ids ) ) {
210
+		if ( ! empty( $course_ids ) ) {
211 211
 
212
-            $posts_array = Sensei()->course->course_query( intval( $instance['limit'] ), esc_attr( $instance['component'] ), $course_ids );
212
+			$posts_array = Sensei()->course->course_query( intval( $instance['limit'] ), esc_attr( $instance['component'] ), $course_ids );
213 213
 
214 214
 		} else {
215 215
 
216
-            if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
216
+			if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
217 217
 				$posts_array = array();
218 218
 
219
-            } else {
219
+			} else {
220 220
 
221
-                $course_args = array(
222
-                    'post_type' => 'course',
223
-                    'orderby'         	=> 'date',
224
-                    'order'           	=> 'DESC',
225
-                    'post_status'      	=> 'publish',
226
-                    'posts_per_page' => $instance['limit'],
227
-                );
221
+				$course_args = array(
222
+					'post_type' => 'course',
223
+					'orderby'         	=> 'date',
224
+					'order'           	=> 'DESC',
225
+					'post_status'      	=> 'publish',
226
+					'posts_per_page' => $instance['limit'],
227
+				);
228 228
 
229 229
 				$posts_array = get_posts( $course_args );
230 230
 			}
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 		if ( count( $posts_array ) > 0 ) { ?>
235 235
 			<ul>
236 236
 			<?php foreach ($posts_array as $post_item){
237
-		    	$post_id = absint( $post_item->ID );
238
-		    	$post_title = $post_item->post_title;
239
-		    	$user_info = get_userdata( absint( $post_item->post_author ) );
240
-		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
241
-		    	$author_display_name = $user_info->display_name;
242
-		    	$author_id = $post_item->post_author;
243
-		    ?>
237
+				$post_id = absint( $post_item->ID );
238
+				$post_title = $post_item->post_title;
239
+				$user_info = get_userdata( absint( $post_item->post_author ) );
240
+				$author_link = get_author_posts_url( absint( $post_item->post_author ) );
241
+				$author_display_name = $user_info->display_name;
242
+				$author_id = $post_item->post_author;
243
+			?>
244 244
 		    	<li class="fix">
245 245
 		    		<?php do_action( 'sensei_course_image', $post_id ); ?>
246 246
 		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 		    	</li>
256 256
 		    <?php } // End For Loop ?>
257 257
 		    <?php if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
258
-		    	$my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
259
-		    	echo '<li class="my-account fix"><a href="'. esc_url( get_permalink( $my_account_page_id ) ) .'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
260
-		    } // End If Statement ?>
258
+				$my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
259
+				echo '<li class="my-account fix"><a href="'. esc_url( get_permalink( $my_account_page_id ) ) .'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
260
+			} // End If Statement ?>
261 261
 		</ul>
262 262
 		<?php } else {
263 263
 			// No posts returned. This means the user either has no active or no completed courses.
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly.
3 6
 
4 7
 /**
5 8
  * Sensei Course Component Widget
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly.
3 3
 
4 4
 /**
5 5
  * Sensei Course Component Widget
@@ -26,30 +26,30 @@  discard block
 block discarded – undo
26 26
 	public function __construct() {
27 27
 		/* Widget variable settings. */
28 28
 		$this->woo_widget_cssclass = 'widget_sensei_course_component';
29
-		$this->woo_widget_description = __( 'This widget will output a list of Courses - New, Featured, Free, Paid, Active, Completed.', 'woothemes-sensei' );
29
+		$this->woo_widget_description = __('This widget will output a list of Courses - New, Featured, Free, Paid, Active, Completed.', 'woothemes-sensei');
30 30
 		$this->woo_widget_idbase = 'sensei_course_component';
31
-		$this->woo_widget_title = __( 'Sensei - Course Component', 'woothemes-sensei' );
31
+		$this->woo_widget_title = __('Sensei - Course Component', 'woothemes-sensei');
32 32
 
33 33
 		$this->woo_widget_componentslist = array(
34
-												'usercourses' => __( 'New Courses', 'woothemes-sensei' ),
35
-												'featuredcourses' => __( 'Featured Courses', 'woothemes-sensei' ),
36
-												'activecourses' => __( 'My Active Courses', 'woothemes-sensei' ),
37
-												'completedcourses' => __( 'My Completed Courses', 'woothemes-sensei' ),
34
+												'usercourses' => __('New Courses', 'woothemes-sensei'),
35
+												'featuredcourses' => __('Featured Courses', 'woothemes-sensei'),
36
+												'activecourses' => __('My Active Courses', 'woothemes-sensei'),
37
+												'completedcourses' => __('My Completed Courses', 'woothemes-sensei'),
38 38
 												);
39 39
 
40 40
 		// Add support for the WooCommerce shelf.
41
-		if ( Sensei_WC::is_woocommerce_active() ) {
42
-			$this->woo_widget_componentslist['freecourses'] = __( 'Free Courses', 'woothemes-sensei' );
43
-			$this->woo_widget_componentslist['paidcourses'] = __( 'Paid Courses', 'woothemes-sensei' );
41
+		if (Sensei_WC::is_woocommerce_active()) {
42
+			$this->woo_widget_componentslist['freecourses'] = __('Free Courses', 'woothemes-sensei');
43
+			$this->woo_widget_componentslist['paidcourses'] = __('Paid Courses', 'woothemes-sensei');
44 44
 		}
45 45
 		/* Widget settings. */
46
-		$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
46
+		$widget_ops = array('classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description);
47 47
 
48 48
 		/* Widget control settings. */
49
-		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
49
+		$control_ops = array('width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase);
50 50
 
51 51
 		/* Create the widget. */
52
-		parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
52
+		parent::__construct($this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops);
53 53
 	} // End __construct()
54 54
 
55 55
 	/**
@@ -59,44 +59,44 @@  discard block
 block discarded – undo
59 59
 	 * @param  array $instance Widget settings for this instance.
60 60
 	 * @return void
61 61
 	 */
62
-	public function widget( $args, $instance ) {
62
+	public function widget($args, $instance) {
63 63
 
64
-		remove_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
64
+		remove_filter('pre_get_posts', 'sensei_course_archive_filter', 10, 1);
65 65
 
66
-		if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) )
67
-            && ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] )
68
-            && !is_user_logged_in() ) {
66
+		if (in_array($instance['component'], array_keys($this->woo_widget_componentslist))
67
+            && ('activecourses' == $instance['component'] || 'completedcourses' == $instance['component'])
68
+            && ! is_user_logged_in()) {
69 69
 
70 70
 			// No Output
71 71
             return;
72 72
 
73 73
 		} else {
74 74
 			/* Our variables from the widget settings. */
75
-			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
75
+			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
76 76
 
77 77
 			/* Before widget (defined by themes). */
78 78
 			echo $args['before_widget'];
79 79
 
80 80
 			/* Display the widget title if one was input (before and after defined by themes). */
81
-			if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; }
81
+			if ($title) { echo $args['before_title'].$title.$args['after_title']; }
82 82
 
83 83
 			/* Widget content. */
84 84
 			// Add actions for plugins/themes to hook onto.
85
-			do_action( $this->woo_widget_cssclass . '_top' );
85
+			do_action($this->woo_widget_cssclass.'_top');
86 86
 
87
-			if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) ) {
88
-				$this->load_component( $instance );
87
+			if (in_array($instance['component'], array_keys($this->woo_widget_componentslist))) {
88
+				$this->load_component($instance);
89 89
 			}
90 90
 
91 91
 			// Add actions for plugins/themes to hook onto.
92
-			do_action( $this->woo_widget_cssclass . '_bottom' );
92
+			do_action($this->woo_widget_cssclass.'_bottom');
93 93
 
94 94
 			/* After widget (defined by themes). */
95 95
 			echo $args['after_widget'];
96 96
 
97 97
 		} // End If Statement
98 98
 
99
-		add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
99
+		add_filter('pre_get_posts', 'sensei_course_archive_filter', 10, 1);
100 100
 
101 101
 	} // End widget()
102 102
 
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
 	 * @param  array $old_instance Previous settings.
108 108
 	 * @return array               Updated settings.
109 109
 	 */
110
-	public function update ( $new_instance, $old_instance ) {
110
+	public function update($new_instance, $old_instance) {
111 111
 		$instance = $old_instance;
112 112
 
113 113
 		/* Strip tags for title and name to remove HTML (important for text inputs). */
114
-		$instance['title'] = strip_tags( $new_instance['title'] );
114
+		$instance['title'] = strip_tags($new_instance['title']);
115 115
 
116 116
 		/* The select box is returning a text value, so we escape it. */
117
-		$instance['component'] = esc_attr( $new_instance['component'] );
117
+		$instance['component'] = esc_attr($new_instance['component']);
118 118
 
119 119
 		/* The select box is returning a text value, so we escape it. */
120
-		$instance['limit'] = esc_attr( $new_instance['limit'] );
120
+		$instance['limit'] = esc_attr($new_instance['limit']);
121 121
 
122 122
 
123 123
 		return $instance;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @param  array $instance The settings for this instance.
131 131
 	 * @return void
132 132
 	 */
133
-    public function form( $instance ) {
133
+    public function form($instance) {
134 134
 
135 135
 		/* Set up some default widget settings. */
136 136
 		/* Make sure all keys are added here, even with empty string values. */
@@ -140,26 +140,26 @@  discard block
 block discarded – undo
140 140
 						'limit' => 3
141 141
 					);
142 142
 
143
-		$instance = wp_parse_args( (array) $instance, $defaults );
143
+		$instance = wp_parse_args((array) $instance, $defaults);
144 144
 ?>
145 145
 		<!-- Widget Title: Text Input -->
146 146
 		<p>
147
-			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
148
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"  value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
147
+			<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title (optional):', 'woothemes-sensei'); ?></label>
148
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>"  value="<?php echo esc_attr($instance['title']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" />
149 149
 		</p>
150 150
 		<!-- Widget Component: Select Input -->
151 151
 		<p>
152
-			<label for="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>"><?php _e( 'Component:', 'woothemes-sensei' ); ?></label>
153
-			<select name="<?php echo esc_attr( $this->get_field_name( 'component' ) ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>">
154
-			<?php foreach ( $this->woo_widget_componentslist as $k => $v ) { ?>
155
-				<option value="<?php echo esc_attr( $k ); ?>"<?php selected( $instance['component'], $k ); ?>><?php echo $v; ?></option>
152
+			<label for="<?php echo esc_attr($this->get_field_id('component')); ?>"><?php _e('Component:', 'woothemes-sensei'); ?></label>
153
+			<select name="<?php echo esc_attr($this->get_field_name('component')); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('component')); ?>">
154
+			<?php foreach ($this->woo_widget_componentslist as $k => $v) { ?>
155
+				<option value="<?php echo esc_attr($k); ?>"<?php selected($instance['component'], $k); ?>><?php echo $v; ?></option>
156 156
 			<?php } ?>
157 157
 			</select>
158 158
 		</p>
159 159
 		<!-- Widget Limit: Text Input -->
160 160
 		<p>
161
-			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Courses (optional):', 'woothemes-sensei' ); ?></label>
162
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>"  value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
161
+			<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>"><?php _e('Number of Courses (optional):', 'woothemes-sensei'); ?></label>
162
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('limit')); ?>"  value="<?php echo esc_attr($instance['limit']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" />
163 163
 		</p>
164 164
 
165 165
 <?php
@@ -172,28 +172,28 @@  discard block
 block discarded – undo
172 172
 	 * @since  1.0.0
173 173
 	 * @return void
174 174
 	 */
175
-	protected function load_component ( $instance ) {
175
+	protected function load_component($instance) {
176 176
 		global  $current_user;
177 177
 
178 178
 		get_currentuserinfo();
179 179
 
180 180
 		$course_ids = array();
181
-		if ( 'activecourses' == esc_attr( $instance['component'] ) ) {
182
-			$courses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress' ), true );
181
+		if ('activecourses' == esc_attr($instance['component'])) {
182
+			$courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress'), true);
183 183
 			// Need to always return an array, even with only 1 item
184
-			if ( !is_array($courses) ) {
185
-				$courses = array( $courses );
184
+			if ( ! is_array($courses)) {
185
+				$courses = array($courses);
186 186
 			}
187
-			foreach( $courses AS $course ) {
187
+			foreach ($courses AS $course) {
188 188
 				$course_ids[] = $course->comment_post_ID;
189 189
 			}
190
-		} elseif( 'completedcourses' == esc_attr( $instance['component'] ) ) {
191
-			$courses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete' ), true );
190
+		} elseif ('completedcourses' == esc_attr($instance['component'])) {
191
+			$courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete'), true);
192 192
 			// Need to always return an array, even with only 1 item
193
-			if ( !is_array($courses) ) {
194
-				$courses = array( $courses );
193
+			if ( ! is_array($courses)) {
194
+				$courses = array($courses);
195 195
 			}
196
-			foreach( $courses AS $course ) {
196
+			foreach ($courses AS $course) {
197 197
 				$course_ids[] = $course->comment_post_ID;
198 198
 			}
199 199
 		} // End If Statement
@@ -201,19 +201,19 @@  discard block
 block discarded – undo
201 201
 		$posts_array = array();
202 202
 
203 203
 		// course_query() is buggy, it doesn't honour the 1st arg if includes are provided, so instead slice the includes
204
-		if ( !empty($instance['limit']) && intval( $instance['limit'] ) >= 1 && intval( $instance['limit'] ) < count($course_ids) ) {
204
+		if ( ! empty($instance['limit']) && intval($instance['limit']) >= 1 && intval($instance['limit']) < count($course_ids)) {
205 205
 
206
-			$course_ids = array_slice( $course_ids, 0, intval( $instance['limit'] ) ); // This does mean the order by is effectively ignored
206
+			$course_ids = array_slice($course_ids, 0, intval($instance['limit'])); // This does mean the order by is effectively ignored
207 207
 
208 208
 		}
209 209
 
210
-        if ( ! empty( $course_ids ) ) {
210
+        if ( ! empty($course_ids)) {
211 211
 
212
-            $posts_array = Sensei()->course->course_query( intval( $instance['limit'] ), esc_attr( $instance['component'] ), $course_ids );
212
+            $posts_array = Sensei()->course->course_query(intval($instance['limit']), esc_attr($instance['component']), $course_ids);
213 213
 
214 214
 		} else {
215 215
 
216
-            if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
216
+            if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) {
217 217
 				$posts_array = array();
218 218
 
219 219
             } else {
@@ -226,43 +226,43 @@  discard block
 block discarded – undo
226 226
                     'posts_per_page' => $instance['limit'],
227 227
                 );
228 228
 
229
-				$posts_array = get_posts( $course_args );
229
+				$posts_array = get_posts($course_args);
230 230
 			}
231 231
 
232 232
 		} // End If Statement
233 233
 
234
-		if ( count( $posts_array ) > 0 ) { ?>
234
+		if (count($posts_array) > 0) { ?>
235 235
 			<ul>
236
-			<?php foreach ($posts_array as $post_item){
237
-		    	$post_id = absint( $post_item->ID );
236
+			<?php foreach ($posts_array as $post_item) {
237
+		    	$post_id = absint($post_item->ID);
238 238
 		    	$post_title = $post_item->post_title;
239
-		    	$user_info = get_userdata( absint( $post_item->post_author ) );
240
-		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
239
+		    	$user_info = get_userdata(absint($post_item->post_author));
240
+		    	$author_link = get_author_posts_url(absint($post_item->post_author));
241 241
 		    	$author_display_name = $user_info->display_name;
242 242
 		    	$author_id = $post_item->post_author;
243 243
 		    ?>
244 244
 		    	<li class="fix">
245
-		    		<?php do_action( 'sensei_course_image', $post_id ); ?>
246
-		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
245
+		    		<?php do_action('sensei_course_image', $post_id); ?>
246
+		    		<a href="<?php echo esc_url(get_permalink($post_id)); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a>
247 247
 		    		<br />
248
-		    		<?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
249
-    					<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo esc_url( $author_link ); ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span>
248
+		    		<?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
249
+    					<span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo esc_url($author_link); ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
250 250
     					<br />
251 251
     				<?php } // End If Statement ?>
252
-    				<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . '&nbsp;' . __( 'Lessons', 'woothemes-sensei' ); ?></span>
252
+    				<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?></span>
253 253
     				<br />
254
-    				<?php sensei_simple_course_price( $post_id ); ?>
254
+    				<?php sensei_simple_course_price($post_id); ?>
255 255
 		    	</li>
256 256
 		    <?php } // End For Loop ?>
257
-		    <?php if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
258
-		    	$my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
259
-		    	echo '<li class="my-account fix"><a href="'. esc_url( get_permalink( $my_account_page_id ) ) .'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
257
+		    <?php if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) {
258
+		    	$my_account_page_id = intval(Sensei()->settings->settings['my_course_page']);
259
+		    	echo '<li class="my-account fix"><a href="'.esc_url(get_permalink($my_account_page_id)).'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
260 260
 		    } // End If Statement ?>
261 261
 		</ul>
262 262
 		<?php } else {
263 263
 			// No posts returned. This means the user either has no active or no completed courses.
264
-			$course_status = substr( esc_attr( $instance['component'] ) , 0, -7);
265
-			echo sprintf( __( 'You have no %1s courses.', 'woothemes-sensei' ), $course_status );
264
+			$course_status = substr(esc_attr($instance['component']), 0, -7);
265
+			echo sprintf(__('You have no %1s courses.', 'woothemes-sensei'), $course_status);
266 266
 		} // End If Statement
267 267
 	} // End load_component()
268 268
 } // End Class
269 269
\ No newline at end of file
Please login to merge, or discard this patch.
widgets/widget-woothemes-sensei-lesson-component.php 4 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -151,7 +151,6 @@
 block discarded – undo
151 151
 
152 152
 	/**
153 153
 	 * Load the desired component, if a method is available for it.
154
-	 * @param  string $component The component to potentially be loaded.
155 154
 	 * @since  5.0.8
156 155
 	 * @return void
157 156
 	 */
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param  array $instance The settings for this instance.
115 115
 	 * @return void
116 116
 	 */
117
-    public function form( $instance ) {
117
+	public function form( $instance ) {
118 118
 
119 119
 		/* Set up some default widget settings. */
120 120
 		/* Make sure all keys are added here, even with empty string values. */
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 		$post_args = array(	'post_type' 		=> 'lesson',
169 169
 							'posts_per_page' 		=> intval( $instance[ 'limit' ] ),
170 170
 							'orderby'         	=> 'menu_order date',
171
-    						'order'           	=> 'DESC',
172
-    						'post_status'       => 'publish',
171
+							'order'           	=> 'DESC',
172
+							'post_status'       => 'publish',
173 173
 							'suppress_filters' 	=> 0
174 174
 							);
175 175
 		$posts_array = get_posts( $post_args );
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 		if ( count( $posts_array ) > 0 ) { ?>
178 178
 			<ul>
179 179
 			<?php foreach ($posts_array as $post_item){
180
-		    	$post_id = absint( $post_item->ID );
181
-		    	$post_title = $post_item->post_title;
182
-		    	$user_info = get_userdata( absint( $post_item->post_author ) );
183
-		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
184
-		    	$author_display_name = $user_info->display_name;
185
-		    	$author_id = $post_item->post_author;
186
-		    	$lesson_course_id = get_post_meta( $post_id, '_lesson_course', true );
187
-		    ?>
180
+				$post_id = absint( $post_item->ID );
181
+				$post_title = $post_item->post_title;
182
+				$user_info = get_userdata( absint( $post_item->post_author ) );
183
+				$author_link = get_author_posts_url( absint( $post_item->post_author ) );
184
+				$author_display_name = $user_info->display_name;
185
+				$author_id = $post_item->post_author;
186
+				$lesson_course_id = get_post_meta( $post_id, '_lesson_course', true );
187
+			?>
188 188
 		    	<li class="fix">
189 189
 		    		<?php do_action( 'sensei_lesson_image', $post_id, '100', '100', false, true ); ?>
190 190
 		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly.
3 3
 
4 4
 /**
5 5
  * Sensei Lesson Component Widget
@@ -26,22 +26,22 @@  discard block
 block discarded – undo
26 26
 	public function __construct() {
27 27
 		/* Widget variable settings. */
28 28
 		$this->woo_widget_cssclass = 'widget_sensei_lesson_component';
29
-		$this->woo_widget_description = __( 'This widget will output a list of the latest Lessons.', 'woothemes-sensei' );
29
+		$this->woo_widget_description = __('This widget will output a list of the latest Lessons.', 'woothemes-sensei');
30 30
 		$this->woo_widget_idbase = 'sensei_lesson_component';
31
-		$this->woo_widget_title = __( 'Sensei - Lesson Component', 'woothemes-sensei' );
31
+		$this->woo_widget_title = __('Sensei - Lesson Component', 'woothemes-sensei');
32 32
 
33 33
 		$this->woo_widget_componentslist = array(
34
-												'newlessons' => __( 'New Lessons', 'woothemes-sensei' ),
34
+												'newlessons' => __('New Lessons', 'woothemes-sensei'),
35 35
 												);
36 36
 
37 37
 		/* Widget settings. */
38
-		$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
38
+		$widget_ops = array('classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description);
39 39
 
40 40
 		/* Widget control settings. */
41
-		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
41
+		$control_ops = array('width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase);
42 42
 
43 43
 		/* Create the widget. */
44
-		parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
44
+		parent::__construct($this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops);
45 45
 	} // End __construct()
46 46
 
47 47
 	/**
@@ -51,32 +51,32 @@  discard block
 block discarded – undo
51 51
 	 * @param  array $instance Widget settings for this instance.
52 52
 	 * @return void
53 53
 	 */
54
-	public function widget( $args, $instance ) {
55
-		extract( $args, EXTR_SKIP );
54
+	public function widget($args, $instance) {
55
+		extract($args, EXTR_SKIP);
56 56
 
57 57
 
58
-		if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) && ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] ) && !is_user_logged_in() ) {
58
+		if (in_array($instance['component'], array_keys($this->woo_widget_componentslist)) && ('activecourses' == $instance['component'] || 'completedcourses' == $instance['component']) && ! is_user_logged_in()) {
59 59
 			// No Output
60 60
 		} else {
61 61
 			/* Our variables from the widget settings. */
62
-			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
62
+			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
63 63
 
64 64
 			/* Before widget (defined by themes). */
65 65
 			echo $before_widget;
66 66
 
67 67
 			/* Display the widget title if one was input (before and after defined by themes). */
68
-			if ( $title ) { echo $before_title . $title . $after_title; }
68
+			if ($title) { echo $before_title.$title.$after_title; }
69 69
 
70 70
 			/* Widget content. */
71 71
 			// Add actions for plugins/themes to hook onto.
72
-			do_action( $this->woo_widget_cssclass . '_top' );
72
+			do_action($this->woo_widget_cssclass.'_top');
73 73
 
74
-			if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) ) {
75
-				$this->load_component( $instance );
74
+			if (in_array($instance['component'], array_keys($this->woo_widget_componentslist))) {
75
+				$this->load_component($instance);
76 76
 			}
77 77
 
78 78
 			// Add actions for plugins/themes to hook onto.
79
-			do_action( $this->woo_widget_cssclass . '_bottom' );
79
+			do_action($this->woo_widget_cssclass.'_bottom');
80 80
 
81 81
 			/* After widget (defined by themes). */
82 82
 			echo $after_widget;
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
 	 * @param  array $old_instance Previous settings.
92 92
 	 * @return array               Updated settings.
93 93
 	 */
94
-	public function update ( $new_instance, $old_instance ) {
94
+	public function update($new_instance, $old_instance) {
95 95
 		$instance = $old_instance;
96 96
 
97 97
 		/* Strip tags for title and name to remove HTML (important for text inputs). */
98
-		$instance['title'] = strip_tags( $new_instance['title'] );
98
+		$instance['title'] = strip_tags($new_instance['title']);
99 99
 
100 100
 		/* The select box is returning a text value, so we escape it. */
101
-		$instance['component'] = esc_attr( $new_instance['component'] );
101
+		$instance['component'] = esc_attr($new_instance['component']);
102 102
 
103 103
 		/* The select box is returning a text value, so we escape it. */
104
-		$instance['limit'] = esc_attr( $new_instance['limit'] );
104
+		$instance['limit'] = esc_attr($new_instance['limit']);
105 105
 
106 106
 
107 107
 		return $instance;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param  array $instance The settings for this instance.
115 115
 	 * @return void
116 116
 	 */
117
-    public function form( $instance ) {
117
+    public function form($instance) {
118 118
 
119 119
 		/* Set up some default widget settings. */
120 120
 		/* Make sure all keys are added here, even with empty string values. */
@@ -124,26 +124,26 @@  discard block
 block discarded – undo
124 124
 						'limit' => 3
125 125
 					);
126 126
 
127
-		$instance = wp_parse_args( (array) $instance, $defaults );
127
+		$instance = wp_parse_args((array) $instance, $defaults);
128 128
 ?>
129 129
 		<!-- Widget Title: Text Input -->
130 130
 		<p>
131
-			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
132
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"  value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
131
+			<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title (optional):', 'woothemes-sensei'); ?></label>
132
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>"  value="<?php echo esc_attr($instance['title']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" />
133 133
 		</p>
134 134
 		<!-- Widget Component: Select Input -->
135 135
 		<p>
136
-			<label for="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>"><?php _e( 'Component:', 'woothemes-sensei' ); ?></label>
137
-			<select name="<?php echo esc_attr( $this->get_field_name( 'component' ) ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>">
138
-			<?php foreach ( $this->woo_widget_componentslist as $k => $v ) { ?>
139
-				<option value="<?php echo esc_attr( $k ); ?>"<?php selected( $instance['component'], $k ); ?>><?php echo $v; ?></option>
136
+			<label for="<?php echo esc_attr($this->get_field_id('component')); ?>"><?php _e('Component:', 'woothemes-sensei'); ?></label>
137
+			<select name="<?php echo esc_attr($this->get_field_name('component')); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('component')); ?>">
138
+			<?php foreach ($this->woo_widget_componentslist as $k => $v) { ?>
139
+				<option value="<?php echo esc_attr($k); ?>"<?php selected($instance['component'], $k); ?>><?php echo $v; ?></option>
140 140
 			<?php } ?>
141 141
 			</select>
142 142
 		</p>
143 143
 		<!-- Widget Limit: Text Input -->
144 144
 		<p>
145
-			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Lessons (optional):', 'woothemes-sensei' ); ?></label>
146
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>"  value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
145
+			<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>"><?php _e('Number of Lessons (optional):', 'woothemes-sensei'); ?></label>
146
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('limit')); ?>"  value="<?php echo esc_attr($instance['limit']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" />
147 147
 		</p>
148 148
 
149 149
 <?php
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @since  5.0.8
156 156
 	 * @return void
157 157
 	 */
158
-	protected function load_component ( $instance ) {
158
+	protected function load_component($instance) {
159 159
 		global  $current_user;
160 160
 		// Get User Meta
161 161
 		get_currentuserinfo();
@@ -165,41 +165,41 @@  discard block
 block discarded – undo
165 165
 
166 166
 		$posts_array = array();
167 167
 
168
-		$post_args = array(	'post_type' 		=> 'lesson',
169
-							'posts_per_page' 		=> intval( $instance[ 'limit' ] ),
168
+		$post_args = array('post_type' 		=> 'lesson',
169
+							'posts_per_page' 		=> intval($instance['limit']),
170 170
 							'orderby'         	=> 'menu_order date',
171 171
     						'order'           	=> 'DESC',
172 172
     						'post_status'       => 'publish',
173 173
 							'suppress_filters' 	=> 0
174 174
 							);
175
-		$posts_array = get_posts( $post_args );
175
+		$posts_array = get_posts($post_args);
176 176
 
177
-		if ( count( $posts_array ) > 0 ) { ?>
177
+		if (count($posts_array) > 0) { ?>
178 178
 			<ul>
179
-			<?php foreach ($posts_array as $post_item){
180
-		    	$post_id = absint( $post_item->ID );
179
+			<?php foreach ($posts_array as $post_item) {
180
+		    	$post_id = absint($post_item->ID);
181 181
 		    	$post_title = $post_item->post_title;
182
-		    	$user_info = get_userdata( absint( $post_item->post_author ) );
183
-		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
182
+		    	$user_info = get_userdata(absint($post_item->post_author));
183
+		    	$author_link = get_author_posts_url(absint($post_item->post_author));
184 184
 		    	$author_display_name = $user_info->display_name;
185 185
 		    	$author_id = $post_item->post_author;
186
-		    	$lesson_course_id = get_post_meta( $post_id, '_lesson_course', true );
186
+		    	$lesson_course_id = get_post_meta($post_id, '_lesson_course', true);
187 187
 		    ?>
188 188
 		    	<li class="fix">
189
-		    		<?php do_action( 'sensei_lesson_image', $post_id, '100', '100', false, true ); ?>
190
-		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
189
+		    		<?php do_action('sensei_lesson_image', $post_id, '100', '100', false, true); ?>
190
+		    		<a href="<?php echo esc_url(get_permalink($post_id)); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a>
191 191
 		    		<br />
192
-		    		<?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?>
193
-    					<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo esc_url( $author_link ); ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span>
192
+		    		<?php if (isset(Sensei()->settings->settings['lesson_author']) && (Sensei()->settings->settings['lesson_author'])) { ?>
193
+    					<span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo esc_url($author_link); ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
194 194
     					<br />
195 195
     				<?php } // End If Statement ?>
196
-    				<?php if ( 0 < $lesson_course_id ) { ?>
197
-                        <span class="lesson-course"><?php echo ' ' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . esc_attr( __( 'View course', 'woothemes-sensei' ) ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span>
196
+    				<?php if (0 < $lesson_course_id) { ?>
197
+                        <span class="lesson-course"><?php echo ' '.sprintf(__('Part of: %s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($lesson_course_id)).'" title="'.esc_attr(__('View course', 'woothemes-sensei')).'"><em>'.get_the_title($lesson_course_id).'</em></a>'); ?></span>
198 198
                     <?php } ?>
199 199
     				<br />
200 200
 		    	</li>
201 201
 		    <?php } // End For Loop ?>
202
-		    <?php echo '<li class="my-account fix"><a class="button" href="'. esc_url( get_post_type_archive_link( 'lesson' ) ) .'">'.__('More Lessons', 'woothemes-sensei').'</a></li>'; ?>
202
+		    <?php echo '<li class="my-account fix"><a class="button" href="'.esc_url(get_post_type_archive_link('lesson')).'">'.__('More Lessons', 'woothemes-sensei').'</a></li>'; ?>
203 203
 		</ul>
204 204
 		<?php } // End If Statement
205 205
 	} // End load_component()
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly.
3 6
 
4 7
 /**
5 8
  * Sensei Course Component Widget
Please login to merge, or discard this patch.
uninstall.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
  * @author WooThemes
11 11
  * @since 1.0.0
12 12
  */
13
-if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit();
13
+if ( ! defined('WP_UNINSTALL_PLUGIN')) exit();
14 14
 
15 15
 $token = 'woothemes-sensei';
16
-delete_option( 'skip_install_sensei_pages' );
17
-delete_option( 'sensei_installed' );
18 16
\ No newline at end of file
17
+delete_option('skip_install_sensei_pages');
18
+delete_option('sensei_installed');
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
10 10
  * @author WooThemes
11 11
  * @since 1.0.0
12 12
  */
13
-if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit();
13
+if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14
+	exit();
15
+}
14 16
 
15 17
 $token = 'woothemes-sensei';
16 18
 delete_option( 'skip_install_sensei_pages' );
Please login to merge, or discard this patch.