@@ -14,251 +14,251 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Sensei_Teacher { |
16 | 16 | |
17 | - /** |
|
18 | - * $teacher_role |
|
19 | - * |
|
20 | - * Keeps a reference to the teacher role object |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @since 1.8.0 |
|
24 | - */ |
|
25 | - protected $teacher_role; |
|
26 | - |
|
27 | - /** |
|
28 | - * $token |
|
29 | - * |
|
30 | - * Keeps a reference to the global sensei token |
|
31 | - * |
|
32 | - * @access protected |
|
33 | - * @since 1.8.0 |
|
34 | - */ |
|
35 | - public $token; |
|
36 | - |
|
37 | - /** |
|
38 | - * Sensei_Teacher::__constructor |
|
39 | - * |
|
40 | - * Constructor Function |
|
41 | - * |
|
42 | - * @since 1.8.0 |
|
43 | - * @access public |
|
44 | - */ |
|
45 | - public function __construct ( ) { |
|
46 | - |
|
47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
52 | - |
|
53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
54 | - |
|
55 | - //filter the quiz submissions |
|
56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
57 | - |
|
58 | - //grading totals count only those belonging to the teacher |
|
59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
60 | - |
|
61 | - // show the courses owned by a user on his author archive page |
|
62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
63 | - |
|
64 | - // notify admin when a teacher creates a course |
|
65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
66 | - |
|
67 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
69 | - |
|
70 | - // give teacher access to question post type |
|
71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
72 | - |
|
73 | - // Teacher column on the courses list on the admin edit screen |
|
74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
76 | - |
|
77 | - //admin edit messages query limit teacher |
|
78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
79 | - |
|
80 | - //add filter by teacher on courses list |
|
81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
83 | - |
|
84 | - // Handle media library restrictions |
|
85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
87 | - |
|
88 | - // update lesson owner to course teacher when saved |
|
89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
90 | - |
|
91 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
93 | - |
|
94 | - |
|
95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
97 | - |
|
98 | - |
|
99 | - } // end __constructor() |
|
100 | - |
|
101 | - /** |
|
102 | - * Sensei_Teacher::create_teacher_role |
|
103 | - * |
|
104 | - * This function checks if the role exist, if not it creates it. |
|
105 | - * for the teacher role |
|
106 | - * |
|
107 | - * @since 1.8.0 |
|
108 | - * @access public |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function create_role ( ) { |
|
112 | - |
|
113 | - // check if the role exists |
|
114 | - $this->teacher_role = get_role( 'teacher' ); |
|
115 | - |
|
116 | - // if the the teacher is not a valid WordPress role create it |
|
117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
118 | - // create the role |
|
119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
120 | - } |
|
121 | - |
|
122 | - // add the capabilities before returning |
|
123 | - $this->add_capabilities(); |
|
124 | - |
|
125 | - }// end create_teacher_role |
|
126 | - |
|
127 | - /** |
|
128 | - * Sensei_Teacher::add_capabilities |
|
129 | - * |
|
130 | - * @since 1.8.0 |
|
131 | - * @access protected |
|
132 | - */ |
|
133 | - protected function add_capabilities ( ) { |
|
134 | - |
|
135 | - // if this is not a valid WP_Role object exit without adding anything |
|
136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Sensei teachers capabilities array filter |
|
142 | - * |
|
143 | - * These capabilities will be applied to the teacher role |
|
144 | - * @param array $capabilities |
|
145 | - * keys: (string) $cap_name => (bool) $grant |
|
146 | - */ |
|
147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
148 | - // General access rules |
|
149 | - 'read' => true, |
|
150 | - 'manage_sensei_grades' => true, |
|
151 | - 'moderate_comments'=> true, |
|
152 | - 'upload_files' => true, |
|
153 | - 'edit_files' => true, |
|
154 | - |
|
155 | - //Lessons |
|
156 | - 'publish_lessons' => true, |
|
157 | - 'manage_lesson_categories' => true, |
|
158 | - 'edit_lessons' => true, |
|
159 | - 'edit_published_lessons' => true, |
|
160 | - 'edit_private_lessons' => true, |
|
161 | - 'read_private_lessons' => true, |
|
162 | - 'delete_published_lessons' => true, |
|
163 | - |
|
164 | - // Courses |
|
165 | - 'create_courses' => true, |
|
166 | - 'publish_courses' => false, |
|
167 | - 'manage_course_categories' => true, |
|
168 | - 'edit_courses' => true, |
|
169 | - 'edit_published_courses' => true, |
|
170 | - 'edit_private_courses' => true, |
|
171 | - 'read_private_courses' => true, |
|
172 | - 'delete_published_courses' => true, |
|
173 | - |
|
174 | - // Quiz |
|
175 | - 'publish_quizzes' => true, |
|
176 | - 'edit_quizzes' => true, |
|
177 | - 'edit_published_quizzes' => true, |
|
178 | - 'edit_private_quizzes' => true, |
|
179 | - 'read_private_quizzes' => true, |
|
180 | - |
|
181 | - // Questions |
|
182 | - 'publish_questions' => true, |
|
183 | - 'edit_questions' => true, |
|
184 | - 'edit_published_questions' => true, |
|
185 | - 'edit_private_questions' => true, |
|
186 | - 'read_private_questions' => true, |
|
187 | - |
|
188 | - //messages |
|
189 | - 'publish_sensei_messages' => true, |
|
190 | - 'edit_sensei_messages' => true, |
|
191 | - 'edit_published_sensei_messages' => true, |
|
192 | - 'edit_private_sensei_messages' => true, |
|
193 | - 'read_private_sensei_messages' => true, |
|
194 | - |
|
195 | - // Comments - |
|
196 | - // Necessary cap so Teachers can moderate comments |
|
197 | - // on their own lessons. We restrict access to other |
|
198 | - // post types in $this->restrict_posts_menu_page() |
|
199 | - |
|
200 | - 'edit_posts' => true, |
|
201 | - |
|
202 | - )); |
|
203 | - |
|
204 | - foreach ( $caps as $cap => $grant ) { |
|
205 | - |
|
206 | - // load the capability on to the teacher role |
|
207 | - $this->teacher_role->add_cap($cap, $grant); |
|
208 | - |
|
209 | - } // end for each |
|
210 | - |
|
211 | - }// end add_cap |
|
212 | - |
|
213 | - /** |
|
214 | - * Sensei_Teacher::teacher_meta_box |
|
215 | - * |
|
216 | - * Add the teacher metabox to the course post type edit screen |
|
217 | - * |
|
218 | - * @since 1.8.0 |
|
219 | - * @access public |
|
220 | - * @parameter string $post_type |
|
221 | - * @parameter WP_Post $post |
|
222 | - * @return void |
|
223 | - */ |
|
224 | - public function add_teacher_meta_boxes ( $post ) { |
|
225 | - |
|
226 | - if( !current_user_can('manage_options') ){ |
|
227 | - return; |
|
228 | - } |
|
229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
230 | - 'course', |
|
231 | - 'side', |
|
232 | - 'core' |
|
233 | - ); |
|
234 | - |
|
235 | - } // end teacher_meta_box() |
|
236 | - |
|
237 | - /** |
|
238 | - * Sensei_Teacher::teacher_meta_box_content |
|
239 | - * |
|
240 | - * Render the teacher meta box markup |
|
241 | - * |
|
242 | - * @since 1.8.0 |
|
243 | - * @access public |
|
244 | - * @parameters |
|
245 | - */ |
|
246 | - public function teacher_meta_box_content ( $post ) { |
|
247 | - |
|
248 | - // get the current author |
|
249 | - $current_author = $post->post_author; |
|
250 | - |
|
251 | - //get the users authorised to author courses |
|
252 | - $users = $this->get_teachers_and_authors(); |
|
253 | - |
|
254 | - ?> |
|
17 | + /** |
|
18 | + * $teacher_role |
|
19 | + * |
|
20 | + * Keeps a reference to the teacher role object |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @since 1.8.0 |
|
24 | + */ |
|
25 | + protected $teacher_role; |
|
26 | + |
|
27 | + /** |
|
28 | + * $token |
|
29 | + * |
|
30 | + * Keeps a reference to the global sensei token |
|
31 | + * |
|
32 | + * @access protected |
|
33 | + * @since 1.8.0 |
|
34 | + */ |
|
35 | + public $token; |
|
36 | + |
|
37 | + /** |
|
38 | + * Sensei_Teacher::__constructor |
|
39 | + * |
|
40 | + * Constructor Function |
|
41 | + * |
|
42 | + * @since 1.8.0 |
|
43 | + * @access public |
|
44 | + */ |
|
45 | + public function __construct ( ) { |
|
46 | + |
|
47 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
48 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
49 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
50 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
51 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
52 | + |
|
53 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
54 | + |
|
55 | + //filter the quiz submissions |
|
56 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
57 | + |
|
58 | + //grading totals count only those belonging to the teacher |
|
59 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
60 | + |
|
61 | + // show the courses owned by a user on his author archive page |
|
62 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
63 | + |
|
64 | + // notify admin when a teacher creates a course |
|
65 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
66 | + |
|
67 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
68 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
69 | + |
|
70 | + // give teacher access to question post type |
|
71 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
72 | + |
|
73 | + // Teacher column on the courses list on the admin edit screen |
|
74 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
75 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
76 | + |
|
77 | + //admin edit messages query limit teacher |
|
78 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
79 | + |
|
80 | + //add filter by teacher on courses list |
|
81 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
82 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
83 | + |
|
84 | + // Handle media library restrictions |
|
85 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
86 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
87 | + |
|
88 | + // update lesson owner to course teacher when saved |
|
89 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
90 | + |
|
91 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
92 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
93 | + |
|
94 | + |
|
95 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
96 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
97 | + |
|
98 | + |
|
99 | + } // end __constructor() |
|
100 | + |
|
101 | + /** |
|
102 | + * Sensei_Teacher::create_teacher_role |
|
103 | + * |
|
104 | + * This function checks if the role exist, if not it creates it. |
|
105 | + * for the teacher role |
|
106 | + * |
|
107 | + * @since 1.8.0 |
|
108 | + * @access public |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function create_role ( ) { |
|
112 | + |
|
113 | + // check if the role exists |
|
114 | + $this->teacher_role = get_role( 'teacher' ); |
|
115 | + |
|
116 | + // if the the teacher is not a valid WordPress role create it |
|
117 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
118 | + // create the role |
|
119 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
120 | + } |
|
121 | + |
|
122 | + // add the capabilities before returning |
|
123 | + $this->add_capabilities(); |
|
124 | + |
|
125 | + }// end create_teacher_role |
|
126 | + |
|
127 | + /** |
|
128 | + * Sensei_Teacher::add_capabilities |
|
129 | + * |
|
130 | + * @since 1.8.0 |
|
131 | + * @access protected |
|
132 | + */ |
|
133 | + protected function add_capabilities ( ) { |
|
134 | + |
|
135 | + // if this is not a valid WP_Role object exit without adding anything |
|
136 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
137 | + return; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Sensei teachers capabilities array filter |
|
142 | + * |
|
143 | + * These capabilities will be applied to the teacher role |
|
144 | + * @param array $capabilities |
|
145 | + * keys: (string) $cap_name => (bool) $grant |
|
146 | + */ |
|
147 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
148 | + // General access rules |
|
149 | + 'read' => true, |
|
150 | + 'manage_sensei_grades' => true, |
|
151 | + 'moderate_comments'=> true, |
|
152 | + 'upload_files' => true, |
|
153 | + 'edit_files' => true, |
|
154 | + |
|
155 | + //Lessons |
|
156 | + 'publish_lessons' => true, |
|
157 | + 'manage_lesson_categories' => true, |
|
158 | + 'edit_lessons' => true, |
|
159 | + 'edit_published_lessons' => true, |
|
160 | + 'edit_private_lessons' => true, |
|
161 | + 'read_private_lessons' => true, |
|
162 | + 'delete_published_lessons' => true, |
|
163 | + |
|
164 | + // Courses |
|
165 | + 'create_courses' => true, |
|
166 | + 'publish_courses' => false, |
|
167 | + 'manage_course_categories' => true, |
|
168 | + 'edit_courses' => true, |
|
169 | + 'edit_published_courses' => true, |
|
170 | + 'edit_private_courses' => true, |
|
171 | + 'read_private_courses' => true, |
|
172 | + 'delete_published_courses' => true, |
|
173 | + |
|
174 | + // Quiz |
|
175 | + 'publish_quizzes' => true, |
|
176 | + 'edit_quizzes' => true, |
|
177 | + 'edit_published_quizzes' => true, |
|
178 | + 'edit_private_quizzes' => true, |
|
179 | + 'read_private_quizzes' => true, |
|
180 | + |
|
181 | + // Questions |
|
182 | + 'publish_questions' => true, |
|
183 | + 'edit_questions' => true, |
|
184 | + 'edit_published_questions' => true, |
|
185 | + 'edit_private_questions' => true, |
|
186 | + 'read_private_questions' => true, |
|
187 | + |
|
188 | + //messages |
|
189 | + 'publish_sensei_messages' => true, |
|
190 | + 'edit_sensei_messages' => true, |
|
191 | + 'edit_published_sensei_messages' => true, |
|
192 | + 'edit_private_sensei_messages' => true, |
|
193 | + 'read_private_sensei_messages' => true, |
|
194 | + |
|
195 | + // Comments - |
|
196 | + // Necessary cap so Teachers can moderate comments |
|
197 | + // on their own lessons. We restrict access to other |
|
198 | + // post types in $this->restrict_posts_menu_page() |
|
199 | + |
|
200 | + 'edit_posts' => true, |
|
201 | + |
|
202 | + )); |
|
203 | + |
|
204 | + foreach ( $caps as $cap => $grant ) { |
|
205 | + |
|
206 | + // load the capability on to the teacher role |
|
207 | + $this->teacher_role->add_cap($cap, $grant); |
|
208 | + |
|
209 | + } // end for each |
|
210 | + |
|
211 | + }// end add_cap |
|
212 | + |
|
213 | + /** |
|
214 | + * Sensei_Teacher::teacher_meta_box |
|
215 | + * |
|
216 | + * Add the teacher metabox to the course post type edit screen |
|
217 | + * |
|
218 | + * @since 1.8.0 |
|
219 | + * @access public |
|
220 | + * @parameter string $post_type |
|
221 | + * @parameter WP_Post $post |
|
222 | + * @return void |
|
223 | + */ |
|
224 | + public function add_teacher_meta_boxes ( $post ) { |
|
225 | + |
|
226 | + if( !current_user_can('manage_options') ){ |
|
227 | + return; |
|
228 | + } |
|
229 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
230 | + 'course', |
|
231 | + 'side', |
|
232 | + 'core' |
|
233 | + ); |
|
234 | + |
|
235 | + } // end teacher_meta_box() |
|
236 | + |
|
237 | + /** |
|
238 | + * Sensei_Teacher::teacher_meta_box_content |
|
239 | + * |
|
240 | + * Render the teacher meta box markup |
|
241 | + * |
|
242 | + * @since 1.8.0 |
|
243 | + * @access public |
|
244 | + * @parameters |
|
245 | + */ |
|
246 | + public function teacher_meta_box_content ( $post ) { |
|
247 | + |
|
248 | + // get the current author |
|
249 | + $current_author = $post->post_author; |
|
250 | + |
|
251 | + //get the users authorised to author courses |
|
252 | + $users = $this->get_teachers_and_authors(); |
|
253 | + |
|
254 | + ?> |
|
255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
256 | 256 | |
257 | 257 | <?php foreach ( $users as $user_id ) { ?> |
258 | 258 | |
259 | 259 | <?php |
260 | - $user = get_user_by('id', $user_id); |
|
261 | - ?> |
|
260 | + $user = get_user_by('id', $user_id); |
|
261 | + ?> |
|
262 | 262 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
263 | 263 | <?php echo $user->display_name; ?> |
264 | 264 | </option> |
@@ -269,1289 +269,1289 @@ discard block |
||
269 | 269 | |
270 | 270 | <?php |
271 | 271 | |
272 | - } // end render_teacher_meta_box() |
|
273 | - |
|
274 | - /** |
|
275 | - * Sensei_Teacher::get_teachers_and_authors |
|
276 | - * |
|
277 | - * Get a list of users who can author courses, lessons and quizes. |
|
278 | - * |
|
279 | - * @since 1.8.0 |
|
280 | - * @access public |
|
281 | - * @parameters |
|
282 | - * @return array $users user id array |
|
283 | - */ |
|
284 | - public function get_teachers_and_authors ( ){ |
|
285 | - |
|
286 | - $author_query_args = array( |
|
287 | - 'blog_id' => $GLOBALS['blog_id'], |
|
288 | - 'fields' => 'any', |
|
289 | - 'who' => 'authors' |
|
290 | - ); |
|
291 | - |
|
292 | - $authors = get_users( $author_query_args ); |
|
293 | - |
|
294 | - $teacher_query_args = array( |
|
295 | - 'blog_id' => $GLOBALS['blog_id'], |
|
296 | - 'fields' => 'any', |
|
297 | - 'role' => 'teacher', |
|
298 | - ); |
|
299 | - |
|
300 | - $teachers = get_users( $teacher_query_args ); |
|
301 | - |
|
302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
303 | - |
|
304 | - }// end get_teachers_and_authors |
|
305 | - |
|
306 | - /** |
|
307 | - * Sensei_Teacher::save_teacher_meta_box |
|
308 | - * |
|
309 | - * Save the new teacher / author to course and all lessons |
|
310 | - * |
|
311 | - * Hooked into admin_init |
|
312 | - * |
|
313 | - * @since 1.8.0 |
|
314 | - * @access public |
|
315 | - * @parameters |
|
316 | - * @return array $users user id array |
|
317 | - */ |
|
318 | - public function save_teacher_meta_box ( $course_id ){ |
|
272 | + } // end render_teacher_meta_box() |
|
273 | + |
|
274 | + /** |
|
275 | + * Sensei_Teacher::get_teachers_and_authors |
|
276 | + * |
|
277 | + * Get a list of users who can author courses, lessons and quizes. |
|
278 | + * |
|
279 | + * @since 1.8.0 |
|
280 | + * @access public |
|
281 | + * @parameters |
|
282 | + * @return array $users user id array |
|
283 | + */ |
|
284 | + public function get_teachers_and_authors ( ){ |
|
285 | + |
|
286 | + $author_query_args = array( |
|
287 | + 'blog_id' => $GLOBALS['blog_id'], |
|
288 | + 'fields' => 'any', |
|
289 | + 'who' => 'authors' |
|
290 | + ); |
|
291 | + |
|
292 | + $authors = get_users( $author_query_args ); |
|
293 | + |
|
294 | + $teacher_query_args = array( |
|
295 | + 'blog_id' => $GLOBALS['blog_id'], |
|
296 | + 'fields' => 'any', |
|
297 | + 'role' => 'teacher', |
|
298 | + ); |
|
299 | + |
|
300 | + $teachers = get_users( $teacher_query_args ); |
|
301 | + |
|
302 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
303 | + |
|
304 | + }// end get_teachers_and_authors |
|
305 | + |
|
306 | + /** |
|
307 | + * Sensei_Teacher::save_teacher_meta_box |
|
308 | + * |
|
309 | + * Save the new teacher / author to course and all lessons |
|
310 | + * |
|
311 | + * Hooked into admin_init |
|
312 | + * |
|
313 | + * @since 1.8.0 |
|
314 | + * @access public |
|
315 | + * @parameters |
|
316 | + * @return array $users user id array |
|
317 | + */ |
|
318 | + public function save_teacher_meta_box ( $course_id ){ |
|
319 | 319 | |
320 | - // check if this is a post from saving the teacher, if not exit early |
|
321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
322 | - return; |
|
323 | - } |
|
320 | + // check if this is a post from saving the teacher, if not exit early |
|
321 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
322 | + return; |
|
323 | + } |
|
324 | 324 | |
325 | - //don't fire this hook again |
|
326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
325 | + //don't fire this hook again |
|
326 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
327 | 327 | |
328 | - // get the current post object |
|
329 | - $post = get_post( $course_id ); |
|
328 | + // get the current post object |
|
329 | + $post = get_post( $course_id ); |
|
330 | 330 | |
331 | - // get the current teacher/author |
|
332 | - $current_author = absint( $post->post_author ); |
|
333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
331 | + // get the current teacher/author |
|
332 | + $current_author = absint( $post->post_author ); |
|
333 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
334 | 334 | |
335 | - // loop through all post lessons to update their authors as well |
|
336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
335 | + // loop through all post lessons to update their authors as well |
|
336 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
337 | 337 | |
338 | - // do not do any processing if the selected author is the same as the current author |
|
339 | - if( $current_author == $new_author ){ |
|
340 | - return; |
|
341 | - } |
|
338 | + // do not do any processing if the selected author is the same as the current author |
|
339 | + if( $current_author == $new_author ){ |
|
340 | + return; |
|
341 | + } |
|
342 | 342 | |
343 | - // save the course author |
|
344 | - $post_updates = array( |
|
345 | - 'ID' => $post->ID , |
|
346 | - 'post_author' => $new_author |
|
347 | - ); |
|
348 | - wp_update_post( $post_updates ); |
|
343 | + // save the course author |
|
344 | + $post_updates = array( |
|
345 | + 'ID' => $post->ID , |
|
346 | + 'post_author' => $new_author |
|
347 | + ); |
|
348 | + wp_update_post( $post_updates ); |
|
349 | 349 | |
350 | - // ensure the the modules are update so that then new teacher has access to them |
|
351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
350 | + // ensure the the modules are update so that then new teacher has access to them |
|
351 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
352 | 352 | |
353 | - // notify the new teacher |
|
354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
353 | + // notify the new teacher |
|
354 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
355 | 355 | |
356 | - } // end save_teacher_meta_box |
|
356 | + } // end save_teacher_meta_box |
|
357 | 357 | |
358 | - /** |
|
359 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
360 | - * the new author. Making sure the course terms are maintained. |
|
361 | - * |
|
362 | - * This function also checks if terms are shared, with other courses |
|
363 | - * |
|
364 | - * @param $course_id |
|
365 | - * @param $new_teacher_id |
|
366 | - * @return void |
|
367 | - */ |
|
368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
358 | + /** |
|
359 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
360 | + * the new author. Making sure the course terms are maintained. |
|
361 | + * |
|
362 | + * This function also checks if terms are shared, with other courses |
|
363 | + * |
|
364 | + * @param $course_id |
|
365 | + * @param $new_teacher_id |
|
366 | + * @return void |
|
367 | + */ |
|
368 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
369 | 369 | |
370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
371 | - return false; |
|
372 | - } |
|
370 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
371 | + return false; |
|
372 | + } |
|
373 | 373 | |
374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
374 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
375 | 375 | |
376 | - if( empty( $terms_selected_on_course ) ){ |
|
377 | - return; |
|
378 | - } |
|
376 | + if( empty( $terms_selected_on_course ) ){ |
|
377 | + return; |
|
378 | + } |
|
379 | 379 | |
380 | - foreach( $terms_selected_on_course as $term ){ |
|
380 | + foreach( $terms_selected_on_course as $term ){ |
|
381 | 381 | |
382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
383 | - if( $new_teacher_id != $term_author->ID ){ |
|
382 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
383 | + if( $new_teacher_id != $term_author->ID ){ |
|
384 | 384 | |
385 | - $new_term = ''; |
|
385 | + $new_term = ''; |
|
386 | 386 | |
387 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
387 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
388 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
389 | 389 | |
390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
393 | - if( !empty( $existing_admin_terms ) ){ |
|
394 | - // insert it even if it exists |
|
395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
396 | - } |
|
397 | - } |
|
390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
391 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
392 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
393 | + if( !empty( $existing_admin_terms ) ){ |
|
394 | + // insert it even if it exists |
|
395 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
396 | + } |
|
397 | + } |
|
398 | 398 | |
399 | - if( empty ( $new_term ) ){ |
|
399 | + if( empty ( $new_term ) ){ |
|
400 | 400 | |
401 | - //setup the new slug |
|
402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
403 | - |
|
404 | - // create new term and set it |
|
405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
406 | - |
|
407 | - } |
|
401 | + //setup the new slug |
|
402 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
403 | + |
|
404 | + // create new term and set it |
|
405 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
406 | + |
|
407 | + } |
|
408 | 408 | |
409 | 409 | |
410 | 410 | |
411 | - // if term exists |
|
412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
411 | + // if term exists |
|
412 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
413 | 413 | |
414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
415 | - $term_id = $existing_term->term_id; |
|
414 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
415 | + $term_id = $existing_term->term_id; |
|
416 | 416 | |
417 | - }else{ |
|
417 | + }else{ |
|
418 | 418 | |
419 | - // for a new term simply get the term from the returned value |
|
420 | - $term_id = $new_term['term_id']; |
|
419 | + // for a new term simply get the term from the returned value |
|
420 | + $term_id = $new_term['term_id']; |
|
421 | 421 | |
422 | - } // end if term exist |
|
422 | + } // end if term exist |
|
423 | 423 | |
424 | - // set the terms selected on the course |
|
425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
424 | + // set the terms selected on the course |
|
425 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
426 | 426 | |
427 | - // remove old term |
|
428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
427 | + // remove old term |
|
428 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
429 | 429 | |
430 | - // update the lessons within the current module term |
|
431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
432 | - foreach( $lessons as $lesson ){ |
|
430 | + // update the lessons within the current module term |
|
431 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
432 | + foreach( $lessons as $lesson ){ |
|
433 | 433 | |
434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
434 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
435 | 435 | |
436 | - // add the new term, the false at the end says to replace all terms on this module |
|
437 | - // with the new term. |
|
438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
440 | - } |
|
436 | + // add the new term, the false at the end says to replace all terms on this module |
|
437 | + // with the new term. |
|
438 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
439 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
440 | + } |
|
441 | 441 | |
442 | - }// end for each |
|
442 | + }// end for each |
|
443 | 443 | |
444 | - } |
|
445 | - } |
|
444 | + } |
|
445 | + } |
|
446 | 446 | |
447 | - }// end update_course_module_terms_author |
|
447 | + }// end update_course_module_terms_author |
|
448 | 448 | |
449 | - /** |
|
450 | - * Sensei_Teacher::update_course_lessons_author |
|
451 | - * |
|
452 | - * Update all course lessons and their quiz with a new author |
|
453 | - * |
|
454 | - * @since 1.8.0 |
|
455 | - * @access public |
|
456 | - * @parameters |
|
457 | - * @return array $users user id array |
|
458 | - */ |
|
459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
449 | + /** |
|
450 | + * Sensei_Teacher::update_course_lessons_author |
|
451 | + * |
|
452 | + * Update all course lessons and their quiz with a new author |
|
453 | + * |
|
454 | + * @since 1.8.0 |
|
455 | + * @access public |
|
456 | + * @parameters |
|
457 | + * @return array $users user id array |
|
458 | + */ |
|
459 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
460 | 460 | |
461 | 461 | |
462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
463 | - return false; |
|
464 | - } |
|
462 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
463 | + return false; |
|
464 | + } |
|
465 | 465 | |
466 | - //get a list of course lessons |
|
467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
466 | + //get a list of course lessons |
|
467 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
468 | 468 | |
469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
470 | - return false; |
|
471 | - } |
|
469 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
470 | + return false; |
|
471 | + } |
|
472 | 472 | |
473 | - // update each lesson and quiz author |
|
474 | - foreach( $lessons as $lesson ){ |
|
473 | + // update each lesson and quiz author |
|
474 | + foreach( $lessons as $lesson ){ |
|
475 | 475 | |
476 | - // don't update if the author is tha same as the new author |
|
477 | - if( $new_author == $lesson->post_author ){ |
|
478 | - continue; |
|
479 | - } |
|
476 | + // don't update if the author is tha same as the new author |
|
477 | + if( $new_author == $lesson->post_author ){ |
|
478 | + continue; |
|
479 | + } |
|
480 | 480 | |
481 | - // update lesson author |
|
482 | - wp_update_post( array( |
|
483 | - 'ID'=> $lesson->ID, |
|
484 | - 'post_author' => $new_author |
|
485 | - ) ); |
|
481 | + // update lesson author |
|
482 | + wp_update_post( array( |
|
483 | + 'ID'=> $lesson->ID, |
|
484 | + 'post_author' => $new_author |
|
485 | + ) ); |
|
486 | 486 | |
487 | - // update quiz author |
|
488 | - //get the lessons quiz |
|
489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
490 | - if( is_array( $lesson_quizzes ) ){ |
|
491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
492 | - // update quiz with new author |
|
493 | - wp_update_post( array( |
|
494 | - 'ID' => $quiz_id, |
|
495 | - 'post_author' => $new_author |
|
496 | - ) ); |
|
497 | - } |
|
498 | - }else{ |
|
499 | - wp_update_post( array( |
|
500 | - 'ID' => $lesson_quizzes, |
|
501 | - 'post_author' => $new_author |
|
502 | - ) ); |
|
503 | - } |
|
487 | + // update quiz author |
|
488 | + //get the lessons quiz |
|
489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
490 | + if( is_array( $lesson_quizzes ) ){ |
|
491 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
492 | + // update quiz with new author |
|
493 | + wp_update_post( array( |
|
494 | + 'ID' => $quiz_id, |
|
495 | + 'post_author' => $new_author |
|
496 | + ) ); |
|
497 | + } |
|
498 | + }else{ |
|
499 | + wp_update_post( array( |
|
500 | + 'ID' => $lesson_quizzes, |
|
501 | + 'post_author' => $new_author |
|
502 | + ) ); |
|
503 | + } |
|
504 | 504 | |
505 | - } // end for each lessons |
|
505 | + } // end for each lessons |
|
506 | 506 | |
507 | - return true; |
|
507 | + return true; |
|
508 | 508 | |
509 | - }// end update_course_lessons_author |
|
510 | - |
|
511 | - |
|
512 | - |
|
513 | - /** |
|
514 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
515 | - * |
|
516 | - * Alter the query so that users can only see their courses on the analysis page |
|
517 | - * |
|
518 | - * @since 1.8.0 |
|
519 | - * @access public |
|
520 | - * @parameters $query |
|
521 | - * @return array $users user id array |
|
522 | - */ |
|
523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
524 | - |
|
525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
526 | - return $query; |
|
527 | - } |
|
528 | - |
|
529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
530 | - return $query; |
|
531 | - } |
|
532 | - |
|
533 | - $screen = get_current_screen(); |
|
534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
535 | - |
|
536 | - // exit early for the following conditions |
|
537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
538 | - |
|
539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
541 | - return $query; |
|
542 | - } |
|
543 | - |
|
544 | - global $current_user; |
|
545 | - // set the query author to the current user to only show those those posts |
|
546 | - $query->set( 'author', $current_user->ID ); |
|
547 | - return $query; |
|
548 | - |
|
549 | - }// end course_analysis_teacher_access_limit |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
554 | - * |
|
555 | - * Determine if we're in admin and the current logged in use is a teacher |
|
556 | - * |
|
557 | - * @since 1.8.0 |
|
558 | - * @access public |
|
559 | - * @parameters array $wp_query |
|
560 | - * @return bool $is_admin_teacher |
|
561 | - */ |
|
562 | - public function is_admin_teacher ( ){ |
|
563 | - |
|
564 | - if( ! is_user_logged_in()){ |
|
565 | - return false; |
|
566 | - } |
|
567 | - $is_admin_teacher = false; |
|
568 | - |
|
569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
570 | - |
|
571 | - $is_admin_teacher = true; |
|
572 | - |
|
573 | - } |
|
574 | - |
|
575 | - return $is_admin_teacher; |
|
576 | - |
|
577 | - } // end is_admin_teacher |
|
578 | - |
|
579 | - /** |
|
580 | - * Show correct post counts on list table for Sensei post types |
|
581 | - * |
|
582 | - * @since 1.8.0 |
|
583 | - * |
|
584 | - * @param object $counts Default status counts |
|
585 | - * @param string $type Current post type |
|
586 | - * @param string $perm User permission level |
|
587 | - * @return object Modified status counts |
|
588 | - */ |
|
589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
590 | - global $current_user; |
|
591 | - |
|
592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
593 | - return $counts; |
|
594 | - } |
|
595 | - |
|
596 | - if( ! $this->is_admin_teacher() ) { |
|
597 | - return $counts; |
|
598 | - } |
|
599 | - |
|
600 | - $args = array( |
|
601 | - 'post_type' => $type, |
|
602 | - 'author' => $current_user->ID, |
|
603 | - 'posts_per_page' => -1 |
|
604 | - ); |
|
605 | - |
|
606 | - // Get all available statuses |
|
607 | - $stati = get_post_stati(); |
|
608 | - |
|
609 | - // Update count object |
|
610 | - foreach( $stati as $status ) { |
|
611 | - $args['post_status'] = $status; |
|
612 | - $posts = get_posts( $args ); |
|
613 | - $counts->$status = count( $posts ); |
|
614 | - } |
|
615 | - |
|
616 | - return $counts; |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Filter the post queries to show |
|
621 | - * only lesson /course and users that belong |
|
622 | - * to the current logged teacher. |
|
623 | - * |
|
624 | - * @since 1.8.0 |
|
625 | - * |
|
626 | - */ |
|
627 | - public function filter_queries ( $query ) { |
|
628 | - global $current_user; |
|
629 | - |
|
630 | - if( ! $this->is_admin_teacher() ) { |
|
631 | - return; |
|
632 | - } |
|
633 | - |
|
634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
635 | - return; |
|
636 | - } |
|
637 | - |
|
638 | - $screen = get_current_screen(); |
|
639 | - if( empty( $screen ) ) { |
|
640 | - return $query; |
|
641 | - } |
|
642 | - switch( $screen->id ) { |
|
643 | - case 'sensei_page_sensei_grading': |
|
644 | - case 'sensei_page_sensei_analysis': |
|
645 | - case 'sensei_page_sensei_learners': |
|
646 | - case 'lesson': |
|
647 | - case 'course': |
|
648 | - case 'question': |
|
649 | - case 'lesson_page_module-order': |
|
650 | - |
|
651 | - /** |
|
652 | - * sensei_filter_queries_set_author |
|
653 | - * Filter the author Sensei set for queries |
|
654 | - * |
|
655 | - * @since 1.8.0 |
|
656 | - * |
|
657 | - * @param int $user_id |
|
658 | - * @param string $screen_id |
|
659 | - * |
|
660 | - */ |
|
661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
662 | - break; |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
668 | - * . This excludes the admin user. |
|
669 | - * |
|
670 | - * @since 1.8.0 |
|
671 | - * @hooked into the_comments |
|
672 | - * @param array $comments |
|
673 | - * |
|
674 | - * @return array $comments |
|
675 | - */ |
|
676 | - public function filter_grading_activity_queries( $comments ){ |
|
677 | - |
|
678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
679 | - return $comments ; |
|
680 | - } |
|
681 | - |
|
682 | - //check if we're on the grading screen |
|
683 | - $screen = get_current_screen(); |
|
684 | - |
|
685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
686 | - return $comments; |
|
687 | - } |
|
688 | - |
|
689 | - // get the course and determine if the current teacher is the owner |
|
690 | - // if not remove it from the list of comments to be returned |
|
691 | - foreach( $comments as $key => $comment){ |
|
692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
694 | - $course = get_post( $course_id ); |
|
695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
696 | - //remove this as the teacher should see this. |
|
697 | - unset( $comments[ $key ] ); |
|
698 | - } |
|
699 | - } |
|
700 | - return $comments ; |
|
701 | - |
|
702 | - }// end function filter grading |
|
703 | - |
|
704 | - /** |
|
705 | - * Limit the grading screen totals to only show lessons in the course |
|
706 | - * belonging to the currently logged in teacher. This only applies to |
|
707 | - * the teacher role. |
|
708 | - * |
|
709 | - * @since 1.8.0 |
|
710 | - * |
|
711 | - * @hooked into sensei_count_statuses_args |
|
712 | - * @param array $args |
|
713 | - * |
|
714 | - * @return array $args |
|
715 | - */ |
|
716 | - public function limit_grading_totals( $args ){ |
|
717 | - |
|
718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
719 | - return $args ; |
|
720 | - } |
|
721 | - |
|
722 | - //get the teachers courses |
|
723 | - // the query is already filtered to only the teacher |
|
724 | - $courses = Sensei()->course->get_all_courses(); |
|
725 | - |
|
726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
727 | - return $args; |
|
728 | - } |
|
729 | - |
|
730 | - //setup the lessons quizzes to limit the grading totals to |
|
731 | - $quiz_scope = array(); |
|
732 | - foreach( $courses as $course ){ |
|
733 | - |
|
734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
735 | - |
|
736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
737 | - |
|
738 | - foreach( $course_lessons as $lesson ){ |
|
739 | - |
|
740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
741 | - if( !empty( $quiz_id ) ) { |
|
742 | - |
|
743 | - array_push( $quiz_scope, $quiz_id ); |
|
744 | - |
|
745 | - } |
|
746 | - |
|
747 | - } |
|
748 | - |
|
749 | - } |
|
750 | - |
|
751 | - } |
|
752 | - |
|
753 | - $args['post__in'] = $quiz_scope; |
|
754 | - |
|
755 | - return $args; |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * It ensures that the author archive shows course by the current user. |
|
760 | - * |
|
761 | - * This function is hooked into the pre_get_posts filter |
|
762 | - * |
|
763 | - * @param WP_Query $query |
|
764 | - * @return WP_Query $query |
|
765 | - */ |
|
766 | - public function add_courses_to_author_archive( $query ) { |
|
767 | - |
|
768 | - if ( is_admin() || ! $query->is_author() ){ |
|
769 | - return $query; |
|
770 | - } |
|
771 | - |
|
772 | - // this should only apply to users with the teacher role |
|
773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
775 | - |
|
776 | - return $query; |
|
777 | - |
|
778 | - } |
|
779 | - |
|
780 | - // Change post types depending on what is set already |
|
781 | - $current_post_types = $query->get( 'post_type' ); |
|
782 | - if( empty( $current_post_types ) ){ |
|
783 | - |
|
784 | - // if empty it means post by default, so add post so that it also includes that for now |
|
785 | - $new_post_types = array( 'post', 'course' ); |
|
786 | - |
|
787 | - } elseif( is_array( $current_post_types ) ) { |
|
788 | - |
|
789 | - // merge the post types instead of overwriting it |
|
790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
791 | - |
|
792 | - }else{ |
|
793 | - |
|
794 | - // in this instance it is probably just one post type in string format |
|
795 | - $new_post_types = array( $current_post_types , 'course'); |
|
796 | - |
|
797 | - } |
|
798 | - |
|
799 | - // change the query before returning it |
|
800 | - $query->set('post_type', $new_post_types ); |
|
801 | - |
|
802 | - /** |
|
803 | - * Change the query on the teacher author archive template |
|
804 | - * |
|
805 | - * @since 1.8.4 |
|
806 | - * @param WP_Query $query |
|
807 | - */ |
|
808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
809 | - |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * Notify teacher when someone assigns a course to their account. |
|
814 | - * |
|
815 | - * @since 1.8.0 |
|
816 | - * |
|
817 | - * @param $teacher_id |
|
818 | - * @param $course_id |
|
819 | - * @return bool |
|
820 | - */ |
|
821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
822 | - |
|
823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
824 | - return false; |
|
825 | - } |
|
826 | - |
|
827 | - // if new user is the same as the current logged user, they don't need an email |
|
828 | - if( $teacher_id == get_current_user_id() ){ |
|
829 | - return true; |
|
830 | - } |
|
831 | - |
|
832 | - // load the email class |
|
833 | - include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
834 | - $email = new Teacher_New_Course_Assignment(); |
|
835 | - $email->trigger( $teacher_id, $course_id ); |
|
836 | - |
|
837 | - return true; |
|
838 | - } // end teacher_course_assigned_notification |
|
839 | - |
|
840 | - /** |
|
841 | - * Email the admin when a teacher creates a new course |
|
842 | - * |
|
843 | - * This function hooks into wp_insert_post |
|
844 | - * |
|
845 | - * @since 1.8.0 |
|
846 | - * @param int $course_id |
|
847 | - * @return bool |
|
848 | - */ |
|
849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
850 | - |
|
851 | - $course_id = $post->ID; |
|
852 | - |
|
853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
855 | - |
|
856 | - return false; |
|
857 | - |
|
858 | - } |
|
859 | - |
|
860 | - /** |
|
861 | - * Filter the option to send admin notification emails when teachers creation |
|
862 | - * course. |
|
863 | - * |
|
864 | - * @since 1.8.0 |
|
865 | - * |
|
866 | - * @param bool $on default true |
|
867 | - */ |
|
868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
869 | - return false; |
|
870 | - } |
|
871 | - |
|
872 | - // setting up the data needed by the email template |
|
873 | - global $sensei_email_data; |
|
874 | - $template = 'admin-teacher-new-course-created'; |
|
875 | - $course = get_post( $course_id ); |
|
876 | - $teacher = new WP_User( $course->post_author ); |
|
877 | - $recipient = get_option('admin_email', true); |
|
878 | - |
|
879 | - // don't send if the course is created by admin |
|
880 | - if( $recipient == $teacher->user_email ){ |
|
881 | - return; |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
886 | - * |
|
887 | - * @since 1.8.0 |
|
888 | - * @param string $template |
|
889 | - */ |
|
890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
891 | - |
|
892 | - /** |
|
893 | - * Filter the email subject for the the |
|
894 | - * admin-teacher-new-course-created template |
|
895 | - * |
|
896 | - * @since 1.8.0 |
|
897 | - * @param string $subject default New course assigned to you |
|
898 | - * @param string $template |
|
899 | - */ |
|
900 | - $subject = apply_filters('sensei_email_subject', |
|
901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
902 | - $template ); |
|
903 | - |
|
904 | - //course edit link |
|
905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
906 | - |
|
907 | - // Construct data array |
|
908 | - $email_data = array( |
|
909 | - 'template' => $template, |
|
910 | - 'heading' => $heading, |
|
911 | - 'teacher' => $teacher, |
|
912 | - 'course_id' => $course_id, |
|
913 | - 'course_name' => $course->post_title, |
|
914 | - 'course_edit_link' => $course_edit_link, |
|
915 | - ); |
|
916 | - |
|
917 | - /** |
|
918 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
919 | - * |
|
920 | - * @since 1.8.0 |
|
921 | - * @param array $email_data |
|
922 | - * @param string $template |
|
923 | - */ |
|
924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
925 | - |
|
926 | - // Send mail |
|
927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
928 | - |
|
929 | - }// end notify admin of course creation |
|
930 | - |
|
931 | - /** |
|
932 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
933 | - * |
|
934 | - * Hooked into sensei_analysis_get_learners |
|
935 | - * @param array $args WP_User_Query arguments |
|
936 | - * @return array $learners_query_results |
|
937 | - */ |
|
938 | - public function limit_analysis_learners( $args ){ |
|
939 | - |
|
940 | - // show default for none teachers |
|
941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
942 | - return $args; |
|
943 | - } |
|
944 | - |
|
945 | - // for teachers all courses only return those which belong to the teacher |
|
946 | - // as they don't have access to course belonging to other users |
|
947 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
509 | + }// end update_course_lessons_author |
|
510 | + |
|
511 | + |
|
512 | + |
|
513 | + /** |
|
514 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
515 | + * |
|
516 | + * Alter the query so that users can only see their courses on the analysis page |
|
517 | + * |
|
518 | + * @since 1.8.0 |
|
519 | + * @access public |
|
520 | + * @parameters $query |
|
521 | + * @return array $users user id array |
|
522 | + */ |
|
523 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
524 | + |
|
525 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
526 | + return $query; |
|
527 | + } |
|
528 | + |
|
529 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
530 | + return $query; |
|
531 | + } |
|
532 | + |
|
533 | + $screen = get_current_screen(); |
|
534 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
535 | + |
|
536 | + // exit early for the following conditions |
|
537 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
538 | + |
|
539 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
540 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
541 | + return $query; |
|
542 | + } |
|
543 | + |
|
544 | + global $current_user; |
|
545 | + // set the query author to the current user to only show those those posts |
|
546 | + $query->set( 'author', $current_user->ID ); |
|
547 | + return $query; |
|
548 | + |
|
549 | + }// end course_analysis_teacher_access_limit |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
554 | + * |
|
555 | + * Determine if we're in admin and the current logged in use is a teacher |
|
556 | + * |
|
557 | + * @since 1.8.0 |
|
558 | + * @access public |
|
559 | + * @parameters array $wp_query |
|
560 | + * @return bool $is_admin_teacher |
|
561 | + */ |
|
562 | + public function is_admin_teacher ( ){ |
|
563 | + |
|
564 | + if( ! is_user_logged_in()){ |
|
565 | + return false; |
|
566 | + } |
|
567 | + $is_admin_teacher = false; |
|
568 | + |
|
569 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
570 | + |
|
571 | + $is_admin_teacher = true; |
|
572 | + |
|
573 | + } |
|
574 | + |
|
575 | + return $is_admin_teacher; |
|
576 | + |
|
577 | + } // end is_admin_teacher |
|
578 | + |
|
579 | + /** |
|
580 | + * Show correct post counts on list table for Sensei post types |
|
581 | + * |
|
582 | + * @since 1.8.0 |
|
583 | + * |
|
584 | + * @param object $counts Default status counts |
|
585 | + * @param string $type Current post type |
|
586 | + * @param string $perm User permission level |
|
587 | + * @return object Modified status counts |
|
588 | + */ |
|
589 | + public function list_table_counts( $counts, $type, $perm ) { |
|
590 | + global $current_user; |
|
591 | + |
|
592 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
593 | + return $counts; |
|
594 | + } |
|
595 | + |
|
596 | + if( ! $this->is_admin_teacher() ) { |
|
597 | + return $counts; |
|
598 | + } |
|
599 | + |
|
600 | + $args = array( |
|
601 | + 'post_type' => $type, |
|
602 | + 'author' => $current_user->ID, |
|
603 | + 'posts_per_page' => -1 |
|
604 | + ); |
|
605 | + |
|
606 | + // Get all available statuses |
|
607 | + $stati = get_post_stati(); |
|
608 | + |
|
609 | + // Update count object |
|
610 | + foreach( $stati as $status ) { |
|
611 | + $args['post_status'] = $status; |
|
612 | + $posts = get_posts( $args ); |
|
613 | + $counts->$status = count( $posts ); |
|
614 | + } |
|
615 | + |
|
616 | + return $counts; |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Filter the post queries to show |
|
621 | + * only lesson /course and users that belong |
|
622 | + * to the current logged teacher. |
|
623 | + * |
|
624 | + * @since 1.8.0 |
|
625 | + * |
|
626 | + */ |
|
627 | + public function filter_queries ( $query ) { |
|
628 | + global $current_user; |
|
629 | + |
|
630 | + if( ! $this->is_admin_teacher() ) { |
|
631 | + return; |
|
632 | + } |
|
633 | + |
|
634 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
635 | + return; |
|
636 | + } |
|
637 | + |
|
638 | + $screen = get_current_screen(); |
|
639 | + if( empty( $screen ) ) { |
|
640 | + return $query; |
|
641 | + } |
|
642 | + switch( $screen->id ) { |
|
643 | + case 'sensei_page_sensei_grading': |
|
644 | + case 'sensei_page_sensei_analysis': |
|
645 | + case 'sensei_page_sensei_learners': |
|
646 | + case 'lesson': |
|
647 | + case 'course': |
|
648 | + case 'question': |
|
649 | + case 'lesson_page_module-order': |
|
650 | + |
|
651 | + /** |
|
652 | + * sensei_filter_queries_set_author |
|
653 | + * Filter the author Sensei set for queries |
|
654 | + * |
|
655 | + * @since 1.8.0 |
|
656 | + * |
|
657 | + * @param int $user_id |
|
658 | + * @param string $screen_id |
|
659 | + * |
|
660 | + */ |
|
661 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
662 | + break; |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
668 | + * . This excludes the admin user. |
|
669 | + * |
|
670 | + * @since 1.8.0 |
|
671 | + * @hooked into the_comments |
|
672 | + * @param array $comments |
|
673 | + * |
|
674 | + * @return array $comments |
|
675 | + */ |
|
676 | + public function filter_grading_activity_queries( $comments ){ |
|
677 | + |
|
678 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
679 | + return $comments ; |
|
680 | + } |
|
681 | + |
|
682 | + //check if we're on the grading screen |
|
683 | + $screen = get_current_screen(); |
|
684 | + |
|
685 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
686 | + return $comments; |
|
687 | + } |
|
688 | + |
|
689 | + // get the course and determine if the current teacher is the owner |
|
690 | + // if not remove it from the list of comments to be returned |
|
691 | + foreach( $comments as $key => $comment){ |
|
692 | + $lesson = get_post( $comment->comment_post_ID ); |
|
693 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
694 | + $course = get_post( $course_id ); |
|
695 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
696 | + //remove this as the teacher should see this. |
|
697 | + unset( $comments[ $key ] ); |
|
698 | + } |
|
699 | + } |
|
700 | + return $comments ; |
|
701 | + |
|
702 | + }// end function filter grading |
|
703 | + |
|
704 | + /** |
|
705 | + * Limit the grading screen totals to only show lessons in the course |
|
706 | + * belonging to the currently logged in teacher. This only applies to |
|
707 | + * the teacher role. |
|
708 | + * |
|
709 | + * @since 1.8.0 |
|
710 | + * |
|
711 | + * @hooked into sensei_count_statuses_args |
|
712 | + * @param array $args |
|
713 | + * |
|
714 | + * @return array $args |
|
715 | + */ |
|
716 | + public function limit_grading_totals( $args ){ |
|
717 | + |
|
718 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
719 | + return $args ; |
|
720 | + } |
|
721 | + |
|
722 | + //get the teachers courses |
|
723 | + // the query is already filtered to only the teacher |
|
724 | + $courses = Sensei()->course->get_all_courses(); |
|
725 | + |
|
726 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
727 | + return $args; |
|
728 | + } |
|
729 | + |
|
730 | + //setup the lessons quizzes to limit the grading totals to |
|
731 | + $quiz_scope = array(); |
|
732 | + foreach( $courses as $course ){ |
|
733 | + |
|
734 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
735 | + |
|
736 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
737 | + |
|
738 | + foreach( $course_lessons as $lesson ){ |
|
739 | + |
|
740 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
741 | + if( !empty( $quiz_id ) ) { |
|
742 | + |
|
743 | + array_push( $quiz_scope, $quiz_id ); |
|
744 | + |
|
745 | + } |
|
746 | + |
|
747 | + } |
|
748 | + |
|
749 | + } |
|
750 | + |
|
751 | + } |
|
752 | + |
|
753 | + $args['post__in'] = $quiz_scope; |
|
754 | + |
|
755 | + return $args; |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * It ensures that the author archive shows course by the current user. |
|
760 | + * |
|
761 | + * This function is hooked into the pre_get_posts filter |
|
762 | + * |
|
763 | + * @param WP_Query $query |
|
764 | + * @return WP_Query $query |
|
765 | + */ |
|
766 | + public function add_courses_to_author_archive( $query ) { |
|
767 | + |
|
768 | + if ( is_admin() || ! $query->is_author() ){ |
|
769 | + return $query; |
|
770 | + } |
|
771 | + |
|
772 | + // this should only apply to users with the teacher role |
|
773 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
774 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
775 | + |
|
776 | + return $query; |
|
777 | + |
|
778 | + } |
|
779 | + |
|
780 | + // Change post types depending on what is set already |
|
781 | + $current_post_types = $query->get( 'post_type' ); |
|
782 | + if( empty( $current_post_types ) ){ |
|
783 | + |
|
784 | + // if empty it means post by default, so add post so that it also includes that for now |
|
785 | + $new_post_types = array( 'post', 'course' ); |
|
786 | + |
|
787 | + } elseif( is_array( $current_post_types ) ) { |
|
788 | + |
|
789 | + // merge the post types instead of overwriting it |
|
790 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
791 | + |
|
792 | + }else{ |
|
793 | + |
|
794 | + // in this instance it is probably just one post type in string format |
|
795 | + $new_post_types = array( $current_post_types , 'course'); |
|
796 | + |
|
797 | + } |
|
798 | + |
|
799 | + // change the query before returning it |
|
800 | + $query->set('post_type', $new_post_types ); |
|
801 | + |
|
802 | + /** |
|
803 | + * Change the query on the teacher author archive template |
|
804 | + * |
|
805 | + * @since 1.8.4 |
|
806 | + * @param WP_Query $query |
|
807 | + */ |
|
808 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
809 | + |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * Notify teacher when someone assigns a course to their account. |
|
814 | + * |
|
815 | + * @since 1.8.0 |
|
816 | + * |
|
817 | + * @param $teacher_id |
|
818 | + * @param $course_id |
|
819 | + * @return bool |
|
820 | + */ |
|
821 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
822 | + |
|
823 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
824 | + return false; |
|
825 | + } |
|
826 | + |
|
827 | + // if new user is the same as the current logged user, they don't need an email |
|
828 | + if( $teacher_id == get_current_user_id() ){ |
|
829 | + return true; |
|
830 | + } |
|
831 | + |
|
832 | + // load the email class |
|
833 | + include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
834 | + $email = new Teacher_New_Course_Assignment(); |
|
835 | + $email->trigger( $teacher_id, $course_id ); |
|
836 | + |
|
837 | + return true; |
|
838 | + } // end teacher_course_assigned_notification |
|
839 | + |
|
840 | + /** |
|
841 | + * Email the admin when a teacher creates a new course |
|
842 | + * |
|
843 | + * This function hooks into wp_insert_post |
|
844 | + * |
|
845 | + * @since 1.8.0 |
|
846 | + * @param int $course_id |
|
847 | + * @return bool |
|
848 | + */ |
|
849 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
850 | + |
|
851 | + $course_id = $post->ID; |
|
852 | + |
|
853 | + if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
854 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
855 | + |
|
856 | + return false; |
|
857 | + |
|
858 | + } |
|
859 | + |
|
860 | + /** |
|
861 | + * Filter the option to send admin notification emails when teachers creation |
|
862 | + * course. |
|
863 | + * |
|
864 | + * @since 1.8.0 |
|
865 | + * |
|
866 | + * @param bool $on default true |
|
867 | + */ |
|
868 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
869 | + return false; |
|
870 | + } |
|
871 | + |
|
872 | + // setting up the data needed by the email template |
|
873 | + global $sensei_email_data; |
|
874 | + $template = 'admin-teacher-new-course-created'; |
|
875 | + $course = get_post( $course_id ); |
|
876 | + $teacher = new WP_User( $course->post_author ); |
|
877 | + $recipient = get_option('admin_email', true); |
|
878 | + |
|
879 | + // don't send if the course is created by admin |
|
880 | + if( $recipient == $teacher->user_email ){ |
|
881 | + return; |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
886 | + * |
|
887 | + * @since 1.8.0 |
|
888 | + * @param string $template |
|
889 | + */ |
|
890 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
891 | + |
|
892 | + /** |
|
893 | + * Filter the email subject for the the |
|
894 | + * admin-teacher-new-course-created template |
|
895 | + * |
|
896 | + * @since 1.8.0 |
|
897 | + * @param string $subject default New course assigned to you |
|
898 | + * @param string $template |
|
899 | + */ |
|
900 | + $subject = apply_filters('sensei_email_subject', |
|
901 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
902 | + $template ); |
|
903 | + |
|
904 | + //course edit link |
|
905 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
906 | + |
|
907 | + // Construct data array |
|
908 | + $email_data = array( |
|
909 | + 'template' => $template, |
|
910 | + 'heading' => $heading, |
|
911 | + 'teacher' => $teacher, |
|
912 | + 'course_id' => $course_id, |
|
913 | + 'course_name' => $course->post_title, |
|
914 | + 'course_edit_link' => $course_edit_link, |
|
915 | + ); |
|
916 | + |
|
917 | + /** |
|
918 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
919 | + * |
|
920 | + * @since 1.8.0 |
|
921 | + * @param array $email_data |
|
922 | + * @param string $template |
|
923 | + */ |
|
924 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
925 | + |
|
926 | + // Send mail |
|
927 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
928 | + |
|
929 | + }// end notify admin of course creation |
|
930 | + |
|
931 | + /** |
|
932 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
933 | + * |
|
934 | + * Hooked into sensei_analysis_get_learners |
|
935 | + * @param array $args WP_User_Query arguments |
|
936 | + * @return array $learners_query_results |
|
937 | + */ |
|
938 | + public function limit_analysis_learners( $args ){ |
|
939 | + |
|
940 | + // show default for none teachers |
|
941 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
942 | + return $args; |
|
943 | + } |
|
944 | + |
|
945 | + // for teachers all courses only return those which belong to the teacher |
|
946 | + // as they don't have access to course belonging to other users |
|
947 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
948 | 948 | |
949 | - // if the user has no courses they should see no users |
|
950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
951 | - // tell the query to return 0 students |
|
952 | - $args[ 'include'] = array( 0 ); |
|
953 | - return $args; |
|
954 | - |
|
955 | - } |
|
956 | - |
|
957 | - $learner_ids_for_teacher_courses = array(); |
|
958 | - foreach( $teacher_courses as $course ){ |
|
959 | - |
|
960 | - $course_learner_ids = array(); |
|
961 | - $activity_comments = 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 |
||
1559 | 1559 | </h2> |
1560 | 1560 | <?php |
1561 | 1561 | |
1562 | - }// archive title |
|
1562 | + }// archive title |
|
1563 | 1563 | |
1564 | - /** |
|
1565 | - * Removing course meta on the teacher archive page |
|
1566 | - * |
|
1567 | - * @since 1.9.0 |
|
1568 | - */ |
|
1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
1564 | + /** |
|
1565 | + * Removing course meta on the teacher archive page |
|
1566 | + * |
|
1567 | + * @since 1.9.0 |
|
1568 | + */ |
|
1569 | + public static function remove_course_meta_on_teacher_archive(){ |
|
1570 | 1570 | |
1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1571 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1572 | 1572 | |
1573 | - } |
|
1573 | + } |
|
1574 | 1574 | |
1575 | 1575 | } // End Class |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Teacher class |
@@ -42,58 +42,58 @@ discard block |
||
42 | 42 | * @since 1.8.0 |
43 | 43 | * @access public |
44 | 44 | */ |
45 | - public function __construct ( ) { |
|
45 | + public function __construct( ) { |
|
46 | 46 | |
47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
47 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
48 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
49 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
50 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
51 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
52 | 52 | |
53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
53 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
54 | 54 | |
55 | 55 | //filter the quiz submissions |
56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
56 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
57 | 57 | |
58 | 58 | //grading totals count only those belonging to the teacher |
59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
59 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
60 | 60 | |
61 | 61 | // show the courses owned by a user on his author archive page |
62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
62 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
63 | 63 | |
64 | 64 | // notify admin when a teacher creates a course |
65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
65 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
66 | 66 | |
67 | 67 | // limit the analysis view to only the users taking courses belong to this teacher |
68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
68 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
69 | 69 | |
70 | 70 | // give teacher access to question post type |
71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
71 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
72 | 72 | |
73 | 73 | // Teacher column on the courses list on the admin edit screen |
74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
74 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
75 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
76 | 76 | |
77 | 77 | //admin edit messages query limit teacher |
78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
78 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
79 | 79 | |
80 | 80 | //add filter by teacher on courses list |
81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
81 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
82 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
83 | 83 | |
84 | 84 | // Handle media library restrictions |
85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
85 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
86 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
87 | 87 | |
88 | 88 | // update lesson owner to course teacher when saved |
89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
89 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
90 | 90 | |
91 | 91 | // If a Teacher logs in, redirect to /wp-admin/ |
92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
92 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
93 | 93 | |
94 | 94 | |
95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
95 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
96 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
97 | 97 | |
98 | 98 | |
99 | 99 | } // end __constructor() |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | * @access public |
109 | 109 | * @return void |
110 | 110 | */ |
111 | - public function create_role ( ) { |
|
111 | + public function create_role( ) { |
|
112 | 112 | |
113 | 113 | // check if the role exists |
114 | - $this->teacher_role = get_role( 'teacher' ); |
|
114 | + $this->teacher_role = get_role('teacher'); |
|
115 | 115 | |
116 | 116 | // if the the teacher is not a valid WordPress role create it |
117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
117 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
118 | 118 | // create the role |
119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
119 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // add the capabilities before returning |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | * @since 1.8.0 |
131 | 131 | * @access protected |
132 | 132 | */ |
133 | - protected function add_capabilities ( ) { |
|
133 | + protected function add_capabilities( ) { |
|
134 | 134 | |
135 | 135 | // if this is not a valid WP_Role object exit without adding anything |
136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
136 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param array $capabilities |
145 | 145 | * keys: (string) $cap_name => (bool) $grant |
146 | 146 | */ |
147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
147 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
148 | 148 | // General access rules |
149 | 149 | 'read' => true, |
150 | 150 | 'manage_sensei_grades' => true, |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | )); |
203 | 203 | |
204 | - foreach ( $caps as $cap => $grant ) { |
|
204 | + foreach ($caps as $cap => $grant) { |
|
205 | 205 | |
206 | 206 | // load the capability on to the teacher role |
207 | 207 | $this->teacher_role->add_cap($cap, $grant); |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | * @parameter WP_Post $post |
222 | 222 | * @return void |
223 | 223 | */ |
224 | - public function add_teacher_meta_boxes ( $post ) { |
|
224 | + public function add_teacher_meta_boxes($post) { |
|
225 | 225 | |
226 | - if( !current_user_can('manage_options') ){ |
|
226 | + if ( ! current_user_can('manage_options')) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , $this->token ), array( $this , 'teacher_meta_box_content' ), |
|
229 | + add_meta_box('sensei-teacher', __('Teacher', $this->token), array($this, 'teacher_meta_box_content'), |
|
230 | 230 | 'course', |
231 | 231 | 'side', |
232 | 232 | 'core' |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @access public |
244 | 244 | * @parameters |
245 | 245 | */ |
246 | - public function teacher_meta_box_content ( $post ) { |
|
246 | + public function teacher_meta_box_content($post) { |
|
247 | 247 | |
248 | 248 | // get the current author |
249 | 249 | $current_author = $post->post_author; |
@@ -254,12 +254,12 @@ discard block |
||
254 | 254 | ?> |
255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
256 | 256 | |
257 | - <?php foreach ( $users as $user_id ) { ?> |
|
257 | + <?php foreach ($users as $user_id) { ?> |
|
258 | 258 | |
259 | 259 | <?php |
260 | 260 | $user = get_user_by('id', $user_id); |
261 | 261 | ?> |
262 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
262 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
263 | 263 | <?php echo $user->display_name; ?> |
264 | 264 | </option> |
265 | 265 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @parameters |
282 | 282 | * @return array $users user id array |
283 | 283 | */ |
284 | - public function get_teachers_and_authors ( ){ |
|
284 | + public function get_teachers_and_authors( ) { |
|
285 | 285 | |
286 | 286 | $author_query_args = array( |
287 | 287 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | 'who' => 'authors' |
290 | 290 | ); |
291 | 291 | |
292 | - $authors = get_users( $author_query_args ); |
|
292 | + $authors = get_users($author_query_args); |
|
293 | 293 | |
294 | 294 | $teacher_query_args = array( |
295 | 295 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | 'role' => 'teacher', |
298 | 298 | ); |
299 | 299 | |
300 | - $teachers = get_users( $teacher_query_args ); |
|
300 | + $teachers = get_users($teacher_query_args); |
|
301 | 301 | |
302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
302 | + return array_unique(array_merge($teachers, $authors)); |
|
303 | 303 | |
304 | 304 | }// end get_teachers_and_authors |
305 | 305 | |
@@ -315,43 +315,43 @@ discard block |
||
315 | 315 | * @parameters |
316 | 316 | * @return array $users user id array |
317 | 317 | */ |
318 | - public function save_teacher_meta_box ( $course_id ){ |
|
318 | + public function save_teacher_meta_box($course_id) { |
|
319 | 319 | |
320 | 320 | // check if this is a post from saving the teacher, if not exit early |
321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
321 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | 324 | |
325 | 325 | //don't fire this hook again |
326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
326 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
327 | 327 | |
328 | 328 | // get the current post object |
329 | - $post = get_post( $course_id ); |
|
329 | + $post = get_post($course_id); |
|
330 | 330 | |
331 | 331 | // get the current teacher/author |
332 | - $current_author = absint( $post->post_author ); |
|
333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
332 | + $current_author = absint($post->post_author); |
|
333 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
334 | 334 | |
335 | 335 | // loop through all post lessons to update their authors as well |
336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
336 | + $this->update_course_lessons_author($course_id, $new_author); |
|
337 | 337 | |
338 | 338 | // do not do any processing if the selected author is the same as the current author |
339 | - if( $current_author == $new_author ){ |
|
339 | + if ($current_author == $new_author) { |
|
340 | 340 | return; |
341 | 341 | } |
342 | 342 | |
343 | 343 | // save the course author |
344 | 344 | $post_updates = array( |
345 | - 'ID' => $post->ID , |
|
345 | + 'ID' => $post->ID, |
|
346 | 346 | 'post_author' => $new_author |
347 | 347 | ); |
348 | - wp_update_post( $post_updates ); |
|
348 | + wp_update_post($post_updates); |
|
349 | 349 | |
350 | 350 | // ensure the the modules are update so that then new teacher has access to them |
351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
351 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
352 | 352 | |
353 | 353 | // notify the new teacher |
354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
354 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
355 | 355 | |
356 | 356 | } // end save_teacher_meta_box |
357 | 357 | |
@@ -365,56 +365,56 @@ discard block |
||
365 | 365 | * @param $new_teacher_id |
366 | 366 | * @return void |
367 | 367 | */ |
368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
368 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
369 | 369 | |
370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
370 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
371 | 371 | return false; |
372 | 372 | } |
373 | 373 | |
374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
374 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
375 | 375 | |
376 | - if( empty( $terms_selected_on_course ) ){ |
|
376 | + if (empty($terms_selected_on_course)) { |
|
377 | 377 | return; |
378 | 378 | } |
379 | 379 | |
380 | - foreach( $terms_selected_on_course as $term ){ |
|
380 | + foreach ($terms_selected_on_course as $term) { |
|
381 | 381 | |
382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
383 | - if( $new_teacher_id != $term_author->ID ){ |
|
382 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
383 | + if ($new_teacher_id != $term_author->ID) { |
|
384 | 384 | |
385 | 385 | $new_term = ''; |
386 | 386 | |
387 | 387 | //if the new teacher is admin first check to see if the term with this name already exists |
388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
388 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
389 | 389 | |
390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
393 | - if( !empty( $existing_admin_terms ) ){ |
|
390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
391 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
392 | + $existing_admin_terms = get_terms('module', $term_args); |
|
393 | + if ( ! empty($existing_admin_terms)) { |
|
394 | 394 | // insert it even if it exists |
395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
395 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | - if( empty ( $new_term ) ){ |
|
399 | + if (empty ($new_term)) { |
|
400 | 400 | |
401 | 401 | //setup the new slug |
402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
402 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
403 | 403 | |
404 | 404 | // create new term and set it |
405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
405 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | |
409 | 409 | |
410 | 410 | |
411 | 411 | // if term exists |
412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
412 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
413 | 413 | |
414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
414 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
415 | 415 | $term_id = $existing_term->term_id; |
416 | 416 | |
417 | - }else{ |
|
417 | + } else { |
|
418 | 418 | |
419 | 419 | // for a new term simply get the term from the returned value |
420 | 420 | $term_id = $new_term['term_id']; |
@@ -422,21 +422,21 @@ discard block |
||
422 | 422 | } // end if term exist |
423 | 423 | |
424 | 424 | // set the terms selected on the course |
425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
425 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
426 | 426 | |
427 | 427 | // remove old term |
428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
428 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
429 | 429 | |
430 | 430 | // update the lessons within the current module term |
431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
432 | - foreach( $lessons as $lesson ){ |
|
431 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
432 | + foreach ($lessons as $lesson) { |
|
433 | 433 | |
434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
434 | + if (has_term($term->slug, 'module', $lesson)) { |
|
435 | 435 | |
436 | 436 | // add the new term, the false at the end says to replace all terms on this module |
437 | 437 | // with the new term. |
438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
438 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
439 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | }// end for each |
@@ -456,50 +456,50 @@ discard block |
||
456 | 456 | * @parameters |
457 | 457 | * @return array $users user id array |
458 | 458 | */ |
459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
459 | + public function update_course_lessons_author($course_id, $new_author) { |
|
460 | 460 | |
461 | 461 | |
462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
462 | + if (empty($course_id) || empty($new_author)) { |
|
463 | 463 | return false; |
464 | 464 | } |
465 | 465 | |
466 | 466 | //get a list of course lessons |
467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
467 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
468 | 468 | |
469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
469 | + if (empty($lessons) || ! is_array($lessons)) { |
|
470 | 470 | return false; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // update each lesson and quiz author |
474 | - foreach( $lessons as $lesson ){ |
|
474 | + foreach ($lessons as $lesson) { |
|
475 | 475 | |
476 | 476 | // don't update if the author is tha same as the new author |
477 | - if( $new_author == $lesson->post_author ){ |
|
477 | + if ($new_author == $lesson->post_author) { |
|
478 | 478 | continue; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // update lesson author |
482 | - wp_update_post( array( |
|
482 | + wp_update_post(array( |
|
483 | 483 | 'ID'=> $lesson->ID, |
484 | 484 | 'post_author' => $new_author |
485 | - ) ); |
|
485 | + )); |
|
486 | 486 | |
487 | 487 | // update quiz author |
488 | 488 | //get the lessons quiz |
489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
490 | - if( is_array( $lesson_quizzes ) ){ |
|
491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
490 | + if (is_array($lesson_quizzes)) { |
|
491 | + foreach ($lesson_quizzes as $quiz_id) { |
|
492 | 492 | // update quiz with new author |
493 | - wp_update_post( array( |
|
493 | + wp_update_post(array( |
|
494 | 494 | 'ID' => $quiz_id, |
495 | 495 | 'post_author' => $new_author |
496 | - ) ); |
|
496 | + )); |
|
497 | 497 | } |
498 | - }else{ |
|
499 | - wp_update_post( array( |
|
498 | + } else { |
|
499 | + wp_update_post(array( |
|
500 | 500 | 'ID' => $lesson_quizzes, |
501 | 501 | 'post_author' => $new_author |
502 | - ) ); |
|
502 | + )); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | } // end for each lessons |
@@ -520,30 +520,30 @@ discard block |
||
520 | 520 | * @parameters $query |
521 | 521 | * @return array $users user id array |
522 | 522 | */ |
523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
523 | + public function course_analysis_teacher_access_limit($query) { |
|
524 | 524 | |
525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
525 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
526 | 526 | return $query; |
527 | 527 | } |
528 | 528 | |
529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
529 | + if ( ! function_exists('get_current_screen')) { |
|
530 | 530 | return $query; |
531 | 531 | } |
532 | 532 | |
533 | 533 | $screen = get_current_screen(); |
534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
534 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
535 | 535 | |
536 | 536 | // exit early for the following conditions |
537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
537 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
538 | 538 | |
539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
539 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
540 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
541 | 541 | return $query; |
542 | 542 | } |
543 | 543 | |
544 | 544 | global $current_user; |
545 | 545 | // set the query author to the current user to only show those those posts |
546 | - $query->set( 'author', $current_user->ID ); |
|
546 | + $query->set('author', $current_user->ID); |
|
547 | 547 | return $query; |
548 | 548 | |
549 | 549 | }// end course_analysis_teacher_access_limit |
@@ -559,14 +559,14 @@ discard block |
||
559 | 559 | * @parameters array $wp_query |
560 | 560 | * @return bool $is_admin_teacher |
561 | 561 | */ |
562 | - public function is_admin_teacher ( ){ |
|
562 | + public function is_admin_teacher( ) { |
|
563 | 563 | |
564 | - if( ! is_user_logged_in()){ |
|
564 | + if ( ! is_user_logged_in()) { |
|
565 | 565 | return false; |
566 | 566 | } |
567 | 567 | $is_admin_teacher = false; |
568 | 568 | |
569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
569 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
570 | 570 | |
571 | 571 | $is_admin_teacher = true; |
572 | 572 | |
@@ -586,14 +586,14 @@ discard block |
||
586 | 586 | * @param string $perm User permission level |
587 | 587 | * @return object Modified status counts |
588 | 588 | */ |
589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
589 | + public function list_table_counts($counts, $type, $perm) { |
|
590 | 590 | global $current_user; |
591 | 591 | |
592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
592 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
593 | 593 | return $counts; |
594 | 594 | } |
595 | 595 | |
596 | - if( ! $this->is_admin_teacher() ) { |
|
596 | + if ( ! $this->is_admin_teacher()) { |
|
597 | 597 | return $counts; |
598 | 598 | } |
599 | 599 | |
@@ -607,10 +607,10 @@ discard block |
||
607 | 607 | $stati = get_post_stati(); |
608 | 608 | |
609 | 609 | // Update count object |
610 | - foreach( $stati as $status ) { |
|
610 | + foreach ($stati as $status) { |
|
611 | 611 | $args['post_status'] = $status; |
612 | - $posts = get_posts( $args ); |
|
613 | - $counts->$status = count( $posts ); |
|
612 | + $posts = get_posts($args); |
|
613 | + $counts->$status = count($posts); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | return $counts; |
@@ -624,22 +624,22 @@ discard block |
||
624 | 624 | * @since 1.8.0 |
625 | 625 | * |
626 | 626 | */ |
627 | - public function filter_queries ( $query ) { |
|
627 | + public function filter_queries($query) { |
|
628 | 628 | global $current_user; |
629 | 629 | |
630 | - if( ! $this->is_admin_teacher() ) { |
|
630 | + if ( ! $this->is_admin_teacher()) { |
|
631 | 631 | return; |
632 | 632 | } |
633 | 633 | |
634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
634 | + if ( ! function_exists('get_current_screen')) { |
|
635 | 635 | return; |
636 | 636 | } |
637 | 637 | |
638 | 638 | $screen = get_current_screen(); |
639 | - if( empty( $screen ) ) { |
|
639 | + if (empty($screen)) { |
|
640 | 640 | return $query; |
641 | 641 | } |
642 | - switch( $screen->id ) { |
|
642 | + switch ($screen->id) { |
|
643 | 643 | case 'sensei_page_sensei_grading': |
644 | 644 | case 'sensei_page_sensei_analysis': |
645 | 645 | case 'sensei_page_sensei_learners': |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | * @param string $screen_id |
659 | 659 | * |
660 | 660 | */ |
661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
661 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
662 | 662 | break; |
663 | 663 | } |
664 | 664 | } |
@@ -673,31 +673,31 @@ discard block |
||
673 | 673 | * |
674 | 674 | * @return array $comments |
675 | 675 | */ |
676 | - public function filter_grading_activity_queries( $comments ){ |
|
676 | + public function filter_grading_activity_queries($comments) { |
|
677 | 677 | |
678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
679 | - return $comments ; |
|
678 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
679 | + return $comments; |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | //check if we're on the grading screen |
683 | 683 | $screen = get_current_screen(); |
684 | 684 | |
685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
685 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
686 | 686 | return $comments; |
687 | 687 | } |
688 | 688 | |
689 | 689 | // get the course and determine if the current teacher is the owner |
690 | 690 | // if not remove it from the list of comments to be returned |
691 | - foreach( $comments as $key => $comment){ |
|
692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
694 | - $course = get_post( $course_id ); |
|
695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
691 | + foreach ($comments as $key => $comment) { |
|
692 | + $lesson = get_post($comment->comment_post_ID); |
|
693 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
694 | + $course = get_post($course_id); |
|
695 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
696 | 696 | //remove this as the teacher should see this. |
697 | - unset( $comments[ $key ] ); |
|
697 | + unset($comments[$key]); |
|
698 | 698 | } |
699 | 699 | } |
700 | - return $comments ; |
|
700 | + return $comments; |
|
701 | 701 | |
702 | 702 | }// end function filter grading |
703 | 703 | |
@@ -713,34 +713,34 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @return array $args |
715 | 715 | */ |
716 | - public function limit_grading_totals( $args ){ |
|
716 | + public function limit_grading_totals($args) { |
|
717 | 717 | |
718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
719 | - return $args ; |
|
718 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
719 | + return $args; |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | //get the teachers courses |
723 | 723 | // the query is already filtered to only the teacher |
724 | - $courses = Sensei()->course->get_all_courses(); |
|
724 | + $courses = Sensei()->course->get_all_courses(); |
|
725 | 725 | |
726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
726 | + if (empty($courses) || ! is_array($courses)) { |
|
727 | 727 | return $args; |
728 | 728 | } |
729 | 729 | |
730 | 730 | //setup the lessons quizzes to limit the grading totals to |
731 | 731 | $quiz_scope = array(); |
732 | - foreach( $courses as $course ){ |
|
732 | + foreach ($courses as $course) { |
|
733 | 733 | |
734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
734 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
735 | 735 | |
736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
736 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
737 | 737 | |
738 | - foreach( $course_lessons as $lesson ){ |
|
738 | + foreach ($course_lessons as $lesson) { |
|
739 | 739 | |
740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
741 | - if( !empty( $quiz_id ) ) { |
|
740 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
741 | + if ( ! empty($quiz_id)) { |
|
742 | 742 | |
743 | - array_push( $quiz_scope, $quiz_id ); |
|
743 | + array_push($quiz_scope, $quiz_id); |
|
744 | 744 | |
745 | 745 | } |
746 | 746 | |
@@ -763,41 +763,41 @@ discard block |
||
763 | 763 | * @param WP_Query $query |
764 | 764 | * @return WP_Query $query |
765 | 765 | */ |
766 | - public function add_courses_to_author_archive( $query ) { |
|
766 | + public function add_courses_to_author_archive($query) { |
|
767 | 767 | |
768 | - if ( is_admin() || ! $query->is_author() ){ |
|
768 | + if (is_admin() || ! $query->is_author()) { |
|
769 | 769 | return $query; |
770 | 770 | } |
771 | 771 | |
772 | 772 | // this should only apply to users with the teacher role |
773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
773 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
774 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
775 | 775 | |
776 | 776 | return $query; |
777 | 777 | |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Change post types depending on what is set already |
781 | - $current_post_types = $query->get( 'post_type' ); |
|
782 | - if( empty( $current_post_types ) ){ |
|
781 | + $current_post_types = $query->get('post_type'); |
|
782 | + if (empty($current_post_types)) { |
|
783 | 783 | |
784 | 784 | // if empty it means post by default, so add post so that it also includes that for now |
785 | - $new_post_types = array( 'post', 'course' ); |
|
785 | + $new_post_types = array('post', 'course'); |
|
786 | 786 | |
787 | - } elseif( is_array( $current_post_types ) ) { |
|
787 | + } elseif (is_array($current_post_types)) { |
|
788 | 788 | |
789 | 789 | // merge the post types instead of overwriting it |
790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
790 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
791 | 791 | |
792 | - }else{ |
|
792 | + } else { |
|
793 | 793 | |
794 | 794 | // in this instance it is probably just one post type in string format |
795 | - $new_post_types = array( $current_post_types , 'course'); |
|
795 | + $new_post_types = array($current_post_types, 'course'); |
|
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | 799 | // change the query before returning it |
800 | - $query->set('post_type', $new_post_types ); |
|
800 | + $query->set('post_type', $new_post_types); |
|
801 | 801 | |
802 | 802 | /** |
803 | 803 | * Change the query on the teacher author archive template |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @since 1.8.4 |
806 | 806 | * @param WP_Query $query |
807 | 807 | */ |
808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
808 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | |
@@ -818,21 +818,21 @@ discard block |
||
818 | 818 | * @param $course_id |
819 | 819 | * @return bool |
820 | 820 | */ |
821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
821 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
822 | 822 | |
823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
823 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
824 | 824 | return false; |
825 | 825 | } |
826 | 826 | |
827 | 827 | // if new user is the same as the current logged user, they don't need an email |
828 | - if( $teacher_id == get_current_user_id() ){ |
|
828 | + if ($teacher_id == get_current_user_id()) { |
|
829 | 829 | return true; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // load the email class |
833 | 833 | include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
834 | 834 | $email = new Teacher_New_Course_Assignment(); |
835 | - $email->trigger( $teacher_id, $course_id ); |
|
835 | + $email->trigger($teacher_id, $course_id); |
|
836 | 836 | |
837 | 837 | return true; |
838 | 838 | } // end teacher_course_assigned_notification |
@@ -846,12 +846,12 @@ discard block |
||
846 | 846 | * @param int $course_id |
847 | 847 | * @return bool |
848 | 848 | */ |
849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
849 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
850 | 850 | |
851 | 851 | $course_id = $post->ID; |
852 | 852 | |
853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
853 | + if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
854 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
855 | 855 | |
856 | 856 | return false; |
857 | 857 | |
@@ -865,19 +865,19 @@ discard block |
||
865 | 865 | * |
866 | 866 | * @param bool $on default true |
867 | 867 | */ |
868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
868 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | |
872 | 872 | // setting up the data needed by the email template |
873 | 873 | global $sensei_email_data; |
874 | 874 | $template = 'admin-teacher-new-course-created'; |
875 | - $course = get_post( $course_id ); |
|
876 | - $teacher = new WP_User( $course->post_author ); |
|
875 | + $course = get_post($course_id); |
|
876 | + $teacher = new WP_User($course->post_author); |
|
877 | 877 | $recipient = get_option('admin_email', true); |
878 | 878 | |
879 | 879 | // don't send if the course is created by admin |
880 | - if( $recipient == $teacher->user_email ){ |
|
880 | + if ($recipient == $teacher->user_email) { |
|
881 | 881 | return; |
882 | 882 | } |
883 | 883 | |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @since 1.8.0 |
888 | 888 | * @param string $template |
889 | 889 | */ |
890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
890 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
891 | 891 | |
892 | 892 | /** |
893 | 893 | * Filter the email subject for the the |
@@ -898,11 +898,11 @@ discard block |
||
898 | 898 | * @param string $template |
899 | 899 | */ |
900 | 900 | $subject = apply_filters('sensei_email_subject', |
901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
902 | - $template ); |
|
901 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
902 | + $template); |
|
903 | 903 | |
904 | 904 | //course edit link |
905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
905 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
906 | 906 | |
907 | 907 | // Construct data array |
908 | 908 | $email_data = array( |
@@ -921,10 +921,10 @@ discard block |
||
921 | 921 | * @param array $email_data |
922 | 922 | * @param string $template |
923 | 923 | */ |
924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
924 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
925 | 925 | |
926 | 926 | // Send mail |
927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
927 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
928 | 928 | |
929 | 929 | }// end notify admin of course creation |
930 | 930 | |
@@ -935,10 +935,10 @@ discard block |
||
935 | 935 | * @param array $args WP_User_Query arguments |
936 | 936 | * @return array $learners_query_results |
937 | 937 | */ |
938 | - public function limit_analysis_learners( $args ){ |
|
938 | + public function limit_analysis_learners($args) { |
|
939 | 939 | |
940 | 940 | // show default for none teachers |
941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
941 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
942 | 942 | return $args; |
943 | 943 | } |
944 | 944 | |
@@ -947,31 +947,31 @@ discard block |
||
947 | 947 | $teacher_courses = Sensei()->course->get_all_courses(); |
948 | 948 | |
949 | 949 | // if the user has no courses they should see no users |
950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
950 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
951 | 951 | // tell the query to return 0 students |
952 | - $args[ 'include'] = array( 0 ); |
|
952 | + $args['include'] = array(0); |
|
953 | 953 | return $args; |
954 | 954 | |
955 | 955 | } |
956 | 956 | |
957 | 957 | $learner_ids_for_teacher_courses = array(); |
958 | - foreach( $teacher_courses as $course ){ |
|
958 | + foreach ($teacher_courses as $course) { |
|
959 | 959 | |
960 | 960 | $course_learner_ids = array(); |
961 | - $activity_comments = 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 |
||
979 | 979 | $course_learner_ids[] = $user->ID; |
980 | 980 | } |
981 | 981 | |
982 | - }else{ |
|
982 | + } else { |
|
983 | 983 | |
984 | - $user = get_userdata( $activity_comments->user_id ); |
|
984 | + $user = get_userdata($activity_comments->user_id); |
|
985 | 985 | $course_learner_ids[] = $user->ID; |
986 | 986 | |
987 | 987 | } |
988 | 988 | |
989 | 989 | // add learners on this course to the all courses learner list |
990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
990 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
991 | 991 | |
992 | 992 | } |
993 | 993 | |
994 | 994 | // if there are no students taking the courses by this teacher don't show them any of the other users |
995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
995 | + if (empty($learner_ids_for_teacher_courses)) { |
|
996 | 996 | |
997 | - $args[ 'include'] = array( 0 ); |
|
997 | + $args['include'] = array(0); |
|
998 | 998 | |
999 | - }else{ |
|
999 | + } else { |
|
1000 | 1000 | |
1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
1001 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
1002 | 1002 | |
1003 | 1003 | } |
1004 | 1004 | |
@@ -1015,35 +1015,35 @@ discard block |
||
1015 | 1015 | * @param $questions |
1016 | 1016 | * @return mixed |
1017 | 1017 | */ |
1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
1018 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
1019 | 1019 | |
1020 | - if( ! $this->is_admin_teacher() ){ |
|
1020 | + if ( ! $this->is_admin_teacher()) { |
|
1021 | 1021 | return $questions; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | $screen = get_current_screen(); |
1025 | 1025 | |
1026 | 1026 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
1027 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
1028 | 1028 | |
1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
1029 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
1030 | 1030 | |
1031 | 1031 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1032 | - if( ! empty($admin_user) ){ |
|
1032 | + if ( ! empty($admin_user)) { |
|
1033 | 1033 | |
1034 | 1034 | $current_teacher_id = get_current_user_id(); |
1035 | 1035 | |
1036 | 1036 | // set current user to admin so teacher can view all questions |
1037 | - wp_set_current_user( $admin_user->ID ); |
|
1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
1037 | + wp_set_current_user($admin_user->ID); |
|
1038 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
1039 | 1039 | |
1040 | 1040 | // set the teacher as the current use again |
1041 | - wp_set_current_user( $current_teacher_id ); |
|
1041 | + wp_set_current_user($current_teacher_id); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | } |
1045 | 1045 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
1046 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
1047 | 1047 | |
1048 | 1048 | return $questions; |
1049 | 1049 | } |
@@ -1055,30 +1055,30 @@ discard block |
||
1055 | 1055 | * @param $wp_query |
1056 | 1056 | * @return mixed |
1057 | 1057 | */ |
1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
1058 | + public function give_access_to_all_questions($wp_query) { |
|
1059 | 1059 | |
1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
1060 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
1061 | 1061 | |
1062 | 1062 | return $wp_query; |
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | $screen = get_current_screen(); |
1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
1066 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
1067 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
1068 | 1068 | |
1069 | 1069 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1070 | - if( ! empty($admin_user) ){ |
|
1070 | + if ( ! empty($admin_user)) { |
|
1071 | 1071 | |
1072 | 1072 | $current_teacher_id = get_current_user_id(); |
1073 | 1073 | |
1074 | 1074 | // set current user to admin so teacher can view all questions |
1075 | - wp_set_current_user( $admin_user->ID ); |
|
1075 | + wp_set_current_user($admin_user->ID); |
|
1076 | 1076 | |
1077 | 1077 | //run new query as admin |
1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
1078 | + $wp_query = new WP_Query($wp_query->query); |
|
1079 | 1079 | |
1080 | 1080 | //set the teache as current use again |
1081 | - wp_set_current_user( $current_teacher_id ); |
|
1081 | + wp_set_current_user($current_teacher_id); |
|
1082 | 1082 | |
1083 | 1083 | } |
1084 | 1084 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | */ |
1096 | 1096 | public function course_column_heading($columns) { |
1097 | 1097 | |
1098 | - if( $this->is_admin_teacher() ){ |
|
1098 | + if ($this->is_admin_teacher()) { |
|
1099 | 1099 | return $columns; |
1100 | 1100 | } |
1101 | 1101 | $new_columns = array( |
@@ -1112,20 +1112,20 @@ discard block |
||
1112 | 1112 | * @param $column |
1113 | 1113 | * @param $course_id |
1114 | 1114 | */ |
1115 | - public function course_column_data( $column, $course_id ){ |
|
1115 | + public function course_column_data($column, $course_id) { |
|
1116 | 1116 | |
1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
1117 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
1118 | 1118 | return; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - $course = get_post( $course_id ); |
|
1122 | - $teacher = get_userdata( $course->post_author ); |
|
1121 | + $course = get_post($course_id); |
|
1122 | + $teacher = get_userdata($course->post_author); |
|
1123 | 1123 | |
1124 | - if( !$teacher ){ |
|
1124 | + if ( ! $teacher) { |
|
1125 | 1125 | return; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
1128 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
1129 | 1129 | |
1130 | 1130 | }// end course_column_ data |
1131 | 1131 | |
@@ -1140,31 +1140,31 @@ discard block |
||
1140 | 1140 | * |
1141 | 1141 | * @return array $teachers_courses |
1142 | 1142 | */ |
1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
1143 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
1144 | 1144 | |
1145 | 1145 | $teachers_courses = array(); |
1146 | 1146 | |
1147 | - if( empty( $teacher_id ) ){ |
|
1147 | + if (empty($teacher_id)) { |
|
1148 | 1148 | $teacher_id = get_current_user_id(); |
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | $all_courses = Sensei()->course->get_all_courses(); |
1152 | 1152 | |
1153 | - if( empty( $all_courses ) ){ |
|
1153 | + if (empty($all_courses)) { |
|
1154 | 1154 | return $all_courses; |
1155 | 1155 | } |
1156 | 1156 | |
1157 | - foreach( $all_courses as $course ){ |
|
1157 | + foreach ($all_courses as $course) { |
|
1158 | 1158 | |
1159 | - if( $course->post_author != $teacher_id ){ |
|
1159 | + if ($course->post_author != $teacher_id) { |
|
1160 | 1160 | continue; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | - if( $return_ids_only ){ |
|
1163 | + if ($return_ids_only) { |
|
1164 | 1164 | |
1165 | 1165 | $teachers_courses[] = $course->ID; |
1166 | 1166 | |
1167 | - }else{ |
|
1167 | + } else { |
|
1168 | 1168 | |
1169 | 1169 | $teachers_courses[] = $course; |
1170 | 1170 | |
@@ -1184,21 +1184,21 @@ discard block |
||
1184 | 1184 | * @param $query |
1185 | 1185 | * @return mixed |
1186 | 1186 | */ |
1187 | - public function limit_edit_messages_query( $query ){ |
|
1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
1187 | + public function limit_edit_messages_query($query) { |
|
1188 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
1189 | 1189 | return $query; |
1190 | 1190 | } |
1191 | 1191 | |
1192 | 1192 | $teacher = wp_get_current_user(); |
1193 | 1193 | |
1194 | - $query->set( 'meta_key', '_receiver' ); |
|
1194 | + $query->set('meta_key', '_receiver'); |
|
1195 | 1195 | $meta_query_args = array( |
1196 | 1196 | 'key' => '_receiver', |
1197 | - 'value' => $teacher->get('user_login') , |
|
1197 | + 'value' => $teacher->get('user_login'), |
|
1198 | 1198 | 'compare' => '=' |
1199 | 1199 | ); |
1200 | 1200 | |
1201 | - $query->set('meta_query', $meta_query_args ); |
|
1201 | + $query->set('meta_query', $meta_query_args); |
|
1202 | 1202 | |
1203 | 1203 | return $query; |
1204 | 1204 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
1214 | 1214 | public function course_teacher_filter_options() { |
1215 | 1215 | global $typenow; |
1216 | 1216 | |
1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1217 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1218 | 1218 | return; |
1219 | 1219 | } |
1220 | 1220 | |
@@ -1224,31 +1224,31 @@ discard block |
||
1224 | 1224 | // get roles with the course edit capability |
1225 | 1225 | // and then get the users with those roles |
1226 | 1226 | $users_who_can_edit_courses = array(); |
1227 | - foreach( $roles as $role_item ){ |
|
1227 | + foreach ($roles as $role_item) { |
|
1228 | 1228 | |
1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
1229 | + $role = get_role(strtolower($role_item['name'])); |
|
1230 | 1230 | |
1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
1231 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
1232 | 1232 | |
1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
1233 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
1234 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
1235 | 1235 | |
1236 | 1236 | // add user from the current $user_role to all users |
1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
1237 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
1238 | 1238 | |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | // Create the select element with the given users who can edit course |
1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1244 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1245 | 1245 | $course_options = ''; |
1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
1246 | + foreach ($users_who_can_edit_courses as $user) { |
|
1247 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
1251 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
1252 | 1252 | $output .= $course_options; |
1253 | 1253 | $output .= '</select>'; |
1254 | 1254 | |
@@ -1263,15 +1263,15 @@ discard block |
||
1263 | 1263 | * @param $query |
1264 | 1264 | * @return $query |
1265 | 1265 | */ |
1266 | - public function teacher_filter_query_modify( $query ){ |
|
1266 | + public function teacher_filter_query_modify($query) { |
|
1267 | 1267 | global $typenow; |
1268 | 1268 | |
1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1269 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1270 | 1270 | return $query; |
1271 | 1271 | } |
1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1272 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1273 | 1273 | |
1274 | - if( empty( $course_teacher ) ) { |
|
1274 | + if (empty($course_teacher)) { |
|
1275 | 1275 | return $query; |
1276 | 1276 | } |
1277 | 1277 | |
@@ -1284,23 +1284,23 @@ discard block |
||
1284 | 1284 | * @param array $request Default request arguments |
1285 | 1285 | * @return array Modified request arguments |
1286 | 1286 | */ |
1287 | - public function restrict_media_library( $request = array() ) { |
|
1287 | + public function restrict_media_library($request = array()) { |
|
1288 | 1288 | |
1289 | - if( ! is_admin() ) { |
|
1289 | + if ( ! is_admin()) { |
|
1290 | 1290 | return $request; |
1291 | 1291 | } |
1292 | 1292 | |
1293 | - if( ! $this->is_admin_teacher() ) { |
|
1293 | + if ( ! $this->is_admin_teacher()) { |
|
1294 | 1294 | return $request; |
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | $screen = get_current_screen(); |
1298 | 1298 | |
1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
1300 | - $teacher = intval( get_current_user_id() ); |
|
1299 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
1300 | + $teacher = intval(get_current_user_id()); |
|
1301 | 1301 | |
1302 | - if( $teacher ) { |
|
1303 | - $request['author__in'] = array( $teacher ); |
|
1302 | + if ($teacher) { |
|
1303 | + $request['author__in'] = array($teacher); |
|
1304 | 1304 | } |
1305 | 1305 | } |
1306 | 1306 | |
@@ -1312,20 +1312,20 @@ discard block |
||
1312 | 1312 | * @param array $query Default query arguments |
1313 | 1313 | * @return array Modified query arguments |
1314 | 1314 | */ |
1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
1315 | + public function restrict_media_library_modal($query = array()) { |
|
1316 | 1316 | |
1317 | - if( ! is_admin() ) { |
|
1317 | + if ( ! is_admin()) { |
|
1318 | 1318 | return $query; |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - if( ! $this->is_admin_teacher() ) { |
|
1321 | + if ( ! $this->is_admin_teacher()) { |
|
1322 | 1322 | return $query; |
1323 | 1323 | } |
1324 | 1324 | |
1325 | - $teacher = intval( get_current_user_id() ); |
|
1325 | + $teacher = intval(get_current_user_id()); |
|
1326 | 1326 | |
1327 | - if( $teacher ) { |
|
1328 | - $query['author__in'] = array( $teacher ); |
|
1327 | + if ($teacher) { |
|
1328 | + $query['author__in'] = array($teacher); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | 1331 | return $query; |
@@ -1338,28 +1338,28 @@ discard block |
||
1338 | 1338 | * |
1339 | 1339 | * @param int $lesson_id |
1340 | 1340 | */ |
1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
1341 | + public function update_lesson_teacher($lesson_id) { |
|
1342 | 1342 | |
1343 | - if( 'lesson'!= get_post_type() ){ |
|
1343 | + if ('lesson' != get_post_type()) { |
|
1344 | 1344 | return; |
1345 | 1345 | } |
1346 | 1346 | |
1347 | 1347 | // this should only run once per request cycle |
1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
1348 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
1349 | 1349 | |
1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1350 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
1351 | 1351 | |
1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
1352 | + if (empty($course_id) || ! $course_id) { |
|
1353 | 1353 | return; |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $course = get_post( $course_id ); |
|
1356 | + $course = get_post($course_id); |
|
1357 | 1357 | |
1358 | - $lesson_update_args= array( |
|
1359 | - 'ID' => $lesson_id , |
|
1358 | + $lesson_update_args = array( |
|
1359 | + 'ID' => $lesson_id, |
|
1360 | 1360 | 'post_author' => $course->post_author |
1361 | 1361 | ); |
1362 | - wp_update_post( $lesson_update_args ); |
|
1362 | + wp_update_post($lesson_update_args); |
|
1363 | 1363 | |
1364 | 1364 | } // end update_lesson_teacher |
1365 | 1365 | |
@@ -1373,21 +1373,21 @@ discard block |
||
1373 | 1373 | * @parameters array $wp_query |
1374 | 1374 | * @return WP_Query $wp_query |
1375 | 1375 | */ |
1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
1376 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
1377 | 1377 | global $current_user; |
1378 | 1378 | |
1379 | 1379 | //exit early |
1380 | - if( ! $this->is_admin_teacher() ){ |
|
1380 | + if ( ! $this->is_admin_teacher()) { |
|
1381 | 1381 | return $wp_query; |
1382 | 1382 | } |
1383 | 1383 | |
1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
1384 | + if ( ! function_exists('get_current_screen')) { |
|
1385 | 1385 | return $wp_query; |
1386 | 1386 | } |
1387 | 1387 | |
1388 | 1388 | $screen = get_current_screen(); |
1389 | 1389 | |
1390 | - if( empty( $screen ) ){ |
|
1390 | + if (empty($screen)) { |
|
1391 | 1391 | return $wp_query; |
1392 | 1392 | } |
1393 | 1393 | |
@@ -1400,10 +1400,10 @@ discard block |
||
1400 | 1400 | 'lesson_page_lesson-order', |
1401 | 1401 | ); |
1402 | 1402 | |
1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
1403 | + if (in_array($screen->id, $limit_screens)) { |
|
1404 | 1404 | |
1405 | 1405 | // set the query author to the current user to only show those those posts |
1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
1406 | + $wp_query->set('author', $current_user->ID); |
|
1407 | 1407 | } |
1408 | 1408 | |
1409 | 1409 | return $wp_query; |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | * @return void |
1424 | 1424 | */ |
1425 | 1425 | |
1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
1426 | + public function teacher_login_redirect($user_login, $user) { |
|
1427 | 1427 | |
1428 | 1428 | if (user_can($user, 'edit_courses')) { |
1429 | 1429 | |
@@ -1473,9 +1473,9 @@ discard block |
||
1473 | 1473 | * @param bool $restrict default true |
1474 | 1474 | */ |
1475 | 1475 | |
1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
1477 | 1477 | |
1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
1478 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
1479 | 1479 | |
1480 | 1480 | remove_menu_page('edit.php'); |
1481 | 1481 | |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | |
1510 | 1510 | global $pagenow; |
1511 | 1511 | |
1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
1512 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
1513 | 1513 | |
1514 | 1514 | $clauses->query_vars['post_author'] = get_current_user_id(); |
1515 | 1515 | |
@@ -1526,15 +1526,15 @@ discard block |
||
1526 | 1526 | * |
1527 | 1527 | * @return bool |
1528 | 1528 | */ |
1529 | - public static function is_a_teacher( $user_id ){ |
|
1529 | + public static function is_a_teacher($user_id) { |
|
1530 | 1530 | |
1531 | 1531 | $user = get_user_by('id', $user_id); |
1532 | 1532 | |
1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
1533 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
1534 | 1534 | |
1535 | 1535 | return true; |
1536 | 1536 | |
1537 | - }else{ |
|
1537 | + } else { |
|
1538 | 1538 | |
1539 | 1539 | return false; |
1540 | 1540 | |
@@ -1547,14 +1547,14 @@ discard block |
||
1547 | 1547 | * |
1548 | 1548 | * @since 1.9.0 |
1549 | 1549 | */ |
1550 | - public static function archive_title(){ |
|
1550 | + public static function archive_title() { |
|
1551 | 1551 | |
1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
1552 | + $author = get_user_by('id', get_query_var('author')); |
|
1553 | 1553 | $author_name = $author->display_name; |
1554 | 1554 | ?> |
1555 | 1555 | <h2 class="teacher-archive-title"> |
1556 | 1556 | |
1557 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
1557 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
1558 | 1558 | |
1559 | 1559 | </h2> |
1560 | 1560 | <?php |
@@ -1566,9 +1566,9 @@ discard block |
||
1566 | 1566 | * |
1567 | 1567 | * @since 1.9.0 |
1568 | 1568 | */ |
1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
1569 | + public static function remove_course_meta_on_teacher_archive() { |
|
1570 | 1570 | |
1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1571 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
1572 | 1572 | |
1573 | 1573 | } |
1574 | 1574 |
@@ -40,16 +40,16 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Administration Class |
@@ -21,51 +21,51 @@ discard block |
||
21 | 21 | * @since 1.0.0 |
22 | 22 | * @return void |
23 | 23 | */ |
24 | - public function __construct () { |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | 26 | //register admin styles |
27 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) ); |
|
27 | + add_action('admin_enqueue_scripts', array($this, 'admin_styles_global')); |
|
28 | 28 | |
29 | 29 | //register admin scripts |
30 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
30 | + add_action('admin_enqueue_scripts', array($this, 'register_scripts')); |
|
31 | 31 | |
32 | - add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) ); |
|
33 | - add_action( 'settings_before_form', array( $this, 'install_pages_output' ) ); |
|
34 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
35 | - add_action( 'menu_order', array( $this, 'admin_menu_order' ) ); |
|
36 | - add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) ); |
|
37 | - add_action( 'admin_init', array( $this, 'page_redirect' ) ); |
|
38 | - add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) ); |
|
39 | - add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
32 | + add_action('admin_print_styles', array($this, 'admin_notices_styles')); |
|
33 | + add_action('settings_before_form', array($this, 'install_pages_output')); |
|
34 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
35 | + add_action('menu_order', array($this, 'admin_menu_order')); |
|
36 | + add_action('admin_head', array($this, 'admin_menu_highlight')); |
|
37 | + add_action('admin_init', array($this, 'page_redirect')); |
|
38 | + add_action('admin_init', array($this, 'sensei_add_custom_menu_items')); |
|
39 | + add_action('admin_init', array(__CLASS__, 'install_pages')); |
|
40 | 40 | |
41 | 41 | // Duplicate lesson & courses |
42 | - add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 ); |
|
43 | - add_action( 'admin_action_duplicate_lesson', array( $this, 'duplicate_lesson_action' ) ); |
|
44 | - add_action( 'admin_action_duplicate_course', array( $this, 'duplicate_course_action' ) ); |
|
45 | - add_action( 'admin_action_duplicate_course_with_lessons', array( $this, 'duplicate_course_with_lessons_action' ) ); |
|
42 | + add_filter('post_row_actions', array($this, 'duplicate_action_link'), 10, 2); |
|
43 | + add_action('admin_action_duplicate_lesson', array($this, 'duplicate_lesson_action')); |
|
44 | + add_action('admin_action_duplicate_course', array($this, 'duplicate_course_action')); |
|
45 | + add_action('admin_action_duplicate_course_with_lessons', array($this, 'duplicate_course_with_lessons_action')); |
|
46 | 46 | |
47 | 47 | // Handle lessons list table filtering |
48 | - add_action( 'restrict_manage_posts', array( $this, 'lesson_filter_options' ) ); |
|
49 | - add_filter( 'request', array( $this, 'lesson_filter_actions' ) ); |
|
48 | + add_action('restrict_manage_posts', array($this, 'lesson_filter_options')); |
|
49 | + add_filter('request', array($this, 'lesson_filter_actions')); |
|
50 | 50 | |
51 | 51 | // Add Sensei items to 'at a glance' widget |
52 | - add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); |
|
52 | + add_filter('dashboard_glance_items', array($this, 'glance_items'), 10, 1); |
|
53 | 53 | |
54 | 54 | // Handle course and lesson deletions |
55 | - add_action( 'trash_course', array( $this, 'delete_content' ), 10, 2 ); |
|
56 | - add_action( 'trash_lesson', array( $this, 'delete_content' ), 10, 2 ); |
|
55 | + add_action('trash_course', array($this, 'delete_content'), 10, 2); |
|
56 | + add_action('trash_lesson', array($this, 'delete_content'), 10, 2); |
|
57 | 57 | |
58 | 58 | // Delete user activity when user is deleted |
59 | - add_action( 'deleted_user', array( $this, 'delete_user_activity' ), 10, 1 ); |
|
59 | + add_action('deleted_user', array($this, 'delete_user_activity'), 10, 1); |
|
60 | 60 | |
61 | 61 | // Add notices to WP dashboard |
62 | - add_action( 'admin_notices', array( $this, 'theme_compatibility_notices' ) ); |
|
62 | + add_action('admin_notices', array($this, 'theme_compatibility_notices')); |
|
63 | 63 | |
64 | 64 | // Reset theme notices when switching themes |
65 | - add_action( 'switch_theme', array( $this, 'reset_theme_check_notices' ) ); |
|
65 | + add_action('switch_theme', array($this, 'reset_theme_check_notices')); |
|
66 | 66 | |
67 | 67 | // Allow Teacher access the admin area |
68 | - add_filter( 'woocommerce_prevent_admin_access', array( $this, 'admin_access' ) ); |
|
68 | + add_filter('woocommerce_prevent_admin_access', array($this, 'admin_access')); |
|
69 | 69 | |
70 | 70 | } // End __construct() |
71 | 71 | |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | public function admin_menu() { |
78 | 78 | global $menu; |
79 | 79 | $menu_cap = ''; |
80 | - if( current_user_can( 'manage_sensei' ) ) { |
|
80 | + if (current_user_can('manage_sensei')) { |
|
81 | 81 | $menu_cap = 'manage_sensei'; |
82 | 82 | } else { |
83 | - if( current_user_can( 'manage_sensei_grades' ) ) { |
|
83 | + if (current_user_can('manage_sensei_grades')) { |
|
84 | 84 | $menu_cap = 'manage_sensei_grades'; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if( $menu_cap ) { |
|
89 | - $menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' ); |
|
90 | - add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
88 | + if ($menu_cap) { |
|
89 | + $menu[] = array('', 'read', 'separator-sensei', '', 'wp-menu-separator sensei'); |
|
90 | + add_menu_page('Sensei', 'Sensei', $menu_cap, 'sensei', array(Sensei()->analysis, 'analysis_page'), '', '50'); |
|
91 | 91 | } |
92 | 92 | |
93 | - add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) ); |
|
94 | - add_submenu_page( 'edit.php?post_type=lesson', __( 'Order Lessons', 'woothemes-sensei' ), __( 'Order Lessons', 'woothemes-sensei' ), 'edit_lessons', 'lesson-order', array( $this, 'lesson_order_screen' ) ); |
|
93 | + add_submenu_page('edit.php?post_type=course', __('Order Courses', 'woothemes-sensei'), __('Order Courses', 'woothemes-sensei'), 'manage_sensei', 'course-order', array($this, 'course_order_screen')); |
|
94 | + add_submenu_page('edit.php?post_type=lesson', __('Order Lessons', 'woothemes-sensei'), __('Order Lessons', 'woothemes-sensei'), 'edit_lessons', 'lesson-order', array($this, 'lesson_order_screen')); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | * @param array $menu_order Existing menu order |
101 | 101 | * @return array Modified menu order for Sensei |
102 | 102 | */ |
103 | - public function admin_menu_order( $menu_order ) { |
|
103 | + public function admin_menu_order($menu_order) { |
|
104 | 104 | |
105 | 105 | // Initialize our custom order array |
106 | 106 | $sensei_menu_order = array(); |
107 | 107 | |
108 | 108 | // Get the index of our custom separator |
109 | - $sensei_separator = array_search( 'separator-sensei', $menu_order ); |
|
109 | + $sensei_separator = array_search('separator-sensei', $menu_order); |
|
110 | 110 | |
111 | 111 | // Loop through menu order and do some rearranging |
112 | - foreach ( $menu_order as $index => $item ) : |
|
112 | + foreach ($menu_order as $index => $item) : |
|
113 | 113 | |
114 | - if ( ( ( 'sensei' ) == $item ) ) : |
|
114 | + if ((('sensei') == $item)) : |
|
115 | 115 | $sensei_menu_order[] = 'separator-sensei'; |
116 | 116 | $sensei_menu_order[] = $item; |
117 | - unset( $menu_order[$sensei_separator] ); |
|
118 | - elseif ( !in_array( $item, array( 'separator-sensei' ) ) ) : |
|
117 | + unset($menu_order[$sensei_separator]); |
|
118 | + elseif ( ! in_array($item, array('separator-sensei'))) : |
|
119 | 119 | $sensei_menu_order[] = $item; |
120 | 120 | endif; |
121 | 121 | |
@@ -135,24 +135,24 @@ discard block |
||
135 | 135 | |
136 | 136 | $screen = get_current_screen(); |
137 | 137 | |
138 | - if ( $screen->base == 'post' && $post_type == 'course' ) { |
|
138 | + if ($screen->base == 'post' && $post_type == 'course') { |
|
139 | 139 | |
140 | - $parent_file = 'edit.php?post_type=course'; |
|
140 | + $parent_file = 'edit.php?post_type=course'; |
|
141 | 141 | |
142 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'course-category' ) { |
|
142 | + } elseif ($screen->base == 'edit-tags' && $taxonomy == 'course-category') { |
|
143 | 143 | |
144 | 144 | $submenu_file = 'edit-tags.php?taxonomy=course-category&post_type=course'; |
145 | 145 | $parent_file = 'edit.php?post_type=course'; |
146 | 146 | |
147 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
147 | + } elseif ($screen->base == 'edit-tags' && $taxonomy == 'module') { |
|
148 | 148 | |
149 | 149 | $submenu_file = 'edit-tags.php?taxonomy=module'; |
150 | 150 | $parent_file = 'edit.php?post_type=course'; |
151 | 151 | |
152 | - } elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) { |
|
152 | + } elseif (in_array($screen->id, array('sensei_message', 'edit-sensei_message'))) { |
|
153 | 153 | |
154 | 154 | $submenu_file = 'edit.php?post_type=sensei_message'; |
155 | - $parent_file = 'sensei'; |
|
155 | + $parent_file = 'sensei'; |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | } |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @return void |
164 | 164 | */ |
165 | 165 | public function page_redirect() { |
166 | - if( isset( $_GET['page'] ) && $_GET['page'] == 'sensei' ) { |
|
167 | - wp_safe_redirect( 'admin.php?page=sensei_analysis' ); |
|
166 | + if (isset($_GET['page']) && $_GET['page'] == 'sensei') { |
|
167 | + wp_safe_redirect('admin.php?page=sensei_analysis'); |
|
168 | 168 | exit; |
169 | 169 | } |
170 | 170 | } |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | */ |
180 | 180 | function install_pages_output() { |
181 | 181 | |
182 | - if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
182 | + if (isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
183 | 183 | |
184 | 184 | ?> |
185 | 185 | <div id="message" class="updated sensei-message sensei-connect"> |
186 | - <p><?php _e( '<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p> |
|
186 | + <p><?php _e('<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei'); ?></p> |
|
187 | 187 | <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a> |
188 | 188 | <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p> |
189 | 189 | </div> |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | * @param int $post_parent (default: 0) |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - function create_page( $slug, $option, $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
208 | + function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0) { |
|
209 | 209 | global $wpdb; |
210 | 210 | |
211 | - $option_value = get_option( $option ); |
|
211 | + $option_value = get_option($option); |
|
212 | 212 | |
213 | - if ( $option_value > 0 && get_post( $option_value ) ) |
|
213 | + if ($option_value > 0 && get_post($option_value)) |
|
214 | 214 | return; |
215 | 215 | |
216 | - $page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
217 | - if ( $page_found ) : |
|
218 | - if ( ! $option_value ) |
|
219 | - update_option( $option, $page_found ); |
|
216 | + $page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->posts." WHERE post_name = %s LIMIT 1;", $slug)); |
|
217 | + if ($page_found) : |
|
218 | + if ( ! $option_value) |
|
219 | + update_option($option, $page_found); |
|
220 | 220 | return; |
221 | 221 | endif; |
222 | 222 | |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | 'post_parent' => $post_parent, |
231 | 231 | 'comment_status' => 'closed' |
232 | 232 | ); |
233 | - $page_id = wp_insert_post( $page_data ); |
|
233 | + $page_id = wp_insert_post($page_data); |
|
234 | 234 | |
235 | - update_option( $option, $page_id ); |
|
235 | + update_option($option, $page_id); |
|
236 | 236 | } // End create_page() |
237 | 237 | |
238 | 238 | |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | function create_pages() { |
246 | 246 | |
247 | 247 | // Courses page |
248 | - $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), $this->token . '_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' ); |
|
248 | + $this->create_page(esc_sql(_x('courses-overview', 'page_slug', 'woothemes-sensei')), $this->token.'_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]'); |
|
249 | 249 | |
250 | 250 | // User Dashboard page |
251 | - $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), $this->token . '_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' ); |
|
251 | + $this->create_page(esc_sql(_x('my-courses', 'page_slug', 'woothemes-sensei')), $this->token.'_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]'); |
|
252 | 252 | |
253 | 253 | } // End create_pages() |
254 | 254 | |
@@ -258,25 +258,25 @@ discard block |
||
258 | 258 | * @since 1.0.0 |
259 | 259 | * @return void |
260 | 260 | */ |
261 | - public function admin_styles_global ( $hook ) { |
|
261 | + public function admin_styles_global($hook) { |
|
262 | 262 | global $post_type; |
263 | 263 | |
264 | - $allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) ); |
|
265 | - $allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) ); |
|
266 | - $allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order' ) ); |
|
264 | + $allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question')); |
|
265 | + $allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php')); |
|
266 | + $allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order')); |
|
267 | 267 | |
268 | 268 | // Global Styles for icons and menu items |
269 | - wp_register_style( Sensei()->token . '-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' ); |
|
270 | - wp_enqueue_style( Sensei()->token . '-global' ); |
|
269 | + wp_register_style(Sensei()->token.'-global', Sensei()->plugin_url.'assets/css/global.css', '', Sensei()->version, 'screen'); |
|
270 | + wp_enqueue_style(Sensei()->token.'-global'); |
|
271 | 271 | |
272 | 272 | // Select 2 styles |
273 | - wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
273 | + wp_enqueue_style('select2', Sensei()->plugin_url.'assets/css/select2/select2.css', '', Sensei()->version, 'screen'); |
|
274 | 274 | |
275 | 275 | // Test for Write Panel Pages |
276 | - if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) { |
|
276 | + if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) { |
|
277 | 277 | |
278 | - wp_register_style( Sensei()->token . '-admin-custom', Sensei()->plugin_url . 'assets/css/admin-custom.css', '', Sensei()->version, 'screen' ); |
|
279 | - wp_enqueue_style( Sensei()->token . '-admin-custom' ); |
|
278 | + wp_register_style(Sensei()->token.'-admin-custom', Sensei()->plugin_url.'assets/css/admin-custom.css', '', Sensei()->version, 'screen'); |
|
279 | + wp_enqueue_style(Sensei()->token.'-admin-custom'); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | * @since 1.8.2 |
292 | 292 | * @access public |
293 | 293 | */ |
294 | - public function register_scripts( $hook ){ |
|
294 | + public function register_scripts($hook) { |
|
295 | 295 | |
296 | 296 | $screen = get_current_screen(); |
297 | 297 | |
298 | 298 | // Allow developers to load non-minified versions of scripts |
299 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
299 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
300 | 300 | |
301 | 301 | // Select2 script used to enhance all select boxes |
302 | - wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
302 | + wp_register_script('select2', Sensei()->plugin_url.'/assets/js/select2/select2'.$suffix.'.js', array('jquery'), Sensei()->version); |
|
303 | 303 | |
304 | 304 | // load edit module scripts |
305 | - if( 'edit-module' == $screen->id ){ |
|
305 | + if ('edit-module' == $screen->id) { |
|
306 | 306 | |
307 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
307 | + wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery.min.js', array('jquery', 'sensei-chosen'), Sensei()->version, true); |
|
308 | 308 | |
309 | 309 | } |
310 | 310 | |
@@ -322,19 +322,19 @@ discard block |
||
322 | 322 | <div id="message" class="updated sensei-message sensei-connect"> |
323 | 323 | |
324 | 324 | <p> |
325 | - <?php _e( '<strong>Welcome to Sensei</strong> – You\'re almost ready to create some courses!', 'woothemes-sensei' ); ?> |
|
325 | + <?php _e('<strong>Welcome to Sensei</strong> – You\'re almost ready to create some courses!', 'woothemes-sensei'); ?> |
|
326 | 326 | </p> |
327 | 327 | |
328 | 328 | <p class="submit"> |
329 | 329 | |
330 | - <a href="<?php echo esc_url( add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings') ) ); ?>" |
|
330 | + <a href="<?php echo esc_url(add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>" |
|
331 | 331 | class="button-primary"> |
332 | 332 | |
333 | - <?php _e( 'Install Sensei Pages', 'woothemes-sensei' ); ?> |
|
333 | + <?php _e('Install Sensei Pages', 'woothemes-sensei'); ?> |
|
334 | 334 | |
335 | 335 | </a> |
336 | 336 | |
337 | - <a class="skip button" href="<?php echo esc_url( add_query_arg( 'skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings' ) ) ); ?>"> |
|
337 | + <a class="skip button" href="<?php echo esc_url(add_query_arg('skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>"> |
|
338 | 338 | |
339 | 339 | <?php _e('Skip setup', 'woothemes-sensei'); ?> |
340 | 340 | |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | <div id="message" class="updated sensei-message sensei-connect"> |
358 | 358 | |
359 | 359 | <p> |
360 | - <?php _e( '<strong>Sensei has been installed</strong> – You\'re ready to start creating courses!', 'woothemes-sensei' ); ?> |
|
360 | + <?php _e('<strong>Sensei has been installed</strong> – You\'re ready to start creating courses!', 'woothemes-sensei'); ?> |
|
361 | 361 | </p> |
362 | 362 | |
363 | 363 | <p class="submit"> |
364 | - <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woothemes-sensei' ); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/"> |
|
364 | + <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e('Settings', 'woothemes-sensei'); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/"> |
|
365 | 365 | <?php _e('Documentation', 'woothemes-sensei'); ?> |
366 | 366 | </a> |
367 | 367 | </p> |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | public function language_pack_install_notice() { |
395 | 395 | ?> |
396 | 396 | <div id="message" class="updated sensei-message sensei-connect"> |
397 | - <p><?php _e( '<strong>Sensei in your language</strong> – There is a translation available for your language.', 'woothemes-sensei' ); ?><p> |
|
397 | + <p><?php _e('<strong>Sensei in your language</strong> – There is a translation available for your language.', 'woothemes-sensei'); ?><p> |
|
398 | 398 | |
399 | 399 | <p class="submit"> |
400 | - <a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_install_uri() ); ?>" class="button-primary"><?php _e( 'Install', 'woothemes-sensei' ); ?></a> |
|
401 | - <a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_dismiss_uri() ) ?>" class="docs button"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?></a> |
|
400 | + <a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_install_uri()); ?>" class="button-primary"><?php _e('Install', 'woothemes-sensei'); ?></a> |
|
401 | + <a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_dismiss_uri()) ?>" class="docs button"><?php _e('Hide this notice', 'woothemes-sensei'); ?></a> |
|
402 | 402 | </p> |
403 | 403 | </div> |
404 | 404 | <?php |
@@ -414,20 +414,20 @@ discard block |
||
414 | 414 | function admin_notices_styles() { |
415 | 415 | |
416 | 416 | // Installed notices |
417 | - if ( 1 == get_option( 'sensei_installed' ) ) { |
|
417 | + if (1 == get_option('sensei_installed')) { |
|
418 | 418 | |
419 | - wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
419 | + wp_enqueue_style('sensei-activation', plugins_url('/assets/css/activation.css', dirname(__FILE__)), '', Sensei()->version); |
|
420 | 420 | |
421 | - if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
422 | - add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
423 | - } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
424 | - add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
421 | + if (get_option('skip_install_sensei_pages') != 1 && Sensei()->get_page_id('course') < 1 && ! isset($_GET['install_sensei_pages']) && ! isset($_GET['skip_install_sensei_pages'])) { |
|
422 | + add_action('admin_notices', array($this, 'admin_install_notice')); |
|
423 | + } elseif ( ! isset($_GET['page']) || $_GET['page'] != 'woothemes-sensei-settings') { |
|
424 | + add_action('admin_notices', array($this, 'admin_installed_notice')); |
|
425 | 425 | } // End If Statement |
426 | 426 | |
427 | 427 | } // End If Statement |
428 | 428 | |
429 | - if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
430 | - add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
429 | + if (Sensei_Language_Pack_Manager::has_language_pack_available()) { |
|
430 | + add_action('admin_notices', array($this, 'language_pack_install_notice')); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | } // End admin_notices_styles() |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | * @param object $post Current post |
439 | 439 | * @return array Modified actions |
440 | 440 | */ |
441 | - public function duplicate_action_link( $actions, $post ) { |
|
442 | - switch( $post->post_type ) { |
|
441 | + public function duplicate_action_link($actions, $post) { |
|
442 | + switch ($post->post_type) { |
|
443 | 443 | case 'lesson': |
444 | - $confirm = __( 'This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei' ); |
|
445 | - $actions['duplicate'] = "<a onclick='return confirm(\"" . $confirm . "\");' href='" . $this->get_duplicate_link( $post->ID ) . "' title='" . esc_attr(__( 'Duplicate this lesson', 'woothemes-sensei' ) ) . "'>" . __('Duplicate', 'woothemes-sensei' ) . "</a>"; |
|
444 | + $confirm = __('This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei'); |
|
445 | + $actions['duplicate'] = "<a onclick='return confirm(\"".$confirm."\");' href='".$this->get_duplicate_link($post->ID)."' title='".esc_attr(__('Duplicate this lesson', 'woothemes-sensei'))."'>".__('Duplicate', 'woothemes-sensei')."</a>"; |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | case 'course': |
449 | - $confirm = __( 'This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei' ); |
|
450 | - $actions['duplicate'] = '<a href="' . $this->get_duplicate_link( $post->ID ) . '" title="' . esc_attr(__( 'Duplicate this course', 'woothemes-sensei' ) ) . '">' . __('Duplicate', 'woothemes-sensei' ) . '</a>'; |
|
451 | - $actions['duplicate_with_lessons'] = '<a onclick="return confirm(\'' . $confirm . '\');" href="' . $this->get_duplicate_link( $post->ID, true ) . '" title="' . esc_attr(__( 'Duplicate this course with its lessons', 'woothemes-sensei' ) ) . '">' . __('Duplicate (with lessons)', 'woothemes-sensei' ) . '</a>'; |
|
449 | + $confirm = __('This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei'); |
|
450 | + $actions['duplicate'] = '<a href="'.$this->get_duplicate_link($post->ID).'" title="'.esc_attr(__('Duplicate this course', 'woothemes-sensei')).'">'.__('Duplicate', 'woothemes-sensei').'</a>'; |
|
451 | + $actions['duplicate_with_lessons'] = '<a onclick="return confirm(\''.$confirm.'\');" href="'.$this->get_duplicate_link($post->ID, true).'" title="'.esc_attr(__('Duplicate this course with its lessons', 'woothemes-sensei')).'">'.__('Duplicate (with lessons)', 'woothemes-sensei').'</a>'; |
|
452 | 452 | break; |
453 | 453 | } |
454 | 454 | |
@@ -461,17 +461,17 @@ discard block |
||
461 | 461 | * @param boolean $with_lessons Include lessons or not |
462 | 462 | * @return string Duplication link |
463 | 463 | */ |
464 | - private function get_duplicate_link( $post_id = 0, $with_lessons = false ) { |
|
464 | + private function get_duplicate_link($post_id = 0, $with_lessons = false) { |
|
465 | 465 | |
466 | - $post = get_post( $post_id ); |
|
466 | + $post = get_post($post_id); |
|
467 | 467 | |
468 | - $action = 'duplicate_' . $post->post_type; |
|
468 | + $action = 'duplicate_'.$post->post_type; |
|
469 | 469 | |
470 | - if( 'course' == $post->post_type && $with_lessons ) { |
|
470 | + if ('course' == $post->post_type && $with_lessons) { |
|
471 | 471 | $action .= '_with_lessons'; |
472 | 472 | } |
473 | 473 | |
474 | - return apply_filters( $action . '_link', admin_url( 'admin.php?action=' . $action . '&post=' . $post_id ), $post_id ); |
|
474 | + return apply_filters($action.'_link', admin_url('admin.php?action='.$action.'&post='.$post_id), $post_id); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @return void |
480 | 480 | */ |
481 | 481 | public function duplicate_lesson_action() { |
482 | - $this->duplicate_content( 'lesson' ); |
|
482 | + $this->duplicate_content('lesson'); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @return void |
488 | 488 | */ |
489 | 489 | public function duplicate_course_action() { |
490 | - $this->duplicate_content( 'course' ); |
|
490 | + $this->duplicate_content('course'); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @return void |
496 | 496 | */ |
497 | 497 | public function duplicate_course_with_lessons_action() { |
498 | - $this->duplicate_content( 'course', true ); |
|
498 | + $this->duplicate_content('course', true); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -504,34 +504,34 @@ discard block |
||
504 | 504 | * @param boolean $with_lessons Include lessons or not |
505 | 505 | * @return void |
506 | 506 | */ |
507 | - private function duplicate_content( $post_type = 'lesson', $with_lessons = false ) { |
|
508 | - if ( ! isset( $_GET['post'] ) ) { |
|
509 | - wp_die( sprintf( __( 'Please supply a %1$s ID.', 'woothemes-sensei' ) ), $post_type ); |
|
507 | + private function duplicate_content($post_type = 'lesson', $with_lessons = false) { |
|
508 | + if ( ! isset($_GET['post'])) { |
|
509 | + wp_die(sprintf(__('Please supply a %1$s ID.', 'woothemes-sensei')), $post_type); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | $post_id = $_GET['post']; |
513 | - $post = get_post( $post_id ); |
|
513 | + $post = get_post($post_id); |
|
514 | 514 | |
515 | - if( ! is_wp_error( $post ) ) { |
|
515 | + if ( ! is_wp_error($post)) { |
|
516 | 516 | |
517 | - $new_post = $this->duplicate_post( $post ); |
|
517 | + $new_post = $this->duplicate_post($post); |
|
518 | 518 | |
519 | - if( $new_post && ! is_wp_error( $new_post ) ) { |
|
519 | + if ($new_post && ! is_wp_error($new_post)) { |
|
520 | 520 | |
521 | - if( 'lesson' == $new_post->post_type ) { |
|
522 | - $this->duplicate_lesson_quizzes( $post_id, $new_post->ID ); |
|
521 | + if ('lesson' == $new_post->post_type) { |
|
522 | + $this->duplicate_lesson_quizzes($post_id, $new_post->ID); |
|
523 | 523 | } |
524 | 524 | |
525 | - if( 'course' == $new_post->post_type && $with_lessons ) { |
|
526 | - $this->duplicate_course_lessons( $post_id, $new_post->ID ); |
|
525 | + if ('course' == $new_post->post_type && $with_lessons) { |
|
526 | + $this->duplicate_course_lessons($post_id, $new_post->ID); |
|
527 | 527 | } |
528 | 528 | |
529 | - $redirect_url = admin_url( 'post.php?post=' . $new_post->ID . '&action=edit' ); |
|
529 | + $redirect_url = admin_url('post.php?post='.$new_post->ID.'&action=edit'); |
|
530 | 530 | } else { |
531 | - $redirect_url = admin_url( 'edit.php?post_type=' . $post->post_type . '&message=duplicate_failed' ); |
|
531 | + $redirect_url = admin_url('edit.php?post_type='.$post->post_type.'&message=duplicate_failed'); |
|
532 | 532 | } |
533 | 533 | |
534 | - wp_safe_redirect( esc_url_raw( $redirect_url ) ); |
|
534 | + wp_safe_redirect(esc_url_raw($redirect_url)); |
|
535 | 535 | exit; |
536 | 536 | } |
537 | 537 | } |
@@ -542,19 +542,19 @@ discard block |
||
542 | 542 | * @param integer $new_lesson_id ID of duplicate lesson |
543 | 543 | * @return void |
544 | 544 | */ |
545 | - private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) { |
|
545 | + private function duplicate_lesson_quizzes($old_lesson_id, $new_lesson_id) { |
|
546 | 546 | |
547 | - $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
548 | - $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
547 | + $old_quiz_id = Sensei()->lesson->lesson_quizzes($old_lesson_id); |
|
548 | + $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions($old_quiz_id); |
|
549 | 549 | |
550 | 550 | // duplicate the generic wp post information |
551 | - $new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' ); |
|
551 | + $new_quiz = $this->duplicate_post(get_post($old_quiz_id), ''); |
|
552 | 552 | |
553 | 553 | //update the new lesson data |
554 | - add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
554 | + add_post_meta($new_lesson_id, '_lesson_quiz', $new_quiz->ID); |
|
555 | 555 | |
556 | 556 | //update the new quiz data |
557 | - add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
557 | + add_post_meta($new_quiz->ID, '_quiz_lesson', $new_lesson_id); |
|
558 | 558 | wp_update_post( |
559 | 559 | array( |
560 | 560 | 'ID' => $new_quiz->ID, |
@@ -562,15 +562,15 @@ discard block |
||
562 | 562 | ) |
563 | 563 | ); |
564 | 564 | |
565 | - foreach( $old_quiz_questions as $question ) { |
|
565 | + foreach ($old_quiz_questions as $question) { |
|
566 | 566 | |
567 | 567 | // copy the question order over to the new quiz |
568 | - $old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true ); |
|
569 | - $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
570 | - add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
568 | + $old_question_order = get_post_meta($question->ID, '_quiz_question_order'.$old_quiz_id, true); |
|
569 | + $new_question_order = str_ireplace($old_quiz_id, $new_quiz->ID, $old_question_order); |
|
570 | + add_post_meta($question->ID, '_quiz_question_order'.$new_quiz->ID, $new_question_order); |
|
571 | 571 | |
572 | 572 | // Add question to quiz |
573 | - add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false ); |
|
573 | + add_post_meta($question->ID, '_quiz_id', $new_quiz->ID, false); |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @param integer $new_course_id ID of duplicated course |
582 | 582 | * @return void |
583 | 583 | */ |
584 | - private function duplicate_course_lessons( $old_course_id, $new_course_id ) { |
|
584 | + private function duplicate_course_lessons($old_course_id, $new_course_id) { |
|
585 | 585 | $lesson_args = array( |
586 | 586 | 'post_type' => 'lesson', |
587 | 587 | 'posts_per_page' => -1, |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | 'meta_value' => $old_course_id, |
590 | 590 | 'suppress_filters' => 0 |
591 | 591 | ); |
592 | - $lessons = get_posts( $lesson_args ); |
|
592 | + $lessons = get_posts($lesson_args); |
|
593 | 593 | |
594 | - foreach( $lessons as $lesson ) { |
|
595 | - $new_lesson = $this->duplicate_post( $lesson, '', true ); |
|
596 | - add_post_meta( $new_lesson->ID, '_lesson_course', $new_course_id ); |
|
594 | + foreach ($lessons as $lesson) { |
|
595 | + $new_lesson = $this->duplicate_post($lesson, '', true); |
|
596 | + add_post_meta($new_lesson->ID, '_lesson_course', $new_course_id); |
|
597 | 597 | |
598 | - $this->duplicate_lesson_quizzes( $lesson->ID, $new_lesson->ID ); |
|
598 | + $this->duplicate_lesson_quizzes($lesson->ID, $new_lesson->ID); |
|
599 | 599 | } |
600 | 600 | } |
601 | 601 | |
@@ -606,24 +606,24 @@ discard block |
||
606 | 606 | * @param boolean $ignore_course Ignore lesson course when dulicating |
607 | 607 | * @return object Duplicate post object |
608 | 608 | */ |
609 | - private function duplicate_post( $post, $suffix = ' (Duplicate)', $ignore_course = false ) { |
|
609 | + private function duplicate_post($post, $suffix = ' (Duplicate)', $ignore_course = false) { |
|
610 | 610 | |
611 | 611 | $new_post = array(); |
612 | 612 | |
613 | - foreach( $post as $k => $v ) { |
|
614 | - if( ! in_array( $k, array( 'ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count' ) ) ) { |
|
615 | - $new_post[ $k ] = $v; |
|
613 | + foreach ($post as $k => $v) { |
|
614 | + if ( ! in_array($k, array('ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count'))) { |
|
615 | + $new_post[$k] = $v; |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
619 | - $new_post['post_title'] .= __( $suffix, 'woothemes-sensei' ); |
|
619 | + $new_post['post_title'] .= __($suffix, 'woothemes-sensei'); |
|
620 | 620 | |
621 | - $new_post['post_date'] = current_time( 'mysql' ); |
|
622 | - $new_post['post_date_gmt'] = get_gmt_from_date( $new_post['post_date'] ); |
|
621 | + $new_post['post_date'] = current_time('mysql'); |
|
622 | + $new_post['post_date_gmt'] = get_gmt_from_date($new_post['post_date']); |
|
623 | 623 | $new_post['post_modified'] = $new_post['post_date']; |
624 | 624 | $new_post['post_modified_gmt'] = $new_post['post_date_gmt']; |
625 | 625 | |
626 | - switch( $post->post_type ) { |
|
626 | + switch ($post->post_type) { |
|
627 | 627 | case 'course': $new_post['post_status'] = 'draft'; break; |
628 | 628 | case 'lesson': $new_post['post_status'] = 'draft'; break; |
629 | 629 | case 'quiz': $new_post['post_status'] = 'publish'; break; |
@@ -631,45 +631,45 @@ discard block |
||
631 | 631 | } |
632 | 632 | |
633 | 633 | // As per wp_update_post() we need to escape the data from the db. |
634 | - $new_post = wp_slash( $new_post ); |
|
634 | + $new_post = wp_slash($new_post); |
|
635 | 635 | |
636 | - $new_post_id = wp_insert_post( $new_post ); |
|
636 | + $new_post_id = wp_insert_post($new_post); |
|
637 | 637 | |
638 | - if( ! is_wp_error( $new_post_id ) ) { |
|
638 | + if ( ! is_wp_error($new_post_id)) { |
|
639 | 639 | |
640 | - $post_meta = get_post_custom( $post->ID ); |
|
641 | - if( $post_meta && count( $post_meta ) > 0 ) { |
|
640 | + $post_meta = get_post_custom($post->ID); |
|
641 | + if ($post_meta && count($post_meta) > 0) { |
|
642 | 642 | |
643 | - $ignore_meta = array( '_quiz_lesson', '_quiz_id', '_lesson_quiz' ); |
|
643 | + $ignore_meta = array('_quiz_lesson', '_quiz_id', '_lesson_quiz'); |
|
644 | 644 | |
645 | - if( $ignore_course ) { |
|
645 | + if ($ignore_course) { |
|
646 | 646 | $ignore_meta[] = '_lesson_course'; |
647 | 647 | } |
648 | 648 | |
649 | - foreach( $post_meta as $key => $meta ) { |
|
650 | - foreach( $meta as $value ) { |
|
651 | - $value = maybe_unserialize( $value ); |
|
652 | - if( ! in_array( $key, $ignore_meta ) ) { |
|
653 | - add_post_meta( $new_post_id, $key, $value ); |
|
649 | + foreach ($post_meta as $key => $meta) { |
|
650 | + foreach ($meta as $value) { |
|
651 | + $value = maybe_unserialize($value); |
|
652 | + if ( ! in_array($key, $ignore_meta)) { |
|
653 | + add_post_meta($new_post_id, $key, $value); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | - add_post_meta( $new_post_id, '_duplicate', $post->ID ); |
|
659 | + add_post_meta($new_post_id, '_duplicate', $post->ID); |
|
660 | 660 | |
661 | - $taxonomies = get_object_taxonomies( $post->post_type, 'objects' ); |
|
661 | + $taxonomies = get_object_taxonomies($post->post_type, 'objects'); |
|
662 | 662 | |
663 | - foreach ( $taxonomies as $slug => $tax ) { |
|
664 | - $terms = get_the_terms( $post->ID, $slug ); |
|
665 | - if( isset( $terms ) && is_array( $terms ) && 0 < count( $terms ) ) { |
|
666 | - foreach( $terms as $term ) { |
|
667 | - wp_set_object_terms( $new_post_id, $term->term_id, $slug, true ); |
|
663 | + foreach ($taxonomies as $slug => $tax) { |
|
664 | + $terms = get_the_terms($post->ID, $slug); |
|
665 | + if (isset($terms) && is_array($terms) && 0 < count($terms)) { |
|
666 | + foreach ($terms as $term) { |
|
667 | + wp_set_object_terms($new_post_id, $term->term_id, $slug, true); |
|
668 | 668 | } |
669 | 669 | } |
670 | 670 | } |
671 | 671 | |
672 | - $new_post = get_post( $new_post_id ); |
|
672 | + $new_post = get_post($new_post_id); |
|
673 | 673 | |
674 | 674 | return $new_post; |
675 | 675 | } |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | public function lesson_filter_options() { |
685 | 685 | global $typenow; |
686 | 686 | |
687 | - if( is_admin() && 'lesson' == $typenow ) { |
|
687 | + if (is_admin() && 'lesson' == $typenow) { |
|
688 | 688 | |
689 | 689 | $args = array( |
690 | 690 | 'post_type' => 'course', |
@@ -694,16 +694,16 @@ discard block |
||
694 | 694 | 'orderby' => 'menu_order date', |
695 | 695 | 'order' => 'ASC', |
696 | 696 | ); |
697 | - $courses = get_posts( $args ); |
|
697 | + $courses = get_posts($args); |
|
698 | 698 | |
699 | - $selected = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : ''; |
|
699 | + $selected = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : ''; |
|
700 | 700 | $course_options = ''; |
701 | - foreach( $courses as $course ) { |
|
702 | - $course_options .= '<option value="' . esc_attr( $course->ID ) . '" ' . selected( $selected, $course->ID, false ) . '>' . get_the_title( $course->ID ) . '</option>'; |
|
701 | + foreach ($courses as $course) { |
|
702 | + $course_options .= '<option value="'.esc_attr($course->ID).'" '.selected($selected, $course->ID, false).'>'.get_the_title($course->ID).'</option>'; |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | $output = '<select name="lesson_course" id="dropdown_lesson_course">'; |
706 | - $output .= '<option value="">'.__( 'Show all courses', 'woothemes-sensei' ).'</option>'; |
|
706 | + $output .= '<option value="">'.__('Show all courses', 'woothemes-sensei').'</option>'; |
|
707 | 707 | $output .= $course_options; |
708 | 708 | $output .= '</select>'; |
709 | 709 | |
@@ -716,13 +716,13 @@ discard block |
||
716 | 716 | * @param array $request Current request |
717 | 717 | * @return array Modified request |
718 | 718 | */ |
719 | - public function lesson_filter_actions( $request ) { |
|
719 | + public function lesson_filter_actions($request) { |
|
720 | 720 | global $typenow; |
721 | 721 | |
722 | - if( is_admin() && 'lesson' == $typenow ) { |
|
723 | - $lesson_course = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : ''; |
|
722 | + if (is_admin() && 'lesson' == $typenow) { |
|
723 | + $lesson_course = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : ''; |
|
724 | 724 | |
725 | - if( $lesson_course ) { |
|
725 | + if ($lesson_course) { |
|
726 | 726 | $request['meta_key'] = '_lesson_course'; |
727 | 727 | $request['meta_value'] = $lesson_course; |
728 | 728 | $request['meta_compare'] = '='; |
@@ -737,27 +737,27 @@ discard block |
||
737 | 737 | * @param array $items Existing items |
738 | 738 | * @return array Updated items |
739 | 739 | */ |
740 | - public function glance_items( $items = array() ) { |
|
740 | + public function glance_items($items = array()) { |
|
741 | 741 | |
742 | - $types = array( 'course', 'lesson', 'question' ); |
|
742 | + $types = array('course', 'lesson', 'question'); |
|
743 | 743 | |
744 | - foreach( $types as $type ) { |
|
745 | - if( ! post_type_exists( $type ) ) continue; |
|
744 | + foreach ($types as $type) { |
|
745 | + if ( ! post_type_exists($type)) continue; |
|
746 | 746 | |
747 | - $num_posts = wp_count_posts( $type ); |
|
747 | + $num_posts = wp_count_posts($type); |
|
748 | 748 | |
749 | - if( $num_posts ) { |
|
749 | + if ($num_posts) { |
|
750 | 750 | |
751 | - $published = intval( $num_posts->publish ); |
|
752 | - $post_type = get_post_type_object( $type ); |
|
751 | + $published = intval($num_posts->publish); |
|
752 | + $post_type = get_post_type_object($type); |
|
753 | 753 | |
754 | - $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'woothemes-sensei' ); |
|
755 | - $text = sprintf( $text, number_format_i18n( $published ) ); |
|
754 | + $text = _n('%s '.$post_type->labels->singular_name, '%s '.$post_type->labels->name, $published, 'woothemes-sensei'); |
|
755 | + $text = sprintf($text, number_format_i18n($published)); |
|
756 | 756 | |
757 | - if ( current_user_can( $post_type->cap->edit_posts ) ) { |
|
758 | - $items[] = sprintf( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text ) . "\n"; |
|
757 | + if (current_user_can($post_type->cap->edit_posts)) { |
|
758 | + $items[] = sprintf('<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text)."\n"; |
|
759 | 759 | } else { |
760 | - $items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n"; |
|
760 | + $items[] = sprintf('<span class="%1$s-count">%2$s</span>', $type, $text)."\n"; |
|
761 | 761 | } |
762 | 762 | } |
763 | 763 | } |
@@ -771,13 +771,13 @@ discard block |
||
771 | 771 | * @param object $post Post object |
772 | 772 | * @return void |
773 | 773 | */ |
774 | - public function delete_content( $post_id, $post ) { |
|
774 | + public function delete_content($post_id, $post) { |
|
775 | 775 | |
776 | 776 | $type = $post->post_type; |
777 | 777 | |
778 | - if( in_array( $type, array( 'lesson', 'course' ) ) ) { |
|
778 | + if (in_array($type, array('lesson', 'course'))) { |
|
779 | 779 | |
780 | - $meta_key = '_' . $type . '_prerequisite'; |
|
780 | + $meta_key = '_'.$type.'_prerequisite'; |
|
781 | 781 | |
782 | 782 | $args = array( |
783 | 783 | 'post_type' => $type, |
@@ -787,10 +787,10 @@ discard block |
||
787 | 787 | 'meta_value' => $post_id |
788 | 788 | ); |
789 | 789 | |
790 | - $posts = get_posts( $args ); |
|
790 | + $posts = get_posts($args); |
|
791 | 791 | |
792 | - foreach( $posts as $post ) { |
|
793 | - delete_post_meta( $post->ID, $meta_key ); |
|
792 | + foreach ($posts as $post) { |
|
793 | + delete_post_meta($post->ID, $meta_key); |
|
794 | 794 | } |
795 | 795 | } |
796 | 796 | } |
@@ -800,181 +800,181 @@ discard block |
||
800 | 800 | * @param integer $user_id User ID |
801 | 801 | * @return void |
802 | 802 | */ |
803 | - public function delete_user_activity( $user_id = 0 ) { |
|
804 | - if( $user_id ) { |
|
805 | - Sensei_Utils::delete_all_user_activity( $user_id ); |
|
803 | + public function delete_user_activity($user_id = 0) { |
|
804 | + if ($user_id) { |
|
805 | + Sensei_Utils::delete_all_user_activity($user_id); |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
809 | - public function render_settings( $settings = array(), $post_id = 0, $group_id = '' ) { |
|
809 | + public function render_settings($settings = array(), $post_id = 0, $group_id = '') { |
|
810 | 810 | |
811 | 811 | $html = ''; |
812 | 812 | |
813 | - if( 0 == count( $settings ) ) return $html; |
|
813 | + if (0 == count($settings)) return $html; |
|
814 | 814 | |
815 | - $html .= '<div class="sensei-options-panel">' . "\n"; |
|
815 | + $html .= '<div class="sensei-options-panel">'."\n"; |
|
816 | 816 | |
817 | - $html .= '<div class="options_group" id="' . esc_attr( $group_id ) . '">' . "\n"; |
|
817 | + $html .= '<div class="options_group" id="'.esc_attr($group_id).'">'."\n"; |
|
818 | 818 | |
819 | - foreach( $settings as $field ) { |
|
819 | + foreach ($settings as $field) { |
|
820 | 820 | |
821 | 821 | $data = ''; |
822 | 822 | |
823 | - if( $post_id ) { |
|
824 | - $data = get_post_meta( $post_id, '_' . $field['id'], true ); |
|
825 | - if( ! $data && isset( $field['default'] ) ) { |
|
823 | + if ($post_id) { |
|
824 | + $data = get_post_meta($post_id, '_'.$field['id'], true); |
|
825 | + if ( ! $data && isset($field['default'])) { |
|
826 | 826 | $data = $field['default']; |
827 | 827 | } |
828 | 828 | } else { |
829 | - $option = get_option( $field['id'] ); |
|
830 | - if( isset( $field['default'] ) ) { |
|
829 | + $option = get_option($field['id']); |
|
830 | + if (isset($field['default'])) { |
|
831 | 831 | $data = $field['default']; |
832 | - if( $option ) { |
|
832 | + if ($option) { |
|
833 | 833 | $data = $option; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | 838 | $disabled = ''; |
839 | - if( isset( $field['disabled'] ) && $field['disabled'] ) { |
|
840 | - $disabled = disabled( $field['disabled'], true, false ); |
|
839 | + if (isset($field['disabled']) && $field['disabled']) { |
|
840 | + $disabled = disabled($field['disabled'], true, false); |
|
841 | 841 | } |
842 | 842 | |
843 | - if( 'hidden' != $field['type'] ) { |
|
843 | + if ('hidden' != $field['type']) { |
|
844 | 844 | |
845 | 845 | $class_tail = ''; |
846 | 846 | |
847 | - if( isset( $field['class'] ) ) { |
|
847 | + if (isset($field['class'])) { |
|
848 | 848 | $class_tail .= $field['class']; |
849 | 849 | } |
850 | 850 | |
851 | - if( isset( $field['disabled'] ) && $field['disabled'] ) { |
|
851 | + if (isset($field['disabled']) && $field['disabled']) { |
|
852 | 852 | $class_tail .= ' disabled'; |
853 | 853 | } |
854 | 854 | |
855 | - $html .= '<p class="form-field ' . esc_attr( $field['id'] ) . ' ' . esc_attr( $class_tail ) . '">' . "\n"; |
|
855 | + $html .= '<p class="form-field '.esc_attr($field['id']).' '.esc_attr($class_tail).'">'."\n"; |
|
856 | 856 | } |
857 | 857 | |
858 | - if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) { |
|
859 | - $html .= '<label for="' . esc_attr( $field['id'] ) . '">' . "\n"; |
|
858 | + if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) { |
|
859 | + $html .= '<label for="'.esc_attr($field['id']).'">'."\n"; |
|
860 | 860 | } |
861 | 861 | |
862 | - if( $field['label'] ) { |
|
863 | - $html .= '<span class="label">' . esc_html( $field['label'] ) . '</span>'; |
|
862 | + if ($field['label']) { |
|
863 | + $html .= '<span class="label">'.esc_html($field['label']).'</span>'; |
|
864 | 864 | } |
865 | 865 | |
866 | - switch( $field['type'] ) { |
|
866 | + switch ($field['type']) { |
|
867 | 867 | case 'text': |
868 | 868 | case 'password': |
869 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $disabled . ' />' . "\n"; |
|
869 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$disabled.' />'."\n"; |
|
870 | 870 | break; |
871 | 871 | |
872 | 872 | case 'number': |
873 | 873 | |
874 | 874 | $min = ''; |
875 | - if( isset( $field['min'] ) ) { |
|
876 | - $min = 'min="' . esc_attr( $field['min'] ) . '"'; |
|
875 | + if (isset($field['min'])) { |
|
876 | + $min = 'min="'.esc_attr($field['min']).'"'; |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | $max = ''; |
880 | - if( isset( $field['max'] ) ) { |
|
881 | - $max = 'max="' . esc_attr( $field['max'] ) . '"'; |
|
880 | + if (isset($field['max'])) { |
|
881 | + $max = 'max="'.esc_attr($field['max']).'"'; |
|
882 | 882 | } |
883 | 883 | |
884 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $min . ' ' . $max . ' class="small-text" ' . $disabled . ' />' . "\n"; |
|
884 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$min.' '.$max.' class="small-text" '.$disabled.' />'."\n"; |
|
885 | 885 | break; |
886 | 886 | |
887 | 887 | case 'textarea': |
888 | - $html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . $disabled . '>' . $data . '</textarea><br/>'. "\n"; |
|
888 | + $html .= '<textarea id="'.esc_attr($field['id']).'" rows="5" cols="50" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" '.$disabled.'>'.$data.'</textarea><br/>'."\n"; |
|
889 | 889 | break; |
890 | 890 | |
891 | 891 | case 'checkbox': |
892 | 892 | //backwards compatibility |
893 | - if( empty( $data ) || 'on' == $data ){ |
|
893 | + if (empty($data) || 'on' == $data) { |
|
894 | 894 | $checked_value = 'on'; |
895 | - }elseif( 'yes' == $data ) { |
|
895 | + }elseif ('yes' == $data) { |
|
896 | 896 | |
897 | 897 | $checked_value = 'yes'; |
898 | 898 | |
899 | - }elseif( 'auto' == $data ) { |
|
899 | + }elseif ('auto' == $data) { |
|
900 | 900 | |
901 | 901 | $checked_value = 'auto'; |
902 | 902 | |
903 | 903 | } else { |
904 | 904 | $checked_value = 1; |
905 | - $data = intval( $data ); |
|
905 | + $data = intval($data); |
|
906 | 906 | } |
907 | - $checked = checked( $checked_value, $data, false ); |
|
908 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n"; |
|
907 | + $checked = checked($checked_value, $data, false); |
|
908 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" '.$checked.' '.$disabled.'/>'."\n"; |
|
909 | 909 | break; |
910 | 910 | |
911 | 911 | case 'checkbox_multi': |
912 | - foreach( $field['options'] as $k => $v ) { |
|
912 | + foreach ($field['options'] as $k => $v) { |
|
913 | 913 | $checked = false; |
914 | - if( in_array( $k, $data ) ) { |
|
914 | + if (in_array($k, $data)) { |
|
915 | 915 | $checked = true; |
916 | 916 | } |
917 | - $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n"; |
|
917 | + $html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="checkbox" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'[]" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n"; |
|
918 | 918 | } |
919 | 919 | break; |
920 | 920 | |
921 | 921 | case 'radio': |
922 | - foreach( $field['options'] as $k => $v ) { |
|
922 | + foreach ($field['options'] as $k => $v) { |
|
923 | 923 | $checked = false; |
924 | - if( $k == $data ) { |
|
924 | + if ($k == $data) { |
|
925 | 925 | $checked = true; |
926 | 926 | } |
927 | - $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n"; |
|
927 | + $html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="radio" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n"; |
|
928 | 928 | } |
929 | 929 | break; |
930 | 930 | |
931 | 931 | case 'select': |
932 | - $html .= '<select name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" ' . $disabled . '>' . "\n"; |
|
933 | - foreach( $field['options'] as $k => $v ) { |
|
932 | + $html .= '<select name="'.esc_attr($field['id']).'" id="'.esc_attr($field['id']).'" '.$disabled.'>'."\n"; |
|
933 | + foreach ($field['options'] as $k => $v) { |
|
934 | 934 | $selected = false; |
935 | - if( $k == $data ) { |
|
935 | + if ($k == $data) { |
|
936 | 936 | $selected = true; |
937 | 937 | } |
938 | - $html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>' . "\n"; |
|
938 | + $html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'">'.$v.'</option>'."\n"; |
|
939 | 939 | } |
940 | - $html .= '</select><br/>' . "\n"; |
|
940 | + $html .= '</select><br/>'."\n"; |
|
941 | 941 | break; |
942 | 942 | |
943 | 943 | case 'select_multi': |
944 | - $html .= '<select name="' . esc_attr( $field['id'] ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple" ' . $disabled . '>' . "\n"; |
|
945 | - foreach( $field['options'] as $k => $v ) { |
|
944 | + $html .= '<select name="'.esc_attr($field['id']).'[]" id="'.esc_attr($field['id']).'" multiple="multiple" '.$disabled.'>'."\n"; |
|
945 | + foreach ($field['options'] as $k => $v) { |
|
946 | 946 | $selected = false; |
947 | - if( in_array( $k, $data ) ) { |
|
947 | + if (in_array($k, $data)) { |
|
948 | 948 | $selected = true; |
949 | 949 | } |
950 | - $html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '" />' . $v . '</option>' . "\n"; |
|
950 | + $html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'" />'.$v.'</option>'."\n"; |
|
951 | 951 | } |
952 | 952 | $html .= '</select> . "\n"'; |
953 | 953 | break; |
954 | 954 | |
955 | 955 | case 'hidden': |
956 | - $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" value="' . $data . '" ' . $disabled . '/>' . "\n"; |
|
956 | + $html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" value="'.$data.'" '.$disabled.'/>'."\n"; |
|
957 | 957 | break; |
958 | 958 | |
959 | 959 | } |
960 | 960 | |
961 | - if( $field['description'] ) { |
|
962 | - $html .= ' <span class="description">' . esc_html( $field['description'] ) . '</span>' . "\n"; |
|
961 | + if ($field['description']) { |
|
962 | + $html .= ' <span class="description">'.esc_html($field['description']).'</span>'."\n"; |
|
963 | 963 | } |
964 | 964 | |
965 | - if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) { |
|
966 | - $html .= '</label>' . "\n"; |
|
965 | + if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) { |
|
966 | + $html .= '</label>'."\n"; |
|
967 | 967 | } |
968 | 968 | |
969 | - if( 'hidden' != $field['type'] ) { |
|
970 | - $html .= '</p>' . "\n"; |
|
969 | + if ('hidden' != $field['type']) { |
|
970 | + $html .= '</p>'."\n"; |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | } |
974 | 974 | |
975 | - $html .= '</div>' . "\n"; |
|
975 | + $html .= '</div>'."\n"; |
|
976 | 976 | |
977 | - $html .= '</div>' . "\n"; |
|
977 | + $html .= '</div>'."\n"; |
|
978 | 978 | |
979 | 979 | return $html; |
980 | 980 | } |
@@ -985,61 +985,61 @@ discard block |
||
985 | 985 | */ |
986 | 986 | public function course_order_screen() { |
987 | 987 | |
988 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
989 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version ); |
|
988 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
989 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version); |
|
990 | 990 | |
991 | 991 | ?><div id="course-order" class="wrap course-order"> |
992 | - <h2><?php _e( 'Order Courses', 'woothemes-sensei' ); ?></h2><?php |
|
992 | + <h2><?php _e('Order Courses', 'woothemes-sensei'); ?></h2><?php |
|
993 | 993 | |
994 | 994 | $html = ''; |
995 | 995 | |
996 | - if( isset( $_POST['course-order'] ) && 0 < strlen( $_POST['course-order'] ) ) { |
|
997 | - $ordered = $this->save_course_order( esc_attr( $_POST['course-order'] ) ); |
|
996 | + if (isset($_POST['course-order']) && 0 < strlen($_POST['course-order'])) { |
|
997 | + $ordered = $this->save_course_order(esc_attr($_POST['course-order'])); |
|
998 | 998 | |
999 | - if( $ordered ) { |
|
1000 | - $html .= '<div class="updated fade">' . "\n"; |
|
1001 | - $html .= '<p>' . __( 'The course order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
1002 | - $html .= '</div>' . "\n"; |
|
999 | + if ($ordered) { |
|
1000 | + $html .= '<div class="updated fade">'."\n"; |
|
1001 | + $html .= '<p>'.__('The course order has been saved.', 'woothemes-sensei').'</p>'."\n"; |
|
1002 | + $html .= '</div>'."\n"; |
|
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | $courses = Sensei()->course->get_all_courses(); |
1007 | 1007 | |
1008 | - if( 0 < count( $courses ) ) { |
|
1008 | + if (0 < count($courses)) { |
|
1009 | 1009 | |
1010 | 1010 | // order the courses as set by the users |
1011 | 1011 | $all_course_ids = array(); |
1012 | - foreach( $courses as $course ){ |
|
1012 | + foreach ($courses as $course) { |
|
1013 | 1013 | |
1014 | - $all_course_ids[] = (string)$course->ID; |
|
1014 | + $all_course_ids[] = (string) $course->ID; |
|
1015 | 1015 | |
1016 | 1016 | } |
1017 | 1017 | $order_string = $this->get_course_order(); |
1018 | 1018 | |
1019 | - if( !empty( $order_string ) ){ |
|
1020 | - $ordered_course_ids = explode(',' , $order_string ); |
|
1021 | - $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1019 | + if ( ! empty($order_string)) { |
|
1020 | + $ordered_course_ids = explode(',', $order_string); |
|
1021 | + $all_course_ids = array_unique(array_merge($ordered_course_ids, $all_course_ids)); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | |
1025 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
1026 | - $html .= '<ul class="sortable-course-list">' . "\n"; |
|
1025 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
1026 | + $html .= '<ul class="sortable-course-list">'."\n"; |
|
1027 | 1027 | $count = 0; |
1028 | - foreach ( $all_course_ids as $course_id ) { |
|
1029 | - $course = get_post( $course_id ); |
|
1028 | + foreach ($all_course_ids as $course_id) { |
|
1029 | + $course = get_post($course_id); |
|
1030 | 1030 | $count++; |
1031 | 1031 | $class = 'course'; |
1032 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1033 | - if ( $count == count( $course ) ) { $class .= ' last'; } |
|
1034 | - if ( $count % 2 != 0 ) { |
|
1032 | + if ($count == 1) { $class .= ' first'; } |
|
1033 | + if ($count == count($course)) { $class .= ' last'; } |
|
1034 | + if ($count % 2 != 0) { |
|
1035 | 1035 | $class .= ' alternate'; |
1036 | 1036 | } |
1037 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $course->ID ) . '" style="width: 100%;"> ' . $course->post_title . '</span></li>' . "\n"; |
|
1037 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($course->ID).'" style="width: 100%;"> '.$course->post_title.'</span></li>'."\n"; |
|
1038 | 1038 | } |
1039 | - $html .= '</ul>' . "\n"; |
|
1039 | + $html .= '</ul>'."\n"; |
|
1040 | 1040 | |
1041 | - $html .= '<input type="hidden" name="course-order" value="' . esc_attr( $order_string ) . '" />' . "\n"; |
|
1042 | - $html .= '<input type="submit" class="button-primary" value="' . __( 'Save course order', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1041 | + $html .= '<input type="hidden" name="course-order" value="'.esc_attr($order_string).'" />'."\n"; |
|
1042 | + $html .= '<input type="submit" class="button-primary" value="'.__('Save course order', 'woothemes-sensei').'" />'."\n"; |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | echo $html; |
@@ -1048,25 +1048,25 @@ discard block |
||
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | public function get_course_order() { |
1051 | - return get_option( 'sensei_course_order', '' ); |
|
1051 | + return get_option('sensei_course_order', ''); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | - public function save_course_order( $order_string = '' ) { |
|
1055 | - $order = explode( ',', $order_string ); |
|
1054 | + public function save_course_order($order_string = '') { |
|
1055 | + $order = explode(',', $order_string); |
|
1056 | 1056 | |
1057 | - update_option( 'sensei_course_order', $order_string ); |
|
1057 | + update_option('sensei_course_order', $order_string); |
|
1058 | 1058 | |
1059 | 1059 | $i = 1; |
1060 | - foreach( $order as $course_id ) { |
|
1060 | + foreach ($order as $course_id) { |
|
1061 | 1061 | |
1062 | - if( $course_id ) { |
|
1062 | + if ($course_id) { |
|
1063 | 1063 | |
1064 | 1064 | $update_args = array( |
1065 | 1065 | 'ID' => $course_id, |
1066 | 1066 | 'menu_order' => $i, |
1067 | 1067 | ); |
1068 | 1068 | |
1069 | - wp_update_post( $update_args ); |
|
1069 | + wp_update_post($update_args); |
|
1070 | 1070 | |
1071 | 1071 | ++$i; |
1072 | 1072 | } |
@@ -1081,22 +1081,22 @@ discard block |
||
1081 | 1081 | */ |
1082 | 1082 | public function lesson_order_screen() { |
1083 | 1083 | |
1084 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1085 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version ); |
|
1084 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
1085 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version); |
|
1086 | 1086 | |
1087 | 1087 | ?><div id="lesson-order" class="wrap lesson-order"> |
1088 | - <h2><?php _e( 'Order Lessons', 'woothemes-sensei' ); ?></h2><?php |
|
1088 | + <h2><?php _e('Order Lessons', 'woothemes-sensei'); ?></h2><?php |
|
1089 | 1089 | |
1090 | 1090 | $html = ''; |
1091 | 1091 | |
1092 | - if( isset( $_POST['lesson-order'] ) ) { |
|
1092 | + if (isset($_POST['lesson-order'])) { |
|
1093 | 1093 | |
1094 | - $ordered = $this->save_lesson_order( esc_attr( $_POST['lesson-order'] ), esc_attr( $_POST['course_id'] ) ); |
|
1094 | + $ordered = $this->save_lesson_order(esc_attr($_POST['lesson-order']), esc_attr($_POST['course_id'])); |
|
1095 | 1095 | |
1096 | - if( $ordered ) { |
|
1097 | - $html .= '<div class="updated fade">' . "\n"; |
|
1098 | - $html .= '<p>' . __( 'The lesson order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
1099 | - $html .= '</div>' . "\n"; |
|
1096 | + if ($ordered) { |
|
1097 | + $html .= '<div class="updated fade">'."\n"; |
|
1098 | + $html .= '<p>'.__('The lesson order has been saved.', 'woothemes-sensei').'</p>'."\n"; |
|
1099 | + $html .= '</div>'."\n"; |
|
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1107,43 +1107,43 @@ discard block |
||
1107 | 1107 | 'orderby' => 'name', |
1108 | 1108 | 'order' => 'ASC', |
1109 | 1109 | ); |
1110 | - $courses = get_posts( $args ); |
|
1110 | + $courses = get_posts($args); |
|
1111 | 1111 | |
1112 | - $html .= '<form action="' . admin_url( 'edit.php' ) . '" method="get">' . "\n"; |
|
1113 | - $html .= '<input type="hidden" name="post_type" value="lesson" />' . "\n"; |
|
1114 | - $html .= '<input type="hidden" name="page" value="lesson-order" />' . "\n"; |
|
1115 | - $html .= '<select id="lesson-order-course" name="course_id">' . "\n"; |
|
1116 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>' . "\n"; |
|
1112 | + $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n"; |
|
1113 | + $html .= '<input type="hidden" name="post_type" value="lesson" />'."\n"; |
|
1114 | + $html .= '<input type="hidden" name="page" value="lesson-order" />'."\n"; |
|
1115 | + $html .= '<select id="lesson-order-course" name="course_id">'."\n"; |
|
1116 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n"; |
|
1117 | 1117 | |
1118 | - foreach( $courses as $course ) { |
|
1118 | + foreach ($courses as $course) { |
|
1119 | 1119 | $course_id = ''; |
1120 | - if( isset( $_GET['course_id'] ) ) { |
|
1121 | - $course_id = intval( $_GET['course_id'] ); |
|
1120 | + if (isset($_GET['course_id'])) { |
|
1121 | + $course_id = intval($_GET['course_id']); |
|
1122 | 1122 | } |
1123 | - $html .= '<option value="' . esc_attr( intval( $course->ID ) ) . '" ' . selected( $course->ID, $course_id, false ) .'>' . get_the_title( $course->ID ) . '</option>' . "\n"; |
|
1123 | + $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n"; |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | - $html .= '</select>' . "\n"; |
|
1127 | - $html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="' . __( 'Select', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1128 | - $html .= '</form>' . "\n"; |
|
1126 | + $html .= '</select>'."\n"; |
|
1127 | + $html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n"; |
|
1128 | + $html .= '</form>'."\n"; |
|
1129 | 1129 | |
1130 | - $html .= '<script type="text/javascript">' . "\n"; |
|
1131 | - $html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});' . "\n"; |
|
1132 | - $html .= '</script>' . "\n"; |
|
1130 | + $html .= '<script type="text/javascript">'."\n"; |
|
1131 | + $html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});'."\n"; |
|
1132 | + $html .= '</script>'."\n"; |
|
1133 | 1133 | |
1134 | - if( isset( $_GET['course_id'] ) ) { |
|
1135 | - $course_id = intval( $_GET['course_id'] ); |
|
1136 | - if( $course_id > 0 ) { |
|
1134 | + if (isset($_GET['course_id'])) { |
|
1135 | + $course_id = intval($_GET['course_id']); |
|
1136 | + if ($course_id > 0) { |
|
1137 | 1137 | |
1138 | - $order_string = $this->get_lesson_order( $course_id ); |
|
1138 | + $order_string = $this->get_lesson_order($course_id); |
|
1139 | 1139 | |
1140 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
1140 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
1141 | 1141 | |
1142 | 1142 | $displayed_lessons = array(); |
1143 | 1143 | |
1144 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1144 | + $modules = Sensei()->modules->get_course_modules(intval($course_id)); |
|
1145 | 1145 | |
1146 | - foreach( $modules as $module ) { |
|
1146 | + foreach ($modules as $module) { |
|
1147 | 1147 | |
1148 | 1148 | $args = array( |
1149 | 1149 | 'post_type' => 'lesson', |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | 'meta_query' => array( |
1153 | 1153 | array( |
1154 | 1154 | 'key' => '_lesson_course', |
1155 | - 'value' => intval( $course_id ), |
|
1155 | + 'value' => intval($course_id), |
|
1156 | 1156 | 'compare' => '=' |
1157 | 1157 | ) |
1158 | 1158 | ), |
@@ -1160,66 +1160,66 @@ discard block |
||
1160 | 1160 | array( |
1161 | 1161 | 'taxonomy' => Sensei()->modules->taxonomy, |
1162 | 1162 | 'field' => 'id', |
1163 | - 'terms' => intval( $module->term_id ) |
|
1163 | + 'terms' => intval($module->term_id) |
|
1164 | 1164 | ) |
1165 | 1165 | ), |
1166 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
1166 | + 'meta_key' => '_order_module_'.$module->term_id, |
|
1167 | 1167 | 'orderby' => 'meta_value_num date', |
1168 | 1168 | 'order' => 'ASC', |
1169 | 1169 | 'suppress_filters' => 0 |
1170 | 1170 | ); |
1171 | 1171 | |
1172 | - $lessons = get_posts( $args ); |
|
1172 | + $lessons = get_posts($args); |
|
1173 | 1173 | |
1174 | - if( count( $lessons ) > 0 ) { |
|
1175 | - $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1176 | - $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1174 | + if (count($lessons) > 0) { |
|
1175 | + $html .= '<h3>'.$module->name.'</h3>'."\n"; |
|
1176 | + $html .= '<ul class="sortable-lesson-list" data-module_id="'.$module->term_id.'">'."\n"; |
|
1177 | 1177 | |
1178 | 1178 | $count = 0; |
1179 | - foreach( $lessons as $lesson ) { |
|
1179 | + foreach ($lessons as $lesson) { |
|
1180 | 1180 | $count++; |
1181 | 1181 | $class = 'lesson'; |
1182 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1183 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1184 | - if ( $count % 2 != 0 ) { |
|
1182 | + if ($count == 1) { $class .= ' first'; } |
|
1183 | + if ($count == count($lesson)) { $class .= ' last'; } |
|
1184 | + if ($count % 2 != 0) { |
|
1185 | 1185 | $class .= ' alternate'; |
1186 | 1186 | } |
1187 | 1187 | |
1188 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1188 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n"; |
|
1189 | 1189 | |
1190 | 1190 | $displayed_lessons[] = $lesson->ID; |
1191 | 1191 | } |
1192 | 1192 | |
1193 | - $html .= '</ul>' . "\n"; |
|
1193 | + $html .= '</ul>'."\n"; |
|
1194 | 1194 | |
1195 | - $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1195 | + $html .= '<input type="hidden" name="lesson-order-module-'.$module->term_id.'" value="" />'."\n"; |
|
1196 | 1196 | } |
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | |
1200 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1200 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1201 | 1201 | |
1202 | - if( 0 < count( $lessons ) ) { |
|
1202 | + if (0 < count($lessons)) { |
|
1203 | 1203 | |
1204 | 1204 | //get module term ids, will be used to exclude lessons |
1205 | 1205 | $module_items_ids = array(); |
1206 | - if( ! empty( $modules ) ) { |
|
1206 | + if ( ! empty($modules)) { |
|
1207 | 1207 | foreach ($modules as $module) { |
1208 | 1208 | $module_items_ids[] = $module->term_id; |
1209 | 1209 | } |
1210 | 1210 | } |
1211 | 1211 | |
1212 | - if( 0 < count( $displayed_lessons ) ) { |
|
1213 | - $html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n"; |
|
1212 | + if (0 < count($displayed_lessons)) { |
|
1213 | + $html .= '<h3>'.__('Other Lessons', 'woothemes-sensei').'</h3>'."\n"; |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | - $html .= '<ul class="sortable-lesson-list" data-module_id="0">' . "\n"; |
|
1216 | + $html .= '<ul class="sortable-lesson-list" data-module_id="0">'."\n"; |
|
1217 | 1217 | $count = 0; |
1218 | - foreach ( $lessons as $lesson ) { |
|
1218 | + foreach ($lessons as $lesson) { |
|
1219 | 1219 | |
1220 | 1220 | // if lesson belongs to one fo the course modules then exclude it here |
1221 | 1221 | // as it is listed above |
1222 | - if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1222 | + if (has_term($module_items_ids, 'module', $lesson->ID)) { |
|
1223 | 1223 | |
1224 | 1224 | continue; |
1225 | 1225 | |
@@ -1227,28 +1227,28 @@ discard block |
||
1227 | 1227 | |
1228 | 1228 | $count++; |
1229 | 1229 | $class = 'lesson'; |
1230 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1231 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1232 | - if ( $count % 2 != 0 ) { |
|
1230 | + if ($count == 1) { $class .= ' first'; } |
|
1231 | + if ($count == count($lesson)) { $class .= ' last'; } |
|
1232 | + if ($count % 2 != 0) { |
|
1233 | 1233 | |
1234 | 1234 | $class .= ' alternate'; |
1235 | 1235 | |
1236 | 1236 | } |
1237 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1237 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n"; |
|
1238 | 1238 | |
1239 | 1239 | $displayed_lessons[] = $lesson->ID; |
1240 | 1240 | } |
1241 | - $html .= '</ul>' . "\n"; |
|
1241 | + $html .= '</ul>'."\n"; |
|
1242 | 1242 | } else { |
1243 | - if( 0 == count( $displayed_lessons ) ) { |
|
1244 | - $html .= '<p><em>' . __( 'There are no lessons in this course.', 'woothemes-sensei' ) . '</em></p>'; |
|
1243 | + if (0 == count($displayed_lessons)) { |
|
1244 | + $html .= '<p><em>'.__('There are no lessons in this course.', 'woothemes-sensei').'</em></p>'; |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - if( 0 < count( $displayed_lessons ) ) { |
|
1249 | - $html .= '<input type="hidden" name="lesson-order" value="' . esc_attr( $order_string ) . '" />' . "\n"; |
|
1250 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
1251 | - $html .= '<input type="submit" class="button-primary" value="' . __( 'Save lesson order', 'woothemes-sensei' ) . '" />' . "\n"; |
|
1248 | + if (0 < count($displayed_lessons)) { |
|
1249 | + $html .= '<input type="hidden" name="lesson-order" value="'.esc_attr($order_string).'" />'."\n"; |
|
1250 | + $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n"; |
|
1251 | + $html .= '<input type="submit" class="button-primary" value="'.__('Save lesson order', 'woothemes-sensei').'" />'."\n"; |
|
1252 | 1252 | } |
1253 | 1253 | } |
1254 | 1254 | } |
@@ -1258,27 +1258,27 @@ discard block |
||
1258 | 1258 | ?></div><?php |
1259 | 1259 | } |
1260 | 1260 | |
1261 | - public function get_lesson_order( $course_id = 0 ) { |
|
1262 | - $order_string = get_post_meta( $course_id, '_lesson_order', true ); |
|
1261 | + public function get_lesson_order($course_id = 0) { |
|
1262 | + $order_string = get_post_meta($course_id, '_lesson_order', true); |
|
1263 | 1263 | return $order_string; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | - public function save_lesson_order( $order_string = '', $course_id = 0 ) { |
|
1266 | + public function save_lesson_order($order_string = '', $course_id = 0) { |
|
1267 | 1267 | |
1268 | - if( $course_id ) { |
|
1268 | + if ($course_id) { |
|
1269 | 1269 | |
1270 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1270 | + $modules = Sensei()->modules->get_course_modules(intval($course_id)); |
|
1271 | 1271 | |
1272 | - foreach( $modules as $module ) { |
|
1272 | + foreach ($modules as $module) { |
|
1273 | 1273 | |
1274 | - $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ]; |
|
1274 | + $module_order_string = $_POST['lesson-order-module-'.$module->term_id]; |
|
1275 | 1275 | |
1276 | - if( $module_order_string ) { |
|
1277 | - $order = explode( ',', $module_order_string ); |
|
1276 | + if ($module_order_string) { |
|
1277 | + $order = explode(',', $module_order_string); |
|
1278 | 1278 | $i = 1; |
1279 | - foreach( $order as $lesson_id ) { |
|
1280 | - if( $lesson_id ) { |
|
1281 | - update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1279 | + foreach ($order as $lesson_id) { |
|
1280 | + if ($lesson_id) { |
|
1281 | + update_post_meta($lesson_id, '_order_module_'.$module->term_id, $i); |
|
1282 | 1282 | ++$i; |
1283 | 1283 | } |
1284 | 1284 | } |
@@ -1286,15 +1286,15 @@ discard block |
||
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | |
1289 | - if( $order_string ) { |
|
1290 | - update_post_meta( $course_id, '_lesson_order', $order_string ); |
|
1289 | + if ($order_string) { |
|
1290 | + update_post_meta($course_id, '_lesson_order', $order_string); |
|
1291 | 1291 | |
1292 | - $order = explode( ',', $order_string ); |
|
1292 | + $order = explode(',', $order_string); |
|
1293 | 1293 | |
1294 | 1294 | $i = 1; |
1295 | - foreach( $order as $lesson_id ) { |
|
1296 | - if( $lesson_id ) { |
|
1297 | - update_post_meta( $lesson_id, '_order_' . $course_id, $i ); |
|
1295 | + foreach ($order as $lesson_id) { |
|
1296 | + if ($lesson_id) { |
|
1297 | + update_post_meta($lesson_id, '_order_'.$course_id, $i); |
|
1298 | 1298 | ++$i; |
1299 | 1299 | } |
1300 | 1300 | } |
@@ -1309,54 +1309,54 @@ discard block |
||
1309 | 1309 | function sensei_add_custom_menu_items() { |
1310 | 1310 | global $pagenow; |
1311 | 1311 | |
1312 | - if( 'nav-menus.php' == $pagenow ) { |
|
1313 | - add_meta_box( 'add-sensei-links', 'Sensei', array( $this, 'wp_nav_menu_item_sensei_links_meta_box' ), 'nav-menus', 'side', 'low' ); |
|
1312 | + if ('nav-menus.php' == $pagenow) { |
|
1313 | + add_meta_box('add-sensei-links', 'Sensei', array($this, 'wp_nav_menu_item_sensei_links_meta_box'), 'nav-menus', 'side', 'low'); |
|
1314 | 1314 | } |
1315 | 1315 | } |
1316 | 1316 | |
1317 | - function wp_nav_menu_item_sensei_links_meta_box( $object ) { |
|
1317 | + function wp_nav_menu_item_sensei_links_meta_box($object) { |
|
1318 | 1318 | global $nav_menu_selected_id; |
1319 | 1319 | |
1320 | 1320 | $menu_items = array( |
1321 | - '#senseicourses' => __( 'Courses', 'woothemes-sensei' ), |
|
1322 | - '#senseilessons' => __( 'Lessons', 'woothemes-sensei' ), |
|
1323 | - '#senseimycourses' => __( 'My Courses', 'woothemes-sensei' ), |
|
1324 | - '#senseilearnerprofile' => __( 'My Profile', 'woothemes-sensei' ), |
|
1325 | - '#senseimymessages' => __( 'My Messages', 'woothemes-sensei' ), |
|
1326 | - '#senseiloginlogout' => __( 'Login', 'woothemes-sensei' ) . '|' . __( 'Logout', 'woothemes-sensei' ) |
|
1321 | + '#senseicourses' => __('Courses', 'woothemes-sensei'), |
|
1322 | + '#senseilessons' => __('Lessons', 'woothemes-sensei'), |
|
1323 | + '#senseimycourses' => __('My Courses', 'woothemes-sensei'), |
|
1324 | + '#senseilearnerprofile' => __('My Profile', 'woothemes-sensei'), |
|
1325 | + '#senseimymessages' => __('My Messages', 'woothemes-sensei'), |
|
1326 | + '#senseiloginlogout' => __('Login', 'woothemes-sensei').'|'.__('Logout', 'woothemes-sensei') |
|
1327 | 1327 | ); |
1328 | 1328 | |
1329 | 1329 | $menu_items_obj = array(); |
1330 | - foreach ( $menu_items as $value => $title ) { |
|
1330 | + foreach ($menu_items as $value => $title) { |
|
1331 | 1331 | $menu_items_obj[$title] = new stdClass; |
1332 | - $menu_items_obj[$title]->object_id = esc_attr( $value ); |
|
1333 | - $menu_items_obj[$title]->title = esc_attr( $title ); |
|
1334 | - $menu_items_obj[$title]->url = esc_attr( $value ); |
|
1335 | - $menu_items_obj[$title]->description = 'description'; |
|
1332 | + $menu_items_obj[$title]->object_id = esc_attr($value); |
|
1333 | + $menu_items_obj[$title]->title = esc_attr($title); |
|
1334 | + $menu_items_obj[$title]->url = esc_attr($value); |
|
1335 | + $menu_items_obj[$title]->description = 'description'; |
|
1336 | 1336 | $menu_items_obj[$title]->db_id = 0; |
1337 | 1337 | $menu_items_obj[$title]->object = 'sensei'; |
1338 | - $menu_items_obj[$title]->menu_item_parent = 0; |
|
1339 | - $menu_items_obj[$title]->type = 'custom'; |
|
1338 | + $menu_items_obj[$title]->menu_item_parent = 0; |
|
1339 | + $menu_items_obj[$title]->type = 'custom'; |
|
1340 | 1340 | $menu_items_obj[$title]->target = ''; |
1341 | - $menu_items_obj[$title]->attr_title = ''; |
|
1342 | - $menu_items_obj[$title]->classes = array(); |
|
1343 | - $menu_items_obj[$title]->xfn = ''; |
|
1341 | + $menu_items_obj[$title]->attr_title = ''; |
|
1342 | + $menu_items_obj[$title]->classes = array(); |
|
1343 | + $menu_items_obj[$title]->xfn = ''; |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | - $walker = new Walker_Nav_Menu_Checklist( array() ); |
|
1346 | + $walker = new Walker_Nav_Menu_Checklist(array()); |
|
1347 | 1347 | ?> |
1348 | 1348 | |
1349 | 1349 | <div id="sensei-links" class="senseidiv taxonomydiv"> |
1350 | 1350 | <div id="tabs-panel-sensei-links-all" class="tabs-panel tabs-panel-view-all tabs-panel-active"> |
1351 | 1351 | |
1352 | 1352 | <ul id="sensei-linkschecklist" class="list:sensei-links categorychecklist form-no-clear"> |
1353 | - <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items_obj ), 0, (object)array( 'walker' => $walker ) ); ?> |
|
1353 | + <?php echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $menu_items_obj), 0, (object) array('walker' => $walker)); ?> |
|
1354 | 1354 | </ul> |
1355 | 1355 | |
1356 | 1356 | </div> |
1357 | 1357 | <p class="button-controls"> |
1358 | 1358 | <span class="add-to-menu"> |
1359 | - <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'woothemes-sensei' ); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" /> |
|
1359 | + <input type="submit"<?php disabled($nav_menu_selected_id, 0); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu', 'woothemes-sensei'); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" /> |
|
1360 | 1360 | <span class="spinner"></span> |
1361 | 1361 | </span> |
1362 | 1362 | </p> |
@@ -1372,17 +1372,17 @@ discard block |
||
1372 | 1372 | */ |
1373 | 1373 | public function theme_compatibility_notices() { |
1374 | 1374 | |
1375 | - if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1376 | - switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1377 | - case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break; |
|
1378 | - case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break; |
|
1375 | + if (isset($_GET['sensei_hide_notice'])) { |
|
1376 | + switch (esc_attr($_GET['sensei_hide_notice'])) { |
|
1377 | + case 'menu_settings': add_user_meta(get_current_user_id(), 'sensei_hide_menu_settings_notice', true); break; |
|
1378 | + case 'theme_check': add_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); break; |
|
1379 | 1379 | } |
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | // white list templates that are already support by default and do not show notice for them |
1383 | - $template = get_option( 'template' ); |
|
1383 | + $template = get_option('template'); |
|
1384 | 1384 | |
1385 | - $white_list = array( 'twentyeleven', |
|
1385 | + $white_list = array('twentyeleven', |
|
1386 | 1386 | 'twentytwelve', |
1387 | 1387 | 'twentyfourteen', |
1388 | 1388 | 'twentyfifteen', |
@@ -1390,43 +1390,43 @@ discard block |
||
1390 | 1390 | 'storefront', |
1391 | 1391 | ); |
1392 | 1392 | |
1393 | - if ( in_array( $template, $white_list ) ) { |
|
1393 | + if (in_array($template, $white_list)) { |
|
1394 | 1394 | |
1395 | 1395 | return; |
1396 | 1396 | |
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | // don't show the notice if the user chose to hide it |
1400 | - $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1401 | - if( $hide_theme_check_notice ) { |
|
1400 | + $hide_theme_check_notice = get_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); |
|
1401 | + if ($hide_theme_check_notice) { |
|
1402 | 1402 | |
1403 | 1403 | return; |
1404 | 1404 | |
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | // show the notice for themes not supporting sensei |
1408 | - if ( ! current_theme_supports( 'sensei' ) ) { |
|
1408 | + if ( ! current_theme_supports('sensei')) { |
|
1409 | 1409 | ?> |
1410 | 1410 | |
1411 | 1411 | <div id="message" class="error sensei-message sensei-connect"> |
1412 | 1412 | <p> |
1413 | 1413 | <strong> |
1414 | 1414 | |
1415 | - <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei' ); ?> |
|
1415 | + <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei'); ?> |
|
1416 | 1416 | |
1417 | 1417 | </strong> – |
1418 | 1418 | |
1419 | - <?php _e( 'if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei' ); ?> |
|
1419 | + <?php _e('if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei'); ?> |
|
1420 | 1420 | |
1421 | - <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php _e( 'Sensei theme', 'woothemes-sensei' ) ?> </a> |
|
1421 | + <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php _e('Sensei theme', 'woothemes-sensei') ?> </a> |
|
1422 | 1422 | |
1423 | 1423 | :) |
1424 | 1424 | |
1425 | 1425 | </p> |
1426 | 1426 | <p class="submit"> |
1427 | - <a href="<?php echo esc_url( apply_filters( 'sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary"> |
|
1427 | + <a href="<?php echo esc_url(apply_filters('sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility')); ?>" class="button-primary"> |
|
1428 | 1428 | |
1429 | - <?php _e( 'Theme Integration Guide', 'woothemes-sensei' ); ?></a> <a class="skip button" href="<?php echo esc_url( add_query_arg( 'sensei_hide_notice', 'theme_check' ) ); ?>"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?> |
|
1429 | + <?php _e('Theme Integration Guide', 'woothemes-sensei'); ?></a> <a class="skip button" href="<?php echo esc_url(add_query_arg('sensei_hide_notice', 'theme_check')); ?>"><?php _e('Hide this notice', 'woothemes-sensei'); ?> |
|
1430 | 1430 | |
1431 | 1431 | </a> |
1432 | 1432 | </p> |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | wp_get_current_user(); |
1445 | 1445 | $user_id = $current_user->ID; |
1446 | 1446 | |
1447 | - delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' ); |
|
1447 | + delete_user_meta($user_id, 'sensei_hide_theme_check_notice'); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1454,8 +1454,8 @@ discard block |
||
1454 | 1454 | * @param bool $prevent_access |
1455 | 1455 | * @return bool |
1456 | 1456 | */ |
1457 | - public function admin_access( $prevent_access ) { |
|
1458 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
1457 | + public function admin_access($prevent_access) { |
|
1458 | + if (current_user_can('manage_sensei_grades')) { |
|
1459 | 1459 | return false; |
1460 | 1460 | } |
1461 | 1461 | |
@@ -1470,12 +1470,12 @@ discard block |
||
1470 | 1470 | * |
1471 | 1471 | * @since 1.8.7 |
1472 | 1472 | */ |
1473 | - public static function install_pages(){ |
|
1473 | + public static function install_pages() { |
|
1474 | 1474 | |
1475 | 1475 | // only fire on the settings page |
1476 | - if( ! isset( $_GET['page'] ) |
|
1476 | + if ( ! isset($_GET['page']) |
|
1477 | 1477 | || 'woothemes-sensei-settings' != $_GET['page'] |
1478 | - || 1 == get_option('skip_install_sensei_pages') ){ |
|
1478 | + || 1 == get_option('skip_install_sensei_pages')) { |
|
1479 | 1479 | |
1480 | 1480 | return; |
1481 | 1481 | |
@@ -1505,13 +1505,13 @@ discard block |
||
1505 | 1505 | if ($install_complete) { |
1506 | 1506 | |
1507 | 1507 | // Flush rules after install |
1508 | - flush_rewrite_rules( true ); |
|
1508 | + flush_rewrite_rules(true); |
|
1509 | 1509 | |
1510 | 1510 | // Set installed option |
1511 | 1511 | update_option('sensei_installed', 0); |
1512 | 1512 | |
1513 | - $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1514 | - wp_redirect( $complete_url ); |
|
1513 | + $complete_url = add_query_arg('sensei_install_complete', 'true', $settings_url); |
|
1514 | + wp_redirect($complete_url); |
|
1515 | 1515 | |
1516 | 1516 | } |
1517 | 1517 | |
@@ -1524,4 +1524,4 @@ discard block |
||
1524 | 1524 | * for backward compatibility |
1525 | 1525 | * @since 1.9.0 |
1526 | 1526 | */ |
1527 | -class WooThemes_Sensei_Admin extends Sensei_Admin{ } |
|
1527 | +class WooThemes_Sensei_Admin extends Sensei_Admin { } |
@@ -31,63 +31,63 @@ discard block |
||
31 | 31 | // listen to the reset button click |
32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
33 | 33 | |
34 | - // fire the complete quiz button submit for grading action |
|
35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
34 | + // fire the complete quiz button submit for grading action |
|
35 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
36 | 36 | |
37 | 37 | // fire the save user answers quiz button click responder |
38 | 38 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
39 | 39 | |
40 | - // fire the load global data function |
|
41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
40 | + // fire the load global data function |
|
41 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
42 | 42 | |
43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
44 | 44 | |
45 | 45 | |
46 | - } // End __construct() |
|
46 | + } // End __construct() |
|
47 | 47 | |
48 | 48 | /** |
49 | - * Update the quiz author when the lesson post type is save |
|
50 | - * |
|
51 | - * @param int $post_id |
|
52 | - * @return void |
|
53 | - */ |
|
49 | + * Update the quiz author when the lesson post type is save |
|
50 | + * |
|
51 | + * @param int $post_id |
|
52 | + * @return void |
|
53 | + */ |
|
54 | 54 | public function update_author( $post_id ){ |
55 | 55 | |
56 | 56 | |
57 | 57 | // If this isn't a 'lesson' post, don't update it. |
58 | - // if this is a revision don't save it |
|
59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
60 | - || wp_is_post_revision( $post_id ) ) { |
|
58 | + // if this is a revision don't save it |
|
59 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
60 | + || wp_is_post_revision( $post_id ) ) { |
|
61 | 61 | |
62 | - return; |
|
62 | + return; |
|
63 | 63 | |
64 | - } |
|
65 | - // get the lesson author id to be use late |
|
66 | - $saved_post = get_post( $post_id ); |
|
67 | - $new_lesson_author_id = $saved_post->post_author; |
|
64 | + } |
|
65 | + // get the lesson author id to be use late |
|
66 | + $saved_post = get_post( $post_id ); |
|
67 | + $new_lesson_author_id = $saved_post->post_author; |
|
68 | 68 | |
69 | - //get the lessons quiz |
|
69 | + //get the lessons quiz |
|
70 | 70 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
71 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
71 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
72 | 72 | |
73 | - if( ! $quiz_item ) { |
|
74 | - continue; |
|
75 | - } |
|
73 | + if( ! $quiz_item ) { |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - // setup the quiz items new author value |
|
77 | + // setup the quiz items new author value |
|
78 | 78 | $my_post = array( |
79 | - 'ID' => $quiz_item, |
|
80 | - 'post_author' => $new_lesson_author_id |
|
79 | + 'ID' => $quiz_item, |
|
80 | + 'post_author' => $new_lesson_author_id |
|
81 | 81 | ); |
82 | 82 | |
83 | - // remove the action so that it doesn't fire again |
|
84 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
83 | + // remove the action so that it doesn't fire again |
|
84 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
85 | 85 | |
86 | 86 | // Update the post into the database |
87 | 87 | wp_update_post( $my_post ); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - return; |
|
90 | + return; |
|
91 | 91 | }// end update_author |
92 | 92 | |
93 | 93 | |
@@ -118,32 +118,32 @@ discard block |
||
118 | 118 | } // end lesson |
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * user_save_quiz_answers_listener |
|
123 | - * |
|
124 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
125 | - * @since 1.7.3 |
|
126 | - * @return bool $saved; |
|
127 | - */ |
|
128 | - public function user_save_quiz_answers_listener(){ |
|
121 | + /** |
|
122 | + * user_save_quiz_answers_listener |
|
123 | + * |
|
124 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
125 | + * @since 1.7.3 |
|
126 | + * @return bool $saved; |
|
127 | + */ |
|
128 | + public function user_save_quiz_answers_listener(){ |
|
129 | 129 | |
130 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
131 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
132 | - || empty( $_POST[ 'sensei_question' ] ) |
|
133 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
134 | - return; |
|
135 | - } |
|
130 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
131 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
132 | + || empty( $_POST[ 'sensei_question' ] ) |
|
133 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
134 | + return; |
|
135 | + } |
|
136 | 136 | |
137 | - global $post; |
|
138 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
139 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
140 | - // call the save function |
|
141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
137 | + global $post; |
|
138 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
139 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
140 | + // call the save function |
|
141 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
142 | 142 | |
143 | - // remove the hook as it should only fire once per click |
|
144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
143 | + // remove the hook as it should only fire once per click |
|
144 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
145 | 145 | |
146 | - } // end user_save_quiz_answers_listener |
|
146 | + } // end user_save_quiz_answers_listener |
|
147 | 147 | |
148 | 148 | /** |
149 | 149 | * Save the user answers for the given lesson's quiz |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @access public |
155 | 155 | * |
156 | 156 | * @param array $quiz_answers |
157 | - * @param array $files from global $_FILES |
|
157 | + * @param array $files from global $_FILES |
|
158 | 158 | * @param int $lesson_id |
159 | 159 | * @param int $user_id |
160 | 160 | * |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
164 | 164 | |
165 | - if( ! ( $user_id > 0 ) ){ |
|
166 | - $user_id = get_current_user_id(); |
|
167 | - } |
|
165 | + if( ! ( $user_id > 0 ) ){ |
|
166 | + $user_id = get_current_user_id(); |
|
167 | + } |
|
168 | 168 | |
169 | - // make sure the parameters are valid before continuing |
|
169 | + // make sure the parameters are valid before continuing |
|
170 | 170 | if( empty( $lesson_id ) || empty( $user_id ) |
171 | 171 | || 'lesson' != get_post_type( $lesson_id ) |
172 | 172 | ||!get_userdata( $user_id ) |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | |
180 | - // start the lesson before saving the data in case the user has not started the lesson |
|
181 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
180 | + // start the lesson before saving the data in case the user has not started the lesson |
|
181 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
182 | 182 | |
183 | 183 | //prepare the answers |
184 | 184 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
185 | 185 | |
186 | 186 | // save the user data |
187 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
187 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
188 | 188 | |
189 | 189 | // were the answers saved correctly? |
190 | 190 | if( intval( $answers_saved ) > 0){ |
191 | 191 | |
192 | - // save transient to make retrieval faster |
|
193 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
192 | + // save transient to make retrieval faster |
|
193 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
194 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
195 | 195 | |
196 | - // update the message showed to user |
|
197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
198 | - } |
|
196 | + // update the message showed to user |
|
197 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | return $answers_saved; |
201 | 201 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | |
204 | 204 | /** |
205 | 205 | * Get the user answers for the given lesson's quiz. |
206 | - * |
|
207 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
208 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
206 | + * |
|
207 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
208 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
209 | 209 | * |
210 | 210 | * |
211 | 211 | * @since 1.7.4 |
@@ -225,27 +225,27 @@ discard block |
||
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | - // save some time and get the transient cached data |
|
229 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
230 | - $transient_cached_answers = get_transient( $transient_key ); |
|
228 | + // save some time and get the transient cached data |
|
229 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
230 | + $transient_cached_answers = get_transient( $transient_key ); |
|
231 | 231 | |
232 | - // return the transient or get the values get the values from the comment meta |
|
233 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
232 | + // return the transient or get the values get the values from the comment meta |
|
233 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
234 | 234 | |
235 | - $encoded_user_answers = $transient_cached_answers; |
|
235 | + $encoded_user_answers = $transient_cached_answers; |
|
236 | 236 | |
237 | - }else{ |
|
237 | + }else{ |
|
238 | 238 | |
239 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
239 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
240 | 240 | |
241 | - } // end if transient check |
|
241 | + } // end if transient check |
|
242 | 242 | |
243 | 243 | if( ! is_array( $encoded_user_answers ) ){ |
244 | 244 | return false; |
245 | 245 | } |
246 | 246 | |
247 | - //set the transient with the new valid data for faster retrieval in future |
|
248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
247 | + //set the transient with the new valid data for faster retrieval in future |
|
248 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
249 | 249 | |
250 | 250 | // decode an unserialize all answers |
251 | 251 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | $current_quiz_id = $post->ID; |
280 | 280 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
281 | 281 | |
282 | - // reset all user data |
|
283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
282 | + // reset all user data |
|
283 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
284 | 284 | |
285 | 285 | //this function should only run once |
286 | 286 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * Complete/ submit quiz hooked function |
292 | 292 | * |
293 | 293 | * This function listens to the complete button submit action and processes the users submitted answers |
294 | - * not that this function submits the given users quiz answers for grading. |
|
294 | + * not that this function submits the given users quiz answers for grading. |
|
295 | 295 | * |
296 | 296 | * @since 1.7.4 |
297 | 297 | * @access public |
@@ -301,90 +301,90 @@ discard block |
||
301 | 301 | */ |
302 | 302 | public function user_quiz_submit_listener() { |
303 | 303 | |
304 | - // only respond to valid quiz completion submissions |
|
305 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
306 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
307 | - || empty( $_POST[ 'sensei_question' ] ) |
|
308 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
309 | - return; |
|
310 | - } |
|
304 | + // only respond to valid quiz completion submissions |
|
305 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
306 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
307 | + || empty( $_POST[ 'sensei_question' ] ) |
|
308 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
309 | + return; |
|
310 | + } |
|
311 | 311 | |
312 | - global $post, $current_user; |
|
313 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
314 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
312 | + global $post, $current_user; |
|
313 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
314 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
315 | 315 | |
316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
316 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
317 | 317 | |
318 | 318 | } // End sensei_complete_quiz() |
319 | 319 | |
320 | - /** |
|
321 | - * This function set's up the data need for the quiz page |
|
322 | - * |
|
323 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
324 | - * current quiz. |
|
325 | - * |
|
326 | - * @since 1.7.4 |
|
327 | - * @access public |
|
328 | - * |
|
329 | - */ |
|
330 | - public function load_global_quiz_data(){ |
|
320 | + /** |
|
321 | + * This function set's up the data need for the quiz page |
|
322 | + * |
|
323 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
324 | + * current quiz. |
|
325 | + * |
|
326 | + * @since 1.7.4 |
|
327 | + * @access public |
|
328 | + * |
|
329 | + */ |
|
330 | + public function load_global_quiz_data(){ |
|
331 | 331 | |
332 | - global $post, $current_user; |
|
333 | - $this->data = new stdClass(); |
|
332 | + global $post, $current_user; |
|
333 | + $this->data = new stdClass(); |
|
334 | 334 | |
335 | - // Default grade |
|
336 | - $grade = 0; |
|
335 | + // Default grade |
|
336 | + $grade = 0; |
|
337 | 337 | |
338 | - // Get Quiz Questions |
|
339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
338 | + // Get Quiz Questions |
|
339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
340 | 340 | |
341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
341 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
342 | 342 | |
343 | - // Get quiz grade type |
|
344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
343 | + // Get quiz grade type |
|
344 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
345 | 345 | |
346 | - // Get quiz pass setting |
|
347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
346 | + // Get quiz pass setting |
|
347 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
348 | 348 | |
349 | - // Get quiz pass mark |
|
350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
349 | + // Get quiz pass mark |
|
350 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
351 | 351 | |
352 | - // Get latest quiz answers and grades |
|
353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
355 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
356 | - $user_quiz_grade = 0; |
|
357 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
359 | - } |
|
352 | + // Get latest quiz answers and grades |
|
353 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
354 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
355 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
356 | + $user_quiz_grade = 0; |
|
357 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
358 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
359 | + } |
|
360 | 360 | |
361 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
361 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
362 | 362 | |
363 | - // Check again that the lesson is complete |
|
364 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
365 | - $user_lesson_complete = false; |
|
366 | - if ( $user_lesson_end ) { |
|
367 | - $user_lesson_complete = true; |
|
368 | - } // End If Statement |
|
363 | + // Check again that the lesson is complete |
|
364 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
365 | + $user_lesson_complete = false; |
|
366 | + if ( $user_lesson_end ) { |
|
367 | + $user_lesson_complete = true; |
|
368 | + } // End If Statement |
|
369 | 369 | |
370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
371 | - //backwards compatibility |
|
372 | - if( 'on' == $reset_allowed ) { |
|
373 | - $reset_allowed = 1; |
|
374 | - } |
|
370 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
371 | + //backwards compatibility |
|
372 | + if( 'on' == $reset_allowed ) { |
|
373 | + $reset_allowed = 1; |
|
374 | + } |
|
375 | 375 | |
376 | - // Build frontend data object for backwards compatibility |
|
377 | - // using this is no longer recommended |
|
378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
379 | - $this->data->quiz_passmark = $quiz_passmark; |
|
380 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
381 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
382 | - $this->data->user_lesson_end = $user_lesson_end; |
|
383 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
384 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
385 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
376 | + // Build frontend data object for backwards compatibility |
|
377 | + // using this is no longer recommended |
|
378 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
379 | + $this->data->quiz_passmark = $quiz_passmark; |
|
380 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
381 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
382 | + $this->data->user_lesson_end = $user_lesson_end; |
|
383 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
384 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
385 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
386 | 386 | |
387 | - } // end load_global_quiz_data |
|
387 | + } // end load_global_quiz_data |
|
388 | 388 | |
389 | 389 | |
390 | 390 | /** |
@@ -414,25 +414,25 @@ discard block |
||
414 | 414 | foreach( $unprepared_answers as $question_id => $answer ) { |
415 | 415 | |
416 | 416 | //get the current questions question type |
417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
417 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
418 | 418 | |
419 | 419 | // Sanitise answer |
420 | 420 | if( 0 == get_magic_quotes_gpc() ) { |
421 | 421 | $answer = wp_unslash( $answer ); |
422 | 422 | } |
423 | 423 | |
424 | - // compress the answer for saving |
|
424 | + // compress the answer for saving |
|
425 | 425 | if( 'multi-line' == $question_type ) { |
426 | - $answer = esc_html( $answer ); |
|
427 | - }elseif( 'file-upload' == $question_type ){ |
|
428 | - $file_key = 'file_upload_' . $question_id; |
|
429 | - if( isset( $files[ $file_key ] ) ) { |
|
430 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
431 | - if( $attachment_id ) { |
|
432 | - $answer = $attachment_id; |
|
433 | - } |
|
434 | - } |
|
435 | - } // end if |
|
426 | + $answer = esc_html( $answer ); |
|
427 | + }elseif( 'file-upload' == $question_type ){ |
|
428 | + $file_key = 'file_upload_' . $question_id; |
|
429 | + if( isset( $files[ $file_key ] ) ) { |
|
430 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
431 | + if( $attachment_id ) { |
|
432 | + $answer = $attachment_id; |
|
433 | + } |
|
434 | + } |
|
435 | + } // end if |
|
436 | 436 | |
437 | 437 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
438 | 438 | |
@@ -441,814 +441,814 @@ discard block |
||
441 | 441 | return $prepared_answers; |
442 | 442 | } // prepare_form_submitted_answers |
443 | 443 | |
444 | - /** |
|
445 | - * Reset user submitted questions |
|
446 | - * |
|
447 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
448 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
449 | - * |
|
450 | - * @since 1.7.4 |
|
451 | - * @access public |
|
452 | - * |
|
453 | - * @return bool $reset_success |
|
454 | - * @param int $user_id |
|
455 | - * @param int $lesson_id |
|
456 | - */ |
|
457 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
444 | + /** |
|
445 | + * Reset user submitted questions |
|
446 | + * |
|
447 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
448 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
449 | + * |
|
450 | + * @since 1.7.4 |
|
451 | + * @access public |
|
452 | + * |
|
453 | + * @return bool $reset_success |
|
454 | + * @param int $user_id |
|
455 | + * @param int $lesson_id |
|
456 | + */ |
|
457 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
458 | + |
|
459 | + //make sure the parameters are valid |
|
460 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
461 | + || 'lesson' != get_post_type( $lesson_id ) |
|
462 | + || ! get_userdata( $user_id ) ){ |
|
463 | + return false; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + //get the users lesson status to make |
|
469 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
470 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
471 | + // this user is not taking this lesson so this process is not needed |
|
472 | + return false; |
|
473 | + } |
|
474 | + |
|
475 | + //get the lesson quiz and course |
|
476 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
477 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
478 | + |
|
479 | + // reset the transients |
|
480 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
481 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
482 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
483 | + delete_transient( $answers_transient_key ); |
|
484 | + delete_transient( $grades_transient_key ); |
|
485 | + delete_transient( $answers_feedback_transient_key ); |
|
486 | + |
|
487 | + // reset the quiz answers and feedback notes |
|
488 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
489 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
490 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
491 | + |
|
492 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
493 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
494 | + |
|
495 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
496 | + |
|
497 | + // Update course completion |
|
498 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
458 | 499 | |
459 | - //make sure the parameters are valid |
|
460 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
461 | - || 'lesson' != get_post_type( $lesson_id ) |
|
462 | - || ! get_userdata( $user_id ) ){ |
|
463 | - return false; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - //get the users lesson status to make |
|
469 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
470 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
471 | - // this user is not taking this lesson so this process is not needed |
|
472 | - return false; |
|
473 | - } |
|
500 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
501 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
502 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
474 | 503 | |
475 | - //get the lesson quiz and course |
|
476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
504 | + return ( $deleted_answers && $deleted_grades ) ; |
|
478 | 505 | |
479 | - // reset the transients |
|
480 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
481 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
482 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
483 | - delete_transient( $answers_transient_key ); |
|
484 | - delete_transient( $grades_transient_key ); |
|
485 | - delete_transient( $answers_feedback_transient_key ); |
|
506 | + } // end reset_user_lesson_data |
|
486 | 507 | |
487 | - // reset the quiz answers and feedback notes |
|
488 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
489 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
490 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
508 | + /** |
|
509 | + * Submit the users quiz answers for grading |
|
510 | + * |
|
511 | + * This function accepts users answers and stores it but also initiates the grading |
|
512 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
513 | + * |
|
514 | + * @since 1.7.4 |
|
515 | + * @access public |
|
516 | + * |
|
517 | + * @param array $quiz_answers |
|
518 | + * @param array $files from $_FILES |
|
519 | + * @param int $user_id |
|
520 | + * @param int $lesson_id |
|
521 | + * |
|
522 | + * @return bool $answers_submitted |
|
523 | + */ |
|
524 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
491 | 525 | |
492 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
493 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
526 | + $answers_submitted = false; |
|
494 | 527 | |
495 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
528 | + // get the user_id if none was passed in use the current logged in user |
|
529 | + if( ! intval( $user_id ) > 0 ) { |
|
530 | + $user_id = get_current_user_id(); |
|
531 | + } |
|
496 | 532 | |
497 | - // Update course completion |
|
498 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
533 | + // make sure the parameters are valid before continuing |
|
534 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
535 | + || 'lesson' != get_post_type( $lesson_id ) |
|
536 | + ||!get_userdata( $user_id ) |
|
537 | + || !is_array( $quiz_answers ) ){ |
|
499 | 538 | |
500 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
539 | + return false; |
|
503 | 540 | |
504 | - return ( $deleted_answers && $deleted_grades ) ; |
|
541 | + } |
|
505 | 542 | |
506 | - } // end reset_user_lesson_data |
|
543 | + // Default grade |
|
544 | + $grade = 0; |
|
507 | 545 | |
508 | - /** |
|
509 | - * Submit the users quiz answers for grading |
|
510 | - * |
|
511 | - * This function accepts users answers and stores it but also initiates the grading |
|
512 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
513 | - * |
|
514 | - * @since 1.7.4 |
|
515 | - * @access public |
|
516 | - * |
|
517 | - * @param array $quiz_answers |
|
518 | - * @param array $files from $_FILES |
|
519 | - * @param int $user_id |
|
520 | - * @param int $lesson_id |
|
521 | - * |
|
522 | - * @return bool $answers_submitted |
|
523 | - */ |
|
524 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
546 | + // Get Quiz ID |
|
547 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
525 | 548 | |
526 | - $answers_submitted = false; |
|
549 | + // Get quiz grade type |
|
550 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
527 | 551 | |
528 | - // get the user_id if none was passed in use the current logged in user |
|
529 | - if( ! intval( $user_id ) > 0 ) { |
|
530 | - $user_id = get_current_user_id(); |
|
531 | - } |
|
552 | + // Get quiz pass setting |
|
553 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
532 | 554 | |
533 | - // make sure the parameters are valid before continuing |
|
534 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
535 | - || 'lesson' != get_post_type( $lesson_id ) |
|
536 | - ||!get_userdata( $user_id ) |
|
537 | - || !is_array( $quiz_answers ) ){ |
|
555 | + // Get the minimum percentage need to pass this quiz |
|
556 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
538 | 557 | |
539 | - return false; |
|
558 | + // Handle Quiz Questions asked |
|
559 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
560 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
561 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
562 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
563 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
564 | + if( empty( $questions_asked ) ){ |
|
540 | 565 | |
541 | - } |
|
566 | + $questions_asked = array_keys( $quiz_answers ); |
|
567 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
542 | 568 | |
543 | - // Default grade |
|
544 | - $grade = 0; |
|
569 | + // Save questions that were asked in this quiz |
|
570 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
545 | 571 | |
546 | - // Get Quiz ID |
|
547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
572 | + } |
|
548 | 573 | |
549 | - // Get quiz grade type |
|
550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
574 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
575 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
551 | 576 | |
552 | - // Get quiz pass setting |
|
553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
577 | + // Grade quiz |
|
578 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
554 | 579 | |
555 | - // Get the minimum percentage need to pass this quiz |
|
556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
580 | + // Get Lesson Grading Setting |
|
581 | + $lesson_metadata = array(); |
|
582 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
557 | 583 | |
558 | - // Handle Quiz Questions asked |
|
559 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
560 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
561 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
562 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
564 | - if( empty( $questions_asked ) ){ |
|
584 | + // At this point the answers have been submitted |
|
585 | + $answers_submitted = true; |
|
565 | 586 | |
566 | - $questions_asked = array_keys( $quiz_answers ); |
|
567 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
568 | - |
|
569 | - // Save questions that were asked in this quiz |
|
570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
587 | + // if this condition is false the quiz should manually be graded by admin |
|
588 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
571 | 589 | |
572 | - } |
|
590 | + // Quiz has been automatically Graded |
|
591 | + if ( 'on' == $pass_required ) { |
|
573 | 592 | |
574 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
593 | + // Student has reached the pass mark and lesson is complete |
|
594 | + if ( $quiz_pass_percentage <= $grade ) { |
|
576 | 595 | |
577 | - // Grade quiz |
|
578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
596 | + $lesson_status = 'passed'; |
|
579 | 597 | |
580 | - // Get Lesson Grading Setting |
|
581 | - $lesson_metadata = array(); |
|
582 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
598 | + } else { |
|
583 | 599 | |
584 | - // At this point the answers have been submitted |
|
585 | - $answers_submitted = true; |
|
600 | + $lesson_status = 'failed'; |
|
586 | 601 | |
587 | - // if this condition is false the quiz should manually be graded by admin |
|
588 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
602 | + } // End If Statement |
|
589 | 603 | |
590 | - // Quiz has been automatically Graded |
|
591 | - if ( 'on' == $pass_required ) { |
|
604 | + } else { |
|
592 | 605 | |
593 | - // Student has reached the pass mark and lesson is complete |
|
594 | - if ( $quiz_pass_percentage <= $grade ) { |
|
606 | + // Student only has to partake the quiz |
|
607 | + $lesson_status = 'graded'; |
|
608 | + |
|
609 | + } |
|
610 | + |
|
611 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
612 | + |
|
613 | + } // end if ! is_wp_error( $grade ... |
|
614 | + |
|
615 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
595 | 616 | |
596 | - $lesson_status = 'passed'; |
|
617 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
597 | 618 | |
598 | - } else { |
|
619 | + /** |
|
620 | + * Lesson end action hook |
|
621 | + * |
|
622 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
623 | + * |
|
624 | + * @param int $user_id |
|
625 | + * @param int $lesson_id |
|
626 | + */ |
|
627 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
599 | 628 | |
600 | - $lesson_status = 'failed'; |
|
629 | + } |
|
601 | 630 | |
602 | - } // End If Statement |
|
631 | + /** |
|
632 | + * User quiz has been submitted |
|
633 | + * |
|
634 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
635 | + * results. |
|
636 | + * |
|
637 | + * @param int $user_id |
|
638 | + * @param int $quiz_id |
|
639 | + * @param string $grade |
|
640 | + * @param string $quiz_pass_percentage |
|
641 | + * @param string $quiz_grade_type |
|
642 | + */ |
|
643 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
603 | 644 | |
604 | - } else { |
|
645 | + return $answers_submitted; |
|
605 | 646 | |
606 | - // Student only has to partake the quiz |
|
607 | - $lesson_status = 'graded'; |
|
608 | - |
|
609 | - } |
|
610 | - |
|
611 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
612 | - |
|
613 | - } // end if ! is_wp_error( $grade ... |
|
614 | - |
|
615 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
647 | + }// end submit_answers_for_grading |
|
616 | 648 | |
617 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
649 | + /** |
|
650 | + * Get the user question answer |
|
651 | + * |
|
652 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
653 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
654 | + * |
|
655 | + * @since 1.7.4 |
|
656 | + * |
|
657 | + * @param int $lesson_id |
|
658 | + * @param int $question_id |
|
659 | + * @param int $user_id ( optional ) |
|
660 | + * |
|
661 | + * @return bool $answers_submitted |
|
662 | + */ |
|
663 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
618 | 664 | |
619 | - /** |
|
620 | - * Lesson end action hook |
|
621 | - * |
|
622 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
623 | - * |
|
624 | - * @param int $user_id |
|
625 | - * @param int $lesson_id |
|
626 | - */ |
|
627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
665 | + // parameter validation |
|
666 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
667 | + || ! ( intval( $lesson_id ) > 0 ) |
|
668 | + || ! ( intval( $question_id ) > 0 ) |
|
669 | + || 'lesson' != get_post_type( $lesson_id ) |
|
670 | + || 'question' != get_post_type( $question_id )) { |
|
628 | 671 | |
629 | - } |
|
672 | + return false; |
|
673 | + } |
|
674 | + |
|
675 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
676 | + $user_id = get_current_user_id(); |
|
677 | + } |
|
678 | + |
|
679 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
680 | + |
|
681 | + if( !$users_answers || empty( $users_answers ) |
|
682 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
683 | + |
|
684 | + //Fallback for pre 1.7.4 data |
|
685 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
686 | + |
|
687 | + if( ! isset( $comment->comment_content ) ){ |
|
688 | + return false; |
|
689 | + } |
|
690 | + |
|
691 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
692 | + } |
|
693 | + |
|
694 | + return $users_answers[ $question_id ]; |
|
695 | + |
|
696 | + }// end get_user_question_answer |
|
697 | + |
|
698 | + /** |
|
699 | + * Saving the users quiz question grades |
|
700 | + * |
|
701 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
702 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
703 | + * |
|
704 | + * @since 1.7.4 |
|
705 | + * |
|
706 | + * @param array $quiz_grades{ |
|
707 | + * @type int $question_id |
|
708 | + * @type int $question_grade |
|
709 | + * } |
|
710 | + * @param $lesson_id |
|
711 | + * @param $user_id (Optional) will use the current user if not supplied |
|
712 | + * |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
716 | + |
|
717 | + // get the user_id if none was passed in use the current logged in user |
|
718 | + if( ! intval( $user_id ) > 0 ) { |
|
719 | + $user_id = get_current_user_id(); |
|
720 | + } |
|
721 | + |
|
722 | + // make sure the parameters are valid before continuing |
|
723 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
724 | + || 'lesson' != get_post_type( $lesson_id ) |
|
725 | + ||!get_userdata( $user_id ) |
|
726 | + || !is_array( $quiz_grades ) ){ |
|
727 | + |
|
728 | + return false; |
|
729 | + |
|
730 | + } |
|
731 | + |
|
732 | + $success = false; |
|
733 | + |
|
734 | + // save that data for the user on the lesson comment meta |
|
735 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
736 | + |
|
737 | + // were the grades save successfully ? |
|
738 | + if( intval( $comment_meta_id ) > 0 ) { |
|
739 | + |
|
740 | + $success = true; |
|
741 | + // save transient |
|
742 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
743 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
744 | + } |
|
745 | + |
|
746 | + return $success; |
|
747 | + |
|
748 | + }// end set_user_grades |
|
749 | + |
|
750 | + /** |
|
751 | + * Retrieve the users quiz question grades |
|
752 | + * |
|
753 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
754 | + * |
|
755 | + * @since 1.7.4 |
|
756 | + * |
|
757 | + * @param $lesson_id |
|
758 | + * @param $user_id (Optional) will use the current user if not supplied |
|
759 | + * |
|
760 | + * @return array $user_quiz_grades or false if none exists for this users |
|
761 | + */ |
|
762 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
763 | + |
|
764 | + $user_grades = array(); |
|
765 | + |
|
766 | + // get the user_id if none was passed in use the current logged in user |
|
767 | + if( ! intval( $user_id ) > 0 ) { |
|
768 | + $user_id = get_current_user_id(); |
|
769 | + } |
|
770 | + |
|
771 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
772 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
773 | + return false; |
|
774 | + } |
|
775 | + |
|
776 | + // save some time and get the transient cached data |
|
777 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
778 | + $user_grades = get_transient( $transient_key ); |
|
779 | + |
|
780 | + // get the data if nothing was stored in the transient |
|
781 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
782 | + |
|
783 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
784 | + |
|
785 | + //set the transient with the new valid data for faster retrieval in future |
|
786 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
787 | + |
|
788 | + } // end if transient check |
|
789 | + |
|
790 | + // if there is no data for this user |
|
791 | + if( ! is_array( $user_grades ) ){ |
|
792 | + return false; |
|
793 | + } |
|
794 | + |
|
795 | + return $user_grades; |
|
796 | + |
|
797 | + }// end get_user_grades |
|
798 | + |
|
799 | + /** |
|
800 | + * Get the user question grade |
|
801 | + * |
|
802 | + * This function gets the grade on a quiz for the given question parameter |
|
803 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
804 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
805 | + * |
|
806 | + * @since 1.7.4 |
|
807 | + * |
|
808 | + * @param int $lesson_id |
|
809 | + * @param int $question_id |
|
810 | + * @param int $user_id ( optional ) |
|
811 | + * |
|
812 | + * @return bool $question_grade |
|
813 | + */ |
|
814 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
815 | + |
|
816 | + // parameter validation |
|
817 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
818 | + || ! ( intval( $lesson_id ) > 0 ) |
|
819 | + || ! ( intval( $question_id ) > 0 ) |
|
820 | + || 'lesson' != get_post_type( $lesson_id ) |
|
821 | + || 'question' != get_post_type( $question_id )) { |
|
822 | + |
|
823 | + return false; |
|
824 | + } |
|
825 | + |
|
826 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
827 | + |
|
828 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
829 | + |
|
830 | + //fallback to data pre 1.7.4 |
|
831 | + $args = array( |
|
832 | + 'post_id' => $question_id, |
|
833 | + 'user_id' => $user_id, |
|
834 | + 'type' => 'sensei_user_answer' |
|
835 | + ); |
|
836 | + |
|
837 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
838 | + $fall_back_grade = false; |
|
839 | + if( isset( $question_activity->comment_ID ) ){ |
|
840 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
841 | + } |
|
842 | + |
|
843 | + return $fall_back_grade; |
|
844 | + |
|
845 | + } // end if $all_user_grades... |
|
846 | + |
|
847 | + return $all_user_grades[ $question_id ]; |
|
848 | + |
|
849 | + }// end get_user_question_grade |
|
850 | + |
|
851 | + /** |
|
852 | + * Save the user's answers feedback |
|
853 | + * |
|
854 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
855 | + * The data will be saved on the lesson ID supplied. |
|
856 | + * |
|
857 | + * @since 1.7.5 |
|
858 | + * @access public |
|
859 | + * |
|
860 | + * @param array $answers_feedback{ |
|
861 | + * $type int $question_id |
|
862 | + * $type string $question_feedback |
|
863 | + * } |
|
864 | + * @param int $lesson_id |
|
865 | + * @param int $user_id |
|
866 | + * |
|
867 | + * @return false or int $feedback_saved |
|
868 | + */ |
|
869 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
870 | + |
|
871 | + // make sure the parameters are valid before continuing |
|
872 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
873 | + || 'lesson' != get_post_type( $lesson_id ) |
|
874 | + ||!get_userdata( $user_id ) |
|
875 | + || !is_array( $answers_feedback ) ){ |
|
876 | + |
|
877 | + return false; |
|
878 | + |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
883 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
884 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
885 | + } |
|
630 | 886 | |
631 | - /** |
|
632 | - * User quiz has been submitted |
|
633 | - * |
|
634 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
635 | - * results. |
|
636 | - * |
|
637 | - * @param int $user_id |
|
638 | - * @param int $quiz_id |
|
639 | - * @param string $grade |
|
640 | - * @param string $quiz_pass_percentage |
|
641 | - * @param string $quiz_grade_type |
|
642 | - */ |
|
643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
887 | + // encode the feedback |
|
888 | + $encoded_answers_feedback = array(); |
|
889 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
890 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
891 | + } |
|
892 | + |
|
893 | + // save the user data |
|
894 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
895 | + |
|
896 | + //Were the the question feedback save correctly? |
|
897 | + if( intval( $feedback_saved ) > 0){ |
|
898 | + |
|
899 | + // save transient to make retrieval faster in future |
|
900 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
901 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
644 | 902 | |
645 | - return $answers_submitted; |
|
903 | + } |
|
904 | + |
|
905 | + return $feedback_saved; |
|
906 | + |
|
907 | + } // end save_user_answers_feedback |
|
908 | + |
|
909 | + /** |
|
910 | + * Get the user's answers feedback. |
|
911 | + * |
|
912 | + * This function returns the feedback submitted by the teacher/admin |
|
913 | + * during grading. Grading occurs manually or automatically. |
|
914 | + * |
|
915 | + * @since 1.7.5 |
|
916 | + * @access public |
|
917 | + * |
|
918 | + * @param int $lesson_id |
|
919 | + * @param int $user_id |
|
920 | + * |
|
921 | + * @return false | array $answers_feedback{ |
|
922 | + * $type int $question_id |
|
923 | + * $type string $question_feedback |
|
924 | + * } |
|
925 | + */ |
|
926 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
927 | + |
|
928 | + $answers_feedback = array(); |
|
646 | 929 | |
647 | - }// end submit_answers_for_grading |
|
930 | + // get the user_id if none was passed in use the current logged in user |
|
931 | + if( ! intval( $user_id ) > 0 ) { |
|
932 | + $user_id = get_current_user_id(); |
|
933 | + } |
|
648 | 934 | |
649 | - /** |
|
650 | - * Get the user question answer |
|
651 | - * |
|
652 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
653 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
654 | - * |
|
655 | - * @since 1.7.4 |
|
656 | - * |
|
657 | - * @param int $lesson_id |
|
658 | - * @param int $question_id |
|
659 | - * @param int $user_id ( optional ) |
|
660 | - * |
|
661 | - * @return bool $answers_submitted |
|
662 | - */ |
|
663 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
935 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
936 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
937 | + return false; |
|
938 | + } |
|
939 | + |
|
940 | + // first check the transient to save a few split seconds |
|
941 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
942 | + $encoded_feedback = get_transient( $transient_key ); |
|
943 | + |
|
944 | + // get the data if nothing was stored in the transient |
|
945 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
664 | 946 | |
665 | - // parameter validation |
|
666 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
667 | - || ! ( intval( $lesson_id ) > 0 ) |
|
668 | - || ! ( intval( $question_id ) > 0 ) |
|
669 | - || 'lesson' != get_post_type( $lesson_id ) |
|
670 | - || 'question' != get_post_type( $question_id )) { |
|
947 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
948 | + |
|
949 | + //set the transient with the new valid data for faster retrieval in future |
|
950 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
951 | + |
|
952 | + } // end if transient check |
|
671 | 953 | |
672 | - return false; |
|
673 | - } |
|
674 | - |
|
675 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
676 | - $user_id = get_current_user_id(); |
|
677 | - } |
|
678 | - |
|
679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
680 | - |
|
681 | - if( !$users_answers || empty( $users_answers ) |
|
682 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
683 | - |
|
684 | - //Fallback for pre 1.7.4 data |
|
685 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
686 | - |
|
687 | - if( ! isset( $comment->comment_content ) ){ |
|
688 | - return false; |
|
689 | - } |
|
690 | - |
|
691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
692 | - } |
|
693 | - |
|
694 | - return $users_answers[ $question_id ]; |
|
695 | - |
|
696 | - }// end get_user_question_answer |
|
697 | - |
|
698 | - /** |
|
699 | - * Saving the users quiz question grades |
|
700 | - * |
|
701 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
702 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
703 | - * |
|
704 | - * @since 1.7.4 |
|
705 | - * |
|
706 | - * @param array $quiz_grades{ |
|
707 | - * @type int $question_id |
|
708 | - * @type int $question_grade |
|
709 | - * } |
|
710 | - * @param $lesson_id |
|
711 | - * @param $user_id (Optional) will use the current user if not supplied |
|
712 | - * |
|
713 | - * @return bool |
|
714 | - */ |
|
715 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
716 | - |
|
717 | - // get the user_id if none was passed in use the current logged in user |
|
718 | - if( ! intval( $user_id ) > 0 ) { |
|
719 | - $user_id = get_current_user_id(); |
|
720 | - } |
|
721 | - |
|
722 | - // make sure the parameters are valid before continuing |
|
723 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
724 | - || 'lesson' != get_post_type( $lesson_id ) |
|
725 | - ||!get_userdata( $user_id ) |
|
726 | - || !is_array( $quiz_grades ) ){ |
|
727 | - |
|
728 | - return false; |
|
729 | - |
|
730 | - } |
|
731 | - |
|
732 | - $success = false; |
|
733 | - |
|
734 | - // save that data for the user on the lesson comment meta |
|
735 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
736 | - |
|
737 | - // were the grades save successfully ? |
|
738 | - if( intval( $comment_meta_id ) > 0 ) { |
|
739 | - |
|
740 | - $success = true; |
|
741 | - // save transient |
|
742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
744 | - } |
|
745 | - |
|
746 | - return $success; |
|
747 | - |
|
748 | - }// end set_user_grades |
|
749 | - |
|
750 | - /** |
|
751 | - * Retrieve the users quiz question grades |
|
752 | - * |
|
753 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
754 | - * |
|
755 | - * @since 1.7.4 |
|
756 | - * |
|
757 | - * @param $lesson_id |
|
758 | - * @param $user_id (Optional) will use the current user if not supplied |
|
759 | - * |
|
760 | - * @return array $user_quiz_grades or false if none exists for this users |
|
761 | - */ |
|
762 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
763 | - |
|
764 | - $user_grades = array(); |
|
765 | - |
|
766 | - // get the user_id if none was passed in use the current logged in user |
|
767 | - if( ! intval( $user_id ) > 0 ) { |
|
768 | - $user_id = get_current_user_id(); |
|
769 | - } |
|
770 | - |
|
771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
772 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
773 | - return false; |
|
774 | - } |
|
775 | - |
|
776 | - // save some time and get the transient cached data |
|
777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
778 | - $user_grades = get_transient( $transient_key ); |
|
779 | - |
|
780 | - // get the data if nothing was stored in the transient |
|
781 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
782 | - |
|
783 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
784 | - |
|
785 | - //set the transient with the new valid data for faster retrieval in future |
|
786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
787 | - |
|
788 | - } // end if transient check |
|
789 | - |
|
790 | - // if there is no data for this user |
|
791 | - if( ! is_array( $user_grades ) ){ |
|
792 | - return false; |
|
793 | - } |
|
794 | - |
|
795 | - return $user_grades; |
|
796 | - |
|
797 | - }// end get_user_grades |
|
798 | - |
|
799 | - /** |
|
800 | - * Get the user question grade |
|
801 | - * |
|
802 | - * This function gets the grade on a quiz for the given question parameter |
|
803 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
804 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
805 | - * |
|
806 | - * @since 1.7.4 |
|
807 | - * |
|
808 | - * @param int $lesson_id |
|
809 | - * @param int $question_id |
|
810 | - * @param int $user_id ( optional ) |
|
811 | - * |
|
812 | - * @return bool $question_grade |
|
813 | - */ |
|
814 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
815 | - |
|
816 | - // parameter validation |
|
817 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
818 | - || ! ( intval( $lesson_id ) > 0 ) |
|
819 | - || ! ( intval( $question_id ) > 0 ) |
|
820 | - || 'lesson' != get_post_type( $lesson_id ) |
|
821 | - || 'question' != get_post_type( $question_id )) { |
|
822 | - |
|
823 | - return false; |
|
824 | - } |
|
825 | - |
|
826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
827 | - |
|
828 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
829 | - |
|
830 | - //fallback to data pre 1.7.4 |
|
831 | - $args = array( |
|
832 | - 'post_id' => $question_id, |
|
833 | - 'user_id' => $user_id, |
|
834 | - 'type' => 'sensei_user_answer' |
|
835 | - ); |
|
836 | - |
|
837 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
838 | - $fall_back_grade = false; |
|
839 | - if( isset( $question_activity->comment_ID ) ){ |
|
840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
841 | - } |
|
842 | - |
|
843 | - return $fall_back_grade; |
|
844 | - |
|
845 | - } // end if $all_user_grades... |
|
846 | - |
|
847 | - return $all_user_grades[ $question_id ]; |
|
848 | - |
|
849 | - }// end get_user_question_grade |
|
850 | - |
|
851 | - /** |
|
852 | - * Save the user's answers feedback |
|
853 | - * |
|
854 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
855 | - * The data will be saved on the lesson ID supplied. |
|
856 | - * |
|
857 | - * @since 1.7.5 |
|
858 | - * @access public |
|
859 | - * |
|
860 | - * @param array $answers_feedback{ |
|
861 | - * $type int $question_id |
|
862 | - * $type string $question_feedback |
|
863 | - * } |
|
864 | - * @param int $lesson_id |
|
865 | - * @param int $user_id |
|
866 | - * |
|
867 | - * @return false or int $feedback_saved |
|
868 | - */ |
|
869 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
870 | - |
|
871 | - // make sure the parameters are valid before continuing |
|
872 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
873 | - || 'lesson' != get_post_type( $lesson_id ) |
|
874 | - ||!get_userdata( $user_id ) |
|
875 | - || !is_array( $answers_feedback ) ){ |
|
876 | - |
|
877 | - return false; |
|
878 | - |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
883 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
884 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
885 | - } |
|
886 | - |
|
887 | - // encode the feedback |
|
888 | - $encoded_answers_feedback = array(); |
|
889 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
891 | - } |
|
892 | - |
|
893 | - // save the user data |
|
894 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
895 | - |
|
896 | - //Were the the question feedback save correctly? |
|
897 | - if( intval( $feedback_saved ) > 0){ |
|
898 | - |
|
899 | - // save transient to make retrieval faster in future |
|
900 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
902 | - |
|
903 | - } |
|
904 | - |
|
905 | - return $feedback_saved; |
|
906 | - |
|
907 | - } // end save_user_answers_feedback |
|
908 | - |
|
909 | - /** |
|
910 | - * Get the user's answers feedback. |
|
911 | - * |
|
912 | - * This function returns the feedback submitted by the teacher/admin |
|
913 | - * during grading. Grading occurs manually or automatically. |
|
914 | - * |
|
915 | - * @since 1.7.5 |
|
916 | - * @access public |
|
917 | - * |
|
918 | - * @param int $lesson_id |
|
919 | - * @param int $user_id |
|
920 | - * |
|
921 | - * @return false | array $answers_feedback{ |
|
922 | - * $type int $question_id |
|
923 | - * $type string $question_feedback |
|
924 | - * } |
|
925 | - */ |
|
926 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
927 | - |
|
928 | - $answers_feedback = array(); |
|
929 | - |
|
930 | - // get the user_id if none was passed in use the current logged in user |
|
931 | - if( ! intval( $user_id ) > 0 ) { |
|
932 | - $user_id = get_current_user_id(); |
|
933 | - } |
|
934 | - |
|
935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
936 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
937 | - return false; |
|
938 | - } |
|
939 | - |
|
940 | - // first check the transient to save a few split seconds |
|
941 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
942 | - $encoded_feedback = get_transient( $transient_key ); |
|
943 | - |
|
944 | - // get the data if nothing was stored in the transient |
|
945 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
946 | - |
|
947 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
948 | - |
|
949 | - //set the transient with the new valid data for faster retrieval in future |
|
950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
951 | - |
|
952 | - } // end if transient check |
|
953 | - |
|
954 | - // if there is no data for this user |
|
955 | - if( ! is_array( $encoded_feedback ) ){ |
|
956 | - return false; |
|
957 | - } |
|
954 | + // if there is no data for this user |
|
955 | + if( ! is_array( $encoded_feedback ) ){ |
|
956 | + return false; |
|
957 | + } |
|
958 | 958 | |
959 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
959 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
960 | 960 | |
961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
961 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
962 | 962 | |
963 | - } |
|
963 | + } |
|
964 | 964 | |
965 | - return $answers_feedback; |
|
965 | + return $answers_feedback; |
|
966 | 966 | |
967 | - } // end get_user_answers_feedback |
|
967 | + } // end get_user_answers_feedback |
|
968 | 968 | |
969 | - /** |
|
970 | - * Get the user's answer feedback for a specific question. |
|
971 | - * |
|
972 | - * This function gives you a single answer note/feedback string |
|
973 | - * for the user on the given question. |
|
974 | - * |
|
975 | - * @since 1.7.5 |
|
976 | - * @access public |
|
977 | - * |
|
978 | - * @param int $lesson_id |
|
979 | - * @param int $question_id |
|
980 | - * @param int $user_id |
|
981 | - * |
|
982 | - * @return string $feedback or bool if false |
|
983 | - */ |
|
984 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
969 | + /** |
|
970 | + * Get the user's answer feedback for a specific question. |
|
971 | + * |
|
972 | + * This function gives you a single answer note/feedback string |
|
973 | + * for the user on the given question. |
|
974 | + * |
|
975 | + * @since 1.7.5 |
|
976 | + * @access public |
|
977 | + * |
|
978 | + * @param int $lesson_id |
|
979 | + * @param int $question_id |
|
980 | + * @param int $user_id |
|
981 | + * |
|
982 | + * @return string $feedback or bool if false |
|
983 | + */ |
|
984 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
985 | 985 | |
986 | - $feedback = false; |
|
986 | + $feedback = false; |
|
987 | 987 | |
988 | - // parameter validation |
|
989 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
990 | - || ! ( intval( $lesson_id ) > 0 ) |
|
991 | - || ! ( intval( $question_id ) > 0 ) |
|
992 | - || 'lesson' != get_post_type( $lesson_id ) |
|
993 | - || 'question' != get_post_type( $question_id )) { |
|
988 | + // parameter validation |
|
989 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
990 | + || ! ( intval( $lesson_id ) > 0 ) |
|
991 | + || ! ( intval( $question_id ) > 0 ) |
|
992 | + || 'lesson' != get_post_type( $lesson_id ) |
|
993 | + || 'question' != get_post_type( $question_id )) { |
|
994 | 994 | |
995 | - return false; |
|
996 | - } |
|
995 | + return false; |
|
996 | + } |
|
997 | 997 | |
998 | - // get all the feedback for the user on the given lesson |
|
999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
998 | + // get all the feedback for the user on the given lesson |
|
999 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
1000 | 1000 | |
1001 | - if( !$all_feedback || empty( $all_feedback ) |
|
1002 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
1001 | + if( !$all_feedback || empty( $all_feedback ) |
|
1002 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
1003 | 1003 | |
1004 | - //fallback to data pre 1.7.4 |
|
1004 | + //fallback to data pre 1.7.4 |
|
1005 | 1005 | |
1006 | - // setup the sensei data query |
|
1007 | - $args = array( |
|
1008 | - 'post_id' => $question_id, |
|
1009 | - 'user_id' => $user_id, |
|
1010 | - 'type' => 'sensei_user_answer' |
|
1011 | - ); |
|
1012 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
1006 | + // setup the sensei data query |
|
1007 | + $args = array( |
|
1008 | + 'post_id' => $question_id, |
|
1009 | + 'user_id' => $user_id, |
|
1010 | + 'type' => 'sensei_user_answer' |
|
1011 | + ); |
|
1012 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
1013 | 1013 | |
1014 | - // set the default to false and return that if no old data is available. |
|
1015 | - if( isset( $question_activity->comment_ID ) ){ |
|
1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
1017 | - } |
|
1014 | + // set the default to false and return that if no old data is available. |
|
1015 | + if( isset( $question_activity->comment_ID ) ){ |
|
1016 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
1017 | + } |
|
1018 | 1018 | |
1019 | - // finally use the default question feedback |
|
1020 | - if( empty( $feedback ) ){ |
|
1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
1022 | - } |
|
1019 | + // finally use the default question feedback |
|
1020 | + if( empty( $feedback ) ){ |
|
1021 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - return $feedback; |
|
1024 | + return $feedback; |
|
1025 | 1025 | |
1026 | - } |
|
1026 | + } |
|
1027 | 1027 | |
1028 | - return $all_feedback[ $question_id ]; |
|
1028 | + return $all_feedback[ $question_id ]; |
|
1029 | 1029 | |
1030 | - } // end get_user_question_feedback |
|
1030 | + } // end get_user_question_feedback |
|
1031 | 1031 | |
1032 | - /** |
|
1033 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
1034 | - * |
|
1035 | - * Though a quiz is created for each lesson, it should not be visible |
|
1036 | - * unless it has questions. |
|
1037 | - * |
|
1038 | - * @since 1.9.0 |
|
1039 | - * @access public |
|
1040 | - * @param none |
|
1041 | - * @return void |
|
1042 | - */ |
|
1032 | + /** |
|
1033 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
1034 | + * |
|
1035 | + * Though a quiz is created for each lesson, it should not be visible |
|
1036 | + * unless it has questions. |
|
1037 | + * |
|
1038 | + * @since 1.9.0 |
|
1039 | + * @access public |
|
1040 | + * @param none |
|
1041 | + * @return void |
|
1042 | + */ |
|
1043 | 1043 | |
1044 | - public function quiz_has_no_questions() { |
|
1044 | + public function quiz_has_no_questions() { |
|
1045 | 1045 | |
1046 | 1046 | |
1047 | - if( ! is_singular( 'quiz' ) ) { |
|
1048 | - return; |
|
1049 | - } |
|
1047 | + if( ! is_singular( 'quiz' ) ) { |
|
1048 | + return; |
|
1049 | + } |
|
1050 | 1050 | |
1051 | - global $post; |
|
1051 | + global $post; |
|
1052 | 1052 | |
1053 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
1053 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
1054 | 1054 | |
1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1055 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1056 | 1056 | |
1057 | - $lesson = get_post($lesson_id); |
|
1057 | + $lesson = get_post($lesson_id); |
|
1058 | 1058 | |
1059 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
1059 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
1060 | 1060 | |
1061 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
1062 | - exit; |
|
1061 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
1062 | + exit; |
|
1063 | 1063 | |
1064 | - } |
|
1064 | + } |
|
1065 | 1065 | |
1066 | - } // end quiz_has_no_questions |
|
1066 | + } // end quiz_has_no_questions |
|
1067 | 1067 | |
1068 | 1068 | /** |
1069 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
1070 | - * |
|
1071 | - * @deprecated since 1.9.0 |
|
1072 | - */ |
|
1069 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
1070 | + * |
|
1071 | + * @deprecated since 1.9.0 |
|
1072 | + */ |
|
1073 | 1073 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
1074 | 1074 | |
1075 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
1075 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
1076 | 1076 | |
1077 | 1077 | } |
1078 | - /* |
|
1078 | + /* |
|
1079 | 1079 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
1080 | 1080 | * |
1081 | 1081 | * @deprecated since 1.9.0 |
1082 | 1082 | */ |
1083 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
1083 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
1084 | 1084 | |
1085 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
1085 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
1086 | 1086 | |
1087 | - } |
|
1087 | + } |
|
1088 | 1088 | |
1089 | - /** |
|
1090 | - * Filter the single title and add the Quiz to it. |
|
1091 | - * |
|
1092 | - * @param string $title |
|
1093 | - * @param int $id title post id |
|
1094 | - * @return string $quiz_title |
|
1095 | - */ |
|
1096 | - public static function single_quiz_title( $title, $post_id ){ |
|
1089 | + /** |
|
1090 | + * Filter the single title and add the Quiz to it. |
|
1091 | + * |
|
1092 | + * @param string $title |
|
1093 | + * @param int $id title post id |
|
1094 | + * @return string $quiz_title |
|
1095 | + */ |
|
1096 | + public static function single_quiz_title( $title, $post_id ){ |
|
1097 | 1097 | |
1098 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
1098 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
1099 | 1099 | |
1100 | - $title_with_no_quizzes = $title; |
|
1100 | + $title_with_no_quizzes = $title; |
|
1101 | 1101 | |
1102 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
1103 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
1102 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
1103 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
1104 | 1104 | |
1105 | - // remove all possible appearances of quiz |
|
1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
1105 | + // remove all possible appearances of quiz |
|
1106 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
1107 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
1108 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
1109 | 1109 | |
1110 | - } |
|
1110 | + } |
|
1111 | 1111 | |
1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
1113 | - } |
|
1112 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
1113 | + } |
|
1114 | 1114 | |
1115 | - /** |
|
1116 | - * hook document in class-woothemes-sensei-message.php |
|
1117 | - */ |
|
1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
1115 | + /** |
|
1116 | + * hook document in class-woothemes-sensei-message.php |
|
1117 | + */ |
|
1118 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
1119 | 1119 | |
1120 | - } |
|
1120 | + } |
|
1121 | 1121 | |
1122 | - /** |
|
1123 | - * Initialize the quiz question loop on the single quiz template |
|
1124 | - * |
|
1125 | - * The function will create a global quiz loop varialbe. |
|
1126 | - * |
|
1127 | - * @since 1.9.0 |
|
1128 | - * |
|
1129 | - */ |
|
1130 | - public static function start_quiz_questions_loop(){ |
|
1122 | + /** |
|
1123 | + * Initialize the quiz question loop on the single quiz template |
|
1124 | + * |
|
1125 | + * The function will create a global quiz loop varialbe. |
|
1126 | + * |
|
1127 | + * @since 1.9.0 |
|
1128 | + * |
|
1129 | + */ |
|
1130 | + public static function start_quiz_questions_loop(){ |
|
1131 | 1131 | |
1132 | - global $sensei_question_loop; |
|
1132 | + global $sensei_question_loop; |
|
1133 | 1133 | |
1134 | - //intialize the questions loop object |
|
1135 | - $sensei_question_loop['current'] = -1; |
|
1136 | - $sensei_question_loop['total'] = 0; |
|
1137 | - $sensei_question_loop['questions'] = array(); |
|
1134 | + //intialize the questions loop object |
|
1135 | + $sensei_question_loop['current'] = -1; |
|
1136 | + $sensei_question_loop['total'] = 0; |
|
1137 | + $sensei_question_loop['questions'] = array(); |
|
1138 | 1138 | |
1139 | 1139 | |
1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
1140 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
1141 | 1141 | |
1142 | - if( count( $questions ) > 0 ){ |
|
1142 | + if( count( $questions ) > 0 ){ |
|
1143 | 1143 | |
1144 | - $sensei_question_loop['total'] = count( $questions ); |
|
1145 | - $sensei_question_loop['questions'] = $questions; |
|
1146 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
1144 | + $sensei_question_loop['total'] = count( $questions ); |
|
1145 | + $sensei_question_loop['questions'] = $questions; |
|
1146 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
1147 | 1147 | |
1148 | - } |
|
1148 | + } |
|
1149 | 1149 | |
1150 | - }// static function |
|
1150 | + }// static function |
|
1151 | 1151 | |
1152 | - /** |
|
1153 | - * Initialize the quiz question loop on the single quiz template |
|
1154 | - * |
|
1155 | - * The function will create a global quiz loop varialbe. |
|
1156 | - * |
|
1157 | - * @since 1.9.0 |
|
1158 | - * |
|
1159 | - */ |
|
1160 | - public static function stop_quiz_questions_loop(){ |
|
1152 | + /** |
|
1153 | + * Initialize the quiz question loop on the single quiz template |
|
1154 | + * |
|
1155 | + * The function will create a global quiz loop varialbe. |
|
1156 | + * |
|
1157 | + * @since 1.9.0 |
|
1158 | + * |
|
1159 | + */ |
|
1160 | + public static function stop_quiz_questions_loop(){ |
|
1161 | 1161 | |
1162 | - $sensei_question_loop['total'] = 0; |
|
1163 | - $sensei_question_loop['questions'] = array(); |
|
1164 | - $sensei_question_loop['quiz_id'] = ''; |
|
1162 | + $sensei_question_loop['total'] = 0; |
|
1163 | + $sensei_question_loop['questions'] = array(); |
|
1164 | + $sensei_question_loop['quiz_id'] = ''; |
|
1165 | 1165 | |
1166 | - } |
|
1166 | + } |
|
1167 | 1167 | |
1168 | - /** |
|
1169 | - * Output the title for the single quiz page |
|
1170 | - * |
|
1171 | - * @since 1.9.0 |
|
1172 | - */ |
|
1173 | - public static function the_title(){ |
|
1174 | - ?> |
|
1168 | + /** |
|
1169 | + * Output the title for the single quiz page |
|
1170 | + * |
|
1171 | + * @since 1.9.0 |
|
1172 | + */ |
|
1173 | + public static function the_title(){ |
|
1174 | + ?> |
|
1175 | 1175 | <header> |
1176 | 1176 | |
1177 | 1177 | <h1> |
1178 | 1178 | |
1179 | 1179 | <?php |
1180 | - /** |
|
1181 | - * Filter documented in class-sensei-messages.php the_title |
|
1182 | - */ |
|
1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
1184 | - ?> |
|
1180 | + /** |
|
1181 | + * Filter documented in class-sensei-messages.php the_title |
|
1182 | + */ |
|
1183 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
1184 | + ?> |
|
1185 | 1185 | |
1186 | 1186 | </h1> |
1187 | 1187 | |
1188 | 1188 | </header> |
1189 | 1189 | |
1190 | 1190 | <?php |
1191 | - }//the_title |
|
1191 | + }//the_title |
|
1192 | 1192 | |
1193 | - /** |
|
1194 | - * Output the sensei quiz status message. |
|
1195 | - * |
|
1196 | - * @param $quiz_id |
|
1197 | - */ |
|
1198 | - public static function the_user_status_message( $quiz_id ){ |
|
1193 | + /** |
|
1194 | + * Output the sensei quiz status message. |
|
1195 | + * |
|
1196 | + * @param $quiz_id |
|
1197 | + */ |
|
1198 | + public static function the_user_status_message( $quiz_id ){ |
|
1199 | 1199 | |
1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
1201 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
1200 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
1201 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
1202 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
1203 | 1203 | |
1204 | - } |
|
1204 | + } |
|
1205 | 1205 | |
1206 | - /** |
|
1207 | - * This functions runs the old sensei_quiz_action_buttons action |
|
1208 | - * for backwards compatiblity sake. |
|
1209 | - * |
|
1210 | - * @since 1.9.0 |
|
1211 | - * @deprecated |
|
1212 | - */ |
|
1213 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
1206 | + /** |
|
1207 | + * This functions runs the old sensei_quiz_action_buttons action |
|
1208 | + * for backwards compatiblity sake. |
|
1209 | + * |
|
1210 | + * @since 1.9.0 |
|
1211 | + * @deprecated |
|
1212 | + */ |
|
1213 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
1214 | 1214 | |
1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1215 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1216 | 1216 | |
1217 | - } |
|
1217 | + } |
|
1218 | 1218 | |
1219 | - /** |
|
1220 | - * The quiz action buttons needed to ouput quiz |
|
1221 | - * action such as reset complete and save. |
|
1222 | - * |
|
1223 | - * @since 1.3.0 |
|
1224 | - */ |
|
1225 | - public static function action_buttons() { |
|
1219 | + /** |
|
1220 | + * The quiz action buttons needed to ouput quiz |
|
1221 | + * action such as reset complete and save. |
|
1222 | + * |
|
1223 | + * @since 1.3.0 |
|
1224 | + */ |
|
1225 | + public static function action_buttons() { |
|
1226 | 1226 | |
1227 | - global $post, $current_user; |
|
1227 | + global $post, $current_user; |
|
1228 | 1228 | |
1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1232 | - $show_actions = true; |
|
1233 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
1229 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
1230 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
1231 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1232 | + $show_actions = true; |
|
1233 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
1234 | 1234 | |
1235 | - //setup quiz grade |
|
1236 | - $user_quiz_grade = ''; |
|
1237 | - if( ! empty( $user_lesson_status ) ){ |
|
1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1239 | - } |
|
1235 | + //setup quiz grade |
|
1236 | + $user_quiz_grade = ''; |
|
1237 | + if( ! empty( $user_lesson_status ) ){ |
|
1238 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1239 | + } |
|
1240 | 1240 | |
1241 | 1241 | |
1242 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
1242 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
1243 | 1243 | |
1244 | - // If the user hasn't completed the prereq then hide the current actions |
|
1245 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
1244 | + // If the user hasn't completed the prereq then hide the current actions |
|
1245 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
1246 | 1246 | |
1247 | - } |
|
1248 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
1247 | + } |
|
1248 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
1249 | 1249 | |
1250 | - // Get Reset Settings |
|
1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
1250 | + // Get Reset Settings |
|
1251 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
1252 | 1252 | |
1253 | 1253 | <!-- Action Nonce's --> |
1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1275,55 +1275,55 @@ discard block |
||
1275 | 1275 | |
1276 | 1276 | <?php } |
1277 | 1277 | |
1278 | - } // End sensei_quiz_action_buttons() |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * Fetch the quiz grade |
|
1282 | - * |
|
1283 | - * @since 1.9.0 |
|
1284 | - * |
|
1285 | - * @param int $lesson_id |
|
1286 | - * @param int $user_id |
|
1287 | - * |
|
1288 | - * @return double $user_quiz_grade |
|
1289 | - */ |
|
1290 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
1291 | - |
|
1292 | - // get the quiz grade |
|
1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1294 | - $user_quiz_grade = 0; |
|
1295 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1297 | - } |
|
1298 | - |
|
1299 | - return (double) $user_quiz_grade; |
|
1300 | - |
|
1301 | - } |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Check the quiz reset property for a given lesson's quiz. |
|
1305 | - * |
|
1306 | - * The data is stored on the quiz but going forward the quiz post |
|
1307 | - * type will be retired, hence the lesson_id is a require parameter. |
|
1308 | - * |
|
1309 | - * @since 1.9.0 |
|
1310 | - * |
|
1311 | - * @param int $lesson_id |
|
1312 | - * @return bool |
|
1313 | - */ |
|
1314 | - public static function is_reset_allowed( $lesson_id ){ |
|
1315 | - |
|
1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1317 | - |
|
1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
1319 | - //backwards compatibility |
|
1320 | - if( 'on' == $reset_allowed ) { |
|
1321 | - $reset_allowed = 1; |
|
1322 | - } |
|
1323 | - |
|
1324 | - return (bool) $reset_allowed; |
|
1325 | - |
|
1326 | - } |
|
1278 | + } // End sensei_quiz_action_buttons() |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * Fetch the quiz grade |
|
1282 | + * |
|
1283 | + * @since 1.9.0 |
|
1284 | + * |
|
1285 | + * @param int $lesson_id |
|
1286 | + * @param int $user_id |
|
1287 | + * |
|
1288 | + * @return double $user_quiz_grade |
|
1289 | + */ |
|
1290 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
1291 | + |
|
1292 | + // get the quiz grade |
|
1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1294 | + $user_quiz_grade = 0; |
|
1295 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
1296 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1297 | + } |
|
1298 | + |
|
1299 | + return (double) $user_quiz_grade; |
|
1300 | + |
|
1301 | + } |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Check the quiz reset property for a given lesson's quiz. |
|
1305 | + * |
|
1306 | + * The data is stored on the quiz but going forward the quiz post |
|
1307 | + * type will be retired, hence the lesson_id is a require parameter. |
|
1308 | + * |
|
1309 | + * @since 1.9.0 |
|
1310 | + * |
|
1311 | + * @param int $lesson_id |
|
1312 | + * @return bool |
|
1313 | + */ |
|
1314 | + public static function is_reset_allowed( $lesson_id ){ |
|
1315 | + |
|
1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1317 | + |
|
1318 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
1319 | + //backwards compatibility |
|
1320 | + if( 'on' == $reset_allowed ) { |
|
1321 | + $reset_allowed = 1; |
|
1322 | + } |
|
1323 | + |
|
1324 | + return (bool) $reset_allowed; |
|
1325 | + |
|
1326 | + } |
|
1327 | 1327 | |
1328 | 1328 | } // End Class WooThemes_Sensei_Quiz |
1329 | 1329 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Quiz Class |
@@ -23,24 +23,24 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $file |
25 | 25 | */ |
26 | - public function __construct ( $file = __FILE__ ) { |
|
26 | + public function __construct($file = __FILE__) { |
|
27 | 27 | $this->file = $file; |
28 | - $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
|
29 | - add_action( 'save_post', array( $this, 'update_author' )); |
|
28 | + $this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset'); |
|
29 | + add_action('save_post', array($this, 'update_author')); |
|
30 | 30 | |
31 | 31 | // listen to the reset button click |
32 | - add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
32 | + add_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
33 | 33 | |
34 | 34 | // fire the complete quiz button submit for grading action |
35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
35 | + add_action('sensei_complete_quiz', array($this, 'user_quiz_submit_listener')); |
|
36 | 36 | |
37 | 37 | // fire the save user answers quiz button click responder |
38 | - add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
|
38 | + add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener')); |
|
39 | 39 | |
40 | 40 | // fire the load global data function |
41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
41 | + add_action('sensei_complete_quiz', array($this, 'load_global_quiz_data'), 80); |
|
42 | 42 | |
43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
43 | + add_action('template_redirect', array($this, 'quiz_has_no_questions')); |
|
44 | 44 | |
45 | 45 | |
46 | 46 | } // End __construct() |
@@ -51,26 +51,26 @@ discard block |
||
51 | 51 | * @param int $post_id |
52 | 52 | * @return void |
53 | 53 | */ |
54 | - public function update_author( $post_id ){ |
|
54 | + public function update_author($post_id) { |
|
55 | 55 | |
56 | 56 | |
57 | 57 | // If this isn't a 'lesson' post, don't update it. |
58 | 58 | // if this is a revision don't save it |
59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
60 | - || wp_is_post_revision( $post_id ) ) { |
|
59 | + if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type'] |
|
60 | + || wp_is_post_revision($post_id)) { |
|
61 | 61 | |
62 | 62 | return; |
63 | 63 | |
64 | 64 | } |
65 | 65 | // get the lesson author id to be use late |
66 | - $saved_post = get_post( $post_id ); |
|
67 | - $new_lesson_author_id = $saved_post->post_author; |
|
66 | + $saved_post = get_post($post_id); |
|
67 | + $new_lesson_author_id = $saved_post->post_author; |
|
68 | 68 | |
69 | 69 | //get the lessons quiz |
70 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
|
71 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
70 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id); |
|
71 | + foreach ((array) $lesson_quizzes as $quiz_item) { |
|
72 | 72 | |
73 | - if( ! $quiz_item ) { |
|
73 | + if ( ! $quiz_item) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | ); |
82 | 82 | |
83 | 83 | // remove the action so that it doesn't fire again |
84 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
84 | + remove_action('save_post', array($this, 'update_author')); |
|
85 | 85 | |
86 | 86 | // Update the post into the database |
87 | - wp_update_post( $my_post ); |
|
87 | + wp_update_post($my_post); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return; |
@@ -98,19 +98,19 @@ discard block |
||
98 | 98 | * @param int $quiz_id |
99 | 99 | * @return int @lesson_id |
100 | 100 | */ |
101 | - public function get_lesson_id( $quiz_id ){ |
|
101 | + public function get_lesson_id($quiz_id) { |
|
102 | 102 | |
103 | - if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){ |
|
103 | + if (empty($quiz_id) || ! intval($quiz_id) > 0) { |
|
104 | 104 | global $post; |
105 | - if( 'quiz' == get_post_type( $post ) ){ |
|
105 | + if ('quiz' == get_post_type($post)) { |
|
106 | 106 | $quiz_id = $post->ID; |
107 | - }else{ |
|
107 | + } else { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
111 | 111 | } |
112 | 112 | |
113 | - $quiz = get_post( $quiz_id ); |
|
113 | + $quiz = get_post($quiz_id); |
|
114 | 114 | $lesson_id = $quiz->post_parent; |
115 | 115 | |
116 | 116 | return $lesson_id; |
@@ -125,23 +125,23 @@ discard block |
||
125 | 125 | * @since 1.7.3 |
126 | 126 | * @return bool $saved; |
127 | 127 | */ |
128 | - public function user_save_quiz_answers_listener(){ |
|
128 | + public function user_save_quiz_answers_listener() { |
|
129 | 129 | |
130 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
131 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
132 | - || empty( $_POST[ 'sensei_question' ] ) |
|
133 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
130 | + if ( ! isset($_POST['quiz_save']) |
|
131 | + || ! isset($_POST['sensei_question']) |
|
132 | + || empty($_POST['sensei_question']) |
|
133 | + || ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | 137 | global $post; |
138 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
139 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
138 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
139 | + $quiz_answers = $_POST['sensei_question']; |
|
140 | 140 | // call the save function |
141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
141 | + self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id()); |
|
142 | 142 | |
143 | 143 | // remove the hook as it should only fire once per click |
144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
144 | + remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener'); |
|
145 | 145 | |
146 | 146 | } // end user_save_quiz_answers_listener |
147 | 147 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return false or int $answers_saved |
162 | 162 | */ |
163 | - public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
|
163 | + public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
164 | 164 | |
165 | - if( ! ( $user_id > 0 ) ){ |
|
165 | + if ( ! ($user_id > 0)) { |
|
166 | 166 | $user_id = get_current_user_id(); |
167 | 167 | } |
168 | 168 | |
169 | 169 | // make sure the parameters are valid before continuing |
170 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
171 | - || 'lesson' != get_post_type( $lesson_id ) |
|
172 | - ||!get_userdata( $user_id ) |
|
173 | - || !is_array( $quiz_answers ) ){ |
|
170 | + if (empty($lesson_id) || empty($user_id) |
|
171 | + || 'lesson' != get_post_type($lesson_id) |
|
172 | + ||! get_userdata($user_id) |
|
173 | + || ! is_array($quiz_answers)) { |
|
174 | 174 | |
175 | 175 | return false; |
176 | 176 | |
@@ -178,23 +178,23 @@ discard block |
||
178 | 178 | |
179 | 179 | |
180 | 180 | // start the lesson before saving the data in case the user has not started the lesson |
181 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
181 | + $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
182 | 182 | |
183 | 183 | //prepare the answers |
184 | - $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
|
184 | + $prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files); |
|
185 | 185 | |
186 | 186 | // save the user data |
187 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
187 | + $answers_saved = Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id); |
|
188 | 188 | |
189 | 189 | // were the answers saved correctly? |
190 | - if( intval( $answers_saved ) > 0){ |
|
190 | + if (intval($answers_saved) > 0) { |
|
191 | 191 | |
192 | 192 | // save transient to make retrieval faster |
193 | 193 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
194 | + set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS); |
|
195 | 195 | |
196 | 196 | // update the message showed to user |
197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
197 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>'; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | return $answers_saved; |
@@ -216,41 +216,41 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return array $answers or false |
218 | 218 | */ |
219 | - public function get_user_answers( $lesson_id, $user_id ){ |
|
219 | + public function get_user_answers($lesson_id, $user_id) { |
|
220 | 220 | |
221 | 221 | $answers = false; |
222 | 222 | |
223 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
224 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
223 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
224 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // save some time and get the transient cached data |
229 | 229 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
230 | - $transient_cached_answers = get_transient( $transient_key ); |
|
230 | + $transient_cached_answers = get_transient($transient_key); |
|
231 | 231 | |
232 | 232 | // return the transient or get the values get the values from the comment meta |
233 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
233 | + if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) { |
|
234 | 234 | |
235 | 235 | $encoded_user_answers = $transient_cached_answers; |
236 | 236 | |
237 | - }else{ |
|
237 | + } else { |
|
238 | 238 | |
239 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
239 | + $encoded_user_answers = Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id); |
|
240 | 240 | |
241 | 241 | } // end if transient check |
242 | 242 | |
243 | - if( ! is_array( $encoded_user_answers ) ){ |
|
243 | + if ( ! is_array($encoded_user_answers)) { |
|
244 | 244 | return false; |
245 | 245 | } |
246 | 246 | |
247 | 247 | //set the transient with the new valid data for faster retrieval in future |
248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
248 | + set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
249 | 249 | |
250 | 250 | // decode an unserialize all answers |
251 | - foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
|
252 | - $decoded_answer = base64_decode( $encoded_answer ); |
|
253 | - $answers[$question_id] = maybe_unserialize( $decoded_answer ); |
|
251 | + foreach ($encoded_user_answers as $question_id => $encoded_answer) { |
|
252 | + $decoded_answer = base64_decode($encoded_answer); |
|
253 | + $answers[$question_id] = maybe_unserialize($decoded_answer); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $answers; |
@@ -267,23 +267,23 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return void; |
269 | 269 | */ |
270 | - public function reset_button_click_listener( ){ |
|
270 | + public function reset_button_click_listener( ) { |
|
271 | 271 | |
272 | - if( ! isset( $_POST[ 'quiz_reset' ]) |
|
273 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce' ) > 1 ) { |
|
272 | + if ( ! isset($_POST['quiz_reset']) |
|
273 | + || ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) { |
|
274 | 274 | |
275 | 275 | return; // exit |
276 | 276 | } |
277 | 277 | |
278 | 278 | global $post; |
279 | 279 | $current_quiz_id = $post->ID; |
280 | - $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
|
280 | + $lesson_id = $this->get_lesson_id($current_quiz_id); |
|
281 | 281 | |
282 | 282 | // reset all user data |
283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
283 | + $this->reset_user_lesson_data($lesson_id, get_current_user_id()); |
|
284 | 284 | |
285 | 285 | //this function should only run once |
286 | - remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
286 | + remove_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
287 | 287 | |
288 | 288 | } // end reset_button_click_listener |
289 | 289 | |
@@ -302,18 +302,18 @@ discard block |
||
302 | 302 | public function user_quiz_submit_listener() { |
303 | 303 | |
304 | 304 | // only respond to valid quiz completion submissions |
305 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
306 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
307 | - || empty( $_POST[ 'sensei_question' ] ) |
|
308 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
305 | + if ( ! isset($_POST['quiz_complete']) |
|
306 | + || ! isset($_POST['sensei_question']) |
|
307 | + || empty($_POST['sensei_question']) |
|
308 | + || ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) { |
|
309 | 309 | return; |
310 | 310 | } |
311 | 311 | |
312 | 312 | global $post, $current_user; |
313 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
314 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
313 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
314 | + $quiz_answers = $_POST['sensei_question']; |
|
315 | 315 | |
316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
316 | + self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID); |
|
317 | 317 | |
318 | 318 | } // End sensei_complete_quiz() |
319 | 319 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @access public |
328 | 328 | * |
329 | 329 | */ |
330 | - public function load_global_quiz_data(){ |
|
330 | + public function load_global_quiz_data() { |
|
331 | 331 | |
332 | 332 | global $post, $current_user; |
333 | 333 | $this->data = new stdClass(); |
@@ -336,46 +336,46 @@ discard block |
||
336 | 336 | $grade = 0; |
337 | 337 | |
338 | 338 | // Get Quiz Questions |
339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID); |
|
340 | 340 | |
341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
341 | + $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true)); |
|
342 | 342 | |
343 | 343 | // Get quiz grade type |
344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
344 | + $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true); |
|
345 | 345 | |
346 | 346 | // Get quiz pass setting |
347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
347 | + $pass_required = get_post_meta($post->ID, '_pass_required', true); |
|
348 | 348 | |
349 | 349 | // Get quiz pass mark |
350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
350 | + $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2)); |
|
351 | 351 | |
352 | 352 | // Get latest quiz answers and grades |
353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
355 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
353 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); |
|
354 | + $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id()); |
|
355 | + $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID); |
|
356 | 356 | $user_quiz_grade = 0; |
357 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
357 | + if (isset($user_lesson_status->comment_ID)) { |
|
358 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
361 | + if ( ! is_array($user_quizzes)) { $user_quizzes = array(); } |
|
362 | 362 | |
363 | 363 | // Check again that the lesson is complete |
364 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
364 | + $user_lesson_end = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
365 | 365 | $user_lesson_complete = false; |
366 | - if ( $user_lesson_end ) { |
|
366 | + if ($user_lesson_end) { |
|
367 | 367 | $user_lesson_complete = true; |
368 | 368 | } // End If Statement |
369 | 369 | |
370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
370 | + $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); |
|
371 | 371 | //backwards compatibility |
372 | - if( 'on' == $reset_allowed ) { |
|
372 | + if ('on' == $reset_allowed) { |
|
373 | 373 | $reset_allowed = 1; |
374 | 374 | } |
375 | 375 | |
376 | 376 | // Build frontend data object for backwards compatibility |
377 | 377 | // using this is no longer recommended |
378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
378 | + $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
379 | 379 | $this->data->quiz_passmark = $quiz_passmark; |
380 | 380 | $this->data->quiz_lesson = $quiz_lesson_id; |
381 | 381 | $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
@@ -400,41 +400,41 @@ discard block |
||
400 | 400 | * @param $files |
401 | 401 | * @return array |
402 | 402 | */ |
403 | - public static function prepare_form_submitted_answers( $unprepared_answers, $files ){ |
|
403 | + public static function prepare_form_submitted_answers($unprepared_answers, $files) { |
|
404 | 404 | |
405 | 405 | |
406 | 406 | $prepared_answers = array(); |
407 | 407 | |
408 | 408 | // validate incoming answers |
409 | - if( empty( $unprepared_answers ) || ! is_array( $unprepared_answers ) ){ |
|
409 | + if (empty($unprepared_answers) || ! is_array($unprepared_answers)) { |
|
410 | 410 | return false; |
411 | 411 | } |
412 | 412 | |
413 | 413 | // Loop through submitted quiz answers and save them appropriately |
414 | - foreach( $unprepared_answers as $question_id => $answer ) { |
|
414 | + foreach ($unprepared_answers as $question_id => $answer) { |
|
415 | 415 | |
416 | 416 | //get the current questions question type |
417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
417 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
418 | 418 | |
419 | 419 | // Sanitise answer |
420 | - if( 0 == get_magic_quotes_gpc() ) { |
|
421 | - $answer = wp_unslash( $answer ); |
|
420 | + if (0 == get_magic_quotes_gpc()) { |
|
421 | + $answer = wp_unslash($answer); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | // compress the answer for saving |
425 | - if( 'multi-line' == $question_type ) { |
|
426 | - $answer = esc_html( $answer ); |
|
427 | - }elseif( 'file-upload' == $question_type ){ |
|
428 | - $file_key = 'file_upload_' . $question_id; |
|
429 | - if( isset( $files[ $file_key ] ) ) { |
|
430 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
431 | - if( $attachment_id ) { |
|
425 | + if ('multi-line' == $question_type) { |
|
426 | + $answer = esc_html($answer); |
|
427 | + }elseif ('file-upload' == $question_type) { |
|
428 | + $file_key = 'file_upload_'.$question_id; |
|
429 | + if (isset($files[$file_key])) { |
|
430 | + $attachment_id = Sensei_Utils::upload_file($files[$file_key]); |
|
431 | + if ($attachment_id) { |
|
432 | 432 | $answer = $attachment_id; |
433 | 433 | } |
434 | 434 | } |
435 | 435 | } // end if |
436 | 436 | |
437 | - $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
|
437 | + $prepared_answers[$question_id] = base64_encode(maybe_serialize($answer)); |
|
438 | 438 | |
439 | 439 | }// end for each $quiz_answers |
440 | 440 | |
@@ -454,54 +454,54 @@ discard block |
||
454 | 454 | * @param int $user_id |
455 | 455 | * @param int $lesson_id |
456 | 456 | */ |
457 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
457 | + public function reset_user_lesson_data($lesson_id, $user_id = 0) { |
|
458 | 458 | |
459 | 459 | //make sure the parameters are valid |
460 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
461 | - || 'lesson' != get_post_type( $lesson_id ) |
|
462 | - || ! get_userdata( $user_id ) ){ |
|
460 | + if (empty($lesson_id) || empty($user_id) |
|
461 | + || 'lesson' != get_post_type($lesson_id) |
|
462 | + || ! get_userdata($user_id)) { |
|
463 | 463 | return false; |
464 | 464 | } |
465 | 465 | |
466 | 466 | |
467 | 467 | |
468 | 468 | //get the users lesson status to make |
469 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
470 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
469 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
470 | + if ( ! isset($user_lesson_status->comment_ID)) { |
|
471 | 471 | // this user is not taking this lesson so this process is not needed |
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | |
475 | 475 | //get the lesson quiz and course |
476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
476 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
477 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
478 | 478 | |
479 | 479 | // reset the transients |
480 | 480 | $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
481 | 481 | $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
482 | 482 | $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
483 | - delete_transient( $answers_transient_key ); |
|
484 | - delete_transient( $grades_transient_key ); |
|
485 | - delete_transient( $answers_feedback_transient_key ); |
|
483 | + delete_transient($answers_transient_key); |
|
484 | + delete_transient($grades_transient_key); |
|
485 | + delete_transient($answers_feedback_transient_key); |
|
486 | 486 | |
487 | 487 | // reset the quiz answers and feedback notes |
488 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
489 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
490 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
488 | + $deleted_answers = Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id); |
|
489 | + $deleted_grades = Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id); |
|
490 | + $deleted_user_feedback = Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
491 | 491 | |
492 | 492 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
493 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
493 | + Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id); |
|
494 | 494 | |
495 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
495 | + Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => '')); |
|
496 | 496 | |
497 | 497 | // Update course completion |
498 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
498 | + Sensei_Utils::update_course_status($user_id, $course_id); |
|
499 | 499 | |
500 | 500 | // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
501 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
502 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>'; |
|
503 | 503 | |
504 | - return ( $deleted_answers && $deleted_grades ) ; |
|
504 | + return ($deleted_answers && $deleted_grades); |
|
505 | 505 | |
506 | 506 | } // end reset_user_lesson_data |
507 | 507 | |
@@ -521,20 +521,20 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @return bool $answers_submitted |
523 | 523 | */ |
524 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
524 | + public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
525 | 525 | |
526 | 526 | $answers_submitted = false; |
527 | 527 | |
528 | 528 | // get the user_id if none was passed in use the current logged in user |
529 | - if( ! intval( $user_id ) > 0 ) { |
|
529 | + if ( ! intval($user_id) > 0) { |
|
530 | 530 | $user_id = get_current_user_id(); |
531 | 531 | } |
532 | 532 | |
533 | 533 | // make sure the parameters are valid before continuing |
534 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
535 | - || 'lesson' != get_post_type( $lesson_id ) |
|
536 | - ||!get_userdata( $user_id ) |
|
537 | - || !is_array( $quiz_answers ) ){ |
|
534 | + if (empty($lesson_id) || empty($user_id) |
|
535 | + || 'lesson' != get_post_type($lesson_id) |
|
536 | + ||! get_userdata($user_id) |
|
537 | + || ! is_array($quiz_answers)) { |
|
538 | 538 | |
539 | 539 | return false; |
540 | 540 | |
@@ -544,38 +544,38 @@ discard block |
||
544 | 544 | $grade = 0; |
545 | 545 | |
546 | 546 | // Get Quiz ID |
547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
547 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
548 | 548 | |
549 | 549 | // Get quiz grade type |
550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
550 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
551 | 551 | |
552 | 552 | // Get quiz pass setting |
553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
553 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
554 | 554 | |
555 | 555 | // Get the minimum percentage need to pass this quiz |
556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
556 | + $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
557 | 557 | |
558 | 558 | // Handle Quiz Questions asked |
559 | 559 | // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
560 | 560 | // the quiz is reset by admin or user( user: only if the setting is enabled ). |
561 | 561 | // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
562 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
564 | - if( empty( $questions_asked ) ){ |
|
562 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
563 | + $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); |
|
564 | + if (empty($questions_asked)) { |
|
565 | 565 | |
566 | - $questions_asked = array_keys( $quiz_answers ); |
|
567 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
566 | + $questions_asked = array_keys($quiz_answers); |
|
567 | + $questions_asked_string = implode(',', $questions_asked); |
|
568 | 568 | |
569 | 569 | // Save questions that were asked in this quiz |
570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
570 | + update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string); |
|
571 | 571 | |
572 | 572 | } |
573 | 573 | |
574 | 574 | // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
575 | + self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id); |
|
576 | 576 | |
577 | 577 | // Grade quiz |
578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
578 | + $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type); |
|
579 | 579 | |
580 | 580 | // Get Lesson Grading Setting |
581 | 581 | $lesson_metadata = array(); |
@@ -585,13 +585,13 @@ discard block |
||
585 | 585 | $answers_submitted = true; |
586 | 586 | |
587 | 587 | // if this condition is false the quiz should manually be graded by admin |
588 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
588 | + if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) { |
|
589 | 589 | |
590 | 590 | // Quiz has been automatically Graded |
591 | - if ( 'on' == $pass_required ) { |
|
591 | + if ('on' == $pass_required) { |
|
592 | 592 | |
593 | 593 | // Student has reached the pass mark and lesson is complete |
594 | - if ( $quiz_pass_percentage <= $grade ) { |
|
594 | + if ($quiz_pass_percentage <= $grade) { |
|
595 | 595 | |
596 | 596 | $lesson_status = 'passed'; |
597 | 597 | |
@@ -612,9 +612,9 @@ discard block |
||
612 | 612 | |
613 | 613 | } // end if ! is_wp_error( $grade ... |
614 | 614 | |
615 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
615 | + Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata); |
|
616 | 616 | |
617 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
617 | + if ('passed' == $lesson_status || 'graded' == $lesson_status) { |
|
618 | 618 | |
619 | 619 | /** |
620 | 620 | * Lesson end action hook |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * @param int $user_id |
625 | 625 | * @param int $lesson_id |
626 | 626 | */ |
627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
627 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
628 | 628 | |
629 | 629 | } |
630 | 630 | |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | * @param string $quiz_pass_percentage |
641 | 641 | * @param string $quiz_grade_type |
642 | 642 | */ |
643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
643 | + do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type); |
|
644 | 644 | |
645 | 645 | return $answers_submitted; |
646 | 646 | |
@@ -660,38 +660,38 @@ discard block |
||
660 | 660 | * |
661 | 661 | * @return bool $answers_submitted |
662 | 662 | */ |
663 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
663 | + public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) { |
|
664 | 664 | |
665 | 665 | // parameter validation |
666 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
667 | - || ! ( intval( $lesson_id ) > 0 ) |
|
668 | - || ! ( intval( $question_id ) > 0 ) |
|
669 | - || 'lesson' != get_post_type( $lesson_id ) |
|
670 | - || 'question' != get_post_type( $question_id )) { |
|
666 | + if (empty($lesson_id) || empty($question_id) |
|
667 | + || ! (intval($lesson_id) > 0) |
|
668 | + || ! (intval($question_id) > 0) |
|
669 | + || 'lesson' != get_post_type($lesson_id) |
|
670 | + || 'question' != get_post_type($question_id)) { |
|
671 | 671 | |
672 | 672 | return false; |
673 | 673 | } |
674 | 674 | |
675 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
675 | + if ( ! (intval($user_id) > 0)) { |
|
676 | 676 | $user_id = get_current_user_id(); |
677 | 677 | } |
678 | 678 | |
679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
679 | + $users_answers = $this->get_user_answers($lesson_id, $user_id); |
|
680 | 680 | |
681 | - if( !$users_answers || empty( $users_answers ) |
|
682 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
681 | + if ( ! $users_answers || empty($users_answers) |
|
682 | + || ! is_array($users_answers) || ! isset($users_answers[$question_id])) { |
|
683 | 683 | |
684 | 684 | //Fallback for pre 1.7.4 data |
685 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
685 | + $comment = Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true); |
|
686 | 686 | |
687 | - if( ! isset( $comment->comment_content ) ){ |
|
687 | + if ( ! isset($comment->comment_content)) { |
|
688 | 688 | return false; |
689 | 689 | } |
690 | 690 | |
691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
691 | + return maybe_unserialize(base64_decode($comment->comment_content)); |
|
692 | 692 | } |
693 | 693 | |
694 | - return $users_answers[ $question_id ]; |
|
694 | + return $users_answers[$question_id]; |
|
695 | 695 | |
696 | 696 | }// end get_user_question_answer |
697 | 697 | |
@@ -712,18 +712,18 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @return bool |
714 | 714 | */ |
715 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
715 | + public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) { |
|
716 | 716 | |
717 | 717 | // get the user_id if none was passed in use the current logged in user |
718 | - if( ! intval( $user_id ) > 0 ) { |
|
718 | + if ( ! intval($user_id) > 0) { |
|
719 | 719 | $user_id = get_current_user_id(); |
720 | 720 | } |
721 | 721 | |
722 | 722 | // make sure the parameters are valid before continuing |
723 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
724 | - || 'lesson' != get_post_type( $lesson_id ) |
|
725 | - ||!get_userdata( $user_id ) |
|
726 | - || !is_array( $quiz_grades ) ){ |
|
723 | + if (empty($lesson_id) || empty($user_id) |
|
724 | + || 'lesson' != get_post_type($lesson_id) |
|
725 | + ||! get_userdata($user_id) |
|
726 | + || ! is_array($quiz_grades)) { |
|
727 | 727 | |
728 | 728 | return false; |
729 | 729 | |
@@ -732,15 +732,15 @@ discard block |
||
732 | 732 | $success = false; |
733 | 733 | |
734 | 734 | // save that data for the user on the lesson comment meta |
735 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
735 | + $comment_meta_id = Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id); |
|
736 | 736 | |
737 | 737 | // were the grades save successfully ? |
738 | - if( intval( $comment_meta_id ) > 0 ) { |
|
738 | + if (intval($comment_meta_id) > 0) { |
|
739 | 739 | |
740 | 740 | $success = true; |
741 | 741 | // save transient |
742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
742 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
743 | + set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | return $success; |
@@ -759,36 +759,36 @@ discard block |
||
759 | 759 | * |
760 | 760 | * @return array $user_quiz_grades or false if none exists for this users |
761 | 761 | */ |
762 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
762 | + public function get_user_grades($lesson_id, $user_id = 0) { |
|
763 | 763 | |
764 | 764 | $user_grades = array(); |
765 | 765 | |
766 | 766 | // get the user_id if none was passed in use the current logged in user |
767 | - if( ! intval( $user_id ) > 0 ) { |
|
767 | + if ( ! intval($user_id) > 0) { |
|
768 | 768 | $user_id = get_current_user_id(); |
769 | 769 | } |
770 | 770 | |
771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
772 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
771 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
772 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
773 | 773 | return false; |
774 | 774 | } |
775 | 775 | |
776 | 776 | // save some time and get the transient cached data |
777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
778 | - $user_grades = get_transient( $transient_key ); |
|
777 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
778 | + $user_grades = get_transient($transient_key); |
|
779 | 779 | |
780 | 780 | // get the data if nothing was stored in the transient |
781 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
781 | + if (empty($user_grades) || false != $user_grades) { |
|
782 | 782 | |
783 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
783 | + $user_grades = Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id); |
|
784 | 784 | |
785 | 785 | //set the transient with the new valid data for faster retrieval in future |
786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
786 | + set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS); |
|
787 | 787 | |
788 | 788 | } // end if transient check |
789 | 789 | |
790 | 790 | // if there is no data for this user |
791 | - if( ! is_array( $user_grades ) ){ |
|
791 | + if ( ! is_array($user_grades)) { |
|
792 | 792 | return false; |
793 | 793 | } |
794 | 794 | |
@@ -811,21 +811,21 @@ discard block |
||
811 | 811 | * |
812 | 812 | * @return bool $question_grade |
813 | 813 | */ |
814 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
814 | + public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) { |
|
815 | 815 | |
816 | 816 | // parameter validation |
817 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
818 | - || ! ( intval( $lesson_id ) > 0 ) |
|
819 | - || ! ( intval( $question_id ) > 0 ) |
|
820 | - || 'lesson' != get_post_type( $lesson_id ) |
|
821 | - || 'question' != get_post_type( $question_id )) { |
|
817 | + if (empty($lesson_id) || empty($question_id) |
|
818 | + || ! (intval($lesson_id) > 0) |
|
819 | + || ! (intval($question_id) > 0) |
|
820 | + || 'lesson' != get_post_type($lesson_id) |
|
821 | + || 'question' != get_post_type($question_id)) { |
|
822 | 822 | |
823 | 823 | return false; |
824 | 824 | } |
825 | 825 | |
826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
826 | + $all_user_grades = self::get_user_grades($lesson_id, $user_id); |
|
827 | 827 | |
828 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
828 | + if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) { |
|
829 | 829 | |
830 | 830 | //fallback to data pre 1.7.4 |
831 | 831 | $args = array( |
@@ -834,17 +834,17 @@ discard block |
||
834 | 834 | 'type' => 'sensei_user_answer' |
835 | 835 | ); |
836 | 836 | |
837 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
837 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); |
|
838 | 838 | $fall_back_grade = false; |
839 | - if( isset( $question_activity->comment_ID ) ){ |
|
840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
839 | + if (isset($question_activity->comment_ID)) { |
|
840 | + $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | return $fall_back_grade; |
844 | 844 | |
845 | 845 | } // end if $all_user_grades... |
846 | 846 | |
847 | - return $all_user_grades[ $question_id ]; |
|
847 | + return $all_user_grades[$question_id]; |
|
848 | 848 | |
849 | 849 | }// end get_user_question_grade |
850 | 850 | |
@@ -866,13 +866,13 @@ discard block |
||
866 | 866 | * |
867 | 867 | * @return false or int $feedback_saved |
868 | 868 | */ |
869 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
869 | + public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) { |
|
870 | 870 | |
871 | 871 | // make sure the parameters are valid before continuing |
872 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
873 | - || 'lesson' != get_post_type( $lesson_id ) |
|
874 | - ||!get_userdata( $user_id ) |
|
875 | - || !is_array( $answers_feedback ) ){ |
|
872 | + if (empty($lesson_id) || empty($user_id) |
|
873 | + || 'lesson' != get_post_type($lesson_id) |
|
874 | + ||! get_userdata($user_id) |
|
875 | + || ! is_array($answers_feedback)) { |
|
876 | 876 | |
877 | 877 | return false; |
878 | 878 | |
@@ -880,25 +880,25 @@ discard block |
||
880 | 880 | |
881 | 881 | |
882 | 882 | // check if the lesson is started before saving, if not start the lesson for the user |
883 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
884 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
883 | + if ( ! (0 < intval(Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) { |
|
884 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | // encode the feedback |
888 | - $encoded_answers_feedback = array(); |
|
889 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
888 | + $encoded_answers_feedback = array(); |
|
889 | + foreach ($answers_feedback as $question_id => $feedback) { |
|
890 | + $encoded_answers_feedback[$question_id] = base64_encode($feedback); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | // save the user data |
894 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
894 | + $feedback_saved = Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id); |
|
895 | 895 | |
896 | 896 | //Were the the question feedback save correctly? |
897 | - if( intval( $feedback_saved ) > 0){ |
|
897 | + if (intval($feedback_saved) > 0) { |
|
898 | 898 | |
899 | 899 | // save transient to make retrieval faster in future |
900 | 900 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
901 | + set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS); |
|
902 | 902 | |
903 | 903 | } |
904 | 904 | |
@@ -923,42 +923,42 @@ discard block |
||
923 | 923 | * $type string $question_feedback |
924 | 924 | * } |
925 | 925 | */ |
926 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
926 | + public function get_user_answers_feedback($lesson_id, $user_id = 0) { |
|
927 | 927 | |
928 | 928 | $answers_feedback = array(); |
929 | 929 | |
930 | 930 | // get the user_id if none was passed in use the current logged in user |
931 | - if( ! intval( $user_id ) > 0 ) { |
|
931 | + if ( ! intval($user_id) > 0) { |
|
932 | 932 | $user_id = get_current_user_id(); |
933 | 933 | } |
934 | 934 | |
935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
936 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
935 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
936 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
937 | 937 | return false; |
938 | 938 | } |
939 | 939 | |
940 | 940 | // first check the transient to save a few split seconds |
941 | 941 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
942 | - $encoded_feedback = get_transient( $transient_key ); |
|
942 | + $encoded_feedback = get_transient($transient_key); |
|
943 | 943 | |
944 | 944 | // get the data if nothing was stored in the transient |
945 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
945 | + if (empty($encoded_feedback) || ! $encoded_feedback) { |
|
946 | 946 | |
947 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
947 | + $encoded_feedback = Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
948 | 948 | |
949 | 949 | //set the transient with the new valid data for faster retrieval in future |
950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
950 | + set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
951 | 951 | |
952 | 952 | } // end if transient check |
953 | 953 | |
954 | 954 | // if there is no data for this user |
955 | - if( ! is_array( $encoded_feedback ) ){ |
|
955 | + if ( ! is_array($encoded_feedback)) { |
|
956 | 956 | return false; |
957 | 957 | } |
958 | 958 | |
959 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
959 | + foreach ($encoded_feedback as $question_id => $feedback) { |
|
960 | 960 | |
961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
961 | + $answers_feedback[$question_id] = base64_decode($feedback); |
|
962 | 962 | |
963 | 963 | } |
964 | 964 | |
@@ -981,25 +981,25 @@ discard block |
||
981 | 981 | * |
982 | 982 | * @return string $feedback or bool if false |
983 | 983 | */ |
984 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
984 | + public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) { |
|
985 | 985 | |
986 | 986 | $feedback = false; |
987 | 987 | |
988 | 988 | // parameter validation |
989 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
990 | - || ! ( intval( $lesson_id ) > 0 ) |
|
991 | - || ! ( intval( $question_id ) > 0 ) |
|
992 | - || 'lesson' != get_post_type( $lesson_id ) |
|
993 | - || 'question' != get_post_type( $question_id )) { |
|
989 | + if (empty($lesson_id) || empty($question_id) |
|
990 | + || ! (intval($lesson_id) > 0) |
|
991 | + || ! (intval($question_id) > 0) |
|
992 | + || 'lesson' != get_post_type($lesson_id) |
|
993 | + || 'question' != get_post_type($question_id)) { |
|
994 | 994 | |
995 | 995 | return false; |
996 | 996 | } |
997 | 997 | |
998 | 998 | // get all the feedback for the user on the given lesson |
999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
999 | + $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id); |
|
1000 | 1000 | |
1001 | - if( !$all_feedback || empty( $all_feedback ) |
|
1002 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
1001 | + if ( ! $all_feedback || empty($all_feedback) |
|
1002 | + || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) { |
|
1003 | 1003 | |
1004 | 1004 | //fallback to data pre 1.7.4 |
1005 | 1005 | |
@@ -1009,23 +1009,23 @@ discard block |
||
1009 | 1009 | 'user_id' => $user_id, |
1010 | 1010 | 'type' => 'sensei_user_answer' |
1011 | 1011 | ); |
1012 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
1012 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); |
|
1013 | 1013 | |
1014 | 1014 | // set the default to false and return that if no old data is available. |
1015 | - if( isset( $question_activity->comment_ID ) ){ |
|
1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
1015 | + if (isset($question_activity->comment_ID)) { |
|
1016 | + $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true)); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | // finally use the default question feedback |
1020 | - if( empty( $feedback ) ){ |
|
1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
1020 | + if (empty($feedback)) { |
|
1021 | + $feedback = get_post_meta($question_id, '_answer_feedback', true); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | return $feedback; |
1025 | 1025 | |
1026 | 1026 | } |
1027 | 1027 | |
1028 | - return $all_feedback[ $question_id ]; |
|
1028 | + return $all_feedback[$question_id]; |
|
1029 | 1029 | |
1030 | 1030 | } // end get_user_question_feedback |
1031 | 1031 | |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | public function quiz_has_no_questions() { |
1045 | 1045 | |
1046 | 1046 | |
1047 | - if( ! is_singular( 'quiz' ) ) { |
|
1047 | + if ( ! is_singular('quiz')) { |
|
1048 | 1048 | return; |
1049 | 1049 | } |
1050 | 1050 | |
@@ -1052,11 +1052,11 @@ discard block |
||
1052 | 1052 | |
1053 | 1053 | $lesson_id = $this->get_lesson_id($post->ID); |
1054 | 1054 | |
1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1055 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
1056 | 1056 | |
1057 | 1057 | $lesson = get_post($lesson_id); |
1058 | 1058 | |
1059 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
1059 | + if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") { |
|
1060 | 1060 | |
1061 | 1061 | wp_redirect(get_permalink($lesson->ID), 301); |
1062 | 1062 | exit; |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * |
1071 | 1071 | * @deprecated since 1.9.0 |
1072 | 1072 | */ |
1073 | - public static function deprecate_quiz_sensei_single_main_content_hook(){ |
|
1073 | + public static function deprecate_quiz_sensei_single_main_content_hook() { |
|
1074 | 1074 | |
1075 | 1075 | sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
1076 | 1076 | |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | * |
1081 | 1081 | * @deprecated since 1.9.0 |
1082 | 1082 | */ |
1083 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
1083 | + public static function deprecate_quiz_sensei_quiz_single_title_hook() { |
|
1084 | 1084 | |
1085 | 1085 | sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
1086 | 1086 | |
@@ -1093,29 +1093,29 @@ discard block |
||
1093 | 1093 | * @param int $id title post id |
1094 | 1094 | * @return string $quiz_title |
1095 | 1095 | */ |
1096 | - public static function single_quiz_title( $title, $post_id ){ |
|
1096 | + public static function single_quiz_title($title, $post_id) { |
|
1097 | 1097 | |
1098 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
1098 | + if ('quiz' == get_post_type($post_id)) { |
|
1099 | 1099 | |
1100 | 1100 | $title_with_no_quizzes = $title; |
1101 | 1101 | |
1102 | 1102 | // if the title has quiz, remove it: legacy titles have the word quiz stored. |
1103 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
1103 | + if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) { |
|
1104 | 1104 | |
1105 | 1105 | // remove all possible appearances of quiz |
1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
1106 | + $title_with_no_quizzes = str_replace('quiz', '', $title); |
|
1107 | + $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes); |
|
1108 | + $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes); |
|
1109 | 1109 | |
1110 | 1110 | } |
1111 | 1111 | |
1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
1112 | + $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei'); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | /** |
1116 | 1116 | * hook document in class-woothemes-sensei-message.php |
1117 | 1117 | */ |
1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
1118 | + return apply_filters('sensei_single_title', $title, get_post_type( )); |
|
1119 | 1119 | |
1120 | 1120 | } |
1121 | 1121 | |
@@ -1127,21 +1127,21 @@ discard block |
||
1127 | 1127 | * @since 1.9.0 |
1128 | 1128 | * |
1129 | 1129 | */ |
1130 | - public static function start_quiz_questions_loop(){ |
|
1130 | + public static function start_quiz_questions_loop() { |
|
1131 | 1131 | |
1132 | 1132 | global $sensei_question_loop; |
1133 | 1133 | |
1134 | 1134 | //intialize the questions loop object |
1135 | 1135 | $sensei_question_loop['current'] = -1; |
1136 | - $sensei_question_loop['total'] = 0; |
|
1136 | + $sensei_question_loop['total'] = 0; |
|
1137 | 1137 | $sensei_question_loop['questions'] = array(); |
1138 | 1138 | |
1139 | 1139 | |
1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
1140 | + $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID()); |
|
1141 | 1141 | |
1142 | - if( count( $questions ) > 0 ){ |
|
1142 | + if (count($questions) > 0) { |
|
1143 | 1143 | |
1144 | - $sensei_question_loop['total'] = count( $questions ); |
|
1144 | + $sensei_question_loop['total'] = count($questions); |
|
1145 | 1145 | $sensei_question_loop['questions'] = $questions; |
1146 | 1146 | $sensei_question_loop['quiz_id'] = get_the_ID(); |
1147 | 1147 | |
@@ -1157,9 +1157,9 @@ discard block |
||
1157 | 1157 | * @since 1.9.0 |
1158 | 1158 | * |
1159 | 1159 | */ |
1160 | - public static function stop_quiz_questions_loop(){ |
|
1160 | + public static function stop_quiz_questions_loop() { |
|
1161 | 1161 | |
1162 | - $sensei_question_loop['total'] = 0; |
|
1162 | + $sensei_question_loop['total'] = 0; |
|
1163 | 1163 | $sensei_question_loop['questions'] = array(); |
1164 | 1164 | $sensei_question_loop['quiz_id'] = ''; |
1165 | 1165 | |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | * |
1171 | 1171 | * @since 1.9.0 |
1172 | 1172 | */ |
1173 | - public static function the_title(){ |
|
1173 | + public static function the_title() { |
|
1174 | 1174 | ?> |
1175 | 1175 | <header> |
1176 | 1176 | |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | /** |
1181 | 1181 | * Filter documented in class-sensei-messages.php the_title |
1182 | 1182 | */ |
1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
1183 | + echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID())); |
|
1184 | 1184 | ?> |
1185 | 1185 | |
1186 | 1186 | </h1> |
@@ -1195,11 +1195,11 @@ discard block |
||
1195 | 1195 | * |
1196 | 1196 | * @param $quiz_id |
1197 | 1197 | */ |
1198 | - public static function the_user_status_message( $quiz_id ){ |
|
1198 | + public static function the_user_status_message($quiz_id) { |
|
1199 | 1199 | |
1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
1201 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
1200 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
1201 | + $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id()); |
|
1202 | + echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>'; |
|
1203 | 1203 | |
1204 | 1204 | } |
1205 | 1205 | |
@@ -1210,9 +1210,9 @@ discard block |
||
1210 | 1210 | * @since 1.9.0 |
1211 | 1211 | * @deprecated |
1212 | 1212 | */ |
1213 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
1213 | + public static function deprecate_sensei_quiz_action_buttons_hook() { |
|
1214 | 1214 | |
1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1215 | + sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1216 | 1216 | |
1217 | 1217 | } |
1218 | 1218 | |
@@ -1226,50 +1226,50 @@ discard block |
||
1226 | 1226 | |
1227 | 1227 | global $post, $current_user; |
1228 | 1228 | |
1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1229 | + $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true); |
|
1230 | + $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true); |
|
1231 | + $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
1232 | 1232 | $show_actions = true; |
1233 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
1233 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID); |
|
1234 | 1234 | |
1235 | 1235 | //setup quiz grade |
1236 | 1236 | $user_quiz_grade = ''; |
1237 | - if( ! empty( $user_lesson_status ) ){ |
|
1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1237 | + if ( ! empty($user_lesson_status)) { |
|
1238 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | |
1242 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
1242 | + if (intval($lesson_prerequisite) > 0) { |
|
1243 | 1243 | |
1244 | 1244 | // If the user hasn't completed the prereq then hide the current actions |
1245 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
1245 | + $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID); |
|
1246 | 1246 | |
1247 | 1247 | } |
1248 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
1248 | + if ($show_actions && is_user_logged_in() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
1249 | 1249 | |
1250 | 1250 | // Get Reset Settings |
1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
1251 | + $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?> |
|
1252 | 1252 | |
1253 | 1253 | <!-- Action Nonce's --> |
1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
1255 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" /> |
|
1255 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" /> |
|
1256 | 1256 | <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce" |
1257 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" /> |
|
1257 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" /> |
|
1258 | 1258 | <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce" |
1259 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" /> |
|
1259 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" /> |
|
1260 | 1260 | <!--#end Action Nonce's --> |
1261 | 1261 | |
1262 | - <?php if ( '' == $user_quiz_grade) { ?> |
|
1262 | + <?php if ('' == $user_quiz_grade) { ?> |
|
1263 | 1263 | |
1264 | - <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
1264 | + <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span> |
|
1265 | 1265 | |
1266 | - <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
1266 | + <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span> |
|
1267 | 1267 | |
1268 | 1268 | <?php } // End If Statement ?> |
1269 | 1269 | |
1270 | - <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?> |
|
1270 | + <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?> |
|
1271 | 1271 | |
1272 | - <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
1272 | + <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span> |
|
1273 | 1273 | |
1274 | 1274 | <?php } ?> |
1275 | 1275 | |
@@ -1287,13 +1287,13 @@ discard block |
||
1287 | 1287 | * |
1288 | 1288 | * @return double $user_quiz_grade |
1289 | 1289 | */ |
1290 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
1290 | + public static function get_user_quiz_grade($lesson_id, $user_id) { |
|
1291 | 1291 | |
1292 | 1292 | // get the quiz grade |
1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
1294 | 1294 | $user_quiz_grade = 0; |
1295 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1295 | + if (isset($user_lesson_status->comment_ID)) { |
|
1296 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | return (double) $user_quiz_grade; |
@@ -1311,13 +1311,13 @@ discard block |
||
1311 | 1311 | * @param int $lesson_id |
1312 | 1312 | * @return bool |
1313 | 1313 | */ |
1314 | - public static function is_reset_allowed( $lesson_id ){ |
|
1314 | + public static function is_reset_allowed($lesson_id) { |
|
1315 | 1315 | |
1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1317 | 1317 | |
1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
1318 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
1319 | 1319 | //backwards compatibility |
1320 | - if( 'on' == $reset_allowed ) { |
|
1320 | + if ('on' == $reset_allowed) { |
|
1321 | 1321 | $reset_allowed = 1; |
1322 | 1322 | } |
1323 | 1323 | |
@@ -1334,4 +1334,4 @@ discard block |
||
1334 | 1334 | * for backward compatibility |
1335 | 1335 | * @since 1.9.0 |
1336 | 1336 | */ |
1337 | -class WooThemes_Sensei_Quiz extends Sensei_Quiz{} |
|
1337 | +class WooThemes_Sensei_Quiz extends Sensei_Quiz {} |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly. |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Course Component Widget |
@@ -26,30 +26,30 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?></span> |
|
252 | + <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).' '.__('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 |