@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * The Template for displaying all single courses. |
|
4 | - * |
|
5 | - * Override this template by copying it to yourtheme/sensei/single-course.php |
|
6 | - * |
|
7 | - * @author Automattic |
|
8 | - * @package Sensei |
|
9 | - * @category Templates |
|
10 | - * @version 1.9.0 |
|
11 | - */ |
|
3 | + * The Template for displaying all single courses. |
|
4 | + * |
|
5 | + * Override this template by copying it to yourtheme/sensei/single-course.php |
|
6 | + * |
|
7 | + * @author Automattic |
|
8 | + * @package Sensei |
|
9 | + * @category Templates |
|
10 | + * @version 1.9.0 |
|
11 | + */ |
|
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <?php get_sensei_header(); ?> |
@@ -17,24 +17,24 @@ discard block |
||
17 | 17 | |
18 | 18 | <?php |
19 | 19 | |
20 | - /** |
|
21 | - * Hook inside the single course post above the content |
|
22 | - * |
|
23 | - * @since 1.9.0 |
|
24 | - * |
|
25 | - * @param integer $course_id |
|
26 | - * |
|
27 | - * @hooked Sensei()->frontend->sensei_course_start - 10 |
|
28 | - * @hooked Sensei_Course::the_title - 10 |
|
29 | - * @hooked Sensei()->course->course_image - 20 |
|
30 | - * @hooked Sensei_WC::course_in_cart_message - 20 |
|
31 | - * @hooked Sensei_Course::the_course_enrolment_actions - 30 |
|
32 | - * @hooked Sensei()->message->send_message_link - 35 |
|
33 | - * @hooked Sensei_Course::the_course_video - 40 |
|
34 | - */ |
|
35 | - do_action( 'sensei_single_course_content_inside_before', get_the_ID() ); |
|
36 | - |
|
37 | - ?> |
|
20 | + /** |
|
21 | + * Hook inside the single course post above the content |
|
22 | + * |
|
23 | + * @since 1.9.0 |
|
24 | + * |
|
25 | + * @param integer $course_id |
|
26 | + * |
|
27 | + * @hooked Sensei()->frontend->sensei_course_start - 10 |
|
28 | + * @hooked Sensei_Course::the_title - 10 |
|
29 | + * @hooked Sensei()->course->course_image - 20 |
|
30 | + * @hooked Sensei_WC::course_in_cart_message - 20 |
|
31 | + * @hooked Sensei_Course::the_course_enrolment_actions - 30 |
|
32 | + * @hooked Sensei()->message->send_message_link - 35 |
|
33 | + * @hooked Sensei_Course::the_course_video - 40 |
|
34 | + */ |
|
35 | + do_action( 'sensei_single_course_content_inside_before', get_the_ID() ); |
|
36 | + |
|
37 | + ?> |
|
38 | 38 | |
39 | 39 | <section class="entry fix"> |
40 | 40 | |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | |
45 | 45 | <?php |
46 | 46 | |
47 | - /** |
|
48 | - * Hook inside the single course post above the content |
|
49 | - * |
|
50 | - * @since 1.9.0 |
|
51 | - * |
|
52 | - * @param integer $course_id |
|
53 | - * |
|
54 | - */ |
|
55 | - do_action( 'sensei_single_course_content_inside_after', get_the_ID() ); |
|
56 | - |
|
57 | - ?> |
|
47 | + /** |
|
48 | + * Hook inside the single course post above the content |
|
49 | + * |
|
50 | + * @since 1.9.0 |
|
51 | + * |
|
52 | + * @param integer $course_id |
|
53 | + * |
|
54 | + */ |
|
55 | + do_action( 'sensei_single_course_content_inside_after', get_the_ID() ); |
|
56 | + |
|
57 | + ?> |
|
58 | 58 | </article><!-- .post .single-course --> |
59 | 59 | |
60 | 60 | <?php get_sensei_footer(); ?> |
61 | 61 | \ No newline at end of file |
@@ -12,251 +12,251 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Sensei_Teacher { |
14 | 14 | |
15 | - /** |
|
16 | - * $teacher_role |
|
17 | - * |
|
18 | - * Keeps a reference to the teacher role object |
|
19 | - * |
|
20 | - * @access protected |
|
21 | - * @since 1.8.0 |
|
22 | - */ |
|
23 | - protected $teacher_role; |
|
24 | - |
|
25 | - /** |
|
26 | - * $token |
|
27 | - * |
|
28 | - * Keeps a reference to the global sensei token |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @since 1.8.0 |
|
32 | - */ |
|
33 | - public $token; |
|
34 | - |
|
35 | - /** |
|
36 | - * Sensei_Teacher::__constructor |
|
37 | - * |
|
38 | - * Constructor Function |
|
39 | - * |
|
40 | - * @since 1.8.0 |
|
41 | - * @access public |
|
42 | - */ |
|
43 | - public function __construct ( ) { |
|
44 | - |
|
45 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
46 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
47 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
48 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
49 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
50 | - |
|
51 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
52 | - |
|
53 | - //filter the quiz submissions |
|
54 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
55 | - |
|
56 | - //grading totals count only those belonging to the teacher |
|
57 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
58 | - |
|
59 | - // show the courses owned by a user on his author archive page |
|
60 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
61 | - |
|
62 | - // notify admin when a teacher creates a course |
|
63 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
64 | - |
|
65 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
66 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
67 | - |
|
68 | - // give teacher access to question post type |
|
69 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
70 | - |
|
71 | - // Teacher column on the courses list on the admin edit screen |
|
72 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
73 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
74 | - |
|
75 | - //admin edit messages query limit teacher |
|
76 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
77 | - |
|
78 | - //add filter by teacher on courses list |
|
79 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
80 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
81 | - |
|
82 | - // Handle media library restrictions |
|
83 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
84 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
85 | - |
|
86 | - // update lesson owner to course teacher when saved |
|
87 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
88 | - |
|
89 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
90 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
91 | - |
|
92 | - |
|
93 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
94 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
95 | - |
|
96 | - |
|
97 | - } // end __constructor() |
|
98 | - |
|
99 | - /** |
|
100 | - * Sensei_Teacher::create_teacher_role |
|
101 | - * |
|
102 | - * This function checks if the role exist, if not it creates it. |
|
103 | - * for the teacher role |
|
104 | - * |
|
105 | - * @since 1.8.0 |
|
106 | - * @access public |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function create_role ( ) { |
|
110 | - |
|
111 | - // check if the role exists |
|
112 | - $this->teacher_role = get_role( 'teacher' ); |
|
113 | - |
|
114 | - // if the the teacher is not a valid WordPress role create it |
|
115 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
116 | - // create the role |
|
117 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
118 | - } |
|
119 | - |
|
120 | - // add the capabilities before returning |
|
121 | - $this->add_capabilities(); |
|
122 | - |
|
123 | - }// end create_teacher_role |
|
124 | - |
|
125 | - /** |
|
126 | - * Sensei_Teacher::add_capabilities |
|
127 | - * |
|
128 | - * @since 1.8.0 |
|
129 | - * @access protected |
|
130 | - */ |
|
131 | - protected function add_capabilities ( ) { |
|
132 | - |
|
133 | - // if this is not a valid WP_Role object exit without adding anything |
|
134 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
135 | - return; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Sensei teachers capabilities array filter |
|
140 | - * |
|
141 | - * These capabilities will be applied to the teacher role |
|
142 | - * @param array $capabilities |
|
143 | - * keys: (string) $cap_name => (bool) $grant |
|
144 | - */ |
|
145 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
146 | - // General access rules |
|
147 | - 'read' => true, |
|
148 | - 'manage_sensei_grades' => true, |
|
149 | - 'moderate_comments'=> true, |
|
150 | - 'upload_files' => true, |
|
151 | - 'edit_files' => true, |
|
152 | - |
|
153 | - //Lessons |
|
154 | - 'publish_lessons' => true, |
|
155 | - 'manage_lesson_categories' => true, |
|
156 | - 'edit_lessons' => true, |
|
157 | - 'edit_published_lessons' => true, |
|
158 | - 'edit_private_lessons' => true, |
|
159 | - 'read_private_lessons' => true, |
|
160 | - 'delete_published_lessons' => true, |
|
161 | - |
|
162 | - // Courses |
|
163 | - 'create_courses' => true, |
|
164 | - 'publish_courses' => false, |
|
165 | - 'manage_course_categories' => true, |
|
166 | - 'edit_courses' => true, |
|
167 | - 'edit_published_courses' => true, |
|
168 | - 'edit_private_courses' => true, |
|
169 | - 'read_private_courses' => true, |
|
170 | - 'delete_published_courses' => true, |
|
171 | - |
|
172 | - // Quiz |
|
173 | - 'publish_quizzes' => true, |
|
174 | - 'edit_quizzes' => true, |
|
175 | - 'edit_published_quizzes' => true, |
|
176 | - 'edit_private_quizzes' => true, |
|
177 | - 'read_private_quizzes' => true, |
|
178 | - |
|
179 | - // Questions |
|
180 | - 'publish_questions' => true, |
|
181 | - 'edit_questions' => true, |
|
182 | - 'edit_published_questions' => true, |
|
183 | - 'edit_private_questions' => true, |
|
184 | - 'read_private_questions' => true, |
|
185 | - |
|
186 | - //messages |
|
187 | - 'publish_sensei_messages' => true, |
|
188 | - 'edit_sensei_messages' => true, |
|
189 | - 'edit_published_sensei_messages' => true, |
|
190 | - 'edit_private_sensei_messages' => true, |
|
191 | - 'read_private_sensei_messages' => true, |
|
192 | - |
|
193 | - // Comments - |
|
194 | - // Necessary cap so Teachers can moderate comments |
|
195 | - // on their own lessons. We restrict access to other |
|
196 | - // post types in $this->restrict_posts_menu_page() |
|
197 | - |
|
198 | - 'edit_posts' => true, |
|
199 | - |
|
200 | - )); |
|
201 | - |
|
202 | - foreach ( $caps as $cap => $grant ) { |
|
203 | - |
|
204 | - // load the capability on to the teacher role |
|
205 | - $this->teacher_role->add_cap($cap, $grant); |
|
206 | - |
|
207 | - } // end for each |
|
208 | - |
|
209 | - }// end add_cap |
|
210 | - |
|
211 | - /** |
|
212 | - * Sensei_Teacher::teacher_meta_box |
|
213 | - * |
|
214 | - * Add the teacher metabox to the course post type edit screen |
|
215 | - * |
|
216 | - * @since 1.8.0 |
|
217 | - * @access public |
|
218 | - * @parameter string $post_type |
|
219 | - * @parameter WP_Post $post |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - public function add_teacher_meta_boxes ( $post ) { |
|
223 | - |
|
224 | - if( !current_user_can('manage_options') ){ |
|
225 | - return; |
|
226 | - } |
|
227 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
228 | - 'course', |
|
229 | - 'side', |
|
230 | - 'core' |
|
231 | - ); |
|
232 | - |
|
233 | - } // end teacher_meta_box() |
|
234 | - |
|
235 | - /** |
|
236 | - * Sensei_Teacher::teacher_meta_box_content |
|
237 | - * |
|
238 | - * Render the teacher meta box markup |
|
239 | - * |
|
240 | - * @since 1.8.0 |
|
241 | - * @access public |
|
242 | - * @parameters |
|
243 | - */ |
|
244 | - public function teacher_meta_box_content ( $post ) { |
|
245 | - |
|
246 | - // get the current author |
|
247 | - $current_author = $post->post_author; |
|
248 | - |
|
249 | - //get the users authorised to author courses |
|
250 | - $users = $this->get_teachers_and_authors(); |
|
251 | - |
|
252 | - ?> |
|
15 | + /** |
|
16 | + * $teacher_role |
|
17 | + * |
|
18 | + * Keeps a reference to the teacher role object |
|
19 | + * |
|
20 | + * @access protected |
|
21 | + * @since 1.8.0 |
|
22 | + */ |
|
23 | + protected $teacher_role; |
|
24 | + |
|
25 | + /** |
|
26 | + * $token |
|
27 | + * |
|
28 | + * Keeps a reference to the global sensei token |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @since 1.8.0 |
|
32 | + */ |
|
33 | + public $token; |
|
34 | + |
|
35 | + /** |
|
36 | + * Sensei_Teacher::__constructor |
|
37 | + * |
|
38 | + * Constructor Function |
|
39 | + * |
|
40 | + * @since 1.8.0 |
|
41 | + * @access public |
|
42 | + */ |
|
43 | + public function __construct ( ) { |
|
44 | + |
|
45 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
46 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
47 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
48 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
49 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
50 | + |
|
51 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
52 | + |
|
53 | + //filter the quiz submissions |
|
54 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
55 | + |
|
56 | + //grading totals count only those belonging to the teacher |
|
57 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
58 | + |
|
59 | + // show the courses owned by a user on his author archive page |
|
60 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
61 | + |
|
62 | + // notify admin when a teacher creates a course |
|
63 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
64 | + |
|
65 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
66 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
67 | + |
|
68 | + // give teacher access to question post type |
|
69 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
70 | + |
|
71 | + // Teacher column on the courses list on the admin edit screen |
|
72 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
73 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
74 | + |
|
75 | + //admin edit messages query limit teacher |
|
76 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
77 | + |
|
78 | + //add filter by teacher on courses list |
|
79 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
80 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
81 | + |
|
82 | + // Handle media library restrictions |
|
83 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
84 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
85 | + |
|
86 | + // update lesson owner to course teacher when saved |
|
87 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
88 | + |
|
89 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
90 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
91 | + |
|
92 | + |
|
93 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
94 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
95 | + |
|
96 | + |
|
97 | + } // end __constructor() |
|
98 | + |
|
99 | + /** |
|
100 | + * Sensei_Teacher::create_teacher_role |
|
101 | + * |
|
102 | + * This function checks if the role exist, if not it creates it. |
|
103 | + * for the teacher role |
|
104 | + * |
|
105 | + * @since 1.8.0 |
|
106 | + * @access public |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function create_role ( ) { |
|
110 | + |
|
111 | + // check if the role exists |
|
112 | + $this->teacher_role = get_role( 'teacher' ); |
|
113 | + |
|
114 | + // if the the teacher is not a valid WordPress role create it |
|
115 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
116 | + // create the role |
|
117 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
118 | + } |
|
119 | + |
|
120 | + // add the capabilities before returning |
|
121 | + $this->add_capabilities(); |
|
122 | + |
|
123 | + }// end create_teacher_role |
|
124 | + |
|
125 | + /** |
|
126 | + * Sensei_Teacher::add_capabilities |
|
127 | + * |
|
128 | + * @since 1.8.0 |
|
129 | + * @access protected |
|
130 | + */ |
|
131 | + protected function add_capabilities ( ) { |
|
132 | + |
|
133 | + // if this is not a valid WP_Role object exit without adding anything |
|
134 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
135 | + return; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Sensei teachers capabilities array filter |
|
140 | + * |
|
141 | + * These capabilities will be applied to the teacher role |
|
142 | + * @param array $capabilities |
|
143 | + * keys: (string) $cap_name => (bool) $grant |
|
144 | + */ |
|
145 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
146 | + // General access rules |
|
147 | + 'read' => true, |
|
148 | + 'manage_sensei_grades' => true, |
|
149 | + 'moderate_comments'=> true, |
|
150 | + 'upload_files' => true, |
|
151 | + 'edit_files' => true, |
|
152 | + |
|
153 | + //Lessons |
|
154 | + 'publish_lessons' => true, |
|
155 | + 'manage_lesson_categories' => true, |
|
156 | + 'edit_lessons' => true, |
|
157 | + 'edit_published_lessons' => true, |
|
158 | + 'edit_private_lessons' => true, |
|
159 | + 'read_private_lessons' => true, |
|
160 | + 'delete_published_lessons' => true, |
|
161 | + |
|
162 | + // Courses |
|
163 | + 'create_courses' => true, |
|
164 | + 'publish_courses' => false, |
|
165 | + 'manage_course_categories' => true, |
|
166 | + 'edit_courses' => true, |
|
167 | + 'edit_published_courses' => true, |
|
168 | + 'edit_private_courses' => true, |
|
169 | + 'read_private_courses' => true, |
|
170 | + 'delete_published_courses' => true, |
|
171 | + |
|
172 | + // Quiz |
|
173 | + 'publish_quizzes' => true, |
|
174 | + 'edit_quizzes' => true, |
|
175 | + 'edit_published_quizzes' => true, |
|
176 | + 'edit_private_quizzes' => true, |
|
177 | + 'read_private_quizzes' => true, |
|
178 | + |
|
179 | + // Questions |
|
180 | + 'publish_questions' => true, |
|
181 | + 'edit_questions' => true, |
|
182 | + 'edit_published_questions' => true, |
|
183 | + 'edit_private_questions' => true, |
|
184 | + 'read_private_questions' => true, |
|
185 | + |
|
186 | + //messages |
|
187 | + 'publish_sensei_messages' => true, |
|
188 | + 'edit_sensei_messages' => true, |
|
189 | + 'edit_published_sensei_messages' => true, |
|
190 | + 'edit_private_sensei_messages' => true, |
|
191 | + 'read_private_sensei_messages' => true, |
|
192 | + |
|
193 | + // Comments - |
|
194 | + // Necessary cap so Teachers can moderate comments |
|
195 | + // on their own lessons. We restrict access to other |
|
196 | + // post types in $this->restrict_posts_menu_page() |
|
197 | + |
|
198 | + 'edit_posts' => true, |
|
199 | + |
|
200 | + )); |
|
201 | + |
|
202 | + foreach ( $caps as $cap => $grant ) { |
|
203 | + |
|
204 | + // load the capability on to the teacher role |
|
205 | + $this->teacher_role->add_cap($cap, $grant); |
|
206 | + |
|
207 | + } // end for each |
|
208 | + |
|
209 | + }// end add_cap |
|
210 | + |
|
211 | + /** |
|
212 | + * Sensei_Teacher::teacher_meta_box |
|
213 | + * |
|
214 | + * Add the teacher metabox to the course post type edit screen |
|
215 | + * |
|
216 | + * @since 1.8.0 |
|
217 | + * @access public |
|
218 | + * @parameter string $post_type |
|
219 | + * @parameter WP_Post $post |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + public function add_teacher_meta_boxes ( $post ) { |
|
223 | + |
|
224 | + if( !current_user_can('manage_options') ){ |
|
225 | + return; |
|
226 | + } |
|
227 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
228 | + 'course', |
|
229 | + 'side', |
|
230 | + 'core' |
|
231 | + ); |
|
232 | + |
|
233 | + } // end teacher_meta_box() |
|
234 | + |
|
235 | + /** |
|
236 | + * Sensei_Teacher::teacher_meta_box_content |
|
237 | + * |
|
238 | + * Render the teacher meta box markup |
|
239 | + * |
|
240 | + * @since 1.8.0 |
|
241 | + * @access public |
|
242 | + * @parameters |
|
243 | + */ |
|
244 | + public function teacher_meta_box_content ( $post ) { |
|
245 | + |
|
246 | + // get the current author |
|
247 | + $current_author = $post->post_author; |
|
248 | + |
|
249 | + //get the users authorised to author courses |
|
250 | + $users = $this->get_teachers_and_authors(); |
|
251 | + |
|
252 | + ?> |
|
253 | 253 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
254 | 254 | |
255 | 255 | <?php foreach ( $users as $user_id ) { ?> |
256 | 256 | |
257 | 257 | <?php |
258 | - $user = get_user_by('id', $user_id); |
|
259 | - ?> |
|
258 | + $user = get_user_by('id', $user_id); |
|
259 | + ?> |
|
260 | 260 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
261 | 261 | <?php echo $user->display_name; ?> |
262 | 262 | </option> |
@@ -267,1289 +267,1289 @@ discard block |
||
267 | 267 | |
268 | 268 | <?php |
269 | 269 | |
270 | - } // end render_teacher_meta_box() |
|
271 | - |
|
272 | - /** |
|
273 | - * Sensei_Teacher::get_teachers_and_authors |
|
274 | - * |
|
275 | - * Get a list of users who can author courses, lessons and quizes. |
|
276 | - * |
|
277 | - * @since 1.8.0 |
|
278 | - * @access public |
|
279 | - * @parameters |
|
280 | - * @return array $users user id array |
|
281 | - */ |
|
282 | - public function get_teachers_and_authors ( ){ |
|
283 | - |
|
284 | - $author_query_args = array( |
|
285 | - 'blog_id' => $GLOBALS['blog_id'], |
|
286 | - 'fields' => 'any', |
|
287 | - 'who' => 'authors' |
|
288 | - ); |
|
289 | - |
|
290 | - $authors = get_users( $author_query_args ); |
|
291 | - |
|
292 | - $teacher_query_args = array( |
|
293 | - 'blog_id' => $GLOBALS['blog_id'], |
|
294 | - 'fields' => 'any', |
|
295 | - 'role' => 'teacher', |
|
296 | - ); |
|
297 | - |
|
298 | - $teachers = get_users( $teacher_query_args ); |
|
299 | - |
|
300 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
301 | - |
|
302 | - }// end get_teachers_and_authors |
|
303 | - |
|
304 | - /** |
|
305 | - * Sensei_Teacher::save_teacher_meta_box |
|
306 | - * |
|
307 | - * Save the new teacher / author to course and all lessons |
|
308 | - * |
|
309 | - * Hooked into admin_init |
|
310 | - * |
|
311 | - * @since 1.8.0 |
|
312 | - * @access public |
|
313 | - * @parameters |
|
314 | - * @return array $users user id array |
|
315 | - */ |
|
316 | - public function save_teacher_meta_box ( $course_id ){ |
|
270 | + } // end render_teacher_meta_box() |
|
271 | + |
|
272 | + /** |
|
273 | + * Sensei_Teacher::get_teachers_and_authors |
|
274 | + * |
|
275 | + * Get a list of users who can author courses, lessons and quizes. |
|
276 | + * |
|
277 | + * @since 1.8.0 |
|
278 | + * @access public |
|
279 | + * @parameters |
|
280 | + * @return array $users user id array |
|
281 | + */ |
|
282 | + public function get_teachers_and_authors ( ){ |
|
283 | + |
|
284 | + $author_query_args = array( |
|
285 | + 'blog_id' => $GLOBALS['blog_id'], |
|
286 | + 'fields' => 'any', |
|
287 | + 'who' => 'authors' |
|
288 | + ); |
|
289 | + |
|
290 | + $authors = get_users( $author_query_args ); |
|
291 | + |
|
292 | + $teacher_query_args = array( |
|
293 | + 'blog_id' => $GLOBALS['blog_id'], |
|
294 | + 'fields' => 'any', |
|
295 | + 'role' => 'teacher', |
|
296 | + ); |
|
297 | + |
|
298 | + $teachers = get_users( $teacher_query_args ); |
|
299 | + |
|
300 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
301 | + |
|
302 | + }// end get_teachers_and_authors |
|
303 | + |
|
304 | + /** |
|
305 | + * Sensei_Teacher::save_teacher_meta_box |
|
306 | + * |
|
307 | + * Save the new teacher / author to course and all lessons |
|
308 | + * |
|
309 | + * Hooked into admin_init |
|
310 | + * |
|
311 | + * @since 1.8.0 |
|
312 | + * @access public |
|
313 | + * @parameters |
|
314 | + * @return array $users user id array |
|
315 | + */ |
|
316 | + public function save_teacher_meta_box ( $course_id ){ |
|
317 | 317 | |
318 | - // check if this is a post from saving the teacher, if not exit early |
|
319 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
320 | - return; |
|
321 | - } |
|
318 | + // check if this is a post from saving the teacher, if not exit early |
|
319 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
320 | + return; |
|
321 | + } |
|
322 | 322 | |
323 | - //don't fire this hook again |
|
324 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
323 | + //don't fire this hook again |
|
324 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
325 | 325 | |
326 | - // get the current post object |
|
327 | - $post = get_post( $course_id ); |
|
326 | + // get the current post object |
|
327 | + $post = get_post( $course_id ); |
|
328 | 328 | |
329 | - // get the current teacher/author |
|
330 | - $current_author = absint( $post->post_author ); |
|
331 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
329 | + // get the current teacher/author |
|
330 | + $current_author = absint( $post->post_author ); |
|
331 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
332 | 332 | |
333 | - // loop through all post lessons to update their authors as well |
|
334 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
333 | + // loop through all post lessons to update their authors as well |
|
334 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
335 | 335 | |
336 | - // do not do any processing if the selected author is the same as the current author |
|
337 | - if( $current_author == $new_author ){ |
|
338 | - return; |
|
339 | - } |
|
336 | + // do not do any processing if the selected author is the same as the current author |
|
337 | + if( $current_author == $new_author ){ |
|
338 | + return; |
|
339 | + } |
|
340 | 340 | |
341 | - // save the course author |
|
342 | - $post_updates = array( |
|
343 | - 'ID' => $post->ID , |
|
344 | - 'post_author' => $new_author |
|
345 | - ); |
|
346 | - wp_update_post( $post_updates ); |
|
341 | + // save the course author |
|
342 | + $post_updates = array( |
|
343 | + 'ID' => $post->ID , |
|
344 | + 'post_author' => $new_author |
|
345 | + ); |
|
346 | + wp_update_post( $post_updates ); |
|
347 | 347 | |
348 | - // ensure the the modules are update so that then new teacher has access to them |
|
349 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
348 | + // ensure the the modules are update so that then new teacher has access to them |
|
349 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
350 | 350 | |
351 | - // notify the new teacher |
|
352 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
351 | + // notify the new teacher |
|
352 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
353 | 353 | |
354 | - } // end save_teacher_meta_box |
|
354 | + } // end save_teacher_meta_box |
|
355 | 355 | |
356 | - /** |
|
357 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
358 | - * the new author. Making sure the course terms are maintained. |
|
359 | - * |
|
360 | - * This function also checks if terms are shared, with other courses |
|
361 | - * |
|
362 | - * @param $course_id |
|
363 | - * @param $new_teacher_id |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
356 | + /** |
|
357 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
358 | + * the new author. Making sure the course terms are maintained. |
|
359 | + * |
|
360 | + * This function also checks if terms are shared, with other courses |
|
361 | + * |
|
362 | + * @param $course_id |
|
363 | + * @param $new_teacher_id |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
367 | 367 | |
368 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
369 | - return; |
|
370 | - } |
|
368 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
369 | + return; |
|
370 | + } |
|
371 | 371 | |
372 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
372 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
373 | 373 | |
374 | - if( empty( $terms_selected_on_course ) ){ |
|
375 | - return; |
|
376 | - } |
|
374 | + if( empty( $terms_selected_on_course ) ){ |
|
375 | + return; |
|
376 | + } |
|
377 | 377 | |
378 | - foreach( $terms_selected_on_course as $term ){ |
|
378 | + foreach( $terms_selected_on_course as $term ){ |
|
379 | 379 | |
380 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
381 | - if( $new_teacher_id != $term_author->ID ){ |
|
380 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
381 | + if( $new_teacher_id != $term_author->ID ){ |
|
382 | 382 | |
383 | - $new_term = ''; |
|
383 | + $new_term = ''; |
|
384 | 384 | |
385 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
386 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
385 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
386 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
387 | 387 | |
388 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
389 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
390 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
391 | - if( !empty( $existing_admin_terms ) ){ |
|
392 | - // insert it even if it exists |
|
393 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
394 | - } |
|
395 | - } |
|
388 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
389 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
390 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
391 | + if( !empty( $existing_admin_terms ) ){ |
|
392 | + // insert it even if it exists |
|
393 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
394 | + } |
|
395 | + } |
|
396 | 396 | |
397 | - if( empty ( $new_term ) ){ |
|
397 | + if( empty ( $new_term ) ){ |
|
398 | 398 | |
399 | - //setup the new slug |
|
400 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
401 | - |
|
402 | - // create new term and set it |
|
403 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
404 | - |
|
405 | - } |
|
399 | + //setup the new slug |
|
400 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
401 | + |
|
402 | + // create new term and set it |
|
403 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
404 | + |
|
405 | + } |
|
406 | 406 | |
407 | 407 | |
408 | 408 | |
409 | - // if term exists |
|
410 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
409 | + // if term exists |
|
410 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
411 | 411 | |
412 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
413 | - $term_id = $existing_term->term_id; |
|
412 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
413 | + $term_id = $existing_term->term_id; |
|
414 | 414 | |
415 | - }else{ |
|
415 | + }else{ |
|
416 | 416 | |
417 | - // for a new term simply get the term from the returned value |
|
418 | - $term_id = $new_term['term_id']; |
|
417 | + // for a new term simply get the term from the returned value |
|
418 | + $term_id = $new_term['term_id']; |
|
419 | 419 | |
420 | - } // end if term exist |
|
420 | + } // end if term exist |
|
421 | 421 | |
422 | - // set the terms selected on the course |
|
423 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
422 | + // set the terms selected on the course |
|
423 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
424 | 424 | |
425 | - // remove old term |
|
426 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
425 | + // remove old term |
|
426 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
427 | 427 | |
428 | - // update the lessons within the current module term |
|
429 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
430 | - foreach( $lessons as $lesson ){ |
|
428 | + // update the lessons within the current module term |
|
429 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
430 | + foreach( $lessons as $lesson ){ |
|
431 | 431 | |
432 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
432 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
433 | 433 | |
434 | - // add the new term, the false at the end says to replace all terms on this module |
|
435 | - // with the new term. |
|
436 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
437 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
438 | - } |
|
434 | + // add the new term, the false at the end says to replace all terms on this module |
|
435 | + // with the new term. |
|
436 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
437 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
438 | + } |
|
439 | 439 | |
440 | - }// end for each |
|
440 | + }// end for each |
|
441 | 441 | |
442 | - } |
|
443 | - } |
|
442 | + } |
|
443 | + } |
|
444 | 444 | |
445 | - }// end update_course_module_terms_author |
|
445 | + }// end update_course_module_terms_author |
|
446 | 446 | |
447 | - /** |
|
448 | - * Sensei_Teacher::update_course_lessons_author |
|
449 | - * |
|
450 | - * Update all course lessons and their quiz with a new author |
|
451 | - * |
|
452 | - * @since 1.8.0 |
|
453 | - * @access public |
|
454 | - * @parameters |
|
455 | - * @return array $users user id array |
|
456 | - */ |
|
457 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
447 | + /** |
|
448 | + * Sensei_Teacher::update_course_lessons_author |
|
449 | + * |
|
450 | + * Update all course lessons and their quiz with a new author |
|
451 | + * |
|
452 | + * @since 1.8.0 |
|
453 | + * @access public |
|
454 | + * @parameters |
|
455 | + * @return array $users user id array |
|
456 | + */ |
|
457 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
458 | 458 | |
459 | 459 | |
460 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
461 | - return false; |
|
462 | - } |
|
460 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
461 | + return false; |
|
462 | + } |
|
463 | 463 | |
464 | - //get a list of course lessons |
|
465 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
464 | + //get a list of course lessons |
|
465 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
466 | 466 | |
467 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
468 | - return false; |
|
469 | - } |
|
467 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
468 | + return false; |
|
469 | + } |
|
470 | 470 | |
471 | - // update each lesson and quiz author |
|
472 | - foreach( $lessons as $lesson ){ |
|
471 | + // update each lesson and quiz author |
|
472 | + foreach( $lessons as $lesson ){ |
|
473 | 473 | |
474 | - // don't update if the author is tha same as the new author |
|
475 | - if( $new_author == $lesson->post_author ){ |
|
476 | - continue; |
|
477 | - } |
|
474 | + // don't update if the author is tha same as the new author |
|
475 | + if( $new_author == $lesson->post_author ){ |
|
476 | + continue; |
|
477 | + } |
|
478 | 478 | |
479 | - // update lesson author |
|
480 | - wp_update_post( array( |
|
481 | - 'ID'=> $lesson->ID, |
|
482 | - 'post_author' => $new_author |
|
483 | - ) ); |
|
479 | + // update lesson author |
|
480 | + wp_update_post( array( |
|
481 | + 'ID'=> $lesson->ID, |
|
482 | + 'post_author' => $new_author |
|
483 | + ) ); |
|
484 | 484 | |
485 | - // update quiz author |
|
486 | - //get the lessons quiz |
|
487 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
488 | - if( is_array( $lesson_quizzes ) ){ |
|
489 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
490 | - // update quiz with new author |
|
491 | - wp_update_post( array( |
|
492 | - 'ID' => $quiz_id, |
|
493 | - 'post_author' => $new_author |
|
494 | - ) ); |
|
495 | - } |
|
496 | - }else{ |
|
497 | - wp_update_post( array( |
|
498 | - 'ID' => $lesson_quizzes, |
|
499 | - 'post_author' => $new_author |
|
500 | - ) ); |
|
501 | - } |
|
485 | + // update quiz author |
|
486 | + //get the lessons quiz |
|
487 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
488 | + if( is_array( $lesson_quizzes ) ){ |
|
489 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
490 | + // update quiz with new author |
|
491 | + wp_update_post( array( |
|
492 | + 'ID' => $quiz_id, |
|
493 | + 'post_author' => $new_author |
|
494 | + ) ); |
|
495 | + } |
|
496 | + }else{ |
|
497 | + wp_update_post( array( |
|
498 | + 'ID' => $lesson_quizzes, |
|
499 | + 'post_author' => $new_author |
|
500 | + ) ); |
|
501 | + } |
|
502 | 502 | |
503 | - } // end for each lessons |
|
503 | + } // end for each lessons |
|
504 | 504 | |
505 | - return true; |
|
505 | + return true; |
|
506 | 506 | |
507 | - }// end update_course_lessons_author |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
513 | - * |
|
514 | - * Alter the query so that users can only see their courses on the analysis page |
|
515 | - * |
|
516 | - * @since 1.8.0 |
|
517 | - * @access public |
|
518 | - * @parameters $query |
|
519 | - * @return array $users user id array |
|
520 | - */ |
|
521 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
522 | - |
|
523 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
524 | - return $query; |
|
525 | - } |
|
526 | - |
|
527 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
528 | - return $query; |
|
529 | - } |
|
530 | - |
|
531 | - $screen = get_current_screen(); |
|
532 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
533 | - |
|
534 | - // exit early for the following conditions |
|
535 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
536 | - |
|
537 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
538 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
539 | - return $query; |
|
540 | - } |
|
541 | - |
|
542 | - global $current_user; |
|
543 | - // set the query author to the current user to only show those those posts |
|
544 | - $query->set( 'author', $current_user->ID ); |
|
545 | - return $query; |
|
546 | - |
|
547 | - }// end course_analysis_teacher_access_limit |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
552 | - * |
|
553 | - * Determine if we're in admin and the current logged in use is a teacher |
|
554 | - * |
|
555 | - * @since 1.8.0 |
|
556 | - * @access public |
|
557 | - * @parameters array $wp_query |
|
558 | - * @return bool $is_admin_teacher |
|
559 | - */ |
|
560 | - public function is_admin_teacher ( ){ |
|
561 | - |
|
562 | - if( ! is_user_logged_in()){ |
|
563 | - return false; |
|
564 | - } |
|
565 | - $is_admin_teacher = false; |
|
566 | - |
|
567 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
568 | - |
|
569 | - $is_admin_teacher = true; |
|
570 | - |
|
571 | - } |
|
572 | - |
|
573 | - return $is_admin_teacher; |
|
574 | - |
|
575 | - } // end is_admin_teacher |
|
576 | - |
|
577 | - /** |
|
578 | - * Show correct post counts on list table for Sensei post types |
|
579 | - * |
|
580 | - * @since 1.8.0 |
|
581 | - * |
|
582 | - * @param object $counts Default status counts |
|
583 | - * @param string $type Current post type |
|
584 | - * @param string $perm User permission level |
|
585 | - * @return object Modified status counts |
|
586 | - */ |
|
587 | - public function list_table_counts( $counts, $type, $perm ) { |
|
588 | - global $current_user; |
|
589 | - |
|
590 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
591 | - return $counts; |
|
592 | - } |
|
593 | - |
|
594 | - if( ! $this->is_admin_teacher() ) { |
|
595 | - return $counts; |
|
596 | - } |
|
597 | - |
|
598 | - $args = array( |
|
599 | - 'post_type' => $type, |
|
600 | - 'author' => $current_user->ID, |
|
601 | - 'posts_per_page' => -1 |
|
602 | - ); |
|
603 | - |
|
604 | - // Get all available statuses |
|
605 | - $stati = get_post_stati(); |
|
606 | - |
|
607 | - // Update count object |
|
608 | - foreach( $stati as $status ) { |
|
609 | - $args['post_status'] = $status; |
|
610 | - $posts = get_posts( $args ); |
|
611 | - $counts->$status = count( $posts ); |
|
612 | - } |
|
613 | - |
|
614 | - return $counts; |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Filter the post queries to show |
|
619 | - * only lesson /course and users that belong |
|
620 | - * to the current logged teacher. |
|
621 | - * |
|
622 | - * @since 1.8.0 |
|
623 | - * |
|
624 | - */ |
|
625 | - public function filter_queries ( $query ) { |
|
626 | - global $current_user; |
|
627 | - |
|
628 | - if( ! $this->is_admin_teacher() ) { |
|
629 | - return; |
|
630 | - } |
|
631 | - |
|
632 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
633 | - return; |
|
634 | - } |
|
635 | - |
|
636 | - $screen = get_current_screen(); |
|
637 | - if( empty( $screen ) ) { |
|
638 | - return $query; |
|
639 | - } |
|
640 | - switch( $screen->id ) { |
|
641 | - case 'sensei_page_sensei_grading': |
|
642 | - case 'sensei_page_sensei_analysis': |
|
643 | - case 'sensei_page_sensei_learners': |
|
644 | - case 'lesson': |
|
645 | - case 'course': |
|
646 | - case 'question': |
|
647 | - case 'lesson_page_module-order': |
|
648 | - |
|
649 | - /** |
|
650 | - * sensei_filter_queries_set_author |
|
651 | - * Filter the author Sensei set for queries |
|
652 | - * |
|
653 | - * @since 1.8.0 |
|
654 | - * |
|
655 | - * @param int $user_id |
|
656 | - * @param string $screen_id |
|
657 | - * |
|
658 | - */ |
|
659 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
660 | - break; |
|
661 | - } |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
666 | - * . This excludes the admin user. |
|
667 | - * |
|
668 | - * @since 1.8.0 |
|
669 | - * @hooked into the_comments |
|
670 | - * @param array $comments |
|
671 | - * |
|
672 | - * @return array $comments |
|
673 | - */ |
|
674 | - public function filter_grading_activity_queries( $comments ){ |
|
675 | - |
|
676 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
677 | - return $comments ; |
|
678 | - } |
|
679 | - |
|
680 | - //check if we're on the grading screen |
|
681 | - $screen = get_current_screen(); |
|
682 | - |
|
683 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
684 | - return $comments; |
|
685 | - } |
|
686 | - |
|
687 | - // get the course and determine if the current teacher is the owner |
|
688 | - // if not remove it from the list of comments to be returned |
|
689 | - foreach( $comments as $key => $comment){ |
|
690 | - $lesson = get_post( $comment->comment_post_ID ); |
|
691 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
692 | - $course = get_post( $course_id ); |
|
693 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
694 | - //remove this as the teacher should see this. |
|
695 | - unset( $comments[ $key ] ); |
|
696 | - } |
|
697 | - } |
|
698 | - return $comments ; |
|
699 | - |
|
700 | - }// end function filter grading |
|
701 | - |
|
702 | - /** |
|
703 | - * Limit the grading screen totals to only show lessons in the course |
|
704 | - * belonging to the currently logged in teacher. This only applies to |
|
705 | - * the teacher role. |
|
706 | - * |
|
707 | - * @since 1.8.0 |
|
708 | - * |
|
709 | - * @hooked into sensei_count_statuses_args |
|
710 | - * @param array $args |
|
711 | - * |
|
712 | - * @return array $args |
|
713 | - */ |
|
714 | - public function limit_grading_totals( $args ){ |
|
715 | - |
|
716 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
717 | - return $args ; |
|
718 | - } |
|
719 | - |
|
720 | - //get the teachers courses |
|
721 | - // the query is already filtered to only the teacher |
|
722 | - $courses = Sensei()->course->get_all_courses(); |
|
723 | - |
|
724 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
725 | - return $args; |
|
726 | - } |
|
727 | - |
|
728 | - //setup the lessons quizzes to limit the grading totals to |
|
729 | - $quiz_scope = array(); |
|
730 | - foreach( $courses as $course ){ |
|
731 | - |
|
732 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
733 | - |
|
734 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
735 | - |
|
736 | - foreach( $course_lessons as $lesson ){ |
|
737 | - |
|
738 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
739 | - if( !empty( $quiz_id ) ) { |
|
740 | - |
|
741 | - array_push( $quiz_scope, $quiz_id ); |
|
742 | - |
|
743 | - } |
|
744 | - |
|
745 | - } |
|
746 | - |
|
747 | - } |
|
748 | - |
|
749 | - } |
|
750 | - |
|
751 | - $args['post__in'] = $quiz_scope; |
|
752 | - |
|
753 | - return $args; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * It ensures that the author archive shows course by the current user. |
|
758 | - * |
|
759 | - * This function is hooked into the pre_get_posts filter |
|
760 | - * |
|
761 | - * @param WP_Query $query |
|
762 | - * @return WP_Query $query |
|
763 | - */ |
|
764 | - public function add_courses_to_author_archive( $query ) { |
|
765 | - |
|
766 | - if ( is_admin() || ! $query->is_author() ){ |
|
767 | - return $query; |
|
768 | - } |
|
769 | - |
|
770 | - // this should only apply to users with the teacher role |
|
771 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
772 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
773 | - |
|
774 | - return $query; |
|
775 | - |
|
776 | - } |
|
777 | - |
|
778 | - // Change post types depending on what is set already |
|
779 | - $current_post_types = $query->get( 'post_type' ); |
|
780 | - if( empty( $current_post_types ) ){ |
|
781 | - |
|
782 | - // if empty it means post by default, so add post so that it also includes that for now |
|
783 | - $new_post_types = array( 'post', 'course' ); |
|
784 | - |
|
785 | - } elseif( is_array( $current_post_types ) ) { |
|
786 | - |
|
787 | - // merge the post types instead of overwriting it |
|
788 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
789 | - |
|
790 | - }else{ |
|
791 | - |
|
792 | - // in this instance it is probably just one post type in string format |
|
793 | - $new_post_types = array( $current_post_types , 'course'); |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - // change the query before returning it |
|
798 | - $query->set('post_type', $new_post_types ); |
|
799 | - |
|
800 | - /** |
|
801 | - * Change the query on the teacher author archive template |
|
802 | - * |
|
803 | - * @since 1.8.4 |
|
804 | - * @param WP_Query $query |
|
805 | - */ |
|
806 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
807 | - |
|
808 | - } |
|
809 | - |
|
810 | - /** |
|
811 | - * Notify teacher when someone assigns a course to their account. |
|
812 | - * |
|
813 | - * @since 1.8.0 |
|
814 | - * |
|
815 | - * @param $teacher_id |
|
816 | - * @param $course_id |
|
817 | - * @return bool |
|
818 | - */ |
|
819 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
820 | - |
|
821 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - // if new user is the same as the current logged user, they don't need an email |
|
826 | - if( $teacher_id == get_current_user_id() ){ |
|
827 | - return true; |
|
828 | - } |
|
829 | - |
|
830 | - // load the email class |
|
831 | - include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
|
832 | - $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
|
833 | - $email->trigger( $teacher_id, $course_id ); |
|
834 | - |
|
835 | - return true; |
|
836 | - } // end teacher_course_assigned_notification |
|
837 | - |
|
838 | - /** |
|
839 | - * Email the admin when a teacher creates a new course |
|
840 | - * |
|
841 | - * This function hooks into wp_insert_post |
|
842 | - * |
|
843 | - * @since 1.8.0 |
|
844 | - * @param int $course_id |
|
845 | - * @return bool |
|
846 | - */ |
|
847 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
848 | - |
|
849 | - $course_id = $post->ID; |
|
850 | - |
|
851 | - if( 'publish'== $old_status || 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
852 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
853 | - |
|
854 | - return false; |
|
855 | - |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Filter the option to send admin notification emails when teachers creation |
|
860 | - * course. |
|
861 | - * |
|
862 | - * @since 1.8.0 |
|
863 | - * |
|
864 | - * @param bool $on default true |
|
865 | - */ |
|
866 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
867 | - return false; |
|
868 | - } |
|
869 | - |
|
870 | - // setting up the data needed by the email template |
|
871 | - global $sensei_email_data; |
|
872 | - $template = 'admin-teacher-new-course-created'; |
|
873 | - $course = get_post( $course_id ); |
|
874 | - $teacher = new WP_User( $course->post_author ); |
|
875 | - $recipient = get_option('admin_email', true); |
|
876 | - |
|
877 | - // don't send if the course is created by admin |
|
878 | - if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
879 | - return false; |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
884 | - * |
|
885 | - * @since 1.8.0 |
|
886 | - * @param string $template |
|
887 | - */ |
|
888 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
889 | - |
|
890 | - /** |
|
891 | - * Filter the email subject for the the |
|
892 | - * admin-teacher-new-course-created template |
|
893 | - * |
|
894 | - * @since 1.8.0 |
|
895 | - * @param string $subject default New course assigned to you |
|
896 | - * @param string $template |
|
897 | - */ |
|
898 | - $subject = apply_filters('sensei_email_subject', |
|
899 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
900 | - $template ); |
|
901 | - |
|
902 | - //course edit link |
|
903 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
904 | - |
|
905 | - // Construct data array |
|
906 | - $email_data = array( |
|
907 | - 'template' => $template, |
|
908 | - 'heading' => $heading, |
|
909 | - 'teacher' => $teacher, |
|
910 | - 'course_id' => $course_id, |
|
911 | - 'course_name' => $course->post_title, |
|
912 | - 'course_edit_link' => $course_edit_link, |
|
913 | - ); |
|
914 | - |
|
915 | - /** |
|
916 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
917 | - * |
|
918 | - * @since 1.8.0 |
|
919 | - * @param array $email_data |
|
920 | - * @param string $template |
|
921 | - */ |
|
922 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
923 | - |
|
924 | - // Send mail |
|
925 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
926 | - |
|
927 | - }// end notify admin of course creation |
|
928 | - |
|
929 | - /** |
|
930 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
931 | - * |
|
932 | - * Hooked into sensei_analysis_get_learners |
|
933 | - * @param array $args WP_User_Query arguments |
|
934 | - * @return array $learners_query_results |
|
935 | - */ |
|
936 | - public function limit_analysis_learners( $args ){ |
|
937 | - |
|
938 | - // show default for none teachers |
|
939 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
940 | - return $args; |
|
941 | - } |
|
942 | - |
|
943 | - // for teachers all courses only return those which belong to the teacher |
|
944 | - // as they don't have access to course belonging to other users |
|
945 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
507 | + }// end update_course_lessons_author |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
513 | + * |
|
514 | + * Alter the query so that users can only see their courses on the analysis page |
|
515 | + * |
|
516 | + * @since 1.8.0 |
|
517 | + * @access public |
|
518 | + * @parameters $query |
|
519 | + * @return array $users user id array |
|
520 | + */ |
|
521 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
522 | + |
|
523 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
524 | + return $query; |
|
525 | + } |
|
526 | + |
|
527 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
528 | + return $query; |
|
529 | + } |
|
530 | + |
|
531 | + $screen = get_current_screen(); |
|
532 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
533 | + |
|
534 | + // exit early for the following conditions |
|
535 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
536 | + |
|
537 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
538 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
539 | + return $query; |
|
540 | + } |
|
541 | + |
|
542 | + global $current_user; |
|
543 | + // set the query author to the current user to only show those those posts |
|
544 | + $query->set( 'author', $current_user->ID ); |
|
545 | + return $query; |
|
546 | + |
|
547 | + }// end course_analysis_teacher_access_limit |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
552 | + * |
|
553 | + * Determine if we're in admin and the current logged in use is a teacher |
|
554 | + * |
|
555 | + * @since 1.8.0 |
|
556 | + * @access public |
|
557 | + * @parameters array $wp_query |
|
558 | + * @return bool $is_admin_teacher |
|
559 | + */ |
|
560 | + public function is_admin_teacher ( ){ |
|
561 | + |
|
562 | + if( ! is_user_logged_in()){ |
|
563 | + return false; |
|
564 | + } |
|
565 | + $is_admin_teacher = false; |
|
566 | + |
|
567 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
568 | + |
|
569 | + $is_admin_teacher = true; |
|
570 | + |
|
571 | + } |
|
572 | + |
|
573 | + return $is_admin_teacher; |
|
574 | + |
|
575 | + } // end is_admin_teacher |
|
576 | + |
|
577 | + /** |
|
578 | + * Show correct post counts on list table for Sensei post types |
|
579 | + * |
|
580 | + * @since 1.8.0 |
|
581 | + * |
|
582 | + * @param object $counts Default status counts |
|
583 | + * @param string $type Current post type |
|
584 | + * @param string $perm User permission level |
|
585 | + * @return object Modified status counts |
|
586 | + */ |
|
587 | + public function list_table_counts( $counts, $type, $perm ) { |
|
588 | + global $current_user; |
|
589 | + |
|
590 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
591 | + return $counts; |
|
592 | + } |
|
593 | + |
|
594 | + if( ! $this->is_admin_teacher() ) { |
|
595 | + return $counts; |
|
596 | + } |
|
597 | + |
|
598 | + $args = array( |
|
599 | + 'post_type' => $type, |
|
600 | + 'author' => $current_user->ID, |
|
601 | + 'posts_per_page' => -1 |
|
602 | + ); |
|
603 | + |
|
604 | + // Get all available statuses |
|
605 | + $stati = get_post_stati(); |
|
606 | + |
|
607 | + // Update count object |
|
608 | + foreach( $stati as $status ) { |
|
609 | + $args['post_status'] = $status; |
|
610 | + $posts = get_posts( $args ); |
|
611 | + $counts->$status = count( $posts ); |
|
612 | + } |
|
613 | + |
|
614 | + return $counts; |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Filter the post queries to show |
|
619 | + * only lesson /course and users that belong |
|
620 | + * to the current logged teacher. |
|
621 | + * |
|
622 | + * @since 1.8.0 |
|
623 | + * |
|
624 | + */ |
|
625 | + public function filter_queries ( $query ) { |
|
626 | + global $current_user; |
|
627 | + |
|
628 | + if( ! $this->is_admin_teacher() ) { |
|
629 | + return; |
|
630 | + } |
|
631 | + |
|
632 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
633 | + return; |
|
634 | + } |
|
635 | + |
|
636 | + $screen = get_current_screen(); |
|
637 | + if( empty( $screen ) ) { |
|
638 | + return $query; |
|
639 | + } |
|
640 | + switch( $screen->id ) { |
|
641 | + case 'sensei_page_sensei_grading': |
|
642 | + case 'sensei_page_sensei_analysis': |
|
643 | + case 'sensei_page_sensei_learners': |
|
644 | + case 'lesson': |
|
645 | + case 'course': |
|
646 | + case 'question': |
|
647 | + case 'lesson_page_module-order': |
|
648 | + |
|
649 | + /** |
|
650 | + * sensei_filter_queries_set_author |
|
651 | + * Filter the author Sensei set for queries |
|
652 | + * |
|
653 | + * @since 1.8.0 |
|
654 | + * |
|
655 | + * @param int $user_id |
|
656 | + * @param string $screen_id |
|
657 | + * |
|
658 | + */ |
|
659 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
660 | + break; |
|
661 | + } |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
666 | + * . This excludes the admin user. |
|
667 | + * |
|
668 | + * @since 1.8.0 |
|
669 | + * @hooked into the_comments |
|
670 | + * @param array $comments |
|
671 | + * |
|
672 | + * @return array $comments |
|
673 | + */ |
|
674 | + public function filter_grading_activity_queries( $comments ){ |
|
675 | + |
|
676 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
677 | + return $comments ; |
|
678 | + } |
|
679 | + |
|
680 | + //check if we're on the grading screen |
|
681 | + $screen = get_current_screen(); |
|
682 | + |
|
683 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
684 | + return $comments; |
|
685 | + } |
|
686 | + |
|
687 | + // get the course and determine if the current teacher is the owner |
|
688 | + // if not remove it from the list of comments to be returned |
|
689 | + foreach( $comments as $key => $comment){ |
|
690 | + $lesson = get_post( $comment->comment_post_ID ); |
|
691 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
692 | + $course = get_post( $course_id ); |
|
693 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
694 | + //remove this as the teacher should see this. |
|
695 | + unset( $comments[ $key ] ); |
|
696 | + } |
|
697 | + } |
|
698 | + return $comments ; |
|
699 | + |
|
700 | + }// end function filter grading |
|
701 | + |
|
702 | + /** |
|
703 | + * Limit the grading screen totals to only show lessons in the course |
|
704 | + * belonging to the currently logged in teacher. This only applies to |
|
705 | + * the teacher role. |
|
706 | + * |
|
707 | + * @since 1.8.0 |
|
708 | + * |
|
709 | + * @hooked into sensei_count_statuses_args |
|
710 | + * @param array $args |
|
711 | + * |
|
712 | + * @return array $args |
|
713 | + */ |
|
714 | + public function limit_grading_totals( $args ){ |
|
715 | + |
|
716 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
717 | + return $args ; |
|
718 | + } |
|
719 | + |
|
720 | + //get the teachers courses |
|
721 | + // the query is already filtered to only the teacher |
|
722 | + $courses = Sensei()->course->get_all_courses(); |
|
723 | + |
|
724 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
725 | + return $args; |
|
726 | + } |
|
727 | + |
|
728 | + //setup the lessons quizzes to limit the grading totals to |
|
729 | + $quiz_scope = array(); |
|
730 | + foreach( $courses as $course ){ |
|
731 | + |
|
732 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
733 | + |
|
734 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
735 | + |
|
736 | + foreach( $course_lessons as $lesson ){ |
|
737 | + |
|
738 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
739 | + if( !empty( $quiz_id ) ) { |
|
740 | + |
|
741 | + array_push( $quiz_scope, $quiz_id ); |
|
742 | + |
|
743 | + } |
|
744 | + |
|
745 | + } |
|
746 | + |
|
747 | + } |
|
748 | + |
|
749 | + } |
|
750 | + |
|
751 | + $args['post__in'] = $quiz_scope; |
|
752 | + |
|
753 | + return $args; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * It ensures that the author archive shows course by the current user. |
|
758 | + * |
|
759 | + * This function is hooked into the pre_get_posts filter |
|
760 | + * |
|
761 | + * @param WP_Query $query |
|
762 | + * @return WP_Query $query |
|
763 | + */ |
|
764 | + public function add_courses_to_author_archive( $query ) { |
|
765 | + |
|
766 | + if ( is_admin() || ! $query->is_author() ){ |
|
767 | + return $query; |
|
768 | + } |
|
769 | + |
|
770 | + // this should only apply to users with the teacher role |
|
771 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
772 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
773 | + |
|
774 | + return $query; |
|
775 | + |
|
776 | + } |
|
777 | + |
|
778 | + // Change post types depending on what is set already |
|
779 | + $current_post_types = $query->get( 'post_type' ); |
|
780 | + if( empty( $current_post_types ) ){ |
|
781 | + |
|
782 | + // if empty it means post by default, so add post so that it also includes that for now |
|
783 | + $new_post_types = array( 'post', 'course' ); |
|
784 | + |
|
785 | + } elseif( is_array( $current_post_types ) ) { |
|
786 | + |
|
787 | + // merge the post types instead of overwriting it |
|
788 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
789 | + |
|
790 | + }else{ |
|
791 | + |
|
792 | + // in this instance it is probably just one post type in string format |
|
793 | + $new_post_types = array( $current_post_types , 'course'); |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + // change the query before returning it |
|
798 | + $query->set('post_type', $new_post_types ); |
|
799 | + |
|
800 | + /** |
|
801 | + * Change the query on the teacher author archive template |
|
802 | + * |
|
803 | + * @since 1.8.4 |
|
804 | + * @param WP_Query $query |
|
805 | + */ |
|
806 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
807 | + |
|
808 | + } |
|
809 | + |
|
810 | + /** |
|
811 | + * Notify teacher when someone assigns a course to their account. |
|
812 | + * |
|
813 | + * @since 1.8.0 |
|
814 | + * |
|
815 | + * @param $teacher_id |
|
816 | + * @param $course_id |
|
817 | + * @return bool |
|
818 | + */ |
|
819 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
820 | + |
|
821 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + // if new user is the same as the current logged user, they don't need an email |
|
826 | + if( $teacher_id == get_current_user_id() ){ |
|
827 | + return true; |
|
828 | + } |
|
829 | + |
|
830 | + // load the email class |
|
831 | + include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
|
832 | + $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
|
833 | + $email->trigger( $teacher_id, $course_id ); |
|
834 | + |
|
835 | + return true; |
|
836 | + } // end teacher_course_assigned_notification |
|
837 | + |
|
838 | + /** |
|
839 | + * Email the admin when a teacher creates a new course |
|
840 | + * |
|
841 | + * This function hooks into wp_insert_post |
|
842 | + * |
|
843 | + * @since 1.8.0 |
|
844 | + * @param int $course_id |
|
845 | + * @return bool |
|
846 | + */ |
|
847 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
848 | + |
|
849 | + $course_id = $post->ID; |
|
850 | + |
|
851 | + if( 'publish'== $old_status || 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
852 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
853 | + |
|
854 | + return false; |
|
855 | + |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Filter the option to send admin notification emails when teachers creation |
|
860 | + * course. |
|
861 | + * |
|
862 | + * @since 1.8.0 |
|
863 | + * |
|
864 | + * @param bool $on default true |
|
865 | + */ |
|
866 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
867 | + return false; |
|
868 | + } |
|
869 | + |
|
870 | + // setting up the data needed by the email template |
|
871 | + global $sensei_email_data; |
|
872 | + $template = 'admin-teacher-new-course-created'; |
|
873 | + $course = get_post( $course_id ); |
|
874 | + $teacher = new WP_User( $course->post_author ); |
|
875 | + $recipient = get_option('admin_email', true); |
|
876 | + |
|
877 | + // don't send if the course is created by admin |
|
878 | + if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
879 | + return false; |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
884 | + * |
|
885 | + * @since 1.8.0 |
|
886 | + * @param string $template |
|
887 | + */ |
|
888 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
889 | + |
|
890 | + /** |
|
891 | + * Filter the email subject for the the |
|
892 | + * admin-teacher-new-course-created template |
|
893 | + * |
|
894 | + * @since 1.8.0 |
|
895 | + * @param string $subject default New course assigned to you |
|
896 | + * @param string $template |
|
897 | + */ |
|
898 | + $subject = apply_filters('sensei_email_subject', |
|
899 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
900 | + $template ); |
|
901 | + |
|
902 | + //course edit link |
|
903 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
904 | + |
|
905 | + // Construct data array |
|
906 | + $email_data = array( |
|
907 | + 'template' => $template, |
|
908 | + 'heading' => $heading, |
|
909 | + 'teacher' => $teacher, |
|
910 | + 'course_id' => $course_id, |
|
911 | + 'course_name' => $course->post_title, |
|
912 | + 'course_edit_link' => $course_edit_link, |
|
913 | + ); |
|
914 | + |
|
915 | + /** |
|
916 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
917 | + * |
|
918 | + * @since 1.8.0 |
|
919 | + * @param array $email_data |
|
920 | + * @param string $template |
|
921 | + */ |
|
922 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
923 | + |
|
924 | + // Send mail |
|
925 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
926 | + |
|
927 | + }// end notify admin of course creation |
|
928 | + |
|
929 | + /** |
|
930 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
931 | + * |
|
932 | + * Hooked into sensei_analysis_get_learners |
|
933 | + * @param array $args WP_User_Query arguments |
|
934 | + * @return array $learners_query_results |
|
935 | + */ |
|
936 | + public function limit_analysis_learners( $args ){ |
|
937 | + |
|
938 | + // show default for none teachers |
|
939 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
940 | + return $args; |
|
941 | + } |
|
942 | + |
|
943 | + // for teachers all courses only return those which belong to the teacher |
|
944 | + // as they don't have access to course belonging to other users |
|
945 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
946 | 946 | |
947 | - // if the user has no courses they should see no users |
|
948 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
949 | - // tell the query to return 0 students |
|
950 | - $args[ 'include'] = array( 0 ); |
|
951 | - return $args; |
|
952 | - |
|
953 | - } |
|
954 | - |
|
955 | - $learner_ids_for_teacher_courses = array(); |
|
956 | - foreach( $teacher_courses as $course ){ |
|
957 | - |
|
958 | - $course_learner_ids = array(); |
|
959 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
960 | - |
|
961 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
962 | - continue; // skip to the next course as there are no users on this course |
|
963 | - } |
|
964 | - |
|
965 | - // it could be an array of comments or a single comment |
|
966 | - if( is_array( $activity_comments ) ){ |
|
947 | + // if the user has no courses they should see no users |
|
948 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
949 | + // tell the query to return 0 students |
|
950 | + $args[ 'include'] = array( 0 ); |
|
951 | + return $args; |
|
952 | + |
|
953 | + } |
|
954 | + |
|
955 | + $learner_ids_for_teacher_courses = array(); |
|
956 | + foreach( $teacher_courses as $course ){ |
|
957 | + |
|
958 | + $course_learner_ids = array(); |
|
959 | + $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
960 | + |
|
961 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
962 | + continue; // skip to the next course as there are no users on this course |
|
963 | + } |
|
964 | + |
|
965 | + // it could be an array of comments or a single comment |
|
966 | + if( is_array( $activity_comments ) ){ |
|
967 | 967 | |
968 | - foreach( $activity_comments as $comment ){ |
|
968 | + foreach( $activity_comments as $comment ){ |
|
969 | 969 | |
970 | - $user = get_userdata( $comment->user_id ); |
|
970 | + $user = get_userdata( $comment->user_id ); |
|
971 | 971 | |
972 | - if( empty( $user ) ){ |
|
973 | - // next comment in this array |
|
974 | - continue; |
|
975 | - } |
|
972 | + if( empty( $user ) ){ |
|
973 | + // next comment in this array |
|
974 | + continue; |
|
975 | + } |
|
976 | 976 | |
977 | - $course_learner_ids[] = $user->ID; |
|
978 | - } |
|
977 | + $course_learner_ids[] = $user->ID; |
|
978 | + } |
|
979 | 979 | |
980 | - }else{ |
|
980 | + }else{ |
|
981 | 981 | |
982 | - $user = get_userdata( $activity_comments->user_id ); |
|
983 | - $course_learner_ids[] = $user->ID; |
|
982 | + $user = get_userdata( $activity_comments->user_id ); |
|
983 | + $course_learner_ids[] = $user->ID; |
|
984 | 984 | |
985 | - } |
|
985 | + } |
|
986 | 986 | |
987 | - // add learners on this course to the all courses learner list |
|
988 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
987 | + // add learners on this course to the all courses learner list |
|
988 | + $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
989 | 989 | |
990 | - } |
|
990 | + } |
|
991 | 991 | |
992 | - // if there are no students taking the courses by this teacher don't show them any of the other users |
|
993 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
992 | + // if there are no students taking the courses by this teacher don't show them any of the other users |
|
993 | + if( empty( $learner_ids_for_teacher_courses ) ){ |
|
994 | 994 | |
995 | - $args[ 'include'] = array( 0 ); |
|
995 | + $args[ 'include'] = array( 0 ); |
|
996 | 996 | |
997 | - }else{ |
|
997 | + }else{ |
|
998 | 998 | |
999 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
999 | + $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
1000 | 1000 | |
1001 | - } |
|
1001 | + } |
|
1002 | 1002 | |
1003 | - // return the WP_Use_Query arguments |
|
1004 | - return $args; |
|
1003 | + // return the WP_Use_Query arguments |
|
1004 | + return $args; |
|
1005 | 1005 | |
1006 | - }// end limit_analysis_learners |
|
1006 | + }// end limit_analysis_learners |
|
1007 | 1007 | |
1008 | - /** |
|
1009 | - * Give teacher full admin access to the question post type |
|
1010 | - * in certain cases. |
|
1011 | - * |
|
1012 | - * @since 1.8.0 |
|
1013 | - * @param $questions |
|
1014 | - * @return mixed |
|
1015 | - */ |
|
1016 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
1008 | + /** |
|
1009 | + * Give teacher full admin access to the question post type |
|
1010 | + * in certain cases. |
|
1011 | + * |
|
1012 | + * @since 1.8.0 |
|
1013 | + * @param $questions |
|
1014 | + * @return mixed |
|
1015 | + */ |
|
1016 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
1017 | 1017 | |
1018 | - if( ! $this->is_admin_teacher() ){ |
|
1019 | - return $questions; |
|
1020 | - } |
|
1018 | + if( ! $this->is_admin_teacher() ){ |
|
1019 | + return $questions; |
|
1020 | + } |
|
1021 | 1021 | |
1022 | - $screen = get_current_screen(); |
|
1022 | + $screen = get_current_screen(); |
|
1023 | 1023 | |
1024 | - // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
1025 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
1024 | + // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
1025 | + remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
1026 | 1026 | |
1027 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
1027 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
1028 | 1028 | |
1029 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
1030 | - if( ! empty($admin_user) ){ |
|
1029 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
1030 | + if( ! empty($admin_user) ){ |
|
1031 | 1031 | |
1032 | - $current_teacher_id = get_current_user_id(); |
|
1032 | + $current_teacher_id = get_current_user_id(); |
|
1033 | 1033 | |
1034 | - // set current user to admin so teacher can view all questions |
|
1035 | - wp_set_current_user( $admin_user->ID ); |
|
1036 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
1034 | + // set current user to admin so teacher can view all questions |
|
1035 | + wp_set_current_user( $admin_user->ID ); |
|
1036 | + $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
1037 | 1037 | |
1038 | - // set the teacher as the current use again |
|
1039 | - wp_set_current_user( $current_teacher_id ); |
|
1040 | - } |
|
1038 | + // set the teacher as the current use again |
|
1039 | + wp_set_current_user( $current_teacher_id ); |
|
1040 | + } |
|
1041 | 1041 | |
1042 | - } |
|
1043 | - // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
1044 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
1042 | + } |
|
1043 | + // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
1044 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
1045 | 1045 | |
1046 | - return $questions; |
|
1047 | - } |
|
1046 | + return $questions; |
|
1047 | + } |
|
1048 | 1048 | |
1049 | - /** |
|
1050 | - * Give the teacher role access to questions from the question bank |
|
1051 | - * |
|
1052 | - * @since 1.8.0 |
|
1053 | - * @param $wp_query |
|
1054 | - * @return mixed |
|
1055 | - */ |
|
1056 | - public function give_access_to_all_questions( $wp_query ){ |
|
1049 | + /** |
|
1050 | + * Give the teacher role access to questions from the question bank |
|
1051 | + * |
|
1052 | + * @since 1.8.0 |
|
1053 | + * @param $wp_query |
|
1054 | + * @return mixed |
|
1055 | + */ |
|
1056 | + public function give_access_to_all_questions( $wp_query ){ |
|
1057 | 1057 | |
1058 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
1058 | + if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
1059 | 1059 | |
1060 | - return $wp_query; |
|
1061 | - } |
|
1060 | + return $wp_query; |
|
1061 | + } |
|
1062 | 1062 | |
1063 | - $screen = get_current_screen(); |
|
1064 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
1065 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
1063 | + $screen = get_current_screen(); |
|
1064 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
1065 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
1066 | 1066 | |
1067 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
1068 | - if( ! empty($admin_user) ){ |
|
1067 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
1068 | + if( ! empty($admin_user) ){ |
|
1069 | 1069 | |
1070 | - $current_teacher_id = get_current_user_id(); |
|
1070 | + $current_teacher_id = get_current_user_id(); |
|
1071 | 1071 | |
1072 | - // set current user to admin so teacher can view all questions |
|
1073 | - wp_set_current_user( $admin_user->ID ); |
|
1072 | + // set current user to admin so teacher can view all questions |
|
1073 | + wp_set_current_user( $admin_user->ID ); |
|
1074 | 1074 | |
1075 | - //run new query as admin |
|
1076 | - $wp_query = new WP_Query( $wp_query->query ); |
|
1075 | + //run new query as admin |
|
1076 | + $wp_query = new WP_Query( $wp_query->query ); |
|
1077 | 1077 | |
1078 | - //set the teache as current use again |
|
1079 | - wp_set_current_user( $current_teacher_id ); |
|
1078 | + //set the teache as current use again |
|
1079 | + wp_set_current_user( $current_teacher_id ); |
|
1080 | 1080 | |
1081 | - } |
|
1082 | - } |
|
1081 | + } |
|
1082 | + } |
|
1083 | 1083 | |
1084 | - return $wp_query; |
|
1085 | - }// end give_access_to_all_questions |
|
1084 | + return $wp_query; |
|
1085 | + }// end give_access_to_all_questions |
|
1086 | 1086 | |
1087 | - /** |
|
1088 | - * Add new column heading to the course admin edit list |
|
1089 | - * |
|
1090 | - * @since 1.8.0 |
|
1091 | - * @param $columns |
|
1092 | - * @return array |
|
1093 | - */ |
|
1094 | - public function course_column_heading($columns) { |
|
1087 | + /** |
|
1088 | + * Add new column heading to the course admin edit list |
|
1089 | + * |
|
1090 | + * @since 1.8.0 |
|
1091 | + * @param $columns |
|
1092 | + * @return array |
|
1093 | + */ |
|
1094 | + public function course_column_heading($columns) { |
|
1095 | 1095 | |
1096 | - if( $this->is_admin_teacher() ){ |
|
1097 | - return $columns; |
|
1098 | - } |
|
1099 | - $new_columns = array( |
|
1100 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
1101 | - ); |
|
1102 | - return array_merge($columns, $new_columns); |
|
1096 | + if( $this->is_admin_teacher() ){ |
|
1097 | + return $columns; |
|
1098 | + } |
|
1099 | + $new_columns = array( |
|
1100 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
1101 | + ); |
|
1102 | + return array_merge($columns, $new_columns); |
|
1103 | 1103 | |
1104 | - }// end teacher column add |
|
1104 | + }// end teacher column add |
|
1105 | 1105 | |
1106 | - /** |
|
1107 | - * Print out teacher column data |
|
1108 | - * |
|
1109 | - * @since 1.8.0 |
|
1110 | - * @param $column |
|
1111 | - * @param $course_id |
|
1112 | - */ |
|
1113 | - public function course_column_data( $column, $course_id ){ |
|
1106 | + /** |
|
1107 | + * Print out teacher column data |
|
1108 | + * |
|
1109 | + * @since 1.8.0 |
|
1110 | + * @param $column |
|
1111 | + * @param $course_id |
|
1112 | + */ |
|
1113 | + public function course_column_data( $column, $course_id ){ |
|
1114 | 1114 | |
1115 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
1116 | - return; |
|
1117 | - } |
|
1115 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
1116 | + return; |
|
1117 | + } |
|
1118 | 1118 | |
1119 | - $course = get_post( $course_id ); |
|
1120 | - $teacher = get_userdata( $course->post_author ); |
|
1119 | + $course = get_post( $course_id ); |
|
1120 | + $teacher = get_userdata( $course->post_author ); |
|
1121 | 1121 | |
1122 | - if( !$teacher ){ |
|
1123 | - return; |
|
1124 | - } |
|
1122 | + if( !$teacher ){ |
|
1123 | + return; |
|
1124 | + } |
|
1125 | 1125 | |
1126 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
1126 | + echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
1127 | 1127 | |
1128 | - }// end course_column_ data |
|
1128 | + }// end course_column_ data |
|
1129 | 1129 | |
1130 | - /** |
|
1131 | - * Return only courses belonging to the given teacher. |
|
1132 | - * |
|
1133 | - * |
|
1134 | - * @since 1.8.0 |
|
1135 | - * |
|
1136 | - * @param int $teacher_id |
|
1137 | - * @param bool $return_ids_only |
|
1138 | - * |
|
1139 | - * @return array $teachers_courses |
|
1140 | - */ |
|
1141 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
1130 | + /** |
|
1131 | + * Return only courses belonging to the given teacher. |
|
1132 | + * |
|
1133 | + * |
|
1134 | + * @since 1.8.0 |
|
1135 | + * |
|
1136 | + * @param int $teacher_id |
|
1137 | + * @param bool $return_ids_only |
|
1138 | + * |
|
1139 | + * @return array $teachers_courses |
|
1140 | + */ |
|
1141 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
1142 | 1142 | |
1143 | - $teachers_courses = array(); |
|
1143 | + $teachers_courses = array(); |
|
1144 | 1144 | |
1145 | - if( empty( $teacher_id ) ){ |
|
1146 | - $teacher_id = get_current_user_id(); |
|
1147 | - } |
|
1145 | + if( empty( $teacher_id ) ){ |
|
1146 | + $teacher_id = get_current_user_id(); |
|
1147 | + } |
|
1148 | 1148 | |
1149 | - $all_courses = Sensei()->course->get_all_courses(); |
|
1149 | + $all_courses = Sensei()->course->get_all_courses(); |
|
1150 | 1150 | |
1151 | - if( empty( $all_courses ) ){ |
|
1152 | - return $all_courses; |
|
1153 | - } |
|
1151 | + if( empty( $all_courses ) ){ |
|
1152 | + return $all_courses; |
|
1153 | + } |
|
1154 | 1154 | |
1155 | - foreach( $all_courses as $course ){ |
|
1155 | + foreach( $all_courses as $course ){ |
|
1156 | 1156 | |
1157 | - if( $course->post_author != $teacher_id ){ |
|
1158 | - continue; |
|
1159 | - } |
|
1157 | + if( $course->post_author != $teacher_id ){ |
|
1158 | + continue; |
|
1159 | + } |
|
1160 | 1160 | |
1161 | - if( $return_ids_only ){ |
|
1161 | + if( $return_ids_only ){ |
|
1162 | 1162 | |
1163 | - $teachers_courses[] = $course->ID; |
|
1163 | + $teachers_courses[] = $course->ID; |
|
1164 | 1164 | |
1165 | - }else{ |
|
1165 | + }else{ |
|
1166 | 1166 | |
1167 | - $teachers_courses[] = $course; |
|
1167 | + $teachers_courses[] = $course; |
|
1168 | 1168 | |
1169 | - } |
|
1169 | + } |
|
1170 | 1170 | |
1171 | - } |
|
1171 | + } |
|
1172 | 1172 | |
1173 | - return $teachers_courses; |
|
1173 | + return $teachers_courses; |
|
1174 | 1174 | |
1175 | - } |
|
1175 | + } |
|
1176 | 1176 | |
1177 | - /** |
|
1178 | - * Limit the message display to only those sent to the current teacher |
|
1179 | - * |
|
1180 | - * @since 1.8.0 |
|
1181 | - * |
|
1182 | - * @param $query |
|
1183 | - * @return mixed |
|
1184 | - */ |
|
1185 | - public function limit_edit_messages_query( $query ){ |
|
1186 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
1187 | - return $query; |
|
1188 | - } |
|
1189 | - |
|
1190 | - $teacher = wp_get_current_user(); |
|
1191 | - |
|
1192 | - $query->set( 'meta_key', '_receiver' ); |
|
1193 | - $meta_query_args = array( |
|
1194 | - 'key' => '_receiver', |
|
1195 | - 'value' => $teacher->get('user_login') , |
|
1196 | - 'compare' => '=' |
|
1197 | - ); |
|
1177 | + /** |
|
1178 | + * Limit the message display to only those sent to the current teacher |
|
1179 | + * |
|
1180 | + * @since 1.8.0 |
|
1181 | + * |
|
1182 | + * @param $query |
|
1183 | + * @return mixed |
|
1184 | + */ |
|
1185 | + public function limit_edit_messages_query( $query ){ |
|
1186 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
1187 | + return $query; |
|
1188 | + } |
|
1189 | + |
|
1190 | + $teacher = wp_get_current_user(); |
|
1191 | + |
|
1192 | + $query->set( 'meta_key', '_receiver' ); |
|
1193 | + $meta_query_args = array( |
|
1194 | + 'key' => '_receiver', |
|
1195 | + 'value' => $teacher->get('user_login') , |
|
1196 | + 'compare' => '=' |
|
1197 | + ); |
|
1198 | 1198 | |
1199 | - $query->set('meta_query', $meta_query_args ); |
|
1199 | + $query->set('meta_query', $meta_query_args ); |
|
1200 | 1200 | |
1201 | - return $query; |
|
1202 | - } |
|
1201 | + return $query; |
|
1202 | + } |
|
1203 | 1203 | |
1204 | 1204 | |
1205 | - /** |
|
1206 | - * Add options to filter courses by teacher |
|
1207 | - * |
|
1208 | - * @since 1.8.0 |
|
1209 | - * |
|
1210 | - * @return void |
|
1211 | - */ |
|
1212 | - public function course_teacher_filter_options() { |
|
1213 | - global $typenow; |
|
1205 | + /** |
|
1206 | + * Add options to filter courses by teacher |
|
1207 | + * |
|
1208 | + * @since 1.8.0 |
|
1209 | + * |
|
1210 | + * @return void |
|
1211 | + */ |
|
1212 | + public function course_teacher_filter_options() { |
|
1213 | + global $typenow; |
|
1214 | 1214 | |
1215 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1216 | - return; |
|
1217 | - } |
|
1215 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1216 | + return; |
|
1217 | + } |
|
1218 | 1218 | |
1219 | - // get all roles |
|
1220 | - $roles = get_editable_roles(); |
|
1219 | + // get all roles |
|
1220 | + $roles = get_editable_roles(); |
|
1221 | 1221 | |
1222 | - // get roles with the course edit capability |
|
1223 | - // and then get the users with those roles |
|
1224 | - $users_who_can_edit_courses = array(); |
|
1225 | - foreach( $roles as $role_item ){ |
|
1222 | + // get roles with the course edit capability |
|
1223 | + // and then get the users with those roles |
|
1224 | + $users_who_can_edit_courses = array(); |
|
1225 | + foreach( $roles as $role_item ){ |
|
1226 | 1226 | |
1227 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
1227 | + $role = get_role( strtolower( $role_item['name'] ) ); |
|
1228 | 1228 | |
1229 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
1229 | + if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
1230 | 1230 | |
1231 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
1232 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
1231 | + $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
1232 | + $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
1233 | 1233 | |
1234 | - // add user from the current $user_role to all users |
|
1235 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
1234 | + // add user from the current $user_role to all users |
|
1235 | + $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
1236 | 1236 | |
1237 | - } |
|
1237 | + } |
|
1238 | 1238 | |
1239 | - } |
|
1239 | + } |
|
1240 | 1240 | |
1241 | - // Create the select element with the given users who can edit course |
|
1242 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1243 | - $course_options = ''; |
|
1244 | - foreach( $users_who_can_edit_courses as $user ) { |
|
1245 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
1246 | - } |
|
1241 | + // Create the select element with the given users who can edit course |
|
1242 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1243 | + $course_options = ''; |
|
1244 | + foreach( $users_who_can_edit_courses as $user ) { |
|
1245 | + $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
1246 | + } |
|
1247 | 1247 | |
1248 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
1249 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
1250 | - $output .= $course_options; |
|
1251 | - $output .= '</select>'; |
|
1248 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
1249 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
1250 | + $output .= $course_options; |
|
1251 | + $output .= '</select>'; |
|
1252 | 1252 | |
1253 | - echo $output; |
|
1254 | - } |
|
1253 | + echo $output; |
|
1254 | + } |
|
1255 | 1255 | |
1256 | - /** |
|
1257 | - * Modify the main query on the admin course list screen |
|
1258 | - * |
|
1259 | - * @since 1.8.0 |
|
1260 | - * |
|
1261 | - * @param $query |
|
1262 | - * @return $query |
|
1263 | - */ |
|
1264 | - public function teacher_filter_query_modify( $query ){ |
|
1265 | - global $typenow; |
|
1256 | + /** |
|
1257 | + * Modify the main query on the admin course list screen |
|
1258 | + * |
|
1259 | + * @since 1.8.0 |
|
1260 | + * |
|
1261 | + * @param $query |
|
1262 | + * @return $query |
|
1263 | + */ |
|
1264 | + public function teacher_filter_query_modify( $query ){ |
|
1265 | + global $typenow; |
|
1266 | 1266 | |
1267 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1268 | - return $query; |
|
1269 | - } |
|
1270 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1271 | - |
|
1272 | - if( empty( $course_teacher ) ) { |
|
1273 | - return $query; |
|
1274 | - } |
|
1275 | - |
|
1276 | - $query['author'] = $course_teacher; |
|
1277 | - return $query; |
|
1278 | - } |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * Only show current teacher's media in the media library |
|
1282 | - * @param array $request Default request arguments |
|
1283 | - * @return array Modified request arguments |
|
1284 | - */ |
|
1285 | - public function restrict_media_library( $request = array() ) { |
|
1286 | - |
|
1287 | - if( ! is_admin() ) { |
|
1288 | - return $request; |
|
1289 | - } |
|
1290 | - |
|
1291 | - if( ! $this->is_admin_teacher() ) { |
|
1292 | - return $request; |
|
1293 | - } |
|
1294 | - |
|
1295 | - $screen = get_current_screen(); |
|
1296 | - |
|
1297 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
1298 | - $teacher = intval( get_current_user_id() ); |
|
1299 | - |
|
1300 | - if( $teacher ) { |
|
1301 | - $request['author__in'] = array( $teacher ); |
|
1302 | - } |
|
1303 | - } |
|
1304 | - |
|
1305 | - return $request; |
|
1306 | - } // End restrict_media_library() |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
1310 | - * @param array $query Default query arguments |
|
1311 | - * @return array Modified query arguments |
|
1312 | - */ |
|
1313 | - public function restrict_media_library_modal( $query = array() ) { |
|
1314 | - |
|
1315 | - if( ! is_admin() ) { |
|
1316 | - return $query; |
|
1317 | - } |
|
1318 | - |
|
1319 | - if( ! $this->is_admin_teacher() ) { |
|
1320 | - return $query; |
|
1321 | - } |
|
1322 | - |
|
1323 | - $teacher = intval( get_current_user_id() ); |
|
1324 | - |
|
1325 | - if( $teacher ) { |
|
1326 | - $query['author__in'] = array( $teacher ); |
|
1327 | - } |
|
1328 | - |
|
1329 | - return $query; |
|
1330 | - } // End restrict_media_library_modal() |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
1334 | - * |
|
1335 | - * @since 1.8.0 |
|
1336 | - * |
|
1337 | - * @param int $lesson_id |
|
1338 | - */ |
|
1339 | - public function update_lesson_teacher( $lesson_id ){ |
|
1340 | - |
|
1341 | - if( 'lesson'!= get_post_type() ){ |
|
1342 | - return; |
|
1343 | - } |
|
1267 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1268 | + return $query; |
|
1269 | + } |
|
1270 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1271 | + |
|
1272 | + if( empty( $course_teacher ) ) { |
|
1273 | + return $query; |
|
1274 | + } |
|
1275 | + |
|
1276 | + $query['author'] = $course_teacher; |
|
1277 | + return $query; |
|
1278 | + } |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * Only show current teacher's media in the media library |
|
1282 | + * @param array $request Default request arguments |
|
1283 | + * @return array Modified request arguments |
|
1284 | + */ |
|
1285 | + public function restrict_media_library( $request = array() ) { |
|
1286 | + |
|
1287 | + if( ! is_admin() ) { |
|
1288 | + return $request; |
|
1289 | + } |
|
1290 | + |
|
1291 | + if( ! $this->is_admin_teacher() ) { |
|
1292 | + return $request; |
|
1293 | + } |
|
1294 | + |
|
1295 | + $screen = get_current_screen(); |
|
1296 | + |
|
1297 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
1298 | + $teacher = intval( get_current_user_id() ); |
|
1299 | + |
|
1300 | + if( $teacher ) { |
|
1301 | + $request['author__in'] = array( $teacher ); |
|
1302 | + } |
|
1303 | + } |
|
1304 | + |
|
1305 | + return $request; |
|
1306 | + } // End restrict_media_library() |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
1310 | + * @param array $query Default query arguments |
|
1311 | + * @return array Modified query arguments |
|
1312 | + */ |
|
1313 | + public function restrict_media_library_modal( $query = array() ) { |
|
1314 | + |
|
1315 | + if( ! is_admin() ) { |
|
1316 | + return $query; |
|
1317 | + } |
|
1318 | + |
|
1319 | + if( ! $this->is_admin_teacher() ) { |
|
1320 | + return $query; |
|
1321 | + } |
|
1322 | + |
|
1323 | + $teacher = intval( get_current_user_id() ); |
|
1324 | + |
|
1325 | + if( $teacher ) { |
|
1326 | + $query['author__in'] = array( $teacher ); |
|
1327 | + } |
|
1328 | + |
|
1329 | + return $query; |
|
1330 | + } // End restrict_media_library_modal() |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
1334 | + * |
|
1335 | + * @since 1.8.0 |
|
1336 | + * |
|
1337 | + * @param int $lesson_id |
|
1338 | + */ |
|
1339 | + public function update_lesson_teacher( $lesson_id ){ |
|
1340 | + |
|
1341 | + if( 'lesson'!= get_post_type() ){ |
|
1342 | + return; |
|
1343 | + } |
|
1344 | 1344 | |
1345 | - // this should only run once per request cycle |
|
1346 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
1345 | + // this should only run once per request cycle |
|
1346 | + remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
1347 | 1347 | |
1348 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1348 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1349 | 1349 | |
1350 | - if( empty( $course_id ) || ! $course_id ){ |
|
1351 | - return; |
|
1352 | - } |
|
1350 | + if( empty( $course_id ) || ! $course_id ){ |
|
1351 | + return; |
|
1352 | + } |
|
1353 | 1353 | |
1354 | - $course = get_post( $course_id ); |
|
1354 | + $course = get_post( $course_id ); |
|
1355 | 1355 | |
1356 | - $lesson_update_args= array( |
|
1357 | - 'ID' => $lesson_id , |
|
1358 | - 'post_author' => $course->post_author |
|
1359 | - ); |
|
1360 | - wp_update_post( $lesson_update_args ); |
|
1356 | + $lesson_update_args= array( |
|
1357 | + 'ID' => $lesson_id , |
|
1358 | + 'post_author' => $course->post_author |
|
1359 | + ); |
|
1360 | + wp_update_post( $lesson_update_args ); |
|
1361 | 1361 | |
1362 | - } // end update_lesson_teacher |
|
1362 | + } // end update_lesson_teacher |
|
1363 | 1363 | |
1364 | - /** |
|
1365 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
1366 | - * |
|
1367 | - * Limit teachers to only see their courses, lessons and questions |
|
1368 | - * |
|
1369 | - * @since 1.8.0 |
|
1370 | - * @access public |
|
1371 | - * @parameters array $wp_query |
|
1372 | - * @return WP_Query $wp_query |
|
1373 | - */ |
|
1374 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
1375 | - global $current_user; |
|
1364 | + /** |
|
1365 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
1366 | + * |
|
1367 | + * Limit teachers to only see their courses, lessons and questions |
|
1368 | + * |
|
1369 | + * @since 1.8.0 |
|
1370 | + * @access public |
|
1371 | + * @parameters array $wp_query |
|
1372 | + * @return WP_Query $wp_query |
|
1373 | + */ |
|
1374 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
1375 | + global $current_user; |
|
1376 | 1376 | |
1377 | - //exit early |
|
1378 | - if( ! $this->is_admin_teacher() ){ |
|
1379 | - return $wp_query; |
|
1380 | - } |
|
1377 | + //exit early |
|
1378 | + if( ! $this->is_admin_teacher() ){ |
|
1379 | + return $wp_query; |
|
1380 | + } |
|
1381 | 1381 | |
1382 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
1383 | - return $wp_query; |
|
1384 | - } |
|
1382 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
1383 | + return $wp_query; |
|
1384 | + } |
|
1385 | 1385 | |
1386 | - $screen = get_current_screen(); |
|
1386 | + $screen = get_current_screen(); |
|
1387 | 1387 | |
1388 | - if( empty( $screen ) ){ |
|
1389 | - return $wp_query; |
|
1390 | - } |
|
1388 | + if( empty( $screen ) ){ |
|
1389 | + return $wp_query; |
|
1390 | + } |
|
1391 | 1391 | |
1392 | - // for any of these conditions limit what the teacher will see |
|
1393 | - $limit_screens = array( |
|
1394 | - 'edit-lesson', |
|
1395 | - 'edit-course', |
|
1396 | - 'edit-question', |
|
1397 | - 'course_page_course-order', |
|
1398 | - 'lesson_page_lesson-order', |
|
1399 | - ); |
|
1392 | + // for any of these conditions limit what the teacher will see |
|
1393 | + $limit_screens = array( |
|
1394 | + 'edit-lesson', |
|
1395 | + 'edit-course', |
|
1396 | + 'edit-question', |
|
1397 | + 'course_page_course-order', |
|
1398 | + 'lesson_page_lesson-order', |
|
1399 | + ); |
|
1400 | 1400 | |
1401 | - if( in_array($screen->id , $limit_screens ) ) { |
|
1401 | + if( in_array($screen->id , $limit_screens ) ) { |
|
1402 | 1402 | |
1403 | - // set the query author to the current user to only show those those posts |
|
1404 | - $wp_query->set( 'author', $current_user->ID ); |
|
1405 | - } |
|
1403 | + // set the query author to the current user to only show those those posts |
|
1404 | + $wp_query->set( 'author', $current_user->ID ); |
|
1405 | + } |
|
1406 | 1406 | |
1407 | - return $wp_query; |
|
1407 | + return $wp_query; |
|
1408 | 1408 | |
1409 | - } // end limit_teacher_edit_screen_post_types() |
|
1409 | + } // end limit_teacher_edit_screen_post_types() |
|
1410 | 1410 | |
1411 | 1411 | |
1412 | - /** |
|
1413 | - * Sensei_Teacher::teacher_login_redirect |
|
1414 | - * |
|
1415 | - * Redirect teachers to /wp-admin/ after login |
|
1416 | - * |
|
1417 | - * @since 1.8.7 |
|
1418 | - * @access public |
|
1419 | - * @param string $user_login |
|
1420 | - * @param object $user |
|
1421 | - * @return void |
|
1422 | - */ |
|
1412 | + /** |
|
1413 | + * Sensei_Teacher::teacher_login_redirect |
|
1414 | + * |
|
1415 | + * Redirect teachers to /wp-admin/ after login |
|
1416 | + * |
|
1417 | + * @since 1.8.7 |
|
1418 | + * @access public |
|
1419 | + * @param string $user_login |
|
1420 | + * @param object $user |
|
1421 | + * @return void |
|
1422 | + */ |
|
1423 | 1423 | |
1424 | - public function teacher_login_redirect( $user_login, $user ) { |
|
1424 | + public function teacher_login_redirect( $user_login, $user ) { |
|
1425 | 1425 | |
1426 | - if (user_can($user, 'edit_courses')) { |
|
1426 | + if (user_can($user, 'edit_courses')) { |
|
1427 | 1427 | |
1428 | - if (isset($_POST['redirect_to'])) { |
|
1428 | + if (isset($_POST['redirect_to'])) { |
|
1429 | 1429 | |
1430 | - wp_redirect($_POST['redirect_to'], 303); |
|
1430 | + wp_redirect($_POST['redirect_to'], 303); |
|
1431 | 1431 | |
1432 | - exit; |
|
1432 | + exit; |
|
1433 | 1433 | |
1434 | - } else { |
|
1434 | + } else { |
|
1435 | 1435 | |
1436 | - wp_redirect(admin_url(), 303); |
|
1436 | + wp_redirect(admin_url(), 303); |
|
1437 | 1437 | |
1438 | - exit; |
|
1438 | + exit; |
|
1439 | 1439 | |
1440 | - } |
|
1441 | - } |
|
1440 | + } |
|
1441 | + } |
|
1442 | 1442 | |
1443 | - } // end teacher_login_redirect() |
|
1443 | + } // end teacher_login_redirect() |
|
1444 | 1444 | |
1445 | 1445 | |
1446 | 1446 | |
1447 | - /** |
|
1448 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
1449 | - * |
|
1450 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
1451 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
1452 | - * so they can 'moderate_comments' as well. |
|
1453 | - * |
|
1454 | - * @since 1.8.7 |
|
1455 | - * @access public |
|
1456 | - * @parameters void |
|
1457 | - * @return void |
|
1458 | - */ |
|
1447 | + /** |
|
1448 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
1449 | + * |
|
1450 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
1451 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
1452 | + * so they can 'moderate_comments' as well. |
|
1453 | + * |
|
1454 | + * @since 1.8.7 |
|
1455 | + * @access public |
|
1456 | + * @parameters void |
|
1457 | + * @return void |
|
1458 | + */ |
|
1459 | 1459 | |
1460 | - public function restrict_posts_menu_page() { |
|
1460 | + public function restrict_posts_menu_page() { |
|
1461 | 1461 | |
1462 | - global $pagenow, $typenow; |
|
1462 | + global $pagenow, $typenow; |
|
1463 | 1463 | |
1464 | - $user = wp_get_current_user(); |
|
1464 | + $user = wp_get_current_user(); |
|
1465 | 1465 | |
1466 | - /** |
|
1467 | - * Filter the option to hide the Posts menu page. |
|
1468 | - * |
|
1469 | - * @since 1.8.7 |
|
1470 | - * |
|
1471 | - * @param bool $restrict default true |
|
1472 | - */ |
|
1466 | + /** |
|
1467 | + * Filter the option to hide the Posts menu page. |
|
1468 | + * |
|
1469 | + * @since 1.8.7 |
|
1470 | + * |
|
1471 | + * @param bool $restrict default true |
|
1472 | + */ |
|
1473 | 1473 | |
1474 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
1474 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
1475 | 1475 | |
1476 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
1476 | + if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
1477 | 1477 | |
1478 | - remove_menu_page('edit.php'); |
|
1478 | + remove_menu_page('edit.php'); |
|
1479 | 1479 | |
1480 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
1480 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
1481 | 1481 | |
1482 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
1482 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
1483 | 1483 | |
1484 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
1484 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
1485 | 1485 | |
1486 | - } |
|
1486 | + } |
|
1487 | 1487 | |
1488 | - } |
|
1488 | + } |
|
1489 | 1489 | |
1490 | - } |
|
1490 | + } |
|
1491 | 1491 | |
1492 | - } // end restrict_posts_menu_page() |
|
1492 | + } // end restrict_posts_menu_page() |
|
1493 | 1493 | |
1494 | - /** |
|
1495 | - * Sensei_Teacher::restrict_comment_moderation() |
|
1496 | - * |
|
1497 | - * Restrict commendation moderation for teachers |
|
1498 | - * so they can only moderate comments made to posts they own. |
|
1499 | - * |
|
1500 | - * @since 1.8.7 |
|
1501 | - * @access public |
|
1502 | - * @parameters obj $clauses |
|
1503 | - * @return WP_Comment_Query $clauses |
|
1504 | - */ |
|
1494 | + /** |
|
1495 | + * Sensei_Teacher::restrict_comment_moderation() |
|
1496 | + * |
|
1497 | + * Restrict commendation moderation for teachers |
|
1498 | + * so they can only moderate comments made to posts they own. |
|
1499 | + * |
|
1500 | + * @since 1.8.7 |
|
1501 | + * @access public |
|
1502 | + * @parameters obj $clauses |
|
1503 | + * @return WP_Comment_Query $clauses |
|
1504 | + */ |
|
1505 | 1505 | |
1506 | - public function restrict_comment_moderation ( $clauses ) { |
|
1506 | + public function restrict_comment_moderation ( $clauses ) { |
|
1507 | 1507 | |
1508 | - global $pagenow; |
|
1508 | + global $pagenow; |
|
1509 | 1509 | |
1510 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
1510 | + if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
1511 | 1511 | |
1512 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
1512 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
1513 | 1513 | |
1514 | - } |
|
1514 | + } |
|
1515 | 1515 | |
1516 | - return $clauses; |
|
1516 | + return $clauses; |
|
1517 | 1517 | |
1518 | - } // end restrict_comment_moderation() |
|
1518 | + } // end restrict_comment_moderation() |
|
1519 | 1519 | |
1520 | - /** |
|
1521 | - * Determine if a user is a teacher by ID |
|
1522 | - * |
|
1523 | - * @param int $user_id |
|
1524 | - * |
|
1525 | - * @return bool |
|
1526 | - */ |
|
1527 | - public static function is_a_teacher( $user_id ){ |
|
1520 | + /** |
|
1521 | + * Determine if a user is a teacher by ID |
|
1522 | + * |
|
1523 | + * @param int $user_id |
|
1524 | + * |
|
1525 | + * @return bool |
|
1526 | + */ |
|
1527 | + public static function is_a_teacher( $user_id ){ |
|
1528 | 1528 | |
1529 | - $user = get_user_by('id', $user_id); |
|
1529 | + $user = get_user_by('id', $user_id); |
|
1530 | 1530 | |
1531 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
1531 | + if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
1532 | 1532 | |
1533 | - return true; |
|
1533 | + return true; |
|
1534 | 1534 | |
1535 | - }else{ |
|
1535 | + }else{ |
|
1536 | 1536 | |
1537 | - return false; |
|
1537 | + return false; |
|
1538 | 1538 | |
1539 | - } |
|
1539 | + } |
|
1540 | 1540 | |
1541 | - }// end is_a_teacher |
|
1541 | + }// end is_a_teacher |
|
1542 | 1542 | |
1543 | - /** |
|
1544 | - * The archive title on the teacher archive filter |
|
1545 | - * |
|
1546 | - * @since 1.9.0 |
|
1547 | - */ |
|
1548 | - public static function archive_title(){ |
|
1543 | + /** |
|
1544 | + * The archive title on the teacher archive filter |
|
1545 | + * |
|
1546 | + * @since 1.9.0 |
|
1547 | + */ |
|
1548 | + public static function archive_title(){ |
|
1549 | 1549 | |
1550 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
1551 | - $author_name = $author->display_name; |
|
1552 | - ?> |
|
1550 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
1551 | + $author_name = $author->display_name; |
|
1552 | + ?> |
|
1553 | 1553 | <h2 class="teacher-archive-title"> |
1554 | 1554 | |
1555 | 1555 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1557,17 +1557,17 @@ discard block |
||
1557 | 1557 | </h2> |
1558 | 1558 | <?php |
1559 | 1559 | |
1560 | - }// archive title |
|
1560 | + }// archive title |
|
1561 | 1561 | |
1562 | - /** |
|
1563 | - * Removing course meta on the teacher archive page |
|
1564 | - * |
|
1565 | - * @since 1.9.0 |
|
1566 | - */ |
|
1567 | - public static function remove_course_meta_on_teacher_archive(){ |
|
1562 | + /** |
|
1563 | + * Removing course meta on the teacher archive page |
|
1564 | + * |
|
1565 | + * @since 1.9.0 |
|
1566 | + */ |
|
1567 | + public static function remove_course_meta_on_teacher_archive(){ |
|
1568 | 1568 | |
1569 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1569 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1570 | 1570 | |
1571 | - } |
|
1571 | + } |
|
1572 | 1572 | |
1573 | 1573 | } // End Class |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | // Only show course & lesson excerpts in search results |
70 | 70 | add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) ); |
71 | 71 | |
72 | - //Use WooCommerce filter to show admin bar to Teachers. |
|
73 | - add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
72 | + //Use WooCommerce filter to show admin bar to Teachers. |
|
73 | + add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
74 | 74 | |
75 | - // Remove course from active courses if an order is cancelled or refunded |
|
75 | + // Remove course from active courses if an order is cancelled or refunded |
|
76 | 76 | add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
77 | 77 | add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
78 | 78 | add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | wp_enqueue_script( Sensei()->token . '-user-dashboard' ); |
134 | 134 | |
135 | 135 | |
136 | - // Course Archive javascript |
|
137 | - if( is_post_type_archive( 'course' ) ){ |
|
136 | + // Course Archive javascript |
|
137 | + if( is_post_type_archive( 'course' ) ){ |
|
138 | 138 | |
139 | - wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
140 | - wp_enqueue_script( 'sensei-course-archive-js' ); |
|
139 | + wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
140 | + wp_enqueue_script( 'sensei-course-archive-js' ); |
|
141 | 141 | |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | 145 | // Allow additional scripts to be loaded |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | /** |
181 | 181 | * sensei_get_template_part function. |
182 | 182 | * |
183 | - * @deprecated sine 1.9.0 |
|
183 | + * @deprecated sine 1.9.0 |
|
184 | 184 | * @access public |
185 | 185 | * @param mixed $slug |
186 | 186 | * @param string $name (default: '') |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | */ |
189 | 189 | function sensei_get_template_part( $slug, $name = '' ) { |
190 | 190 | |
191 | - _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
192 | - Sensei_Templates::get_part( $slug, $name ); |
|
191 | + _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
192 | + Sensei_Templates::get_part( $slug, $name ); |
|
193 | 193 | |
194 | 194 | } // End sensei_get_template_part() |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * sensei_get_template function. |
198 | 198 | * |
199 | - * @deprecated since 1.9.0 |
|
199 | + * @deprecated since 1.9.0 |
|
200 | 200 | * @access public |
201 | 201 | * @param mixed $template_name |
202 | 202 | * @param array $args (default: array()) |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | */ |
207 | 207 | function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
208 | 208 | |
209 | - _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
210 | - Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
209 | + _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
210 | + Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
211 | 211 | |
212 | 212 | } // End sensei_get_template() |
213 | 213 | |
@@ -223,33 +223,33 @@ discard block |
||
223 | 223 | */ |
224 | 224 | function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
225 | 225 | |
226 | - _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
227 | - Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
226 | + _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
227 | + Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
228 | 228 | |
229 | 229 | } // End sensei_locate_template() |
230 | 230 | |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * sensei_output_content_wrapper function. |
234 | - * |
|
234 | + * |
|
235 | 235 | * @access public |
236 | 236 | * @return void |
237 | 237 | */ |
238 | 238 | function sensei_output_content_wrapper() { |
239 | 239 | |
240 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
241 | - $backwards_compatible_wrapper_location = array( |
|
242 | - Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
243 | - 'wrappers/wrapper-start.php' |
|
244 | - ); |
|
240 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
241 | + $backwards_compatible_wrapper_location = array( |
|
242 | + Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
243 | + 'wrappers/wrapper-start.php' |
|
244 | + ); |
|
245 | 245 | |
246 | - $template = locate_template( $backwards_compatible_wrapper_location ); |
|
247 | - if( !empty( $template ) ){ |
|
246 | + $template = locate_template( $backwards_compatible_wrapper_location ); |
|
247 | + if( !empty( $template ) ){ |
|
248 | 248 | |
249 | - Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
250 | - return; |
|
249 | + Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
250 | + return; |
|
251 | 251 | |
252 | - } |
|
252 | + } |
|
253 | 253 | |
254 | 254 | Sensei_Templates::get_template( 'globals/wrapper-start.php' ); |
255 | 255 | |
@@ -258,25 +258,25 @@ discard block |
||
258 | 258 | |
259 | 259 | /** |
260 | 260 | * sensei_output_content_wrapper_end function. |
261 | - * |
|
261 | + * |
|
262 | 262 | * @access public |
263 | 263 | * @return void |
264 | 264 | */ |
265 | 265 | function sensei_output_content_wrapper_end() { |
266 | 266 | |
267 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
268 | - $backwards_compatible_wrapper_location = array( |
|
269 | - Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
270 | - 'wrappers/wrapper-end.php' |
|
271 | - ); |
|
267 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
268 | + $backwards_compatible_wrapper_location = array( |
|
269 | + Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
270 | + 'wrappers/wrapper-end.php' |
|
271 | + ); |
|
272 | 272 | |
273 | - $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
274 | - if( !empty( $backwards_compatible_template ) ){ |
|
273 | + $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
274 | + if( !empty( $backwards_compatible_template ) ){ |
|
275 | 275 | |
276 | - Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
277 | - return; |
|
276 | + Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
277 | + return; |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | 281 | |
282 | 282 | Sensei_Templates::get_template( 'globals/wrapper-end.php' ); |
@@ -292,55 +292,55 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public static function load_content_pagination() { |
294 | 294 | |
295 | - if( is_singular('course') ) { |
|
295 | + if( is_singular('course') ) { |
|
296 | 296 | |
297 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
298 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
299 | - if( !empty( $template ) ){ |
|
297 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
298 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
299 | + if( !empty( $template ) ){ |
|
300 | 300 | |
301 | - Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
302 | - return; |
|
301 | + Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
302 | + return; |
|
303 | 303 | |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | 306 | Sensei_Templates::get_template( 'globals/pagination-posts.php' ); |
307 | 307 | |
308 | 308 | } elseif( is_singular('lesson') ) { |
309 | 309 | |
310 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
311 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
312 | - if( !empty( $template ) ){ |
|
310 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
311 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
312 | + if( !empty( $template ) ){ |
|
313 | 313 | |
314 | - Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
315 | - return; |
|
314 | + Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
315 | + return; |
|
316 | 316 | |
317 | - } |
|
317 | + } |
|
318 | 318 | |
319 | 319 | Sensei_Templates::get_template( 'globals/pagination-lesson.php' ); |
320 | 320 | |
321 | 321 | } elseif( is_singular('quiz') ) { |
322 | 322 | |
323 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
324 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
325 | - if( !empty( $template ) ){ |
|
323 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
324 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
325 | + if( !empty( $template ) ){ |
|
326 | 326 | |
327 | - Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
328 | - return; |
|
327 | + Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
328 | + return; |
|
329 | 329 | |
330 | - } |
|
330 | + } |
|
331 | 331 | |
332 | 332 | Sensei_Templates::get_template( 'globals/pagination-quiz.php' ); |
333 | 333 | |
334 | 334 | } else { |
335 | 335 | |
336 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
337 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
338 | - if( !empty( $template ) ){ |
|
336 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
337 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
338 | + if( !empty( $template ) ){ |
|
339 | 339 | |
340 | - Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
341 | - return; |
|
340 | + Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
341 | + return; |
|
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | 345 | Sensei_Templates::get_template( 'globals/pagination.php' ); |
346 | 346 | |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | |
398 | 398 | case '#senseimymessages': |
399 | 399 | $item->url = $my_messages_url; |
400 | - // if no archive link exist for sensei_message |
|
401 | - // set it back to the place holder |
|
402 | - if( ! $item->url ){ |
|
400 | + // if no archive link exist for sensei_message |
|
401 | + // set it back to the place holder |
|
402 | + if( ! $item->url ){ |
|
403 | 403 | |
404 | - $item->url = '#senseimymessages'; |
|
404 | + $item->url = '#senseimymessages'; |
|
405 | 405 | |
406 | - } |
|
406 | + } |
|
407 | 407 | break; |
408 | 408 | |
409 | 409 | case '#senseilearnerprofile': |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | |
470 | 470 | // Remove the My Messages link for logged out users or if Private Messages are disabled |
471 | 471 | if( ! get_post_type_archive_link( 'sensei_message' ) |
472 | - && '#senseimymessages' == $item->url ) { |
|
472 | + && '#senseimymessages' == $item->url ) { |
|
473 | 473 | |
474 | 474 | if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) { |
475 | 475 | |
@@ -492,42 +492,42 @@ discard block |
||
492 | 492 | |
493 | 493 | // add category nicenames in body and post class |
494 | 494 | function sensei_search_results_classes($classes) { |
495 | - global $post; |
|
496 | - // Handle Search Classes for Courses, Lessons, and WC Products |
|
497 | - if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
498 | - $classes[] = 'post'; |
|
495 | + global $post; |
|
496 | + // Handle Search Classes for Courses, Lessons, and WC Products |
|
497 | + if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
498 | + $classes[] = 'post'; |
|
499 | 499 | } // End If Statement |
500 | - return $classes; |
|
500 | + return $classes; |
|
501 | 501 | } // End sensei_search_results_classes() |
502 | 502 | |
503 | - /** |
|
504 | - * sensei_single_title output for single page title |
|
505 | - * @since 1.1.0 |
|
506 | - * @return void |
|
507 | - * @deprecated |
|
508 | - */ |
|
509 | - function the_single_title() { |
|
503 | + /** |
|
504 | + * sensei_single_title output for single page title |
|
505 | + * @since 1.1.0 |
|
506 | + * @return void |
|
507 | + * @deprecated |
|
508 | + */ |
|
509 | + function the_single_title() { |
|
510 | 510 | |
511 | - _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0'); |
|
511 | + _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0'); |
|
512 | 512 | |
513 | - } // End sensei_single_title() |
|
513 | + } // End sensei_single_title() |
|
514 | 514 | |
515 | 515 | /** |
516 | 516 | * sensei_course_image output for course image Please use Sensei()->course->course_image instead. |
517 | - * |
|
518 | - * @deprecated since 1.9.0 |
|
519 | - * @param $course_id |
|
520 | - * @param string $width |
|
521 | - * @param string $height |
|
522 | - * @param bool|false $return |
|
523 | - * @return string|void |
|
517 | + * |
|
518 | + * @deprecated since 1.9.0 |
|
519 | + * @param $course_id |
|
520 | + * @param string $width |
|
521 | + * @param string $height |
|
522 | + * @param bool|false $return |
|
523 | + * @return string|void |
|
524 | 524 | */ |
525 | 525 | function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) { |
526 | 526 | |
527 | - if ( ! $return ) { |
|
527 | + if ( ! $return ) { |
|
528 | 528 | |
529 | 529 | echo Sensei()->course->course_image( $course_id, $width, $height ); |
530 | - return ''; |
|
530 | + return ''; |
|
531 | 531 | |
532 | 532 | } // End If Statement |
533 | 533 | |
@@ -538,31 +538,31 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * sensei_lesson_image output for lesson image |
540 | 540 | * @since 1.2.0 |
541 | - * @deprecated since 1.9.0 |
|
542 | - * @param $lesson_id |
|
543 | - * @param string $width |
|
544 | - * @param string $height |
|
545 | - * @param bool|false $return |
|
546 | - * @param bool|false $widget |
|
547 | - * @return string |
|
541 | + * @deprecated since 1.9.0 |
|
542 | + * @param $lesson_id |
|
543 | + * @param string $width |
|
544 | + * @param string $height |
|
545 | + * @param bool|false $return |
|
546 | + * @param bool|false $widget |
|
547 | + * @return string |
|
548 | 548 | */ |
549 | 549 | function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) { |
550 | 550 | |
551 | - if( ! $return ){ |
|
551 | + if( ! $return ){ |
|
552 | 552 | |
553 | - echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
554 | - return ''; |
|
555 | - } |
|
553 | + echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
554 | + return ''; |
|
555 | + } |
|
556 | 556 | |
557 | - return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
557 | + return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
558 | 558 | |
559 | 559 | } // End sensei_lesson_image() |
560 | 560 | |
561 | - /** |
|
562 | - * @since 1.0.0 |
|
563 | - * @param WP_Query $query |
|
564 | - */ |
|
565 | - function sensei_course_archive_pagination( $query ) { |
|
561 | + /** |
|
562 | + * @since 1.0.0 |
|
563 | + * @param WP_Query $query |
|
564 | + */ |
|
565 | + function sensei_course_archive_pagination( $query ) { |
|
566 | 566 | |
567 | 567 | if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) { |
568 | 568 | |
@@ -585,50 +585,50 @@ discard block |
||
585 | 585 | * |
586 | 586 | * @access public |
587 | 587 | * @since 1.2.0 |
588 | - * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header |
|
588 | + * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header |
|
589 | 589 | * @return void |
590 | 590 | */ |
591 | 591 | function sensei_course_archive_header( ) { |
592 | 592 | |
593 | - trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
|
594 | - WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
593 | + trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
|
594 | + WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
595 | 595 | |
596 | 596 | } // sensei_course_archive_header() |
597 | 597 | |
598 | 598 | /** |
599 | 599 | * sensei_lesson_archive_header function. |
600 | 600 | * |
601 | - * @deprecated since 1.9.0 |
|
601 | + * @deprecated since 1.9.0 |
|
602 | 602 | * @access public |
603 | 603 | * @since 1.2.1 |
604 | 604 | * @return void |
605 | 605 | */ |
606 | 606 | public function sensei_lesson_archive_header( ) { |
607 | - _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
608 | - Sensei()->lesson->the_archive_header(); |
|
607 | + _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
608 | + Sensei()->lesson->the_archive_header(); |
|
609 | 609 | } // sensei_course_archive_header() |
610 | 610 | |
611 | - /** |
|
612 | - * @deprecated since 1.9.0 |
|
613 | - */ |
|
611 | + /** |
|
612 | + * @deprecated since 1.9.0 |
|
613 | + */ |
|
614 | 614 | public function sensei_message_archive_header( ){ |
615 | - _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
616 | - Sensei_Messages::the_archive_header(); |
|
615 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
616 | + Sensei_Messages::the_archive_header(); |
|
617 | 617 | } // sensei_message_archive_header() |
618 | 618 | |
619 | 619 | /** |
620 | 620 | * sensei_course_archive_course_title output for course archive page individual course title |
621 | 621 | * @since 1.2.0 |
622 | - * @param WP_Post $post_item |
|
622 | + * @param WP_Post $post_item |
|
623 | 623 | * @return void |
624 | 624 | */ |
625 | 625 | function sensei_course_archive_course_title( $post_item ) { |
626 | 626 | if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) { |
627 | 627 | $post_id = absint( $post_item->ID ); |
628 | - $post_title = $post_item->post_title; |
|
628 | + $post_title = $post_item->post_title; |
|
629 | 629 | } else { |
630 | 630 | $post_id = get_the_ID(); |
631 | - $post_title = get_the_title(); |
|
631 | + $post_title = get_the_title(); |
|
632 | 632 | } // End If Statement |
633 | 633 | ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
634 | 634 | } // End sensei_course_archive_course_title() |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | */ |
641 | 641 | public function sensei_lesson_archive_lesson_title() { |
642 | 642 | $post_id = get_the_ID(); |
643 | - $post_title = get_the_title(); |
|
643 | + $post_title = get_the_title(); |
|
644 | 644 | ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
645 | 645 | } // End sensei_lesson_archive_lesson_title() |
646 | 646 | |
@@ -657,9 +657,9 @@ discard block |
||
657 | 657 | |
658 | 658 | if( empty( $id ) ){ |
659 | 659 | |
660 | - $id = get_the_ID(); |
|
660 | + $id = get_the_ID(); |
|
661 | 661 | |
662 | - } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | $sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' ); |
665 | 665 | $separator = apply_filters( 'sensei_breadcrumb_separator', '>' ); |
@@ -672,31 +672,31 @@ discard block |
||
672 | 672 | return; |
673 | 673 | } |
674 | 674 | $html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>'; |
675 | - } // End If Statement |
|
676 | - // Quiz |
|
675 | + } // End If Statement |
|
676 | + // Quiz |
|
677 | 677 | if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) { |
678 | 678 | $lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) ); |
679 | 679 | if( ! $lesson_id ) { |
680 | 680 | return; |
681 | 681 | } |
682 | 682 | $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>'; |
683 | - } // End If Statement |
|
683 | + } // End If Statement |
|
684 | 684 | |
685 | - // Allow other plugins to filter html |
|
686 | - $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
687 | - $html .= '</section>'; |
|
685 | + // Allow other plugins to filter html |
|
686 | + $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
687 | + $html .= '</section>'; |
|
688 | 688 | |
689 | - echo $html; |
|
689 | + echo $html; |
|
690 | 690 | } // End sensei_breadcrumb() |
691 | 691 | |
692 | 692 | |
693 | - /** |
|
694 | - * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead |
|
695 | - */ |
|
693 | + /** |
|
694 | + * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead |
|
695 | + */ |
|
696 | 696 | public function sensei_lesson_course_signup_link( ) { |
697 | 697 | |
698 | - _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
699 | - WooThemes_Sensei_Lesson::course_signup_link(); |
|
698 | + _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
699 | + WooThemes_Sensei_Lesson::course_signup_link(); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | public function lesson_tags_display( $lesson_id = 0 ) { |
@@ -715,27 +715,27 @@ discard block |
||
715 | 715 | ?><section class="lesson-tags"> |
716 | 716 | <?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?> |
717 | 717 | </section><?php |
718 | - } |
|
719 | - } |
|
718 | + } |
|
719 | + } |
|
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | - /** |
|
724 | - * @param WP_Query $query |
|
725 | - */ |
|
723 | + /** |
|
724 | + * @param WP_Query $query |
|
725 | + */ |
|
726 | 726 | public function lesson_tag_archive_filter( $query ) { |
727 | - if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
728 | - // Limit to lessons only |
|
729 | - $query->set( 'post_type', 'lesson' ); |
|
727 | + if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
728 | + // Limit to lessons only |
|
729 | + $query->set( 'post_type', 'lesson' ); |
|
730 | 730 | |
731 | - // Set order of lessons |
|
732 | - $query->set( 'orderby', 'menu_order' ); |
|
733 | - $query->set( 'order', 'ASC' ); |
|
731 | + // Set order of lessons |
|
732 | + $query->set( 'orderby', 'menu_order' ); |
|
733 | + $query->set( 'order', 'ASC' ); |
|
734 | 734 | |
735 | - } |
|
736 | - } |
|
735 | + } |
|
736 | + } |
|
737 | 737 | |
738 | - public function lesson_tag_archive_header( $title ) { |
|
738 | + public function lesson_tag_archive_header( $title ) { |
|
739 | 739 | if( is_tax( 'lesson-tag' ) ) { |
740 | 740 | $title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) ); |
741 | 741 | } |
@@ -757,13 +757,13 @@ discard block |
||
757 | 757 | $sanitized_submit = esc_html( $_POST['quiz_action'] ); |
758 | 758 | |
759 | 759 | switch ($sanitized_submit) { |
760 | - case 'lesson-complete': |
|
760 | + case 'lesson-complete': |
|
761 | 761 | |
762 | 762 | Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true ); |
763 | 763 | |
764 | 764 | break; |
765 | 765 | |
766 | - case 'lesson-reset': |
|
766 | + case 'lesson-reset': |
|
767 | 767 | |
768 | 768 | Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID ); |
769 | 769 | |
@@ -875,13 +875,13 @@ discard block |
||
875 | 875 | if ( 0 < intval( $post_id ) ) { |
876 | 876 | $lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true ); |
877 | 877 | if ( 'http' == substr( $lesson_video_embed, 0, 4) ) { |
878 | - // V2 - make width and height a setting for video embed |
|
879 | - $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
880 | - } // End If Statement |
|
881 | - if ( '' != $lesson_video_embed ) { |
|
882 | - ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
|
883 | - } // End If Statement |
|
884 | - } // End If Statement |
|
878 | + // V2 - make width and height a setting for video embed |
|
879 | + $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
880 | + } // End If Statement |
|
881 | + if ( '' != $lesson_video_embed ) { |
|
882 | + ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
|
883 | + } // End If Statement |
|
884 | + } // End If Statement |
|
885 | 885 | } // End sensei_lesson_video() |
886 | 886 | |
887 | 887 | public function sensei_complete_lesson_button() { |
@@ -894,8 +894,8 @@ discard block |
||
894 | 894 | $pass_required = true; |
895 | 895 | if( $quiz_id ) { |
896 | 896 | // Get quiz pass setting |
897 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
898 | - } |
|
897 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
898 | + } |
|
899 | 899 | if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) { |
900 | 900 | ?> |
901 | 901 | <form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
@@ -948,12 +948,12 @@ discard block |
||
948 | 948 | } // End If Statement |
949 | 949 | } // End sensei_reset_lesson_button() |
950 | 950 | |
951 | - /** |
|
952 | - * @deprecated since 1.9.0 |
|
953 | - */ |
|
954 | - public function sensei_lesson_quiz_meta( ) { |
|
951 | + /** |
|
952 | + * @deprecated since 1.9.0 |
|
953 | + */ |
|
954 | + public function sensei_lesson_quiz_meta( ) { |
|
955 | 955 | |
956 | - Sensei_Lesson::footer_quiz_call_to_action(); |
|
956 | + Sensei_Lesson::footer_quiz_call_to_action(); |
|
957 | 957 | |
958 | 958 | } // End sensei_lesson_quiz_meta() |
959 | 959 | |
@@ -979,38 +979,38 @@ discard block |
||
979 | 979 | </p> |
980 | 980 | <p class="course-excerpt"><?php the_excerpt(); ?></p> |
981 | 981 | <?php if ( 0 < $free_lesson_count ) { |
982 | - $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
982 | + $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
983 | 983 | <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p> |
984 | 984 | <?php } ?> |
985 | 985 | </section><?php |
986 | 986 | } // End sensei_course_archive_meta() |
987 | 987 | |
988 | - /** |
|
989 | - * @deprecated since 1.9.0 |
|
990 | - */ |
|
988 | + /** |
|
989 | + * @deprecated since 1.9.0 |
|
990 | + */ |
|
991 | 991 | public function sensei_single_main_content() { |
992 | - _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0'); |
|
992 | + _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0'); |
|
993 | 993 | } // End sensei_single_main_content() |
994 | 994 | |
995 | - /** |
|
996 | - * @deprecated since 1.9.0 |
|
997 | - */ |
|
995 | + /** |
|
996 | + * @deprecated since 1.9.0 |
|
997 | + */ |
|
998 | 998 | public function sensei_lesson_archive_main_content() { |
999 | - _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly'); |
|
999 | + _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly'); |
|
1000 | 1000 | } // End sensei_lesson_archive_main_content() |
1001 | 1001 | |
1002 | - /** |
|
1003 | - * @deprecated since 1.9.0 |
|
1004 | - */ |
|
1002 | + /** |
|
1003 | + * @deprecated since 1.9.0 |
|
1004 | + */ |
|
1005 | 1005 | public function sensei_message_archive_main_content() { |
1006 | 1006 | _deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' ); |
1007 | 1007 | } // End sensei_lesson_archive_main_content() |
1008 | 1008 | |
1009 | - /** |
|
1010 | - * @deprecated since 1.9.0 |
|
1011 | - */ |
|
1009 | + /** |
|
1010 | + * @deprecated since 1.9.0 |
|
1011 | + */ |
|
1012 | 1012 | public function sensei_no_permissions_main_content() { |
1013 | - _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
1013 | + _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
1014 | 1014 | } // End sensei_no_permissions_main_content() |
1015 | 1015 | |
1016 | 1016 | public function sensei_course_category_main_content() { |
@@ -1058,7 +1058,7 @@ discard block |
||
1058 | 1058 | <div class="col-1"> |
1059 | 1059 | <?php |
1060 | 1060 | // output the actual form markup |
1061 | - Sensei_Templates::get_template( 'user/login-form.php'); |
|
1061 | + Sensei_Templates::get_template( 'user/login-form.php'); |
|
1062 | 1062 | ?> |
1063 | 1063 | </div> |
1064 | 1064 | |
@@ -1139,12 +1139,12 @@ discard block |
||
1139 | 1139 | |
1140 | 1140 | //if this is a paid course |
1141 | 1141 | if ( Sensei_WC::is_woocommerce_active() ) { |
1142 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
1143 | - if ( 0 < $wc_post_id ) { |
|
1144 | - $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
1145 | - } // End If Statement |
|
1146 | - } |
|
1147 | - return $preview_text; |
|
1142 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
1143 | + if ( 0 < $wc_post_id ) { |
|
1144 | + $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
1145 | + } // End If Statement |
|
1146 | + } |
|
1147 | + return $preview_text; |
|
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | public function sensei_lesson_preview_title( $title = '', $id = 0 ) { |
@@ -1176,8 +1176,8 @@ discard block |
||
1176 | 1176 | $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
1177 | 1177 | // Handle user starting the course |
1178 | 1178 | if ( isset( $_POST['course_start'] ) |
1179 | - && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
1180 | - && !$is_user_taking_course ) { |
|
1179 | + && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
1180 | + && !$is_user_taking_course ) { |
|
1181 | 1181 | |
1182 | 1182 | // Start the course |
1183 | 1183 | $activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID ); |
@@ -1196,35 +1196,35 @@ discard block |
||
1196 | 1196 | } // End If Statement |
1197 | 1197 | } // End sensei_course_start() |
1198 | 1198 | |
1199 | - /** |
|
1200 | - * @deprecated since 1.9.0 |
|
1201 | - */ |
|
1199 | + /** |
|
1200 | + * @deprecated since 1.9.0 |
|
1201 | + */ |
|
1202 | 1202 | public function sensei_course_meta() { |
1203 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
1204 | - Sensei()->course->the_course_meta( get_post() ); |
|
1203 | + _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
1204 | + Sensei()->course->the_course_meta( get_post() ); |
|
1205 | 1205 | } // End sensei_course_meta() |
1206 | 1206 | |
1207 | - /** |
|
1208 | - * @deprecated since 1.9.0 |
|
1209 | - */ |
|
1207 | + /** |
|
1208 | + * @deprecated since 1.9.0 |
|
1209 | + */ |
|
1210 | 1210 | public function sensei_course_meta_video() { |
1211 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
1212 | - Sensei_Course::the_course_video(); |
|
1211 | + _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
1212 | + Sensei_Course::the_course_video(); |
|
1213 | 1213 | } // End sensei_course_meta_video() |
1214 | 1214 | |
1215 | - /** |
|
1216 | - * This function shows the WooCommerce cart notice if the user has |
|
1217 | - * added the current course to cart. It does not show if the user is already taking |
|
1218 | - * the course. |
|
1219 | - * |
|
1220 | - * @since 1.0.2 |
|
1221 | - * @return void; |
|
1222 | - */ |
|
1223 | - public function sensei_woocommerce_in_cart_message() { |
|
1215 | + /** |
|
1216 | + * This function shows the WooCommerce cart notice if the user has |
|
1217 | + * added the current course to cart. It does not show if the user is already taking |
|
1218 | + * the course. |
|
1219 | + * |
|
1220 | + * @since 1.0.2 |
|
1221 | + * @return void; |
|
1222 | + */ |
|
1223 | + public function sensei_woocommerce_in_cart_message() { |
|
1224 | 1224 | global $post, $woocommerce; |
1225 | 1225 | |
1226 | 1226 | $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
1227 | - $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
1227 | + $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
1228 | 1228 | if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
1229 | 1229 | |
1230 | 1230 | if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) { |
@@ -1272,7 +1272,7 @@ discard block |
||
1272 | 1272 | $item_id = $item['product_id']; |
1273 | 1273 | } |
1274 | 1274 | |
1275 | - if ( $item_id > 0 ) { |
|
1275 | + if ( $item_id > 0 ) { |
|
1276 | 1276 | |
1277 | 1277 | $user_id = get_post_meta( $order_id, '_customer_user', true ); |
1278 | 1278 | |
@@ -1352,15 +1352,15 @@ discard block |
||
1352 | 1352 | |
1353 | 1353 | $items = $order->get_items(); |
1354 | 1354 | foreach( $items as $item ) { |
1355 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
1356 | - $item_id = $item['variation_id']; |
|
1357 | - $product_type = 'variation'; |
|
1358 | - } else { |
|
1359 | - $item_id = $item['product_id']; |
|
1360 | - } |
|
1355 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
1356 | + $item_id = $item['variation_id']; |
|
1357 | + $product_type = 'variation'; |
|
1358 | + } else { |
|
1359 | + $item_id = $item['product_id']; |
|
1360 | + } |
|
1361 | 1361 | |
1362 | - $product_ids[] = $item_id; |
|
1363 | - } |
|
1362 | + $product_ids[] = $item_id; |
|
1363 | + } |
|
1364 | 1364 | |
1365 | 1365 | $order_ids[] = $post_id; |
1366 | 1366 | } |
@@ -1468,32 +1468,32 @@ discard block |
||
1468 | 1468 | $items = $order->get_items(); |
1469 | 1469 | foreach( $items as $item ) { |
1470 | 1470 | |
1471 | - $product = wc_get_product( $item['product_id'] ); |
|
1471 | + $product = wc_get_product( $item['product_id'] ); |
|
1472 | 1472 | |
1473 | - // handle product bundles |
|
1474 | - if( is_object( $product ) && $product->is_type('bundle') ){ |
|
1473 | + // handle product bundles |
|
1474 | + if( is_object( $product ) && $product->is_type('bundle') ){ |
|
1475 | 1475 | |
1476 | - $bundled_product = new WC_Product_Bundle( $product->id ); |
|
1477 | - $bundled_items = $bundled_product->get_bundled_items(); |
|
1476 | + $bundled_product = new WC_Product_Bundle( $product->id ); |
|
1477 | + $bundled_items = $bundled_product->get_bundled_items(); |
|
1478 | 1478 | |
1479 | - foreach( $bundled_items as $bundled_item ){ |
|
1479 | + foreach( $bundled_items as $bundled_item ){ |
|
1480 | 1480 | |
1481 | - if( $bundled_item->product_id == $course_product_id ) { |
|
1482 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1483 | - return; |
|
1484 | - } |
|
1481 | + if( $bundled_item->product_id == $course_product_id ) { |
|
1482 | + Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1483 | + return; |
|
1484 | + } |
|
1485 | 1485 | |
1486 | - } |
|
1486 | + } |
|
1487 | 1487 | |
1488 | - } else { |
|
1488 | + } else { |
|
1489 | 1489 | |
1490 | - // handle regular products |
|
1491 | - if( $item['product_id'] == $course_product_id ) { |
|
1492 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1493 | - return; |
|
1494 | - } |
|
1490 | + // handle regular products |
|
1491 | + if( $item['product_id'] == $course_product_id ) { |
|
1492 | + Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1493 | + return; |
|
1494 | + } |
|
1495 | 1495 | |
1496 | - } |
|
1496 | + } |
|
1497 | 1497 | } |
1498 | 1498 | } |
1499 | 1499 | |
@@ -1524,21 +1524,21 @@ discard block |
||
1524 | 1524 | |
1525 | 1525 | //if not posted from the sensei login form let |
1526 | 1526 | // WordPress or any other party handle the failed request |
1527 | - if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
1527 | + if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
1528 | 1528 | |
1529 | - return ; |
|
1529 | + return ; |
|
1530 | 1530 | |
1531 | - } |
|
1531 | + } |
|
1532 | 1532 | |
1533 | - // Get the reffering page, where did the post submission come from? |
|
1534 | - $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
|
1533 | + // Get the reffering page, where did the post submission come from? |
|
1534 | + $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
|
1535 | 1535 | |
1536 | 1536 | // if there's a valid referrer, and it's not the default log-in screen |
1537 | - if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
1538 | - // let's append some information (login=failed) to the URL for the theme to use |
|
1539 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1540 | - exit; |
|
1541 | - } |
|
1537 | + if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
1538 | + // let's append some information (login=failed) to the URL for the theme to use |
|
1539 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1540 | + exit; |
|
1541 | + } |
|
1542 | 1542 | }// End sensei_login_fail_redirect_to_front_end_login |
1543 | 1543 | |
1544 | 1544 | /** |
@@ -1549,46 +1549,46 @@ discard block |
||
1549 | 1549 | function sensei_handle_login_request( ) { |
1550 | 1550 | |
1551 | 1551 | // Check that it is a sensei login request and if it has a valid nonce |
1552 | - if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
1552 | + if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
1553 | 1553 | |
1554 | - // Validate the login request nonce |
|
1555 | - if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
1556 | - return; |
|
1557 | - } |
|
1554 | + // Validate the login request nonce |
|
1555 | + if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
1556 | + return; |
|
1557 | + } |
|
1558 | 1558 | |
1559 | - //get the page where the sensei log form is located |
|
1560 | - $referrer = $_REQUEST['_wp_http_referer']; |
|
1561 | - //$redirect = $_REQUEST['_sensei_redirect']; |
|
1559 | + //get the page where the sensei log form is located |
|
1560 | + $referrer = $_REQUEST['_wp_http_referer']; |
|
1561 | + //$redirect = $_REQUEST['_sensei_redirect']; |
|
1562 | 1562 | |
1563 | - if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
1564 | - && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
1563 | + if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
1564 | + && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
1565 | 1565 | |
1566 | - // when the user has entered a password or username do the sensei login |
|
1567 | - $creds = array(); |
|
1566 | + // when the user has entered a password or username do the sensei login |
|
1567 | + $creds = array(); |
|
1568 | 1568 | |
1569 | - // check if the requests login is an email address |
|
1570 | - if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
1571 | - // query wordpress for the users details |
|
1572 | - $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
1569 | + // check if the requests login is an email address |
|
1570 | + if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
1571 | + // query wordpress for the users details |
|
1572 | + $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
1573 | 1573 | |
1574 | - // validate the user object |
|
1575 | - if( !$user ){ |
|
1574 | + // validate the user object |
|
1575 | + if( !$user ){ |
|
1576 | 1576 | |
1577 | - // the email doesnt exist |
|
1578 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1579 | - exit; |
|
1577 | + // the email doesnt exist |
|
1578 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1579 | + exit; |
|
1580 | 1580 | |
1581 | - } |
|
1581 | + } |
|
1582 | 1582 | |
1583 | - //assigne the username to the creds array for further processing |
|
1584 | - $creds['user_login'] = $user->user_login ; |
|
1583 | + //assigne the username to the creds array for further processing |
|
1584 | + $creds['user_login'] = $user->user_login ; |
|
1585 | 1585 | |
1586 | - }else{ |
|
1586 | + }else{ |
|
1587 | 1587 | |
1588 | - // process this as a default username login |
|
1589 | - $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
1588 | + // process this as a default username login |
|
1589 | + $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
1590 | 1590 | |
1591 | - } |
|
1591 | + } |
|
1592 | 1592 | |
1593 | 1593 | // get setup the rest of the creds array |
1594 | 1594 | $creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] ); |
@@ -1598,42 +1598,42 @@ discard block |
||
1598 | 1598 | $user = wp_signon( $creds, false ); |
1599 | 1599 | |
1600 | 1600 | if ( is_wp_error($user) ){ // on login failure |
1601 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1602 | - exit; |
|
1601 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1602 | + exit; |
|
1603 | 1603 | }else{ // on login success |
1604 | 1604 | |
1605 | 1605 | /** |
1606 | - * change the redirect url programatically |
|
1607 | - * |
|
1608 | - * @since 1.6.1 |
|
1609 | - * |
|
1610 | - * @param string $referrer the page where the current url wheresensei login form was posted from |
|
1611 | - */ |
|
1606 | + * change the redirect url programatically |
|
1607 | + * |
|
1608 | + * @since 1.6.1 |
|
1609 | + * |
|
1610 | + * @param string $referrer the page where the current url wheresensei login form was posted from |
|
1611 | + */ |
|
1612 | 1612 | |
1613 | 1613 | $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) ); |
1614 | 1614 | |
1615 | 1615 | wp_redirect( esc_url_raw( $success_redirect_url ) ); |
1616 | - exit; |
|
1616 | + exit; |
|
1617 | 1617 | |
1618 | 1618 | } // end is_wp_error($user) |
1619 | 1619 | |
1620 | - }else{ // if username or password is empty |
|
1620 | + }else{ // if username or password is empty |
|
1621 | 1621 | |
1622 | - wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
1623 | - exit; |
|
1622 | + wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
1623 | + exit; |
|
1624 | 1624 | |
1625 | - } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
|
1625 | + } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
|
1626 | 1626 | |
1627 | - }elseif( ( isset( $_GET['login'] ) ) ) { |
|
1628 | - // else if this request is a redircect from a previously faile login request |
|
1629 | - $this->login_message_process(); |
|
1627 | + }elseif( ( isset( $_GET['login'] ) ) ) { |
|
1628 | + // else if this request is a redircect from a previously faile login request |
|
1629 | + $this->login_message_process(); |
|
1630 | 1630 | |
1631 | 1631 | //exit the handle login request function |
1632 | 1632 | return; |
1633 | - } |
|
1633 | + } |
|
1634 | 1634 | |
1635 | - // if none of the above |
|
1636 | - return; |
|
1635 | + // if none of the above |
|
1636 | + return; |
|
1637 | 1637 | |
1638 | 1638 | } // End sensei_login_fail_redirect_to_front_end_login |
1639 | 1639 | |
@@ -1736,7 +1736,7 @@ discard block |
||
1736 | 1736 | */ |
1737 | 1737 | public function login_message_process(){ |
1738 | 1738 | |
1739 | - // setup the message variables |
|
1739 | + // setup the message variables |
|
1740 | 1740 | $message = ''; |
1741 | 1741 | |
1742 | 1742 | //only output message if the url contains login=failed and login=emptyfields |
@@ -1755,22 +1755,22 @@ discard block |
||
1755 | 1755 | }// end login_message_process |
1756 | 1756 | |
1757 | 1757 | |
1758 | - /** |
|
1759 | - * sensei_show_admin_bar(). Use WooCommerce filter |
|
1760 | - * to show admin bar to Teachers as well. |
|
1761 | - * |
|
1762 | - * @return void redirect |
|
1763 | - * |
|
1764 | - */ |
|
1765 | - public function sensei_show_admin_bar () { |
|
1758 | + /** |
|
1759 | + * sensei_show_admin_bar(). Use WooCommerce filter |
|
1760 | + * to show admin bar to Teachers as well. |
|
1761 | + * |
|
1762 | + * @return void redirect |
|
1763 | + * |
|
1764 | + */ |
|
1765 | + public function sensei_show_admin_bar () { |
|
1766 | 1766 | |
1767 | - if (current_user_can('edit_courses')) { |
|
1767 | + if (current_user_can('edit_courses')) { |
|
1768 | 1768 | |
1769 | - add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
1769 | + add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
1770 | 1770 | |
1771 | - } |
|
1771 | + } |
|
1772 | 1772 | |
1773 | - } |
|
1773 | + } |
|
1774 | 1774 | |
1775 | 1775 | } // End Class |
1776 | 1776 |
@@ -16,25 +16,25 @@ discard block |
||
16 | 16 | public $slider_labels; |
17 | 17 | public $role_caps; |
18 | 18 | |
19 | - /** |
|
20 | - * @var Sensei_Course |
|
21 | - */ |
|
22 | - public $course; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Sensei_Lesson |
|
26 | - */ |
|
27 | - public $lesson; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var Sensei_Question |
|
31 | - */ |
|
32 | - public $question; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Sensei_Quiz |
|
36 | - */ |
|
37 | - public $quiz; |
|
19 | + /** |
|
20 | + * @var Sensei_Course |
|
21 | + */ |
|
22 | + public $course; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Sensei_Lesson |
|
26 | + */ |
|
27 | + public $lesson; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var Sensei_Question |
|
31 | + */ |
|
32 | + public $question; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Sensei_Quiz |
|
36 | + */ |
|
37 | + public $quiz; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Constructor |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | // Setup Post Types |
46 | 46 | $this->labels = array(); |
47 | - $this->token = 'woothemes-sensei-posttypes'; |
|
47 | + $this->token = 'woothemes-sensei-posttypes'; |
|
48 | 48 | |
49 | 49 | $this->setup_post_type_labels_base(); |
50 | 50 | add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
@@ -103,94 +103,94 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * Setup the "course" post type, it's admin menu item and the appropriate labels and permissions. |
105 | 105 | * @since 1.0.0 |
106 | - * @uses Sensei() |
|
106 | + * @uses Sensei() |
|
107 | 107 | * @return void |
108 | 108 | */ |
109 | 109 | public function setup_course_post_type () { |
110 | 110 | |
111 | 111 | $args = array( |
112 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
113 | - 'public' => true, |
|
114 | - 'publicly_queryable' => true, |
|
115 | - 'show_ui' => true, |
|
116 | - 'show_in_menu' => true, |
|
117 | - 'show_in_admin_bar' => true, |
|
118 | - 'query_var' => true, |
|
119 | - 'rewrite' => array( |
|
120 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
121 | - 'with_front' => true, |
|
122 | - 'feeds' => true, |
|
123 | - 'pages' => true |
|
124 | - ), |
|
125 | - 'map_meta_cap' => true, |
|
126 | - 'capability_type' => 'course', |
|
127 | - 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
128 | - 'hierarchical' => false, |
|
129 | - 'menu_position' => 51, |
|
130 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
112 | + 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
113 | + 'public' => true, |
|
114 | + 'publicly_queryable' => true, |
|
115 | + 'show_ui' => true, |
|
116 | + 'show_in_menu' => true, |
|
117 | + 'show_in_admin_bar' => true, |
|
118 | + 'query_var' => true, |
|
119 | + 'rewrite' => array( |
|
120 | + 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
121 | + 'with_front' => true, |
|
122 | + 'feeds' => true, |
|
123 | + 'pages' => true |
|
124 | + ), |
|
125 | + 'map_meta_cap' => true, |
|
126 | + 'capability_type' => 'course', |
|
127 | + 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
128 | + 'hierarchical' => false, |
|
129 | + 'menu_position' => 51, |
|
130 | + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
131 | 131 | ); |
132 | 132 | |
133 | - /** |
|
134 | - * Filter the arguments passed in when registering the Sensei Course post type. |
|
135 | - * |
|
136 | - * @since 1.9.0 |
|
137 | - * @param array $args |
|
138 | - */ |
|
133 | + /** |
|
134 | + * Filter the arguments passed in when registering the Sensei Course post type. |
|
135 | + * |
|
136 | + * @since 1.9.0 |
|
137 | + * @param array $args |
|
138 | + */ |
|
139 | 139 | register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
140 | 140 | |
141 | 141 | } // End setup_course_post_type() |
142 | 142 | |
143 | - /** |
|
144 | - * Figure out of the course post type has an archive and what it should be. |
|
145 | - * |
|
146 | - * This function should return 'courses' or the page_uri for the course page setting. |
|
147 | - * |
|
148 | - * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
149 | - * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
150 | - * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
151 | - * |
|
152 | - * |
|
153 | - * @sine 1.9.0 |
|
154 | - * |
|
155 | - * |
|
156 | - * @return false|string |
|
157 | - */ |
|
158 | - public function get_course_post_type_archive_slug(){ |
|
143 | + /** |
|
144 | + * Figure out of the course post type has an archive and what it should be. |
|
145 | + * |
|
146 | + * This function should return 'courses' or the page_uri for the course page setting. |
|
147 | + * |
|
148 | + * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
149 | + * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
150 | + * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
151 | + * |
|
152 | + * |
|
153 | + * @sine 1.9.0 |
|
154 | + * |
|
155 | + * |
|
156 | + * @return false|string |
|
157 | + */ |
|
158 | + public function get_course_post_type_archive_slug(){ |
|
159 | 159 | |
160 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
160 | + $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
161 | 161 | |
162 | - // for a valid post that doesn't have any of the old short codes set the archive the same |
|
163 | - // as the page URI |
|
164 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
162 | + // for a valid post that doesn't have any of the old short codes set the archive the same |
|
163 | + // as the page URI |
|
164 | + if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
165 | 165 | |
166 | - return get_page_uri( $settings_course_page->ID ); |
|
166 | + return get_page_uri( $settings_course_page->ID ); |
|
167 | 167 | |
168 | - }else{ |
|
168 | + }else{ |
|
169 | 169 | |
170 | - return 'courses'; |
|
170 | + return 'courses'; |
|
171 | 171 | |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | - }// end course_post_type_determine_archive |
|
174 | + }// end course_post_type_determine_archive |
|
175 | 175 | |
176 | - /** |
|
177 | - * Check if given content has any of these old shortcodes: |
|
178 | - * [newcourses][featuredcourses][freecourses][paidcourses] |
|
179 | - * |
|
180 | - * @since 1.9.0 |
|
181 | - * |
|
182 | - * @param string $content |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function has_old_shortcodes( $content ){ |
|
176 | + /** |
|
177 | + * Check if given content has any of these old shortcodes: |
|
178 | + * [newcourses][featuredcourses][freecourses][paidcourses] |
|
179 | + * |
|
180 | + * @since 1.9.0 |
|
181 | + * |
|
182 | + * @param string $content |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function has_old_shortcodes( $content ){ |
|
187 | 187 | |
188 | - return ( has_shortcode( $content, 'newcourses') |
|
189 | - || has_shortcode( $content, 'featuredcourses') |
|
190 | - || has_shortcode( $content, 'freecourses') |
|
191 | - || has_shortcode( $content, 'paidcourses') ); |
|
188 | + return ( has_shortcode( $content, 'newcourses') |
|
189 | + || has_shortcode( $content, 'featuredcourses') |
|
190 | + || has_shortcode( $content, 'freecourses') |
|
191 | + || has_shortcode( $content, 'paidcourses') ); |
|
192 | 192 | |
193 | - }// end has old shortcodes |
|
193 | + }// end has old shortcodes |
|
194 | 194 | |
195 | 195 | |
196 | 196 | /** |
@@ -211,32 +211,32 @@ discard block |
||
211 | 211 | } // End If Statement |
212 | 212 | |
213 | 213 | $args = array( |
214 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
215 | - 'public' => true, |
|
216 | - 'publicly_queryable' => true, |
|
217 | - 'show_ui' => true, |
|
218 | - 'show_in_menu' => true, |
|
219 | - 'query_var' => true, |
|
220 | - 'rewrite' => array( |
|
221 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
222 | - 'with_front' => true, |
|
223 | - 'feeds' => true, |
|
224 | - 'pages' => true |
|
225 | - ), |
|
226 | - 'map_meta_cap' => true, |
|
227 | - 'capability_type' => 'lesson', |
|
228 | - 'has_archive' => true, |
|
229 | - 'hierarchical' => false, |
|
230 | - 'menu_position' => 52, |
|
231 | - 'supports' => $supports_array |
|
214 | + 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
215 | + 'public' => true, |
|
216 | + 'publicly_queryable' => true, |
|
217 | + 'show_ui' => true, |
|
218 | + 'show_in_menu' => true, |
|
219 | + 'query_var' => true, |
|
220 | + 'rewrite' => array( |
|
221 | + 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
222 | + 'with_front' => true, |
|
223 | + 'feeds' => true, |
|
224 | + 'pages' => true |
|
225 | + ), |
|
226 | + 'map_meta_cap' => true, |
|
227 | + 'capability_type' => 'lesson', |
|
228 | + 'has_archive' => true, |
|
229 | + 'hierarchical' => false, |
|
230 | + 'menu_position' => 52, |
|
231 | + 'supports' => $supports_array |
|
232 | 232 | ); |
233 | 233 | |
234 | - /** |
|
235 | - * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
236 | - * |
|
237 | - * @since 1.9.0 |
|
238 | - * @param array $args |
|
239 | - */ |
|
234 | + /** |
|
235 | + * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
236 | + * |
|
237 | + * @since 1.9.0 |
|
238 | + * @param array $args |
|
239 | + */ |
|
240 | 240 | register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
241 | 241 | |
242 | 242 | } // End setup_lesson_post_type() |
@@ -244,44 +244,44 @@ discard block |
||
244 | 244 | /** |
245 | 245 | * Setup the "quiz" post type, it's admin menu item and the appropriate labels and permissions. |
246 | 246 | * @since 1.0.0 |
247 | - * @uses Sensei() |
|
247 | + * @uses Sensei() |
|
248 | 248 | * @return void |
249 | 249 | */ |
250 | 250 | public function setup_quiz_post_type () { |
251 | 251 | |
252 | 252 | $args = array( |
253 | - 'labels' => $this->create_post_type_labels( |
|
254 | - $this->labels['quiz']['singular'], |
|
255 | - $this->labels['quiz']['plural'], |
|
256 | - $this->labels['quiz']['menu'] |
|
257 | - ), |
|
258 | - 'public' => true, |
|
259 | - 'publicly_queryable' => true, |
|
260 | - 'show_ui' => true, |
|
261 | - 'show_in_menu' => false, |
|
262 | - 'show_in_nav_menus' => false, |
|
263 | - 'query_var' => true, |
|
264 | - 'exclude_from_search' => true, |
|
265 | - 'rewrite' => array( |
|
266 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
267 | - 'with_front' => true, |
|
268 | - 'feeds' => true, |
|
269 | - 'pages' => true |
|
270 | - ), |
|
271 | - 'map_meta_cap' => true, |
|
272 | - 'capability_type' => 'quiz', |
|
273 | - 'has_archive' => false, |
|
274 | - 'hierarchical' => false, |
|
275 | - 'menu_position' => 20, // Below "Pages" |
|
276 | - 'supports' => array( '' ) |
|
253 | + 'labels' => $this->create_post_type_labels( |
|
254 | + $this->labels['quiz']['singular'], |
|
255 | + $this->labels['quiz']['plural'], |
|
256 | + $this->labels['quiz']['menu'] |
|
257 | + ), |
|
258 | + 'public' => true, |
|
259 | + 'publicly_queryable' => true, |
|
260 | + 'show_ui' => true, |
|
261 | + 'show_in_menu' => false, |
|
262 | + 'show_in_nav_menus' => false, |
|
263 | + 'query_var' => true, |
|
264 | + 'exclude_from_search' => true, |
|
265 | + 'rewrite' => array( |
|
266 | + 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
267 | + 'with_front' => true, |
|
268 | + 'feeds' => true, |
|
269 | + 'pages' => true |
|
270 | + ), |
|
271 | + 'map_meta_cap' => true, |
|
272 | + 'capability_type' => 'quiz', |
|
273 | + 'has_archive' => false, |
|
274 | + 'hierarchical' => false, |
|
275 | + 'menu_position' => 20, // Below "Pages" |
|
276 | + 'supports' => array( '' ) |
|
277 | 277 | ); |
278 | 278 | |
279 | - /** |
|
280 | - * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
281 | - * |
|
282 | - * @since 1.9.0 |
|
283 | - * @param array $args |
|
284 | - */ |
|
279 | + /** |
|
280 | + * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
281 | + * |
|
282 | + * @since 1.9.0 |
|
283 | + * @param array $args |
|
284 | + */ |
|
285 | 285 | register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
286 | 286 | |
287 | 287 | } // End setup_quiz_post_type() |
@@ -295,34 +295,34 @@ discard block |
||
295 | 295 | public function setup_question_post_type () { |
296 | 296 | |
297 | 297 | $args = array( |
298 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
299 | - 'public' => false, |
|
300 | - 'publicly_queryable' => true, |
|
301 | - 'show_ui' => true, |
|
302 | - 'show_in_menu' => true, |
|
303 | - 'show_in_nav_menus' => false, |
|
304 | - 'query_var' => true, |
|
305 | - 'exclude_from_search' => true, |
|
306 | - 'rewrite' => array( |
|
307 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
308 | - 'with_front' => true, |
|
309 | - 'feeds' => true, |
|
310 | - 'pages' => true |
|
311 | - ), |
|
312 | - 'map_meta_cap' => true, |
|
313 | - 'capability_type' => 'question', |
|
314 | - 'has_archive' => true, |
|
315 | - 'hierarchical' => false, |
|
316 | - 'menu_position' => 51, |
|
317 | - 'supports' => array( 'title' ) |
|
298 | + 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
299 | + 'public' => false, |
|
300 | + 'publicly_queryable' => true, |
|
301 | + 'show_ui' => true, |
|
302 | + 'show_in_menu' => true, |
|
303 | + 'show_in_nav_menus' => false, |
|
304 | + 'query_var' => true, |
|
305 | + 'exclude_from_search' => true, |
|
306 | + 'rewrite' => array( |
|
307 | + 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
308 | + 'with_front' => true, |
|
309 | + 'feeds' => true, |
|
310 | + 'pages' => true |
|
311 | + ), |
|
312 | + 'map_meta_cap' => true, |
|
313 | + 'capability_type' => 'question', |
|
314 | + 'has_archive' => true, |
|
315 | + 'hierarchical' => false, |
|
316 | + 'menu_position' => 51, |
|
317 | + 'supports' => array( 'title' ) |
|
318 | 318 | ); |
319 | 319 | |
320 | - /** |
|
321 | - * Filter the arguments passed in when registering the Sensei Question post type. |
|
322 | - * |
|
323 | - * @since 1.9.0 |
|
324 | - * @param array $args |
|
325 | - */ |
|
320 | + /** |
|
321 | + * Filter the arguments passed in when registering the Sensei Question post type. |
|
322 | + * |
|
323 | + * @since 1.9.0 |
|
324 | + * @param array $args |
|
325 | + */ |
|
326 | 326 | register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
327 | 327 | |
328 | 328 | } // End setup_question_post_type() |
@@ -335,26 +335,26 @@ discard block |
||
335 | 335 | public function setup_multiple_question_post_type () { |
336 | 336 | |
337 | 337 | $args = array( |
338 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
339 | - 'public' => false, |
|
340 | - 'publicly_queryable' => false, |
|
341 | - 'show_ui' => false, |
|
342 | - 'show_in_menu' => false, |
|
343 | - 'show_in_nav_menus' => false, |
|
344 | - 'query_var' => false, |
|
345 | - 'exclude_from_search' => true, |
|
346 | - 'rewrite' => array( |
|
347 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
348 | - 'with_front' => false, |
|
349 | - 'feeds' => false, |
|
350 | - 'pages' => false |
|
351 | - ), |
|
352 | - 'map_meta_cap' => true, |
|
353 | - 'capability_type' => 'question', |
|
354 | - 'has_archive' => false, |
|
355 | - 'hierarchical' => false, |
|
356 | - 'menu_position' => 51, |
|
357 | - 'supports' => array( 'title', 'custom-fields' ) |
|
338 | + 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
339 | + 'public' => false, |
|
340 | + 'publicly_queryable' => false, |
|
341 | + 'show_ui' => false, |
|
342 | + 'show_in_menu' => false, |
|
343 | + 'show_in_nav_menus' => false, |
|
344 | + 'query_var' => false, |
|
345 | + 'exclude_from_search' => true, |
|
346 | + 'rewrite' => array( |
|
347 | + 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
348 | + 'with_front' => false, |
|
349 | + 'feeds' => false, |
|
350 | + 'pages' => false |
|
351 | + ), |
|
352 | + 'map_meta_cap' => true, |
|
353 | + 'capability_type' => 'question', |
|
354 | + 'has_archive' => false, |
|
355 | + 'hierarchical' => false, |
|
356 | + 'menu_position' => 51, |
|
357 | + 'supports' => array( 'title', 'custom-fields' ) |
|
358 | 358 | ); |
359 | 359 | |
360 | 360 | register_post_type( 'multiple_question', $args ); |
@@ -370,34 +370,34 @@ discard block |
||
370 | 370 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
371 | 371 | |
372 | 372 | $args = array( |
373 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
374 | - 'public' => true, |
|
375 | - 'publicly_queryable' => true, |
|
376 | - 'show_ui' => true, |
|
377 | - 'show_in_menu' => 'admin.php?page=sensei', |
|
378 | - 'show_in_nav_menus' => true, |
|
379 | - 'query_var' => true, |
|
380 | - 'exclude_from_search' => true, |
|
381 | - 'rewrite' => array( |
|
382 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
383 | - 'with_front' => false, |
|
384 | - 'feeds' => false, |
|
385 | - 'pages' => true |
|
386 | - ), |
|
387 | - 'map_meta_cap' => true, |
|
388 | - 'capability_type' => 'question', |
|
389 | - 'has_archive' => true, |
|
390 | - 'hierarchical' => false, |
|
391 | - 'menu_position' => 50, |
|
392 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
373 | + 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
374 | + 'public' => true, |
|
375 | + 'publicly_queryable' => true, |
|
376 | + 'show_ui' => true, |
|
377 | + 'show_in_menu' => 'admin.php?page=sensei', |
|
378 | + 'show_in_nav_menus' => true, |
|
379 | + 'query_var' => true, |
|
380 | + 'exclude_from_search' => true, |
|
381 | + 'rewrite' => array( |
|
382 | + 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
383 | + 'with_front' => false, |
|
384 | + 'feeds' => false, |
|
385 | + 'pages' => true |
|
386 | + ), |
|
387 | + 'map_meta_cap' => true, |
|
388 | + 'capability_type' => 'question', |
|
389 | + 'has_archive' => true, |
|
390 | + 'hierarchical' => false, |
|
391 | + 'menu_position' => 50, |
|
392 | + 'supports' => array( 'title', 'editor', 'comments' ), |
|
393 | 393 | ); |
394 | 394 | |
395 | - /** |
|
396 | - * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
397 | - * |
|
398 | - * @since 1.9.0 |
|
399 | - * @param array $args |
|
400 | - */ |
|
395 | + /** |
|
396 | + * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
397 | + * |
|
398 | + * @since 1.9.0 |
|
399 | + * @param array $args |
|
400 | + */ |
|
401 | 401 | register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
402 | 402 | } |
403 | 403 | } // End setup_sensei_message_post_type() |
@@ -430,11 +430,11 @@ discard block |
||
430 | 430 | 'show_ui' => true, |
431 | 431 | 'query_var' => true, |
432 | 432 | 'show_in_nav_menus' => true, |
433 | - 'capabilities' => array( |
|
434 | - 'manage_terms' => 'manage_categories', |
|
435 | - 'edit_terms' => 'edit_courses', |
|
436 | - 'delete_terms' => 'manage_categories', |
|
437 | - 'assign_terms' => 'edit_courses',), |
|
433 | + 'capabilities' => array( |
|
434 | + 'manage_terms' => 'manage_categories', |
|
435 | + 'edit_terms' => 'edit_courses', |
|
436 | + 'delete_terms' => 'manage_categories', |
|
437 | + 'assign_terms' => 'edit_courses',), |
|
438 | 438 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
439 | 439 | ); |
440 | 440 | |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | 'show_ui' => true, /* TO DO - future releases */ |
472 | 472 | 'query_var' => true, |
473 | 473 | 'show_in_nav_menus' => false, |
474 | - 'public' => false, |
|
474 | + 'public' => false, |
|
475 | 475 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
476 | 476 | ); |
477 | 477 | |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | 'query_var' => false, |
545 | 545 | 'show_in_nav_menus' => false, |
546 | 546 | 'show_admin_column' => true, |
547 | - 'capabilities' => array( |
|
548 | - 'manage_terms' => 'manage_categories', |
|
549 | - 'edit_terms' => 'edit_questions', |
|
550 | - 'delete_terms' => 'manage_categories', |
|
551 | - 'assign_terms' => 'edit_questions',), |
|
547 | + 'capabilities' => array( |
|
548 | + 'manage_terms' => 'manage_categories', |
|
549 | + 'edit_terms' => 'edit_questions', |
|
550 | + 'delete_terms' => 'manage_categories', |
|
551 | + 'assign_terms' => 'edit_questions',), |
|
552 | 552 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
553 | 553 | ); |
554 | 554 | |
@@ -582,11 +582,11 @@ discard block |
||
582 | 582 | 'show_ui' => true, |
583 | 583 | 'query_var' => true, |
584 | 584 | 'show_in_nav_menus' => true, |
585 | - 'capabilities' => array( |
|
586 | - 'manage_terms' => 'manage_categories', |
|
587 | - 'edit_terms' => 'edit_lessons', |
|
588 | - 'delete_terms' => 'manage_categories', |
|
589 | - 'assign_terms' => 'edit_lessons',), |
|
585 | + 'capabilities' => array( |
|
586 | + 'manage_terms' => 'manage_categories', |
|
587 | + 'edit_terms' => 'edit_lessons', |
|
588 | + 'delete_terms' => 'manage_categories', |
|
589 | + 'assign_terms' => 'edit_lessons',), |
|
590 | 590 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
591 | 591 | ); |
592 | 592 | |
@@ -620,19 +620,19 @@ discard block |
||
620 | 620 | */ |
621 | 621 | private function create_post_type_labels ( $singular, $plural, $menu ) { |
622 | 622 | $labels = array( |
623 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
624 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
625 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
626 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
627 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
628 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
629 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
630 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
631 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
632 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
633 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
634 | - 'parent_item_colon' => '', |
|
635 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
623 | + 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
624 | + 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
625 | + 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
626 | + 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
627 | + 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
628 | + 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
629 | + 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
630 | + 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
631 | + 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
632 | + 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
633 | + 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
634 | + 'parent_item_colon' => '', |
|
635 | + 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
636 | 636 | ); |
637 | 637 | |
638 | 638 | return $labels; |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | * Assigns the defaults for each user role capabilities. |
706 | 706 | * |
707 | 707 | * @since 1.1.0 |
708 | - * |
|
708 | + * |
|
709 | 709 | * @param array $post_types |
710 | 710 | * @return void |
711 | 711 | */ |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | * Adds a 'Edit Quiz' link to the admin bar when viewing a Quiz linked to a corresponding Lesson |
774 | 774 | * |
775 | 775 | * @since 1.7.0 |
776 | - * @param WP_Admin_Bar $bar |
|
776 | + * @param WP_Admin_Bar $bar |
|
777 | 777 | * @return void |
778 | 778 | */ |
779 | 779 | public function quiz_admin_bar_menu( $bar ) { |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | |
79 | 79 | // Load Learners JS |
80 | 80 | wp_enqueue_script( 'sensei-learners-general', |
81 | - Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | - array('jquery','sensei-core-select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
81 | + Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | + array('jquery','sensei-core-select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
83 | 83 | |
84 | 84 | $data = array( |
85 | 85 | 'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ), |
86 | 86 | 'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ), |
87 | 87 | 'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ), |
88 | 88 | 'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ), |
89 | - 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | - 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
89 | + 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | + 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
91 | 91 | ); |
92 | 92 | |
93 | 93 | wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data ); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | /** |
187 | 187 | * learners_headers outputs Learners general headers |
188 | 188 | * @since 1.6.0 |
189 | - * @param array $args |
|
189 | + * @param array $args |
|
190 | 190 | * @return void |
191 | 191 | */ |
192 | 192 | public function learners_headers( $args = array( 'nav' => 'default' ) ) { |
@@ -252,38 +252,38 @@ discard block |
||
252 | 252 | |
253 | 253 | public function remove_user_from_post() { |
254 | 254 | |
255 | - // Parse POST data |
|
256 | - $data = sanitize_text_field( $_POST['data'] ); |
|
257 | - $action_data = array(); |
|
258 | - parse_str( $data, $action_data ); |
|
255 | + // Parse POST data |
|
256 | + $data = sanitize_text_field( $_POST['data'] ); |
|
257 | + $action_data = array(); |
|
258 | + parse_str( $data, $action_data ); |
|
259 | 259 | |
260 | 260 | // Security checks |
261 | - // ensure the current user may remove users from post |
|
262 | - // only teacher or admin can remove users |
|
261 | + // ensure the current user may remove users from post |
|
262 | + // only teacher or admin can remove users |
|
263 | 263 | |
264 | - // check the nonce, valid post |
|
264 | + // check the nonce, valid post |
|
265 | 265 | $nonce = ''; |
266 | 266 | if ( isset($_POST['remove_user_from_post_nonce']) ) { |
267 | 267 | $nonce = esc_html( $_POST['remove_user_from_post_nonce'] ); |
268 | 268 | } |
269 | - $post = get_post( intval( $action_data[ 'post_id' ] ) ); |
|
269 | + $post = get_post( intval( $action_data[ 'post_id' ] ) ); |
|
270 | 270 | |
271 | - // validate the user |
|
272 | - $may_remove_user = false; |
|
273 | - if( current_user_can('manage_sensei') |
|
274 | - || $post->post_author == get_current_user_id() ){ |
|
271 | + // validate the user |
|
272 | + $may_remove_user = false; |
|
273 | + if( current_user_can('manage_sensei') |
|
274 | + || $post->post_author == get_current_user_id() ){ |
|
275 | 275 | |
276 | - $may_remove_user = true; |
|
276 | + $may_remove_user = true; |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - if( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' ) |
|
281 | - || ! is_a( $post ,'WP_Post' ) |
|
282 | - || ! $may_remove_user ){ |
|
280 | + if( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' ) |
|
281 | + || ! is_a( $post ,'WP_Post' ) |
|
282 | + || ! $may_remove_user ){ |
|
283 | 283 | |
284 | - die(''); |
|
284 | + die(''); |
|
285 | 285 | |
286 | - } |
|
286 | + } |
|
287 | 287 | |
288 | 288 | if( $action_data['user_id'] && $action_data['post_id'] && $action_data['post_type'] ) { |
289 | 289 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | |
298 | 298 | case 'course': |
299 | 299 | |
300 | - $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
300 | + $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
301 | 301 | |
302 | 302 | break; |
303 | 303 | |
@@ -344,19 +344,19 @@ discard block |
||
344 | 344 | |
345 | 345 | if ( $users ) { |
346 | 346 | foreach ( $users as $user ) { |
347 | - $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
347 | + $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
348 | 348 | |
349 | - if( trim($user->display_name ) == trim( $full_name ) ){ |
|
349 | + if( trim($user->display_name ) == trim( $full_name ) ){ |
|
350 | 350 | |
351 | - $name = $full_name; |
|
351 | + $name = $full_name; |
|
352 | 352 | |
353 | - }else{ |
|
353 | + }else{ |
|
354 | 354 | |
355 | - $name = $full_name . ' ['. $user->display_name .']'; |
|
355 | + $name = $full_name . ' ['. $user->display_name .']'; |
|
356 | 356 | |
357 | - } |
|
357 | + } |
|
358 | 358 | |
359 | - $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
359 | + $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | break; |
401 | 401 | |
402 | 402 | case 'lesson': |
403 | - $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
403 | + $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
404 | 404 | $complete = false; |
405 | 405 | if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) { |
406 | 406 | $complete = true; |
@@ -460,23 +460,23 @@ discard block |
||
460 | 460 | } |
461 | 461 | } |
462 | 462 | |
463 | - /** |
|
464 | - * Return the full name and surname or the display name of the user. |
|
465 | - * |
|
466 | - * The user must have both name and surname otherwise display name will be returned. |
|
467 | - * |
|
468 | - * @deprecated since 1.9.0 use Se |
|
469 | - * @since 1.8.0 |
|
470 | - * |
|
471 | - * @param int $user_id | bool false for an invalid $user_id |
|
472 | - * |
|
473 | - * @return string $full_name |
|
474 | - */ |
|
475 | - public function get_learner_full_name( $user_id ){ |
|
476 | - |
|
477 | - return Sensei_Learner::get_full_name( $user_id ); |
|
478 | - |
|
479 | - } // end get_learner_full_name |
|
463 | + /** |
|
464 | + * Return the full name and surname or the display name of the user. |
|
465 | + * |
|
466 | + * The user must have both name and surname otherwise display name will be returned. |
|
467 | + * |
|
468 | + * @deprecated since 1.9.0 use Se |
|
469 | + * @since 1.8.0 |
|
470 | + * |
|
471 | + * @param int $user_id | bool false for an invalid $user_id |
|
472 | + * |
|
473 | + * @return string $full_name |
|
474 | + */ |
|
475 | + public function get_learner_full_name( $user_id ){ |
|
476 | + |
|
477 | + return Sensei_Learner::get_full_name( $user_id ); |
|
478 | + |
|
479 | + } // end get_learner_full_name |
|
480 | 480 | |
481 | 481 | } // End Class |
482 | 482 |
@@ -14,265 +14,265 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Sensei_Core_Modules |
16 | 16 | { |
17 | - private $dir; |
|
18 | - private $file; |
|
19 | - private $assets_dir; |
|
20 | - private $assets_url; |
|
21 | - private $order_page_slug; |
|
22 | - public $taxonomy; |
|
23 | - |
|
24 | - public function __construct( $file ) |
|
25 | - { |
|
26 | - $this->file = $file; |
|
27 | - $this->dir = dirname($this->file); |
|
28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
29 | - $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
30 | - $this->taxonomy = 'module'; |
|
31 | - $this->order_page_slug = 'module-order'; |
|
32 | - |
|
33 | - // setup taxonomy |
|
34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
35 | - |
|
36 | - // Manage lesson meta boxes for taxonomy |
|
37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
38 | - |
|
39 | - // Save lesson meta box |
|
40 | - add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
41 | - |
|
42 | - //Reset the none modules lessons transient |
|
43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
44 | - |
|
45 | - // Frontend styling |
|
46 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
47 | - |
|
48 | - // Admin styling |
|
49 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
51 | - |
|
52 | - // Handle module completion record |
|
53 | - add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
54 | - add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
55 | - add_action('wp', array($this, 'save_module_progress'), 10); |
|
56 | - |
|
57 | - // Handle module ordering |
|
58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
59 | - add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
60 | - add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
61 | - |
|
62 | - // Ensure modules always show under courses |
|
63 | - add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
64 | - add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
65 | - add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
66 | - |
|
67 | - // Add course field to taxonomy |
|
68 | - add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
69 | - add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
70 | - add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
71 | - add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
72 | - add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
73 | - |
|
74 | - // Manage module taxonomy archive page |
|
75 | - add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
76 | - add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
77 | - add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
78 | - add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
79 | - add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
80 | - add_filter('body_class', array($this, 'module_archive_body_class')); |
|
81 | - |
|
82 | - // add modules to the single course template |
|
83 | - add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
84 | - |
|
85 | - //Single Course modules actions. Add to single-course/course-modules.php |
|
86 | - add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
87 | - |
|
88 | - // Set up display on single lesson page |
|
89 | - add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
90 | - |
|
91 | - // Add 'Modules' columns to Analysis tables |
|
92 | - add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
93 | - add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
94 | - add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
95 | - add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
96 | - |
|
97 | - // Manage module taxonomy columns |
|
98 | - add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
99 | - add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
100 | - add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
101 | - |
|
102 | - //store new modules created on the course edit screen |
|
103 | - add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
104 | - |
|
105 | - // for non admin users, only show taxonomies that belong to them |
|
106 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
107 | - add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
108 | - |
|
109 | - // add the teacher name next to the module term in for admin users |
|
110 | - add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
111 | - |
|
112 | - // remove the default modules metabox |
|
113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
114 | - |
|
115 | - } // end constructor |
|
116 | - |
|
117 | - /** |
|
118 | - * Alter a module term slug when a new taxonomy term is created |
|
119 | - * This will add the creators user name to the slug for uniqueness. |
|
120 | - * |
|
121 | - * @since 1.8.0 |
|
122 | - * |
|
123 | - * @param $term_id |
|
124 | - * @param $tt_id |
|
125 | - * @param $taxonomy |
|
126 | - * |
|
127 | - * @return void |
|
128 | - * @deprecated since 1.9.0 |
|
129 | - */ |
|
130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
131 | - |
|
132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
133 | - |
|
134 | - }// end add_module_term_group |
|
135 | - |
|
136 | - /** |
|
137 | - * Hook in all meta boxes related tot he modules taxonomy |
|
138 | - * |
|
139 | - * @since 1.8.0 |
|
140 | - * |
|
141 | - * @param string $post_type |
|
142 | - * @param WP_Post $post |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function modules_metaboxes( $post_type, $post ) |
|
147 | - { |
|
148 | - if ('lesson' == $post_type ) { |
|
149 | - |
|
150 | - // Remove default taxonomy meta box from Lesson edit screen |
|
151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
152 | - |
|
153 | - // Add custom meta box to limit module selection to one per lesson |
|
154 | - add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
155 | - } |
|
156 | - |
|
157 | - if( 'course' == $post_type ){ |
|
158 | - // Course modules selection metabox |
|
159 | - add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Build content for custom module meta box |
|
165 | - * |
|
166 | - * @since 1.8.0 |
|
167 | - * @param object $post Current post object |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function lesson_module_metabox($post) |
|
171 | - { |
|
172 | - |
|
173 | - // Get lesson course |
|
174 | - $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
175 | - |
|
176 | - $html = ''; |
|
177 | - |
|
178 | - // Only show module selection if this lesson is part of a course |
|
179 | - if ($lesson_course && $lesson_course > 0) { |
|
180 | - |
|
181 | - // Get existing lesson module |
|
182 | - $lesson_module = 0; |
|
183 | - $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
184 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
185 | - foreach ($lesson_module_list as $single_module) { |
|
186 | - $lesson_module = $single_module->term_id; |
|
187 | - break; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - // Get the available modules for this lesson's course |
|
192 | - $modules = $this->get_course_modules($lesson_course); |
|
193 | - |
|
194 | - // Build the HTML to output |
|
195 | - $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
196 | - if (is_array($modules) && count($modules) > 0) { |
|
197 | - $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
198 | - $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
199 | - foreach ($modules as $module) { |
|
200 | - $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
201 | - } |
|
202 | - $html .= '</select>' . "\n"; |
|
203 | - } else { |
|
204 | - $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
205 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
206 | - } // End If Statement |
|
207 | - |
|
208 | - } else { |
|
209 | - $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
210 | - } // End If Statement |
|
211 | - |
|
212 | - // Output the HTML |
|
213 | - echo $html; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Save module to lesson |
|
218 | - * |
|
219 | - * @since 1.8.0 |
|
220 | - * @param integer $post_id ID of post |
|
221 | - * @return mixed Post ID on permissions failure, boolean true on success |
|
222 | - */ |
|
223 | - public function save_lesson_module($post_id) |
|
224 | - { |
|
225 | - global $post; |
|
226 | - |
|
227 | - // Verify post type and nonce |
|
228 | - if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
229 | - ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
230 | - return $post_id; |
|
231 | - } |
|
232 | - |
|
233 | - // Check if user has permissions to edit lessons |
|
234 | - $post_type = get_post_type_object($post->post_type); |
|
235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
236 | - return $post_id; |
|
237 | - } |
|
238 | - |
|
239 | - // Check if user has permissions to edit this specific post |
|
240 | - if (!current_user_can('edit_post', $post_id)) { |
|
241 | - return $post_id; |
|
242 | - } |
|
243 | - |
|
244 | - // Cast module ID as an integer if selected, otherwise leave as empty string |
|
245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
246 | - |
|
247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
249 | - return true; |
|
250 | - } |
|
251 | - |
|
252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
253 | - |
|
254 | - // Assign lesson to selected module |
|
255 | - wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
256 | - |
|
257 | - // Set default order for lesson inside module |
|
258 | - if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
259 | - update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - return true; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Display course field on new module screen |
|
268 | - * |
|
269 | - * @since 1.8.0 |
|
270 | - * @param object $taxonomy Taxonomy object |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function add_module_fields($taxonomy) |
|
274 | - { |
|
275 | - ?> |
|
17 | + private $dir; |
|
18 | + private $file; |
|
19 | + private $assets_dir; |
|
20 | + private $assets_url; |
|
21 | + private $order_page_slug; |
|
22 | + public $taxonomy; |
|
23 | + |
|
24 | + public function __construct( $file ) |
|
25 | + { |
|
26 | + $this->file = $file; |
|
27 | + $this->dir = dirname($this->file); |
|
28 | + $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
29 | + $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
|
30 | + $this->taxonomy = 'module'; |
|
31 | + $this->order_page_slug = 'module-order'; |
|
32 | + |
|
33 | + // setup taxonomy |
|
34 | + add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
35 | + |
|
36 | + // Manage lesson meta boxes for taxonomy |
|
37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
38 | + |
|
39 | + // Save lesson meta box |
|
40 | + add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
|
41 | + |
|
42 | + //Reset the none modules lessons transient |
|
43 | + add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
44 | + |
|
45 | + // Frontend styling |
|
46 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
47 | + |
|
48 | + // Admin styling |
|
49 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
|
50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
51 | + |
|
52 | + // Handle module completion record |
|
53 | + add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
|
54 | + add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2); |
|
55 | + add_action('wp', array($this, 'save_module_progress'), 10); |
|
56 | + |
|
57 | + // Handle module ordering |
|
58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
59 | + add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
|
60 | + add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
|
61 | + |
|
62 | + // Ensure modules always show under courses |
|
63 | + add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 ); |
|
64 | + add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 ); |
|
65 | + add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 ); |
|
66 | + |
|
67 | + // Add course field to taxonomy |
|
68 | + add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1); |
|
69 | + add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1); |
|
70 | + add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
71 | + add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2); |
|
72 | + add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
|
73 | + |
|
74 | + // Manage module taxonomy archive page |
|
75 | + add_filter('template_include', array($this, 'module_archive_template'), 10); |
|
76 | + add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1); |
|
77 | + add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title')); |
|
78 | + add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11); |
|
79 | + add_action('sensei_pagination', array($this, 'module_navigation_links'), 11); |
|
80 | + add_filter('body_class', array($this, 'module_archive_body_class')); |
|
81 | + |
|
82 | + // add modules to the single course template |
|
83 | + add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 ); |
|
84 | + |
|
85 | + //Single Course modules actions. Add to single-course/course-modules.php |
|
86 | + add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20); |
|
87 | + |
|
88 | + // Set up display on single lesson page |
|
89 | + add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
|
90 | + |
|
91 | + // Add 'Modules' columns to Analysis tables |
|
92 | + add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2); |
|
93 | + add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3); |
|
94 | + add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2); |
|
95 | + add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
|
96 | + |
|
97 | + // Manage module taxonomy columns |
|
98 | + add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1); |
|
99 | + add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3); |
|
100 | + add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
|
101 | + |
|
102 | + //store new modules created on the course edit screen |
|
103 | + add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) ); |
|
104 | + |
|
105 | + // for non admin users, only show taxonomies that belong to them |
|
106 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
107 | + add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 ); |
|
108 | + |
|
109 | + // add the teacher name next to the module term in for admin users |
|
110 | + add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 ); |
|
111 | + |
|
112 | + // remove the default modules metabox |
|
113 | + add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
114 | + |
|
115 | + } // end constructor |
|
116 | + |
|
117 | + /** |
|
118 | + * Alter a module term slug when a new taxonomy term is created |
|
119 | + * This will add the creators user name to the slug for uniqueness. |
|
120 | + * |
|
121 | + * @since 1.8.0 |
|
122 | + * |
|
123 | + * @param $term_id |
|
124 | + * @param $tt_id |
|
125 | + * @param $taxonomy |
|
126 | + * |
|
127 | + * @return void |
|
128 | + * @deprecated since 1.9.0 |
|
129 | + */ |
|
130 | + public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
131 | + |
|
132 | + _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
133 | + |
|
134 | + }// end add_module_term_group |
|
135 | + |
|
136 | + /** |
|
137 | + * Hook in all meta boxes related tot he modules taxonomy |
|
138 | + * |
|
139 | + * @since 1.8.0 |
|
140 | + * |
|
141 | + * @param string $post_type |
|
142 | + * @param WP_Post $post |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function modules_metaboxes( $post_type, $post ) |
|
147 | + { |
|
148 | + if ('lesson' == $post_type ) { |
|
149 | + |
|
150 | + // Remove default taxonomy meta box from Lesson edit screen |
|
151 | + remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
152 | + |
|
153 | + // Add custom meta box to limit module selection to one per lesson |
|
154 | + add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
155 | + } |
|
156 | + |
|
157 | + if( 'course' == $post_type ){ |
|
158 | + // Course modules selection metabox |
|
159 | + add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Build content for custom module meta box |
|
165 | + * |
|
166 | + * @since 1.8.0 |
|
167 | + * @param object $post Current post object |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function lesson_module_metabox($post) |
|
171 | + { |
|
172 | + |
|
173 | + // Get lesson course |
|
174 | + $lesson_course = get_post_meta($post->ID, '_lesson_course', true); |
|
175 | + |
|
176 | + $html = ''; |
|
177 | + |
|
178 | + // Only show module selection if this lesson is part of a course |
|
179 | + if ($lesson_course && $lesson_course > 0) { |
|
180 | + |
|
181 | + // Get existing lesson module |
|
182 | + $lesson_module = 0; |
|
183 | + $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy); |
|
184 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
185 | + foreach ($lesson_module_list as $single_module) { |
|
186 | + $lesson_module = $single_module->term_id; |
|
187 | + break; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + // Get the available modules for this lesson's course |
|
192 | + $modules = $this->get_course_modules($lesson_course); |
|
193 | + |
|
194 | + // Build the HTML to output |
|
195 | + $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />'; |
|
196 | + if (is_array($modules) && count($modules) > 0) { |
|
197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n"; |
|
198 | + $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
199 | + foreach ($modules as $module) { |
|
200 | + $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n"; |
|
201 | + } |
|
202 | + $html .= '</select>' . "\n"; |
|
203 | + } else { |
|
204 | + $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit'); |
|
205 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>'; |
|
206 | + } // End If Statement |
|
207 | + |
|
208 | + } else { |
|
209 | + $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>'; |
|
210 | + } // End If Statement |
|
211 | + |
|
212 | + // Output the HTML |
|
213 | + echo $html; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Save module to lesson |
|
218 | + * |
|
219 | + * @since 1.8.0 |
|
220 | + * @param integer $post_id ID of post |
|
221 | + * @return mixed Post ID on permissions failure, boolean true on success |
|
222 | + */ |
|
223 | + public function save_lesson_module($post_id) |
|
224 | + { |
|
225 | + global $post; |
|
226 | + |
|
227 | + // Verify post type and nonce |
|
228 | + if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] ) |
|
229 | + ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) { |
|
230 | + return $post_id; |
|
231 | + } |
|
232 | + |
|
233 | + // Check if user has permissions to edit lessons |
|
234 | + $post_type = get_post_type_object($post->post_type); |
|
235 | + if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
236 | + return $post_id; |
|
237 | + } |
|
238 | + |
|
239 | + // Check if user has permissions to edit this specific post |
|
240 | + if (!current_user_can('edit_post', $post_id)) { |
|
241 | + return $post_id; |
|
242 | + } |
|
243 | + |
|
244 | + // Cast module ID as an integer if selected, otherwise leave as empty string |
|
245 | + if ( isset( $_POST['lesson_module'] ) ) { |
|
246 | + |
|
247 | + if( empty ( $_POST['lesson_module'] ) ){ |
|
248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
249 | + return true; |
|
250 | + } |
|
251 | + |
|
252 | + $module_id = intval( $_POST['lesson_module'] ); |
|
253 | + |
|
254 | + // Assign lesson to selected module |
|
255 | + wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
|
256 | + |
|
257 | + // Set default order for lesson inside module |
|
258 | + if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) { |
|
259 | + update_post_meta($post_id, '_order_module_' . $module_id, 0); |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + return true; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Display course field on new module screen |
|
268 | + * |
|
269 | + * @since 1.8.0 |
|
270 | + * @param object $taxonomy Taxonomy object |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function add_module_fields($taxonomy) |
|
274 | + { |
|
275 | + ?> |
|
276 | 276 | <div class="form-field"> |
277 | 277 | <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label> |
278 | 278 | <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses" |
@@ -281,44 +281,44 @@ discard block |
||
281 | 281 | class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span> |
282 | 282 | </div> |
283 | 283 | <?php |
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Display course field on module edit screen |
|
288 | - * |
|
289 | - * @since 1.8.0 |
|
290 | - * @param object $module Module term object |
|
291 | - * @return void |
|
292 | - */ |
|
293 | - public function edit_module_fields($module) |
|
294 | - { |
|
295 | - |
|
296 | - $module_id = $module->term_id; |
|
297 | - |
|
298 | - // Get module's existing courses |
|
299 | - $args = array( |
|
300 | - 'post_type' => 'course', |
|
301 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
302 | - 'posts_per_page' => -1, |
|
303 | - 'tax_query' => array( |
|
304 | - array( |
|
305 | - 'taxonomy' => $this->taxonomy, |
|
306 | - 'field' => 'id', |
|
307 | - 'terms' => $module_id |
|
308 | - ) |
|
309 | - ) |
|
310 | - ); |
|
311 | - $courses = get_posts($args); |
|
312 | - |
|
313 | - //build the defaults array |
|
314 | - $module_courses = array(); |
|
315 | - if (isset($courses) && is_array($courses)) { |
|
316 | - foreach ($courses as $course) { |
|
317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - ?> |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Display course field on module edit screen |
|
288 | + * |
|
289 | + * @since 1.8.0 |
|
290 | + * @param object $module Module term object |
|
291 | + * @return void |
|
292 | + */ |
|
293 | + public function edit_module_fields($module) |
|
294 | + { |
|
295 | + |
|
296 | + $module_id = $module->term_id; |
|
297 | + |
|
298 | + // Get module's existing courses |
|
299 | + $args = array( |
|
300 | + 'post_type' => 'course', |
|
301 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
302 | + 'posts_per_page' => -1, |
|
303 | + 'tax_query' => array( |
|
304 | + array( |
|
305 | + 'taxonomy' => $this->taxonomy, |
|
306 | + 'field' => 'id', |
|
307 | + 'terms' => $module_id |
|
308 | + ) |
|
309 | + ) |
|
310 | + ); |
|
311 | + $courses = get_posts($args); |
|
312 | + |
|
313 | + //build the defaults array |
|
314 | + $module_courses = array(); |
|
315 | + if (isset($courses) && is_array($courses)) { |
|
316 | + foreach ($courses as $course) { |
|
317 | + $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + ?> |
|
322 | 322 | <tr class="form-field"> |
323 | 323 | <th scope="row" valign="top"><label |
324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
@@ -335,1401 +335,1401 @@ discard block |
||
335 | 335 | </td> |
336 | 336 | </tr> |
337 | 337 | <?php |
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Save module course on add/edit |
|
342 | - * |
|
343 | - * @since 1.8.0 |
|
344 | - * @param integer $module_id ID of module |
|
345 | - * @return void |
|
346 | - */ |
|
347 | - public function save_module_course($module_id) |
|
348 | - { |
|
349 | - |
|
350 | - // Get module's existing courses |
|
351 | - $args = array( |
|
352 | - 'post_type' => 'course', |
|
353 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
354 | - 'posts_per_page' => -1, |
|
355 | - 'tax_query' => array( |
|
356 | - array( |
|
357 | - 'taxonomy' => $this->taxonomy, |
|
358 | - 'field' => 'id', |
|
359 | - 'terms' => $module_id |
|
360 | - ) |
|
361 | - ) |
|
362 | - ); |
|
363 | - $courses = get_posts($args); |
|
364 | - |
|
365 | - // Remove module from existing courses |
|
366 | - if (isset($courses) && is_array($courses)) { |
|
367 | - foreach ($courses as $course) { |
|
368 | - wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - // Add module to selected courses |
|
373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
374 | - |
|
375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
376 | - |
|
377 | - foreach ( $course_ids as $course_id ) { |
|
378 | - |
|
379 | - wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
380 | - |
|
381 | - } |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Ajax function to search for courses matching term |
|
387 | - * |
|
388 | - * @since 1.8.0 |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - public function search_courses_json() |
|
392 | - { |
|
393 | - |
|
394 | - // Security check |
|
395 | - check_ajax_referer('search-courses', 'security'); |
|
396 | - |
|
397 | - // Set content type |
|
398 | - header('Content-Type: application/json; charset=utf-8'); |
|
399 | - |
|
400 | - // Get user input |
|
401 | - $term = urldecode(stripslashes($_GET['term'])); |
|
402 | - |
|
403 | - // Return nothing if term is empty |
|
404 | - if (empty($term)) |
|
405 | - die(); |
|
406 | - |
|
407 | - // Set a default if none is given |
|
408 | - $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
409 | - |
|
410 | - // Set up array of results |
|
411 | - $found_courses = array('' => $default); |
|
412 | - |
|
413 | - // Fetch results |
|
414 | - $args = array( |
|
415 | - 'post_type' => 'course', |
|
416 | - 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
417 | - 'posts_per_page' => -1, |
|
418 | - 'orderby' => 'title', |
|
419 | - 's' => $term |
|
420 | - ); |
|
421 | - $courses = get_posts($args); |
|
422 | - |
|
423 | - // Add results to array |
|
424 | - if ($courses) { |
|
425 | - foreach ($courses as $course) { |
|
426 | - $found_courses[$course->ID] = $course->post_title; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - // Encode and return results for processing & selection |
|
431 | - echo json_encode($found_courses); |
|
432 | - die(); |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * display modules on single course pages |
|
437 | - * |
|
438 | - * @since 1.8.0 |
|
439 | - * @return void |
|
440 | - */ |
|
441 | - public function single_course_modules(){ |
|
442 | - |
|
443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
444 | - // only show modules on the course that has modules |
|
445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
446 | - |
|
447 | - $this->load_course_module_content_template(); |
|
448 | - |
|
449 | - } |
|
450 | - |
|
451 | - } // end single_course_modules |
|
452 | - |
|
453 | - public function sensei_course_preview_titles($title, $lesson_id) |
|
454 | - { |
|
455 | - global $post, $current_user; |
|
456 | - |
|
457 | - $course_id = $post->ID; |
|
458 | - $title_text = ''; |
|
459 | - |
|
460 | - if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
461 | - $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
462 | - if (!$is_user_taking_course) { |
|
463 | - if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
464 | - $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
465 | - // Remove brackets for display here |
|
466 | - $title_text = str_replace('(', '', $title_text); |
|
467 | - $title_text = str_replace(')', '', $title_text); |
|
468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
469 | - } |
|
470 | - $title .= ' ' . $title_text; |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - return $title; |
|
475 | - } |
|
476 | - |
|
477 | - public function module_breadcrumb_link($html, $separator) |
|
478 | - { |
|
479 | - global $post; |
|
480 | - // Lesson |
|
481 | - if (is_singular('lesson')) { |
|
482 | - if (has_term('', $this->taxonomy, $post->ID)) { |
|
483 | - $module = $this->get_lesson_module($post->ID); |
|
484 | - if( $module ) { |
|
485 | - $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
486 | - } |
|
487 | - } |
|
488 | - } |
|
489 | - // Module |
|
490 | - if (is_tax($this->taxonomy)) { |
|
491 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
492 | - $course_id = intval($_GET['course_id']); |
|
493 | - $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
494 | - } |
|
495 | - } |
|
496 | - return $html; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Set lesson archive template to display on module taxonomy archive page |
|
501 | - * |
|
502 | - * @since 1.8.0 |
|
503 | - * @param string $template Default template |
|
504 | - * @return string Modified template |
|
505 | - */ |
|
506 | - public function module_archive_template($template) { |
|
507 | - |
|
508 | - if ( ! is_tax($this->taxonomy) ) { |
|
509 | - return $template; |
|
510 | - } |
|
511 | - |
|
512 | - $file = 'archive-lesson.php'; |
|
513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
514 | - |
|
515 | - // locate the template file |
|
516 | - $template = locate_template($find); |
|
517 | - if (!$template) { |
|
518 | - |
|
519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
520 | - |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - return $template; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Modify module taxonomy archive query |
|
529 | - * |
|
530 | - * @since 1.8.0 |
|
531 | - * @param object $query The query object passed by reference |
|
532 | - * @return void |
|
533 | - */ |
|
534 | - public function module_archive_filter($query) |
|
535 | - { |
|
536 | - if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
537 | - |
|
538 | - |
|
539 | - // Limit to lessons only |
|
540 | - $query->set('post_type', 'lesson'); |
|
541 | - |
|
542 | - // Set order of lessons |
|
543 | - if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
544 | - $module_id = $query->queried_object_id; |
|
545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
546 | - $query->set('orderby', 'meta_value_num date'); |
|
547 | - } else { |
|
548 | - $query->set('orderby', 'menu_order'); |
|
549 | - } |
|
550 | - $query->set('order', 'ASC'); |
|
551 | - |
|
552 | - // Limit to specific course if specified |
|
553 | - if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
554 | - $course_id = intval($_GET['course_id']); |
|
555 | - $meta_query[] = array( |
|
556 | - 'key' => '_lesson_course', |
|
557 | - 'value' => intval($course_id) |
|
558 | - ); |
|
559 | - $query->set('meta_query', $meta_query); |
|
560 | - } |
|
561 | - |
|
562 | - } |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Modify archive page title |
|
567 | - * |
|
568 | - * @since 1.8.0 |
|
569 | - * @param string $title Default title |
|
570 | - * @return string Modified title |
|
571 | - */ |
|
572 | - public function module_archive_title($title) |
|
573 | - { |
|
574 | - if (is_tax($this->taxonomy)) { |
|
575 | - $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
576 | - } |
|
577 | - return $title; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Display module description on taxonomy archive page |
|
582 | - * |
|
583 | - * @since 1.8.0 |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - public function module_archive_description() |
|
587 | - { |
|
588 | - if (is_tax($this->taxonomy)) { |
|
589 | - |
|
590 | - $module = get_queried_object(); |
|
591 | - |
|
592 | - $module_progress = false; |
|
593 | - if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
594 | - global $current_user; |
|
595 | - wp_get_current_user(); |
|
596 | - $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
597 | - } |
|
598 | - |
|
599 | - if ($module_progress && $module_progress > 0) { |
|
600 | - $status = __('Completed', 'woothemes-sensei'); |
|
601 | - $class = 'completed'; |
|
602 | - if ($module_progress < 100) { |
|
603 | - $status = __('In progress', 'woothemes-sensei'); |
|
604 | - $class = 'in-progress'; |
|
605 | - } |
|
606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
607 | - } |
|
608 | - |
|
609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
610 | - } |
|
611 | - } |
|
612 | - |
|
613 | - public function module_archive_body_class($classes) |
|
614 | - { |
|
615 | - if (is_tax($this->taxonomy)) { |
|
616 | - $classes[] = 'module-archive'; |
|
617 | - } |
|
618 | - return $classes; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Display module navigation links on module taxonomy archive page |
|
623 | - * |
|
624 | - * @since 1.8.0 |
|
625 | - * @return void |
|
626 | - */ |
|
627 | - public function module_navigation_links() |
|
628 | - { |
|
629 | - if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
630 | - |
|
631 | - $queried_module = get_queried_object(); |
|
632 | - $course_modules = $this->get_course_modules($_GET['course_id']); |
|
633 | - |
|
634 | - $prev_module = false; |
|
635 | - $next_module = false; |
|
636 | - $on_current = false; |
|
637 | - foreach ($course_modules as $module) { |
|
638 | - $this_module = $module; |
|
639 | - if ($on_current) { |
|
640 | - $next_module = $this_module; |
|
641 | - break; |
|
642 | - } |
|
643 | - if ($this_module == $queried_module) { |
|
644 | - $on_current = true; |
|
645 | - } else { |
|
646 | - $prev_module = $module; |
|
647 | - } |
|
648 | - } |
|
649 | - |
|
650 | - ?> |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Save module course on add/edit |
|
342 | + * |
|
343 | + * @since 1.8.0 |
|
344 | + * @param integer $module_id ID of module |
|
345 | + * @return void |
|
346 | + */ |
|
347 | + public function save_module_course($module_id) |
|
348 | + { |
|
349 | + |
|
350 | + // Get module's existing courses |
|
351 | + $args = array( |
|
352 | + 'post_type' => 'course', |
|
353 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
354 | + 'posts_per_page' => -1, |
|
355 | + 'tax_query' => array( |
|
356 | + array( |
|
357 | + 'taxonomy' => $this->taxonomy, |
|
358 | + 'field' => 'id', |
|
359 | + 'terms' => $module_id |
|
360 | + ) |
|
361 | + ) |
|
362 | + ); |
|
363 | + $courses = get_posts($args); |
|
364 | + |
|
365 | + // Remove module from existing courses |
|
366 | + if (isset($courses) && is_array($courses)) { |
|
367 | + foreach ($courses as $course) { |
|
368 | + wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + // Add module to selected courses |
|
373 | + if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
374 | + |
|
375 | + $course_ids = explode( ",", $_POST['module_courses'] ); |
|
376 | + |
|
377 | + foreach ( $course_ids as $course_id ) { |
|
378 | + |
|
379 | + wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
|
380 | + |
|
381 | + } |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Ajax function to search for courses matching term |
|
387 | + * |
|
388 | + * @since 1.8.0 |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + public function search_courses_json() |
|
392 | + { |
|
393 | + |
|
394 | + // Security check |
|
395 | + check_ajax_referer('search-courses', 'security'); |
|
396 | + |
|
397 | + // Set content type |
|
398 | + header('Content-Type: application/json; charset=utf-8'); |
|
399 | + |
|
400 | + // Get user input |
|
401 | + $term = urldecode(stripslashes($_GET['term'])); |
|
402 | + |
|
403 | + // Return nothing if term is empty |
|
404 | + if (empty($term)) |
|
405 | + die(); |
|
406 | + |
|
407 | + // Set a default if none is given |
|
408 | + $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
|
409 | + |
|
410 | + // Set up array of results |
|
411 | + $found_courses = array('' => $default); |
|
412 | + |
|
413 | + // Fetch results |
|
414 | + $args = array( |
|
415 | + 'post_type' => 'course', |
|
416 | + 'post_status' => array('publish', 'draft', 'future', 'private'), |
|
417 | + 'posts_per_page' => -1, |
|
418 | + 'orderby' => 'title', |
|
419 | + 's' => $term |
|
420 | + ); |
|
421 | + $courses = get_posts($args); |
|
422 | + |
|
423 | + // Add results to array |
|
424 | + if ($courses) { |
|
425 | + foreach ($courses as $course) { |
|
426 | + $found_courses[$course->ID] = $course->post_title; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + // Encode and return results for processing & selection |
|
431 | + echo json_encode($found_courses); |
|
432 | + die(); |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * display modules on single course pages |
|
437 | + * |
|
438 | + * @since 1.8.0 |
|
439 | + * @return void |
|
440 | + */ |
|
441 | + public function single_course_modules(){ |
|
442 | + |
|
443 | + _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
444 | + // only show modules on the course that has modules |
|
445 | + if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
446 | + |
|
447 | + $this->load_course_module_content_template(); |
|
448 | + |
|
449 | + } |
|
450 | + |
|
451 | + } // end single_course_modules |
|
452 | + |
|
453 | + public function sensei_course_preview_titles($title, $lesson_id) |
|
454 | + { |
|
455 | + global $post, $current_user; |
|
456 | + |
|
457 | + $course_id = $post->ID; |
|
458 | + $title_text = ''; |
|
459 | + |
|
460 | + if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) { |
|
461 | + $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status')); |
|
462 | + if (!$is_user_taking_course) { |
|
463 | + if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
|
464 | + $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
|
465 | + // Remove brackets for display here |
|
466 | + $title_text = str_replace('(', '', $title_text); |
|
467 | + $title_text = str_replace(')', '', $title_text); |
|
468 | + $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
469 | + } |
|
470 | + $title .= ' ' . $title_text; |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + return $title; |
|
475 | + } |
|
476 | + |
|
477 | + public function module_breadcrumb_link($html, $separator) |
|
478 | + { |
|
479 | + global $post; |
|
480 | + // Lesson |
|
481 | + if (is_singular('lesson')) { |
|
482 | + if (has_term('', $this->taxonomy, $post->ID)) { |
|
483 | + $module = $this->get_lesson_module($post->ID); |
|
484 | + if( $module ) { |
|
485 | + $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' . __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>'; |
|
486 | + } |
|
487 | + } |
|
488 | + } |
|
489 | + // Module |
|
490 | + if (is_tax($this->taxonomy)) { |
|
491 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
492 | + $course_id = intval($_GET['course_id']); |
|
493 | + $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>'; |
|
494 | + } |
|
495 | + } |
|
496 | + return $html; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Set lesson archive template to display on module taxonomy archive page |
|
501 | + * |
|
502 | + * @since 1.8.0 |
|
503 | + * @param string $template Default template |
|
504 | + * @return string Modified template |
|
505 | + */ |
|
506 | + public function module_archive_template($template) { |
|
507 | + |
|
508 | + if ( ! is_tax($this->taxonomy) ) { |
|
509 | + return $template; |
|
510 | + } |
|
511 | + |
|
512 | + $file = 'archive-lesson.php'; |
|
513 | + $find = array( $file, Sensei()->template_url . $file ); |
|
514 | + |
|
515 | + // locate the template file |
|
516 | + $template = locate_template($find); |
|
517 | + if (!$template) { |
|
518 | + |
|
519 | + $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
520 | + |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + return $template; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Modify module taxonomy archive query |
|
529 | + * |
|
530 | + * @since 1.8.0 |
|
531 | + * @param object $query The query object passed by reference |
|
532 | + * @return void |
|
533 | + */ |
|
534 | + public function module_archive_filter($query) |
|
535 | + { |
|
536 | + if (is_tax($this->taxonomy) && $query->is_main_query()) { |
|
537 | + |
|
538 | + |
|
539 | + // Limit to lessons only |
|
540 | + $query->set('post_type', 'lesson'); |
|
541 | + |
|
542 | + // Set order of lessons |
|
543 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
544 | + $module_id = $query->queried_object_id; |
|
545 | + $query->set('meta_key', '_order_module_' . $module_id); |
|
546 | + $query->set('orderby', 'meta_value_num date'); |
|
547 | + } else { |
|
548 | + $query->set('orderby', 'menu_order'); |
|
549 | + } |
|
550 | + $query->set('order', 'ASC'); |
|
551 | + |
|
552 | + // Limit to specific course if specified |
|
553 | + if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
554 | + $course_id = intval($_GET['course_id']); |
|
555 | + $meta_query[] = array( |
|
556 | + 'key' => '_lesson_course', |
|
557 | + 'value' => intval($course_id) |
|
558 | + ); |
|
559 | + $query->set('meta_query', $meta_query); |
|
560 | + } |
|
561 | + |
|
562 | + } |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Modify archive page title |
|
567 | + * |
|
568 | + * @since 1.8.0 |
|
569 | + * @param string $title Default title |
|
570 | + * @return string Modified title |
|
571 | + */ |
|
572 | + public function module_archive_title($title) |
|
573 | + { |
|
574 | + if (is_tax($this->taxonomy)) { |
|
575 | + $title = apply_filters('sensei_module_archive_title', get_queried_object()->name); |
|
576 | + } |
|
577 | + return $title; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Display module description on taxonomy archive page |
|
582 | + * |
|
583 | + * @since 1.8.0 |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + public function module_archive_description() |
|
587 | + { |
|
588 | + if (is_tax($this->taxonomy)) { |
|
589 | + |
|
590 | + $module = get_queried_object(); |
|
591 | + |
|
592 | + $module_progress = false; |
|
593 | + if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) { |
|
594 | + global $current_user; |
|
595 | + wp_get_current_user(); |
|
596 | + $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID); |
|
597 | + } |
|
598 | + |
|
599 | + if ($module_progress && $module_progress > 0) { |
|
600 | + $status = __('Completed', 'woothemes-sensei'); |
|
601 | + $class = 'completed'; |
|
602 | + if ($module_progress < 100) { |
|
603 | + $status = __('In progress', 'woothemes-sensei'); |
|
604 | + $class = 'in-progress'; |
|
605 | + } |
|
606 | + echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
607 | + } |
|
608 | + |
|
609 | + echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
610 | + } |
|
611 | + } |
|
612 | + |
|
613 | + public function module_archive_body_class($classes) |
|
614 | + { |
|
615 | + if (is_tax($this->taxonomy)) { |
|
616 | + $classes[] = 'module-archive'; |
|
617 | + } |
|
618 | + return $classes; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Display module navigation links on module taxonomy archive page |
|
623 | + * |
|
624 | + * @since 1.8.0 |
|
625 | + * @return void |
|
626 | + */ |
|
627 | + public function module_navigation_links() |
|
628 | + { |
|
629 | + if (is_tax($this->taxonomy) && isset($_GET['course_id'])) { |
|
630 | + |
|
631 | + $queried_module = get_queried_object(); |
|
632 | + $course_modules = $this->get_course_modules($_GET['course_id']); |
|
633 | + |
|
634 | + $prev_module = false; |
|
635 | + $next_module = false; |
|
636 | + $on_current = false; |
|
637 | + foreach ($course_modules as $module) { |
|
638 | + $this_module = $module; |
|
639 | + if ($on_current) { |
|
640 | + $next_module = $this_module; |
|
641 | + break; |
|
642 | + } |
|
643 | + if ($this_module == $queried_module) { |
|
644 | + $on_current = true; |
|
645 | + } else { |
|
646 | + $prev_module = $module; |
|
647 | + } |
|
648 | + } |
|
649 | + |
|
650 | + ?> |
|
651 | 651 | <div id="post-entries" class="post-entries module-navigation fix"> |
652 | 652 | <?php if ($next_module) { |
653 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
654 | - ?> |
|
653 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy)); |
|
654 | + ?> |
|
655 | 655 | <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>" |
656 | 656 | title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?> |
657 | 657 | <span class="meta-nav"></span></a></div> |
658 | 658 | <?php } ?> |
659 | 659 | <?php if ($prev_module) { |
660 | - $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
661 | - ?> |
|
660 | + $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy)); |
|
661 | + ?> |
|
662 | 662 | <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>" |
663 | 663 | title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span |
664 | 664 | class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div> |
665 | 665 | <?php } ?> |
666 | 666 | </div> |
667 | 667 | <?php |
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
673 | - * |
|
674 | - * @since 1.8.0 |
|
675 | - * @param string $status Status of the lesson for the user |
|
676 | - * @param integer $user_id ID of user |
|
677 | - * @param integer $lesson_id ID of lesson |
|
678 | - * @return void |
|
679 | - */ |
|
680 | - public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
681 | - { |
|
682 | - $this->save_lesson_module_progress($user_id, $lesson_id); |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Save lesson's module progress for a specific user |
|
687 | - * |
|
688 | - * @since 1.8.0 |
|
689 | - * @param integer $user_id ID of user |
|
690 | - * @param integer $lesson_id ID of lesson |
|
691 | - * @return void |
|
692 | - */ |
|
693 | - public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
694 | - { |
|
695 | - $module = $this->get_lesson_module($lesson_id); |
|
696 | - $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
697 | - if ($module && $course_id) { |
|
698 | - $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
699 | - } |
|
700 | - } |
|
701 | - |
|
702 | - /** |
|
703 | - * Save progress of module for user |
|
704 | - * |
|
705 | - * @since 1.8.0 |
|
706 | - * @return void |
|
707 | - */ |
|
708 | - public function save_module_progress() |
|
709 | - { |
|
710 | - if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
711 | - global $current_user; |
|
712 | - wp_get_current_user(); |
|
713 | - $user_id = $current_user->ID; |
|
714 | - |
|
715 | - $module = get_queried_object(); |
|
716 | - |
|
717 | - $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
718 | - } |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * Save module progess for user |
|
723 | - * |
|
724 | - * @since 1.8.0 |
|
725 | - * |
|
726 | - * @param integer $module_id ID of module |
|
727 | - * @param integer $course_id ID of course |
|
728 | - * @param integer $user_id ID of user |
|
729 | - * @return void |
|
730 | - */ |
|
731 | - public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
732 | - { |
|
733 | - $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
734 | - update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
735 | - |
|
736 | - do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Get module progress for a user |
|
741 | - * |
|
742 | - * @since 1.8.0 |
|
743 | - * |
|
744 | - * @param integer $module_id ID of module |
|
745 | - * @param integer $course_id ID of course |
|
746 | - * @param integer $user_id ID of user |
|
747 | - * @return mixed Module progress percentage on success, false on failure |
|
748 | - */ |
|
749 | - public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
750 | - { |
|
751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
752 | - if ($module_progress) { |
|
753 | - return (float)$module_progress; |
|
754 | - } |
|
755 | - return false; |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Calculate module progess for user |
|
760 | - * |
|
761 | - * @since 1.8.0 |
|
762 | - * |
|
763 | - * @param integer $user_id ID of user |
|
764 | - * @param integer $module_id ID of module |
|
765 | - * @param integer $course_id ID of course |
|
766 | - * @return integer Module progress percentage |
|
767 | - */ |
|
768 | - public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
769 | - { |
|
770 | - |
|
771 | - $args = array( |
|
772 | - 'post_type' => 'lesson', |
|
773 | - 'post_status' => 'publish', |
|
774 | - 'posts_per_page' => -1, |
|
775 | - 'tax_query' => array( |
|
776 | - array( |
|
777 | - 'taxonomy' => $this->taxonomy, |
|
778 | - 'field' => 'id', |
|
779 | - 'terms' => $module_id |
|
780 | - ) |
|
781 | - ), |
|
782 | - 'meta_query' => array( |
|
783 | - array( |
|
784 | - 'key' => '_lesson_course', |
|
785 | - 'value' => $course_id |
|
786 | - ) |
|
787 | - ), |
|
788 | - 'fields' => 'ids' |
|
789 | - ); |
|
790 | - $lessons = get_posts($args); |
|
791 | - |
|
792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
793 | - |
|
794 | - $completed = false; |
|
795 | - $lesson_count = 0; |
|
796 | - $completed_count = 0; |
|
797 | - foreach ($lessons as $lesson_id) { |
|
798 | - $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
799 | - ++$lesson_count; |
|
800 | - if ($completed) { |
|
801 | - ++$completed_count; |
|
802 | - } |
|
803 | - } |
|
804 | - $module_progress = ($completed_count / $lesson_count) * 100; |
|
805 | - |
|
806 | - return (float)$module_progress; |
|
807 | - } |
|
808 | - |
|
809 | - /** |
|
810 | - * Register admin screen for ordering modules |
|
811 | - * |
|
812 | - * @since 1.8.0 |
|
813 | - * |
|
814 | - * @return void |
|
815 | - */ |
|
816 | - public function register_modules_admin_menu_items() |
|
817 | - { |
|
818 | - //add the modules link under the Course main menu |
|
819 | - add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
820 | - |
|
821 | - // Regsiter new admin page for module ordering |
|
822 | - $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
823 | - |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Display Module Order screen |
|
828 | - * |
|
829 | - * @since 1.8.0 |
|
830 | - * |
|
831 | - * @return void |
|
832 | - */ |
|
833 | - public function module_order_screen() |
|
834 | - { |
|
835 | - ?> |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user |
|
673 | + * |
|
674 | + * @since 1.8.0 |
|
675 | + * @param string $status Status of the lesson for the user |
|
676 | + * @param integer $user_id ID of user |
|
677 | + * @param integer $lesson_id ID of lesson |
|
678 | + * @return void |
|
679 | + */ |
|
680 | + public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0) |
|
681 | + { |
|
682 | + $this->save_lesson_module_progress($user_id, $lesson_id); |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Save lesson's module progress for a specific user |
|
687 | + * |
|
688 | + * @since 1.8.0 |
|
689 | + * @param integer $user_id ID of user |
|
690 | + * @param integer $lesson_id ID of lesson |
|
691 | + * @return void |
|
692 | + */ |
|
693 | + public function save_lesson_module_progress($user_id = 0, $lesson_id = 0) |
|
694 | + { |
|
695 | + $module = $this->get_lesson_module($lesson_id); |
|
696 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
697 | + if ($module && $course_id) { |
|
698 | + $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id)); |
|
699 | + } |
|
700 | + } |
|
701 | + |
|
702 | + /** |
|
703 | + * Save progress of module for user |
|
704 | + * |
|
705 | + * @since 1.8.0 |
|
706 | + * @return void |
|
707 | + */ |
|
708 | + public function save_module_progress() |
|
709 | + { |
|
710 | + if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
|
711 | + global $current_user; |
|
712 | + wp_get_current_user(); |
|
713 | + $user_id = $current_user->ID; |
|
714 | + |
|
715 | + $module = get_queried_object(); |
|
716 | + |
|
717 | + $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id)); |
|
718 | + } |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Save module progess for user |
|
723 | + * |
|
724 | + * @since 1.8.0 |
|
725 | + * |
|
726 | + * @param integer $module_id ID of module |
|
727 | + * @param integer $course_id ID of course |
|
728 | + * @param integer $user_id ID of user |
|
729 | + * @return void |
|
730 | + */ |
|
731 | + public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
732 | + { |
|
733 | + $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id); |
|
734 | + update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress)); |
|
735 | + |
|
736 | + do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Get module progress for a user |
|
741 | + * |
|
742 | + * @since 1.8.0 |
|
743 | + * |
|
744 | + * @param integer $module_id ID of module |
|
745 | + * @param integer $course_id ID of course |
|
746 | + * @param integer $user_id ID of user |
|
747 | + * @return mixed Module progress percentage on success, false on failure |
|
748 | + */ |
|
749 | + public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
|
750 | + { |
|
751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
752 | + if ($module_progress) { |
|
753 | + return (float)$module_progress; |
|
754 | + } |
|
755 | + return false; |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Calculate module progess for user |
|
760 | + * |
|
761 | + * @since 1.8.0 |
|
762 | + * |
|
763 | + * @param integer $user_id ID of user |
|
764 | + * @param integer $module_id ID of module |
|
765 | + * @param integer $course_id ID of course |
|
766 | + * @return integer Module progress percentage |
|
767 | + */ |
|
768 | + public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0) |
|
769 | + { |
|
770 | + |
|
771 | + $args = array( |
|
772 | + 'post_type' => 'lesson', |
|
773 | + 'post_status' => 'publish', |
|
774 | + 'posts_per_page' => -1, |
|
775 | + 'tax_query' => array( |
|
776 | + array( |
|
777 | + 'taxonomy' => $this->taxonomy, |
|
778 | + 'field' => 'id', |
|
779 | + 'terms' => $module_id |
|
780 | + ) |
|
781 | + ), |
|
782 | + 'meta_query' => array( |
|
783 | + array( |
|
784 | + 'key' => '_lesson_course', |
|
785 | + 'value' => $course_id |
|
786 | + ) |
|
787 | + ), |
|
788 | + 'fields' => 'ids' |
|
789 | + ); |
|
790 | + $lessons = get_posts($args); |
|
791 | + |
|
792 | + if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
793 | + |
|
794 | + $completed = false; |
|
795 | + $lesson_count = 0; |
|
796 | + $completed_count = 0; |
|
797 | + foreach ($lessons as $lesson_id) { |
|
798 | + $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id); |
|
799 | + ++$lesson_count; |
|
800 | + if ($completed) { |
|
801 | + ++$completed_count; |
|
802 | + } |
|
803 | + } |
|
804 | + $module_progress = ($completed_count / $lesson_count) * 100; |
|
805 | + |
|
806 | + return (float)$module_progress; |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * Register admin screen for ordering modules |
|
811 | + * |
|
812 | + * @since 1.8.0 |
|
813 | + * |
|
814 | + * @return void |
|
815 | + */ |
|
816 | + public function register_modules_admin_menu_items() |
|
817 | + { |
|
818 | + //add the modules link under the Course main menu |
|
819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' ); |
|
820 | + |
|
821 | + // Regsiter new admin page for module ordering |
|
822 | + $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen')); |
|
823 | + |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Display Module Order screen |
|
828 | + * |
|
829 | + * @since 1.8.0 |
|
830 | + * |
|
831 | + * @return void |
|
832 | + */ |
|
833 | + public function module_order_screen() |
|
834 | + { |
|
835 | + ?> |
|
836 | 836 | <div id="<?php echo esc_attr($this->order_page_slug); ?>" |
837 | 837 | class="wrap <?php echo esc_attr($this->order_page_slug); ?>"> |
838 | 838 | <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php |
839 | 839 | |
840 | - $html = ''; |
|
841 | - |
|
842 | - if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
843 | - $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
844 | - |
|
845 | - if ($ordered) { |
|
846 | - $html .= '<div class="updated fade">' . "\n"; |
|
847 | - $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
848 | - $html .= '</div>' . "\n"; |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - $courses = Sensei()->course->get_all_courses(); |
|
853 | - |
|
854 | - $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
855 | - $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
856 | - $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
857 | - $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
858 | - $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
859 | - |
|
860 | - foreach ($courses as $course) { |
|
861 | - if (has_term('', $this->taxonomy, $course->ID)) { |
|
862 | - $course_id = ''; |
|
863 | - if (isset($_GET['course_id'])) { |
|
864 | - $course_id = intval($_GET['course_id']); |
|
865 | - } |
|
866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
867 | - } |
|
868 | - } |
|
869 | - |
|
870 | - $html .= '</select>' . "\n"; |
|
871 | - $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
872 | - $html .= '</form>' . "\n"; |
|
873 | - |
|
874 | - if (isset($_GET['course_id'])) { |
|
875 | - $course_id = intval($_GET['course_id']); |
|
876 | - if ($course_id > 0) { |
|
877 | - $modules = $this->get_course_modules($course_id); |
|
878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
879 | - if ($modules) { |
|
880 | - |
|
881 | - $order = $this->get_course_module_order($course_id); |
|
882 | - |
|
883 | - $order_string=''; |
|
884 | - if ($order) { |
|
885 | - $order_string = implode(',', $order); |
|
886 | - } |
|
887 | - |
|
888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
890 | - $count = 0; |
|
891 | - foreach ($modules as $module) { |
|
892 | - $count++; |
|
893 | - $class = $this->taxonomy; |
|
894 | - if ($count == 1) { |
|
895 | - $class .= ' first'; |
|
896 | - } |
|
897 | - if ($count == count($module)) { |
|
898 | - $class .= ' last'; |
|
899 | - } |
|
900 | - if ($count % 2 != 0) { |
|
901 | - $class .= ' alternate'; |
|
902 | - } |
|
903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
904 | - } |
|
905 | - $html .= '</ul>' . "\n"; |
|
906 | - |
|
907 | - $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
908 | - $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
909 | - $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
910 | - $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
911 | - } |
|
912 | - } |
|
913 | - } |
|
914 | - |
|
915 | - echo $html; |
|
916 | - |
|
917 | - ?></div><?php |
|
918 | - } |
|
919 | - |
|
920 | - /** |
|
921 | - * Add 'Module order' column to courses list table |
|
922 | - * |
|
923 | - * @since 1.8.0 |
|
924 | - * |
|
925 | - * @param array $columns Existing columns |
|
926 | - * @return array Modifed columns |
|
927 | - */ |
|
928 | - public function course_columns($columns = array()) |
|
929 | - { |
|
930 | - $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
931 | - return $columns; |
|
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Load content in 'Module order' column |
|
936 | - * |
|
937 | - * @since 1.8.0 |
|
938 | - * |
|
939 | - * @param string $column Current column name |
|
940 | - * @param integer $course_id ID of course |
|
941 | - * @return void |
|
942 | - */ |
|
943 | - public function course_column_content($column = '', $course_id = 0) |
|
944 | - { |
|
945 | - if ($column == 'module_order') { |
|
946 | - if (has_term('', $this->taxonomy, $course_id)) { |
|
947 | - echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
948 | - } |
|
949 | - } |
|
950 | - } |
|
951 | - |
|
952 | - /** |
|
953 | - * Save module order for course |
|
954 | - * |
|
955 | - * @since 1.8.0 |
|
956 | - * |
|
957 | - * @param string $order_string Comma-separated string of module IDs |
|
958 | - * @param integer $course_id ID of course |
|
959 | - * @return boolean True on success, false on failure |
|
960 | - */ |
|
961 | - private function save_course_module_order($order_string = '', $course_id = 0) |
|
962 | - { |
|
963 | - if ($order_string && $course_id) { |
|
964 | - $order = explode(',', $order_string); |
|
965 | - update_post_meta(intval($course_id), '_module_order', $order); |
|
966 | - return true; |
|
967 | - } |
|
968 | - return false; |
|
969 | - } |
|
970 | - |
|
971 | - /** |
|
972 | - * Get module order for course |
|
973 | - * |
|
974 | - * @since 1.8.0 |
|
975 | - * |
|
976 | - * @param integer $course_id ID of course |
|
977 | - * @return mixed Module order on success, false if no module order has been saved |
|
978 | - */ |
|
979 | - public function get_course_module_order($course_id = 0) |
|
980 | - { |
|
981 | - if ($course_id) { |
|
982 | - $order = get_post_meta(intval($course_id), '_module_order', true); |
|
983 | - return $order; |
|
984 | - } |
|
985 | - return false; |
|
986 | - } |
|
987 | - |
|
988 | - /** |
|
989 | - * Modify module taxonomy columns |
|
990 | - * |
|
991 | - * @since 1.8.0 |
|
992 | - * |
|
993 | - * @param array $columns Default columns |
|
994 | - * @return array Modified columns |
|
995 | - */ |
|
996 | - public function taxonomy_column_headings($columns) |
|
997 | - { |
|
998 | - |
|
999 | - unset($columns['posts']); |
|
1000 | - |
|
1001 | - $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
1002 | - |
|
1003 | - return $columns; |
|
1004 | - } |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Manage content in custom module taxonomy columns |
|
1008 | - * |
|
1009 | - * @since 1.8.0 |
|
1010 | - * |
|
1011 | - * @param string $column_data Default data for column |
|
1012 | - * @param string $column_name Name of current column |
|
1013 | - * @param integer $term_id ID of current term |
|
1014 | - * @return string Modified column data |
|
1015 | - */ |
|
1016 | - public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
1017 | - { |
|
1018 | - |
|
1019 | - $args = array( |
|
1020 | - 'post_status' => 'publish', |
|
1021 | - 'posts_per_page' => -1, |
|
1022 | - 'tax_query' => array( |
|
1023 | - array( |
|
1024 | - 'taxonomy' => $this->taxonomy, |
|
1025 | - 'field' => 'id', |
|
1026 | - 'terms' => intval($term_id) |
|
1027 | - ) |
|
1028 | - ) |
|
1029 | - ); |
|
1030 | - |
|
1031 | - $module = get_term($term_id, $this->taxonomy); |
|
1032 | - |
|
1033 | - switch ($column_name) { |
|
1034 | - |
|
1035 | - case 'lessons': |
|
1036 | - $args['post_type'] = 'lesson'; |
|
1037 | - $lessons = get_posts($args); |
|
1038 | - $total_lessons = count($lessons); |
|
1039 | - $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
1040 | - break; |
|
1041 | - } |
|
1042 | - |
|
1043 | - return $column_data; |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Add 'Module' columns to Analysis Lesson Overview table |
|
1048 | - * |
|
1049 | - * @since 1.8.0 |
|
1050 | - * |
|
1051 | - * @param array $columns Default columns |
|
1052 | - * @return array Modified columns |
|
1053 | - */ |
|
1054 | - public function analysis_overview_column_title($columns) |
|
1055 | - { |
|
1056 | - |
|
1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1058 | - $new_columns = array(); |
|
1059 | - if (is_array($columns) && 0 < count($columns)) { |
|
1060 | - foreach ($columns as $column => $title) { |
|
1061 | - $new_columns[$column] = $title; |
|
1062 | - if ($column == 'title') { |
|
1063 | - $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
1064 | - } |
|
1065 | - } |
|
1066 | - } |
|
1067 | - |
|
1068 | - if (0 < count($new_columns)) { |
|
1069 | - return $new_columns; |
|
1070 | - } |
|
1071 | - } |
|
1072 | - |
|
1073 | - return $columns; |
|
1074 | - } |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Data for 'Module' column Analysis Lesson Overview table |
|
1078 | - * |
|
1079 | - * @since 1.8.0 |
|
1080 | - * |
|
1081 | - * @param array $columns Table column data |
|
1082 | - * @param WP_Post $lesson |
|
1083 | - * @return array Updated column data |
|
1084 | - */ |
|
1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
1086 | - { |
|
1087 | - |
|
1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1089 | - $lesson_module = ''; |
|
1090 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
1091 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
1092 | - foreach ($lesson_module_list as $single_module) { |
|
1093 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
1094 | - break; |
|
1095 | - } |
|
1096 | - } |
|
1097 | - |
|
1098 | - $columns['lesson_module'] = $lesson_module; |
|
1099 | - } |
|
1100 | - |
|
1101 | - return $columns; |
|
1102 | - } |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * Add 'Module' columns to Analysis Course table |
|
1106 | - * |
|
1107 | - * @since 1.8.0 |
|
1108 | - * |
|
1109 | - * @param array $columns Default columns |
|
1110 | - * @return array Modified columns |
|
1111 | - */ |
|
1112 | - public function analysis_course_column_title($columns) |
|
1113 | - { |
|
1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1115 | - $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
1116 | - } |
|
1117 | - return $columns; |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * Data for 'Module' column in Analysis Course table |
|
1122 | - * |
|
1123 | - * @since 1.8.0 |
|
1124 | - * |
|
1125 | - * @param array $columns Table column data |
|
1126 | - * @param WP_Post $lesson |
|
1127 | - * @return array Updated columns data |
|
1128 | - */ |
|
1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
1130 | - { |
|
1131 | - |
|
1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
1133 | - $lesson_module = ''; |
|
1134 | - $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
1135 | - if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
1136 | - foreach ($lesson_module_list as $single_module) { |
|
1137 | - $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
1138 | - break; |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - $columns['lesson_module'] = $lesson_module; |
|
1143 | - } |
|
1144 | - |
|
1145 | - return $columns; |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Get module for lesson |
|
1150 | - * |
|
1151 | - * This function also checks if the module still |
|
1152 | - * exists on the course before returning it. Although |
|
1153 | - * the lesson has a module the same module must exist on the |
|
1154 | - * course for it to be valid. |
|
1155 | - * |
|
1156 | - * @since 1.8.0 |
|
1157 | - * |
|
1158 | - * @param integer $lesson_id ID of lesson |
|
1159 | - * @return object Module taxonomy term object |
|
1160 | - */ |
|
1161 | - public function get_lesson_module($lesson_id = 0) |
|
1162 | - { |
|
1163 | - $lesson_id = intval($lesson_id); |
|
1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
1165 | - return false; |
|
1166 | - } |
|
1167 | - |
|
1168 | - // get taxonomy terms on this lesson |
|
1169 | - $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
1170 | - |
|
1171 | - //check if error returned |
|
1172 | - if( empty( $modules ) |
|
1173 | - || is_wp_error( $modules ) |
|
1174 | - || isset( $modules['errors'] ) ){ |
|
1175 | - |
|
1176 | - return false; |
|
1177 | - |
|
1178 | - } |
|
1179 | - |
|
1180 | - // get the last item in the array there should be only be 1 really. |
|
1181 | - // this method works for all php versions. |
|
1182 | - foreach( $modules as $module ){ |
|
1183 | - break; |
|
1184 | - } |
|
1185 | - |
|
1186 | - if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
1187 | - return false; |
|
1188 | - } |
|
1189 | - |
|
1190 | - $module->url = get_term_link($module, $this->taxonomy); |
|
1191 | - $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
1192 | - if (isset($course_id) && 0 < $course_id) { |
|
1193 | - |
|
1194 | - // the course should contain the same module taxonomy term for this to be valid |
|
1195 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
1196 | - return false; |
|
1197 | - } |
|
1198 | - |
|
1199 | - $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
1200 | - } |
|
1201 | - return $module; |
|
1202 | - |
|
1203 | - } |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * Get ordered array of all modules in course |
|
1207 | - * |
|
1208 | - * @since 1.8.0 |
|
1209 | - * |
|
1210 | - * @param integer $course_id ID of course |
|
1211 | - * @return array Ordered array of module taxonomy term objects |
|
1212 | - */ |
|
1213 | - public function get_course_modules($course_id = 0) |
|
1214 | - { |
|
1215 | - $course_id = intval($course_id); |
|
1216 | - if (0 < $course_id) { |
|
1217 | - |
|
1218 | - // Get modules for course |
|
1219 | - $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
1220 | - |
|
1221 | - // Get custom module order for course |
|
1222 | - $order = $this->get_course_module_order($course_id); |
|
1223 | - |
|
1224 | - // Sort by custom order if custom order exists |
|
1225 | - if ($order) { |
|
1226 | - $ordered_modules = array(); |
|
1227 | - $unordered_modules = array(); |
|
1228 | - foreach ($modules as $module) { |
|
1229 | - $order_key = array_search($module->term_id, $order); |
|
1230 | - if ($order_key !== false) { |
|
1231 | - $ordered_modules[$order_key] = $module; |
|
1232 | - } else { |
|
1233 | - $unordered_modules[] = $module; |
|
1234 | - } |
|
1235 | - } |
|
1236 | - |
|
1237 | - // Order modules correctly |
|
1238 | - ksort($ordered_modules); |
|
1239 | - |
|
1240 | - // Append modules that have not yet been ordered |
|
1241 | - if (count($unordered_modules) > 0) { |
|
1242 | - $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
1243 | - } |
|
1244 | - |
|
1245 | - } else { |
|
1246 | - |
|
1247 | - $ordered_modules = $modules; |
|
1248 | - |
|
1249 | - } |
|
1250 | - |
|
1251 | - return $ordered_modules; |
|
1252 | - |
|
1253 | - } |
|
1254 | - |
|
1255 | - return false; |
|
1256 | - } |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Load frontend CSS |
|
1260 | - * |
|
1261 | - * @since 1.8.0 |
|
1262 | - * |
|
1263 | - * @return void |
|
1264 | - */ |
|
1265 | - public function enqueue_styles() { |
|
1266 | - |
|
1267 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
1268 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
1269 | - |
|
1270 | - } |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * Load admin Javascript |
|
1274 | - * |
|
1275 | - * @since 1.8.0 |
|
1276 | - * |
|
1277 | - * @return void |
|
1278 | - */ |
|
1279 | - public function admin_enqueue_scripts( $hook ) { |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * Filter the page hooks where modules admin script can be loaded on. |
|
1283 | - * |
|
1284 | - * @param array $white_listed_pages |
|
1285 | - */ |
|
1286 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
1287 | - 'edit-tags.php', |
|
1288 | - 'course_page_module-order', |
|
1289 | - 'post-new.php', |
|
1290 | - 'post.php' |
|
1291 | - ) ); |
|
1292 | - |
|
1293 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
1294 | - return; |
|
1295 | - } |
|
1296 | - |
|
1297 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1298 | - |
|
1299 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
1300 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
1301 | - wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true ); |
|
1302 | - |
|
1303 | - // localized module data |
|
1304 | - $localize_modulesAdmin = array( |
|
1305 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
1306 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
1307 | - ); |
|
1308 | - |
|
1309 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
1310 | - } |
|
1311 | - |
|
1312 | - /** |
|
1313 | - * Load admin CSS |
|
1314 | - * |
|
1315 | - * @since 1.8.0 |
|
1316 | - * |
|
1317 | - * @return void |
|
1318 | - */ |
|
1319 | - public function admin_enqueue_styles() { |
|
1320 | - |
|
1321 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
1322 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
1323 | - |
|
1324 | - } |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * Show the title modules on the single course template. |
|
1328 | - * |
|
1329 | - * Function is hooked into sensei_single_course_modules_before. |
|
1330 | - * |
|
1331 | - * @since 1.8.0 |
|
1332 | - * @return void |
|
1333 | - */ |
|
1334 | - public function course_modules_title( ) { |
|
1335 | - |
|
1336 | - if( sensei_module_has_lessons() ){ |
|
1337 | - |
|
1338 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
1339 | - |
|
1340 | - } |
|
1341 | - |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Display the single course modules content this will only show |
|
1346 | - * if the course has modules. |
|
1347 | - * |
|
1348 | - * @since 1.8.0 |
|
1349 | - * @return void |
|
1350 | - */ |
|
1351 | - public function load_course_module_content_template(){ |
|
1352 | - |
|
1353 | - // load backwards compatible template name if it exists in the users theme |
|
1354 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
1355 | - if( $located_template ){ |
|
1356 | - |
|
1357 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
1358 | - return; |
|
1359 | - |
|
1360 | - } |
|
1361 | - |
|
1362 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
1363 | - |
|
1364 | - } // end course_module_content |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * Returns all lessons for the given module ID |
|
1368 | - * |
|
1369 | - * @since 1.8.0 |
|
1370 | - * |
|
1371 | - * @param $course_id |
|
1372 | - * @param $term_id |
|
1373 | - * @return array $lessons |
|
1374 | - */ |
|
1375 | - public function get_lessons( $course_id , $term_id ){ |
|
1376 | - |
|
1377 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
1378 | - |
|
1379 | - if( isset( $lesson_query->posts ) ){ |
|
840 | + $html = ''; |
|
841 | + |
|
842 | + if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) { |
|
843 | + $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
|
844 | + |
|
845 | + if ($ordered) { |
|
846 | + $html .= '<div class="updated fade">' . "\n"; |
|
847 | + $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n"; |
|
848 | + $html .= '</div>' . "\n"; |
|
849 | + } |
|
850 | + } |
|
851 | + |
|
852 | + $courses = Sensei()->course->get_all_courses(); |
|
853 | + |
|
854 | + $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n"; |
|
855 | + $html .= '<input type="hidden" name="post_type" value="course" />' . "\n"; |
|
856 | + $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n"; |
|
857 | + $html .= '<select id="module-order-course" name="course_id">' . "\n"; |
|
858 | + $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n"; |
|
859 | + |
|
860 | + foreach ($courses as $course) { |
|
861 | + if (has_term('', $this->taxonomy, $course->ID)) { |
|
862 | + $course_id = ''; |
|
863 | + if (isset($_GET['course_id'])) { |
|
864 | + $course_id = intval($_GET['course_id']); |
|
865 | + } |
|
866 | + $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
867 | + } |
|
868 | + } |
|
869 | + |
|
870 | + $html .= '</select>' . "\n"; |
|
871 | + $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n"; |
|
872 | + $html .= '</form>' . "\n"; |
|
873 | + |
|
874 | + if (isset($_GET['course_id'])) { |
|
875 | + $course_id = intval($_GET['course_id']); |
|
876 | + if ($course_id > 0) { |
|
877 | + $modules = $this->get_course_modules($course_id); |
|
878 | + $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
879 | + if ($modules) { |
|
880 | + |
|
881 | + $order = $this->get_course_module_order($course_id); |
|
882 | + |
|
883 | + $order_string=''; |
|
884 | + if ($order) { |
|
885 | + $order_string = implode(',', $order); |
|
886 | + } |
|
887 | + |
|
888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
889 | + $html .= '<ul class="sortable-module-list">' . "\n"; |
|
890 | + $count = 0; |
|
891 | + foreach ($modules as $module) { |
|
892 | + $count++; |
|
893 | + $class = $this->taxonomy; |
|
894 | + if ($count == 1) { |
|
895 | + $class .= ' first'; |
|
896 | + } |
|
897 | + if ($count == count($module)) { |
|
898 | + $class .= ' last'; |
|
899 | + } |
|
900 | + if ($count % 2 != 0) { |
|
901 | + $class .= ' alternate'; |
|
902 | + } |
|
903 | + $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
904 | + } |
|
905 | + $html .= '</ul>' . "\n"; |
|
906 | + |
|
907 | + $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n"; |
|
908 | + $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n"; |
|
909 | + $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n"; |
|
910 | + $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n"; |
|
911 | + } |
|
912 | + } |
|
913 | + } |
|
914 | + |
|
915 | + echo $html; |
|
916 | + |
|
917 | + ?></div><?php |
|
918 | + } |
|
919 | + |
|
920 | + /** |
|
921 | + * Add 'Module order' column to courses list table |
|
922 | + * |
|
923 | + * @since 1.8.0 |
|
924 | + * |
|
925 | + * @param array $columns Existing columns |
|
926 | + * @return array Modifed columns |
|
927 | + */ |
|
928 | + public function course_columns($columns = array()) |
|
929 | + { |
|
930 | + $columns['module_order'] = __('Module order', 'woothemes-sensei'); |
|
931 | + return $columns; |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Load content in 'Module order' column |
|
936 | + * |
|
937 | + * @since 1.8.0 |
|
938 | + * |
|
939 | + * @param string $column Current column name |
|
940 | + * @param integer $course_id ID of course |
|
941 | + * @return void |
|
942 | + */ |
|
943 | + public function course_column_content($column = '', $course_id = 0) |
|
944 | + { |
|
945 | + if ($column == 'module_order') { |
|
946 | + if (has_term('', $this->taxonomy, $course_id)) { |
|
947 | + echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>'; |
|
948 | + } |
|
949 | + } |
|
950 | + } |
|
951 | + |
|
952 | + /** |
|
953 | + * Save module order for course |
|
954 | + * |
|
955 | + * @since 1.8.0 |
|
956 | + * |
|
957 | + * @param string $order_string Comma-separated string of module IDs |
|
958 | + * @param integer $course_id ID of course |
|
959 | + * @return boolean True on success, false on failure |
|
960 | + */ |
|
961 | + private function save_course_module_order($order_string = '', $course_id = 0) |
|
962 | + { |
|
963 | + if ($order_string && $course_id) { |
|
964 | + $order = explode(',', $order_string); |
|
965 | + update_post_meta(intval($course_id), '_module_order', $order); |
|
966 | + return true; |
|
967 | + } |
|
968 | + return false; |
|
969 | + } |
|
970 | + |
|
971 | + /** |
|
972 | + * Get module order for course |
|
973 | + * |
|
974 | + * @since 1.8.0 |
|
975 | + * |
|
976 | + * @param integer $course_id ID of course |
|
977 | + * @return mixed Module order on success, false if no module order has been saved |
|
978 | + */ |
|
979 | + public function get_course_module_order($course_id = 0) |
|
980 | + { |
|
981 | + if ($course_id) { |
|
982 | + $order = get_post_meta(intval($course_id), '_module_order', true); |
|
983 | + return $order; |
|
984 | + } |
|
985 | + return false; |
|
986 | + } |
|
987 | + |
|
988 | + /** |
|
989 | + * Modify module taxonomy columns |
|
990 | + * |
|
991 | + * @since 1.8.0 |
|
992 | + * |
|
993 | + * @param array $columns Default columns |
|
994 | + * @return array Modified columns |
|
995 | + */ |
|
996 | + public function taxonomy_column_headings($columns) |
|
997 | + { |
|
998 | + |
|
999 | + unset($columns['posts']); |
|
1000 | + |
|
1001 | + $columns['lessons'] = __('Lessons', 'woothemes-sensei'); |
|
1002 | + |
|
1003 | + return $columns; |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Manage content in custom module taxonomy columns |
|
1008 | + * |
|
1009 | + * @since 1.8.0 |
|
1010 | + * |
|
1011 | + * @param string $column_data Default data for column |
|
1012 | + * @param string $column_name Name of current column |
|
1013 | + * @param integer $term_id ID of current term |
|
1014 | + * @return string Modified column data |
|
1015 | + */ |
|
1016 | + public function taxonomy_column_content($column_data, $column_name, $term_id) |
|
1017 | + { |
|
1018 | + |
|
1019 | + $args = array( |
|
1020 | + 'post_status' => 'publish', |
|
1021 | + 'posts_per_page' => -1, |
|
1022 | + 'tax_query' => array( |
|
1023 | + array( |
|
1024 | + 'taxonomy' => $this->taxonomy, |
|
1025 | + 'field' => 'id', |
|
1026 | + 'terms' => intval($term_id) |
|
1027 | + ) |
|
1028 | + ) |
|
1029 | + ); |
|
1030 | + |
|
1031 | + $module = get_term($term_id, $this->taxonomy); |
|
1032 | + |
|
1033 | + switch ($column_name) { |
|
1034 | + |
|
1035 | + case 'lessons': |
|
1036 | + $args['post_type'] = 'lesson'; |
|
1037 | + $lessons = get_posts($args); |
|
1038 | + $total_lessons = count($lessons); |
|
1039 | + $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>'; |
|
1040 | + break; |
|
1041 | + } |
|
1042 | + |
|
1043 | + return $column_data; |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Add 'Module' columns to Analysis Lesson Overview table |
|
1048 | + * |
|
1049 | + * @since 1.8.0 |
|
1050 | + * |
|
1051 | + * @param array $columns Default columns |
|
1052 | + * @return array Modified columns |
|
1053 | + */ |
|
1054 | + public function analysis_overview_column_title($columns) |
|
1055 | + { |
|
1056 | + |
|
1057 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1058 | + $new_columns = array(); |
|
1059 | + if (is_array($columns) && 0 < count($columns)) { |
|
1060 | + foreach ($columns as $column => $title) { |
|
1061 | + $new_columns[$column] = $title; |
|
1062 | + if ($column == 'title') { |
|
1063 | + $new_columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
1064 | + } |
|
1065 | + } |
|
1066 | + } |
|
1067 | + |
|
1068 | + if (0 < count($new_columns)) { |
|
1069 | + return $new_columns; |
|
1070 | + } |
|
1071 | + } |
|
1072 | + |
|
1073 | + return $columns; |
|
1074 | + } |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Data for 'Module' column Analysis Lesson Overview table |
|
1078 | + * |
|
1079 | + * @since 1.8.0 |
|
1080 | + * |
|
1081 | + * @param array $columns Table column data |
|
1082 | + * @param WP_Post $lesson |
|
1083 | + * @return array Updated column data |
|
1084 | + */ |
|
1085 | + public function analysis_overview_column_data($columns, $lesson ) |
|
1086 | + { |
|
1087 | + |
|
1088 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1089 | + $lesson_module = ''; |
|
1090 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
1091 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
1092 | + foreach ($lesson_module_list as $single_module) { |
|
1093 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
1094 | + break; |
|
1095 | + } |
|
1096 | + } |
|
1097 | + |
|
1098 | + $columns['lesson_module'] = $lesson_module; |
|
1099 | + } |
|
1100 | + |
|
1101 | + return $columns; |
|
1102 | + } |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Add 'Module' columns to Analysis Course table |
|
1106 | + * |
|
1107 | + * @since 1.8.0 |
|
1108 | + * |
|
1109 | + * @param array $columns Default columns |
|
1110 | + * @return array Modified columns |
|
1111 | + */ |
|
1112 | + public function analysis_course_column_title($columns) |
|
1113 | + { |
|
1114 | + if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1115 | + $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
|
1116 | + } |
|
1117 | + return $columns; |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * Data for 'Module' column in Analysis Course table |
|
1122 | + * |
|
1123 | + * @since 1.8.0 |
|
1124 | + * |
|
1125 | + * @param array $columns Table column data |
|
1126 | + * @param WP_Post $lesson |
|
1127 | + * @return array Updated columns data |
|
1128 | + */ |
|
1129 | + public function analysis_course_column_data($columns, $lesson ) |
|
1130 | + { |
|
1131 | + |
|
1132 | + if ( isset( $_GET['course_id'] ) ) { |
|
1133 | + $lesson_module = ''; |
|
1134 | + $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
|
1135 | + if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
|
1136 | + foreach ($lesson_module_list as $single_module) { |
|
1137 | + $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>'; |
|
1138 | + break; |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + $columns['lesson_module'] = $lesson_module; |
|
1143 | + } |
|
1144 | + |
|
1145 | + return $columns; |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Get module for lesson |
|
1150 | + * |
|
1151 | + * This function also checks if the module still |
|
1152 | + * exists on the course before returning it. Although |
|
1153 | + * the lesson has a module the same module must exist on the |
|
1154 | + * course for it to be valid. |
|
1155 | + * |
|
1156 | + * @since 1.8.0 |
|
1157 | + * |
|
1158 | + * @param integer $lesson_id ID of lesson |
|
1159 | + * @return object Module taxonomy term object |
|
1160 | + */ |
|
1161 | + public function get_lesson_module($lesson_id = 0) |
|
1162 | + { |
|
1163 | + $lesson_id = intval($lesson_id); |
|
1164 | + if ( ! ( intval( $lesson_id > 0) ) ) { |
|
1165 | + return false; |
|
1166 | + } |
|
1167 | + |
|
1168 | + // get taxonomy terms on this lesson |
|
1169 | + $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
|
1170 | + |
|
1171 | + //check if error returned |
|
1172 | + if( empty( $modules ) |
|
1173 | + || is_wp_error( $modules ) |
|
1174 | + || isset( $modules['errors'] ) ){ |
|
1175 | + |
|
1176 | + return false; |
|
1177 | + |
|
1178 | + } |
|
1179 | + |
|
1180 | + // get the last item in the array there should be only be 1 really. |
|
1181 | + // this method works for all php versions. |
|
1182 | + foreach( $modules as $module ){ |
|
1183 | + break; |
|
1184 | + } |
|
1185 | + |
|
1186 | + if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
1187 | + return false; |
|
1188 | + } |
|
1189 | + |
|
1190 | + $module->url = get_term_link($module, $this->taxonomy); |
|
1191 | + $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
1192 | + if (isset($course_id) && 0 < $course_id) { |
|
1193 | + |
|
1194 | + // the course should contain the same module taxonomy term for this to be valid |
|
1195 | + if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
1196 | + return false; |
|
1197 | + } |
|
1198 | + |
|
1199 | + $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
1200 | + } |
|
1201 | + return $module; |
|
1202 | + |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * Get ordered array of all modules in course |
|
1207 | + * |
|
1208 | + * @since 1.8.0 |
|
1209 | + * |
|
1210 | + * @param integer $course_id ID of course |
|
1211 | + * @return array Ordered array of module taxonomy term objects |
|
1212 | + */ |
|
1213 | + public function get_course_modules($course_id = 0) |
|
1214 | + { |
|
1215 | + $course_id = intval($course_id); |
|
1216 | + if (0 < $course_id) { |
|
1217 | + |
|
1218 | + // Get modules for course |
|
1219 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
1220 | + |
|
1221 | + // Get custom module order for course |
|
1222 | + $order = $this->get_course_module_order($course_id); |
|
1223 | + |
|
1224 | + // Sort by custom order if custom order exists |
|
1225 | + if ($order) { |
|
1226 | + $ordered_modules = array(); |
|
1227 | + $unordered_modules = array(); |
|
1228 | + foreach ($modules as $module) { |
|
1229 | + $order_key = array_search($module->term_id, $order); |
|
1230 | + if ($order_key !== false) { |
|
1231 | + $ordered_modules[$order_key] = $module; |
|
1232 | + } else { |
|
1233 | + $unordered_modules[] = $module; |
|
1234 | + } |
|
1235 | + } |
|
1236 | + |
|
1237 | + // Order modules correctly |
|
1238 | + ksort($ordered_modules); |
|
1239 | + |
|
1240 | + // Append modules that have not yet been ordered |
|
1241 | + if (count($unordered_modules) > 0) { |
|
1242 | + $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
1243 | + } |
|
1244 | + |
|
1245 | + } else { |
|
1246 | + |
|
1247 | + $ordered_modules = $modules; |
|
1248 | + |
|
1249 | + } |
|
1250 | + |
|
1251 | + return $ordered_modules; |
|
1252 | + |
|
1253 | + } |
|
1254 | + |
|
1255 | + return false; |
|
1256 | + } |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Load frontend CSS |
|
1260 | + * |
|
1261 | + * @since 1.8.0 |
|
1262 | + * |
|
1263 | + * @return void |
|
1264 | + */ |
|
1265 | + public function enqueue_styles() { |
|
1266 | + |
|
1267 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
1268 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
1269 | + |
|
1270 | + } |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * Load admin Javascript |
|
1274 | + * |
|
1275 | + * @since 1.8.0 |
|
1276 | + * |
|
1277 | + * @return void |
|
1278 | + */ |
|
1279 | + public function admin_enqueue_scripts( $hook ) { |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * Filter the page hooks where modules admin script can be loaded on. |
|
1283 | + * |
|
1284 | + * @param array $white_listed_pages |
|
1285 | + */ |
|
1286 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
1287 | + 'edit-tags.php', |
|
1288 | + 'course_page_module-order', |
|
1289 | + 'post-new.php', |
|
1290 | + 'post.php' |
|
1291 | + ) ); |
|
1292 | + |
|
1293 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
1294 | + return; |
|
1295 | + } |
|
1296 | + |
|
1297 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1298 | + |
|
1299 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
1300 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
1301 | + wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true ); |
|
1302 | + |
|
1303 | + // localized module data |
|
1304 | + $localize_modulesAdmin = array( |
|
1305 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
1306 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
1307 | + ); |
|
1308 | + |
|
1309 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
1310 | + } |
|
1311 | + |
|
1312 | + /** |
|
1313 | + * Load admin CSS |
|
1314 | + * |
|
1315 | + * @since 1.8.0 |
|
1316 | + * |
|
1317 | + * @return void |
|
1318 | + */ |
|
1319 | + public function admin_enqueue_styles() { |
|
1320 | + |
|
1321 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
1322 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
1323 | + |
|
1324 | + } |
|
1325 | + |
|
1326 | + /** |
|
1327 | + * Show the title modules on the single course template. |
|
1328 | + * |
|
1329 | + * Function is hooked into sensei_single_course_modules_before. |
|
1330 | + * |
|
1331 | + * @since 1.8.0 |
|
1332 | + * @return void |
|
1333 | + */ |
|
1334 | + public function course_modules_title( ) { |
|
1335 | + |
|
1336 | + if( sensei_module_has_lessons() ){ |
|
1337 | + |
|
1338 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
1339 | + |
|
1340 | + } |
|
1341 | + |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Display the single course modules content this will only show |
|
1346 | + * if the course has modules. |
|
1347 | + * |
|
1348 | + * @since 1.8.0 |
|
1349 | + * @return void |
|
1350 | + */ |
|
1351 | + public function load_course_module_content_template(){ |
|
1352 | + |
|
1353 | + // load backwards compatible template name if it exists in the users theme |
|
1354 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
1355 | + if( $located_template ){ |
|
1356 | + |
|
1357 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
1358 | + return; |
|
1359 | + |
|
1360 | + } |
|
1361 | + |
|
1362 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
1363 | + |
|
1364 | + } // end course_module_content |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * Returns all lessons for the given module ID |
|
1368 | + * |
|
1369 | + * @since 1.8.0 |
|
1370 | + * |
|
1371 | + * @param $course_id |
|
1372 | + * @param $term_id |
|
1373 | + * @return array $lessons |
|
1374 | + */ |
|
1375 | + public function get_lessons( $course_id , $term_id ){ |
|
1376 | + |
|
1377 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
1378 | + |
|
1379 | + if( isset( $lesson_query->posts ) ){ |
|
1380 | 1380 | |
1381 | - return $lesson_query->posts; |
|
1381 | + return $lesson_query->posts; |
|
1382 | 1382 | |
1383 | - }else{ |
|
1383 | + }else{ |
|
1384 | 1384 | |
1385 | - return array(); |
|
1385 | + return array(); |
|
1386 | 1386 | |
1387 | - } |
|
1387 | + } |
|
1388 | 1388 | |
1389 | - } // end get lessons |
|
1389 | + } // end get lessons |
|
1390 | 1390 | |
1391 | - /** |
|
1392 | - * Returns all lessons for the given module ID |
|
1393 | - * |
|
1394 | - * @since 1.8.0 |
|
1395 | - * |
|
1396 | - * @param $course_id |
|
1397 | - * @param $term_id |
|
1398 | - * @return WP_Query $lessons_query |
|
1399 | - */ |
|
1400 | - public function get_lessons_query( $course_id , $term_id ){ |
|
1401 | - |
|
1402 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
1403 | - |
|
1404 | - return array(); |
|
1405 | - |
|
1406 | - } |
|
1407 | - |
|
1408 | - $args = array( |
|
1409 | - 'post_type' => 'lesson', |
|
1410 | - 'post_status' => 'publish', |
|
1411 | - 'posts_per_page' => -1, |
|
1412 | - 'meta_query' => array( |
|
1413 | - array( |
|
1414 | - 'key' => '_lesson_course', |
|
1415 | - 'value' => intval($course_id), |
|
1416 | - 'compare' => '=' |
|
1417 | - ) |
|
1418 | - ), |
|
1419 | - 'tax_query' => array( |
|
1420 | - array( |
|
1421 | - 'taxonomy' => 'module', |
|
1422 | - 'field' => 'id', |
|
1423 | - 'terms' => intval( $term_id ) |
|
1424 | - ) |
|
1425 | - ), |
|
1426 | - 'orderby' => 'menu_order', |
|
1427 | - 'order' => 'ASC', |
|
1428 | - 'suppress_filters' => 0 |
|
1429 | - ); |
|
1430 | - |
|
1431 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
1432 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
1433 | - $args['orderby'] = 'meta_value_num date'; |
|
1434 | - } |
|
1435 | - |
|
1436 | - $lessons_query = new WP_Query( $args ); |
|
1437 | - |
|
1438 | - return $lessons_query; |
|
1439 | - |
|
1440 | - } // end get lessons |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * Find the lesson in the given course that doesn't belong |
|
1444 | - * to any of the courses modules |
|
1445 | - * |
|
1446 | - * |
|
1447 | - * @param $course_id |
|
1448 | - * |
|
1449 | - * @return array $non_module_lessons |
|
1450 | - */ |
|
1451 | - public function get_none_module_lessons( $course_id ){ |
|
1452 | - |
|
1453 | - $non_module_lessons = array(); |
|
1454 | - |
|
1455 | - //exit if there is no course id passed in |
|
1456 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
1457 | - |
|
1458 | - return $non_module_lessons; |
|
1459 | - } |
|
1460 | - |
|
1461 | - //save some time and check if we already have the saved |
|
1462 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
1463 | - |
|
1464 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
1465 | - |
|
1466 | - } |
|
1467 | - |
|
1468 | - // create terms array which must be excluded from other arrays |
|
1469 | - $course_modules = $this->get_course_modules( $course_id ); |
|
1470 | - |
|
1471 | - //exit if there are no module on this course |
|
1472 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
1473 | - |
|
1474 | - return Sensei()->course->course_lessons( $course_id ); |
|
1475 | - |
|
1476 | - } |
|
1477 | - |
|
1478 | - $terms = array(); |
|
1479 | - foreach( $course_modules as $module ){ |
|
1480 | - |
|
1481 | - array_push( $terms , $module->term_id ); |
|
1482 | - |
|
1483 | - } |
|
1484 | - |
|
1485 | - $args = array( |
|
1486 | - 'post_type' => 'lesson', |
|
1487 | - 'post_status' => 'publish', |
|
1488 | - 'posts_per_page' => -1, |
|
1489 | - 'meta_query' => array( |
|
1490 | - array( |
|
1491 | - 'key' => '_lesson_course', |
|
1492 | - 'value' => intval( $course_id ), |
|
1493 | - 'compare' => '=' |
|
1494 | - ) |
|
1495 | - ), |
|
1496 | - 'tax_query' => array( |
|
1497 | - array( |
|
1498 | - 'taxonomy' => 'module', |
|
1499 | - 'field' => 'id', |
|
1500 | - 'terms' => $terms, |
|
1501 | - 'operator' => 'NOT IN' |
|
1502 | - ) |
|
1503 | - ), |
|
1504 | - 'orderby' => 'menu_order', |
|
1505 | - 'order' => 'ASC', |
|
1506 | - 'suppress_filters' => 0 |
|
1507 | - ); |
|
1508 | - |
|
1509 | - $wp_lessons_query = new WP_Query( $args ); |
|
1510 | - |
|
1511 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
1512 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
1513 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
1514 | - } |
|
1515 | - |
|
1516 | - return $non_module_lessons; |
|
1517 | - } // end get_none_module_lessons |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Register the modules taxonomy |
|
1521 | - * |
|
1522 | - * @since 1.8.0 |
|
1523 | - */ |
|
1524 | - public function setup_modules_taxonomy(){ |
|
1525 | - |
|
1526 | - $labels = array( |
|
1527 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
1528 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
1529 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
1530 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
1531 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
1532 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
1533 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
1534 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
1535 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
1536 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
1537 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
1538 | - ); |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Filter to alter the Sensei Modules rewrite slug |
|
1542 | - * |
|
1543 | - * @since 1.8.0 |
|
1544 | - * @param string default 'modules' |
|
1545 | - */ |
|
1546 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
1547 | - |
|
1548 | - $args = array( |
|
1549 | - 'public' => true, |
|
1550 | - 'hierarchical' => true, |
|
1551 | - 'show_admin_column' => true, |
|
1552 | - 'capabilities' => array( |
|
1553 | - 'manage_terms' => 'manage_categories', |
|
1554 | - 'edit_terms' => 'edit_courses', |
|
1555 | - 'delete_terms' => 'manage_categories', |
|
1556 | - 'assign_terms' => 'edit_courses' |
|
1557 | - ), |
|
1558 | - 'show_in_nav_menus' => false, |
|
1559 | - 'show_in_quick_edit' => false, |
|
1560 | - 'show_ui' => true, |
|
1561 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
1562 | - 'labels' => $labels |
|
1563 | - ); |
|
1564 | - |
|
1565 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
1566 | - |
|
1567 | - }// end setup_modules_taxonomy |
|
1568 | - |
|
1569 | - /** |
|
1570 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
1571 | - * |
|
1572 | - * This function is hooked into the admin_menu |
|
1573 | - * |
|
1574 | - * @since 1.8.0 |
|
1575 | - * @return void |
|
1576 | - */ |
|
1577 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
1578 | - |
|
1579 | - global $typenow , $taxnow; |
|
1580 | - |
|
1581 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
1582 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
1583 | - } |
|
1584 | - |
|
1585 | - }// end redirect to course taxonomy |
|
1586 | - |
|
1587 | - /** |
|
1588 | - * Completely remove the module menu item under lessons. |
|
1589 | - * |
|
1590 | - * This function is hooked into the admin_menu |
|
1591 | - * |
|
1592 | - * @since 1.8.0 |
|
1593 | - * @return void |
|
1594 | - */ |
|
1595 | - public function remove_lessons_menu_model_taxonomy(){ |
|
1596 | - global $submenu; |
|
1597 | - |
|
1598 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
1599 | - return; // exit |
|
1600 | - } |
|
1601 | - |
|
1602 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
1603 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
1604 | - |
|
1605 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
1606 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
1607 | - } |
|
1608 | - } |
|
1609 | - |
|
1610 | - }// end remove lesson module tax |
|
1611 | - |
|
1612 | - /** |
|
1613 | - * Completely remove the second modules under courses |
|
1614 | - * |
|
1615 | - * This function is hooked into the admin_menu |
|
1616 | - * |
|
1617 | - * @since 1.8.0 |
|
1618 | - * @return void |
|
1619 | - */ |
|
1620 | - public function remove_courses_menu_model_taxonomy(){ |
|
1621 | - global $submenu; |
|
1622 | - |
|
1623 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
1624 | - return; // exit |
|
1625 | - } |
|
1626 | - |
|
1627 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
1628 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
1629 | - |
|
1630 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
1631 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
1632 | - } |
|
1633 | - } |
|
1634 | - |
|
1635 | - }// end remove courses module tax |
|
1636 | - |
|
1637 | - /** |
|
1638 | - * Determine the author of a module term term by looking at |
|
1639 | - * the prefixed author id. This function will query the full term object. |
|
1640 | - * Will return the admin user author could not be determined. |
|
1641 | - * |
|
1642 | - * @since 1.8.0 |
|
1643 | - * |
|
1644 | - * @param string $term_name |
|
1645 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
1646 | - */ |
|
1647 | - public static function get_term_authors( $term_name ){ |
|
1648 | - |
|
1649 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
1650 | - |
|
1651 | - $owners = array(); |
|
1652 | - if( empty( $terms ) ){ |
|
1653 | - |
|
1654 | - return $owners; |
|
1391 | + /** |
|
1392 | + * Returns all lessons for the given module ID |
|
1393 | + * |
|
1394 | + * @since 1.8.0 |
|
1395 | + * |
|
1396 | + * @param $course_id |
|
1397 | + * @param $term_id |
|
1398 | + * @return WP_Query $lessons_query |
|
1399 | + */ |
|
1400 | + public function get_lessons_query( $course_id , $term_id ){ |
|
1401 | + |
|
1402 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
1403 | + |
|
1404 | + return array(); |
|
1405 | + |
|
1406 | + } |
|
1407 | + |
|
1408 | + $args = array( |
|
1409 | + 'post_type' => 'lesson', |
|
1410 | + 'post_status' => 'publish', |
|
1411 | + 'posts_per_page' => -1, |
|
1412 | + 'meta_query' => array( |
|
1413 | + array( |
|
1414 | + 'key' => '_lesson_course', |
|
1415 | + 'value' => intval($course_id), |
|
1416 | + 'compare' => '=' |
|
1417 | + ) |
|
1418 | + ), |
|
1419 | + 'tax_query' => array( |
|
1420 | + array( |
|
1421 | + 'taxonomy' => 'module', |
|
1422 | + 'field' => 'id', |
|
1423 | + 'terms' => intval( $term_id ) |
|
1424 | + ) |
|
1425 | + ), |
|
1426 | + 'orderby' => 'menu_order', |
|
1427 | + 'order' => 'ASC', |
|
1428 | + 'suppress_filters' => 0 |
|
1429 | + ); |
|
1430 | + |
|
1431 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
1432 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
1433 | + $args['orderby'] = 'meta_value_num date'; |
|
1434 | + } |
|
1435 | + |
|
1436 | + $lessons_query = new WP_Query( $args ); |
|
1437 | + |
|
1438 | + return $lessons_query; |
|
1439 | + |
|
1440 | + } // end get lessons |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * Find the lesson in the given course that doesn't belong |
|
1444 | + * to any of the courses modules |
|
1445 | + * |
|
1446 | + * |
|
1447 | + * @param $course_id |
|
1448 | + * |
|
1449 | + * @return array $non_module_lessons |
|
1450 | + */ |
|
1451 | + public function get_none_module_lessons( $course_id ){ |
|
1452 | + |
|
1453 | + $non_module_lessons = array(); |
|
1454 | + |
|
1455 | + //exit if there is no course id passed in |
|
1456 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
1457 | + |
|
1458 | + return $non_module_lessons; |
|
1459 | + } |
|
1460 | + |
|
1461 | + //save some time and check if we already have the saved |
|
1462 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
1463 | + |
|
1464 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
1465 | + |
|
1466 | + } |
|
1467 | + |
|
1468 | + // create terms array which must be excluded from other arrays |
|
1469 | + $course_modules = $this->get_course_modules( $course_id ); |
|
1470 | + |
|
1471 | + //exit if there are no module on this course |
|
1472 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
1473 | + |
|
1474 | + return Sensei()->course->course_lessons( $course_id ); |
|
1475 | + |
|
1476 | + } |
|
1477 | + |
|
1478 | + $terms = array(); |
|
1479 | + foreach( $course_modules as $module ){ |
|
1480 | + |
|
1481 | + array_push( $terms , $module->term_id ); |
|
1482 | + |
|
1483 | + } |
|
1484 | + |
|
1485 | + $args = array( |
|
1486 | + 'post_type' => 'lesson', |
|
1487 | + 'post_status' => 'publish', |
|
1488 | + 'posts_per_page' => -1, |
|
1489 | + 'meta_query' => array( |
|
1490 | + array( |
|
1491 | + 'key' => '_lesson_course', |
|
1492 | + 'value' => intval( $course_id ), |
|
1493 | + 'compare' => '=' |
|
1494 | + ) |
|
1495 | + ), |
|
1496 | + 'tax_query' => array( |
|
1497 | + array( |
|
1498 | + 'taxonomy' => 'module', |
|
1499 | + 'field' => 'id', |
|
1500 | + 'terms' => $terms, |
|
1501 | + 'operator' => 'NOT IN' |
|
1502 | + ) |
|
1503 | + ), |
|
1504 | + 'orderby' => 'menu_order', |
|
1505 | + 'order' => 'ASC', |
|
1506 | + 'suppress_filters' => 0 |
|
1507 | + ); |
|
1508 | + |
|
1509 | + $wp_lessons_query = new WP_Query( $args ); |
|
1510 | + |
|
1511 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
1512 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
1513 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
1514 | + } |
|
1515 | + |
|
1516 | + return $non_module_lessons; |
|
1517 | + } // end get_none_module_lessons |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Register the modules taxonomy |
|
1521 | + * |
|
1522 | + * @since 1.8.0 |
|
1523 | + */ |
|
1524 | + public function setup_modules_taxonomy(){ |
|
1525 | + |
|
1526 | + $labels = array( |
|
1527 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
1528 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
1529 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
1530 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
1531 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
1532 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
1533 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
1534 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
1535 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
1536 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
1537 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
1538 | + ); |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Filter to alter the Sensei Modules rewrite slug |
|
1542 | + * |
|
1543 | + * @since 1.8.0 |
|
1544 | + * @param string default 'modules' |
|
1545 | + */ |
|
1546 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
1547 | + |
|
1548 | + $args = array( |
|
1549 | + 'public' => true, |
|
1550 | + 'hierarchical' => true, |
|
1551 | + 'show_admin_column' => true, |
|
1552 | + 'capabilities' => array( |
|
1553 | + 'manage_terms' => 'manage_categories', |
|
1554 | + 'edit_terms' => 'edit_courses', |
|
1555 | + 'delete_terms' => 'manage_categories', |
|
1556 | + 'assign_terms' => 'edit_courses' |
|
1557 | + ), |
|
1558 | + 'show_in_nav_menus' => false, |
|
1559 | + 'show_in_quick_edit' => false, |
|
1560 | + 'show_ui' => true, |
|
1561 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
1562 | + 'labels' => $labels |
|
1563 | + ); |
|
1564 | + |
|
1565 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
1566 | + |
|
1567 | + }// end setup_modules_taxonomy |
|
1568 | + |
|
1569 | + /** |
|
1570 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
1571 | + * |
|
1572 | + * This function is hooked into the admin_menu |
|
1573 | + * |
|
1574 | + * @since 1.8.0 |
|
1575 | + * @return void |
|
1576 | + */ |
|
1577 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
1578 | + |
|
1579 | + global $typenow , $taxnow; |
|
1580 | + |
|
1581 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
1582 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
1583 | + } |
|
1584 | + |
|
1585 | + }// end redirect to course taxonomy |
|
1586 | + |
|
1587 | + /** |
|
1588 | + * Completely remove the module menu item under lessons. |
|
1589 | + * |
|
1590 | + * This function is hooked into the admin_menu |
|
1591 | + * |
|
1592 | + * @since 1.8.0 |
|
1593 | + * @return void |
|
1594 | + */ |
|
1595 | + public function remove_lessons_menu_model_taxonomy(){ |
|
1596 | + global $submenu; |
|
1597 | + |
|
1598 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
1599 | + return; // exit |
|
1600 | + } |
|
1601 | + |
|
1602 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
1603 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
1604 | + |
|
1605 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
1606 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
1607 | + } |
|
1608 | + } |
|
1609 | + |
|
1610 | + }// end remove lesson module tax |
|
1611 | + |
|
1612 | + /** |
|
1613 | + * Completely remove the second modules under courses |
|
1614 | + * |
|
1615 | + * This function is hooked into the admin_menu |
|
1616 | + * |
|
1617 | + * @since 1.8.0 |
|
1618 | + * @return void |
|
1619 | + */ |
|
1620 | + public function remove_courses_menu_model_taxonomy(){ |
|
1621 | + global $submenu; |
|
1622 | + |
|
1623 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
1624 | + return; // exit |
|
1625 | + } |
|
1626 | + |
|
1627 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
1628 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
1629 | + |
|
1630 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
1631 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
1632 | + } |
|
1633 | + } |
|
1634 | + |
|
1635 | + }// end remove courses module tax |
|
1636 | + |
|
1637 | + /** |
|
1638 | + * Determine the author of a module term term by looking at |
|
1639 | + * the prefixed author id. This function will query the full term object. |
|
1640 | + * Will return the admin user author could not be determined. |
|
1641 | + * |
|
1642 | + * @since 1.8.0 |
|
1643 | + * |
|
1644 | + * @param string $term_name |
|
1645 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
1646 | + */ |
|
1647 | + public static function get_term_authors( $term_name ){ |
|
1648 | + |
|
1649 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
1650 | + |
|
1651 | + $owners = array(); |
|
1652 | + if( empty( $terms ) ){ |
|
1653 | + |
|
1654 | + return $owners; |
|
1655 | 1655 | |
1656 | - } |
|
1656 | + } |
|
1657 | 1657 | |
1658 | - // setup the admin user |
|
1658 | + // setup the admin user |
|
1659 | 1659 | |
1660 | 1660 | |
1661 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
1662 | - foreach( $terms as $term){ |
|
1663 | - if( $term->name == $term_name ){ |
|
1661 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
1662 | + foreach( $terms as $term){ |
|
1663 | + if( $term->name == $term_name ){ |
|
1664 | 1664 | |
1665 | - // look for the author in the slug |
|
1666 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1665 | + // look for the author in the slug |
|
1666 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1667 | 1667 | |
1668 | - }// end if term name |
|
1668 | + }// end if term name |
|
1669 | 1669 | |
1670 | - } // end for each |
|
1670 | + } // end for each |
|
1671 | 1671 | |
1672 | - return $owners; |
|
1672 | + return $owners; |
|
1673 | 1673 | |
1674 | - }// end get_term_author |
|
1674 | + }// end get_term_author |
|
1675 | 1675 | |
1676 | - /** |
|
1677 | - * Looks at a term slug and figures out |
|
1678 | - * which author created the slug. The author was |
|
1679 | - * appended when the user saved the module term in the course edit |
|
1680 | - * screen. |
|
1681 | - * |
|
1682 | - * @since 1.8.0 |
|
1683 | - * |
|
1684 | - * @param $slug |
|
1685 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
1686 | - */ |
|
1687 | - public static function get_term_author( $slug='' ){ |
|
1676 | + /** |
|
1677 | + * Looks at a term slug and figures out |
|
1678 | + * which author created the slug. The author was |
|
1679 | + * appended when the user saved the module term in the course edit |
|
1680 | + * screen. |
|
1681 | + * |
|
1682 | + * @since 1.8.0 |
|
1683 | + * |
|
1684 | + * @param $slug |
|
1685 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
1686 | + */ |
|
1687 | + public static function get_term_author( $slug='' ){ |
|
1688 | 1688 | |
1689 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
1689 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
1690 | 1690 | |
1691 | - if( empty( $slug ) ){ |
|
1691 | + if( empty( $slug ) ){ |
|
1692 | 1692 | |
1693 | - return $term_owner; |
|
1693 | + return $term_owner; |
|
1694 | 1694 | |
1695 | - } |
|
1695 | + } |
|
1696 | 1696 | |
1697 | - // look for the author in the slug |
|
1698 | - $slug_parts = explode( '-', $slug ); |
|
1697 | + // look for the author in the slug |
|
1698 | + $slug_parts = explode( '-', $slug ); |
|
1699 | 1699 | |
1700 | - if( count( $slug_parts ) > 1 ){ |
|
1700 | + if( count( $slug_parts ) > 1 ){ |
|
1701 | 1701 | |
1702 | - // get the user data |
|
1703 | - $possible_user_id = $slug_parts[0]; |
|
1704 | - $author = get_userdata( $possible_user_id ); |
|
1702 | + // get the user data |
|
1703 | + $possible_user_id = $slug_parts[0]; |
|
1704 | + $author = get_userdata( $possible_user_id ); |
|
1705 | 1705 | |
1706 | - // if the user doesnt exist for the first part of the slug |
|
1707 | - // then this slug was also created by admin |
|
1708 | - if( is_a( $author, 'WP_User' ) ){ |
|
1706 | + // if the user doesnt exist for the first part of the slug |
|
1707 | + // then this slug was also created by admin |
|
1708 | + if( is_a( $author, 'WP_User' ) ){ |
|
1709 | 1709 | |
1710 | - $term_owner = $author; |
|
1710 | + $term_owner = $author; |
|
1711 | 1711 | |
1712 | - } |
|
1713 | - } |
|
1712 | + } |
|
1713 | + } |
|
1714 | 1714 | |
1715 | - return $term_owner; |
|
1716 | - } |
|
1715 | + return $term_owner; |
|
1716 | + } |
|
1717 | 1717 | |
1718 | - /** |
|
1719 | - * Display the Sensei modules taxonomy terms metabox |
|
1720 | - * |
|
1721 | - * @since 1.8.0 |
|
1722 | - * |
|
1723 | - * @hooked into add_meta_box |
|
1724 | - * |
|
1725 | - * @param WP_Post $post Post object. |
|
1726 | - */ |
|
1727 | - public function course_module_metabox( $post ) { |
|
1718 | + /** |
|
1719 | + * Display the Sensei modules taxonomy terms metabox |
|
1720 | + * |
|
1721 | + * @since 1.8.0 |
|
1722 | + * |
|
1723 | + * @hooked into add_meta_box |
|
1724 | + * |
|
1725 | + * @param WP_Post $post Post object. |
|
1726 | + */ |
|
1727 | + public function course_module_metabox( $post ) { |
|
1728 | 1728 | |
1729 | - $tax_name = 'module'; |
|
1730 | - $taxonomy = get_taxonomy( 'module' ); |
|
1729 | + $tax_name = 'module'; |
|
1730 | + $taxonomy = get_taxonomy( 'module' ); |
|
1731 | 1731 | |
1732 | - ?> |
|
1732 | + ?> |
|
1733 | 1733 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
1734 | 1734 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
1735 | 1735 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1744,9 +1744,9 @@ discard block |
||
1744 | 1744 | |
1745 | 1745 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
1746 | 1746 | <?php |
1747 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
1748 | - echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
1749 | - ?> |
|
1747 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
1748 | + echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
1749 | + ?> |
|
1750 | 1750 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
1751 | 1751 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
1752 | 1752 | </ul> |
@@ -1756,9 +1756,9 @@ discard block |
||
1756 | 1756 | <h4> |
1757 | 1757 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
1758 | 1758 | <?php |
1759 | - /* translators: %s: add new taxonomy label */ |
|
1760 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
1761 | - ?> |
|
1759 | + /* translators: %s: add new taxonomy label */ |
|
1760 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
1761 | + ?> |
|
1762 | 1762 | </a> |
1763 | 1763 | </h4> |
1764 | 1764 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1773,331 +1773,331 @@ discard block |
||
1773 | 1773 | </div> |
1774 | 1774 | <?php |
1775 | 1775 | |
1776 | - } // end course_module_metabox |
|
1776 | + } // end course_module_metabox |
|
1777 | 1777 | |
1778 | 1778 | |
1779 | - /** |
|
1780 | - * Submits a new module term prefixed with the |
|
1781 | - * the current author id. |
|
1782 | - * |
|
1783 | - * @since 1.8.0 |
|
1784 | - */ |
|
1785 | - public static function add_new_module_term( ) { |
|
1779 | + /** |
|
1780 | + * Submits a new module term prefixed with the |
|
1781 | + * the current author id. |
|
1782 | + * |
|
1783 | + * @since 1.8.0 |
|
1784 | + */ |
|
1785 | + public static function add_new_module_term( ) { |
|
1786 | 1786 | |
1787 | 1787 | |
1788 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
1789 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
1790 | - } |
|
1788 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
1789 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
1790 | + } |
|
1791 | 1791 | |
1792 | - // get the term an create the new term storing infomration |
|
1793 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
1792 | + // get the term an create the new term storing infomration |
|
1793 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
1794 | 1794 | |
1795 | - if( current_user_can('manage_options' ) ) { |
|
1795 | + if( current_user_can('manage_options' ) ) { |
|
1796 | 1796 | |
1797 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
1797 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
1798 | 1798 | |
1799 | - } else { |
|
1799 | + } else { |
|
1800 | 1800 | |
1801 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
1801 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
1802 | 1802 | |
1803 | - } |
|
1803 | + } |
|
1804 | 1804 | |
1805 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
1805 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
1806 | 1806 | |
1807 | - // save the term |
|
1808 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
1807 | + // save the term |
|
1808 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
1809 | 1809 | |
1810 | - // send error for all errors except term exits |
|
1811 | - if( is_wp_error( $slug ) ){ |
|
1810 | + // send error for all errors except term exits |
|
1811 | + if( is_wp_error( $slug ) ){ |
|
1812 | 1812 | |
1813 | - // prepare for possible term name and id to be passed down if term exists |
|
1814 | - $term_data = array(); |
|
1813 | + // prepare for possible term name and id to be passed down if term exists |
|
1814 | + $term_data = array(); |
|
1815 | 1815 | |
1816 | - // if term exists also send back the term name and id |
|
1817 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
1816 | + // if term exists also send back the term name and id |
|
1817 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
1818 | 1818 | |
1819 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
1820 | - $term_data['name'] = $term_name; |
|
1821 | - $term_data['id'] = $term->term_id; |
|
1819 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
1820 | + $term_data['name'] = $term_name; |
|
1821 | + $term_data['id'] = $term->term_id; |
|
1822 | 1822 | |
1823 | - // set the object terms |
|
1824 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
1825 | - } |
|
1823 | + // set the object terms |
|
1824 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
1825 | + } |
|
1826 | 1826 | |
1827 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
1827 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
1828 | 1828 | |
1829 | - } |
|
1829 | + } |
|
1830 | 1830 | |
1831 | - //make sure the new term is checked for this course |
|
1831 | + //make sure the new term is checked for this course |
|
1832 | 1832 | |
1833 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
1833 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
1834 | 1834 | |
1835 | - // Handle request then generate response using WP_Ajax_Response |
|
1836 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
1835 | + // Handle request then generate response using WP_Ajax_Response |
|
1836 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
1837 | 1837 | |
1838 | - } |
|
1838 | + } |
|
1839 | 1839 | |
1840 | - /** |
|
1841 | - * Limit the course module metabox |
|
1842 | - * term list to only those on courses belonging to current teacher. |
|
1843 | - * |
|
1844 | - * Hooked into 'get_terms' |
|
1845 | - * |
|
1846 | - * @since 1.8.0 |
|
1847 | - */ |
|
1848 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
1840 | + /** |
|
1841 | + * Limit the course module metabox |
|
1842 | + * term list to only those on courses belonging to current teacher. |
|
1843 | + * |
|
1844 | + * Hooked into 'get_terms' |
|
1845 | + * |
|
1846 | + * @since 1.8.0 |
|
1847 | + */ |
|
1848 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
1849 | 1849 | |
1850 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1851 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
1852 | - return $terms; |
|
1853 | - } |
|
1850 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1851 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
1852 | + return $terms; |
|
1853 | + } |
|
1854 | 1854 | |
1855 | - // avoid infinite call loop |
|
1856 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1855 | + // avoid infinite call loop |
|
1856 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1857 | 1857 | |
1858 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1859 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
1860 | - // change only scrub the terms ids form the array keys |
|
1861 | - $terms = array_keys( $terms ); |
|
1862 | - } |
|
1858 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1859 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
1860 | + // change only scrub the terms ids form the array keys |
|
1861 | + $terms = array_keys( $terms ); |
|
1862 | + } |
|
1863 | 1863 | |
1864 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1864 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1865 | 1865 | |
1866 | - // add filter again as removed above |
|
1867 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1866 | + // add filter again as removed above |
|
1867 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1868 | 1868 | |
1869 | - return $teachers_terms; |
|
1870 | - }// end filter_module_terms |
|
1869 | + return $teachers_terms; |
|
1870 | + }// end filter_module_terms |
|
1871 | 1871 | |
1872 | - /** |
|
1873 | - * For the selected items on a course module only return those |
|
1874 | - * for the current user. This does not apply to admin and super admin users. |
|
1875 | - * |
|
1876 | - * hooked into get_object_terms |
|
1877 | - * |
|
1878 | - * @since 1.8.0 |
|
1879 | - */ |
|
1880 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
1872 | + /** |
|
1873 | + * For the selected items on a course module only return those |
|
1874 | + * for the current user. This does not apply to admin and super admin users. |
|
1875 | + * |
|
1876 | + * hooked into get_object_terms |
|
1877 | + * |
|
1878 | + * @since 1.8.0 |
|
1879 | + */ |
|
1880 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
1881 | 1881 | |
1882 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1883 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
1884 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
1885 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
1886 | - return $terms; |
|
1887 | - } |
|
1882 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1883 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
1884 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
1885 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
1886 | + return $terms; |
|
1887 | + } |
|
1888 | 1888 | |
1889 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1889 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1890 | 1890 | |
1891 | - // if term objects were passed in send back objects |
|
1892 | - // if term id were passed in send that back |
|
1893 | - if( is_object( $terms[0] ) ){ |
|
1894 | - return $term_objects; |
|
1895 | - } |
|
1891 | + // if term objects were passed in send back objects |
|
1892 | + // if term id were passed in send that back |
|
1893 | + if( is_object( $terms[0] ) ){ |
|
1894 | + return $term_objects; |
|
1895 | + } |
|
1896 | 1896 | |
1897 | - $terms = array(); |
|
1898 | - foreach( $term_objects as $term_object ){ |
|
1899 | - $terms[] = $term_object->term_id; |
|
1900 | - } |
|
1897 | + $terms = array(); |
|
1898 | + foreach( $term_objects as $term_object ){ |
|
1899 | + $terms[] = $term_object->term_id; |
|
1900 | + } |
|
1901 | 1901 | |
1902 | - return $terms; |
|
1902 | + return $terms; |
|
1903 | 1903 | |
1904 | 1904 | |
1905 | - }// end filter_course_selected_terms |
|
1905 | + }// end filter_course_selected_terms |
|
1906 | 1906 | |
1907 | - /** |
|
1908 | - * Filter the given terms and only return the |
|
1909 | - * terms that belong to the given user id. |
|
1910 | - * |
|
1911 | - * @since 1.8.0 |
|
1912 | - * @param $terms |
|
1913 | - * @param $user_id |
|
1914 | - * @return array |
|
1915 | - */ |
|
1916 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
1907 | + /** |
|
1908 | + * Filter the given terms and only return the |
|
1909 | + * terms that belong to the given user id. |
|
1910 | + * |
|
1911 | + * @since 1.8.0 |
|
1912 | + * @param $terms |
|
1913 | + * @param $user_id |
|
1914 | + * @return array |
|
1915 | + */ |
|
1916 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
1917 | 1917 | |
1918 | - $users_terms = array(); |
|
1918 | + $users_terms = array(); |
|
1919 | 1919 | |
1920 | - foreach( $terms as $index => $term ){ |
|
1920 | + foreach( $terms as $index => $term ){ |
|
1921 | 1921 | |
1922 | - if( is_numeric( $term ) ){ |
|
1923 | - // the term id was given, get the term object |
|
1924 | - $term = get_term( $term, 'module' ); |
|
1925 | - } |
|
1922 | + if( is_numeric( $term ) ){ |
|
1923 | + // the term id was given, get the term object |
|
1924 | + $term = get_term( $term, 'module' ); |
|
1925 | + } |
|
1926 | 1926 | |
1927 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1927 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1928 | 1928 | |
1929 | - if ( $user_id == $author->ID ) { |
|
1930 | - // add the term to the teachers terms |
|
1931 | - $users_terms[] = $term; |
|
1932 | - } |
|
1929 | + if ( $user_id == $author->ID ) { |
|
1930 | + // add the term to the teachers terms |
|
1931 | + $users_terms[] = $term; |
|
1932 | + } |
|
1933 | 1933 | |
1934 | - } |
|
1934 | + } |
|
1935 | 1935 | |
1936 | - return $users_terms; |
|
1936 | + return $users_terms; |
|
1937 | 1937 | |
1938 | - } // end filter terms by owner |
|
1938 | + } // end filter terms by owner |
|
1939 | 1939 | |
1940 | - /** |
|
1941 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
1942 | - * This will not add name to terms belonging to admin user. |
|
1943 | - * |
|
1944 | - * Hooked into 'get_terms' |
|
1945 | - * |
|
1946 | - * @since 1.8.0 |
|
1947 | - */ |
|
1948 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
1949 | - { |
|
1940 | + /** |
|
1941 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
1942 | + * This will not add name to terms belonging to admin user. |
|
1943 | + * |
|
1944 | + * Hooked into 'get_terms' |
|
1945 | + * |
|
1946 | + * @since 1.8.0 |
|
1947 | + */ |
|
1948 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
1949 | + { |
|
1950 | 1950 | |
1951 | - // only for admin users ont he module taxonomy |
|
1952 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
1953 | - return $terms; |
|
1954 | - } |
|
1951 | + // only for admin users ont he module taxonomy |
|
1952 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
1953 | + return $terms; |
|
1954 | + } |
|
1955 | 1955 | |
1956 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1957 | - // simply return this as wp doesn't need an array of stdObject Term |
|
1958 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
1956 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1957 | + // simply return this as wp doesn't need an array of stdObject Term |
|
1958 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
1959 | 1959 | |
1960 | - return $terms; |
|
1960 | + return $terms; |
|
1961 | 1961 | |
1962 | - } |
|
1962 | + } |
|
1963 | 1963 | |
1964 | - // loop through and update all terms adding the author name |
|
1965 | - foreach( $terms as $index => $term ){ |
|
1964 | + // loop through and update all terms adding the author name |
|
1965 | + foreach( $terms as $index => $term ){ |
|
1966 | 1966 | |
1967 | - if( is_numeric( $term ) ){ |
|
1968 | - // the term id was given, get the term object |
|
1969 | - $term = get_term( $term, 'module' ); |
|
1970 | - } |
|
1967 | + if( is_numeric( $term ) ){ |
|
1968 | + // the term id was given, get the term object |
|
1969 | + $term = get_term( $term, 'module' ); |
|
1970 | + } |
|
1971 | 1971 | |
1972 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1972 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1973 | 1973 | |
1974 | - if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) { |
|
1975 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
1976 | - } |
|
1974 | + if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) { |
|
1975 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
1976 | + } |
|
1977 | 1977 | |
1978 | - // add the term to the teachers terms |
|
1979 | - $users_terms[] = $term; |
|
1978 | + // add the term to the teachers terms |
|
1979 | + $users_terms[] = $term; |
|
1980 | 1980 | |
1981 | - } |
|
1981 | + } |
|
1982 | 1982 | |
1983 | - return $users_terms; |
|
1984 | - } |
|
1983 | + return $users_terms; |
|
1984 | + } |
|
1985 | 1985 | |
1986 | - /** |
|
1987 | - * Remove modules metabox that come by default |
|
1988 | - * with the modules taxonomy. We are removing this as |
|
1989 | - * we have created our own custom meta box. |
|
1990 | - */ |
|
1991 | - public static function remove_default_modules_box() { |
|
1986 | + /** |
|
1987 | + * Remove modules metabox that come by default |
|
1988 | + * with the modules taxonomy. We are removing this as |
|
1989 | + * we have created our own custom meta box. |
|
1990 | + */ |
|
1991 | + public static function remove_default_modules_box() { |
|
1992 | 1992 | |
1993 | - remove_meta_box('modulediv', 'course', 'side'); |
|
1993 | + remove_meta_box('modulediv', 'course', 'side'); |
|
1994 | 1994 | |
1995 | - } |
|
1995 | + } |
|
1996 | 1996 | |
1997 | - /** |
|
1998 | - * When a course is save make sure to reset the transient set |
|
1999 | - * for it when determining the none module lessons. |
|
2000 | - * |
|
2001 | - * @sine 1.9.0 |
|
2002 | - * @param $post_id |
|
2003 | - */ |
|
2004 | - public static function reset_none_modules_transient ( $post_id ){ |
|
1997 | + /** |
|
1998 | + * When a course is save make sure to reset the transient set |
|
1999 | + * for it when determining the none module lessons. |
|
2000 | + * |
|
2001 | + * @sine 1.9.0 |
|
2002 | + * @param $post_id |
|
2003 | + */ |
|
2004 | + public static function reset_none_modules_transient ( $post_id ){ |
|
2005 | 2005 | |
2006 | - // this should only apply to course and lesson post types |
|
2007 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
2006 | + // this should only apply to course and lesson post types |
|
2007 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
2008 | 2008 | |
2009 | - $course_id = ''; |
|
2009 | + $course_id = ''; |
|
2010 | 2010 | |
2011 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
2011 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
2012 | 2012 | |
2013 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
2013 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
2014 | 2014 | |
2015 | - } |
|
2015 | + } |
|
2016 | 2016 | |
2017 | 2017 | |
2018 | - if( !empty( $course_id ) ){ |
|
2018 | + if( !empty( $course_id ) ){ |
|
2019 | 2019 | |
2020 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
2020 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
2021 | 2021 | |
2022 | - } |
|
2022 | + } |
|
2023 | 2023 | |
2024 | - } // end if is a course or a lesson |
|
2024 | + } // end if is a course or a lesson |
|
2025 | 2025 | |
2026 | - } // end reset_none_modules_transient |
|
2026 | + } // end reset_none_modules_transient |
|
2027 | 2027 | |
2028 | - /** |
|
2029 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
2030 | - * |
|
2031 | - * @since 1.9.0 |
|
2032 | - * @deprecated since 1.9.0 |
|
2033 | - * |
|
2034 | - */ |
|
2035 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
2028 | + /** |
|
2029 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
2030 | + * |
|
2031 | + * @since 1.9.0 |
|
2032 | + * @deprecated since 1.9.0 |
|
2033 | + * |
|
2034 | + */ |
|
2035 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
2036 | 2036 | |
2037 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
2037 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
2038 | 2038 | |
2039 | - } |
|
2039 | + } |
|
2040 | 2040 | |
2041 | - /** |
|
2042 | - * Setup the single course module loop. |
|
2043 | - * |
|
2044 | - * Setup the global $sensei_modules_loop |
|
2045 | - * |
|
2046 | - * @since 1.9.0 |
|
2047 | - */ |
|
2048 | - public static function setup_single_course_module_loop(){ |
|
2041 | + /** |
|
2042 | + * Setup the single course module loop. |
|
2043 | + * |
|
2044 | + * Setup the global $sensei_modules_loop |
|
2045 | + * |
|
2046 | + * @since 1.9.0 |
|
2047 | + */ |
|
2048 | + public static function setup_single_course_module_loop(){ |
|
2049 | 2049 | |
2050 | - global $sensei_modules_loop, $post; |
|
2051 | - $course_id = $post->ID; |
|
2050 | + global $sensei_modules_loop, $post; |
|
2051 | + $course_id = $post->ID; |
|
2052 | 2052 | |
2053 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
2053 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
2054 | 2054 | |
2055 | - //initial setup |
|
2056 | - $sensei_modules_loop['total'] = 0; |
|
2057 | - $sensei_modules_loop['modules'] = array(); |
|
2058 | - $sensei_modules_loop['current'] = -1; |
|
2055 | + //initial setup |
|
2056 | + $sensei_modules_loop['total'] = 0; |
|
2057 | + $sensei_modules_loop['modules'] = array(); |
|
2058 | + $sensei_modules_loop['current'] = -1; |
|
2059 | 2059 | |
2060 | - // exit if this course doesn't have modules |
|
2061 | - if( !$modules || empty( $modules ) ){ |
|
2062 | - return; |
|
2063 | - } |
|
2060 | + // exit if this course doesn't have modules |
|
2061 | + if( !$modules || empty( $modules ) ){ |
|
2062 | + return; |
|
2063 | + } |
|
2064 | 2064 | |
2065 | 2065 | |
2066 | - $lessons_in_all_modules = array(); |
|
2067 | - foreach( $modules as $term ){ |
|
2066 | + $lessons_in_all_modules = array(); |
|
2067 | + foreach( $modules as $term ){ |
|
2068 | 2068 | |
2069 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
2070 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
2069 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
2070 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
2071 | 2071 | |
2072 | - } |
|
2072 | + } |
|
2073 | 2073 | |
2074 | 2074 | |
2075 | - //setup all of the modules loop variables |
|
2076 | - $sensei_modules_loop['total'] = count( $modules ); |
|
2077 | - $sensei_modules_loop['modules'] = $modules; |
|
2078 | - $sensei_modules_loop['current'] = -1; |
|
2079 | - $sensei_modules_loop['course_id'] = $course_id; |
|
2075 | + //setup all of the modules loop variables |
|
2076 | + $sensei_modules_loop['total'] = count( $modules ); |
|
2077 | + $sensei_modules_loop['modules'] = $modules; |
|
2078 | + $sensei_modules_loop['current'] = -1; |
|
2079 | + $sensei_modules_loop['course_id'] = $course_id; |
|
2080 | 2080 | |
2081 | - }// end setup_single_course_module_loop |
|
2081 | + }// end setup_single_course_module_loop |
|
2082 | 2082 | |
2083 | - /** |
|
2084 | - * Tear down the course module loop. |
|
2085 | - * |
|
2086 | - * @since 1.9.0 |
|
2087 | - * |
|
2088 | - */ |
|
2089 | - public static function teardown_single_course_module_loop(){ |
|
2083 | + /** |
|
2084 | + * Tear down the course module loop. |
|
2085 | + * |
|
2086 | + * @since 1.9.0 |
|
2087 | + * |
|
2088 | + */ |
|
2089 | + public static function teardown_single_course_module_loop(){ |
|
2090 | 2090 | |
2091 | - global $sensei_modules_loop, $wp_query, $post; |
|
2091 | + global $sensei_modules_loop, $wp_query, $post; |
|
2092 | 2092 | |
2093 | - //reset all of the modules loop variables |
|
2094 | - $sensei_modules_loop['total'] = 0; |
|
2095 | - $sensei_modules_loop['modules'] = array(); |
|
2096 | - $sensei_modules_loop['current'] = -1; |
|
2093 | + //reset all of the modules loop variables |
|
2094 | + $sensei_modules_loop['total'] = 0; |
|
2095 | + $sensei_modules_loop['modules'] = array(); |
|
2096 | + $sensei_modules_loop['current'] = -1; |
|
2097 | 2097 | |
2098 | - // set the current course to be the global post again |
|
2099 | - wp_reset_query(); |
|
2100 | - $post = $wp_query->post; |
|
2101 | - }// end teardown_single_course_module_loop |
|
2098 | + // set the current course to be the global post again |
|
2099 | + wp_reset_query(); |
|
2100 | + $post = $wp_query->post; |
|
2101 | + }// end teardown_single_course_module_loop |
|
2102 | 2102 | |
2103 | 2103 | } // end modules class |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @since 1.0.0 |
21 | 21 | */ |
22 | 22 | public function __construct () { |
23 | - $this->token = 'question'; |
|
23 | + $this->token = 'question'; |
|
24 | 24 | $this->question_types = $this->question_types(); |
25 | 25 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
26 | 26 | if ( is_admin() ) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | if( isset( $post->ID ) ) { |
119 | 119 | |
120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
120 | + $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
121 | 121 | |
122 | 122 | if( $question_type ) { |
123 | 123 | $type = $this->question_types[ $question_type ]; |
@@ -237,15 +237,15 @@ discard block |
||
237 | 237 | public function save_question( $post_id = 0 ) { |
238 | 238 | |
239 | 239 | if( ! isset( $_POST['post_type'] |
240 | - ) || 'question' != $_POST['post_type'] ) { |
|
241 | - return; |
|
242 | - } |
|
240 | + ) || 'question' != $_POST['post_type'] ) { |
|
241 | + return; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | 245 | |
246 | - //setup the data for saving |
|
246 | + //setup the data for saving |
|
247 | 247 | $data = $_POST ; |
248 | - $data['quiz_id'] = 0; |
|
248 | + $data['quiz_id'] = 0; |
|
249 | 249 | $data['question_id'] = $post_id; |
250 | 250 | |
251 | 251 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -339,34 +339,34 @@ discard block |
||
339 | 339 | return $request; |
340 | 340 | } |
341 | 341 | |
342 | - /** |
|
343 | - * Get the type of question by id |
|
344 | - * |
|
345 | - * This function uses the post terms to determine which question type |
|
346 | - * the passed question id belongs to. |
|
347 | - * |
|
348 | - * @since 1.7.4 |
|
349 | - * |
|
350 | - * @param int $question_id |
|
351 | - * |
|
352 | - * @return string $question_type | bool |
|
353 | - */ |
|
354 | - public function get_question_type( $question_id ){ |
|
355 | - |
|
356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
357 | - || 'question' != get_post_type( $question_id ) ){ |
|
358 | - return false; |
|
359 | - } |
|
360 | - |
|
361 | - $question_type = 'multiple-choice'; |
|
362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
363 | - foreach( $question_types as $type ) { |
|
364 | - $question_type = $type->slug; |
|
365 | - } |
|
366 | - |
|
367 | - return $question_type; |
|
368 | - |
|
369 | - }// end get_question_type |
|
342 | + /** |
|
343 | + * Get the type of question by id |
|
344 | + * |
|
345 | + * This function uses the post terms to determine which question type |
|
346 | + * the passed question id belongs to. |
|
347 | + * |
|
348 | + * @since 1.7.4 |
|
349 | + * |
|
350 | + * @param int $question_id |
|
351 | + * |
|
352 | + * @return string $question_type | bool |
|
353 | + */ |
|
354 | + public function get_question_type( $question_id ){ |
|
355 | + |
|
356 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
357 | + || 'question' != get_post_type( $question_id ) ){ |
|
358 | + return false; |
|
359 | + } |
|
360 | + |
|
361 | + $question_type = 'multiple-choice'; |
|
362 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
363 | + foreach( $question_types as $type ) { |
|
364 | + $question_type = $type->slug; |
|
365 | + } |
|
366 | + |
|
367 | + return $question_type; |
|
368 | + |
|
369 | + }// end get_question_type |
|
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Given a question ID, return the grade that can be achieved. |
@@ -398,317 +398,317 @@ discard block |
||
398 | 398 | } // end get_question_grade |
399 | 399 | |
400 | 400 | |
401 | - /** |
|
402 | - * This function simply loads the question type template |
|
403 | - * |
|
404 | - * @since 1.9.0 |
|
405 | - * @param $question_type |
|
406 | - */ |
|
407 | - public static function load_question_template( $question_type ){ |
|
408 | - |
|
409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Echo the sensei question title. |
|
414 | - * |
|
415 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
416 | - * |
|
417 | - * @since 1.9.0 |
|
418 | - * @param $question_id |
|
419 | - */ |
|
420 | - public static function the_question_title( $question_id ){ |
|
421 | - |
|
422 | - echo self::get_the_question_title( $question_id ); |
|
423 | - |
|
424 | - }// end the_question_title |
|
425 | - |
|
426 | - /** |
|
427 | - * Generate the question title with it's grade. |
|
428 | - * |
|
429 | - * @since 1.9.0 |
|
430 | - * |
|
431 | - * @param $question_id |
|
432 | - * @return string |
|
433 | - */ |
|
434 | - public static function get_the_question_title( $question_id ){ |
|
435 | - |
|
436 | - /** |
|
437 | - * Filter the sensei question title |
|
438 | - * |
|
439 | - * @since 1.3.0 |
|
440 | - * @param $question_title |
|
441 | - */ |
|
442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
443 | - |
|
444 | - /** |
|
445 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
446 | - */ |
|
447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
448 | - |
|
449 | - $title_html = '<span class="question question-title">'; |
|
450 | - $title_html .= $title; |
|
451 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
452 | - $title_html .='</span>'; |
|
453 | - |
|
454 | - return $title_html; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Tech the question description |
|
459 | - * |
|
460 | - * @param $question_id |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public static function get_the_question_description( $question_id ){ |
|
464 | - |
|
465 | - $question = get_post( $question_id ); |
|
466 | - |
|
467 | - /** |
|
468 | - * Already documented within WordPress Core |
|
469 | - */ |
|
470 | - return apply_filters( 'the_content', $question->post_content ); |
|
471 | - |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Output the question description |
|
476 | - * |
|
477 | - * @since 1.9.0 |
|
478 | - * @param $question_id |
|
479 | - */ |
|
480 | - public static function the_question_description( $question_id ){ |
|
481 | - |
|
482 | - echo self::get_the_question_description( $question_id ); |
|
483 | - |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the questions media markup |
|
488 | - * |
|
489 | - * @since 1.9.0 |
|
490 | - * @param $question_id |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public static function get_the_question_media( $question_id ){ |
|
494 | - |
|
495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
496 | - $question_media_link = ''; |
|
497 | - if( 0 < intval( $question_media ) ) { |
|
498 | - $mimetype = get_post_mime_type( $question_media ); |
|
499 | - if( $mimetype ) { |
|
500 | - $mimetype_array = explode( '/', $mimetype); |
|
501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
502 | - $question_media_type = $mimetype_array[0]; |
|
503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
504 | - $attachment = get_post( $question_media ); |
|
505 | - $question_media_title = $attachment->post_title; |
|
506 | - $question_media_description = $attachment->post_content; |
|
507 | - switch( $question_media_type ) { |
|
508 | - case 'image': |
|
509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
512 | - break; |
|
513 | - |
|
514 | - case 'audio': |
|
515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
516 | - break; |
|
517 | - |
|
518 | - case 'video': |
|
519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
520 | - break; |
|
521 | - |
|
522 | - default: |
|
523 | - $question_media_filename = basename( $question_media_url ); |
|
524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
525 | - break; |
|
526 | - } |
|
527 | - } |
|
528 | - } |
|
529 | - } |
|
530 | - |
|
531 | - $output = ''; |
|
532 | - if( $question_media_link ) { |
|
533 | - |
|
534 | - $output .= '<div class="question_media_display">'; |
|
535 | - $output .= $question_media_link; |
|
536 | - $output .= '<dl>'; |
|
537 | - |
|
538 | - if( $question_media_title ) { |
|
539 | - |
|
540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
541 | - |
|
542 | - } |
|
543 | - |
|
544 | - if( $question_media_description ) { |
|
545 | - |
|
546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
547 | - |
|
548 | - } |
|
549 | - |
|
550 | - $output .= '</dl>'; |
|
551 | - $output .= '</div>'; |
|
401 | + /** |
|
402 | + * This function simply loads the question type template |
|
403 | + * |
|
404 | + * @since 1.9.0 |
|
405 | + * @param $question_type |
|
406 | + */ |
|
407 | + public static function load_question_template( $question_type ){ |
|
408 | + |
|
409 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Echo the sensei question title. |
|
414 | + * |
|
415 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
416 | + * |
|
417 | + * @since 1.9.0 |
|
418 | + * @param $question_id |
|
419 | + */ |
|
420 | + public static function the_question_title( $question_id ){ |
|
421 | + |
|
422 | + echo self::get_the_question_title( $question_id ); |
|
423 | + |
|
424 | + }// end the_question_title |
|
425 | + |
|
426 | + /** |
|
427 | + * Generate the question title with it's grade. |
|
428 | + * |
|
429 | + * @since 1.9.0 |
|
430 | + * |
|
431 | + * @param $question_id |
|
432 | + * @return string |
|
433 | + */ |
|
434 | + public static function get_the_question_title( $question_id ){ |
|
435 | + |
|
436 | + /** |
|
437 | + * Filter the sensei question title |
|
438 | + * |
|
439 | + * @since 1.3.0 |
|
440 | + * @param $question_title |
|
441 | + */ |
|
442 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
443 | + |
|
444 | + /** |
|
445 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
446 | + */ |
|
447 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
448 | + |
|
449 | + $title_html = '<span class="question question-title">'; |
|
450 | + $title_html .= $title; |
|
451 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
452 | + $title_html .='</span>'; |
|
453 | + |
|
454 | + return $title_html; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Tech the question description |
|
459 | + * |
|
460 | + * @param $question_id |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public static function get_the_question_description( $question_id ){ |
|
464 | + |
|
465 | + $question = get_post( $question_id ); |
|
466 | + |
|
467 | + /** |
|
468 | + * Already documented within WordPress Core |
|
469 | + */ |
|
470 | + return apply_filters( 'the_content', $question->post_content ); |
|
471 | + |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Output the question description |
|
476 | + * |
|
477 | + * @since 1.9.0 |
|
478 | + * @param $question_id |
|
479 | + */ |
|
480 | + public static function the_question_description( $question_id ){ |
|
481 | + |
|
482 | + echo self::get_the_question_description( $question_id ); |
|
483 | + |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the questions media markup |
|
488 | + * |
|
489 | + * @since 1.9.0 |
|
490 | + * @param $question_id |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public static function get_the_question_media( $question_id ){ |
|
494 | + |
|
495 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
496 | + $question_media_link = ''; |
|
497 | + if( 0 < intval( $question_media ) ) { |
|
498 | + $mimetype = get_post_mime_type( $question_media ); |
|
499 | + if( $mimetype ) { |
|
500 | + $mimetype_array = explode( '/', $mimetype); |
|
501 | + if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
502 | + $question_media_type = $mimetype_array[0]; |
|
503 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
504 | + $attachment = get_post( $question_media ); |
|
505 | + $question_media_title = $attachment->post_title; |
|
506 | + $question_media_description = $attachment->post_content; |
|
507 | + switch( $question_media_type ) { |
|
508 | + case 'image': |
|
509 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
510 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
511 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
512 | + break; |
|
513 | + |
|
514 | + case 'audio': |
|
515 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
516 | + break; |
|
517 | + |
|
518 | + case 'video': |
|
519 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
520 | + break; |
|
521 | + |
|
522 | + default: |
|
523 | + $question_media_filename = basename( $question_media_url ); |
|
524 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
525 | + break; |
|
526 | + } |
|
527 | + } |
|
528 | + } |
|
529 | + } |
|
530 | + |
|
531 | + $output = ''; |
|
532 | + if( $question_media_link ) { |
|
552 | 533 | |
534 | + $output .= '<div class="question_media_display">'; |
|
535 | + $output .= $question_media_link; |
|
536 | + $output .= '<dl>'; |
|
553 | 537 | |
554 | - } |
|
555 | - |
|
556 | - return $output; |
|
557 | - |
|
558 | - } // end get_the_question_media |
|
559 | - |
|
538 | + if( $question_media_title ) { |
|
560 | 539 | |
561 | - /** |
|
562 | - * Output the question media |
|
563 | - * |
|
564 | - * @since 1.9.0 |
|
565 | - * @param string $question_id |
|
566 | - */ |
|
567 | - public static function the_question_media( $question_id ){ |
|
540 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
568 | 541 | |
569 | - echo self::get_the_question_media( $question_id ); |
|
542 | + } |
|
570 | 543 | |
571 | - } |
|
544 | + if( $question_media_description ) { |
|
572 | 545 | |
573 | - /** |
|
574 | - * Output a special field for the question needed for question submission. |
|
575 | - * |
|
576 | - * @since 1.9.0 |
|
577 | - * |
|
578 | - * @param $question_id |
|
579 | - */ |
|
580 | - public static function the_question_hidden_fields( $question_id ){ |
|
581 | - ?> |
|
546 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
547 | + |
|
548 | + } |
|
549 | + |
|
550 | + $output .= '</dl>'; |
|
551 | + $output .= '</div>'; |
|
552 | + |
|
553 | + |
|
554 | + } |
|
555 | + |
|
556 | + return $output; |
|
557 | + |
|
558 | + } // end get_the_question_media |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Output the question media |
|
563 | + * |
|
564 | + * @since 1.9.0 |
|
565 | + * @param string $question_id |
|
566 | + */ |
|
567 | + public static function the_question_media( $question_id ){ |
|
568 | + |
|
569 | + echo self::get_the_question_media( $question_id ); |
|
570 | + |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Output a special field for the question needed for question submission. |
|
575 | + * |
|
576 | + * @since 1.9.0 |
|
577 | + * |
|
578 | + * @param $question_id |
|
579 | + */ |
|
580 | + public static function the_question_hidden_fields( $question_id ){ |
|
581 | + ?> |
|
582 | 582 | |
583 | 583 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
584 | 584 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
585 | 585 | |
586 | 586 | <?php |
587 | - } |
|
587 | + } |
|
588 | 588 | |
589 | - /** |
|
590 | - * This function can only be run withing the single quiz question loop |
|
591 | - * |
|
592 | - * @since 1.9.0 |
|
593 | - * @param $question_id |
|
594 | - */ |
|
595 | - public static function answer_feedback_notes( $question_id ){ |
|
589 | + /** |
|
590 | + * This function can only be run withing the single quiz question loop |
|
591 | + * |
|
592 | + * @since 1.9.0 |
|
593 | + * @param $question_id |
|
594 | + */ |
|
595 | + public static function answer_feedback_notes( $question_id ){ |
|
596 | 596 | |
597 | - //IDS |
|
598 | - $quiz_id = get_the_ID(); |
|
599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
597 | + //IDS |
|
598 | + $quiz_id = get_the_ID(); |
|
599 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
600 | 600 | |
601 | - // Data to check before showing feedback |
|
602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
601 | + // Data to check before showing feedback |
|
602 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
604 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
606 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
607 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
608 | 608 | |
609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
609 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
610 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
611 | + || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
612 | 612 | |
613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
614 | 614 | |
615 | - if( $answer_notes ) { ?> |
|
615 | + if( $answer_notes ) { ?> |
|
616 | 616 | |
617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
618 | 618 | |
619 | 619 | <?php |
620 | 620 | |
621 | - /** |
|
622 | - * Filter the answer feedback |
|
623 | - * Since 1.9.0 |
|
624 | - * |
|
625 | - * @param string $answer_notes |
|
626 | - * @param string $question_id |
|
627 | - * @param string $lesson_id |
|
628 | - */ |
|
629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
621 | + /** |
|
622 | + * Filter the answer feedback |
|
623 | + * Since 1.9.0 |
|
624 | + * |
|
625 | + * @param string $answer_notes |
|
626 | + * @param string $question_id |
|
627 | + * @param string $lesson_id |
|
628 | + */ |
|
629 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
630 | 630 | |
631 | - ?> |
|
631 | + ?> |
|
632 | 632 | |
633 | 633 | </div> |
634 | 634 | |
635 | 635 | <?php } |
636 | 636 | |
637 | - }// end if we can show answer feedback |
|
637 | + }// end if we can show answer feedback |
|
638 | 638 | |
639 | - }// end answer_feedback_notes |
|
639 | + }// end answer_feedback_notes |
|
640 | 640 | |
641 | - /** |
|
642 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
643 | - * |
|
644 | - * |
|
645 | - * @since 1.9.0 |
|
646 | - * @param string $question_id |
|
647 | - */ |
|
648 | - public static function the_answer_result_indication( $question_id ){ |
|
641 | + /** |
|
642 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
643 | + * |
|
644 | + * |
|
645 | + * @since 1.9.0 |
|
646 | + * @param string $question_id |
|
647 | + */ |
|
648 | + public static function the_answer_result_indication( $question_id ){ |
|
649 | 649 | |
650 | - global $post, $current_user, $sensei_question_loop; |
|
650 | + global $post, $current_user, $sensei_question_loop; |
|
651 | 651 | |
652 | - // Post Data |
|
653 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
655 | - $question_item = $sensei_question_loop['current_question']; |
|
652 | + // Post Data |
|
653 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
654 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
655 | + $question_item = $sensei_question_loop['current_question']; |
|
656 | 656 | |
657 | - // Setup variable needed to determine if the message should show and what it should show |
|
658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
657 | + // Setup variable needed to determine if the message should show and what it should show |
|
658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
659 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
661 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
662 | 662 | |
663 | - // retrieve the question total grade |
|
664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
663 | + // retrieve the question total grade |
|
664 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
665 | 665 | |
666 | - // retrieve grade the user achieved |
|
667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
666 | + // retrieve grade the user achieved |
|
667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
668 | 668 | |
669 | - // Question ID |
|
670 | - $question_id = $question_item->ID; |
|
669 | + // Question ID |
|
670 | + $question_id = $question_item->ID; |
|
671 | 671 | |
672 | - // conditions to check |
|
673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
672 | + // conditions to check |
|
673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
676 | 676 | |
677 | - if ( $completed_with_valid_grade |
|
678 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
677 | + if ( $completed_with_valid_grade |
|
678 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
680 | 680 | |
681 | - $user_correct = false; |
|
682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
683 | - $answer_message_class = 'user_wrong'; |
|
684 | - // For zero grade mark as 'correct' but add no classes |
|
685 | - if ( 0 == $question_grade ) { |
|
681 | + $user_correct = false; |
|
682 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
683 | + $answer_message_class = 'user_wrong'; |
|
684 | + // For zero grade mark as 'correct' but add no classes |
|
685 | + if ( 0 == $question_grade ) { |
|
686 | 686 | |
687 | - $user_correct = true; |
|
688 | - $answer_message = ''; |
|
689 | - $answer_message_class = ''; |
|
687 | + $user_correct = true; |
|
688 | + $answer_message = ''; |
|
689 | + $answer_message_class = ''; |
|
690 | 690 | |
691 | - } else if( $user_question_grade > 0 ) { |
|
691 | + } else if( $user_question_grade > 0 ) { |
|
692 | 692 | |
693 | - $user_correct = true; |
|
694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
695 | - $answer_message_class = 'user_right'; |
|
693 | + $user_correct = true; |
|
694 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
695 | + $answer_message_class = 'user_right'; |
|
696 | 696 | |
697 | - } |
|
697 | + } |
|
698 | 698 | |
699 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
699 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
700 | + if( !$reset_quiz_allowed && !$user_correct ){ |
|
701 | 701 | |
702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
702 | + $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
703 | 703 | |
704 | - } |
|
704 | + } |
|
705 | 705 | |
706 | - // answer feedback |
|
707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
708 | - if( $answer_notes ) { |
|
709 | - $answer_message_class .= ' has_notes'; |
|
710 | - } |
|
711 | - ?> |
|
706 | + // answer feedback |
|
707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
708 | + if( $answer_notes ) { |
|
709 | + $answer_message_class .= ' has_notes'; |
|
710 | + } |
|
711 | + ?> |
|
712 | 712 | |
713 | 713 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
714 | 714 | |
@@ -718,387 +718,387 @@ discard block |
||
718 | 718 | |
719 | 719 | <?php |
720 | 720 | |
721 | - } // end if user can see all the goodies |
|
722 | - |
|
723 | - }// end the_answer_result_indication |
|
724 | - |
|
725 | - /** |
|
726 | - * Generate the question template data and return it as an array. |
|
727 | - * |
|
728 | - * @since 1.9.0 |
|
729 | - * |
|
730 | - * @param string $question_id |
|
731 | - * @param $quiz_id |
|
732 | - * @return array $question_data |
|
733 | - */ |
|
734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
735 | - |
|
736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
737 | - |
|
738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
739 | - //backwards compatibility |
|
740 | - if( 'on' == $reset_allowed ) { |
|
741 | - $reset_allowed = 1; |
|
742 | - } |
|
743 | - |
|
744 | - // Check again that the lesson is complete |
|
745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
746 | - $user_lesson_complete = false; |
|
747 | - if ( $user_lesson_end ) { |
|
748 | - $user_lesson_complete = true; |
|
749 | - } |
|
750 | - |
|
751 | - //setup the question data |
|
752 | - $data[ 'ID' ] = $question_id; |
|
753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
767 | - |
|
768 | - /** |
|
769 | - * Filter the question template data. This filter fires in |
|
770 | - * the get_template_data function |
|
771 | - * |
|
772 | - * @hooked self::boolean_load_question_data |
|
773 | - * |
|
774 | - * @since 1.9.0 |
|
775 | - * |
|
776 | - * @param array $data |
|
777 | - * @param string $question_id |
|
778 | - * @param string $quiz_id |
|
779 | - */ |
|
780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
721 | + } // end if user can see all the goodies |
|
781 | 722 | |
782 | - } |
|
723 | + }// end the_answer_result_indication |
|
783 | 724 | |
784 | - /** |
|
785 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
786 | - * filter. |
|
787 | - * |
|
788 | - * @since 1.9.0 |
|
789 | - * |
|
790 | - * @param $question_data |
|
791 | - * @param $question_id |
|
792 | - * @param $quiz_id |
|
793 | - * |
|
794 | - * @return array() |
|
795 | - */ |
|
796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
725 | + /** |
|
726 | + * Generate the question template data and return it as an array. |
|
727 | + * |
|
728 | + * @since 1.9.0 |
|
729 | + * |
|
730 | + * @param string $question_id |
|
731 | + * @param $quiz_id |
|
732 | + * @return array $question_data |
|
733 | + */ |
|
734 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
797 | 735 | |
736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
798 | 737 | |
799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
738 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
739 | + //backwards compatibility |
|
740 | + if( 'on' == $reset_allowed ) { |
|
741 | + $reset_allowed = 1; |
|
742 | + } |
|
800 | 743 | |
801 | - // Get uploaded file |
|
802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
803 | - $answer_media_url = $answer_media_filename = ''; |
|
744 | + // Check again that the lesson is complete |
|
745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
746 | + $user_lesson_complete = false; |
|
747 | + if ( $user_lesson_end ) { |
|
748 | + $user_lesson_complete = true; |
|
749 | + } |
|
804 | 750 | |
751 | + //setup the question data |
|
752 | + $data[ 'ID' ] = $question_id; |
|
753 | + $data[ 'title' ] = get_the_title( $question_id ); |
|
754 | + $data[ 'content' ] = get_post( $question_id )->post_content; |
|
755 | + $data[ 'quiz_id' ] = $quiz_id; |
|
756 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
757 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
758 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
759 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
760 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
761 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
762 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
763 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
764 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
765 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
766 | + $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
767 | + |
|
768 | + /** |
|
769 | + * Filter the question template data. This filter fires in |
|
770 | + * the get_template_data function |
|
771 | + * |
|
772 | + * @hooked self::boolean_load_question_data |
|
773 | + * |
|
774 | + * @since 1.9.0 |
|
775 | + * |
|
776 | + * @param array $data |
|
777 | + * @param string $question_id |
|
778 | + * @param string $quiz_id |
|
779 | + */ |
|
780 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
805 | 781 | |
806 | - $question_helptext = ''; |
|
807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
782 | + } |
|
808 | 783 | |
809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
784 | + /** |
|
785 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
786 | + * filter. |
|
787 | + * |
|
788 | + * @since 1.9.0 |
|
789 | + * |
|
790 | + * @param $question_data |
|
791 | + * @param $question_id |
|
792 | + * @param $quiz_id |
|
793 | + * |
|
794 | + * @return array() |
|
795 | + */ |
|
796 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
810 | 797 | |
811 | - } |
|
812 | 798 | |
799 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
813 | 800 | |
814 | - if( 0 < intval( $attachment_id ) ) { |
|
801 | + // Get uploaded file |
|
802 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
803 | + $answer_media_url = $answer_media_filename = ''; |
|
815 | 804 | |
816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
817 | - $answer_media_filename = basename( $answer_media_url ); |
|
818 | 805 | |
819 | - } |
|
806 | + $question_helptext = ''; |
|
807 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
820 | 808 | |
809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
821 | 810 | |
822 | - // Get max upload file size, formatted for display |
|
823 | - // Code copied from wp-admin/includes/media.php:1515 |
|
824 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
827 | - $upload_size_unit /= 1024; |
|
828 | - } |
|
829 | - if ( $u < 0 ) { |
|
811 | + } |
|
830 | 812 | |
831 | - $upload_size_unit = 0; |
|
832 | - $u = 0; |
|
833 | 813 | |
834 | - } else { |
|
814 | + if( 0 < intval( $attachment_id ) ) { |
|
835 | 815 | |
836 | - $upload_size_unit = (int) $upload_size_unit; |
|
816 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
817 | + $answer_media_filename = basename( $answer_media_url ); |
|
837 | 818 | |
838 | - } |
|
839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
819 | + } |
|
840 | 820 | |
841 | - // Assemble all the data needed by the file upload template |
|
842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
845 | 821 | |
846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
822 | + // Get max upload file size, formatted for display |
|
823 | + // Code copied from wp-admin/includes/media.php:1515 |
|
824 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
825 | + $sizes = array( 'KB', 'MB', 'GB' ); |
|
826 | + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
827 | + $upload_size_unit /= 1024; |
|
828 | + } |
|
829 | + if ( $u < 0 ) { |
|
847 | 830 | |
848 | - }// end if is file upload type |
|
831 | + $upload_size_unit = 0; |
|
832 | + $u = 0; |
|
849 | 833 | |
850 | - return $question_data; |
|
834 | + } else { |
|
851 | 835 | |
852 | - }// end file_upload_load_question_data |
|
836 | + $upload_size_unit = (int) $upload_size_unit; |
|
853 | 837 | |
854 | - /** |
|
855 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
856 | - * filter. |
|
857 | - * |
|
858 | - * @since 1.9.0 |
|
859 | - * |
|
860 | - * @param $question_data |
|
861 | - * @param $question_id |
|
862 | - * @param $quiz_id |
|
863 | - * |
|
864 | - * @return array() |
|
865 | - */ |
|
866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
838 | + } |
|
839 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
867 | 840 | |
868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
841 | + // Assemble all the data needed by the file upload template |
|
842 | + $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
843 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
844 | + $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
869 | 845 | |
846 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
870 | 847 | |
871 | - $answer_type = 'radio'; |
|
872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
848 | + }// end if is file upload type |
|
873 | 849 | |
874 | - $answer_type = 'checkbox'; |
|
850 | + return $question_data; |
|
875 | 851 | |
876 | - } |
|
852 | + }// end file_upload_load_question_data |
|
877 | 853 | |
878 | - // Merge right and wrong answers |
|
879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
854 | + /** |
|
855 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
856 | + * filter. |
|
857 | + * |
|
858 | + * @since 1.9.0 |
|
859 | + * |
|
860 | + * @param $question_data |
|
861 | + * @param $question_id |
|
862 | + * @param $quiz_id |
|
863 | + * |
|
864 | + * @return array() |
|
865 | + */ |
|
866 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
880 | 867 | |
881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
868 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
882 | 869 | |
883 | - } else { |
|
884 | 870 | |
885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
871 | + $answer_type = 'radio'; |
|
872 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
887 | 873 | |
888 | - } |
|
874 | + $answer_type = 'checkbox'; |
|
889 | 875 | |
890 | - // Setup answer options array. |
|
891 | - $question_answers_options = array(); |
|
892 | - $count = 0; |
|
876 | + } |
|
893 | 877 | |
894 | - foreach( $merged_options as $answer ) { |
|
878 | + // Merge right and wrong answers |
|
879 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
895 | 880 | |
896 | - $count++; |
|
897 | - $question_option = array(); |
|
881 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
898 | 882 | |
899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
883 | + } else { |
|
902 | 884 | |
903 | - $user_correct = false; |
|
885 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
886 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
904 | 887 | |
888 | + } |
|
905 | 889 | |
906 | - // For zero grade mark as 'correct' but add no classes |
|
907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
890 | + // Setup answer options array. |
|
891 | + $question_answers_options = array(); |
|
892 | + $count = 0; |
|
908 | 893 | |
909 | - $user_correct = true; |
|
894 | + foreach( $merged_options as $answer ) { |
|
910 | 895 | |
911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
896 | + $count++; |
|
897 | + $question_option = array(); |
|
912 | 898 | |
913 | - $user_correct = true; |
|
899 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
900 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
901 | + || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
914 | 902 | |
915 | - } |
|
903 | + $user_correct = false; |
|
916 | 904 | |
917 | - } |
|
918 | 905 | |
919 | - // setup the option specific classes |
|
920 | - $answer_class = ''; |
|
921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
906 | + // For zero grade mark as 'correct' but add no classes |
|
907 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
923 | 908 | |
924 | - $answer_class .= ' right_answer'; |
|
909 | + $user_correct = true; |
|
925 | 910 | |
926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
911 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
927 | 912 | |
928 | - $answer_class .= ' right_answer'; |
|
913 | + $user_correct = true; |
|
929 | 914 | |
930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
915 | + } |
|
932 | 916 | |
933 | - $answer_class = 'user_wrong'; |
|
934 | - if( $user_correct ) { |
|
917 | + } |
|
935 | 918 | |
936 | - $answer_class = 'user_right'; |
|
919 | + // setup the option specific classes |
|
920 | + $answer_class = ''; |
|
921 | + if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
922 | + if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
937 | 923 | |
938 | - } |
|
924 | + $answer_class .= ' right_answer'; |
|
939 | 925 | |
940 | - } |
|
926 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
941 | 927 | |
942 | - } |
|
928 | + $answer_class .= ' right_answer'; |
|
943 | 929 | |
944 | - // determine if the current option must be checked |
|
945 | - $checked = ''; |
|
946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
930 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
948 | 932 | |
949 | - $checked = 'checked="checked"'; |
|
933 | + $answer_class = 'user_wrong'; |
|
934 | + if( $user_correct ) { |
|
950 | 935 | |
951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
936 | + $answer_class = 'user_right'; |
|
952 | 937 | |
953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
938 | + } |
|
954 | 939 | |
955 | - } |
|
940 | + } |
|
956 | 941 | |
957 | - } // End If Statement |
|
942 | + } |
|
958 | 943 | |
959 | - //Load the answer option data |
|
960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
961 | - $question_option[ 'answer' ] = $answer; |
|
962 | - $question_option[ 'option_class'] = $answer_class; |
|
963 | - $question_option[ 'checked'] = $checked; |
|
964 | - $question_option[ 'count' ] = $count; |
|
965 | - $question_option[ 'type' ] = $answer_type; |
|
944 | + // determine if the current option must be checked |
|
945 | + $checked = ''; |
|
946 | + if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
947 | + if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
966 | 948 | |
967 | - // add the speci fic option to the list of options for this question |
|
968 | - $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
949 | + $checked = 'checked="checked"'; |
|
969 | 950 | |
970 | - } // end for each option |
|
951 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
971 | 952 | |
953 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
972 | 954 | |
973 | - // Shuffle the array depending on the settings |
|
974 | - $answer_options_sorted = array(); |
|
975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
976 | - if( $random_order && $random_order == 'yes' ) { |
|
955 | + } |
|
977 | 956 | |
978 | - $answer_options_sorted = $question_answers_options; |
|
979 | - shuffle( $answer_options_sorted ); |
|
957 | + } // End If Statement |
|
980 | 958 | |
981 | - } else { |
|
959 | + //Load the answer option data |
|
960 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
961 | + $question_option[ 'answer' ] = $answer; |
|
962 | + $question_option[ 'option_class'] = $answer_class; |
|
963 | + $question_option[ 'checked'] = $checked; |
|
964 | + $question_option[ 'count' ] = $count; |
|
965 | + $question_option[ 'type' ] = $answer_type; |
|
982 | 966 | |
983 | - $answer_order = array(); |
|
984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
985 | - if( $answer_order_string ) { |
|
967 | + // add the speci fic option to the list of options for this question |
|
968 | + $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
986 | 969 | |
987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
988 | - if( count( $answer_order ) > 0 ) { |
|
970 | + } // end for each option |
|
989 | 971 | |
990 | - foreach( $answer_order as $answer_id ) { |
|
991 | 972 | |
992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
973 | + // Shuffle the array depending on the settings |
|
974 | + $answer_options_sorted = array(); |
|
975 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
976 | + if( $random_order && $random_order == 'yes' ) { |
|
993 | 977 | |
994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
995 | - unset( $question_answers_options[ $answer_id ] ); |
|
978 | + $answer_options_sorted = $question_answers_options; |
|
979 | + shuffle( $answer_options_sorted ); |
|
996 | 980 | |
997 | - } |
|
981 | + } else { |
|
998 | 982 | |
999 | - } |
|
983 | + $answer_order = array(); |
|
984 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
985 | + if( $answer_order_string ) { |
|
1000 | 986 | |
1001 | - if( count( $question_answers_options ) > 0 ) { |
|
1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
987 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
988 | + if( count( $answer_order ) > 0 ) { |
|
1003 | 989 | |
1004 | - $answer_options_sorted[ $id ] = $answer; |
|
990 | + foreach( $answer_order as $answer_id ) { |
|
1005 | 991 | |
1006 | - } |
|
1007 | - } |
|
992 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
1008 | 993 | |
1009 | - }else{ |
|
994 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
995 | + unset( $question_answers_options[ $answer_id ] ); |
|
1010 | 996 | |
1011 | - $answer_options_sorted = $question_answers_options; |
|
997 | + } |
|
1012 | 998 | |
1013 | - } |
|
999 | + } |
|
1014 | 1000 | |
1015 | - }else{ |
|
1001 | + if( count( $question_answers_options ) > 0 ) { |
|
1002 | + foreach( $question_answers_options as $id => $answer ) { |
|
1016 | 1003 | |
1017 | - $answer_options_sorted = $question_answers_options; |
|
1004 | + $answer_options_sorted[ $id ] = $answer; |
|
1018 | 1005 | |
1019 | - } // end if $answer_order_string |
|
1006 | + } |
|
1007 | + } |
|
1020 | 1008 | |
1021 | - } // end if random order |
|
1009 | + }else{ |
|
1022 | 1010 | |
1011 | + $answer_options_sorted = $question_answers_options; |
|
1023 | 1012 | |
1024 | - // assemble and setup the data for the templates data array |
|
1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
1013 | + } |
|
1026 | 1014 | |
1027 | - } |
|
1015 | + }else{ |
|
1028 | 1016 | |
1029 | - return $question_data; |
|
1017 | + $answer_options_sorted = $question_answers_options; |
|
1030 | 1018 | |
1031 | - }// end multiple_choice_load_question_data |
|
1019 | + } // end if $answer_order_string |
|
1032 | 1020 | |
1033 | - /** |
|
1034 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
1035 | - * filter. |
|
1036 | - * |
|
1037 | - * @since 1.9.0 |
|
1038 | - * |
|
1039 | - * @param $question_data |
|
1040 | - * @param $question_id |
|
1041 | - * @param $quiz_id |
|
1042 | - * |
|
1043 | - * @return array() |
|
1044 | - */ |
|
1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
1021 | + } // end if random order |
|
1046 | 1022 | |
1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
1048 | 1023 | |
1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
1024 | + // assemble and setup the data for the templates data array |
|
1025 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
1053 | 1026 | |
1054 | - } |
|
1027 | + } |
|
1055 | 1028 | |
1056 | - return $question_data; |
|
1029 | + return $question_data; |
|
1057 | 1030 | |
1058 | - }// end gap_fill_load_question_data |
|
1031 | + }// end multiple_choice_load_question_data |
|
1032 | + |
|
1033 | + /** |
|
1034 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
1035 | + * filter. |
|
1036 | + * |
|
1037 | + * @since 1.9.0 |
|
1038 | + * |
|
1039 | + * @param $question_data |
|
1040 | + * @param $question_id |
|
1041 | + * @param $quiz_id |
|
1042 | + * |
|
1043 | + * @return array() |
|
1044 | + */ |
|
1045 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
1046 | + |
|
1047 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
1048 | + |
|
1049 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
1050 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
1051 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
1052 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
1053 | + |
|
1054 | + } |
|
1055 | + |
|
1056 | + return $question_data; |
|
1057 | + |
|
1058 | + }// end gap_fill_load_question_data |
|
1059 | 1059 | |
1060 | 1060 | |
1061 | - /** |
|
1062 | - * Get the correct answer for a question |
|
1063 | - * |
|
1064 | - * @param $question_id |
|
1065 | - * @return string $correct_answer or empty |
|
1066 | - */ |
|
1067 | - public static function get_correct_answer( $question_id ){ |
|
1061 | + /** |
|
1062 | + * Get the correct answer for a question |
|
1063 | + * |
|
1064 | + * @param $question_id |
|
1065 | + * @return string $correct_answer or empty |
|
1066 | + */ |
|
1067 | + public static function get_correct_answer( $question_id ){ |
|
1068 | 1068 | |
1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
1072 | - $grade_type = 'manual-grade'; |
|
1069 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
1070 | + $type = Sensei()->question->get_question_type( $question_id ); |
|
1071 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
1072 | + $grade_type = 'manual-grade'; |
|
1073 | 1073 | |
1074 | - if ('boolean'== $type ) { |
|
1074 | + if ('boolean'== $type ) { |
|
1075 | 1075 | |
1076 | - $right_answer = ucfirst($right_answer); |
|
1076 | + $right_answer = ucfirst($right_answer); |
|
1077 | 1077 | |
1078 | - }elseif( 'multiple-choice' == $type ) { |
|
1078 | + }elseif( 'multiple-choice' == $type ) { |
|
1079 | 1079 | |
1080 | - $right_answer = (array) $right_answer; |
|
1081 | - $right_answer = implode( ', ', $right_answer ); |
|
1080 | + $right_answer = (array) $right_answer; |
|
1081 | + $right_answer = implode( ', ', $right_answer ); |
|
1082 | 1082 | |
1083 | - }elseif( 'gap-fill' == $type ) { |
|
1083 | + }elseif( 'gap-fill' == $type ) { |
|
1084 | 1084 | |
1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
1085 | + $right_answer_array = explode( '||', $right_answer ); |
|
1086 | + if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
1087 | + if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
1088 | + if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
1089 | 1089 | |
1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
1090 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
1091 | 1091 | |
1092 | - }else{ |
|
1092 | + }else{ |
|
1093 | 1093 | |
1094 | - // for non auto gradable question types no answer should be returned. |
|
1095 | - $right_answer = ''; |
|
1094 | + // for non auto gradable question types no answer should be returned. |
|
1095 | + $right_answer = ''; |
|
1096 | 1096 | |
1097 | - } |
|
1097 | + } |
|
1098 | 1098 | |
1099 | - return $right_answer; |
|
1099 | + return $right_answer; |
|
1100 | 1100 | |
1101 | - } // get_correct_answer |
|
1101 | + } // get_correct_answer |
|
1102 | 1102 | |
1103 | 1103 | } // End Class |
1104 | 1104 |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | public $total_items = 0; |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @var array $sortable_columns |
|
45 | - * |
|
46 | - */ |
|
47 | - public $sortable_columns = array(); |
|
43 | + /** |
|
44 | + * @var array $sortable_columns |
|
45 | + * |
|
46 | + */ |
|
47 | + public $sortable_columns = array(); |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var array columns |
|
51 | - */ |
|
52 | - public $columns = array(); |
|
49 | + /** |
|
50 | + * @var array columns |
|
51 | + */ |
|
52 | + public $columns = array(); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | $sortable[$id] = $data; |
176 | 176 | } |
177 | 177 | |
178 | - $primary = $this->get_primary_column_name(); |
|
179 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
178 | + $primary = $this->get_primary_column_name(); |
|
179 | + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
180 | 180 | |
181 | 181 | return $this->_column_headers; |
182 | 182 | } |
@@ -12,107 +12,107 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Sensei_Updates |
14 | 14 | { |
15 | - public $token = 'woothemes-sensei'; |
|
16 | - public $version; |
|
17 | - public $updates_run; |
|
18 | - public $updates; |
|
19 | - private $parent; |
|
20 | - |
|
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @access public |
|
25 | - * @since 1.1.0 |
|
26 | - * @param string $parent The main Sensei object by Ref. |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function __construct($parent) |
|
30 | - { |
|
15 | + public $token = 'woothemes-sensei'; |
|
16 | + public $version; |
|
17 | + public $updates_run; |
|
18 | + public $updates; |
|
19 | + private $parent; |
|
20 | + |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @access public |
|
25 | + * @since 1.1.0 |
|
26 | + * @param string $parent The main Sensei object by Ref. |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function __construct($parent) |
|
30 | + { |
|
31 | 31 | |
32 | 32 | // Setup object data |
33 | 33 | $this->parent = $parent; |
34 | 34 | $this->updates_run = get_option( 'woothemes-sensei-upgrades', array() ); |
35 | 35 | |
36 | - // The list of upgrades to run |
|
37 | - $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
|
38 | - 'manual' => array() |
|
39 | - ), |
|
40 | - '1.3.0' => array('auto' => array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')), |
|
41 | - 'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei')) |
|
42 | - ), |
|
43 | - 'manual' => array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei'))) |
|
44 | - ), |
|
45 | - '1.4.0' => array('auto' => array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))), |
|
46 | - 'manual' => array() |
|
47 | - ), |
|
48 | - '1.5.0' => array('auto' => array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))), |
|
49 | - 'manual' => array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')), |
|
50 | - 'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')), |
|
51 | - 'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei'))) |
|
52 | - ), |
|
53 | - '1.6.0' => array('auto' => array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')), |
|
54 | - 'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')), |
|
55 | - 'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')), |
|
56 | - 'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')), |
|
57 | - 'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),), |
|
58 | - 'manual' => array() |
|
59 | - ), |
|
60 | - '1.7.0' => array('auto' => array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),), |
|
61 | - 'forced' => array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')), |
|
62 | - 'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')), |
|
63 | - 'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')), |
|
64 | - 'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')), |
|
65 | - 'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')), |
|
66 | - 'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')), |
|
67 | - 'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')), |
|
68 | - 'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),), |
|
69 | - ), |
|
70 | - '1.7.2' => array('auto' => array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),), |
|
71 | - /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
|
72 | - ), |
|
73 | - '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),), |
|
74 | - 'manual' => array() |
|
75 | - ), |
|
76 | - ); |
|
36 | + // The list of upgrades to run |
|
37 | + $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
|
38 | + 'manual' => array() |
|
39 | + ), |
|
40 | + '1.3.0' => array('auto' => array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')), |
|
41 | + 'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei')) |
|
42 | + ), |
|
43 | + 'manual' => array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei'))) |
|
44 | + ), |
|
45 | + '1.4.0' => array('auto' => array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))), |
|
46 | + 'manual' => array() |
|
47 | + ), |
|
48 | + '1.5.0' => array('auto' => array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))), |
|
49 | + 'manual' => array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')), |
|
50 | + 'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')), |
|
51 | + 'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei'))) |
|
52 | + ), |
|
53 | + '1.6.0' => array('auto' => array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')), |
|
54 | + 'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')), |
|
55 | + 'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')), |
|
56 | + 'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')), |
|
57 | + 'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),), |
|
58 | + 'manual' => array() |
|
59 | + ), |
|
60 | + '1.7.0' => array('auto' => array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),), |
|
61 | + 'forced' => array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')), |
|
62 | + 'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')), |
|
63 | + 'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')), |
|
64 | + 'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')), |
|
65 | + 'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')), |
|
66 | + 'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')), |
|
67 | + 'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')), |
|
68 | + 'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),), |
|
69 | + ), |
|
70 | + '1.7.2' => array('auto' => array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),), |
|
71 | + /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
|
72 | + ), |
|
73 | + '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),), |
|
74 | + 'manual' => array() |
|
75 | + ), |
|
76 | + ); |
|
77 | 77 | |
78 | 78 | $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
79 | 79 | $this->version = get_option( 'woothemes-sensei-version' ); |
80 | 80 | |
81 | - // Manual Update Screen |
|
82 | - add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
|
83 | - |
|
84 | - } // End __construct() |
|
85 | - |
|
86 | - /** |
|
87 | - * add_update_admin_screen Adds admin screen to run manual udpates |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @since 1.3.7 |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public function add_update_admin_screen() |
|
94 | - { |
|
95 | - if (current_user_can('manage_options')) { |
|
96 | - add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page')); |
|
97 | - } |
|
98 | - } // End add_update_admin_screen() |
|
99 | - |
|
100 | - /** |
|
101 | - * sensei_updates_page HTML output for manual update screen |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @since 1.3.7 |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function sensei_updates_page() { |
|
108 | - |
|
109 | - // Only allow admins to load this page and run the update functions |
|
110 | - if ( ! current_user_can('manage_options')) { |
|
111 | - |
|
112 | - return; |
|
113 | - |
|
114 | - } |
|
115 | - ?> |
|
81 | + // Manual Update Screen |
|
82 | + add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
|
83 | + |
|
84 | + } // End __construct() |
|
85 | + |
|
86 | + /** |
|
87 | + * add_update_admin_screen Adds admin screen to run manual udpates |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @since 1.3.7 |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public function add_update_admin_screen() |
|
94 | + { |
|
95 | + if (current_user_can('manage_options')) { |
|
96 | + add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page')); |
|
97 | + } |
|
98 | + } // End add_update_admin_screen() |
|
99 | + |
|
100 | + /** |
|
101 | + * sensei_updates_page HTML output for manual update screen |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @since 1.3.7 |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function sensei_updates_page() { |
|
108 | + |
|
109 | + // Only allow admins to load this page and run the update functions |
|
110 | + if ( ! current_user_can('manage_options')) { |
|
111 | + |
|
112 | + return; |
|
113 | + |
|
114 | + } |
|
115 | + ?> |
|
116 | 116 | |
117 | 117 | <div class="wrap"> |
118 | 118 | |
@@ -120,111 +120,111 @@ discard block |
||
120 | 120 | <h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2> |
121 | 121 | |
122 | 122 | <?php |
123 | - $function_name= ''; |
|
124 | - if ( isset($_GET['action']) && $_GET['action'] == 'update' |
|
125 | - && isset($_GET['n']) && intval($_GET['n']) >= 0 |
|
126 | - && ( (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
123 | + $function_name= ''; |
|
124 | + if ( isset($_GET['action']) && $_GET['action'] == 'update' |
|
125 | + && isset($_GET['n']) && intval($_GET['n']) >= 0 |
|
126 | + && ( (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
127 | 127 | |
128 | - // Setup the data variables |
|
129 | - $n = intval($_GET['n']); |
|
130 | - $functions_list = ''; |
|
131 | - $done_processing = false; |
|
128 | + // Setup the data variables |
|
129 | + $n = intval($_GET['n']); |
|
130 | + $functions_list = ''; |
|
131 | + $done_processing = false; |
|
132 | 132 | |
133 | - // Check for updates to run |
|
134 | - if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) { |
|
133 | + // Check for updates to run |
|
134 | + if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) { |
|
135 | 135 | |
136 | - foreach ($_POST['checked'] as $key => $function_name) { |
|
136 | + foreach ($_POST['checked'] as $key => $function_name) { |
|
137 | 137 | |
138 | - if( ! isset( $_POST[ $function_name.'_nonce_field' ] ) |
|
139 | - || ! wp_verify_nonce( $_POST[ $function_name.'_nonce_field' ] , 'run_'.$function_name ) ){ |
|
138 | + if( ! isset( $_POST[ $function_name.'_nonce_field' ] ) |
|
139 | + || ! wp_verify_nonce( $_POST[ $function_name.'_nonce_field' ] , 'run_'.$function_name ) ){ |
|
140 | 140 | |
141 | - wp_die( |
|
142 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
143 | - '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
144 | - 403 |
|
145 | - ); |
|
141 | + wp_die( |
|
142 | + '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
143 | + '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
144 | + 403 |
|
145 | + ); |
|
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | - // Dynamic function call |
|
150 | - if (method_exists($this, $function_name)) { |
|
149 | + // Dynamic function call |
|
150 | + if (method_exists($this, $function_name)) { |
|
151 | 151 | |
152 | - $done_processing = call_user_func_array(array($this, $function_name), array(50, $n)); |
|
152 | + $done_processing = call_user_func_array(array($this, $function_name), array(50, $n)); |
|
153 | 153 | |
154 | - } elseif ($this->function_in_whitelist($function_name)) { |
|
154 | + } elseif ($this->function_in_whitelist($function_name)) { |
|
155 | 155 | |
156 | - $done_processing = call_user_func_array($function_name, array(50, $n)); |
|
156 | + $done_processing = call_user_func_array($function_name, array(50, $n)); |
|
157 | 157 | |
158 | - } else { |
|
158 | + } else { |
|
159 | 159 | |
160 | - _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
161 | - return; |
|
160 | + _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
161 | + return; |
|
162 | 162 | |
163 | - }// End If Statement |
|
163 | + }// End If Statement |
|
164 | 164 | |
165 | - // Add to functions list get args |
|
166 | - if ('' == $functions_list) { |
|
167 | - $functions_list .= $function_name; |
|
168 | - } else { |
|
169 | - $functions_list .= '+' . $function_name; |
|
170 | - } // End If Statement |
|
165 | + // Add to functions list get args |
|
166 | + if ('' == $functions_list) { |
|
167 | + $functions_list .= $function_name; |
|
168 | + } else { |
|
169 | + $functions_list .= '+' . $function_name; |
|
170 | + } // End If Statement |
|
171 | 171 | |
172 | - // Mark update has having been run |
|
173 | - $this->set_update_run($function_name); |
|
172 | + // Mark update has having been run |
|
173 | + $this->set_update_run($function_name); |
|
174 | 174 | |
175 | - } // End For Loop |
|
175 | + } // End For Loop |
|
176 | 176 | |
177 | - } // End If Statement |
|
177 | + } // End If Statement |
|
178 | 178 | |
179 | - // Check for updates to run |
|
180 | - if (isset($_GET['functions']) && '' != $_GET['functions']) { |
|
179 | + // Check for updates to run |
|
180 | + if (isset($_GET['functions']) && '' != $_GET['functions']) { |
|
181 | 181 | |
182 | - // Existing functions from GET variables instead of POST |
|
183 | - $functions_array = $_GET['functions']; |
|
182 | + // Existing functions from GET variables instead of POST |
|
183 | + $functions_array = $_GET['functions']; |
|
184 | 184 | |
185 | - foreach ($functions_array as $key => $function_name) { |
|
185 | + foreach ($functions_array as $key => $function_name) { |
|
186 | 186 | |
187 | - if( ! isset( $_GET[ $function_name.'_nonce' ] ) |
|
188 | - || ! wp_verify_nonce( $_GET[ $function_name.'_nonce' ] , 'run_'.$function_name ) ){ |
|
187 | + if( ! isset( $_GET[ $function_name.'_nonce' ] ) |
|
188 | + || ! wp_verify_nonce( $_GET[ $function_name.'_nonce' ] , 'run_'.$function_name ) ){ |
|
189 | 189 | |
190 | - wp_die( |
|
191 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
192 | - '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
193 | - 403 |
|
194 | - ); |
|
190 | + wp_die( |
|
191 | + '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
192 | + '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
193 | + 403 |
|
194 | + ); |
|
195 | 195 | |
196 | - } |
|
196 | + } |
|
197 | 197 | |
198 | - // Dynamic function call |
|
199 | - if (method_exists($this, $function_name)) { |
|
198 | + // Dynamic function call |
|
199 | + if (method_exists($this, $function_name)) { |
|
200 | 200 | |
201 | - $done_processing = call_user_func_array(array($this, $function_name), array(50, $n)); |
|
201 | + $done_processing = call_user_func_array(array($this, $function_name), array(50, $n)); |
|
202 | 202 | |
203 | - } elseif ($this->function_in_whitelist($function_name)) { |
|
203 | + } elseif ($this->function_in_whitelist($function_name)) { |
|
204 | 204 | |
205 | - $done_processing = call_user_func_array($function_name, array(50, $n)); |
|
205 | + $done_processing = call_user_func_array($function_name, array(50, $n)); |
|
206 | 206 | |
207 | - } else { |
|
207 | + } else { |
|
208 | 208 | |
209 | - _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
210 | - return; |
|
209 | + _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
210 | + return; |
|
211 | 211 | |
212 | - } // End If Statement |
|
212 | + } // End If Statement |
|
213 | 213 | |
214 | - // Add to functions list get args |
|
215 | - if ('' == $functions_list) { |
|
216 | - $functions_list .= $function_name; |
|
217 | - } else { |
|
218 | - $functions_list .= '+' . $function_name; |
|
219 | - } // End If Statement |
|
214 | + // Add to functions list get args |
|
215 | + if ('' == $functions_list) { |
|
216 | + $functions_list .= $function_name; |
|
217 | + } else { |
|
218 | + $functions_list .= '+' . $function_name; |
|
219 | + } // End If Statement |
|
220 | 220 | |
221 | - $this->set_update_run($function_name); |
|
221 | + $this->set_update_run($function_name); |
|
222 | 222 | |
223 | - } // End For Loop |
|
223 | + } // End For Loop |
|
224 | 224 | |
225 | - } // End If Statement |
|
225 | + } // End If Statement |
|
226 | 226 | |
227 | - if (!$done_processing) { ?> |
|
227 | + if (!$done_processing) { ?> |
|
228 | 228 | |
229 | 229 | <h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3> |
230 | 230 | |
@@ -233,14 +233,14 @@ discard block |
||
233 | 233 | <?php _e( "If your browser doesn't start loading the next page automatically, click this button:", 'woothemes-sensei' ); ?> |
234 | 234 | |
235 | 235 | <?php |
236 | - $next_action_url = add_query_arg( array( |
|
237 | - 'page' => 'sensei_updates', |
|
238 | - 'action' => 'update', |
|
239 | - 'n' => $n + 50, |
|
240 | - 'functions' => array( $functions_list ), |
|
241 | - $function_name.'_nonce' => wp_create_nonce( 'run_'. $function_name ), |
|
242 | - ), admin_url( 'admin.php' ) ); |
|
243 | - ?> |
|
236 | + $next_action_url = add_query_arg( array( |
|
237 | + 'page' => 'sensei_updates', |
|
238 | + 'action' => 'update', |
|
239 | + 'n' => $n + 50, |
|
240 | + 'functions' => array( $functions_list ), |
|
241 | + $function_name.'_nonce' => wp_create_nonce( 'run_'. $function_name ), |
|
242 | + ), admin_url( 'admin.php' ) ); |
|
243 | + ?> |
|
244 | 244 | |
245 | 245 | <a class="button" href="<?php echo esc_url( $next_action_url ); ?>"> |
246 | 246 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | |
270 | 270 | <?php } // End If Statement |
271 | 271 | |
272 | - } else { ?> |
|
272 | + } else { ?> |
|
273 | 273 | |
274 | 274 | <h3><?php _e('Updates', 'woothemes-sensei'); ?></h3> |
275 | 275 | <p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p> |
@@ -298,19 +298,19 @@ discard block |
||
298 | 298 | |
299 | 299 | <tbody class="updates"> |
300 | 300 | <?php |
301 | - // Sort updates with the latest at the top |
|
302 | - uksort($this->updates, array($this, 'sort_updates')); |
|
303 | - $this->updates = array_reverse($this->updates, true); |
|
304 | - $class = 'alternate'; |
|
305 | - foreach ($this->updates as $version => $version_updates) { |
|
306 | - foreach ($version_updates as $type => $updates) { |
|
307 | - foreach ($updates as $update => $data) { |
|
308 | - $update_run = $this->has_update_run($update); |
|
309 | - $product = 'Sensei'; |
|
310 | - if (isset($data['product']) && '' != $data['product']) { |
|
311 | - $product = $data['product']; |
|
312 | - } // End If Statement |
|
313 | - ?> |
|
301 | + // Sort updates with the latest at the top |
|
302 | + uksort($this->updates, array($this, 'sort_updates')); |
|
303 | + $this->updates = array_reverse($this->updates, true); |
|
304 | + $class = 'alternate'; |
|
305 | + foreach ($this->updates as $version => $version_updates) { |
|
306 | + foreach ($version_updates as $type => $updates) { |
|
307 | + foreach ($updates as $update => $data) { |
|
308 | + $update_run = $this->has_update_run($update); |
|
309 | + $product = 'Sensei'; |
|
310 | + if (isset($data['product']) && '' != $data['product']) { |
|
311 | + $product = $data['product']; |
|
312 | + } // End If Statement |
|
313 | + ?> |
|
314 | 314 | <form method="post" action="admin.php?page=sensei_updates&action=update&n=0" |
315 | 315 | name="update-sensei" class="upgrade"> |
316 | 316 | <tr class="<?php echo $class; ?>"> |
@@ -323,11 +323,11 @@ discard block |
||
323 | 323 | </p> |
324 | 324 | </td> |
325 | 325 | <?php |
326 | - $type_label = __('Auto', 'woothemes-sensei'); |
|
327 | - if ($type != 'auto') { |
|
328 | - $type_label = __('Manual', 'woothemes-sensei'); |
|
329 | - } |
|
330 | - ?> |
|
326 | + $type_label = __('Auto', 'woothemes-sensei'); |
|
327 | + if ($type != 'auto') { |
|
328 | + $type_label = __('Manual', 'woothemes-sensei'); |
|
329 | + } |
|
330 | + ?> |
|
331 | 331 | <td><p><?php echo $type_label; ?></p></td> |
332 | 332 | <td> |
333 | 333 | <p> |
@@ -339,24 +339,24 @@ discard block |
||
339 | 339 | name="update"> |
340 | 340 | |
341 | 341 | <?php |
342 | - $nonce_action = 'run_'.$update; |
|
343 | - $nonce_field_name = $update.'_nonce_field'; |
|
344 | - wp_nonce_field( $nonce_action, $nonce_field_name, false, true ); |
|
345 | - ?> |
|
342 | + $nonce_action = 'run_'.$update; |
|
343 | + $nonce_field_name = $update.'_nonce_field'; |
|
344 | + wp_nonce_field( $nonce_action, $nonce_field_name, false, true ); |
|
345 | + ?> |
|
346 | 346 | </p> |
347 | 347 | </td> |
348 | 348 | </tr> |
349 | 349 | </form> |
350 | 350 | <?php |
351 | - if ('alternate' == $class) { |
|
352 | - $class = ''; |
|
353 | - } else { |
|
354 | - $class = 'alternate'; |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - } |
|
359 | - ?> |
|
351 | + if ('alternate' == $class) { |
|
352 | + $class = ''; |
|
353 | + } else { |
|
354 | + $class = 'alternate'; |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + } |
|
359 | + ?> |
|
360 | 360 | </tbody> |
361 | 361 | |
362 | 362 | </table> |
@@ -364,31 +364,31 @@ discard block |
||
364 | 364 | </div> |
365 | 365 | |
366 | 366 | <?php |
367 | - } // End If Statement |
|
368 | - } // End sensei_updates_page() |
|
367 | + } // End If Statement |
|
368 | + } // End sensei_updates_page() |
|
369 | 369 | |
370 | - /** |
|
371 | - * Since 1.9.0 |
|
372 | - * |
|
373 | - * A list of safe to execute functions withing the |
|
374 | - * updater context. |
|
375 | - * |
|
376 | - * @param string $function_name |
|
377 | - */ |
|
378 | - public function function_in_whitelist( $function_name ){ |
|
370 | + /** |
|
371 | + * Since 1.9.0 |
|
372 | + * |
|
373 | + * A list of safe to execute functions withing the |
|
374 | + * updater context. |
|
375 | + * |
|
376 | + * @param string $function_name |
|
377 | + */ |
|
378 | + public function function_in_whitelist( $function_name ){ |
|
379 | 379 | |
380 | - $function_whitelist = array( |
|
381 | - 'status_changes_convert_questions', |
|
382 | - 'status_changes_fix_lessons', |
|
383 | - 'status_changes_convert_courses', |
|
384 | - 'status_changes_convert_lessons', |
|
385 | - 'status_changes_repair_course_statuses', |
|
380 | + $function_whitelist = array( |
|
381 | + 'status_changes_convert_questions', |
|
382 | + 'status_changes_fix_lessons', |
|
383 | + 'status_changes_convert_courses', |
|
384 | + 'status_changes_convert_lessons', |
|
385 | + 'status_changes_repair_course_statuses', |
|
386 | 386 | |
387 | - ); |
|
387 | + ); |
|
388 | 388 | |
389 | - return in_array($function_name, $function_whitelist ); |
|
389 | + return in_array($function_name, $function_whitelist ); |
|
390 | 390 | |
391 | - }// end function_in_whitelist |
|
391 | + }// end function_in_whitelist |
|
392 | 392 | |
393 | 393 | /** |
394 | 394 | * Sort updates list by version number |
@@ -413,47 +413,47 @@ discard block |
||
413 | 413 | |
414 | 414 | // Only allow admins to run update functions |
415 | 415 | if( ! current_user_can( 'manage_options' ) ) { |
416 | - return false; |
|
417 | - } |
|
418 | - |
|
419 | - $this->force_updates(); |
|
420 | - |
|
421 | - // Run through all functions |
|
422 | - foreach ( $this->updates as $version => $value ) { |
|
423 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
424 | - if ( $upgrade_type == $type ) { |
|
425 | - $updated = false; |
|
426 | - // Run the update function |
|
427 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
428 | - if ( isset( $function_name ) && '' != $function_name ) { |
|
429 | - if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
430 | - $updated = false; |
|
431 | - if ( method_exists( $this, $function_name ) ) { |
|
432 | - |
|
433 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
416 | + return false; |
|
417 | + } |
|
418 | + |
|
419 | + $this->force_updates(); |
|
420 | + |
|
421 | + // Run through all functions |
|
422 | + foreach ( $this->updates as $version => $value ) { |
|
423 | + foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
424 | + if ( $upgrade_type == $type ) { |
|
425 | + $updated = false; |
|
426 | + // Run the update function |
|
427 | + foreach ( $function_to_run as $function_name => $update_data ) { |
|
428 | + if ( isset( $function_name ) && '' != $function_name ) { |
|
429 | + if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
430 | + $updated = false; |
|
431 | + if ( method_exists( $this, $function_name ) ) { |
|
432 | + |
|
433 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
434 | 434 | update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
435 | 435 | return true; |
436 | 436 | |
437 | - } elseif( $this->function_in_whitelist( $function_name ) ) { |
|
437 | + } elseif( $this->function_in_whitelist( $function_name ) ) { |
|
438 | 438 | |
439 | - $updated = call_user_func( $function_name ); |
|
439 | + $updated = call_user_func( $function_name ); |
|
440 | 440 | |
441 | - } // End If Statement |
|
441 | + } // End If Statement |
|
442 | 442 | |
443 | - if ( $updated ) { |
|
444 | - array_push( $this->updates_run, $function_name ); |
|
445 | - } // End If Statement |
|
446 | - } |
|
447 | - } // End If Statement |
|
448 | - } // End For Loop |
|
449 | - } // End If Statement |
|
450 | - } // End For Loop |
|
451 | - } // End For Loop |
|
443 | + if ( $updated ) { |
|
444 | + array_push( $this->updates_run, $function_name ); |
|
445 | + } // End If Statement |
|
446 | + } |
|
447 | + } // End If Statement |
|
448 | + } // End For Loop |
|
449 | + } // End If Statement |
|
450 | + } // End For Loop |
|
451 | + } // End For Loop |
|
452 | 452 | |
453 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
454 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
453 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
454 | + update_option( $this->token . '-upgrades', $this->updates_run ); |
|
455 | 455 | |
456 | - return true; |
|
456 | + return true; |
|
457 | 457 | |
458 | 458 | } // End update() |
459 | 459 | |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | */ |
567 | 567 | private function set_update_run( $update ) { |
568 | 568 | array_push( $this->updates_run, $update ); |
569 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
569 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
570 | 570 | update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
571 | 571 | } |
572 | 572 | |
@@ -1030,11 +1030,11 @@ discard block |
||
1030 | 1030 | update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
1031 | 1031 | } |
1032 | 1032 | |
1033 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
1033 | + $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
1034 | 1034 | |
1035 | - if( $module ) { |
|
1036 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
1037 | - } |
|
1035 | + if( $module ) { |
|
1036 | + update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
1037 | + } |
|
1038 | 1038 | |
1039 | 1039 | } |
1040 | 1040 | |
@@ -1844,22 +1844,22 @@ discard block |
||
1844 | 1844 | |
1845 | 1845 | } |
1846 | 1846 | |
1847 | - /** |
|
1848 | - * WooThemes_Sensei_Updates::enhance_teacher_role |
|
1849 | - * |
|
1850 | - * This runs the update to create the teacher role |
|
1851 | - * @access public |
|
1852 | - * @since 1.8.0 |
|
1853 | - * @return bool; |
|
1854 | - */ |
|
1855 | - public function enhance_teacher_role ( ) { |
|
1856 | - |
|
1857 | - require_once('class-sensei-teacher.php'); |
|
1858 | - $teacher = new Sensei_Teacher(); |
|
1859 | - $teacher->create_role(); |
|
1860 | - return true; |
|
1861 | - |
|
1862 | - }// end enhance_teacher_role |
|
1847 | + /** |
|
1848 | + * WooThemes_Sensei_Updates::enhance_teacher_role |
|
1849 | + * |
|
1850 | + * This runs the update to create the teacher role |
|
1851 | + * @access public |
|
1852 | + * @since 1.8.0 |
|
1853 | + * @return bool; |
|
1854 | + */ |
|
1855 | + public function enhance_teacher_role ( ) { |
|
1856 | + |
|
1857 | + require_once('class-sensei-teacher.php'); |
|
1858 | + $teacher = new Sensei_Teacher(); |
|
1859 | + $teacher->create_role(); |
|
1860 | + return true; |
|
1861 | + |
|
1862 | + }// end enhance_teacher_role |
|
1863 | 1863 | |
1864 | 1864 | } // End Class |
1865 | 1865 |