@@ -17,270 +17,270 @@ |
||
17 | 17 | */ |
18 | 18 | class Sensei_Shortcode_Teachers implements Sensei_Shortcode_Interface { |
19 | 19 | |
20 | - /** |
|
21 | - * @var WP_User_Query keeps a reference to the user query created |
|
22 | - */ |
|
23 | - protected $user_query; |
|
20 | + /** |
|
21 | + * @var WP_User_Query keeps a reference to the user query created |
|
22 | + */ |
|
23 | + protected $user_query; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var which user id's to include |
|
27 | - */ |
|
28 | - protected $include; |
|
25 | + /** |
|
26 | + * @var which user id's to include |
|
27 | + */ |
|
28 | + protected $include; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var which user id's to exclude |
|
32 | - */ |
|
33 | - protected $exclude; |
|
30 | + /** |
|
31 | + * @var which user id's to exclude |
|
32 | + */ |
|
33 | + protected $exclude; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Setup the shortcode object |
|
37 | - * |
|
38 | - * @since 1.9.0 |
|
39 | - * @param array $attributes |
|
40 | - * @param string $content |
|
41 | - * @param string $shortcode the shortcode that was called for this instance |
|
42 | - */ |
|
43 | - public function __construct( $attributes, $content, $shortcode ){ |
|
35 | + /** |
|
36 | + * Setup the shortcode object |
|
37 | + * |
|
38 | + * @since 1.9.0 |
|
39 | + * @param array $attributes |
|
40 | + * @param string $content |
|
41 | + * @param string $shortcode the shortcode that was called for this instance |
|
42 | + */ |
|
43 | + public function __construct( $attributes, $content, $shortcode ){ |
|
44 | 44 | |
45 | - $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
46 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
45 | + $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
46 | + $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
47 | 47 | |
48 | - // convert teacher usernames given to the id |
|
49 | - $this->include = $this->convert_usernames_to_ids( $include ); |
|
50 | - $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
48 | + // convert teacher usernames given to the id |
|
49 | + $this->include = $this->convert_usernames_to_ids( $include ); |
|
50 | + $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
51 | 51 | |
52 | - $this->setup_teacher_query(); |
|
52 | + $this->setup_teacher_query(); |
|
53 | 53 | |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * |
|
58 | - * Setup the user query that will be used in the render method |
|
59 | - * |
|
60 | - * @since 1.9.0 |
|
61 | - */ |
|
62 | - protected function setup_teacher_query(){ |
|
56 | + /** |
|
57 | + * |
|
58 | + * Setup the user query that will be used in the render method |
|
59 | + * |
|
60 | + * @since 1.9.0 |
|
61 | + */ |
|
62 | + protected function setup_teacher_query(){ |
|
63 | 63 | |
64 | - $user_query_args = array( |
|
65 | - 'role' => 'teacher', |
|
66 | - ); |
|
64 | + $user_query_args = array( |
|
65 | + 'role' => 'teacher', |
|
66 | + ); |
|
67 | 67 | |
68 | - $this->user_query = new WP_User_Query( $user_query_args ); |
|
68 | + $this->user_query = new WP_User_Query( $user_query_args ); |
|
69 | 69 | |
70 | - }// end setup _course_query |
|
70 | + }// end setup _course_query |
|
71 | 71 | |
72 | - /** |
|
73 | - * Rendering the shortcode this class is responsible for. |
|
74 | - * |
|
75 | - * @return string $content |
|
76 | - */ |
|
77 | - public function render(){ |
|
72 | + /** |
|
73 | + * Rendering the shortcode this class is responsible for. |
|
74 | + * |
|
75 | + * @return string $content |
|
76 | + */ |
|
77 | + public function render(){ |
|
78 | 78 | |
79 | - $all_users = $this->user_query->get_results(); |
|
80 | - // if the user has specified more users add them as well. |
|
81 | - if( ! empty( $this->include ) ){ |
|
79 | + $all_users = $this->user_query->get_results(); |
|
80 | + // if the user has specified more users add them as well. |
|
81 | + if( ! empty( $this->include ) ){ |
|
82 | 82 | |
83 | - $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
84 | - $included_users = $included_users_query->get_results(); |
|
85 | - if( ! empty( $included_users ) ){ |
|
83 | + $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
84 | + $included_users = $included_users_query->get_results(); |
|
85 | + if( ! empty( $included_users ) ){ |
|
86 | 86 | |
87 | - $merged_users = array_merge( $all_users, $included_users ); |
|
88 | - $all_users = $this->users_unique( $merged_users ); |
|
89 | - $all_users = $this->users_sort( $all_users ); |
|
87 | + $merged_users = array_merge( $all_users, $included_users ); |
|
88 | + $all_users = $this->users_unique( $merged_users ); |
|
89 | + $all_users = $this->users_sort( $all_users ); |
|
90 | 90 | |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - // exclude the users not wanted |
|
96 | - if( ! empty( $this->exclude ) ){ |
|
95 | + // exclude the users not wanted |
|
96 | + if( ! empty( $this->exclude ) ){ |
|
97 | 97 | |
98 | - $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
98 | + $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
99 | 99 | |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - if( ! count( $all_users )> 0 ){ |
|
103 | - return ''; |
|
104 | - } |
|
102 | + if( ! count( $all_users )> 0 ){ |
|
103 | + return ''; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - $users_output = ''; |
|
107 | + $users_output = ''; |
|
108 | 108 | |
109 | - foreach ( $all_users as $user ) { |
|
109 | + foreach ( $all_users as $user ) { |
|
110 | 110 | |
111 | - $user_display_name = $this->get_user_public_name( $user ); |
|
111 | + $user_display_name = $this->get_user_public_name( $user ); |
|
112 | 112 | |
113 | - /** |
|
114 | - * Sensei teachers shortcode list item filter |
|
115 | - * |
|
116 | - * @since 1.9.0 |
|
117 | - * |
|
118 | - * @param string $teacher_li the html for the teacher li |
|
119 | - * @param WP_User $user |
|
120 | - */ |
|
121 | - $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
113 | + /** |
|
114 | + * Sensei teachers shortcode list item filter |
|
115 | + * |
|
116 | + * @since 1.9.0 |
|
117 | + * |
|
118 | + * @param string $teacher_li the html for the teacher li |
|
119 | + * @param WP_User $user |
|
120 | + */ |
|
121 | + $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
122 | 122 | |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | - return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
125 | + return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
126 | 126 | |
127 | - }// end render |
|
127 | + }// end render |
|
128 | 128 | |
129 | - /** |
|
130 | - * remove duplicate user objects from and array of users |
|
131 | - * |
|
132 | - * @since 1.9.0 |
|
133 | - * |
|
134 | - * @param array $users{ |
|
135 | - * @type WP_User |
|
136 | - * } |
|
137 | - * |
|
138 | - * @return array $unique_users { |
|
139 | - * @type WP_User |
|
140 | - * } |
|
141 | - */ |
|
142 | - public function users_unique( $users ){ |
|
129 | + /** |
|
130 | + * remove duplicate user objects from and array of users |
|
131 | + * |
|
132 | + * @since 1.9.0 |
|
133 | + * |
|
134 | + * @param array $users{ |
|
135 | + * @type WP_User |
|
136 | + * } |
|
137 | + * |
|
138 | + * @return array $unique_users { |
|
139 | + * @type WP_User |
|
140 | + * } |
|
141 | + */ |
|
142 | + public function users_unique( $users ){ |
|
143 | 143 | |
144 | - $array_unique_users_ids = array(); |
|
145 | - foreach( $users as $index => $user ){ |
|
144 | + $array_unique_users_ids = array(); |
|
145 | + foreach( $users as $index => $user ){ |
|
146 | 146 | |
147 | - if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
147 | + if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
148 | 148 | |
149 | - // exclude this user as it is already in the list |
|
150 | - unset( $users[ $index ] ); |
|
149 | + // exclude this user as it is already in the list |
|
150 | + unset( $users[ $index ] ); |
|
151 | 151 | |
152 | - }else{ |
|
152 | + }else{ |
|
153 | 153 | |
154 | - // add teh user to the list of users |
|
155 | - $array_unique_users_ids[] = $user->ID; |
|
154 | + // add teh user to the list of users |
|
155 | + $array_unique_users_ids[] = $user->ID; |
|
156 | 156 | |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - return $users; |
|
161 | + return $users; |
|
162 | 162 | |
163 | - }// end users_unique |
|
163 | + }// end users_unique |
|
164 | 164 | |
165 | - /** |
|
166 | - * Exclude users based ont he ids given. |
|
167 | - * |
|
168 | - * @since 1.9.0 |
|
169 | - * |
|
170 | - * @param array $users |
|
171 | - * @param array $exclude_ids |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function exclude_users( $users, $exclude_ids ){ |
|
165 | + /** |
|
166 | + * Exclude users based ont he ids given. |
|
167 | + * |
|
168 | + * @since 1.9.0 |
|
169 | + * |
|
170 | + * @param array $users |
|
171 | + * @param array $exclude_ids |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function exclude_users( $users, $exclude_ids ){ |
|
175 | 175 | |
176 | - foreach( $users as $index => $user ){ |
|
176 | + foreach( $users as $index => $user ){ |
|
177 | 177 | |
178 | - if( in_array( $user->ID, $exclude_ids ) ){ |
|
178 | + if( in_array( $user->ID, $exclude_ids ) ){ |
|
179 | 179 | |
180 | - // remove the user from the list |
|
181 | - unset( $users[ $index ] ); |
|
180 | + // remove the user from the list |
|
181 | + unset( $users[ $index ] ); |
|
182 | 182 | |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - return $users; |
|
187 | + return $users; |
|
188 | 188 | |
189 | - }// end exclude_users |
|
189 | + }// end exclude_users |
|
190 | 190 | |
191 | - /** |
|
192 | - * Convert mixed array of user id and user names to only be an array of user_ids |
|
193 | - * |
|
194 | - * @param array $users |
|
195 | - * @return array $users_ids |
|
196 | - */ |
|
197 | - public function convert_usernames_to_ids( $users ){ |
|
191 | + /** |
|
192 | + * Convert mixed array of user id and user names to only be an array of user_ids |
|
193 | + * |
|
194 | + * @param array $users |
|
195 | + * @return array $users_ids |
|
196 | + */ |
|
197 | + public function convert_usernames_to_ids( $users ){ |
|
198 | 198 | |
199 | - // backup |
|
200 | - $users_ids = array(); |
|
199 | + // backup |
|
200 | + $users_ids = array(); |
|
201 | 201 | |
202 | - if ( is_array($users) ) { |
|
202 | + if ( is_array($users) ) { |
|
203 | 203 | |
204 | - foreach ($users as $user_id_or_username) { |
|
204 | + foreach ($users as $user_id_or_username) { |
|
205 | 205 | |
206 | - if (!is_numeric($user_id_or_username)) { |
|
206 | + if (!is_numeric($user_id_or_username)) { |
|
207 | 207 | |
208 | - $user_name = $user_id_or_username; |
|
209 | - $user = get_user_by('login', $user_name); |
|
208 | + $user_name = $user_id_or_username; |
|
209 | + $user = get_user_by('login', $user_name); |
|
210 | 210 | |
211 | - if (is_a($user, 'WP_User')) { |
|
212 | - $users_ids[] = $user->ID; |
|
213 | - } |
|
211 | + if (is_a($user, 'WP_User')) { |
|
212 | + $users_ids[] = $user->ID; |
|
213 | + } |
|
214 | 214 | |
215 | - } else { |
|
215 | + } else { |
|
216 | 216 | |
217 | - $user_id = $user_id_or_username; |
|
218 | - $users_ids[] = $user_id; |
|
217 | + $user_id = $user_id_or_username; |
|
218 | + $users_ids[] = $user_id; |
|
219 | 219 | |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - } |
|
223 | - } |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | - return $users_ids; |
|
226 | - } |
|
225 | + return $users_ids; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Returns the first name and last name or the display name of a user. |
|
230 | - * |
|
231 | - * @since 1.9.0 |
|
232 | - * |
|
233 | - * @param $user |
|
234 | - * @return string $user_public_name |
|
235 | - */ |
|
236 | - public function get_user_public_name( $user ){ |
|
228 | + /** |
|
229 | + * Returns the first name and last name or the display name of a user. |
|
230 | + * |
|
231 | + * @since 1.9.0 |
|
232 | + * |
|
233 | + * @param $user |
|
234 | + * @return string $user_public_name |
|
235 | + */ |
|
236 | + public function get_user_public_name( $user ){ |
|
237 | 237 | |
238 | - if (!empty($user->first_name) && !empty($user->last_name)) { |
|
238 | + if (!empty($user->first_name) && !empty($user->last_name)) { |
|
239 | 239 | |
240 | - $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
240 | + $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
241 | 241 | |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | - else { |
|
244 | + else { |
|
245 | 245 | |
246 | - $user_public_name = $user->display_name; |
|
246 | + $user_public_name = $user->display_name; |
|
247 | 247 | |
248 | - } |
|
248 | + } |
|
249 | 249 | |
250 | - return $user_public_name; |
|
251 | - } |
|
250 | + return $user_public_name; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * |
|
255 | - * Sort user objects by user display |
|
256 | - * |
|
257 | - * @since 1.9.0 |
|
258 | - * |
|
259 | - * @param $users |
|
260 | - * @return array $sorted_users |
|
261 | - */ |
|
262 | - public function users_sort( $users ){ |
|
253 | + /** |
|
254 | + * |
|
255 | + * Sort user objects by user display |
|
256 | + * |
|
257 | + * @since 1.9.0 |
|
258 | + * |
|
259 | + * @param $users |
|
260 | + * @return array $sorted_users |
|
261 | + */ |
|
262 | + public function users_sort( $users ){ |
|
263 | 263 | |
264 | - $sorted_users = $users; |
|
264 | + $sorted_users = $users; |
|
265 | 265 | |
266 | - uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
266 | + uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
267 | 267 | |
268 | - return $sorted_users; |
|
269 | - } |
|
268 | + return $sorted_users; |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Used in the uasort function to sort users by title |
|
273 | - * |
|
274 | - * @since 1.9.0 |
|
275 | - * |
|
276 | - * @param $user_1 |
|
277 | - * @param $user_2 |
|
278 | - * @return int |
|
279 | - */ |
|
280 | - public function custom_user_sort($user_1, $user_2){ |
|
271 | + /** |
|
272 | + * Used in the uasort function to sort users by title |
|
273 | + * |
|
274 | + * @since 1.9.0 |
|
275 | + * |
|
276 | + * @param $user_1 |
|
277 | + * @param $user_2 |
|
278 | + * @return int |
|
279 | + */ |
|
280 | + public function custom_user_sort($user_1, $user_2){ |
|
281 | 281 | |
282 | - return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
282 | + return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
283 | 283 | |
284 | - }// end custom_user_sort |
|
284 | + }// end custom_user_sort |
|
285 | 285 | |
286 | 286 | }// end class |
287 | 287 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Renders the [sensei_teachers] shortcode. Will show a list of teachers |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | * @param string $content |
41 | 41 | * @param string $shortcode the shortcode that was called for this instance |
42 | 42 | */ |
43 | - public function __construct( $attributes, $content, $shortcode ){ |
|
43 | + public function __construct($attributes, $content, $shortcode) { |
|
44 | 44 | |
45 | - $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
46 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
45 | + $include = isset($attributes['include']) ? explode(',', $attributes['include']) : ''; |
|
46 | + $exclude = isset($attributes['exclude']) ? explode(',', $attributes['exclude']) : ''; |
|
47 | 47 | |
48 | 48 | // convert teacher usernames given to the id |
49 | - $this->include = $this->convert_usernames_to_ids( $include ); |
|
50 | - $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
49 | + $this->include = $this->convert_usernames_to_ids($include); |
|
50 | + $this->exclude = $this->convert_usernames_to_ids($exclude); |
|
51 | 51 | |
52 | 52 | $this->setup_teacher_query(); |
53 | 53 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @since 1.9.0 |
61 | 61 | */ |
62 | - protected function setup_teacher_query(){ |
|
62 | + protected function setup_teacher_query() { |
|
63 | 63 | |
64 | 64 | $user_query_args = array( |
65 | 65 | 'role' => 'teacher', |
66 | 66 | ); |
67 | 67 | |
68 | - $this->user_query = new WP_User_Query( $user_query_args ); |
|
68 | + $this->user_query = new WP_User_Query($user_query_args); |
|
69 | 69 | |
70 | 70 | }// end setup _course_query |
71 | 71 | |
@@ -74,41 +74,41 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return string $content |
76 | 76 | */ |
77 | - public function render(){ |
|
77 | + public function render() { |
|
78 | 78 | |
79 | 79 | $all_users = $this->user_query->get_results(); |
80 | 80 | // if the user has specified more users add them as well. |
81 | - if( ! empty( $this->include ) ){ |
|
81 | + if ( ! empty($this->include)) { |
|
82 | 82 | |
83 | - $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
83 | + $included_users_query = new WP_User_Query(array('include' => $this->include)); |
|
84 | 84 | $included_users = $included_users_query->get_results(); |
85 | - if( ! empty( $included_users ) ){ |
|
85 | + if ( ! empty($included_users)) { |
|
86 | 86 | |
87 | - $merged_users = array_merge( $all_users, $included_users ); |
|
88 | - $all_users = $this->users_unique( $merged_users ); |
|
89 | - $all_users = $this->users_sort( $all_users ); |
|
87 | + $merged_users = array_merge($all_users, $included_users); |
|
88 | + $all_users = $this->users_unique($merged_users); |
|
89 | + $all_users = $this->users_sort($all_users); |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | // exclude the users not wanted |
96 | - if( ! empty( $this->exclude ) ){ |
|
96 | + if ( ! empty($this->exclude)) { |
|
97 | 97 | |
98 | - $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
98 | + $all_users = $this->exclude_users($all_users, $this->exclude); |
|
99 | 99 | |
100 | 100 | } |
101 | 101 | |
102 | - if( ! count( $all_users )> 0 ){ |
|
102 | + if ( ! count($all_users) > 0) { |
|
103 | 103 | return ''; |
104 | 104 | } |
105 | 105 | |
106 | 106 | |
107 | 107 | $users_output = ''; |
108 | 108 | |
109 | - foreach ( $all_users as $user ) { |
|
109 | + foreach ($all_users as $user) { |
|
110 | 110 | |
111 | - $user_display_name = $this->get_user_public_name( $user ); |
|
111 | + $user_display_name = $this->get_user_public_name($user); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Sensei teachers shortcode list item filter |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | * @param string $teacher_li the html for the teacher li |
119 | 119 | * @param WP_User $user |
120 | 120 | */ |
121 | - $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
121 | + $users_output .= apply_filters('sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'.get_author_posts_url($user->ID).'">'.$user_display_name.'<a/></li>', $user); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
125 | - return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
125 | + return '<ul class="sensei-teachers">'.$users_output.'</ul>'; |
|
126 | 126 | |
127 | 127 | }// end render |
128 | 128 | |
@@ -139,17 +139,17 @@ discard block |
||
139 | 139 | * @type WP_User |
140 | 140 | * } |
141 | 141 | */ |
142 | - public function users_unique( $users ){ |
|
142 | + public function users_unique($users) { |
|
143 | 143 | |
144 | 144 | $array_unique_users_ids = array(); |
145 | - foreach( $users as $index => $user ){ |
|
145 | + foreach ($users as $index => $user) { |
|
146 | 146 | |
147 | - if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
147 | + if (in_array($user->ID, $array_unique_users_ids)) { |
|
148 | 148 | |
149 | 149 | // exclude this user as it is already in the list |
150 | - unset( $users[ $index ] ); |
|
150 | + unset($users[$index]); |
|
151 | 151 | |
152 | - }else{ |
|
152 | + } else { |
|
153 | 153 | |
154 | 154 | // add teh user to the list of users |
155 | 155 | $array_unique_users_ids[] = $user->ID; |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | * @param array $exclude_ids |
172 | 172 | * @return array |
173 | 173 | */ |
174 | - public function exclude_users( $users, $exclude_ids ){ |
|
174 | + public function exclude_users($users, $exclude_ids) { |
|
175 | 175 | |
176 | - foreach( $users as $index => $user ){ |
|
176 | + foreach ($users as $index => $user) { |
|
177 | 177 | |
178 | - if( in_array( $user->ID, $exclude_ids ) ){ |
|
178 | + if (in_array($user->ID, $exclude_ids)) { |
|
179 | 179 | |
180 | 180 | // remove the user from the list |
181 | - unset( $users[ $index ] ); |
|
181 | + unset($users[$index]); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | * @param array $users |
195 | 195 | * @return array $users_ids |
196 | 196 | */ |
197 | - public function convert_usernames_to_ids( $users ){ |
|
197 | + public function convert_usernames_to_ids($users) { |
|
198 | 198 | |
199 | 199 | // backup |
200 | 200 | $users_ids = array(); |
201 | 201 | |
202 | - if ( is_array($users) ) { |
|
202 | + if (is_array($users)) { |
|
203 | 203 | |
204 | 204 | foreach ($users as $user_id_or_username) { |
205 | 205 | |
206 | - if (!is_numeric($user_id_or_username)) { |
|
206 | + if ( ! is_numeric($user_id_or_username)) { |
|
207 | 207 | |
208 | 208 | $user_name = $user_id_or_username; |
209 | 209 | $user = get_user_by('login', $user_name); |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | * @param $user |
234 | 234 | * @return string $user_public_name |
235 | 235 | */ |
236 | - public function get_user_public_name( $user ){ |
|
236 | + public function get_user_public_name($user) { |
|
237 | 237 | |
238 | - if (!empty($user->first_name) && !empty($user->last_name)) { |
|
238 | + if ( ! empty($user->first_name) && ! empty($user->last_name)) { |
|
239 | 239 | |
240 | - $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
240 | + $user_public_name = $user->first_name.' '.$user->last_name; |
|
241 | 241 | |
242 | 242 | } |
243 | 243 | |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | * @param $users |
260 | 260 | * @return array $sorted_users |
261 | 261 | */ |
262 | - public function users_sort( $users ){ |
|
262 | + public function users_sort($users) { |
|
263 | 263 | |
264 | 264 | $sorted_users = $users; |
265 | 265 | |
266 | - uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
266 | + uasort($sorted_users, array($this, 'custom_user_sort')); |
|
267 | 267 | |
268 | 268 | return $sorted_users; |
269 | 269 | } |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param $user_2 |
278 | 278 | * @return int |
279 | 279 | */ |
280 | - public function custom_user_sort($user_1, $user_2){ |
|
280 | + public function custom_user_sort($user_1, $user_2) { |
|
281 | 281 | |
282 | - return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
282 | + return strcasecmp($this->get_user_public_name($user_1), $this->get_user_public_name($user_2)); |
|
283 | 283 | |
284 | 284 | }// end custom_user_sort |
285 | 285 |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | /** |
4 | 7 | * |
5 | 8 | * Renders the [sensei_teachers] shortcode. Will show a list of teachers |
@@ -149,7 +152,7 @@ discard block |
||
149 | 152 | // exclude this user as it is already in the list |
150 | 153 | unset( $users[ $index ] ); |
151 | 154 | |
152 | - }else{ |
|
155 | + } else{ |
|
153 | 156 | |
154 | 157 | // add teh user to the list of users |
155 | 158 | $array_unique_users_ids[] = $user->ID; |
@@ -239,9 +242,7 @@ discard block |
||
239 | 242 | |
240 | 243 | $user_public_name = $user->first_name . ' ' . $user->last_name; |
241 | 244 | |
242 | - } |
|
243 | - |
|
244 | - else { |
|
245 | + } else { |
|
245 | 246 | |
246 | 247 | $user_public_name = $user->display_name; |
247 | 248 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Sensei Modules Class |
@@ -21,33 +21,33 @@ discard block |
||
21 | 21 | private $order_page_slug; |
22 | 22 | public $taxonomy; |
23 | 23 | |
24 | - public function __construct( $file ) |
|
24 | + public function __construct($file) |
|
25 | 25 | { |
26 | 26 | $this->file = $file; |
27 | 27 | $this->dir = dirname($this->file); |
28 | - $this->assets_dir = trailingslashit($this->dir) . 'assets'; |
|
28 | + $this->assets_dir = trailingslashit($this->dir).'assets'; |
|
29 | 29 | $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file))); |
30 | 30 | $this->taxonomy = 'module'; |
31 | 31 | $this->order_page_slug = 'module-order'; |
32 | 32 | |
33 | 33 | // setup taxonomy |
34 | - add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 ); |
|
34 | + add_action('init', array($this, 'setup_modules_taxonomy'), 10); |
|
35 | 35 | |
36 | 36 | // Manage lesson meta boxes for taxonomy |
37 | - add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 ); |
|
37 | + add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2); |
|
38 | 38 | |
39 | 39 | // Save lesson meta box |
40 | 40 | add_action('save_post', array($this, 'save_lesson_module'), 10, 1); |
41 | 41 | |
42 | 42 | //Reset the none modules lessons transient |
43 | - add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) ); |
|
43 | + add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient')); |
|
44 | 44 | |
45 | 45 | // Frontend styling |
46 | 46 | add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
47 | 47 | |
48 | 48 | // Admin styling |
49 | 49 | add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles')); |
50 | - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20 , 2 ); |
|
50 | + add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2); |
|
51 | 51 | |
52 | 52 | // Handle module completion record |
53 | 53 | add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3); |
@@ -55,20 +55,20 @@ discard block |
||
55 | 55 | add_action('wp', array($this, 'save_module_progress'), 10); |
56 | 56 | |
57 | 57 | // Handle module ordering |
58 | - add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 ); |
|
58 | + add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30); |
|
59 | 59 | add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1); |
60 | 60 | add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2); |
61 | 61 | |
62 | 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 ); |
|
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 | 66 | |
67 | 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); |
|
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 | 72 | add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json')); |
73 | 73 | |
74 | 74 | // Manage module taxonomy archive page |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | add_filter('body_class', array($this, 'module_archive_body_class')); |
81 | 81 | |
82 | 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 ); |
|
83 | + add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8); |
|
84 | 84 | |
85 | 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); |
|
86 | + add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20); |
|
87 | 87 | |
88 | 88 | // Set up display on single lesson page |
89 | 89 | add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2); |
@@ -95,22 +95,22 @@ discard block |
||
95 | 95 | add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3); |
96 | 96 | |
97 | 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); |
|
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 | 100 | add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2); |
101 | 101 | |
102 | 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' ) ); |
|
103 | + add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term')); |
|
104 | 104 | |
105 | 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 ); |
|
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 | 108 | |
109 | 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 ); |
|
110 | + add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3); |
|
111 | 111 | |
112 | 112 | // remove the default modules metabox |
113 | - add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' )); |
|
113 | + add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box')); |
|
114 | 114 | |
115 | 115 | } // end constructor |
116 | 116 | |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @return void |
128 | 128 | * @deprecated since 1.9.0 |
129 | 129 | */ |
130 | - public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){ |
|
130 | + public function change_module_term_slug($term_id, $tt_id, $taxonomy) { |
|
131 | 131 | |
132 | - _deprecated_function('change_module_term_slug', '1.9.0' ); |
|
132 | + _deprecated_function('change_module_term_slug', '1.9.0'); |
|
133 | 133 | |
134 | 134 | }// end add_module_term_group |
135 | 135 | |
@@ -143,20 +143,20 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public function modules_metaboxes( $post_type, $post ) |
|
146 | + public function modules_metaboxes($post_type, $post) |
|
147 | 147 | { |
148 | - if ('lesson' == $post_type ) { |
|
148 | + if ('lesson' == $post_type) { |
|
149 | 149 | |
150 | 150 | // Remove default taxonomy meta box from Lesson edit screen |
151 | - remove_meta_box($this->taxonomy . 'div', 'lesson', 'side'); |
|
151 | + remove_meta_box($this->taxonomy.'div', 'lesson', 'side'); |
|
152 | 152 | |
153 | 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'); |
|
154 | + add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default'); |
|
155 | 155 | } |
156 | 156 | |
157 | - if( 'course' == $post_type ){ |
|
157 | + if ('course' == $post_type) { |
|
158 | 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'); |
|
159 | + add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core'); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | $modules = $this->get_course_modules($lesson_course); |
193 | 193 | |
194 | 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))) . '" />'; |
|
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 | 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>'; |
|
197 | + $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n"; |
|
198 | + $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
199 | 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"; |
|
200 | + $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n"; |
|
201 | 201 | } |
202 | - $html .= '</select>' . "\n"; |
|
202 | + $html .= '</select>'."\n"; |
|
203 | 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>'; |
|
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 | 206 | } // End If Statement |
207 | 207 | |
208 | 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>'; |
|
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 | 210 | } // End If Statement |
211 | 211 | |
212 | 212 | // Output the HTML |
@@ -225,38 +225,38 @@ discard block |
||
225 | 225 | global $post; |
226 | 226 | |
227 | 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))) { |
|
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 | 230 | return $post_id; |
231 | 231 | } |
232 | 232 | |
233 | 233 | // Check if user has permissions to edit lessons |
234 | 234 | $post_type = get_post_type_object($post->post_type); |
235 | - if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
|
235 | + if ( ! current_user_can($post_type->cap->edit_post, $post_id)) { |
|
236 | 236 | return $post_id; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Check if user has permissions to edit this specific post |
240 | - if (!current_user_can('edit_post', $post_id)) { |
|
240 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
241 | 241 | return $post_id; |
242 | 242 | } |
243 | 243 | |
244 | 244 | // Cast module ID as an integer if selected, otherwise leave as empty string |
245 | - if ( isset( $_POST['lesson_module'] ) ) { |
|
245 | + if (isset($_POST['lesson_module'])) { |
|
246 | 246 | |
247 | - if( empty ( $_POST['lesson_module'] ) ){ |
|
248 | - wp_delete_object_term_relationships($post_id, $this->taxonomy ); |
|
247 | + if (empty ($_POST['lesson_module'])) { |
|
248 | + wp_delete_object_term_relationships($post_id, $this->taxonomy); |
|
249 | 249 | return true; |
250 | 250 | } |
251 | 251 | |
252 | - $module_id = intval( $_POST['lesson_module'] ); |
|
252 | + $module_id = intval($_POST['lesson_module']); |
|
253 | 253 | |
254 | 254 | // Assign lesson to selected module |
255 | 255 | wp_set_object_terms($post_id, $module_id, $this->taxonomy, false); |
256 | 256 | |
257 | 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); |
|
258 | + if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) { |
|
259 | + update_post_meta($post_id, '_order_module_'.$module_id, 0); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $module_courses = array(); |
315 | 315 | if (isset($courses) && is_array($courses)) { |
316 | 316 | foreach ($courses as $course) { |
317 | - $module_courses[] = array( 'id' =>$course->ID, 'details'=>$course->post_title ); |
|
317 | + $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th> |
325 | 325 | <td> |
326 | 326 | <input type="hidden" |
327 | - data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>" |
|
328 | - value="<?php echo esc_attr( json_encode($module_courses) ); ?>" |
|
327 | + data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>" |
|
328 | + value="<?php echo esc_attr(json_encode($module_courses)); ?>" |
|
329 | 329 | id="module_courses" name="module_courses" |
330 | 330 | class="ajax_chosen_select_courses" |
331 | 331 | placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>" |
@@ -370,11 +370,11 @@ discard block |
||
370 | 370 | } |
371 | 371 | |
372 | 372 | // Add module to selected courses |
373 | - if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) { |
|
373 | + if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) { |
|
374 | 374 | |
375 | - $course_ids = explode( ",", $_POST['module_courses'] ); |
|
375 | + $course_ids = explode(",", $_POST['module_courses']); |
|
376 | 376 | |
377 | - foreach ( $course_ids as $course_id ) { |
|
377 | + foreach ($course_ids as $course_id) { |
|
378 | 378 | |
379 | 379 | wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); |
380 | 380 | |
@@ -438,11 +438,11 @@ discard block |
||
438 | 438 | * @since 1.8.0 |
439 | 439 | * @return void |
440 | 440 | */ |
441 | - public function single_course_modules(){ |
|
441 | + public function single_course_modules() { |
|
442 | 442 | |
443 | - _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
443 | + _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template'); |
|
444 | 444 | // only show modules on the course that has modules |
445 | - if( is_singular( 'course' ) && has_term( '', 'module' ) ) { |
|
445 | + if (is_singular('course') && has_term('', 'module')) { |
|
446 | 446 | |
447 | 447 | $this->load_course_module_content_template(); |
448 | 448 | |
@@ -459,15 +459,15 @@ discard block |
||
459 | 459 | |
460 | 460 | if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) { |
461 | 461 | $is_user_taking_course = WooThemes_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) { |
|
462 | + if ( ! $is_user_taking_course) { |
|
463 | 463 | if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) { |
464 | 464 | $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id); |
465 | 465 | // Remove brackets for display here |
466 | 466 | $title_text = str_replace('(', '', $title_text); |
467 | 467 | $title_text = str_replace(')', '', $title_text); |
468 | - $title_text = '<span class="preview-label">' . $title_text . '</span>'; |
|
468 | + $title_text = '<span class="preview-label">'.$title_text.'</span>'; |
|
469 | 469 | } |
470 | - $title .= ' ' . $title_text; |
|
470 | + $title .= ' '.$title_text; |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | if (is_singular('lesson')) { |
482 | 482 | if (has_term('', $this->taxonomy, $post->ID)) { |
483 | 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>'; |
|
484 | + if ($module) { |
|
485 | + $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>'; |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | if (is_tax($this->taxonomy)) { |
491 | 491 | if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) { |
492 | 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>'; |
|
493 | + $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>'; |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | return $html; |
@@ -505,18 +505,18 @@ discard block |
||
505 | 505 | */ |
506 | 506 | public function module_archive_template($template) { |
507 | 507 | |
508 | - if ( ! is_tax($this->taxonomy) ) { |
|
508 | + if ( ! is_tax($this->taxonomy)) { |
|
509 | 509 | return $template; |
510 | 510 | } |
511 | 511 | |
512 | 512 | $file = 'archive-lesson.php'; |
513 | - $find = array( $file, Sensei()->template_url . $file ); |
|
513 | + $find = array($file, Sensei()->template_url.$file); |
|
514 | 514 | |
515 | 515 | // locate the template file |
516 | 516 | $template = locate_template($find); |
517 | - if (!$template) { |
|
517 | + if ( ! $template) { |
|
518 | 518 | |
519 | - $template = Sensei()->plugin_path() . 'templates/' . $file; |
|
519 | + $template = Sensei()->plugin_path().'templates/'.$file; |
|
520 | 520 | |
521 | 521 | } |
522 | 522 | |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | // Set order of lessons |
543 | 543 | if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
544 | 544 | $module_id = $query->queried_object_id; |
545 | - $query->set('meta_key', '_order_module_' . $module_id); |
|
545 | + $query->set('meta_key', '_order_module_'.$module_id); |
|
546 | 546 | $query->set('orderby', 'meta_value_num date'); |
547 | 547 | } else { |
548 | 548 | $query->set('orderby', 'menu_order'); |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | $status = __('In progress', 'woothemes-sensei'); |
604 | 604 | $class = 'in-progress'; |
605 | 605 | } |
606 | - echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>'; |
|
606 | + echo '<p class="status '.esc_attr($class).'">'.$status.'</p>'; |
|
607 | 607 | } |
608 | 608 | |
609 | - echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>'; |
|
609 | + echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>'; |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
732 | 732 | { |
733 | 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)); |
|
734 | + update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress)); |
|
735 | 735 | |
736 | 736 | do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress); |
737 | 737 | } |
@@ -748,9 +748,9 @@ discard block |
||
748 | 748 | */ |
749 | 749 | public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0) |
750 | 750 | { |
751 | - $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true); |
|
751 | + $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true); |
|
752 | 752 | if ($module_progress) { |
753 | - return (float)$module_progress; |
|
753 | + return (float) $module_progress; |
|
754 | 754 | } |
755 | 755 | return false; |
756 | 756 | } |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | } |
804 | 804 | $module_progress = ($completed_count / $lesson_count) * 100; |
805 | 805 | |
806 | - return (float)$module_progress; |
|
806 | + return (float) $module_progress; |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | public function register_modules_admin_menu_items() |
817 | 817 | { |
818 | 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','' ); |
|
819 | + add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', ''); |
|
820 | 820 | |
821 | 821 | // Regsiter new admin page for module ordering |
822 | 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')); |
@@ -843,19 +843,19 @@ discard block |
||
843 | 843 | $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id'])); |
844 | 844 | |
845 | 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"; |
|
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 | 849 | } |
850 | 850 | } |
851 | 851 | |
852 | 852 | $courses = Sensei()->course->get_all_courses(); |
853 | 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"; |
|
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 | 859 | |
860 | 860 | foreach ($courses as $course) { |
861 | 861 | if (has_term('', $this->taxonomy, $course->ID)) { |
@@ -863,30 +863,30 @@ discard block |
||
863 | 863 | if (isset($_GET['course_id'])) { |
864 | 864 | $course_id = intval($_GET['course_id']); |
865 | 865 | } |
866 | - $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n"; |
|
866 | + $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n"; |
|
867 | 867 | } |
868 | 868 | } |
869 | 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"; |
|
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 | 873 | |
874 | 874 | if (isset($_GET['course_id'])) { |
875 | 875 | $course_id = intval($_GET['course_id']); |
876 | 876 | if ($course_id > 0) { |
877 | 877 | $modules = $this->get_course_modules($course_id); |
878 | - $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() ); |
|
878 | + $modules = $this->append_teacher_name_to_module($modules, array('module'), array()); |
|
879 | 879 | if ($modules) { |
880 | 880 | |
881 | 881 | $order = $this->get_course_module_order($course_id); |
882 | 882 | |
883 | - $order_string=''; |
|
883 | + $order_string = ''; |
|
884 | 884 | if ($order) { |
885 | 885 | $order_string = implode(',', $order); |
886 | 886 | } |
887 | 887 | |
888 | - $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
|
889 | - $html .= '<ul class="sortable-module-list">' . "\n"; |
|
888 | + $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n"; |
|
889 | + $html .= '<ul class="sortable-module-list">'."\n"; |
|
890 | 890 | $count = 0; |
891 | 891 | foreach ($modules as $module) { |
892 | 892 | $count++; |
@@ -900,14 +900,14 @@ discard block |
||
900 | 900 | if ($count % 2 != 0) { |
901 | 901 | $class .= ' alternate'; |
902 | 902 | } |
903 | - $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n"; |
|
903 | + $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n"; |
|
904 | 904 | } |
905 | - $html .= '</ul>' . "\n"; |
|
905 | + $html .= '</ul>'."\n"; |
|
906 | 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"; |
|
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 | 911 | } |
912 | 912 | } |
913 | 913 | } |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | { |
945 | 945 | if ($column == 'module_order') { |
946 | 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>'; |
|
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 | 948 | } |
949 | 949 | } |
950 | 950 | } |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | $args['post_type'] = 'lesson'; |
1037 | 1037 | $lessons = get_posts($args); |
1038 | 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>'; |
|
1039 | + $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>'; |
|
1040 | 1040 | break; |
1041 | 1041 | } |
1042 | 1042 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | public function analysis_overview_column_title($columns) |
1055 | 1055 | { |
1056 | 1056 | |
1057 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1057 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
1058 | 1058 | $new_columns = array(); |
1059 | 1059 | if (is_array($columns) && 0 < count($columns)) { |
1060 | 1060 | foreach ($columns as $column => $title) { |
@@ -1082,15 +1082,15 @@ discard block |
||
1082 | 1082 | * @param WP_Post $lesson |
1083 | 1083 | * @return array Updated column data |
1084 | 1084 | */ |
1085 | - public function analysis_overview_column_data($columns, $lesson ) |
|
1085 | + public function analysis_overview_column_data($columns, $lesson) |
|
1086 | 1086 | { |
1087 | 1087 | |
1088 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1088 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
1089 | 1089 | $lesson_module = ''; |
1090 | 1090 | $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
1091 | 1091 | if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
1092 | 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>'; |
|
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 | 1094 | break; |
1095 | 1095 | } |
1096 | 1096 | } |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | */ |
1112 | 1112 | public function analysis_course_column_title($columns) |
1113 | 1113 | { |
1114 | - if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) { |
|
1114 | + if (isset($_GET['view']) && 'lessons' == $_GET['view']) { |
|
1115 | 1115 | $columns['lesson_module'] = __('Module', 'woothemes-sensei'); |
1116 | 1116 | } |
1117 | 1117 | return $columns; |
@@ -1126,15 +1126,15 @@ discard block |
||
1126 | 1126 | * @param WP_Post $lesson |
1127 | 1127 | * @return array Updated columns data |
1128 | 1128 | */ |
1129 | - public function analysis_course_column_data($columns, $lesson ) |
|
1129 | + public function analysis_course_column_data($columns, $lesson) |
|
1130 | 1130 | { |
1131 | 1131 | |
1132 | - if ( isset( $_GET['course_id'] ) ) { |
|
1132 | + if (isset($_GET['course_id'])) { |
|
1133 | 1133 | $lesson_module = ''; |
1134 | 1134 | $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy); |
1135 | 1135 | if (is_array($lesson_module_list) && count($lesson_module_list) > 0) { |
1136 | 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>'; |
|
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 | 1138 | break; |
1139 | 1139 | } |
1140 | 1140 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | public function get_lesson_module($lesson_id = 0) |
1162 | 1162 | { |
1163 | 1163 | $lesson_id = intval($lesson_id); |
1164 | - if ( ! ( intval( $lesson_id > 0) ) ) { |
|
1164 | + if ( ! (intval($lesson_id > 0))) { |
|
1165 | 1165 | return false; |
1166 | 1166 | } |
1167 | 1167 | |
@@ -1169,13 +1169,13 @@ discard block |
||
1169 | 1169 | $modules = wp_get_post_terms($lesson_id, $this->taxonomy); |
1170 | 1170 | |
1171 | 1171 | //check if error returned |
1172 | - if( empty( $modules ) || isset( $modules['errors'] ) ){ |
|
1172 | + if (empty($modules) || isset($modules['errors'])) { |
|
1173 | 1173 | return false; |
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | // get the last item in the array there should be only be 1 really. |
1177 | 1177 | // this method works for all php versions. |
1178 | - foreach( $modules as $module ){ |
|
1178 | + foreach ($modules as $module) { |
|
1179 | 1179 | break; |
1180 | 1180 | } |
1181 | 1181 | |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | if (isset($course_id) && 0 < $course_id) { |
1189 | 1189 | |
1190 | 1190 | // the course should contain the same module taxonomy term for this to be valid |
1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
1191 | + if ( ! has_term($module, $this->taxonomy, $course_id)) { |
|
1192 | 1192 | return false; |
1193 | 1193 | } |
1194 | 1194 | |
@@ -1262,8 +1262,8 @@ discard block |
||
1262 | 1262 | { |
1263 | 1263 | |
1264 | 1264 | |
1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
1265 | + wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version); |
|
1266 | + wp_enqueue_style($this->taxonomy.'-frontend'); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | /** |
@@ -1273,37 +1273,37 @@ discard block |
||
1273 | 1273 | * |
1274 | 1274 | * @return void |
1275 | 1275 | */ |
1276 | - public function admin_enqueue_scripts( $hook ) { |
|
1276 | + public function admin_enqueue_scripts($hook) { |
|
1277 | 1277 | |
1278 | 1278 | /** |
1279 | 1279 | * Filter the page hooks where modules admin script can be loaded on. |
1280 | 1280 | * |
1281 | 1281 | * @param array $white_listed_pages |
1282 | 1282 | */ |
1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
1283 | + $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array( |
|
1284 | 1284 | 'edit-tags.php', |
1285 | 1285 | 'course_page_module-order', |
1286 | 1286 | 'post-new.php', |
1287 | 1287 | 'post.php' |
1288 | - ) ); |
|
1288 | + )); |
|
1289 | 1289 | |
1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
1290 | + if ( ! in_array($hook, $script_on_pages_white_list)) { |
|
1291 | 1291 | return; |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1294 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
1295 | 1295 | |
1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
1298 | - 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', 'select2' ), Sensei()->version, true ); |
|
1296 | + wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true); |
|
1297 | + wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true); |
|
1298 | + 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', 'select2'), Sensei()->version, true); |
|
1299 | 1299 | |
1300 | 1300 | // localized module data |
1301 | 1301 | $localize_modulesAdmin = array( |
1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
1302 | + 'search_courses_nonce' => wp_create_nonce('search-courses'), |
|
1303 | + 'selectPlaceholder' => __('Search for courses', 'woothemes-sensei') |
|
1304 | 1304 | ); |
1305 | 1305 | |
1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
1306 | + wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | /** |
@@ -1316,8 +1316,8 @@ discard block |
||
1316 | 1316 | public function admin_enqueue_styles() { |
1317 | 1317 | |
1318 | 1318 | |
1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
1319 | + wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version); |
|
1320 | + wp_enqueue_style($this->taxonomy.'-sortable'); |
|
1321 | 1321 | |
1322 | 1322 | } |
1323 | 1323 | |
@@ -1331,9 +1331,9 @@ discard block |
||
1331 | 1331 | */ |
1332 | 1332 | public function course_modules_title( ) { |
1333 | 1333 | |
1334 | - if( sensei_module_has_lessons() ){ |
|
1334 | + if (sensei_module_has_lessons()) { |
|
1335 | 1335 | |
1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
1336 | + echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>'; |
|
1337 | 1337 | |
1338 | 1338 | } |
1339 | 1339 | |
@@ -1346,18 +1346,18 @@ discard block |
||
1346 | 1346 | * @since 1.8.0 |
1347 | 1347 | * @return void |
1348 | 1348 | */ |
1349 | - public function load_course_module_content_template(){ |
|
1349 | + public function load_course_module_content_template() { |
|
1350 | 1350 | |
1351 | 1351 | // load backwards compatible template name if it exists in the users theme |
1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
1353 | - if( $located_template ){ |
|
1352 | + $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php'); |
|
1353 | + if ($located_template) { |
|
1354 | 1354 | |
1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
1355 | + Sensei_Templates::get_template('single-course/course-modules.php'); |
|
1356 | 1356 | return; |
1357 | 1357 | |
1358 | 1358 | } |
1359 | 1359 | |
1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
1360 | + Sensei_Templates::get_template('single-course/modules.php'); |
|
1361 | 1361 | |
1362 | 1362 | } // end course_module_content |
1363 | 1363 | |
@@ -1370,15 +1370,15 @@ discard block |
||
1370 | 1370 | * @param $term_id |
1371 | 1371 | * @return array $lessons |
1372 | 1372 | */ |
1373 | - public function get_lessons( $course_id , $term_id ){ |
|
1373 | + public function get_lessons($course_id, $term_id) { |
|
1374 | 1374 | |
1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
1375 | + $lesson_query = $this->get_lessons_query($course_id, $term_id); |
|
1376 | 1376 | |
1377 | - if( isset( $lesson_query->posts ) ){ |
|
1377 | + if (isset($lesson_query->posts)) { |
|
1378 | 1378 | |
1379 | 1379 | return $lesson_query->posts; |
1380 | 1380 | |
1381 | - }else{ |
|
1381 | + } else { |
|
1382 | 1382 | |
1383 | 1383 | return array(); |
1384 | 1384 | |
@@ -1395,9 +1395,9 @@ discard block |
||
1395 | 1395 | * @param $term_id |
1396 | 1396 | * @return WP_Query $lessons_query |
1397 | 1397 | */ |
1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
1398 | + public function get_lessons_query($course_id, $term_id) { |
|
1399 | 1399 | |
1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
1400 | + if (empty($term_id) || empty($course_id)) { |
|
1401 | 1401 | |
1402 | 1402 | return array(); |
1403 | 1403 | |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | array( |
1419 | 1419 | 'taxonomy' => 'module', |
1420 | 1420 | 'field' => 'id', |
1421 | - 'terms' => intval( $term_id ) |
|
1421 | + 'terms' => intval($term_id) |
|
1422 | 1422 | ) |
1423 | 1423 | ), |
1424 | 1424 | 'orderby' => 'menu_order', |
@@ -1426,12 +1426,12 @@ discard block |
||
1426 | 1426 | 'suppress_filters' => 0 |
1427 | 1427 | ); |
1428 | 1428 | |
1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
1429 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
1430 | + $args['meta_key'] = '_order_module_'.intval($term_id); |
|
1431 | 1431 | $args['orderby'] = 'meta_value_num date'; |
1432 | 1432 | } |
1433 | 1433 | |
1434 | - $lessons_query = new WP_Query( $args ); |
|
1434 | + $lessons_query = new WP_Query($args); |
|
1435 | 1435 | |
1436 | 1436 | return $lessons_query; |
1437 | 1437 | |
@@ -1446,37 +1446,37 @@ discard block |
||
1446 | 1446 | * |
1447 | 1447 | * @return array $non_module_lessons |
1448 | 1448 | */ |
1449 | - public function get_none_module_lessons( $course_id ){ |
|
1449 | + public function get_none_module_lessons($course_id) { |
|
1450 | 1450 | |
1451 | 1451 | $non_module_lessons = array(); |
1452 | 1452 | |
1453 | 1453 | //exit if there is no course id passed in |
1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
1454 | + if (empty($course_id) || 'course' != get_post_type($course_id)) { |
|
1455 | 1455 | |
1456 | 1456 | return $non_module_lessons; |
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | //save some time and check if we already have the saved |
1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
1460 | + if (get_transient('sensei_'.$course_id.'_none_module_lessons')) { |
|
1461 | 1461 | |
1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
1462 | + return get_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
1463 | 1463 | |
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | // create terms array which must be excluded from other arrays |
1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
1467 | + $course_modules = $this->get_course_modules($course_id); |
|
1468 | 1468 | |
1469 | 1469 | //exit if there are no module on this course |
1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
1470 | + if (empty($course_modules) || ! is_array($course_modules)) { |
|
1471 | 1471 | |
1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
1472 | + return Sensei()->course->course_lessons($course_id); |
|
1473 | 1473 | |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | $terms = array(); |
1477 | - foreach( $course_modules as $module ){ |
|
1477 | + foreach ($course_modules as $module) { |
|
1478 | 1478 | |
1479 | - array_push( $terms , $module->term_id ); |
|
1479 | + array_push($terms, $module->term_id); |
|
1480 | 1480 | |
1481 | 1481 | } |
1482 | 1482 | |
@@ -1487,7 +1487,7 @@ discard block |
||
1487 | 1487 | 'meta_query' => array( |
1488 | 1488 | array( |
1489 | 1489 | 'key' => '_lesson_course', |
1490 | - 'value' => intval( $course_id ), |
|
1490 | + 'value' => intval($course_id), |
|
1491 | 1491 | 'compare' => '=' |
1492 | 1492 | ) |
1493 | 1493 | ), |
@@ -1504,11 +1504,11 @@ discard block |
||
1504 | 1504 | 'suppress_filters' => 0 |
1505 | 1505 | ); |
1506 | 1506 | |
1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
1507 | + $wp_lessons_query = new WP_Query($args); |
|
1508 | 1508 | |
1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
1509 | + if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) { |
|
1510 | 1510 | $non_module_lessons = $wp_lessons_query->get_posts(); |
1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
1511 | + set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS); |
|
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | return $non_module_lessons; |
@@ -1519,7 +1519,7 @@ discard block |
||
1519 | 1519 | * |
1520 | 1520 | * @since 1.8.0 |
1521 | 1521 | */ |
1522 | - public function setup_modules_taxonomy(){ |
|
1522 | + public function setup_modules_taxonomy() { |
|
1523 | 1523 | |
1524 | 1524 | $labels = array( |
1525 | 1525 | 'name' => __('Modules', 'woothemes-sensei'), |
@@ -1556,11 +1556,11 @@ discard block |
||
1556 | 1556 | 'show_in_nav_menus' => false, |
1557 | 1557 | 'show_in_quick_edit' => false, |
1558 | 1558 | 'show_ui' => true, |
1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug), |
|
1560 | 1560 | 'labels' => $labels |
1561 | 1561 | ); |
1562 | 1562 | |
1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
1563 | + register_taxonomy('module', array('course', 'lesson'), $args); |
|
1564 | 1564 | |
1565 | 1565 | }// end setup_modules_taxonomy |
1566 | 1566 | |
@@ -1572,12 +1572,12 @@ discard block |
||
1572 | 1572 | * @since 1.8.0 |
1573 | 1573 | * @return void |
1574 | 1574 | */ |
1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
1575 | + function redirect_to_lesson_module_taxonomy_to_course( ) { |
|
1576 | 1576 | |
1577 | - global $typenow , $taxnow; |
|
1577 | + global $typenow, $taxnow; |
|
1578 | 1578 | |
1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
1579 | + if ('lesson' == $typenow && 'module' == $taxnow) { |
|
1580 | + wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course')); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | }// end redirect to course taxonomy |
@@ -1590,18 +1590,18 @@ discard block |
||
1590 | 1590 | * @since 1.8.0 |
1591 | 1591 | * @return void |
1592 | 1592 | */ |
1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
1593 | + public function remove_lessons_menu_model_taxonomy() { |
|
1594 | 1594 | global $submenu; |
1595 | 1595 | |
1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
1596 | + if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) { |
|
1597 | 1597 | return; // exit |
1598 | 1598 | } |
1599 | 1599 | |
1600 | 1600 | $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
1601 | + foreach ($lesson_main_menu as $index => $sub_item) { |
|
1602 | 1602 | |
1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
1603 | + if ('edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2]) { |
|
1604 | + unset($submenu['edit.php?post_type=lesson'][$index]); |
|
1605 | 1605 | } |
1606 | 1606 | } |
1607 | 1607 | |
@@ -1615,18 +1615,18 @@ discard block |
||
1615 | 1615 | * @since 1.8.0 |
1616 | 1616 | * @return void |
1617 | 1617 | */ |
1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
1618 | + public function remove_courses_menu_model_taxonomy() { |
|
1619 | 1619 | global $submenu; |
1620 | 1620 | |
1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
1621 | + if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) { |
|
1622 | 1622 | return; // exit |
1623 | 1623 | } |
1624 | 1624 | |
1625 | 1625 | $course_main_menu = $submenu['edit.php?post_type=course']; |
1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
1626 | + foreach ($course_main_menu as $index => $sub_item) { |
|
1627 | 1627 | |
1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
1628 | + if ('edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2]) { |
|
1629 | + unset($submenu['edit.php?post_type=course'][$index]); |
|
1630 | 1630 | } |
1631 | 1631 | } |
1632 | 1632 | |
@@ -1642,12 +1642,12 @@ discard block |
||
1642 | 1642 | * @param string $term_name |
1643 | 1643 | * @return array $owners { type WP_User }. Empty array if none if found. |
1644 | 1644 | */ |
1645 | - public static function get_term_authors( $term_name ){ |
|
1645 | + public static function get_term_authors($term_name) { |
|
1646 | 1646 | |
1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
1647 | + $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false)); |
|
1648 | 1648 | |
1649 | 1649 | $owners = array(); |
1650 | - if( empty( $terms ) ){ |
|
1650 | + if (empty($terms)) { |
|
1651 | 1651 | |
1652 | 1652 | return $owners; |
1653 | 1653 | |
@@ -1657,11 +1657,11 @@ discard block |
||
1657 | 1657 | |
1658 | 1658 | |
1659 | 1659 | //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
1660 | - foreach( $terms as $term){ |
|
1661 | - if( $term->name == $term_name ){ |
|
1660 | + foreach ($terms as $term) { |
|
1661 | + if ($term->name == $term_name) { |
|
1662 | 1662 | |
1663 | 1663 | // look for the author in the slug |
1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1664 | + $owners[] = Sensei_Core_Modules::get_term_author($term->slug); |
|
1665 | 1665 | |
1666 | 1666 | }// end if term name |
1667 | 1667 | |
@@ -1682,30 +1682,30 @@ discard block |
||
1682 | 1682 | * @param $slug |
1683 | 1683 | * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
1684 | 1684 | */ |
1685 | - public static function get_term_author( $slug='' ){ |
|
1685 | + public static function get_term_author($slug = '') { |
|
1686 | 1686 | |
1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
1687 | + $term_owner = get_user_by('email', get_bloginfo('admin_email')); |
|
1688 | 1688 | |
1689 | - if( empty( $slug ) ){ |
|
1689 | + if (empty($slug)) { |
|
1690 | 1690 | |
1691 | 1691 | return $term_owner; |
1692 | 1692 | |
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | // look for the author in the slug |
1696 | - $slug_parts = explode( '-', $slug ); |
|
1696 | + $slug_parts = explode('-', $slug); |
|
1697 | 1697 | |
1698 | - if( count( $slug_parts ) > 1 ){ |
|
1698 | + if (count($slug_parts) > 1) { |
|
1699 | 1699 | |
1700 | 1700 | // get the user data |
1701 | 1701 | $possible_user_id = $slug_parts[0]; |
1702 | - $author = get_userdata( $possible_user_id ); |
|
1702 | + $author = get_userdata($possible_user_id); |
|
1703 | 1703 | |
1704 | 1704 | // if the user doesnt exist for the first part of the slug |
1705 | 1705 | // then this slug was also created by admin |
1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
1706 | + if (is_a($author, 'WP_User')) { |
|
1707 | 1707 | |
1708 | - $term_owner = $author; |
|
1708 | + $term_owner = $author; |
|
1709 | 1709 | |
1710 | 1710 | } |
1711 | 1711 | } |
@@ -1722,48 +1722,48 @@ discard block |
||
1722 | 1722 | * |
1723 | 1723 | * @param WP_Post $post Post object. |
1724 | 1724 | */ |
1725 | - public function course_module_metabox( $post ) { |
|
1725 | + public function course_module_metabox($post) { |
|
1726 | 1726 | |
1727 | 1727 | $tax_name = 'module'; |
1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
1728 | + $taxonomy = get_taxonomy('module'); |
|
1729 | 1729 | |
1730 | 1730 | ?> |
1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
1734 | - <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li> |
|
1734 | + <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li> |
|
1735 | 1735 | </ul> |
1736 | 1736 | |
1737 | 1737 | <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;"> |
1738 | 1738 | <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" > |
1739 | - <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?> |
|
1739 | + <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?> |
|
1740 | 1740 | </ul> |
1741 | 1741 | </div> |
1742 | 1742 | |
1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
1744 | 1744 | <?php |
1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
1745 | + $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']'; |
|
1746 | 1746 | 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. |
1747 | 1747 | ?> |
1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
1749 | - <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
|
1749 | + <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?> |
|
1750 | 1750 | </ul> |
1751 | 1751 | </div> |
1752 | - <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> |
|
1752 | + <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?> |
|
1753 | 1753 | <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children"> |
1754 | 1754 | <h4> |
1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
1756 | 1756 | <?php |
1757 | 1757 | /* translators: %s: add new taxonomy label */ |
1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
1758 | + printf(__('+ %s'), $taxonomy->labels->add_new_item); |
|
1759 | 1759 | ?> |
1760 | 1760 | </a> |
1761 | 1761 | </h4> |
1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
1763 | 1763 | <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
1764 | - <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/> |
|
1765 | - <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a> |
|
1766 | - <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?> |
|
1764 | + <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/> |
|
1765 | + <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a> |
|
1766 | + <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?> |
|
1767 | 1767 | <span id="<?php echo $tax_name; ?>-ajax-response"></span> |
1768 | 1768 | </p> |
1769 | 1769 | </div> |
@@ -1783,55 +1783,55 @@ discard block |
||
1783 | 1783 | public static function add_new_module_term( ) { |
1784 | 1784 | |
1785 | 1785 | |
1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
1786 | + if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) { |
|
1787 | + wp_send_json_error(array('error'=> 'wrong security nonce')); |
|
1788 | 1788 | } |
1789 | 1789 | |
1790 | 1790 | // get the term an create the new term storing infomration |
1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
1791 | + $term_name = sanitize_text_field($_POST['newTerm']); |
|
1792 | 1792 | |
1793 | - if( current_user_can('manage_options' ) ) { |
|
1793 | + if (current_user_can('manage_options')) { |
|
1794 | 1794 | |
1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
1795 | + $term_slug = str_ireplace(' ', '-', trim($term_name)); |
|
1796 | 1796 | |
1797 | 1797 | } else { |
1798 | 1798 | |
1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
1799 | + $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name)); |
|
1800 | 1800 | |
1801 | 1801 | } |
1802 | 1802 | |
1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
1803 | + $course_id = sanitize_text_field($_POST['course_id']); |
|
1804 | 1804 | |
1805 | 1805 | // save the term |
1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
1806 | + $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug)); |
|
1807 | 1807 | |
1808 | 1808 | // send error for all errors except term exits |
1809 | - if( is_wp_error( $slug ) ){ |
|
1809 | + if (is_wp_error($slug)) { |
|
1810 | 1810 | |
1811 | 1811 | // prepare for possible term name and id to be passed down if term exists |
1812 | 1812 | $term_data = array(); |
1813 | 1813 | |
1814 | 1814 | // if term exists also send back the term name and id |
1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
1815 | + if (isset($slug->errors['term_exists'])) { |
|
1816 | 1816 | |
1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
1817 | + $term = get_term_by('slug', $term_slug, 'module'); |
|
1818 | 1818 | $term_data['name'] = $term_name; |
1819 | 1819 | $term_data['id'] = $term->term_id; |
1820 | 1820 | |
1821 | 1821 | // set the object terms |
1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
1822 | + wp_set_object_terms($course_id, $term->term_id, 'module', true); |
|
1823 | 1823 | } |
1824 | 1824 | |
1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
1825 | + wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data)); |
|
1826 | 1826 | |
1827 | 1827 | } |
1828 | 1828 | |
1829 | 1829 | //make sure the new term is checked for this course |
1830 | 1830 | |
1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
1831 | + wp_set_object_terms($course_id, $slug['term_id'], 'module', true); |
|
1832 | 1832 | |
1833 | 1833 | // Handle request then generate response using WP_Ajax_Response |
1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
1834 | + wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name)); |
|
1835 | 1835 | |
1836 | 1836 | } |
1837 | 1837 | |
@@ -1843,26 +1843,26 @@ discard block |
||
1843 | 1843 | * |
1844 | 1844 | * @since 1.8.0 |
1845 | 1845 | */ |
1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
1846 | + public function filter_module_terms($terms, $taxonomies, $args) { |
|
1847 | 1847 | |
1848 | 1848 | //dont limit for admins and other taxonomies. This should also only apply to admin |
1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
1849 | + if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
1850 | 1850 | return $terms; |
1851 | 1851 | } |
1852 | 1852 | |
1853 | 1853 | // avoid infinite call loop |
1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1854 | + remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
1855 | 1855 | |
1856 | 1856 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
1857 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
1858 | 1858 | // change only scrub the terms ids form the array keys |
1859 | - $terms = array_keys( $terms ); |
|
1859 | + $terms = array_keys($terms); |
|
1860 | 1860 | } |
1861 | 1861 | |
1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1862 | + $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
1863 | 1863 | |
1864 | 1864 | // add filter again as removed above |
1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1865 | + add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
1866 | 1866 | |
1867 | 1867 | return $teachers_terms; |
1868 | 1868 | }// end filter_module_terms |
@@ -1875,25 +1875,25 @@ discard block |
||
1875 | 1875 | * |
1876 | 1876 | * @since 1.8.0 |
1877 | 1877 | */ |
1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
1878 | + public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) { |
|
1879 | 1879 | |
1880 | 1880 | //dont limit for admins and other taxonomies. This should also only apply to admin |
1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
1881 | + if (current_user_can('manage_options') || ! is_admin() || empty($terms) |
|
1882 | 1882 | // only apply this to module only taxonomy queries so 1 taxonomy only: |
1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
1883 | + || count($taxonomies) > 1 || ! in_array('module', $taxonomies)) { |
|
1884 | 1884 | return $terms; |
1885 | 1885 | } |
1886 | 1886 | |
1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1887 | + $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
1888 | 1888 | |
1889 | 1889 | // if term objects were passed in send back objects |
1890 | 1890 | // if term id were passed in send that back |
1891 | - if( is_object( $terms[0] ) ){ |
|
1891 | + if (is_object($terms[0])) { |
|
1892 | 1892 | return $term_objects; |
1893 | 1893 | } |
1894 | 1894 | |
1895 | 1895 | $terms = array(); |
1896 | - foreach( $term_objects as $term_object ){ |
|
1896 | + foreach ($term_objects as $term_object) { |
|
1897 | 1897 | $terms[] = $term_object->term_id; |
1898 | 1898 | } |
1899 | 1899 | |
@@ -1911,20 +1911,20 @@ discard block |
||
1911 | 1911 | * @param $user_id |
1912 | 1912 | * @return array |
1913 | 1913 | */ |
1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
1914 | + public function filter_terms_by_owner($terms, $user_id) { |
|
1915 | 1915 | |
1916 | 1916 | $users_terms = array(); |
1917 | 1917 | |
1918 | - foreach( $terms as $index => $term ){ |
|
1918 | + foreach ($terms as $index => $term) { |
|
1919 | 1919 | |
1920 | - if( is_numeric( $term ) ){ |
|
1920 | + if (is_numeric($term)) { |
|
1921 | 1921 | // the term id was given, get the term object |
1922 | - $term = get_term( $term, 'module' ); |
|
1922 | + $term = get_term($term, 'module'); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1925 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
1926 | 1926 | |
1927 | - if ( $user_id == $author->ID ) { |
|
1927 | + if ($user_id == $author->ID) { |
|
1928 | 1928 | // add the term to the teachers terms |
1929 | 1929 | $users_terms[] = $term; |
1930 | 1930 | } |
@@ -1943,34 +1943,34 @@ discard block |
||
1943 | 1943 | * |
1944 | 1944 | * @since 1.8.0 |
1945 | 1945 | */ |
1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
1946 | + public function append_teacher_name_to_module($terms, $taxonomies, $args) |
|
1947 | 1947 | { |
1948 | 1948 | |
1949 | 1949 | // only for admin users ont he module taxonomy |
1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
1950 | + if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
1951 | 1951 | return $terms; |
1952 | 1952 | } |
1953 | 1953 | |
1954 | 1954 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
1955 | 1955 | // simply return this as wp doesn't need an array of stdObject Term |
1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
1956 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
1957 | 1957 | |
1958 | 1958 | return $terms; |
1959 | 1959 | |
1960 | 1960 | } |
1961 | 1961 | |
1962 | 1962 | // loop through and update all terms adding the author name |
1963 | - foreach( $terms as $index => $term ){ |
|
1963 | + foreach ($terms as $index => $term) { |
|
1964 | 1964 | |
1965 | - if( is_numeric( $term ) ){ |
|
1965 | + if (is_numeric($term)) { |
|
1966 | 1966 | // the term id was given, get the term object |
1967 | - $term = get_term( $term, 'module' ); |
|
1967 | + $term = get_term($term, 'module'); |
|
1968 | 1968 | } |
1969 | 1969 | |
1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1970 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
1971 | 1971 | |
1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
1972 | + if ( ! user_can($author, 'manage_options')) { |
|
1973 | + $term->name = $term->name.' ('.$author->display_name.') '; |
|
1974 | 1974 | } |
1975 | 1975 | |
1976 | 1976 | // add the term to the teachers terms |
@@ -1999,23 +1999,23 @@ discard block |
||
1999 | 1999 | * @sine 1.9.0 |
2000 | 2000 | * @param $post_id |
2001 | 2001 | */ |
2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
2002 | + public static function reset_none_modules_transient($post_id) { |
|
2003 | 2003 | |
2004 | 2004 | // this should only apply to course and lesson post types |
2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
2005 | + if (in_array(get_post_type($post_id), array('course', 'lesson'))) { |
|
2006 | 2006 | |
2007 | 2007 | $course_id = ''; |
2008 | 2008 | |
2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
2009 | + if ('lesson' == get_post_type($post_id)) { |
|
2010 | 2010 | |
2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
2011 | + $course_id = Sensei()->lesson->get_course_id($post_id); |
|
2012 | 2012 | |
2013 | 2013 | } |
2014 | 2014 | |
2015 | 2015 | |
2016 | - if( !empty( $course_id ) ){ |
|
2016 | + if ( ! empty($course_id)) { |
|
2017 | 2017 | |
2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
2018 | + delete_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
2019 | 2019 | |
2020 | 2020 | } |
2021 | 2021 | |
@@ -2030,9 +2030,9 @@ discard block |
||
2030 | 2030 | * @deprecated since 1.9.0 |
2031 | 2031 | * |
2032 | 2032 | */ |
2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
2033 | + public static function deprecate_sensei_single_course_modules_content() { |
|
2034 | 2034 | |
2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
2035 | + sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after'); |
|
2036 | 2036 | |
2037 | 2037 | } |
2038 | 2038 | |
@@ -2043,12 +2043,12 @@ discard block |
||
2043 | 2043 | * |
2044 | 2044 | * @since 1.9.0 |
2045 | 2045 | */ |
2046 | - public static function setup_single_course_module_loop(){ |
|
2046 | + public static function setup_single_course_module_loop() { |
|
2047 | 2047 | |
2048 | 2048 | global $sensei_modules_loop, $post; |
2049 | 2049 | $course_id = $post->ID; |
2050 | 2050 | |
2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
2051 | + $modules = Sensei()->modules->get_course_modules($course_id); |
|
2052 | 2052 | |
2053 | 2053 | //initial setup |
2054 | 2054 | $sensei_modules_loop['total'] = 0; |
@@ -2056,22 +2056,22 @@ discard block |
||
2056 | 2056 | $sensei_modules_loop['current'] = -1; |
2057 | 2057 | |
2058 | 2058 | // exit if this course doesn't have modules |
2059 | - if( !$modules || empty( $modules ) ){ |
|
2059 | + if ( ! $modules || empty($modules)) { |
|
2060 | 2060 | return; |
2061 | 2061 | } |
2062 | 2062 | |
2063 | 2063 | |
2064 | 2064 | $lessons_in_all_modules = array(); |
2065 | - foreach( $modules as $term ){ |
|
2065 | + foreach ($modules as $term) { |
|
2066 | 2066 | |
2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id); |
|
2068 | + $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module); |
|
2069 | 2069 | |
2070 | 2070 | } |
2071 | 2071 | |
2072 | 2072 | |
2073 | 2073 | //setup all of the modules loop variables |
2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
2074 | + $sensei_modules_loop['total'] = count($modules); |
|
2075 | 2075 | $sensei_modules_loop['modules'] = $modules; |
2076 | 2076 | $sensei_modules_loop['current'] = -1; |
2077 | 2077 | $sensei_modules_loop['course_id'] = $course_id; |
@@ -2084,7 +2084,7 @@ discard block |
||
2084 | 2084 | * @since 1.9.0 |
2085 | 2085 | * |
2086 | 2086 | */ |
2087 | - public static function teardown_single_course_module_loop(){ |
|
2087 | + public static function teardown_single_course_module_loop() { |
|
2088 | 2088 | |
2089 | 2089 | global $sensei_modules_loop, $wp_query, $post; |
2090 | 2090 |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | /** |
6 | 8 | * Sensei Modules Class |
@@ -401,8 +403,9 @@ discard block |
||
401 | 403 | $term = urldecode(stripslashes($_GET['term'])); |
402 | 404 | |
403 | 405 | // Return nothing if term is empty |
404 | - if (empty($term)) |
|
405 | - die(); |
|
406 | + if (empty($term)) { |
|
407 | + die(); |
|
408 | + } |
|
406 | 409 | |
407 | 410 | // Set a default if none is given |
408 | 411 | $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei'); |
@@ -789,7 +792,9 @@ discard block |
||
789 | 792 | ); |
790 | 793 | $lessons = get_posts($args); |
791 | 794 | |
792 | - if (is_wp_error($lessons) || 0 >= count($lessons)) return 0; |
|
795 | + if (is_wp_error($lessons) || 0 >= count($lessons)) { |
|
796 | + return 0; |
|
797 | + } |
|
793 | 798 | |
794 | 799 | $completed = false; |
795 | 800 | $lesson_count = 0; |
@@ -1378,7 +1383,7 @@ discard block |
||
1378 | 1383 | |
1379 | 1384 | return $lesson_query->posts; |
1380 | 1385 | |
1381 | - }else{ |
|
1386 | + } else{ |
|
1382 | 1387 | |
1383 | 1388 | return array(); |
1384 | 1389 |
@@ -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,1399 +335,1399 @@ 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 ) || isset( $modules['errors'] ) ){ |
|
1173 | - return false; |
|
1174 | - } |
|
1175 | - |
|
1176 | - // get the last item in the array there should be only be 1 really. |
|
1177 | - // this method works for all php versions. |
|
1178 | - foreach( $modules as $module ){ |
|
1179 | - break; |
|
1180 | - } |
|
1181 | - |
|
1182 | - if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
1183 | - return false; |
|
1184 | - } |
|
1185 | - |
|
1186 | - $module->url = get_term_link($module, $this->taxonomy); |
|
1187 | - $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
1188 | - if (isset($course_id) && 0 < $course_id) { |
|
1189 | - |
|
1190 | - // the course should contain the same module taxonomy term for this to be valid |
|
1191 | - if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
1192 | - return false; |
|
1193 | - } |
|
1194 | - |
|
1195 | - $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
1196 | - } |
|
1197 | - return $module; |
|
1198 | - |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Get ordered array of all modules in course |
|
1203 | - * |
|
1204 | - * @since 1.8.0 |
|
1205 | - * |
|
1206 | - * @param integer $course_id ID of course |
|
1207 | - * @return array Ordered array of module taxonomy term objects |
|
1208 | - */ |
|
1209 | - public function get_course_modules($course_id = 0) |
|
1210 | - { |
|
1211 | - $course_id = intval($course_id); |
|
1212 | - if (0 < $course_id) { |
|
1213 | - |
|
1214 | - // Get modules for course |
|
1215 | - $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
1216 | - |
|
1217 | - // Get custom module order for course |
|
1218 | - $order = $this->get_course_module_order($course_id); |
|
1219 | - |
|
1220 | - // Sort by custom order if custom order exists |
|
1221 | - if ($order) { |
|
1222 | - $ordered_modules = array(); |
|
1223 | - $unordered_modules = array(); |
|
1224 | - foreach ($modules as $module) { |
|
1225 | - $order_key = array_search($module->term_id, $order); |
|
1226 | - if ($order_key !== false) { |
|
1227 | - $ordered_modules[$order_key] = $module; |
|
1228 | - } else { |
|
1229 | - $unordered_modules[] = $module; |
|
1230 | - } |
|
1231 | - } |
|
1232 | - |
|
1233 | - // Order modules correctly |
|
1234 | - ksort($ordered_modules); |
|
1235 | - |
|
1236 | - // Append modules that have not yet been ordered |
|
1237 | - if (count($unordered_modules) > 0) { |
|
1238 | - $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
1239 | - } |
|
1240 | - |
|
1241 | - } else { |
|
1242 | - |
|
1243 | - $ordered_modules = $modules; |
|
1244 | - |
|
1245 | - } |
|
1246 | - |
|
1247 | - return $ordered_modules; |
|
1248 | - |
|
1249 | - } |
|
1250 | - |
|
1251 | - return false; |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * Load frontend CSS |
|
1256 | - * |
|
1257 | - * @since 1.8.0 |
|
1258 | - * |
|
1259 | - * @return void |
|
1260 | - */ |
|
1261 | - public function enqueue_styles() |
|
1262 | - { |
|
1263 | - |
|
1264 | - |
|
1265 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
1266 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Load admin Javascript |
|
1271 | - * |
|
1272 | - * @since 1.8.0 |
|
1273 | - * |
|
1274 | - * @return void |
|
1275 | - */ |
|
1276 | - public function admin_enqueue_scripts( $hook ) { |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * Filter the page hooks where modules admin script can be loaded on. |
|
1280 | - * |
|
1281 | - * @param array $white_listed_pages |
|
1282 | - */ |
|
1283 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
1284 | - 'edit-tags.php', |
|
1285 | - 'course_page_module-order', |
|
1286 | - 'post-new.php', |
|
1287 | - 'post.php' |
|
1288 | - ) ); |
|
1289 | - |
|
1290 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
1291 | - return; |
|
1292 | - } |
|
1293 | - |
|
1294 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1295 | - |
|
1296 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
1297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
1298 | - 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', 'select2' ), Sensei()->version, true ); |
|
1299 | - |
|
1300 | - // localized module data |
|
1301 | - $localize_modulesAdmin = array( |
|
1302 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
1303 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
1304 | - ); |
|
1305 | - |
|
1306 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
1307 | - } |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * Load admin CSS |
|
1311 | - * |
|
1312 | - * @since 1.8.0 |
|
1313 | - * |
|
1314 | - * @return void |
|
1315 | - */ |
|
1316 | - public function admin_enqueue_styles() { |
|
1317 | - |
|
1318 | - |
|
1319 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
1320 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
1321 | - |
|
1322 | - } |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * Show the title modules on the single course template. |
|
1326 | - * |
|
1327 | - * Function is hooked into sensei_single_course_modules_before. |
|
1328 | - * |
|
1329 | - * @since 1.8.0 |
|
1330 | - * @return void |
|
1331 | - */ |
|
1332 | - public function course_modules_title( ) { |
|
1333 | - |
|
1334 | - if( sensei_module_has_lessons() ){ |
|
1335 | - |
|
1336 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
1337 | - |
|
1338 | - } |
|
1339 | - |
|
1340 | - } |
|
1341 | - |
|
1342 | - /** |
|
1343 | - * Display the single course modules content this will only show |
|
1344 | - * if the course has modules. |
|
1345 | - * |
|
1346 | - * @since 1.8.0 |
|
1347 | - * @return void |
|
1348 | - */ |
|
1349 | - public function load_course_module_content_template(){ |
|
1350 | - |
|
1351 | - // load backwards compatible template name if it exists in the users theme |
|
1352 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
1353 | - if( $located_template ){ |
|
1354 | - |
|
1355 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
1356 | - return; |
|
1357 | - |
|
1358 | - } |
|
1359 | - |
|
1360 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
1361 | - |
|
1362 | - } // end course_module_content |
|
1363 | - |
|
1364 | - /** |
|
1365 | - * Returns all lessons for the given module ID |
|
1366 | - * |
|
1367 | - * @since 1.8.0 |
|
1368 | - * |
|
1369 | - * @param $course_id |
|
1370 | - * @param $term_id |
|
1371 | - * @return array $lessons |
|
1372 | - */ |
|
1373 | - public function get_lessons( $course_id , $term_id ){ |
|
1374 | - |
|
1375 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
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 ) || isset( $modules['errors'] ) ){ |
|
1173 | + return false; |
|
1174 | + } |
|
1175 | + |
|
1176 | + // get the last item in the array there should be only be 1 really. |
|
1177 | + // this method works for all php versions. |
|
1178 | + foreach( $modules as $module ){ |
|
1179 | + break; |
|
1180 | + } |
|
1181 | + |
|
1182 | + if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) { |
|
1183 | + return false; |
|
1184 | + } |
|
1185 | + |
|
1186 | + $module->url = get_term_link($module, $this->taxonomy); |
|
1187 | + $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true)); |
|
1188 | + if (isset($course_id) && 0 < $course_id) { |
|
1189 | + |
|
1190 | + // the course should contain the same module taxonomy term for this to be valid |
|
1191 | + if( ! has_term( $module, $this->taxonomy, $course_id)){ |
|
1192 | + return false; |
|
1193 | + } |
|
1194 | + |
|
1195 | + $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url)); |
|
1196 | + } |
|
1197 | + return $module; |
|
1198 | + |
|
1199 | + } |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Get ordered array of all modules in course |
|
1203 | + * |
|
1204 | + * @since 1.8.0 |
|
1205 | + * |
|
1206 | + * @param integer $course_id ID of course |
|
1207 | + * @return array Ordered array of module taxonomy term objects |
|
1208 | + */ |
|
1209 | + public function get_course_modules($course_id = 0) |
|
1210 | + { |
|
1211 | + $course_id = intval($course_id); |
|
1212 | + if (0 < $course_id) { |
|
1213 | + |
|
1214 | + // Get modules for course |
|
1215 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
1216 | + |
|
1217 | + // Get custom module order for course |
|
1218 | + $order = $this->get_course_module_order($course_id); |
|
1219 | + |
|
1220 | + // Sort by custom order if custom order exists |
|
1221 | + if ($order) { |
|
1222 | + $ordered_modules = array(); |
|
1223 | + $unordered_modules = array(); |
|
1224 | + foreach ($modules as $module) { |
|
1225 | + $order_key = array_search($module->term_id, $order); |
|
1226 | + if ($order_key !== false) { |
|
1227 | + $ordered_modules[$order_key] = $module; |
|
1228 | + } else { |
|
1229 | + $unordered_modules[] = $module; |
|
1230 | + } |
|
1231 | + } |
|
1232 | + |
|
1233 | + // Order modules correctly |
|
1234 | + ksort($ordered_modules); |
|
1235 | + |
|
1236 | + // Append modules that have not yet been ordered |
|
1237 | + if (count($unordered_modules) > 0) { |
|
1238 | + $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
|
1239 | + } |
|
1240 | + |
|
1241 | + } else { |
|
1242 | + |
|
1243 | + $ordered_modules = $modules; |
|
1244 | + |
|
1245 | + } |
|
1246 | + |
|
1247 | + return $ordered_modules; |
|
1248 | + |
|
1249 | + } |
|
1250 | + |
|
1251 | + return false; |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * Load frontend CSS |
|
1256 | + * |
|
1257 | + * @since 1.8.0 |
|
1258 | + * |
|
1259 | + * @return void |
|
1260 | + */ |
|
1261 | + public function enqueue_styles() |
|
1262 | + { |
|
1263 | + |
|
1264 | + |
|
1265 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
1266 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Load admin Javascript |
|
1271 | + * |
|
1272 | + * @since 1.8.0 |
|
1273 | + * |
|
1274 | + * @return void |
|
1275 | + */ |
|
1276 | + public function admin_enqueue_scripts( $hook ) { |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * Filter the page hooks where modules admin script can be loaded on. |
|
1280 | + * |
|
1281 | + * @param array $white_listed_pages |
|
1282 | + */ |
|
1283 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
1284 | + 'edit-tags.php', |
|
1285 | + 'course_page_module-order', |
|
1286 | + 'post-new.php', |
|
1287 | + 'post.php' |
|
1288 | + ) ); |
|
1289 | + |
|
1290 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
1291 | + return; |
|
1292 | + } |
|
1293 | + |
|
1294 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
1295 | + |
|
1296 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
1297 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
1298 | + 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', 'select2' ), Sensei()->version, true ); |
|
1299 | + |
|
1300 | + // localized module data |
|
1301 | + $localize_modulesAdmin = array( |
|
1302 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
1303 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
1304 | + ); |
|
1305 | + |
|
1306 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
1307 | + } |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * Load admin CSS |
|
1311 | + * |
|
1312 | + * @since 1.8.0 |
|
1313 | + * |
|
1314 | + * @return void |
|
1315 | + */ |
|
1316 | + public function admin_enqueue_styles() { |
|
1317 | + |
|
1318 | + |
|
1319 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
1320 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
1321 | + |
|
1322 | + } |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * Show the title modules on the single course template. |
|
1326 | + * |
|
1327 | + * Function is hooked into sensei_single_course_modules_before. |
|
1328 | + * |
|
1329 | + * @since 1.8.0 |
|
1330 | + * @return void |
|
1331 | + */ |
|
1332 | + public function course_modules_title( ) { |
|
1333 | + |
|
1334 | + if( sensei_module_has_lessons() ){ |
|
1335 | + |
|
1336 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
1337 | + |
|
1338 | + } |
|
1339 | + |
|
1340 | + } |
|
1341 | + |
|
1342 | + /** |
|
1343 | + * Display the single course modules content this will only show |
|
1344 | + * if the course has modules. |
|
1345 | + * |
|
1346 | + * @since 1.8.0 |
|
1347 | + * @return void |
|
1348 | + */ |
|
1349 | + public function load_course_module_content_template(){ |
|
1350 | + |
|
1351 | + // load backwards compatible template name if it exists in the users theme |
|
1352 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
1353 | + if( $located_template ){ |
|
1354 | + |
|
1355 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
1356 | + return; |
|
1357 | + |
|
1358 | + } |
|
1359 | + |
|
1360 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
1361 | + |
|
1362 | + } // end course_module_content |
|
1363 | + |
|
1364 | + /** |
|
1365 | + * Returns all lessons for the given module ID |
|
1366 | + * |
|
1367 | + * @since 1.8.0 |
|
1368 | + * |
|
1369 | + * @param $course_id |
|
1370 | + * @param $term_id |
|
1371 | + * @return array $lessons |
|
1372 | + */ |
|
1373 | + public function get_lessons( $course_id , $term_id ){ |
|
1374 | + |
|
1375 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
1376 | 1376 | |
1377 | - if( isset( $lesson_query->posts ) ){ |
|
1377 | + if( isset( $lesson_query->posts ) ){ |
|
1378 | 1378 | |
1379 | - return $lesson_query->posts; |
|
1379 | + return $lesson_query->posts; |
|
1380 | 1380 | |
1381 | - }else{ |
|
1381 | + }else{ |
|
1382 | 1382 | |
1383 | - return array(); |
|
1383 | + return array(); |
|
1384 | 1384 | |
1385 | - } |
|
1385 | + } |
|
1386 | 1386 | |
1387 | - } // end get lessons |
|
1387 | + } // end get lessons |
|
1388 | 1388 | |
1389 | - /** |
|
1390 | - * Returns all lessons for the given module ID |
|
1391 | - * |
|
1392 | - * @since 1.8.0 |
|
1393 | - * |
|
1394 | - * @param $course_id |
|
1395 | - * @param $term_id |
|
1396 | - * @return WP_Query $lessons_query |
|
1397 | - */ |
|
1398 | - public function get_lessons_query( $course_id , $term_id ){ |
|
1399 | - |
|
1400 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
1401 | - |
|
1402 | - return array(); |
|
1403 | - |
|
1404 | - } |
|
1405 | - |
|
1406 | - $args = array( |
|
1407 | - 'post_type' => 'lesson', |
|
1408 | - 'post_status' => 'publish', |
|
1409 | - 'posts_per_page' => -1, |
|
1410 | - 'meta_query' => array( |
|
1411 | - array( |
|
1412 | - 'key' => '_lesson_course', |
|
1413 | - 'value' => intval($course_id), |
|
1414 | - 'compare' => '=' |
|
1415 | - ) |
|
1416 | - ), |
|
1417 | - 'tax_query' => array( |
|
1418 | - array( |
|
1419 | - 'taxonomy' => 'module', |
|
1420 | - 'field' => 'id', |
|
1421 | - 'terms' => intval( $term_id ) |
|
1422 | - ) |
|
1423 | - ), |
|
1424 | - 'orderby' => 'menu_order', |
|
1425 | - 'order' => 'ASC', |
|
1426 | - 'suppress_filters' => 0 |
|
1427 | - ); |
|
1428 | - |
|
1429 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
1430 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
1431 | - $args['orderby'] = 'meta_value_num date'; |
|
1432 | - } |
|
1433 | - |
|
1434 | - $lessons_query = new WP_Query( $args ); |
|
1435 | - |
|
1436 | - return $lessons_query; |
|
1437 | - |
|
1438 | - } // end get lessons |
|
1439 | - |
|
1440 | - /** |
|
1441 | - * Find the lesson in the given course that doesn't belong |
|
1442 | - * to any of the courses modules |
|
1443 | - * |
|
1444 | - * |
|
1445 | - * @param $course_id |
|
1446 | - * |
|
1447 | - * @return array $non_module_lessons |
|
1448 | - */ |
|
1449 | - public function get_none_module_lessons( $course_id ){ |
|
1450 | - |
|
1451 | - $non_module_lessons = array(); |
|
1452 | - |
|
1453 | - //exit if there is no course id passed in |
|
1454 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
1455 | - |
|
1456 | - return $non_module_lessons; |
|
1457 | - } |
|
1458 | - |
|
1459 | - //save some time and check if we already have the saved |
|
1460 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
1461 | - |
|
1462 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
1463 | - |
|
1464 | - } |
|
1465 | - |
|
1466 | - // create terms array which must be excluded from other arrays |
|
1467 | - $course_modules = $this->get_course_modules( $course_id ); |
|
1468 | - |
|
1469 | - //exit if there are no module on this course |
|
1470 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
1471 | - |
|
1472 | - return Sensei()->course->course_lessons( $course_id ); |
|
1473 | - |
|
1474 | - } |
|
1475 | - |
|
1476 | - $terms = array(); |
|
1477 | - foreach( $course_modules as $module ){ |
|
1478 | - |
|
1479 | - array_push( $terms , $module->term_id ); |
|
1480 | - |
|
1481 | - } |
|
1482 | - |
|
1483 | - $args = array( |
|
1484 | - 'post_type' => 'lesson', |
|
1485 | - 'post_status' => 'publish', |
|
1486 | - 'posts_per_page' => -1, |
|
1487 | - 'meta_query' => array( |
|
1488 | - array( |
|
1489 | - 'key' => '_lesson_course', |
|
1490 | - 'value' => intval( $course_id ), |
|
1491 | - 'compare' => '=' |
|
1492 | - ) |
|
1493 | - ), |
|
1494 | - 'tax_query' => array( |
|
1495 | - array( |
|
1496 | - 'taxonomy' => 'module', |
|
1497 | - 'field' => 'id', |
|
1498 | - 'terms' => $terms, |
|
1499 | - 'operator' => 'NOT IN' |
|
1500 | - ) |
|
1501 | - ), |
|
1502 | - 'orderby' => 'menu_order', |
|
1503 | - 'order' => 'ASC', |
|
1504 | - 'suppress_filters' => 0 |
|
1505 | - ); |
|
1506 | - |
|
1507 | - $wp_lessons_query = new WP_Query( $args ); |
|
1508 | - |
|
1509 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
1510 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
1511 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
1512 | - } |
|
1513 | - |
|
1514 | - return $non_module_lessons; |
|
1515 | - } // end get_none_module_lessons |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * Register the modules taxonomy |
|
1519 | - * |
|
1520 | - * @since 1.8.0 |
|
1521 | - */ |
|
1522 | - public function setup_modules_taxonomy(){ |
|
1523 | - |
|
1524 | - $labels = array( |
|
1525 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
1526 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
1527 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
1528 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
1529 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
1530 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
1531 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
1532 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
1533 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
1534 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
1535 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
1536 | - ); |
|
1537 | - |
|
1538 | - /** |
|
1539 | - * Filter to alter the Sensei Modules rewrite slug |
|
1540 | - * |
|
1541 | - * @since 1.8.0 |
|
1542 | - * @param string default 'modules' |
|
1543 | - */ |
|
1544 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
1545 | - |
|
1546 | - $args = array( |
|
1547 | - 'public' => true, |
|
1548 | - 'hierarchical' => true, |
|
1549 | - 'show_admin_column' => true, |
|
1550 | - 'capabilities' => array( |
|
1551 | - 'manage_terms' => 'manage_categories', |
|
1552 | - 'edit_terms' => 'edit_courses', |
|
1553 | - 'delete_terms' => 'manage_categories', |
|
1554 | - 'assign_terms' => 'edit_courses' |
|
1555 | - ), |
|
1556 | - 'show_in_nav_menus' => false, |
|
1557 | - 'show_in_quick_edit' => false, |
|
1558 | - 'show_ui' => true, |
|
1559 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
1560 | - 'labels' => $labels |
|
1561 | - ); |
|
1562 | - |
|
1563 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
1564 | - |
|
1565 | - }// end setup_modules_taxonomy |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
1569 | - * |
|
1570 | - * This function is hooked into the admin_menu |
|
1571 | - * |
|
1572 | - * @since 1.8.0 |
|
1573 | - * @return void |
|
1574 | - */ |
|
1575 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
1576 | - |
|
1577 | - global $typenow , $taxnow; |
|
1578 | - |
|
1579 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
1580 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
1581 | - } |
|
1582 | - |
|
1583 | - }// end redirect to course taxonomy |
|
1584 | - |
|
1585 | - /** |
|
1586 | - * Completely remove the module menu item under lessons. |
|
1587 | - * |
|
1588 | - * This function is hooked into the admin_menu |
|
1589 | - * |
|
1590 | - * @since 1.8.0 |
|
1591 | - * @return void |
|
1592 | - */ |
|
1593 | - public function remove_lessons_menu_model_taxonomy(){ |
|
1594 | - global $submenu; |
|
1595 | - |
|
1596 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
1597 | - return; // exit |
|
1598 | - } |
|
1599 | - |
|
1600 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
1601 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
1602 | - |
|
1603 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
1604 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
1605 | - } |
|
1606 | - } |
|
1607 | - |
|
1608 | - }// end remove lesson module tax |
|
1609 | - |
|
1610 | - /** |
|
1611 | - * Completely remove the second modules under courses |
|
1612 | - * |
|
1613 | - * This function is hooked into the admin_menu |
|
1614 | - * |
|
1615 | - * @since 1.8.0 |
|
1616 | - * @return void |
|
1617 | - */ |
|
1618 | - public function remove_courses_menu_model_taxonomy(){ |
|
1619 | - global $submenu; |
|
1620 | - |
|
1621 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
1622 | - return; // exit |
|
1623 | - } |
|
1624 | - |
|
1625 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
1626 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
1627 | - |
|
1628 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
1629 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
1630 | - } |
|
1631 | - } |
|
1632 | - |
|
1633 | - }// end remove courses module tax |
|
1634 | - |
|
1635 | - /** |
|
1636 | - * Determine the author of a module term term by looking at |
|
1637 | - * the prefixed author id. This function will query the full term object. |
|
1638 | - * Will return the admin user author could not be determined. |
|
1639 | - * |
|
1640 | - * @since 1.8.0 |
|
1641 | - * |
|
1642 | - * @param string $term_name |
|
1643 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
1644 | - */ |
|
1645 | - public static function get_term_authors( $term_name ){ |
|
1646 | - |
|
1647 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
1648 | - |
|
1649 | - $owners = array(); |
|
1650 | - if( empty( $terms ) ){ |
|
1651 | - |
|
1652 | - return $owners; |
|
1389 | + /** |
|
1390 | + * Returns all lessons for the given module ID |
|
1391 | + * |
|
1392 | + * @since 1.8.0 |
|
1393 | + * |
|
1394 | + * @param $course_id |
|
1395 | + * @param $term_id |
|
1396 | + * @return WP_Query $lessons_query |
|
1397 | + */ |
|
1398 | + public function get_lessons_query( $course_id , $term_id ){ |
|
1399 | + |
|
1400 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
1401 | + |
|
1402 | + return array(); |
|
1403 | + |
|
1404 | + } |
|
1405 | + |
|
1406 | + $args = array( |
|
1407 | + 'post_type' => 'lesson', |
|
1408 | + 'post_status' => 'publish', |
|
1409 | + 'posts_per_page' => -1, |
|
1410 | + 'meta_query' => array( |
|
1411 | + array( |
|
1412 | + 'key' => '_lesson_course', |
|
1413 | + 'value' => intval($course_id), |
|
1414 | + 'compare' => '=' |
|
1415 | + ) |
|
1416 | + ), |
|
1417 | + 'tax_query' => array( |
|
1418 | + array( |
|
1419 | + 'taxonomy' => 'module', |
|
1420 | + 'field' => 'id', |
|
1421 | + 'terms' => intval( $term_id ) |
|
1422 | + ) |
|
1423 | + ), |
|
1424 | + 'orderby' => 'menu_order', |
|
1425 | + 'order' => 'ASC', |
|
1426 | + 'suppress_filters' => 0 |
|
1427 | + ); |
|
1428 | + |
|
1429 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
1430 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
1431 | + $args['orderby'] = 'meta_value_num date'; |
|
1432 | + } |
|
1433 | + |
|
1434 | + $lessons_query = new WP_Query( $args ); |
|
1435 | + |
|
1436 | + return $lessons_query; |
|
1437 | + |
|
1438 | + } // end get lessons |
|
1439 | + |
|
1440 | + /** |
|
1441 | + * Find the lesson in the given course that doesn't belong |
|
1442 | + * to any of the courses modules |
|
1443 | + * |
|
1444 | + * |
|
1445 | + * @param $course_id |
|
1446 | + * |
|
1447 | + * @return array $non_module_lessons |
|
1448 | + */ |
|
1449 | + public function get_none_module_lessons( $course_id ){ |
|
1450 | + |
|
1451 | + $non_module_lessons = array(); |
|
1452 | + |
|
1453 | + //exit if there is no course id passed in |
|
1454 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
1455 | + |
|
1456 | + return $non_module_lessons; |
|
1457 | + } |
|
1458 | + |
|
1459 | + //save some time and check if we already have the saved |
|
1460 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
1461 | + |
|
1462 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
1463 | + |
|
1464 | + } |
|
1465 | + |
|
1466 | + // create terms array which must be excluded from other arrays |
|
1467 | + $course_modules = $this->get_course_modules( $course_id ); |
|
1468 | + |
|
1469 | + //exit if there are no module on this course |
|
1470 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
1471 | + |
|
1472 | + return Sensei()->course->course_lessons( $course_id ); |
|
1473 | + |
|
1474 | + } |
|
1475 | + |
|
1476 | + $terms = array(); |
|
1477 | + foreach( $course_modules as $module ){ |
|
1478 | + |
|
1479 | + array_push( $terms , $module->term_id ); |
|
1480 | + |
|
1481 | + } |
|
1482 | + |
|
1483 | + $args = array( |
|
1484 | + 'post_type' => 'lesson', |
|
1485 | + 'post_status' => 'publish', |
|
1486 | + 'posts_per_page' => -1, |
|
1487 | + 'meta_query' => array( |
|
1488 | + array( |
|
1489 | + 'key' => '_lesson_course', |
|
1490 | + 'value' => intval( $course_id ), |
|
1491 | + 'compare' => '=' |
|
1492 | + ) |
|
1493 | + ), |
|
1494 | + 'tax_query' => array( |
|
1495 | + array( |
|
1496 | + 'taxonomy' => 'module', |
|
1497 | + 'field' => 'id', |
|
1498 | + 'terms' => $terms, |
|
1499 | + 'operator' => 'NOT IN' |
|
1500 | + ) |
|
1501 | + ), |
|
1502 | + 'orderby' => 'menu_order', |
|
1503 | + 'order' => 'ASC', |
|
1504 | + 'suppress_filters' => 0 |
|
1505 | + ); |
|
1506 | + |
|
1507 | + $wp_lessons_query = new WP_Query( $args ); |
|
1508 | + |
|
1509 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
1510 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
1511 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
1512 | + } |
|
1513 | + |
|
1514 | + return $non_module_lessons; |
|
1515 | + } // end get_none_module_lessons |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * Register the modules taxonomy |
|
1519 | + * |
|
1520 | + * @since 1.8.0 |
|
1521 | + */ |
|
1522 | + public function setup_modules_taxonomy(){ |
|
1523 | + |
|
1524 | + $labels = array( |
|
1525 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
1526 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
1527 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
1528 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
1529 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
1530 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
1531 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
1532 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
1533 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
1534 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
1535 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
1536 | + ); |
|
1537 | + |
|
1538 | + /** |
|
1539 | + * Filter to alter the Sensei Modules rewrite slug |
|
1540 | + * |
|
1541 | + * @since 1.8.0 |
|
1542 | + * @param string default 'modules' |
|
1543 | + */ |
|
1544 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
1545 | + |
|
1546 | + $args = array( |
|
1547 | + 'public' => true, |
|
1548 | + 'hierarchical' => true, |
|
1549 | + 'show_admin_column' => true, |
|
1550 | + 'capabilities' => array( |
|
1551 | + 'manage_terms' => 'manage_categories', |
|
1552 | + 'edit_terms' => 'edit_courses', |
|
1553 | + 'delete_terms' => 'manage_categories', |
|
1554 | + 'assign_terms' => 'edit_courses' |
|
1555 | + ), |
|
1556 | + 'show_in_nav_menus' => false, |
|
1557 | + 'show_in_quick_edit' => false, |
|
1558 | + 'show_ui' => true, |
|
1559 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
1560 | + 'labels' => $labels |
|
1561 | + ); |
|
1562 | + |
|
1563 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
1564 | + |
|
1565 | + }// end setup_modules_taxonomy |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
1569 | + * |
|
1570 | + * This function is hooked into the admin_menu |
|
1571 | + * |
|
1572 | + * @since 1.8.0 |
|
1573 | + * @return void |
|
1574 | + */ |
|
1575 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
1576 | + |
|
1577 | + global $typenow , $taxnow; |
|
1578 | + |
|
1579 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
1580 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
1581 | + } |
|
1582 | + |
|
1583 | + }// end redirect to course taxonomy |
|
1584 | + |
|
1585 | + /** |
|
1586 | + * Completely remove the module menu item under lessons. |
|
1587 | + * |
|
1588 | + * This function is hooked into the admin_menu |
|
1589 | + * |
|
1590 | + * @since 1.8.0 |
|
1591 | + * @return void |
|
1592 | + */ |
|
1593 | + public function remove_lessons_menu_model_taxonomy(){ |
|
1594 | + global $submenu; |
|
1595 | + |
|
1596 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
1597 | + return; // exit |
|
1598 | + } |
|
1599 | + |
|
1600 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
1601 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
1602 | + |
|
1603 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
1604 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
1605 | + } |
|
1606 | + } |
|
1607 | + |
|
1608 | + }// end remove lesson module tax |
|
1609 | + |
|
1610 | + /** |
|
1611 | + * Completely remove the second modules under courses |
|
1612 | + * |
|
1613 | + * This function is hooked into the admin_menu |
|
1614 | + * |
|
1615 | + * @since 1.8.0 |
|
1616 | + * @return void |
|
1617 | + */ |
|
1618 | + public function remove_courses_menu_model_taxonomy(){ |
|
1619 | + global $submenu; |
|
1620 | + |
|
1621 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
1622 | + return; // exit |
|
1623 | + } |
|
1624 | + |
|
1625 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
1626 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
1627 | + |
|
1628 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
1629 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
1630 | + } |
|
1631 | + } |
|
1632 | + |
|
1633 | + }// end remove courses module tax |
|
1634 | + |
|
1635 | + /** |
|
1636 | + * Determine the author of a module term term by looking at |
|
1637 | + * the prefixed author id. This function will query the full term object. |
|
1638 | + * Will return the admin user author could not be determined. |
|
1639 | + * |
|
1640 | + * @since 1.8.0 |
|
1641 | + * |
|
1642 | + * @param string $term_name |
|
1643 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
1644 | + */ |
|
1645 | + public static function get_term_authors( $term_name ){ |
|
1646 | + |
|
1647 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
1648 | + |
|
1649 | + $owners = array(); |
|
1650 | + if( empty( $terms ) ){ |
|
1651 | + |
|
1652 | + return $owners; |
|
1653 | 1653 | |
1654 | - } |
|
1654 | + } |
|
1655 | 1655 | |
1656 | - // setup the admin user |
|
1656 | + // setup the admin user |
|
1657 | 1657 | |
1658 | 1658 | |
1659 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
1660 | - foreach( $terms as $term){ |
|
1661 | - if( $term->name == $term_name ){ |
|
1659 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
1660 | + foreach( $terms as $term){ |
|
1661 | + if( $term->name == $term_name ){ |
|
1662 | 1662 | |
1663 | - // look for the author in the slug |
|
1664 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1663 | + // look for the author in the slug |
|
1664 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1665 | 1665 | |
1666 | - }// end if term name |
|
1666 | + }// end if term name |
|
1667 | 1667 | |
1668 | - } // end for each |
|
1668 | + } // end for each |
|
1669 | 1669 | |
1670 | - return $owners; |
|
1670 | + return $owners; |
|
1671 | 1671 | |
1672 | - }// end get_term_author |
|
1672 | + }// end get_term_author |
|
1673 | 1673 | |
1674 | - /** |
|
1675 | - * Looks at a term slug and figures out |
|
1676 | - * which author created the slug. The author was |
|
1677 | - * appended when the user saved the module term in the course edit |
|
1678 | - * screen. |
|
1679 | - * |
|
1680 | - * @since 1.8.0 |
|
1681 | - * |
|
1682 | - * @param $slug |
|
1683 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
1684 | - */ |
|
1685 | - public static function get_term_author( $slug='' ){ |
|
1674 | + /** |
|
1675 | + * Looks at a term slug and figures out |
|
1676 | + * which author created the slug. The author was |
|
1677 | + * appended when the user saved the module term in the course edit |
|
1678 | + * screen. |
|
1679 | + * |
|
1680 | + * @since 1.8.0 |
|
1681 | + * |
|
1682 | + * @param $slug |
|
1683 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
1684 | + */ |
|
1685 | + public static function get_term_author( $slug='' ){ |
|
1686 | 1686 | |
1687 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
1687 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
1688 | 1688 | |
1689 | - if( empty( $slug ) ){ |
|
1689 | + if( empty( $slug ) ){ |
|
1690 | 1690 | |
1691 | - return $term_owner; |
|
1691 | + return $term_owner; |
|
1692 | 1692 | |
1693 | - } |
|
1693 | + } |
|
1694 | 1694 | |
1695 | - // look for the author in the slug |
|
1696 | - $slug_parts = explode( '-', $slug ); |
|
1695 | + // look for the author in the slug |
|
1696 | + $slug_parts = explode( '-', $slug ); |
|
1697 | 1697 | |
1698 | - if( count( $slug_parts ) > 1 ){ |
|
1698 | + if( count( $slug_parts ) > 1 ){ |
|
1699 | 1699 | |
1700 | - // get the user data |
|
1701 | - $possible_user_id = $slug_parts[0]; |
|
1702 | - $author = get_userdata( $possible_user_id ); |
|
1700 | + // get the user data |
|
1701 | + $possible_user_id = $slug_parts[0]; |
|
1702 | + $author = get_userdata( $possible_user_id ); |
|
1703 | 1703 | |
1704 | - // if the user doesnt exist for the first part of the slug |
|
1705 | - // then this slug was also created by admin |
|
1706 | - if( is_a( $author, 'WP_User' ) ){ |
|
1704 | + // if the user doesnt exist for the first part of the slug |
|
1705 | + // then this slug was also created by admin |
|
1706 | + if( is_a( $author, 'WP_User' ) ){ |
|
1707 | 1707 | |
1708 | - $term_owner = $author; |
|
1708 | + $term_owner = $author; |
|
1709 | 1709 | |
1710 | - } |
|
1711 | - } |
|
1710 | + } |
|
1711 | + } |
|
1712 | 1712 | |
1713 | - return $term_owner; |
|
1714 | - } |
|
1713 | + return $term_owner; |
|
1714 | + } |
|
1715 | 1715 | |
1716 | - /** |
|
1717 | - * Display the Sensei modules taxonomy terms metabox |
|
1718 | - * |
|
1719 | - * @since 1.8.0 |
|
1720 | - * |
|
1721 | - * @hooked into add_meta_box |
|
1722 | - * |
|
1723 | - * @param WP_Post $post Post object. |
|
1724 | - */ |
|
1725 | - public function course_module_metabox( $post ) { |
|
1716 | + /** |
|
1717 | + * Display the Sensei modules taxonomy terms metabox |
|
1718 | + * |
|
1719 | + * @since 1.8.0 |
|
1720 | + * |
|
1721 | + * @hooked into add_meta_box |
|
1722 | + * |
|
1723 | + * @param WP_Post $post Post object. |
|
1724 | + */ |
|
1725 | + public function course_module_metabox( $post ) { |
|
1726 | 1726 | |
1727 | - $tax_name = 'module'; |
|
1728 | - $taxonomy = get_taxonomy( 'module' ); |
|
1727 | + $tax_name = 'module'; |
|
1728 | + $taxonomy = get_taxonomy( 'module' ); |
|
1729 | 1729 | |
1730 | - ?> |
|
1730 | + ?> |
|
1731 | 1731 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
1732 | 1732 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
1733 | 1733 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1742,9 +1742,9 @@ discard block |
||
1742 | 1742 | |
1743 | 1743 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
1744 | 1744 | <?php |
1745 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
1746 | - 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. |
|
1747 | - ?> |
|
1745 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
1746 | + 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. |
|
1747 | + ?> |
|
1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
1749 | 1749 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
1750 | 1750 | </ul> |
@@ -1754,9 +1754,9 @@ discard block |
||
1754 | 1754 | <h4> |
1755 | 1755 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
1756 | 1756 | <?php |
1757 | - /* translators: %s: add new taxonomy label */ |
|
1758 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
1759 | - ?> |
|
1757 | + /* translators: %s: add new taxonomy label */ |
|
1758 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
1759 | + ?> |
|
1760 | 1760 | </a> |
1761 | 1761 | </h4> |
1762 | 1762 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1771,331 +1771,331 @@ discard block |
||
1771 | 1771 | </div> |
1772 | 1772 | <?php |
1773 | 1773 | |
1774 | - } // end course_module_metabox |
|
1774 | + } // end course_module_metabox |
|
1775 | 1775 | |
1776 | 1776 | |
1777 | - /** |
|
1778 | - * Submits a new module term prefixed with the |
|
1779 | - * the current author id. |
|
1780 | - * |
|
1781 | - * @since 1.8.0 |
|
1782 | - */ |
|
1783 | - public static function add_new_module_term( ) { |
|
1777 | + /** |
|
1778 | + * Submits a new module term prefixed with the |
|
1779 | + * the current author id. |
|
1780 | + * |
|
1781 | + * @since 1.8.0 |
|
1782 | + */ |
|
1783 | + public static function add_new_module_term( ) { |
|
1784 | 1784 | |
1785 | 1785 | |
1786 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
1787 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
1788 | - } |
|
1786 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
1787 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
1788 | + } |
|
1789 | 1789 | |
1790 | - // get the term an create the new term storing infomration |
|
1791 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
1790 | + // get the term an create the new term storing infomration |
|
1791 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
1792 | 1792 | |
1793 | - if( current_user_can('manage_options' ) ) { |
|
1793 | + if( current_user_can('manage_options' ) ) { |
|
1794 | 1794 | |
1795 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
1795 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
1796 | 1796 | |
1797 | - } else { |
|
1797 | + } else { |
|
1798 | 1798 | |
1799 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
1799 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
1800 | 1800 | |
1801 | - } |
|
1801 | + } |
|
1802 | 1802 | |
1803 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
1803 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
1804 | 1804 | |
1805 | - // save the term |
|
1806 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
1805 | + // save the term |
|
1806 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
1807 | 1807 | |
1808 | - // send error for all errors except term exits |
|
1809 | - if( is_wp_error( $slug ) ){ |
|
1808 | + // send error for all errors except term exits |
|
1809 | + if( is_wp_error( $slug ) ){ |
|
1810 | 1810 | |
1811 | - // prepare for possible term name and id to be passed down if term exists |
|
1812 | - $term_data = array(); |
|
1811 | + // prepare for possible term name and id to be passed down if term exists |
|
1812 | + $term_data = array(); |
|
1813 | 1813 | |
1814 | - // if term exists also send back the term name and id |
|
1815 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
1814 | + // if term exists also send back the term name and id |
|
1815 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
1816 | 1816 | |
1817 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
1818 | - $term_data['name'] = $term_name; |
|
1819 | - $term_data['id'] = $term->term_id; |
|
1817 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
1818 | + $term_data['name'] = $term_name; |
|
1819 | + $term_data['id'] = $term->term_id; |
|
1820 | 1820 | |
1821 | - // set the object terms |
|
1822 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
1823 | - } |
|
1821 | + // set the object terms |
|
1822 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
1823 | + } |
|
1824 | 1824 | |
1825 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
1825 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
1826 | 1826 | |
1827 | - } |
|
1827 | + } |
|
1828 | 1828 | |
1829 | - //make sure the new term is checked for this course |
|
1829 | + //make sure the new term is checked for this course |
|
1830 | 1830 | |
1831 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
1831 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
1832 | 1832 | |
1833 | - // Handle request then generate response using WP_Ajax_Response |
|
1834 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
1833 | + // Handle request then generate response using WP_Ajax_Response |
|
1834 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
1835 | 1835 | |
1836 | - } |
|
1836 | + } |
|
1837 | 1837 | |
1838 | - /** |
|
1839 | - * Limit the course module metabox |
|
1840 | - * term list to only those on courses belonging to current teacher. |
|
1841 | - * |
|
1842 | - * Hooked into 'get_terms' |
|
1843 | - * |
|
1844 | - * @since 1.8.0 |
|
1845 | - */ |
|
1846 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
1838 | + /** |
|
1839 | + * Limit the course module metabox |
|
1840 | + * term list to only those on courses belonging to current teacher. |
|
1841 | + * |
|
1842 | + * Hooked into 'get_terms' |
|
1843 | + * |
|
1844 | + * @since 1.8.0 |
|
1845 | + */ |
|
1846 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
1847 | 1847 | |
1848 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1849 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
1850 | - return $terms; |
|
1851 | - } |
|
1848 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1849 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
1850 | + return $terms; |
|
1851 | + } |
|
1852 | 1852 | |
1853 | - // avoid infinite call loop |
|
1854 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1853 | + // avoid infinite call loop |
|
1854 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1855 | 1855 | |
1856 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1857 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
1858 | - // change only scrub the terms ids form the array keys |
|
1859 | - $terms = array_keys( $terms ); |
|
1860 | - } |
|
1856 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1857 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
1858 | + // change only scrub the terms ids form the array keys |
|
1859 | + $terms = array_keys( $terms ); |
|
1860 | + } |
|
1861 | 1861 | |
1862 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1862 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1863 | 1863 | |
1864 | - // add filter again as removed above |
|
1865 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1864 | + // add filter again as removed above |
|
1865 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
1866 | 1866 | |
1867 | - return $teachers_terms; |
|
1868 | - }// end filter_module_terms |
|
1867 | + return $teachers_terms; |
|
1868 | + }// end filter_module_terms |
|
1869 | 1869 | |
1870 | - /** |
|
1871 | - * For the selected items on a course module only return those |
|
1872 | - * for the current user. This does not apply to admin and super admin users. |
|
1873 | - * |
|
1874 | - * hooked into get_object_terms |
|
1875 | - * |
|
1876 | - * @since 1.8.0 |
|
1877 | - */ |
|
1878 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
1870 | + /** |
|
1871 | + * For the selected items on a course module only return those |
|
1872 | + * for the current user. This does not apply to admin and super admin users. |
|
1873 | + * |
|
1874 | + * hooked into get_object_terms |
|
1875 | + * |
|
1876 | + * @since 1.8.0 |
|
1877 | + */ |
|
1878 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
1879 | 1879 | |
1880 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1881 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
1882 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
1883 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
1884 | - return $terms; |
|
1885 | - } |
|
1880 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
1881 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
1882 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
1883 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
1884 | + return $terms; |
|
1885 | + } |
|
1886 | 1886 | |
1887 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1887 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
1888 | 1888 | |
1889 | - // if term objects were passed in send back objects |
|
1890 | - // if term id were passed in send that back |
|
1891 | - if( is_object( $terms[0] ) ){ |
|
1892 | - return $term_objects; |
|
1893 | - } |
|
1889 | + // if term objects were passed in send back objects |
|
1890 | + // if term id were passed in send that back |
|
1891 | + if( is_object( $terms[0] ) ){ |
|
1892 | + return $term_objects; |
|
1893 | + } |
|
1894 | 1894 | |
1895 | - $terms = array(); |
|
1896 | - foreach( $term_objects as $term_object ){ |
|
1897 | - $terms[] = $term_object->term_id; |
|
1898 | - } |
|
1895 | + $terms = array(); |
|
1896 | + foreach( $term_objects as $term_object ){ |
|
1897 | + $terms[] = $term_object->term_id; |
|
1898 | + } |
|
1899 | 1899 | |
1900 | - return $terms; |
|
1900 | + return $terms; |
|
1901 | 1901 | |
1902 | 1902 | |
1903 | - }// end filter_course_selected_terms |
|
1903 | + }// end filter_course_selected_terms |
|
1904 | 1904 | |
1905 | - /** |
|
1906 | - * Filter the given terms and only return the |
|
1907 | - * terms that belong to the given user id. |
|
1908 | - * |
|
1909 | - * @since 1.8.0 |
|
1910 | - * @param $terms |
|
1911 | - * @param $user_id |
|
1912 | - * @return array |
|
1913 | - */ |
|
1914 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
1905 | + /** |
|
1906 | + * Filter the given terms and only return the |
|
1907 | + * terms that belong to the given user id. |
|
1908 | + * |
|
1909 | + * @since 1.8.0 |
|
1910 | + * @param $terms |
|
1911 | + * @param $user_id |
|
1912 | + * @return array |
|
1913 | + */ |
|
1914 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
1915 | 1915 | |
1916 | - $users_terms = array(); |
|
1916 | + $users_terms = array(); |
|
1917 | 1917 | |
1918 | - foreach( $terms as $index => $term ){ |
|
1918 | + foreach( $terms as $index => $term ){ |
|
1919 | 1919 | |
1920 | - if( is_numeric( $term ) ){ |
|
1921 | - // the term id was given, get the term object |
|
1922 | - $term = get_term( $term, 'module' ); |
|
1923 | - } |
|
1920 | + if( is_numeric( $term ) ){ |
|
1921 | + // the term id was given, get the term object |
|
1922 | + $term = get_term( $term, 'module' ); |
|
1923 | + } |
|
1924 | 1924 | |
1925 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1925 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1926 | 1926 | |
1927 | - if ( $user_id == $author->ID ) { |
|
1928 | - // add the term to the teachers terms |
|
1929 | - $users_terms[] = $term; |
|
1930 | - } |
|
1927 | + if ( $user_id == $author->ID ) { |
|
1928 | + // add the term to the teachers terms |
|
1929 | + $users_terms[] = $term; |
|
1930 | + } |
|
1931 | 1931 | |
1932 | - } |
|
1932 | + } |
|
1933 | 1933 | |
1934 | - return $users_terms; |
|
1934 | + return $users_terms; |
|
1935 | 1935 | |
1936 | - } // end filter terms by owner |
|
1936 | + } // end filter terms by owner |
|
1937 | 1937 | |
1938 | - /** |
|
1939 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
1940 | - * This will not add name to terms belonging to admin user. |
|
1941 | - * |
|
1942 | - * Hooked into 'get_terms' |
|
1943 | - * |
|
1944 | - * @since 1.8.0 |
|
1945 | - */ |
|
1946 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
1947 | - { |
|
1938 | + /** |
|
1939 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
1940 | + * This will not add name to terms belonging to admin user. |
|
1941 | + * |
|
1942 | + * Hooked into 'get_terms' |
|
1943 | + * |
|
1944 | + * @since 1.8.0 |
|
1945 | + */ |
|
1946 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
1947 | + { |
|
1948 | 1948 | |
1949 | - // only for admin users ont he module taxonomy |
|
1950 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
1951 | - return $terms; |
|
1952 | - } |
|
1949 | + // only for admin users ont he module taxonomy |
|
1950 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
1951 | + return $terms; |
|
1952 | + } |
|
1953 | 1953 | |
1954 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1955 | - // simply return this as wp doesn't need an array of stdObject Term |
|
1956 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
1954 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
1955 | + // simply return this as wp doesn't need an array of stdObject Term |
|
1956 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
1957 | 1957 | |
1958 | - return $terms; |
|
1958 | + return $terms; |
|
1959 | 1959 | |
1960 | - } |
|
1960 | + } |
|
1961 | 1961 | |
1962 | - // loop through and update all terms adding the author name |
|
1963 | - foreach( $terms as $index => $term ){ |
|
1962 | + // loop through and update all terms adding the author name |
|
1963 | + foreach( $terms as $index => $term ){ |
|
1964 | 1964 | |
1965 | - if( is_numeric( $term ) ){ |
|
1966 | - // the term id was given, get the term object |
|
1967 | - $term = get_term( $term, 'module' ); |
|
1968 | - } |
|
1965 | + if( is_numeric( $term ) ){ |
|
1966 | + // the term id was given, get the term object |
|
1967 | + $term = get_term( $term, 'module' ); |
|
1968 | + } |
|
1969 | 1969 | |
1970 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1970 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
1971 | 1971 | |
1972 | - if( ! user_can( $author, 'manage_options' ) ) { |
|
1973 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
1974 | - } |
|
1972 | + if( ! user_can( $author, 'manage_options' ) ) { |
|
1973 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
1974 | + } |
|
1975 | 1975 | |
1976 | - // add the term to the teachers terms |
|
1977 | - $users_terms[] = $term; |
|
1976 | + // add the term to the teachers terms |
|
1977 | + $users_terms[] = $term; |
|
1978 | 1978 | |
1979 | - } |
|
1979 | + } |
|
1980 | 1980 | |
1981 | - return $users_terms; |
|
1982 | - } |
|
1981 | + return $users_terms; |
|
1982 | + } |
|
1983 | 1983 | |
1984 | - /** |
|
1985 | - * Remove modules metabox that come by default |
|
1986 | - * with the modules taxonomy. We are removing this as |
|
1987 | - * we have created our own custom meta box. |
|
1988 | - */ |
|
1989 | - public static function remove_default_modules_box() { |
|
1984 | + /** |
|
1985 | + * Remove modules metabox that come by default |
|
1986 | + * with the modules taxonomy. We are removing this as |
|
1987 | + * we have created our own custom meta box. |
|
1988 | + */ |
|
1989 | + public static function remove_default_modules_box() { |
|
1990 | 1990 | |
1991 | - remove_meta_box('modulediv', 'course', 'side'); |
|
1991 | + remove_meta_box('modulediv', 'course', 'side'); |
|
1992 | 1992 | |
1993 | - } |
|
1993 | + } |
|
1994 | 1994 | |
1995 | - /** |
|
1996 | - * When a course is save make sure to reset the transient set |
|
1997 | - * for it when determining the none module lessons. |
|
1998 | - * |
|
1999 | - * @sine 1.9.0 |
|
2000 | - * @param $post_id |
|
2001 | - */ |
|
2002 | - public static function reset_none_modules_transient ( $post_id ){ |
|
1995 | + /** |
|
1996 | + * When a course is save make sure to reset the transient set |
|
1997 | + * for it when determining the none module lessons. |
|
1998 | + * |
|
1999 | + * @sine 1.9.0 |
|
2000 | + * @param $post_id |
|
2001 | + */ |
|
2002 | + public static function reset_none_modules_transient ( $post_id ){ |
|
2003 | 2003 | |
2004 | - // this should only apply to course and lesson post types |
|
2005 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
2004 | + // this should only apply to course and lesson post types |
|
2005 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
2006 | 2006 | |
2007 | - $course_id = ''; |
|
2007 | + $course_id = ''; |
|
2008 | 2008 | |
2009 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
2009 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
2010 | 2010 | |
2011 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
2011 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
2012 | 2012 | |
2013 | - } |
|
2013 | + } |
|
2014 | 2014 | |
2015 | 2015 | |
2016 | - if( !empty( $course_id ) ){ |
|
2016 | + if( !empty( $course_id ) ){ |
|
2017 | 2017 | |
2018 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
2018 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
2019 | 2019 | |
2020 | - } |
|
2020 | + } |
|
2021 | 2021 | |
2022 | - } // end if is a course or a lesson |
|
2022 | + } // end if is a course or a lesson |
|
2023 | 2023 | |
2024 | - } // end reset_none_modules_transient |
|
2024 | + } // end reset_none_modules_transient |
|
2025 | 2025 | |
2026 | - /** |
|
2027 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
2028 | - * |
|
2029 | - * @since 1.9.0 |
|
2030 | - * @deprecated since 1.9.0 |
|
2031 | - * |
|
2032 | - */ |
|
2033 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
2026 | + /** |
|
2027 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
2028 | + * |
|
2029 | + * @since 1.9.0 |
|
2030 | + * @deprecated since 1.9.0 |
|
2031 | + * |
|
2032 | + */ |
|
2033 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
2034 | 2034 | |
2035 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
2035 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
2036 | 2036 | |
2037 | - } |
|
2037 | + } |
|
2038 | 2038 | |
2039 | - /** |
|
2040 | - * Setup the single course module loop. |
|
2041 | - * |
|
2042 | - * Setup the global $sensei_modules_loop |
|
2043 | - * |
|
2044 | - * @since 1.9.0 |
|
2045 | - */ |
|
2046 | - public static function setup_single_course_module_loop(){ |
|
2039 | + /** |
|
2040 | + * Setup the single course module loop. |
|
2041 | + * |
|
2042 | + * Setup the global $sensei_modules_loop |
|
2043 | + * |
|
2044 | + * @since 1.9.0 |
|
2045 | + */ |
|
2046 | + public static function setup_single_course_module_loop(){ |
|
2047 | 2047 | |
2048 | - global $sensei_modules_loop, $post; |
|
2049 | - $course_id = $post->ID; |
|
2048 | + global $sensei_modules_loop, $post; |
|
2049 | + $course_id = $post->ID; |
|
2050 | 2050 | |
2051 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
2051 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
2052 | 2052 | |
2053 | - //initial setup |
|
2054 | - $sensei_modules_loop['total'] = 0; |
|
2055 | - $sensei_modules_loop['modules'] = array(); |
|
2056 | - $sensei_modules_loop['current'] = -1; |
|
2053 | + //initial setup |
|
2054 | + $sensei_modules_loop['total'] = 0; |
|
2055 | + $sensei_modules_loop['modules'] = array(); |
|
2056 | + $sensei_modules_loop['current'] = -1; |
|
2057 | 2057 | |
2058 | - // exit if this course doesn't have modules |
|
2059 | - if( !$modules || empty( $modules ) ){ |
|
2060 | - return; |
|
2061 | - } |
|
2058 | + // exit if this course doesn't have modules |
|
2059 | + if( !$modules || empty( $modules ) ){ |
|
2060 | + return; |
|
2061 | + } |
|
2062 | 2062 | |
2063 | 2063 | |
2064 | - $lessons_in_all_modules = array(); |
|
2065 | - foreach( $modules as $term ){ |
|
2064 | + $lessons_in_all_modules = array(); |
|
2065 | + foreach( $modules as $term ){ |
|
2066 | 2066 | |
2067 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
2068 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
2067 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
2068 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
2069 | 2069 | |
2070 | - } |
|
2070 | + } |
|
2071 | 2071 | |
2072 | 2072 | |
2073 | - //setup all of the modules loop variables |
|
2074 | - $sensei_modules_loop['total'] = count( $modules ); |
|
2075 | - $sensei_modules_loop['modules'] = $modules; |
|
2076 | - $sensei_modules_loop['current'] = -1; |
|
2077 | - $sensei_modules_loop['course_id'] = $course_id; |
|
2073 | + //setup all of the modules loop variables |
|
2074 | + $sensei_modules_loop['total'] = count( $modules ); |
|
2075 | + $sensei_modules_loop['modules'] = $modules; |
|
2076 | + $sensei_modules_loop['current'] = -1; |
|
2077 | + $sensei_modules_loop['course_id'] = $course_id; |
|
2078 | 2078 | |
2079 | - }// end setup_single_course_module_loop |
|
2079 | + }// end setup_single_course_module_loop |
|
2080 | 2080 | |
2081 | - /** |
|
2082 | - * Tear down the course module loop. |
|
2083 | - * |
|
2084 | - * @since 1.9.0 |
|
2085 | - * |
|
2086 | - */ |
|
2087 | - public static function teardown_single_course_module_loop(){ |
|
2081 | + /** |
|
2082 | + * Tear down the course module loop. |
|
2083 | + * |
|
2084 | + * @since 1.9.0 |
|
2085 | + * |
|
2086 | + */ |
|
2087 | + public static function teardown_single_course_module_loop(){ |
|
2088 | 2088 | |
2089 | - global $sensei_modules_loop, $wp_query, $post; |
|
2089 | + global $sensei_modules_loop, $wp_query, $post; |
|
2090 | 2090 | |
2091 | - //reset all of the modules loop variables |
|
2092 | - $sensei_modules_loop['total'] = 0; |
|
2093 | - $sensei_modules_loop['modules'] = array(); |
|
2094 | - $sensei_modules_loop['current'] = -1; |
|
2091 | + //reset all of the modules loop variables |
|
2092 | + $sensei_modules_loop['total'] = 0; |
|
2093 | + $sensei_modules_loop['modules'] = array(); |
|
2094 | + $sensei_modules_loop['current'] = -1; |
|
2095 | 2095 | |
2096 | - // set the current course to be the global post again |
|
2097 | - wp_reset_query(); |
|
2098 | - $post = $wp_query->post; |
|
2099 | - }// end teardown_single_course_module_loop |
|
2096 | + // set the current course to be the global post again |
|
2097 | + wp_reset_query(); |
|
2098 | + $post = $wp_query->post; |
|
2099 | + }// end teardown_single_course_module_loop |
|
2100 | 2100 | |
2101 | 2101 | } // end modules class |
@@ -21,6 +21,9 @@ discard block |
||
21 | 21 | private $order_page_slug; |
22 | 22 | public $taxonomy; |
23 | 23 | |
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
24 | 27 | public function __construct( $file ) |
25 | 28 | { |
26 | 29 | $this->file = $file; |
@@ -1942,6 +1945,7 @@ discard block |
||
1942 | 1945 | * Hooked into 'get_terms' |
1943 | 1946 | * |
1944 | 1947 | * @since 1.8.0 |
1948 | + * @param string[] $taxonomies |
|
1945 | 1949 | */ |
1946 | 1950 | public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
1947 | 1951 | { |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Analysis Overview List Table Class |
@@ -306,8 +309,7 @@ discard block |
||
306 | 309 | // Output course data |
307 | 310 | if ( $this->csv_output ) { |
308 | 311 | $course_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
309 | - } |
|
310 | - else { |
|
312 | + } else { |
|
311 | 313 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) ); |
312 | 314 | |
313 | 315 | $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
@@ -363,16 +365,14 @@ discard block |
||
363 | 365 | // Output lesson data |
364 | 366 | if ( $this->csv_output ) { |
365 | 367 | $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
366 | - } |
|
367 | - else { |
|
368 | + } else { |
|
368 | 369 | $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
369 | 370 | $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
370 | 371 | |
371 | 372 | if ( $course_id ) { |
372 | 373 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
373 | 374 | $course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>'; |
374 | - } |
|
375 | - else { |
|
375 | + } else { |
|
376 | 376 | $course_title = __('n/a', 'woothemes-sensei'); |
377 | 377 | } |
378 | 378 | if ( is_numeric( $lesson_average_grade ) ) { |
@@ -423,8 +423,7 @@ discard block |
||
423 | 423 | // Output the users data |
424 | 424 | if ( $this->csv_output ) { |
425 | 425 | $user_name = Sensei()->learners->get_learner_full_name( $item->ID ); |
426 | - } |
|
427 | - else { |
|
426 | + } else { |
|
428 | 427 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
429 | 428 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
430 | 429 | $user_average_grade .= '%'; |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | 'order' => $order, |
163 | 163 | ); |
164 | 164 | |
165 | - // Handle search |
|
166 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
167 | - $args['search'] = esc_html( $_GET['s'] ); |
|
168 | - } |
|
165 | + // Handle search |
|
166 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
167 | + $args['search'] = esc_html( $_GET['s'] ); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | switch ( $this->type ) { |
171 | 171 | case 'courses': |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | ); |
223 | 223 | |
224 | 224 | |
225 | - // Handle search |
|
226 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
227 | - $args['search'] = esc_html( $_GET['s'] ); |
|
228 | - } |
|
225 | + // Handle search |
|
226 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
227 | + $args['search'] = esc_html( $_GET['s'] ); |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 | // Start the csv with the column headings |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * Generates the overall array for a single item in the display |
264 | 264 | * @since 1.7.0 |
265 | 265 | * @param object $item The current item |
266 | - * @return array $column_data; |
|
266 | + * @return array $column_data; |
|
267 | 267 | */ |
268 | 268 | protected function get_row_data( $item ) { |
269 | 269 | |
@@ -422,8 +422,8 @@ discard block |
||
422 | 422 | |
423 | 423 | // Output the users data |
424 | 424 | if ( $this->csv_output ) { |
425 | - $user_name = Sensei_Student::get_full_name( $item->ID ); |
|
426 | - } |
|
425 | + $user_name = Sensei_Student::get_full_name( $item->ID ); |
|
426 | + } |
|
427 | 427 | else { |
428 | 428 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
429 | 429 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
@@ -517,17 +517,17 @@ discard block |
||
517 | 517 | // This stops the full meta data of each user being loaded |
518 | 518 | $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
519 | 519 | |
520 | - /** |
|
521 | - * Filter the WP_User_Query arguments |
|
522 | - * @since 1.6.0 |
|
523 | - * @param $args |
|
524 | - */ |
|
525 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
520 | + /** |
|
521 | + * Filter the WP_User_Query arguments |
|
522 | + * @since 1.6.0 |
|
523 | + * @param $args |
|
524 | + */ |
|
525 | + $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
526 | 526 | $wp_user_search = new WP_User_Query( $args ); |
527 | - $learners = $wp_user_search->get_results(); |
|
527 | + $learners = $wp_user_search->get_results(); |
|
528 | 528 | $this->total_items = $wp_user_search->get_total(); |
529 | 529 | |
530 | - return $learners; |
|
530 | + return $learners; |
|
531 | 531 | |
532 | 532 | } // End get_learners() |
533 | 533 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Analysis Overview List Table Class |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | * @since 1.2.0 |
22 | 22 | * @return void |
23 | 23 | */ |
24 | - public function __construct ( $type = 'users' ) { |
|
25 | - $this->type = in_array( $type, array( 'courses', 'lessons', 'users' ) ) ? $type : 'users'; |
|
24 | + public function __construct($type = 'users') { |
|
25 | + $this->type = in_array($type, array('courses', 'lessons', 'users')) ? $type : 'users'; |
|
26 | 26 | |
27 | 27 | // Load Parent token into constructor |
28 | - parent::__construct( 'analysis_overview' ); |
|
28 | + parent::__construct('analysis_overview'); |
|
29 | 29 | |
30 | 30 | // Actions |
31 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
32 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
31 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
32 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
33 | 33 | |
34 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
34 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
35 | 35 | } // End __construct() |
36 | 36 | |
37 | 37 | /** |
@@ -41,41 +41,41 @@ discard block |
||
41 | 41 | */ |
42 | 42 | function get_columns() { |
43 | 43 | |
44 | - switch( $this->type ) { |
|
44 | + switch ($this->type) { |
|
45 | 45 | case 'courses': |
46 | 46 | $columns = array( |
47 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
48 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
49 | - 'lessons' => __( 'Lessons', 'woothemes-sensei' ), |
|
50 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
51 | - 'average_percent' => __( 'Average Percentage', 'woothemes-sensei' ), |
|
47 | + 'title' => __('Course', 'woothemes-sensei'), |
|
48 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
49 | + 'lessons' => __('Lessons', 'woothemes-sensei'), |
|
50 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
51 | + 'average_percent' => __('Average Percentage', 'woothemes-sensei'), |
|
52 | 52 | ); |
53 | 53 | break; |
54 | 54 | |
55 | 55 | case 'lessons': |
56 | 56 | $columns = array( |
57 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
58 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
59 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
60 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
61 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
57 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
58 | + 'course' => __('Course', 'woothemes-sensei'), |
|
59 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
60 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
61 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
62 | 62 | ); |
63 | 63 | break; |
64 | 64 | |
65 | 65 | case 'users': |
66 | 66 | default: |
67 | 67 | $columns = array( |
68 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
69 | - 'registered' => __( 'Date Registered', 'woothemes-sensei' ), |
|
70 | - 'active_courses' => __( 'Active Courses', 'woothemes-sensei' ), |
|
71 | - 'completed_courses' => __( 'Completed Courses', 'woothemes-sensei' ), |
|
72 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
68 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
69 | + 'registered' => __('Date Registered', 'woothemes-sensei'), |
|
70 | + 'active_courses' => __('Active Courses', 'woothemes-sensei'), |
|
71 | + 'completed_courses' => __('Completed Courses', 'woothemes-sensei'), |
|
72 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
73 | 73 | ); |
74 | 74 | break; |
75 | 75 | } |
76 | 76 | // Backwards compatible filter name, moving forward should have single filter name |
77 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns', $columns, $this ); |
|
78 | - $columns = apply_filters( 'sensei_analysis_overview_columns', $columns, $this ); |
|
77 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns', $columns, $this); |
|
78 | + $columns = apply_filters('sensei_analysis_overview_columns', $columns, $this); |
|
79 | 79 | return $columns; |
80 | 80 | } |
81 | 81 | |
@@ -86,41 +86,41 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function get_sortable_columns() { |
88 | 88 | |
89 | - switch( $this->type ) { |
|
89 | + switch ($this->type) { |
|
90 | 90 | case 'courses': |
91 | 91 | $columns = array( |
92 | - 'title' => array( 'title', false ), |
|
93 | - 'students' => array( 'students', false ), |
|
94 | - 'lessons' => array( 'lessons', false ), |
|
95 | - 'completions' => array( 'completions', false ), |
|
96 | - 'average_percent' => array( 'average_percent', false ), |
|
92 | + 'title' => array('title', false), |
|
93 | + 'students' => array('students', false), |
|
94 | + 'lessons' => array('lessons', false), |
|
95 | + 'completions' => array('completions', false), |
|
96 | + 'average_percent' => array('average_percent', false), |
|
97 | 97 | ); |
98 | 98 | break; |
99 | 99 | |
100 | 100 | case 'lessons': |
101 | 101 | $columns = array( |
102 | - 'title' => array( 'title', false ), |
|
103 | - 'course' => array( 'course', false ), |
|
104 | - 'students' => array( 'students', false ), |
|
105 | - 'completions' => array( 'completions', false ), |
|
106 | - 'average_grade' => array( 'average_grade', false ), |
|
102 | + 'title' => array('title', false), |
|
103 | + 'course' => array('course', false), |
|
104 | + 'students' => array('students', false), |
|
105 | + 'completions' => array('completions', false), |
|
106 | + 'average_grade' => array('average_grade', false), |
|
107 | 107 | ); |
108 | 108 | break; |
109 | 109 | |
110 | 110 | case 'users': |
111 | 111 | default: |
112 | 112 | $columns = array( |
113 | - 'title' => array( 'user_login', false ), |
|
114 | - 'registered' => array( 'registered', false ), |
|
115 | - 'active_courses' => array( 'active_courses', false ), |
|
116 | - 'completed_courses' => array( 'completed_courses', false ), |
|
117 | - 'average_grade' => array( 'average_grade', false ) |
|
113 | + 'title' => array('user_login', false), |
|
114 | + 'registered' => array('registered', false), |
|
115 | + 'active_courses' => array('active_courses', false), |
|
116 | + 'completed_courses' => array('completed_courses', false), |
|
117 | + 'average_grade' => array('average_grade', false) |
|
118 | 118 | ); |
119 | 119 | break; |
120 | 120 | } |
121 | 121 | // Backwards compatible filter name, moving forward should have single filter name |
122 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns_sortable', $columns, $this ); |
|
123 | - $columns = apply_filters( 'sensei_analysis_overview_columns_sortable', $columns, $this ); |
|
122 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns_sortable', $columns, $this); |
|
123 | + $columns = apply_filters('sensei_analysis_overview_columns_sortable', $columns, $this); |
|
124 | 124 | return $columns; |
125 | 125 | } |
126 | 126 | |
@@ -134,25 +134,25 @@ discard block |
||
134 | 134 | |
135 | 135 | // Handle orderby |
136 | 136 | $orderby = ''; |
137 | - if ( !empty( $_GET['orderby'] ) ) { |
|
138 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
139 | - $orderby = esc_html( $_GET['orderby'] ); |
|
137 | + if ( ! empty($_GET['orderby'])) { |
|
138 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
139 | + $orderby = esc_html($_GET['orderby']); |
|
140 | 140 | } // End If Statement |
141 | 141 | } |
142 | 142 | |
143 | 143 | // Handle order |
144 | 144 | $order = 'ASC'; |
145 | - if ( !empty( $_GET['order'] ) ) { |
|
146 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
145 | + if ( ! empty($_GET['order'])) { |
|
146 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
147 | 147 | } |
148 | 148 | |
149 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
150 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
149 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
150 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
151 | 151 | |
152 | 152 | $paged = $this->get_pagenum(); |
153 | 153 | $offset = 0; |
154 | - if ( !empty($paged) ) { |
|
155 | - $offset = $per_page * ( $paged - 1 ); |
|
154 | + if ( ! empty($paged)) { |
|
155 | + $offset = $per_page * ($paged - 1); |
|
156 | 156 | } // End If Statement |
157 | 157 | |
158 | 158 | $args = array( |
@@ -163,32 +163,32 @@ discard block |
||
163 | 163 | ); |
164 | 164 | |
165 | 165 | // Handle search |
166 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
167 | - $args['search'] = esc_html( $_GET['s'] ); |
|
166 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
167 | + $args['search'] = esc_html($_GET['s']); |
|
168 | 168 | } |
169 | 169 | |
170 | - switch ( $this->type ) { |
|
170 | + switch ($this->type) { |
|
171 | 171 | case 'courses': |
172 | - $this->items = $this->get_courses( $args ); |
|
172 | + $this->items = $this->get_courses($args); |
|
173 | 173 | break; |
174 | 174 | |
175 | 175 | case 'lessons': |
176 | - $this->items = $this->get_lessons( $args ); |
|
176 | + $this->items = $this->get_lessons($args); |
|
177 | 177 | break; |
178 | 178 | |
179 | 179 | case 'users': |
180 | 180 | default : |
181 | - $this->items = $this->get_learners( $args ); |
|
181 | + $this->items = $this->get_learners($args); |
|
182 | 182 | break; |
183 | 183 | } |
184 | 184 | |
185 | 185 | $total_items = $this->total_items; |
186 | - $total_pages = ceil( $total_items / $per_page ); |
|
187 | - $this->set_pagination_args( array( |
|
186 | + $total_pages = ceil($total_items / $per_page); |
|
187 | + $this->set_pagination_args(array( |
|
188 | 188 | 'total_items' => $total_items, |
189 | 189 | 'total_pages' => $total_pages, |
190 | 190 | 'per_page' => $per_page |
191 | - ) ); |
|
191 | + )); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @since 1.7.0 |
197 | 197 | * @return data |
198 | 198 | */ |
199 | - public function generate_report( $report ) { |
|
199 | + public function generate_report($report) { |
|
200 | 200 | |
201 | 201 | $data = array(); |
202 | 202 | |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | |
205 | 205 | // Handle orderby |
206 | 206 | $orderby = ''; |
207 | - if ( !empty( $_GET['orderby'] ) ) { |
|
208 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
209 | - $orderby = esc_html( $_GET['orderby'] ); |
|
207 | + if ( ! empty($_GET['orderby'])) { |
|
208 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
209 | + $orderby = esc_html($_GET['orderby']); |
|
210 | 210 | } // End If Statement |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Handle order |
214 | 214 | $order = 'ASC'; |
215 | - if ( !empty( $_GET['order'] ) ) { |
|
216 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
215 | + if ( ! empty($_GET['order'])) { |
|
216 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | $args = array( |
@@ -223,37 +223,37 @@ discard block |
||
223 | 223 | |
224 | 224 | |
225 | 225 | // Handle search |
226 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
227 | - $args['search'] = esc_html( $_GET['s'] ); |
|
226 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
227 | + $args['search'] = esc_html($_GET['s']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | |
231 | 231 | // Start the csv with the column headings |
232 | 232 | $column_headers = array(); |
233 | 233 | $columns = $this->get_columns(); |
234 | - foreach( $columns AS $key => $title ) { |
|
234 | + foreach ($columns AS $key => $title) { |
|
235 | 235 | $column_headers[] = $title; |
236 | 236 | } |
237 | 237 | $data[] = $column_headers; |
238 | 238 | |
239 | - switch ( $this->type ) { |
|
239 | + switch ($this->type) { |
|
240 | 240 | case 'courses': |
241 | - $this->items = $this->get_courses( $args ); |
|
241 | + $this->items = $this->get_courses($args); |
|
242 | 242 | break; |
243 | 243 | |
244 | 244 | case 'lessons': |
245 | - $this->items = $this->get_lessons( $args ); |
|
245 | + $this->items = $this->get_lessons($args); |
|
246 | 246 | break; |
247 | 247 | |
248 | 248 | case 'users': |
249 | 249 | default : |
250 | - $this->items = $this->get_learners( $args ); |
|
250 | + $this->items = $this->get_learners($args); |
|
251 | 251 | break; |
252 | 252 | } |
253 | 253 | |
254 | 254 | // Process each row |
255 | - foreach( $this->items AS $item) { |
|
256 | - $data[] = $this->get_row_data( $item ); |
|
255 | + foreach ($this->items AS $item) { |
|
256 | + $data[] = $this->get_row_data($item); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return $data; |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | * @param object $item The current item |
266 | 266 | * @return array $column_data; |
267 | 267 | */ |
268 | - protected function get_row_data( $item ) { |
|
268 | + protected function get_row_data($item) { |
|
269 | 269 | |
270 | - switch( $this->type ) { |
|
270 | + switch ($this->type) { |
|
271 | 271 | case 'courses' : |
272 | 272 | // Get Learners (i.e. those who have started) |
273 | 273 | $course_args = array( |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | 'type' => 'sensei_course_status', |
276 | 276 | 'status' => 'any', |
277 | 277 | ); |
278 | - $course_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_learners', $course_args, $item ) ); |
|
278 | + $course_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_learners', $course_args, $item)); |
|
279 | 279 | |
280 | 280 | // Get Course Completions |
281 | 281 | $course_args = array( |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | 'type' => 'sensei_course_status', |
284 | 284 | 'status' => 'complete', |
285 | 285 | ); |
286 | - $course_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_completions', $course_args, $item ) ); |
|
286 | + $course_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_completions', $course_args, $item)); |
|
287 | 287 | |
288 | 288 | // Course Lessons |
289 | - $course_lessons = Sensei()->lesson->lesson_count( array('publish', 'private'), $item->ID ); |
|
289 | + $course_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'), $item->ID); |
|
290 | 290 | |
291 | 291 | // Get Percent Complete |
292 | 292 | $grade_args = array( |
@@ -295,30 +295,30 @@ discard block |
||
295 | 295 | 'status' => 'any', |
296 | 296 | 'meta_key' => 'percent', |
297 | 297 | ); |
298 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
299 | - $course_percentage = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ); |
|
300 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
298 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
299 | + $course_percentage = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true); |
|
300 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
301 | 301 | |
302 | - $percent_count = !empty( $course_percentage->total ) ? $course_percentage->total : 1; |
|
303 | - $percent_total = !empty( $course_percentage->meta_sum ) ? doubleval( $course_percentage->meta_sum ) : 0; |
|
304 | - $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) ); |
|
302 | + $percent_count = ! empty($course_percentage->total) ? $course_percentage->total : 1; |
|
303 | + $percent_total = ! empty($course_percentage->meta_sum) ? doubleval($course_percentage->meta_sum) : 0; |
|
304 | + $course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2)); |
|
305 | 305 | |
306 | 306 | // Output course data |
307 | - if ( $this->csv_output ) { |
|
308 | - $course_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
307 | + if ($this->csv_output) { |
|
308 | + $course_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
309 | 309 | } |
310 | 310 | else { |
311 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
311 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php')); |
|
312 | 312 | |
313 | - $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
313 | + $course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
314 | 314 | $course_average_percent .= '%'; |
315 | 315 | } // End If Statement |
316 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $course_title, |
|
316 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title, |
|
317 | 317 | 'students' => $course_students, |
318 | 318 | 'lessons' => $course_lessons, |
319 | 319 | 'completions' => $course_completions, |
320 | 320 | 'average_percent' => $course_average_percent, |
321 | - ), $item, $this ); |
|
321 | + ), $item, $this); |
|
322 | 322 | break; |
323 | 323 | |
324 | 324 | case 'lessons' : |
@@ -328,63 +328,63 @@ discard block |
||
328 | 328 | 'type' => 'sensei_lesson_status', |
329 | 329 | 'status' => 'any', |
330 | 330 | ); |
331 | - $lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) ); |
|
331 | + $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item)); |
|
332 | 332 | |
333 | 333 | // Get Course Completions |
334 | 334 | $lesson_args = array( |
335 | 335 | 'post_id' => $item->ID, |
336 | 336 | 'type' => 'sensei_lesson_status', |
337 | - 'status' => array( 'complete', 'graded', 'passed', 'failed' ), |
|
337 | + 'status' => array('complete', 'graded', 'passed', 'failed'), |
|
338 | 338 | 'count' => true, |
339 | 339 | ); |
340 | - $lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) ); |
|
340 | + $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item)); |
|
341 | 341 | |
342 | 342 | // Course |
343 | - $course_id = get_post_meta( $item->ID, '_lesson_course', true ); |
|
344 | - $course_title = $course_id ? get_the_title( $course_id ) : ''; |
|
343 | + $course_id = get_post_meta($item->ID, '_lesson_course', true); |
|
344 | + $course_title = $course_id ? get_the_title($course_id) : ''; |
|
345 | 345 | |
346 | 346 | $lesson_average_grade = __('n/a', 'woothemes-sensei'); |
347 | - if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) { |
|
347 | + if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
348 | 348 | // Get Percent Complete |
349 | 349 | $grade_args = array( |
350 | 350 | 'post_id' => $item->ID, |
351 | 351 | 'type' => 'sensei_lesson_status', |
352 | - 'status' => array( 'graded', 'passed', 'failed' ), |
|
352 | + 'status' => array('graded', 'passed', 'failed'), |
|
353 | 353 | 'meta_key' => 'grade', |
354 | 354 | ); |
355 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
356 | - $lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ); |
|
357 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
355 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
356 | + $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true); |
|
357 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
358 | 358 | |
359 | - $grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1; |
|
360 | - $grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0; |
|
361 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
359 | + $grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1; |
|
360 | + $grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0; |
|
361 | + $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
362 | 362 | } |
363 | 363 | // Output lesson data |
364 | - if ( $this->csv_output ) { |
|
365 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
364 | + if ($this->csv_output) { |
|
365 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
366 | 366 | } |
367 | 367 | else { |
368 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
369 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
368 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
369 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
370 | 370 | |
371 | - if ( $course_id ) { |
|
372 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
373 | - $course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>'; |
|
371 | + if ($course_id) { |
|
372 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
373 | + $course_title = '<a href="'.esc_url($url).'">'.$course_title.'</a>'; |
|
374 | 374 | } |
375 | 375 | else { |
376 | 376 | $course_title = __('n/a', 'woothemes-sensei'); |
377 | 377 | } |
378 | - if ( is_numeric( $lesson_average_grade ) ) { |
|
378 | + if (is_numeric($lesson_average_grade)) { |
|
379 | 379 | $lesson_average_grade .= '%'; |
380 | 380 | } |
381 | 381 | } // End If Statement |
382 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $lesson_title, |
|
382 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title, |
|
383 | 383 | 'course' => $course_title, |
384 | 384 | 'students' => $lesson_students, |
385 | 385 | 'completions' => $lesson_completions, |
386 | 386 | 'average_grade' => $lesson_average_grade, |
387 | - ), $item, $this ); |
|
387 | + ), $item, $this); |
|
388 | 388 | break; |
389 | 389 | |
390 | 390 | case 'users' : |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | 'type' => 'sensei_course_status', |
396 | 396 | 'status' => 'any', |
397 | 397 | ); |
398 | - $user_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_started', $course_args, $item ) ); |
|
398 | + $user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item)); |
|
399 | 399 | |
400 | 400 | // Get Completed Courses |
401 | 401 | $course_args = array( |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | 'type' => 'sensei_course_status', |
404 | 404 | 'status' => 'complete', |
405 | 405 | ); |
406 | - $user_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_ended', $course_args, $item ) ); |
|
406 | + $user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item)); |
|
407 | 407 | |
408 | 408 | // Get Quiz Grades |
409 | 409 | $grade_args = array( |
@@ -412,29 +412,29 @@ discard block |
||
412 | 412 | 'status' => 'any', |
413 | 413 | 'meta_key' => 'grade', |
414 | 414 | ); |
415 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
416 | - $user_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ); |
|
417 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
415 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
416 | + $user_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true); |
|
417 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
418 | 418 | |
419 | - $grade_count = !empty( $user_quiz_grades->total ) ? $user_quiz_grades->total : 1; |
|
420 | - $grade_total = !empty( $user_quiz_grades->meta_sum ) ? doubleval( $user_quiz_grades->meta_sum ) : 0; |
|
421 | - $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
419 | + $grade_count = ! empty($user_quiz_grades->total) ? $user_quiz_grades->total : 1; |
|
420 | + $grade_total = ! empty($user_quiz_grades->meta_sum) ? doubleval($user_quiz_grades->meta_sum) : 0; |
|
421 | + $user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
422 | 422 | |
423 | 423 | // Output the users data |
424 | - if ( $this->csv_output ) { |
|
425 | - $user_name = Sensei_Student::get_full_name( $item->ID ); |
|
424 | + if ($this->csv_output) { |
|
425 | + $user_name = Sensei_Student::get_full_name($item->ID); |
|
426 | 426 | } |
427 | 427 | else { |
428 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
429 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
|
428 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php')); |
|
429 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$item->display_name.'</a></strong>'; |
|
430 | 430 | $user_average_grade .= '%'; |
431 | 431 | } // End If Statement |
432 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $user_name, |
|
432 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name, |
|
433 | 433 | 'registered' => $item->user_registered, |
434 | - 'active_courses' => ( $user_courses_started - $user_courses_ended ), |
|
434 | + 'active_courses' => ($user_courses_started - $user_courses_ended), |
|
435 | 435 | 'completed_courses' => $user_courses_ended, |
436 | 436 | 'average_grade' => $user_average_grade, |
437 | - ), $item, $this ); |
|
437 | + ), $item, $this); |
|
438 | 438 | break; |
439 | 439 | } // end switch |
440 | 440 | return $column_data; |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @since 1.7.0 |
446 | 446 | * @return array courses |
447 | 447 | */ |
448 | - private function get_courses( $args ) { |
|
448 | + private function get_courses($args) { |
|
449 | 449 | $course_args = array( |
450 | 450 | 'post_type' => 'course', |
451 | 451 | 'post_status' => array('publish', 'private'), |
@@ -456,16 +456,16 @@ discard block |
||
456 | 456 | 'suppress_filters' => 0, |
457 | 457 | ); |
458 | 458 | |
459 | - if ( $this->csv_output ) { |
|
459 | + if ($this->csv_output) { |
|
460 | 460 | $course_args['posts_per_page'] = '-1'; |
461 | 461 | } |
462 | 462 | |
463 | - if( isset( $args['search'] ) ) { |
|
463 | + if (isset($args['search'])) { |
|
464 | 464 | $course_args['s'] = $args['search']; |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
468 | - $courses_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_courses', $course_args ) ); |
|
468 | + $courses_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_courses', $course_args)); |
|
469 | 469 | $this->total_items = $courses_query->found_posts; |
470 | 470 | return $courses_query->posts; |
471 | 471 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @since 1.7.0 |
477 | 477 | * @return array lessons |
478 | 478 | */ |
479 | - private function get_lessons( $args ) { |
|
479 | + private function get_lessons($args) { |
|
480 | 480 | $lessons_args = array( |
481 | 481 | 'post_type' => 'lesson', |
482 | 482 | 'post_status' => array('publish', 'private'), |
@@ -487,16 +487,16 @@ discard block |
||
487 | 487 | 'suppress_filters' => 0, |
488 | 488 | ); |
489 | 489 | |
490 | - if ( $this->csv_output ) { |
|
490 | + if ($this->csv_output) { |
|
491 | 491 | $lessons_args['posts_per_page'] = '-1'; |
492 | 492 | } |
493 | 493 | |
494 | - if( isset( $args['search'] ) ) { |
|
494 | + if (isset($args['search'])) { |
|
495 | 495 | $lessons_args['s'] = $args['search']; |
496 | 496 | } |
497 | 497 | |
498 | 498 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
499 | - $lessons_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_lessons', $lessons_args ) ); |
|
499 | + $lessons_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_lessons', $lessons_args)); |
|
500 | 500 | $this->total_items = $lessons_query->found_posts; |
501 | 501 | return $lessons_query->posts; |
502 | 502 | } // End get_lessons() |
@@ -506,24 +506,24 @@ discard block |
||
506 | 506 | * @since 1.7.0 |
507 | 507 | * @return array learners |
508 | 508 | */ |
509 | - private function get_learners( $args ) { |
|
509 | + private function get_learners($args) { |
|
510 | 510 | |
511 | - if ( !empty($args['search']) ) { |
|
511 | + if ( ! empty($args['search'])) { |
|
512 | 512 | $args = array( |
513 | - 'search' => '*' . trim( $args['search'], '*' ) . '*', |
|
513 | + 'search' => '*'.trim($args['search'], '*').'*', |
|
514 | 514 | ); |
515 | 515 | } |
516 | 516 | |
517 | 517 | // This stops the full meta data of each user being loaded |
518 | - $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
|
518 | + $args['fields'] = array('ID', 'user_login', 'user_email', 'user_registered', 'display_name'); |
|
519 | 519 | |
520 | 520 | /** |
521 | 521 | * Filter the WP_User_Query arguments |
522 | 522 | * @since 1.6.0 |
523 | 523 | * @param $args |
524 | 524 | */ |
525 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
526 | - $wp_user_search = new WP_User_Query( $args ); |
|
525 | + $args = apply_filters('sensei_analysis_overview_filter_users', $args); |
|
526 | + $wp_user_search = new WP_User_Query($args); |
|
527 | 527 | $learners = $wp_user_search->get_results(); |
528 | 528 | $this->total_items = $wp_user_search->get_total(); |
529 | 529 | |
@@ -536,13 +536,13 @@ discard block |
||
536 | 536 | * @since 1.2.0 |
537 | 537 | * @return array $stats_to_render of stats boxes and values |
538 | 538 | */ |
539 | - public function stats_boxes () { |
|
539 | + public function stats_boxes() { |
|
540 | 540 | |
541 | 541 | // Get the data required |
542 | 542 | $user_count = count_users(); |
543 | - $user_count = apply_filters( 'sensei_analysis_total_users', $user_count['total_users'], $user_count ); |
|
544 | - $total_courses = Sensei()->course->course_count( array('publish', 'private') ); |
|
545 | - $total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') ); |
|
543 | + $user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count); |
|
544 | + $total_courses = Sensei()->course->course_count(array('publish', 'private')); |
|
545 | + $total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private')); |
|
546 | 546 | |
547 | 547 | $grade_args = array( |
548 | 548 | 'type' => 'sensei_lesson_status', |
@@ -550,36 +550,36 @@ discard block |
||
550 | 550 | 'meta_key' => 'grade', |
551 | 551 | ); |
552 | 552 | |
553 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
554 | - $total_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_quiz_grades', $grade_args ), true ); |
|
555 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
553 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
554 | + $total_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_quiz_grades', $grade_args), true); |
|
555 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
556 | 556 | |
557 | - $total_grade_count = !empty( $total_quiz_grades->total ) ? $total_quiz_grades->total : 1; |
|
558 | - $total_grade_total = !empty( $total_quiz_grades->meta_sum ) ? doubleval( $total_quiz_grades->meta_sum ) : 0; |
|
559 | - $total_average_grade = abs( round( doubleval( $total_grade_total / $total_grade_count ), 2 ) ); |
|
557 | + $total_grade_count = ! empty($total_quiz_grades->total) ? $total_quiz_grades->total : 1; |
|
558 | + $total_grade_total = ! empty($total_quiz_grades->meta_sum) ? doubleval($total_quiz_grades->meta_sum) : 0; |
|
559 | + $total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2)); |
|
560 | 560 | |
561 | 561 | $course_args = array( |
562 | 562 | 'type' => 'sensei_course_status', |
563 | 563 | 'status' => 'any', |
564 | 564 | ); |
565 | - $total_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_started', $course_args ) ); |
|
565 | + $total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args)); |
|
566 | 566 | $course_args = array( |
567 | 567 | 'type' => 'sensei_course_status', |
568 | 568 | 'status' => 'complete', |
569 | 569 | ); |
570 | - $total_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_ended', $course_args ) ); |
|
571 | - $average_courses_per_learner = abs( round( doubleval( $total_courses_started / $user_count ), 2 ) ); |
|
570 | + $total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args)); |
|
571 | + $average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2)); |
|
572 | 572 | |
573 | 573 | // Setup the boxes to render |
574 | 574 | $stats_to_render = array( |
575 | - __( 'Total Courses', 'woothemes-sensei' ) => $total_courses, |
|
576 | - __( 'Total Lessons', 'woothemes-sensei' ) => $total_lessons, |
|
577 | - __( 'Total Learners', 'woothemes-sensei' ) => $user_count, |
|
578 | - __( 'Average Courses per Learner', 'woothemes-sensei' ) => $average_courses_per_learner, |
|
579 | - __( 'Average Grade', 'woothemes-sensei' ) => $total_average_grade . '%', |
|
580 | - __( 'Total Completed Courses', 'woothemes-sensei' ) => $total_courses_ended, |
|
575 | + __('Total Courses', 'woothemes-sensei') => $total_courses, |
|
576 | + __('Total Lessons', 'woothemes-sensei') => $total_lessons, |
|
577 | + __('Total Learners', 'woothemes-sensei') => $user_count, |
|
578 | + __('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner, |
|
579 | + __('Average Grade', 'woothemes-sensei') => $total_average_grade.'%', |
|
580 | + __('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended, |
|
581 | 581 | ); |
582 | - return apply_filters( 'sensei_analysis_stats_boxes', $stats_to_render ); |
|
582 | + return apply_filters('sensei_analysis_stats_boxes', $stats_to_render); |
|
583 | 583 | } // End stats_boxes() |
584 | 584 | |
585 | 585 | /** |
@@ -589,12 +589,12 @@ discard block |
||
589 | 589 | * @return void |
590 | 590 | */ |
591 | 591 | public function no_items() { |
592 | - if( ! $this->view || 'users' == $this->view ) { |
|
592 | + if ( ! $this->view || 'users' == $this->view) { |
|
593 | 593 | $type = 'learners'; |
594 | 594 | } else { |
595 | 595 | $type = $this->view; |
596 | 596 | } |
597 | - echo sprintf( __( '%1$sNo %2$s found%3$s', 'woothemes-sensei' ), '<em>', $type, '</em>' ); |
|
597 | + echo sprintf(__('%1$sNo %2$s found%3$s', 'woothemes-sensei'), '<em>', $type, '</em>'); |
|
598 | 598 | } // End no_items() |
599 | 599 | |
600 | 600 | /** |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | 'page' => $this->page_slug, |
610 | 610 | ); |
611 | 611 | $learners_class = $courses_class = $lessons_class = ''; |
612 | - switch( $this->type ) { |
|
612 | + switch ($this->type) { |
|
613 | 613 | case 'courses': |
614 | 614 | $courses_class = 'current'; |
615 | 615 | break; |
@@ -627,18 +627,18 @@ discard block |
||
627 | 627 | $lesson_args['view'] = 'lessons'; |
628 | 628 | $courses_args['view'] = 'courses'; |
629 | 629 | |
630 | - $menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ). '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>'; |
|
631 | - $menu['courses'] = '<a class="' . $courses_class . '" href="' . esc_url ( add_query_arg( $courses_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Courses', 'woothemes-sensei' ) . '</a>'; |
|
632 | - $menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>'; |
|
630 | + $menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>'; |
|
631 | + $menu['courses'] = '<a class="'.$courses_class.'" href="'.esc_url(add_query_arg($courses_args, admin_url('admin.php'))).'">'.__('Courses', 'woothemes-sensei').'</a>'; |
|
632 | + $menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>'; |
|
633 | 633 | |
634 | - $menu = apply_filters( 'sensei_analysis_overview_sub_menu', $menu ); |
|
635 | - if ( !empty($menu) ) { |
|
636 | - echo '<ul class="subsubsub">' . "\n"; |
|
637 | - foreach ( $menu as $class => $item ) { |
|
638 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
634 | + $menu = apply_filters('sensei_analysis_overview_sub_menu', $menu); |
|
635 | + if ( ! empty($menu)) { |
|
636 | + echo '<ul class="subsubsub">'."\n"; |
|
637 | + foreach ($menu as $class => $item) { |
|
638 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
639 | 639 | } |
640 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
641 | - echo '</ul>' . "\n"; |
|
640 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
641 | + echo '</ul>'."\n"; |
|
642 | 642 | } |
643 | 643 | } // End data_table_header() |
644 | 644 | |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * @return void |
649 | 649 | */ |
650 | 650 | public function data_table_footer() { |
651 | - switch ( $this->type ) { |
|
651 | + switch ($this->type) { |
|
652 | 652 | case 'courses': |
653 | 653 | $report = 'courses-overview'; |
654 | 654 | break; |
@@ -662,8 +662,8 @@ discard block |
||
662 | 662 | $report = 'user-overview'; |
663 | 663 | break; |
664 | 664 | } // End Switch Statement |
665 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
666 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
665 | + $url = add_query_arg(array('page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
666 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
667 | 667 | } // End data_table_footer() |
668 | 668 | |
669 | 669 | /** |
@@ -671,19 +671,19 @@ discard block |
||
671 | 671 | * @since 1.7.0 |
672 | 672 | * @return void |
673 | 673 | */ |
674 | - public function search_button( $text = '' ) { |
|
675 | - switch( $this->type ) { |
|
674 | + public function search_button($text = '') { |
|
675 | + switch ($this->type) { |
|
676 | 676 | case 'courses': |
677 | - $text = __( 'Search Courses', 'woothemes-sensei' ); |
|
677 | + $text = __('Search Courses', 'woothemes-sensei'); |
|
678 | 678 | break; |
679 | 679 | |
680 | 680 | case 'lessons': |
681 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
681 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
682 | 682 | break; |
683 | 683 | |
684 | 684 | case 'users': |
685 | 685 | default: |
686 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
686 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
687 | 687 | break; |
688 | 688 | } // End Switch Statement |
689 | 689 |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Display output to the admin view |
44 | - * |
|
45 | - * This view is shown when grading a quiz for a single user in admin under grading |
|
46 | - * |
|
44 | + * |
|
45 | + * This view is shown when grading a quiz for a single user in admin under grading |
|
46 | + * |
|
47 | 47 | * @since 1.3.0 |
48 | 48 | * @return html |
49 | 49 | */ |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | $user_quiz_grade_total = 0; |
58 | 58 | $quiz_grade_total = 0; |
59 | 59 | $quiz_grade = 0; |
60 | - $lesson_id = $this->lesson_id; |
|
61 | - $user_id = $this->user_id; |
|
60 | + $lesson_id = $this->lesson_id; |
|
61 | + $user_id = $this->user_id; |
|
62 | 62 | |
63 | 63 | ?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post"> |
64 | 64 | <?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?> |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | <p class="user-answer"><?php |
207 | 207 | foreach ( $user_answer_content as $_user_answer ) { |
208 | 208 | |
209 | - if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
209 | + if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
210 | 210 | |
211 | - $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
211 | + $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
212 | 212 | |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | 215 | echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>"; |
216 | 216 | } |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Grading User Quiz Class |
@@ -172,8 +175,7 @@ discard block |
||
172 | 175 | ++$correct_answers; |
173 | 176 | ++$graded_count; |
174 | 177 | $user_question_grade = 0; |
175 | - } |
|
176 | - elseif( intval( $user_question_grade ) > 0 ) { |
|
178 | + } elseif( intval( $user_question_grade ) > 0 ) { |
|
177 | 179 | $graded_class = 'user_right'; |
178 | 180 | ++$correct_answers; |
179 | 181 | $user_quiz_grade_total += $user_question_grade; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Grading User Quiz Class |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * @since 1.3.0 |
23 | 23 | * @return void |
24 | 24 | */ |
25 | - public function __construct ( $user_id = 0, $quiz_id = 0 ) { |
|
26 | - $this->user_id = intval( $user_id ); |
|
27 | - $this->quiz_id = intval( $quiz_id ); |
|
28 | - $this->lesson_id = get_post_meta( $this->quiz_id, '_quiz_lesson', true ); |
|
25 | + public function __construct($user_id = 0, $quiz_id = 0) { |
|
26 | + $this->user_id = intval($user_id); |
|
27 | + $this->quiz_id = intval($quiz_id); |
|
28 | + $this->lesson_id = get_post_meta($this->quiz_id, '_quiz_lesson', true); |
|
29 | 29 | } // End __construct() |
30 | 30 | |
31 | 31 | /** |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @return array |
36 | 36 | */ |
37 | 37 | public function build_data_array() { |
38 | - $data_array = Sensei_Utils::sensei_get_quiz_questions( $this->quiz_id ); |
|
38 | + $data_array = Sensei_Utils::sensei_get_quiz_questions($this->quiz_id); |
|
39 | 39 | return $data_array; |
40 | 40 | } // End build_data_array() |
41 | 41 | |
@@ -60,94 +60,94 @@ discard block |
||
60 | 60 | $lesson_id = $this->lesson_id; |
61 | 61 | $user_id = $this->user_id; |
62 | 62 | |
63 | - ?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post"> |
|
64 | - <?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?> |
|
65 | - <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e( $this->quiz_id ); ?>" /> |
|
66 | - <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e( $this->user_id ); ?>" /> |
|
63 | + ?><form name="<?php esc_attr_e('quiz_'.$this->quiz_id); ?>" action="" method="post"> |
|
64 | + <?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?> |
|
65 | + <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?>" /> |
|
66 | + <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?>" /> |
|
67 | 67 | <div class="total_grade_display"> |
68 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
68 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
69 | 69 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
70 | 70 | </div> |
71 | 71 | <div class="buttons"> |
72 | - <input type="submit" value="<?php esc_attr_e( __( 'Save', 'woothemes-sensei' ) ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
73 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
74 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
72 | + <input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
73 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
74 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
75 | 75 | </div> |
76 | 76 | <div class="clear"></div><br/><?php |
77 | 77 | |
78 | - $lesson_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID' ) ); |
|
79 | - $user_quiz_grade = get_comment_meta( $lesson_status_id, 'grade', true ); |
|
78 | + $lesson_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); |
|
79 | + $user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true); |
|
80 | 80 | $correct_answers = 0; |
81 | 81 | |
82 | - foreach( $questions as $question ) { |
|
82 | + foreach ($questions as $question) { |
|
83 | 83 | $question_id = $question->ID; |
84 | 84 | ++$count; |
85 | 85 | |
86 | 86 | $type = false; |
87 | 87 | $type_name = ''; |
88 | 88 | |
89 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
89 | + $type = Sensei()->question->get_question_type($question_id); |
|
90 | 90 | |
91 | - $question_answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $user_id ); |
|
91 | + $question_answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id); |
|
92 | 92 | |
93 | 93 | |
94 | - $question_grade_total = Sensei()->question->get_question_grade( $question_id ); |
|
94 | + $question_grade_total = Sensei()->question->get_question_grade($question_id); |
|
95 | 95 | $quiz_grade_total += $question_grade_total; |
96 | 96 | |
97 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
98 | - $user_answer_content = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id, $user_id ); |
|
99 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
97 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
98 | + $user_answer_content = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, $user_id); |
|
99 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
100 | 100 | $grade_type = 'manual-grade'; |
101 | 101 | |
102 | - switch( $type ) { |
|
102 | + switch ($type) { |
|
103 | 103 | case 'boolean': |
104 | - $type_name = __( 'True/False', 'woothemes-sensei' ); |
|
105 | - $right_answer = ucfirst( $right_answer ); |
|
106 | - $user_answer_content = ucfirst( $user_answer_content ); |
|
104 | + $type_name = __('True/False', 'woothemes-sensei'); |
|
105 | + $right_answer = ucfirst($right_answer); |
|
106 | + $user_answer_content = ucfirst($user_answer_content); |
|
107 | 107 | $grade_type = 'auto-grade'; |
108 | 108 | break; |
109 | 109 | case 'multiple-choice': |
110 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
110 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
111 | 111 | $grade_type = 'auto-grade'; |
112 | 112 | break; |
113 | 113 | case 'gap-fill': |
114 | - $type_name = __( 'Gap Fill', 'woothemes-sensei' ); |
|
114 | + $type_name = __('Gap Fill', 'woothemes-sensei'); |
|
115 | 115 | |
116 | - $right_answer_array = explode( '||', $right_answer ); |
|
117 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
118 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
119 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
116 | + $right_answer_array = explode('||', $right_answer); |
|
117 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
118 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
119 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
120 | 120 | |
121 | - if( ! $user_answer_content ) { |
|
121 | + if ( ! $user_answer_content) { |
|
122 | 122 | $user_answer_content = '______'; |
123 | 123 | } |
124 | 124 | |
125 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
126 | - $user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post; |
|
125 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
126 | + $user_answer_content = $gapfill_pre.' <span class="highlight">'.$user_answer_content.'</span> '.$gapfill_post; |
|
127 | 127 | $grade_type = 'auto-grade'; |
128 | 128 | |
129 | 129 | break; |
130 | 130 | case 'multi-line': |
131 | - $type_name = __( 'Multi Line', 'woothemes-sensei' ); |
|
131 | + $type_name = __('Multi Line', 'woothemes-sensei'); |
|
132 | 132 | $grade_type = 'manual-grade'; |
133 | 133 | break; |
134 | 134 | case 'single-line': |
135 | - $type_name = __( 'Single Line', 'woothemes-sensei' ); |
|
135 | + $type_name = __('Single Line', 'woothemes-sensei'); |
|
136 | 136 | $grade_type = 'manual-grade'; |
137 | 137 | break; |
138 | 138 | case 'file-upload': |
139 | - $type_name = __( 'File Upload', 'woothemes-sensei' ); |
|
139 | + $type_name = __('File Upload', 'woothemes-sensei'); |
|
140 | 140 | $grade_type = 'manual-grade'; |
141 | 141 | |
142 | 142 | // Get uploaded file |
143 | - if( $user_answer_content ) { |
|
143 | + if ($user_answer_content) { |
|
144 | 144 | $attachment_id = $user_answer_content; |
145 | 145 | $answer_media_url = $answer_media_filename = ''; |
146 | - if( 0 < intval( $attachment_id ) ) { |
|
147 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
148 | - $answer_media_filename = basename( $answer_media_url ); |
|
149 | - if( $answer_media_url && $answer_media_filename ) { |
|
150 | - $user_answer_content = sprintf( __( 'Submitted file: %1$s', 'woothemes-sensei' ), '<a href="' . esc_url( $answer_media_url ) . '" target="_blank">' . esc_html( $answer_media_filename ) . '</a>' ); |
|
146 | + if (0 < intval($attachment_id)) { |
|
147 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
148 | + $answer_media_filename = basename($answer_media_url); |
|
149 | + if ($answer_media_url && $answer_media_filename) { |
|
150 | + $user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="'.esc_url($answer_media_url).'" target="_blank">'.esc_html($answer_media_filename).'</a>'); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } else { |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | } |
161 | 161 | $user_answer_content = (array) $user_answer_content; |
162 | 162 | $right_answer = (array) $right_answer; |
163 | - $question_title = sprintf( __( 'Question %d: ', 'woothemes-sensei' ), $count ) . $type_name; |
|
163 | + $question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count).$type_name; |
|
164 | 164 | |
165 | 165 | $graded_class = ''; |
166 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, $user_id ); |
|
166 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, $user_id); |
|
167 | 167 | $graded_class = 'ungraded'; |
168 | - if ( 0 == $question_grade_total && 0 == intval( $user_question_grade ) ) { |
|
168 | + if (0 == $question_grade_total && 0 == intval($user_question_grade)) { |
|
169 | 169 | // Question skips grading |
170 | 170 | $grade_type = 'zero-graded'; |
171 | 171 | $graded_class = ''; |
@@ -173,86 +173,86 @@ discard block |
||
173 | 173 | ++$graded_count; |
174 | 174 | $user_question_grade = 0; |
175 | 175 | } |
176 | - elseif( intval( $user_question_grade ) > 0 ) { |
|
176 | + elseif (intval($user_question_grade) > 0) { |
|
177 | 177 | $graded_class = 'user_right'; |
178 | 178 | ++$correct_answers; |
179 | 179 | $user_quiz_grade_total += $user_question_grade; |
180 | 180 | ++$graded_count; |
181 | 181 | } else { |
182 | - if( ! is_string( $user_question_grade ) && intval( $user_question_grade ) == 0 ) { |
|
182 | + if ( ! is_string($user_question_grade) && intval($user_question_grade) == 0) { |
|
183 | 183 | $graded_class = 'user_wrong'; |
184 | 184 | ++$graded_count; |
185 | 185 | } |
186 | 186 | $user_question_grade = 0; |
187 | 187 | } |
188 | 188 | |
189 | - ?><div class="postbox question_box <?php esc_attr_e( $type ); ?> <?php esc_attr_e( $grade_type ); ?> <?php esc_attr_e( $graded_class ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_box' ); ?>"> |
|
189 | + ?><div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?>" id="<?php esc_attr_e('question_'.$question_id.'_box'); ?>"> |
|
190 | 190 | <div class="handlediv" title="Click to toggle"><br></div> |
191 | 191 | <h3 class="hndle"><span><?php echo $question_title; ?></span></h3> |
192 | 192 | <div class="inside"> |
193 | 193 | <div class="sensei-grading-actions"> |
194 | 194 | <div class="actions"> |
195 | - <input type="hidden" class="question_id" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
196 | - <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
197 | - <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_right_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="right" <?php checked( $graded_class, 'user_right', true ); ?> /></span> |
|
198 | - <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_wrong_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="wrong" <?php checked( $graded_class, 'user_wrong', true ); ?> /></span> |
|
199 | - <input type="number" class="question-grade" name="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" value="<?php echo esc_attr( $user_question_grade ); ?>" min="0" max="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
195 | + <input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?>" /> |
|
196 | + <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr($question_grade_total); ?>" /> |
|
197 | + <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_right_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="right" <?php checked($graded_class, 'user_right', true); ?> /></span> |
|
198 | + <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_wrong_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span> |
|
199 | + <input type="number" class="question-grade" name="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" id="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" value="<?php echo esc_attr($user_question_grade); ?>" min="0" max="<?php echo esc_attr($question_grade_total); ?>" /> |
|
200 | 200 | <span class="question-grade-total"><?php echo $question_grade_total; ?></span> |
201 | 201 | </div> |
202 | 202 | </div> |
203 | 203 | <div class="sensei-grading-answer"> |
204 | - <h4><?php echo apply_filters( 'sensei_question_title', $question->post_title ); ?></h4> |
|
205 | - <?php echo apply_filters( 'the_content', $question->post_content );?> |
|
204 | + <h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?></h4> |
|
205 | + <?php echo apply_filters('the_content', $question->post_content); ?> |
|
206 | 206 | <p class="user-answer"><?php |
207 | - foreach ( $user_answer_content as $_user_answer ) { |
|
207 | + foreach ($user_answer_content as $_user_answer) { |
|
208 | 208 | |
209 | - if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
209 | + if ('multi-line' == Sensei()->question->get_question_type($question->ID)) { |
|
210 | 210 | |
211 | - $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
211 | + $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer))); |
|
212 | 212 | |
213 | 213 | } |
214 | 214 | |
215 | - echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>"; |
|
215 | + echo apply_filters('sensei_answer_text', $_user_answer)."<br>"; |
|
216 | 216 | } |
217 | 217 | ?></p> |
218 | 218 | <div class="right-answer"> |
219 | - <h5><?php _e( 'Correct answer', 'woothemes-sensei' ) ?></h5> |
|
219 | + <h5><?php _e('Correct answer', 'woothemes-sensei') ?></h5> |
|
220 | 220 | <span class="correct-answer"><?php |
221 | - foreach ( $right_answer as $_right_answer ) { |
|
221 | + foreach ($right_answer as $_right_answer) { |
|
222 | 222 | |
223 | - echo apply_filters( 'sensei_answer_text', $_right_answer ) . "<br>"; |
|
223 | + echo apply_filters('sensei_answer_text', $_right_answer)."<br>"; |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | ?></span> |
227 | 227 | </div> |
228 | 228 | <div class="answer-notes"> |
229 | - <h5><?php _e( 'Grading Notes', 'woothemes-sensei' ) ?></h5> |
|
230 | - <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e( $question_id ); ?>]" placeholder="<?php _e( 'Add notes here...', 'woothemes-sensei' ) ?>"><?php echo $question_answer_notes; ?></textarea> |
|
229 | + <h5><?php _e('Grading Notes', 'woothemes-sensei') ?></h5> |
|
230 | + <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?>]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei') ?>"><?php echo $question_answer_notes; ?></textarea> |
|
231 | 231 | </div> |
232 | 232 | </div> |
233 | 233 | </div> |
234 | 234 | </div><?php |
235 | 235 | } |
236 | 236 | |
237 | - $quiz_grade = intval( $user_quiz_grade ); |
|
237 | + $quiz_grade = intval($user_quiz_grade); |
|
238 | 238 | $all_graded = 'no'; |
239 | - if( intval( $count ) == intval( $graded_count ) ) { |
|
239 | + if (intval($count) == intval($graded_count)) { |
|
240 | 240 | $all_graded = 'yes'; |
241 | 241 | } |
242 | 242 | |
243 | - ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e( $user_quiz_grade_total ); ?>" /> |
|
244 | - <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e( $count ); ?>" /> |
|
245 | - <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e( $quiz_grade_total ); ?>" /> |
|
246 | - <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e( $graded_count ); ?>" /> |
|
247 | - <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e( $all_graded ); ?>" /> |
|
243 | + ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?>" /> |
|
244 | + <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?>" /> |
|
245 | + <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?>" /> |
|
246 | + <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?>" /> |
|
247 | + <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?>" /> |
|
248 | 248 | <div class="total_grade_display"> |
249 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
249 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
250 | 250 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
251 | 251 | </div> |
252 | 252 | <div class="buttons"> |
253 | - <input type="submit" value="<?php esc_attr_e( 'Save' ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
254 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
255 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
253 | + <input type="submit" value="<?php esc_attr_e('Save'); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
254 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
255 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
256 | 256 | </div> |
257 | 257 | <div class="clear"></div> |
258 | 258 | <script type="text/javascript"> |
@@ -271,4 +271,4 @@ discard block |
||
271 | 271 | * for backward compatibility |
272 | 272 | * @since 1.9.0 |
273 | 273 | */ |
274 | -class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz{} |
|
274 | +class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz {} |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Grading Overview List Table Class |
@@ -155,8 +158,7 @@ discard block |
||
155 | 158 | |
156 | 159 | if( $this->lesson_id ) { |
157 | 160 | $activity_args['post_id'] = $this->lesson_id; |
158 | - } |
|
159 | - elseif( $this->course_id ) { |
|
161 | + } elseif( $this->course_id ) { |
|
160 | 162 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
161 | 163 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
162 | 164 | if ( version_compare($wp_version, '4.1', '>=') ) { |
@@ -231,24 +233,19 @@ discard block |
||
231 | 233 | if( 'complete' == $item->comment_approved ) { |
232 | 234 | $status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>'; |
233 | 235 | $grade = __( 'No Grade', 'woothemes-sensei' ); |
234 | - } |
|
235 | - elseif( 'graded' == $item->comment_approved ) { |
|
236 | + } elseif( 'graded' == $item->comment_approved ) { |
|
236 | 237 | $status_html = '<span class="graded">' . __( 'Graded', 'woothemes-sensei' ) . '</span>'; |
237 | 238 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
238 | - } |
|
239 | - elseif( 'passed' == $item->comment_approved ) { |
|
239 | + } elseif( 'passed' == $item->comment_approved ) { |
|
240 | 240 | $status_html = '<span class="passed">' . __( 'Passed', 'woothemes-sensei' ) . '</span>'; |
241 | 241 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
242 | - } |
|
243 | - elseif( 'failed' == $item->comment_approved ) { |
|
242 | + } elseif( 'failed' == $item->comment_approved ) { |
|
244 | 243 | $status_html = '<span class="failed">' . __( 'Failed', 'woothemes-sensei' ) . '</span>'; |
245 | 244 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
246 | - } |
|
247 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
245 | + } elseif( 'ungraded' == $item->comment_approved ) { |
|
248 | 246 | $status_html = '<span class="ungraded">' . __( 'Ungraded', 'woothemes-sensei' ) . '</span>'; |
249 | 247 | $grade = __( 'N/A', 'woothemes-sensei' ); |
250 | - } |
|
251 | - else { |
|
248 | + } else { |
|
252 | 249 | $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
253 | 250 | $grade = __( 'N/A', 'woothemes-sensei' ); |
254 | 251 | } |
@@ -276,8 +273,7 @@ discard block |
||
276 | 273 | $course_title = ''; |
277 | 274 | if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) { |
278 | 275 | $course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>'; |
279 | - } |
|
280 | - else if ( !empty($course_id) ) { |
|
276 | + } else if ( !empty($course_id) ) { |
|
281 | 277 | $course_title = get_the_title( $course_id ); |
282 | 278 | } |
283 | 279 | $lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>'; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $grade = __( 'N/A', 'woothemes-sensei' ); |
254 | 254 | } |
255 | 255 | |
256 | - $title = Sensei_Student::get_full_name( $item->user_id ); |
|
256 | + $title = Sensei_Student::get_full_name( $item->user_id ); |
|
257 | 257 | |
258 | 258 | // QuizID to be deprecated |
259 | 259 | $quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true ); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function no_items() { |
305 | 305 | |
306 | - _e( 'No submissions found.', 'woothemes-sensei' ); |
|
306 | + _e( 'No submissions found.', 'woothemes-sensei' ); |
|
307 | 307 | |
308 | 308 | } // End no_items() |
309 | 309 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Grading Overview List Table Class |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @since 1.3.0 |
26 | 26 | * @return void |
27 | 27 | */ |
28 | - public function __construct ( $args = null ) { |
|
28 | + public function __construct($args = null) { |
|
29 | 29 | |
30 | 30 | $defaults = array( |
31 | 31 | 'course_id' => 0, |
@@ -33,24 +33,24 @@ discard block |
||
33 | 33 | 'user_id' => false, |
34 | 34 | 'view' => 'ungraded', |
35 | 35 | ); |
36 | - $args = wp_parse_args( $args, $defaults ); |
|
36 | + $args = wp_parse_args($args, $defaults); |
|
37 | 37 | |
38 | - $this->course_id = intval( $args['course_id'] ); |
|
39 | - $this->lesson_id = intval( $args['lesson_id'] ); |
|
40 | - if ( !empty($args['user_id']) ) { |
|
41 | - $this->user_id = intval( $args['user_id'] ); |
|
38 | + $this->course_id = intval($args['course_id']); |
|
39 | + $this->lesson_id = intval($args['lesson_id']); |
|
40 | + if ( ! empty($args['user_id'])) { |
|
41 | + $this->user_id = intval($args['user_id']); |
|
42 | 42 | } |
43 | 43 | |
44 | - if( !empty( $args['view'] ) && in_array( $args['view'], array( 'in-progress', 'graded', 'ungraded', 'all' ) ) ) { |
|
44 | + if ( ! empty($args['view']) && in_array($args['view'], array('in-progress', 'graded', 'ungraded', 'all'))) { |
|
45 | 45 | $this->view = $args['view']; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Load Parent token into constructor |
49 | - parent::__construct( 'grading_main' ); |
|
49 | + parent::__construct('grading_main'); |
|
50 | 50 | |
51 | 51 | // Actions |
52 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
53 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
52 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
53 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
54 | 54 | } // End __construct() |
55 | 55 | |
56 | 56 | /** |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function get_columns() { |
62 | 62 | $columns = array( |
63 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
64 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
65 | - 'lesson' => __( 'Lesson', 'woothemes-sensei' ), |
|
66 | - 'updated' => __( 'Updated', 'woothemes-sensei' ), |
|
67 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
68 | - 'user_grade' => __( 'Grade', 'woothemes-sensei' ), |
|
63 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
64 | + 'course' => __('Course', 'woothemes-sensei'), |
|
65 | + 'lesson' => __('Lesson', 'woothemes-sensei'), |
|
66 | + 'updated' => __('Updated', 'woothemes-sensei'), |
|
67 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
68 | + 'user_grade' => __('Grade', 'woothemes-sensei'), |
|
69 | 69 | 'action' => '', |
70 | 70 | ); |
71 | 71 | |
72 | - $columns = apply_filters( 'sensei_grading_default_columns', $columns, $this ); |
|
72 | + $columns = apply_filters('sensei_grading_default_columns', $columns, $this); |
|
73 | 73 | return $columns; |
74 | 74 | } |
75 | 75 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function get_sortable_columns() { |
82 | 82 | $columns = array( |
83 | - 'title' => array( 'title', false ), |
|
84 | - 'course' => array( 'course', false ), |
|
85 | - 'lesson' => array( 'lesson', false ), |
|
86 | - 'updated' => array( 'updated', false ), |
|
87 | - 'user_status' => array( 'user_status', false ), |
|
88 | - 'user_grade' => array( 'user_grade', false ), |
|
83 | + 'title' => array('title', false), |
|
84 | + 'course' => array('course', false), |
|
85 | + 'lesson' => array('lesson', false), |
|
86 | + 'updated' => array('updated', false), |
|
87 | + 'user_status' => array('user_status', false), |
|
88 | + 'user_grade' => array('user_grade', false), |
|
89 | 89 | ); |
90 | - $columns = apply_filters( 'sensei_grading_default_columns_sortable', $columns, $this ); |
|
90 | + $columns = apply_filters('sensei_grading_default_columns_sortable', $columns, $this); |
|
91 | 91 | return $columns; |
92 | 92 | } |
93 | 93 | |
@@ -101,47 +101,47 @@ discard block |
||
101 | 101 | |
102 | 102 | // Handle orderby |
103 | 103 | $orderby = ''; |
104 | - if ( !empty( $_GET['orderby'] ) ) { |
|
105 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
106 | - $orderby = esc_html( $_GET['orderby'] ); |
|
104 | + if ( ! empty($_GET['orderby'])) { |
|
105 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
106 | + $orderby = esc_html($_GET['orderby']); |
|
107 | 107 | } // End If Statement |
108 | 108 | } |
109 | 109 | |
110 | 110 | // Handle order |
111 | 111 | $order = 'DESC'; |
112 | - if ( !empty( $_GET['order'] ) ) { |
|
113 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
112 | + if ( ! empty($_GET['order'])) { |
|
113 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // Handle search |
117 | 117 | $search = false; |
118 | - if ( !empty( $_GET['s'] ) ) { |
|
119 | - $search = esc_html( $_GET['s'] ); |
|
118 | + if ( ! empty($_GET['s'])) { |
|
119 | + $search = esc_html($_GET['s']); |
|
120 | 120 | } // End If Statement |
121 | 121 | $this->search = $search; |
122 | 122 | |
123 | 123 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
124 | - if ( $this->search ) { |
|
124 | + if ($this->search) { |
|
125 | 125 | $user_args = array( |
126 | - 'search' => '*' . $this->search . '*', |
|
126 | + 'search' => '*'.$this->search.'*', |
|
127 | 127 | 'fields' => 'ID', |
128 | 128 | ); |
129 | 129 | // Filter for extending |
130 | - $user_args = apply_filters( 'sensei_grading_search_users', $user_args ); |
|
131 | - if ( !empty( $user_args ) ) { |
|
132 | - $learners_search = new WP_User_Query( $user_args ); |
|
130 | + $user_args = apply_filters('sensei_grading_search_users', $user_args); |
|
131 | + if ( ! empty($user_args)) { |
|
132 | + $learners_search = new WP_User_Query($user_args); |
|
133 | 133 | // Store for reuse on counts |
134 | 134 | $this->user_ids = $learners_search->get_results(); |
135 | 135 | } |
136 | 136 | } // End If Statement |
137 | 137 | |
138 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
139 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
138 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
139 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
140 | 140 | |
141 | 141 | $paged = $this->get_pagenum(); |
142 | 142 | $offset = 0; |
143 | - if ( !empty($paged) ) { |
|
144 | - $offset = $per_page * ( $paged - 1 ); |
|
143 | + if ( ! empty($paged)) { |
|
144 | + $offset = $per_page * ($paged - 1); |
|
145 | 145 | } // End If Statement |
146 | 146 | |
147 | 147 | $activity_args = array( |
@@ -153,27 +153,27 @@ discard block |
||
153 | 153 | 'status' => 'any', |
154 | 154 | ); |
155 | 155 | |
156 | - if( $this->lesson_id ) { |
|
156 | + if ($this->lesson_id) { |
|
157 | 157 | $activity_args['post_id'] = $this->lesson_id; |
158 | 158 | } |
159 | - elseif( $this->course_id ) { |
|
159 | + elseif ($this->course_id) { |
|
160 | 160 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
161 | 161 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
162 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
163 | - $activity_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
162 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
163 | + $activity_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | // Sub select to group of learners |
167 | - if ( $this->user_ids ) { |
|
167 | + if ($this->user_ids) { |
|
168 | 168 | $activity_args['user_id'] = (array) $this->user_ids; |
169 | 169 | } |
170 | 170 | // Restrict to a single Learner |
171 | - if( $this->user_id ) { |
|
171 | + if ($this->user_id) { |
|
172 | 172 | $activity_args['user_id'] = $this->user_id; |
173 | 173 | } |
174 | 174 | |
175 | 175 | |
176 | - switch( $this->view ) { |
|
176 | + switch ($this->view) { |
|
177 | 177 | case 'in-progress' : |
178 | 178 | $activity_args['status'] = 'in-progress'; |
179 | 179 | break; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | break; |
184 | 184 | |
185 | 185 | case 'graded' : |
186 | - $activity_args['status'] = array( 'graded', 'passed', 'failed' ); |
|
186 | + $activity_args['status'] = array('graded', 'passed', 'failed'); |
|
187 | 187 | break; |
188 | 188 | |
189 | 189 | case 'all' : |
@@ -192,31 +192,31 @@ discard block |
||
192 | 192 | break; |
193 | 193 | } // End switch |
194 | 194 | |
195 | - $activity_args = apply_filters( 'sensei_grading_filter_statuses', $activity_args ); |
|
195 | + $activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args); |
|
196 | 196 | |
197 | 197 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
198 | - $total_statuses = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
198 | + $total_statuses = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
199 | 199 | |
200 | 200 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
201 | - if ( $total_statuses < $activity_args['offset'] ) { |
|
202 | - $new_paged = floor( $total_statuses / $activity_args['number'] ); |
|
201 | + if ($total_statuses < $activity_args['offset']) { |
|
202 | + $new_paged = floor($total_statuses / $activity_args['number']); |
|
203 | 203 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
204 | 204 | } |
205 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
205 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
206 | 206 | // Need to always return an array, even with only 1 item |
207 | - if ( !is_array($statuses) ) { |
|
208 | - $statuses = array( $statuses ); |
|
207 | + if ( ! is_array($statuses)) { |
|
208 | + $statuses = array($statuses); |
|
209 | 209 | } |
210 | 210 | $this->total_items = $total_statuses; |
211 | 211 | $this->items = $statuses; |
212 | 212 | |
213 | 213 | $total_items = $this->total_items; |
214 | - $total_pages = ceil( $total_items / $per_page ); |
|
215 | - $this->set_pagination_args( array( |
|
214 | + $total_pages = ceil($total_items / $per_page); |
|
215 | + $this->set_pagination_args(array( |
|
216 | 216 | 'total_items' => $total_items, |
217 | 217 | 'total_pages' => $total_pages, |
218 | 218 | 'per_page' => $per_page |
219 | - ) ); |
|
219 | + )); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -224,73 +224,73 @@ discard block |
||
224 | 224 | * @since 1.7.0 |
225 | 225 | * @param object $item The current item |
226 | 226 | */ |
227 | - protected function get_row_data( $item ) { |
|
227 | + protected function get_row_data($item) { |
|
228 | 228 | global $wp_version; |
229 | 229 | |
230 | 230 | $grade = ''; |
231 | - if( 'complete' == $item->comment_approved ) { |
|
232 | - $status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
233 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
231 | + if ('complete' == $item->comment_approved) { |
|
232 | + $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>'; |
|
233 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
234 | 234 | } |
235 | - elseif( 'graded' == $item->comment_approved ) { |
|
236 | - $status_html = '<span class="graded">' . __( 'Graded', 'woothemes-sensei' ) . '</span>'; |
|
237 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
235 | + elseif ('graded' == $item->comment_approved) { |
|
236 | + $status_html = '<span class="graded">'.__('Graded', 'woothemes-sensei').'</span>'; |
|
237 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
238 | 238 | } |
239 | - elseif( 'passed' == $item->comment_approved ) { |
|
240 | - $status_html = '<span class="passed">' . __( 'Passed', 'woothemes-sensei' ) . '</span>'; |
|
241 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
239 | + elseif ('passed' == $item->comment_approved) { |
|
240 | + $status_html = '<span class="passed">'.__('Passed', 'woothemes-sensei').'</span>'; |
|
241 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
242 | 242 | } |
243 | - elseif( 'failed' == $item->comment_approved ) { |
|
244 | - $status_html = '<span class="failed">' . __( 'Failed', 'woothemes-sensei' ) . '</span>'; |
|
245 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
243 | + elseif ('failed' == $item->comment_approved) { |
|
244 | + $status_html = '<span class="failed">'.__('Failed', 'woothemes-sensei').'</span>'; |
|
245 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
246 | 246 | } |
247 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
248 | - $status_html = '<span class="ungraded">' . __( 'Ungraded', 'woothemes-sensei' ) . '</span>'; |
|
249 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
247 | + elseif ('ungraded' == $item->comment_approved) { |
|
248 | + $status_html = '<span class="ungraded">'.__('Ungraded', 'woothemes-sensei').'</span>'; |
|
249 | + $grade = __('N/A', 'woothemes-sensei'); |
|
250 | 250 | } |
251 | 251 | else { |
252 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
253 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
252 | + $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>'; |
|
253 | + $grade = __('N/A', 'woothemes-sensei'); |
|
254 | 254 | } |
255 | 255 | |
256 | - $title = Sensei_Student::get_full_name( $item->user_id ); |
|
256 | + $title = Sensei_Student::get_full_name($item->user_id); |
|
257 | 257 | |
258 | 258 | // QuizID to be deprecated |
259 | - $quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true ); |
|
260 | - $quiz_link = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id ), admin_url( 'admin.php' ) ) ); |
|
259 | + $quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true); |
|
260 | + $quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php'))); |
|
261 | 261 | |
262 | 262 | $grade_link = ''; |
263 | - switch( $item->comment_approved ) { |
|
263 | + switch ($item->comment_approved) { |
|
264 | 264 | case 'ungraded': |
265 | - $grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei' ) . '</a>'; |
|
265 | + $grade_link = '<a class="button-primary button" href="'.$quiz_link.'">'.__('Grade quiz', 'woothemes-sensei').'</a>'; |
|
266 | 266 | break; |
267 | 267 | |
268 | 268 | case 'graded': |
269 | 269 | case 'passed': |
270 | 270 | case 'failed': |
271 | - $grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei' ) . '</a>'; |
|
271 | + $grade_link = '<a class="button-secondary button" href="'.$quiz_link.'">'.__('Review grade', 'woothemes-sensei').'</a>'; |
|
272 | 272 | break; |
273 | 273 | } |
274 | 274 | |
275 | - $course_id = get_post_meta( $item->comment_post_ID, '_lesson_course', true ); |
|
275 | + $course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true); |
|
276 | 276 | $course_title = ''; |
277 | - if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) { |
|
278 | - $course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>'; |
|
277 | + if ( ! empty($course_id) && version_compare($wp_version, '4.1', '>=')) { |
|
278 | + $course_title = '<a href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))).'">'.get_the_title($course_id).'</a>'; |
|
279 | 279 | } |
280 | - else if ( !empty($course_id) ) { |
|
281 | - $course_title = get_the_title( $course_id ); |
|
280 | + else if ( ! empty($course_id)) { |
|
281 | + $course_title = get_the_title($course_id); |
|
282 | 282 | } |
283 | - $lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>'; |
|
283 | + $lesson_title = '<a href="'.add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')).'">'.get_the_title($item->comment_post_ID).'</a>'; |
|
284 | 284 | |
285 | - $column_data = apply_filters( 'sensei_grading_main_column_data', array( |
|
286 | - 'title' => '<strong><a class="row-title" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id ), admin_url( 'admin.php' ) ) ) . '"">' . $title . '</a></strong>', |
|
285 | + $column_data = apply_filters('sensei_grading_main_column_data', array( |
|
286 | + 'title' => '<strong><a class="row-title" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))).'"">'.$title.'</a></strong>', |
|
287 | 287 | 'course' => $course_title, |
288 | 288 | 'lesson' => $lesson_title, |
289 | 289 | 'updated' => $item->comment_date, |
290 | 290 | 'user_status' => $status_html, |
291 | 291 | 'user_grade' => $grade, |
292 | 292 | 'action' => $grade_link, |
293 | - ), $item, $course_id ); |
|
293 | + ), $item, $course_id); |
|
294 | 294 | |
295 | 295 | return $column_data; |
296 | 296 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function no_items() { |
305 | 305 | |
306 | - _e( 'No submissions found.', 'woothemes-sensei' ); |
|
306 | + _e('No submissions found.', 'woothemes-sensei'); |
|
307 | 307 | |
308 | 308 | } // End no_items() |
309 | 309 | |
@@ -316,35 +316,35 @@ discard block |
||
316 | 316 | global $wp_version; |
317 | 317 | |
318 | 318 | echo '<div class="grading-selects">'; |
319 | - do_action( 'sensei_grading_before_dropdown_filters' ); |
|
319 | + do_action('sensei_grading_before_dropdown_filters'); |
|
320 | 320 | |
321 | - echo '<div class="select-box">' . "\n"; |
|
321 | + echo '<div class="select-box">'."\n"; |
|
322 | 322 | |
323 | - echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">' . "\n"; |
|
323 | + echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">'."\n"; |
|
324 | 324 | |
325 | - echo Sensei()->grading->courses_drop_down_html( $this->course_id ); |
|
325 | + echo Sensei()->grading->courses_drop_down_html($this->course_id); |
|
326 | 326 | |
327 | - echo '</select>' . "\n"; |
|
327 | + echo '</select>'."\n"; |
|
328 | 328 | |
329 | - echo '</div>' . "\n"; |
|
329 | + echo '</div>'."\n"; |
|
330 | 330 | |
331 | - echo '<div class="select-box">' . "\n"; |
|
331 | + echo '<div class="select-box">'."\n"; |
|
332 | 332 | |
333 | - echo '<select id="grading-lesson-options" data-placeholder="← ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n"; |
|
333 | + echo '<select id="grading-lesson-options" data-placeholder="← '.__('Select a course', 'woothemes-sensei').'" name="grading_lesson" class="chosen_select widefat">'."\n"; |
|
334 | 334 | |
335 | - echo Sensei()->grading->lessons_drop_down_html( $this->course_id, $this->lesson_id ); |
|
335 | + echo Sensei()->grading->lessons_drop_down_html($this->course_id, $this->lesson_id); |
|
336 | 336 | |
337 | - echo '</select>' . "\n"; |
|
337 | + echo '</select>'."\n"; |
|
338 | 338 | |
339 | - echo '</div>' . "\n"; |
|
339 | + echo '</div>'."\n"; |
|
340 | 340 | |
341 | - if( $this->course_id && $this->lesson_id ) { |
|
341 | + if ($this->course_id && $this->lesson_id) { |
|
342 | 342 | |
343 | - echo '<div class="select-box reset-filter">' . "\n"; |
|
343 | + echo '<div class="select-box reset-filter">'."\n"; |
|
344 | 344 | |
345 | - echo '<a class="button-secondary" href="' . esc_url( remove_query_arg( array( 'lesson_id', 'course_id' ) ) ) . '">' . __( 'Reset filter', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
345 | + echo '<a class="button-secondary" href="'.esc_url(remove_query_arg(array('lesson_id', 'course_id'))).'">'.__('Reset filter', 'woothemes-sensei').'</a>'."\n"; |
|
346 | 346 | |
347 | - echo '</div>' . "\n"; |
|
347 | + echo '</div>'."\n"; |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | $query_args = array( |
360 | 360 | 'page' => $this->page_slug, |
361 | 361 | ); |
362 | - if( $this->course_id ) { |
|
362 | + if ($this->course_id) { |
|
363 | 363 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
364 | 364 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
365 | 365 | $query_args['course_id'] = $this->course_id; |
366 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
367 | - $count_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
366 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
367 | + $count_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
368 | 368 | } |
369 | 369 | } |
370 | - if( $this->lesson_id ) { |
|
370 | + if ($this->lesson_id) { |
|
371 | 371 | $query_args['lesson_id'] = $this->lesson_id; |
372 | 372 | // Restrict to a single lesson |
373 | 373 | $count_args['post_id'] = $this->lesson_id; |
374 | 374 | } |
375 | - if( $this->search ) { |
|
375 | + if ($this->search) { |
|
376 | 376 | $query_args['s'] = $this->search; |
377 | 377 | } |
378 | - if ( !empty($this->user_ids) ) { |
|
378 | + if ( ! empty($this->user_ids)) { |
|
379 | 379 | $count_args['user_id'] = $this->user_ids; |
380 | 380 | } |
381 | - if( !empty($this->user_id) ) { |
|
381 | + if ( ! empty($this->user_id)) { |
|
382 | 382 | $query_args['user_id'] = $this->user_id; |
383 | 383 | $count_args['user_id'] = $this->user_id; |
384 | 384 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | $all_lessons_count = $ungraded_lessons_count = $graded_lessons_count = $inprogress_lessons_count = 0; |
387 | 387 | $all_class = $ungraded_class = $graded_class = $inprogress_class = ''; |
388 | 388 | |
389 | - switch( $this->view ) : |
|
389 | + switch ($this->view) : |
|
390 | 390 | case 'all': |
391 | 391 | $all_class = 'current'; |
392 | 392 | break; |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | break; |
403 | 403 | endswitch; |
404 | 404 | |
405 | - $counts = Sensei()->grading->count_statuses( apply_filters( 'sensei_grading_count_statues', $count_args ) ); |
|
405 | + $counts = Sensei()->grading->count_statuses(apply_filters('sensei_grading_count_statues', $count_args)); |
|
406 | 406 | |
407 | 407 | $inprogress_lessons_count = $counts['in-progress']; |
408 | 408 | $ungraded_lessons_count = $counts['ungraded']; |
@@ -418,19 +418,19 @@ discard block |
||
418 | 418 | $inprogress_args['view'] = 'in-progress'; |
419 | 419 | |
420 | 420 | $format = '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>'; |
421 | - $menu['all'] = sprintf( $format, $all_class, esc_url( add_query_arg( $all_args, admin_url( 'admin.php' ) ) ), __( 'All', 'woothemes-sensei' ), number_format( (int) $all_lessons_count ) ); |
|
422 | - $menu['ungraded'] = sprintf( $format, $ungraded_class, esc_url( add_query_arg( $ungraded_args, admin_url( 'admin.php' ) ) ), __( 'Ungraded', 'woothemes-sensei' ), number_format( (int) $ungraded_lessons_count ) ); |
|
423 | - $menu['graded'] = sprintf( $format, $graded_class, esc_url( add_query_arg( $graded_args, admin_url( 'admin.php' ) ) ), __( 'Graded', 'woothemes-sensei' ), number_format( (int) $graded_lessons_count ) ); |
|
424 | - $menu['in-progress'] = sprintf( $format, $inprogress_class, esc_url( add_query_arg( $inprogress_args, admin_url( 'admin.php' ) ) ), __( 'In Progress', 'woothemes-sensei' ), number_format( (int) $inprogress_lessons_count ) ); |
|
425 | - |
|
426 | - $menu = apply_filters( 'sensei_grading_sub_menu', $menu ); |
|
427 | - if ( !empty($menu) ) { |
|
428 | - echo '<ul class="subsubsub">' . "\n"; |
|
429 | - foreach ( $menu as $class => $item ) { |
|
430 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
421 | + $menu['all'] = sprintf($format, $all_class, esc_url(add_query_arg($all_args, admin_url('admin.php'))), __('All', 'woothemes-sensei'), number_format((int) $all_lessons_count)); |
|
422 | + $menu['ungraded'] = sprintf($format, $ungraded_class, esc_url(add_query_arg($ungraded_args, admin_url('admin.php'))), __('Ungraded', 'woothemes-sensei'), number_format((int) $ungraded_lessons_count)); |
|
423 | + $menu['graded'] = sprintf($format, $graded_class, esc_url(add_query_arg($graded_args, admin_url('admin.php'))), __('Graded', 'woothemes-sensei'), number_format((int) $graded_lessons_count)); |
|
424 | + $menu['in-progress'] = sprintf($format, $inprogress_class, esc_url(add_query_arg($inprogress_args, admin_url('admin.php'))), __('In Progress', 'woothemes-sensei'), number_format((int) $inprogress_lessons_count)); |
|
425 | + |
|
426 | + $menu = apply_filters('sensei_grading_sub_menu', $menu); |
|
427 | + if ( ! empty($menu)) { |
|
428 | + echo '<ul class="subsubsub">'."\n"; |
|
429 | + foreach ($menu as $class => $item) { |
|
430 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
431 | 431 | } |
432 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
433 | - echo '</ul>' . "\n"; |
|
432 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
433 | + echo '</ul>'."\n"; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | } // End data_table_header() |
@@ -451,4 +451,4 @@ discard block |
||
451 | 451 | * for backward compatibility |
452 | 452 | * @since 1.9.0 |
453 | 453 | */ |
454 | -class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main{} |
|
454 | +class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main {} |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// security check, don't load file outside WP |
|
3 | 6 | /** |
4 | 7 | * Sensei Autoloader Class |
5 | 8 | * |
@@ -13,124 +13,124 @@ |
||
13 | 13 | */ |
14 | 14 | class Sensei_Autoloader { |
15 | 15 | |
16 | - /** |
|
17 | - * @var path to the includes directory within Sensei. |
|
18 | - */ |
|
19 | - private $include_path = 'includes'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var array $class_file_map. List of classes mapped to their files |
|
23 | - */ |
|
24 | - private $class_file_map = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Constructor |
|
28 | - * @since 1.9.0 |
|
29 | - */ |
|
30 | - public function __construct(){ |
|
31 | - |
|
32 | - // make sure we do not override an existing autoload function |
|
33 | - if( function_exists('__autoload') ){ |
|
34 | - spl_autoload_register( '__autoload' ); |
|
35 | - } |
|
36 | - |
|
37 | - // setup a relative path for the current autoload instance |
|
38 | - $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
39 | - |
|
40 | - //setup the class file map |
|
41 | - $this->initialize_class_file_map(); |
|
42 | - |
|
43 | - // add Sensei custom auto loader |
|
44 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Generate a list of Sensei class and map them the their respective |
|
50 | - * files within the includes directory |
|
51 | - * |
|
52 | - * @since 1.9.0 |
|
53 | - */ |
|
54 | - public function initialize_class_file_map(){ |
|
55 | - |
|
56 | - $this->class_file_map = array( |
|
57 | - |
|
58 | - /** |
|
59 | - * Main Sensei class |
|
60 | - */ |
|
61 | - 'Sensei_Main' => 'class-sensei.php', |
|
62 | - |
|
63 | - /** |
|
64 | - * Admin |
|
65 | - */ |
|
66 | - 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
67 | - 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
68 | - |
|
69 | - /** |
|
70 | - * Shortcodes |
|
71 | - */ |
|
72 | - 'Sensei_Shortcode_Loader' => 'shortcodes/class-sensei-shortcode-loader.php', |
|
73 | - 'Sensei_Shortcode_Interface' => 'shortcodes/interface-sensei-shortcode.php', |
|
74 | - 'Sensei_Shortcode_Featured_Courses' => 'shortcodes/class-sensei-shortcode-featured-courses.php', |
|
75 | - 'Sensei_Shortcode_User_Courses' => 'shortcodes/class-sensei-shortcode-user-courses.php', |
|
76 | - 'Sensei_Shortcode_Courses' => 'shortcodes/class-sensei-shortcode-courses.php', |
|
77 | - 'Sensei_Shortcode_Teachers' => 'shortcodes/class-sensei-shortcode-teachers.php', |
|
78 | - 'Sensei_Shortcode_User_Messages' => 'shortcodes/class-sensei-shortcode-user-messages.php', |
|
79 | - 'Sensei_Shortcode_Course_Page' => 'shortcodes/class-sensei-shortcode-course-page.php', |
|
80 | - 'Sensei_Shortcode_Lesson_Page' => 'shortcodes/class-sensei-shortcode-lesson-page.php', |
|
81 | - 'Sensei_Shortcode_Course_Categories' => 'shortcodes/class-sensei-shortcode-course-categories.php', |
|
82 | - 'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php', |
|
83 | - 'Sensei_Legacy_Shortcodes' => 'shortcodes/class-sensei-legacy-shortcodes.php', |
|
84 | - |
|
85 | - /** |
|
86 | - * WooCommerce |
|
87 | - */ |
|
88 | - 'Sensei_WC' => 'class-sensei-wc.php', |
|
89 | - |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Autoload all sensei files as the class names are used. |
|
95 | - */ |
|
96 | - public function autoload( $class ){ |
|
97 | - |
|
98 | - // only handle classes with the word `sensei` in it |
|
99 | - if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
100 | - |
|
101 | - return; |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - // exit if we didn't provide mapping for this class |
|
106 | - if( isset( $this->class_file_map[ $class ] ) ){ |
|
107 | - |
|
108 | - $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
109 | - require_once( $file_location); |
|
110 | - return; |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - // check for file in the main includes directory |
|
115 | - $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
116 | - if( file_exists( $class_file_path ) ){ |
|
117 | - |
|
118 | - require_once( $class_file_path ); |
|
119 | - return; |
|
120 | - } |
|
121 | - |
|
122 | - // lastly check legacy types |
|
123 | - $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
124 | - $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
125 | - if( file_exists( $legacy_class_file_path ) ){ |
|
126 | - |
|
127 | - require_once( $legacy_class_file_path ); |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - return; |
|
132 | - |
|
133 | - }// end autoload |
|
16 | + /** |
|
17 | + * @var path to the includes directory within Sensei. |
|
18 | + */ |
|
19 | + private $include_path = 'includes'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var array $class_file_map. List of classes mapped to their files |
|
23 | + */ |
|
24 | + private $class_file_map = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Constructor |
|
28 | + * @since 1.9.0 |
|
29 | + */ |
|
30 | + public function __construct(){ |
|
31 | + |
|
32 | + // make sure we do not override an existing autoload function |
|
33 | + if( function_exists('__autoload') ){ |
|
34 | + spl_autoload_register( '__autoload' ); |
|
35 | + } |
|
36 | + |
|
37 | + // setup a relative path for the current autoload instance |
|
38 | + $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
39 | + |
|
40 | + //setup the class file map |
|
41 | + $this->initialize_class_file_map(); |
|
42 | + |
|
43 | + // add Sensei custom auto loader |
|
44 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Generate a list of Sensei class and map them the their respective |
|
50 | + * files within the includes directory |
|
51 | + * |
|
52 | + * @since 1.9.0 |
|
53 | + */ |
|
54 | + public function initialize_class_file_map(){ |
|
55 | + |
|
56 | + $this->class_file_map = array( |
|
57 | + |
|
58 | + /** |
|
59 | + * Main Sensei class |
|
60 | + */ |
|
61 | + 'Sensei_Main' => 'class-sensei.php', |
|
62 | + |
|
63 | + /** |
|
64 | + * Admin |
|
65 | + */ |
|
66 | + 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
67 | + 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
68 | + |
|
69 | + /** |
|
70 | + * Shortcodes |
|
71 | + */ |
|
72 | + 'Sensei_Shortcode_Loader' => 'shortcodes/class-sensei-shortcode-loader.php', |
|
73 | + 'Sensei_Shortcode_Interface' => 'shortcodes/interface-sensei-shortcode.php', |
|
74 | + 'Sensei_Shortcode_Featured_Courses' => 'shortcodes/class-sensei-shortcode-featured-courses.php', |
|
75 | + 'Sensei_Shortcode_User_Courses' => 'shortcodes/class-sensei-shortcode-user-courses.php', |
|
76 | + 'Sensei_Shortcode_Courses' => 'shortcodes/class-sensei-shortcode-courses.php', |
|
77 | + 'Sensei_Shortcode_Teachers' => 'shortcodes/class-sensei-shortcode-teachers.php', |
|
78 | + 'Sensei_Shortcode_User_Messages' => 'shortcodes/class-sensei-shortcode-user-messages.php', |
|
79 | + 'Sensei_Shortcode_Course_Page' => 'shortcodes/class-sensei-shortcode-course-page.php', |
|
80 | + 'Sensei_Shortcode_Lesson_Page' => 'shortcodes/class-sensei-shortcode-lesson-page.php', |
|
81 | + 'Sensei_Shortcode_Course_Categories' => 'shortcodes/class-sensei-shortcode-course-categories.php', |
|
82 | + 'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php', |
|
83 | + 'Sensei_Legacy_Shortcodes' => 'shortcodes/class-sensei-legacy-shortcodes.php', |
|
84 | + |
|
85 | + /** |
|
86 | + * WooCommerce |
|
87 | + */ |
|
88 | + 'Sensei_WC' => 'class-sensei-wc.php', |
|
89 | + |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Autoload all sensei files as the class names are used. |
|
95 | + */ |
|
96 | + public function autoload( $class ){ |
|
97 | + |
|
98 | + // only handle classes with the word `sensei` in it |
|
99 | + if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
100 | + |
|
101 | + return; |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + // exit if we didn't provide mapping for this class |
|
106 | + if( isset( $this->class_file_map[ $class ] ) ){ |
|
107 | + |
|
108 | + $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
109 | + require_once( $file_location); |
|
110 | + return; |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + // check for file in the main includes directory |
|
115 | + $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
116 | + if( file_exists( $class_file_path ) ){ |
|
117 | + |
|
118 | + require_once( $class_file_path ); |
|
119 | + return; |
|
120 | + } |
|
121 | + |
|
122 | + // lastly check legacy types |
|
123 | + $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
124 | + $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
125 | + if( file_exists( $legacy_class_file_path ) ){ |
|
126 | + |
|
127 | + require_once( $legacy_class_file_path ); |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + return; |
|
132 | + |
|
133 | + }// end autoload |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | new Sensei_Autoloader(); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
3 | 3 | /** |
4 | 4 | * Sensei Autoloader Class |
5 | 5 | * |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | * Constructor |
28 | 28 | * @since 1.9.0 |
29 | 29 | */ |
30 | - public function __construct(){ |
|
30 | + public function __construct() { |
|
31 | 31 | |
32 | 32 | // make sure we do not override an existing autoload function |
33 | - if( function_exists('__autoload') ){ |
|
34 | - spl_autoload_register( '__autoload' ); |
|
33 | + if (function_exists('__autoload')) { |
|
34 | + spl_autoload_register('__autoload'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // setup a relative path for the current autoload instance |
38 | - $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
38 | + $this->include_path = trailingslashit(untrailingslashit(dirname(__FILE__))); |
|
39 | 39 | |
40 | 40 | //setup the class file map |
41 | 41 | $this->initialize_class_file_map(); |
42 | 42 | |
43 | 43 | // add Sensei custom auto loader |
44 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
44 | + spl_autoload_register(array($this, 'autoload')); |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @since 1.9.0 |
53 | 53 | */ |
54 | - public function initialize_class_file_map(){ |
|
54 | + public function initialize_class_file_map() { |
|
55 | 55 | |
56 | 56 | $this->class_file_map = array( |
57 | 57 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Admin |
65 | 65 | */ |
66 | - 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
67 | - 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
66 | + 'Sensei_Welcome' => 'admin/class-sensei-welcome.php', |
|
67 | + 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php', |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Shortcodes |
@@ -93,38 +93,38 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * Autoload all sensei files as the class names are used. |
95 | 95 | */ |
96 | - public function autoload( $class ){ |
|
96 | + public function autoload($class) { |
|
97 | 97 | |
98 | 98 | // only handle classes with the word `sensei` in it |
99 | - if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
99 | + if ( ! is_numeric(strpos(strtolower($class), 'sensei'))) { |
|
100 | 100 | |
101 | 101 | return; |
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | 105 | // exit if we didn't provide mapping for this class |
106 | - if( isset( $this->class_file_map[ $class ] ) ){ |
|
106 | + if (isset($this->class_file_map[$class])) { |
|
107 | 107 | |
108 | - $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
109 | - require_once( $file_location); |
|
108 | + $file_location = $this->include_path.$this->class_file_map[$class]; |
|
109 | + require_once($file_location); |
|
110 | 110 | return; |
111 | 111 | |
112 | 112 | } |
113 | 113 | |
114 | 114 | // check for file in the main includes directory |
115 | - $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
116 | - if( file_exists( $class_file_path ) ){ |
|
115 | + $class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($class)).'.php'; |
|
116 | + if (file_exists($class_file_path)) { |
|
117 | 117 | |
118 | - require_once( $class_file_path ); |
|
118 | + require_once($class_file_path); |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // lastly check legacy types |
123 | - $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
124 | - $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
125 | - if( file_exists( $legacy_class_file_path ) ){ |
|
123 | + $stripped_woothemes_from_class = str_replace('woothemes_', '', strtolower($class)); // remove woothemes |
|
124 | + $legacy_class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($stripped_woothemes_from_class)).'.php'; |
|
125 | + if (file_exists($legacy_class_file_path)) { |
|
126 | 126 | |
127 | - require_once( $legacy_class_file_path ); |
|
127 | + require_once($legacy_class_file_path); |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Post Types Class |
@@ -146,7 +149,7 @@ discard block |
||
146 | 149 | |
147 | 150 | return get_page_uri( $settings_course_page->ID ); |
148 | 151 | |
149 | - }else{ |
|
152 | + } else{ |
|
150 | 153 | |
151 | 154 | return 'courses'; |
152 | 155 |
@@ -17,25 +17,25 @@ discard block |
||
17 | 17 | public $slider_labels; |
18 | 18 | public $role_caps; |
19 | 19 | |
20 | - /** |
|
21 | - * @var Sensei_Course |
|
22 | - */ |
|
23 | - public $course; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var Sensei_Lesson |
|
27 | - */ |
|
28 | - public $lesson; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var Sensei_Question |
|
32 | - */ |
|
33 | - public $question; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Sensei_Quiz |
|
37 | - */ |
|
38 | - public $quiz; |
|
20 | + /** |
|
21 | + * @var Sensei_Course |
|
22 | + */ |
|
23 | + public $course; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var Sensei_Lesson |
|
27 | + */ |
|
28 | + public $lesson; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var Sensei_Question |
|
32 | + */ |
|
33 | + public $question; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Sensei_Quiz |
|
37 | + */ |
|
38 | + public $quiz; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Constructor |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | // Setup Post Types |
47 | 47 | $this->labels = array(); |
48 | - $this->token = 'woothemes-sensei-posttypes'; |
|
48 | + $this->token = 'woothemes-sensei-posttypes'; |
|
49 | 49 | |
50 | 50 | $this->setup_post_type_labels_base(); |
51 | 51 | add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
@@ -104,94 +104,94 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * Setup the "course" post type, it's admin menu item and the appropriate labels and permissions. |
106 | 106 | * @since 1.0.0 |
107 | - * @uses Sensei() |
|
107 | + * @uses Sensei() |
|
108 | 108 | * @return void |
109 | 109 | */ |
110 | 110 | public function setup_course_post_type () { |
111 | 111 | |
112 | 112 | $args = array( |
113 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
114 | - 'public' => true, |
|
115 | - 'publicly_queryable' => true, |
|
116 | - 'show_ui' => true, |
|
117 | - 'show_in_menu' => true, |
|
118 | - 'show_in_admin_bar' => true, |
|
119 | - 'query_var' => true, |
|
120 | - 'rewrite' => array( |
|
121 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
122 | - 'with_front' => true, |
|
123 | - 'feeds' => true, |
|
124 | - 'pages' => true |
|
125 | - ), |
|
126 | - 'map_meta_cap' => true, |
|
127 | - 'capability_type' => 'course', |
|
128 | - 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
129 | - 'hierarchical' => false, |
|
130 | - 'menu_position' => 51, |
|
131 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
113 | + 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
114 | + 'public' => true, |
|
115 | + 'publicly_queryable' => true, |
|
116 | + 'show_ui' => true, |
|
117 | + 'show_in_menu' => true, |
|
118 | + 'show_in_admin_bar' => true, |
|
119 | + 'query_var' => true, |
|
120 | + 'rewrite' => array( |
|
121 | + 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
122 | + 'with_front' => true, |
|
123 | + 'feeds' => true, |
|
124 | + 'pages' => true |
|
125 | + ), |
|
126 | + 'map_meta_cap' => true, |
|
127 | + 'capability_type' => 'course', |
|
128 | + 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
129 | + 'hierarchical' => false, |
|
130 | + 'menu_position' => 51, |
|
131 | + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
132 | 132 | ); |
133 | 133 | |
134 | - /** |
|
135 | - * Filter the arguments passed in when registering the Sensei Course post type. |
|
136 | - * |
|
137 | - * @since 1.9.0 |
|
138 | - * @param array $args |
|
139 | - */ |
|
134 | + /** |
|
135 | + * Filter the arguments passed in when registering the Sensei Course post type. |
|
136 | + * |
|
137 | + * @since 1.9.0 |
|
138 | + * @param array $args |
|
139 | + */ |
|
140 | 140 | register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
141 | 141 | |
142 | 142 | } // End setup_course_post_type() |
143 | 143 | |
144 | - /** |
|
145 | - * Figure out of the course post type has an archive and what it should be. |
|
146 | - * |
|
147 | - * This function should return 'courses' or the page_uri for the course page setting. |
|
148 | - * |
|
149 | - * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
150 | - * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
151 | - * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
152 | - * |
|
153 | - * |
|
154 | - * @sine 1.9.0 |
|
155 | - * |
|
156 | - * |
|
157 | - * @return false|string |
|
158 | - */ |
|
159 | - public function get_course_post_type_archive_slug(){ |
|
144 | + /** |
|
145 | + * Figure out of the course post type has an archive and what it should be. |
|
146 | + * |
|
147 | + * This function should return 'courses' or the page_uri for the course page setting. |
|
148 | + * |
|
149 | + * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
150 | + * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
151 | + * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
152 | + * |
|
153 | + * |
|
154 | + * @sine 1.9.0 |
|
155 | + * |
|
156 | + * |
|
157 | + * @return false|string |
|
158 | + */ |
|
159 | + public function get_course_post_type_archive_slug(){ |
|
160 | 160 | |
161 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
161 | + $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
162 | 162 | |
163 | - // for a valid post that doesn't have any of the old short codes set the archive the same |
|
164 | - // as the page URI |
|
165 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
163 | + // for a valid post that doesn't have any of the old short codes set the archive the same |
|
164 | + // as the page URI |
|
165 | + if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
166 | 166 | |
167 | - return get_page_uri( $settings_course_page->ID ); |
|
167 | + return get_page_uri( $settings_course_page->ID ); |
|
168 | 168 | |
169 | - }else{ |
|
169 | + }else{ |
|
170 | 170 | |
171 | - return 'courses'; |
|
171 | + return 'courses'; |
|
172 | 172 | |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - }// end course_post_type_determine_archive |
|
175 | + }// end course_post_type_determine_archive |
|
176 | 176 | |
177 | - /** |
|
178 | - * Check if given content has any of these old shortcodes: |
|
179 | - * [newcourses][featuredcourses][freecourses][paidcourses] |
|
180 | - * |
|
181 | - * @since 1.9.0 |
|
182 | - * |
|
183 | - * @param string $content |
|
184 | - * |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function has_old_shortcodes( $content ){ |
|
177 | + /** |
|
178 | + * Check if given content has any of these old shortcodes: |
|
179 | + * [newcourses][featuredcourses][freecourses][paidcourses] |
|
180 | + * |
|
181 | + * @since 1.9.0 |
|
182 | + * |
|
183 | + * @param string $content |
|
184 | + * |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function has_old_shortcodes( $content ){ |
|
188 | 188 | |
189 | - return ( has_shortcode( $content, 'newcourses') |
|
190 | - || has_shortcode( $content, 'featuredcourses') |
|
191 | - || has_shortcode( $content, 'freecourses') |
|
192 | - || has_shortcode( $content, 'paidcourses') ); |
|
189 | + return ( has_shortcode( $content, 'newcourses') |
|
190 | + || has_shortcode( $content, 'featuredcourses') |
|
191 | + || has_shortcode( $content, 'freecourses') |
|
192 | + || has_shortcode( $content, 'paidcourses') ); |
|
193 | 193 | |
194 | - }// end has old shortcodes |
|
194 | + }// end has old shortcodes |
|
195 | 195 | |
196 | 196 | |
197 | 197 | /** |
@@ -213,32 +213,32 @@ discard block |
||
213 | 213 | } // End If Statement |
214 | 214 | |
215 | 215 | $args = array( |
216 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
217 | - 'public' => true, |
|
218 | - 'publicly_queryable' => true, |
|
219 | - 'show_ui' => true, |
|
220 | - 'show_in_menu' => true, |
|
221 | - 'query_var' => true, |
|
222 | - 'rewrite' => array( |
|
223 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
224 | - 'with_front' => true, |
|
225 | - 'feeds' => true, |
|
226 | - 'pages' => true |
|
227 | - ), |
|
228 | - 'map_meta_cap' => true, |
|
229 | - 'capability_type' => 'lesson', |
|
230 | - 'has_archive' => true, |
|
231 | - 'hierarchical' => false, |
|
232 | - 'menu_position' => 52, |
|
233 | - 'supports' => $supports_array |
|
216 | + 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
217 | + 'public' => true, |
|
218 | + 'publicly_queryable' => true, |
|
219 | + 'show_ui' => true, |
|
220 | + 'show_in_menu' => true, |
|
221 | + 'query_var' => true, |
|
222 | + 'rewrite' => array( |
|
223 | + 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
224 | + 'with_front' => true, |
|
225 | + 'feeds' => true, |
|
226 | + 'pages' => true |
|
227 | + ), |
|
228 | + 'map_meta_cap' => true, |
|
229 | + 'capability_type' => 'lesson', |
|
230 | + 'has_archive' => true, |
|
231 | + 'hierarchical' => false, |
|
232 | + 'menu_position' => 52, |
|
233 | + 'supports' => $supports_array |
|
234 | 234 | ); |
235 | 235 | |
236 | - /** |
|
237 | - * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
238 | - * |
|
239 | - * @since 1.9.0 |
|
240 | - * @param array $args |
|
241 | - */ |
|
236 | + /** |
|
237 | + * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
238 | + * |
|
239 | + * @since 1.9.0 |
|
240 | + * @param array $args |
|
241 | + */ |
|
242 | 242 | register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
243 | 243 | |
244 | 244 | } // End setup_lesson_post_type() |
@@ -246,45 +246,45 @@ discard block |
||
246 | 246 | /** |
247 | 247 | * Setup the "quiz" post type, it's admin menu item and the appropriate labels and permissions. |
248 | 248 | * @since 1.0.0 |
249 | - * @uses Sensei() |
|
249 | + * @uses Sensei() |
|
250 | 250 | * @return void |
251 | 251 | */ |
252 | 252 | public function setup_quiz_post_type () { |
253 | 253 | |
254 | 254 | |
255 | 255 | $args = array( |
256 | - 'labels' => $this->create_post_type_labels( |
|
257 | - $this->labels['quiz']['singular'], |
|
258 | - $this->labels['quiz']['plural'], |
|
259 | - $this->labels['quiz']['menu'] |
|
260 | - ), |
|
261 | - 'public' => true, |
|
262 | - 'publicly_queryable' => true, |
|
263 | - 'show_ui' => true, |
|
264 | - 'show_in_menu' => false, |
|
265 | - 'show_in_nav_menus' => false, |
|
266 | - 'query_var' => true, |
|
267 | - 'exclude_from_search' => true, |
|
268 | - 'rewrite' => array( |
|
269 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
270 | - 'with_front' => true, |
|
271 | - 'feeds' => true, |
|
272 | - 'pages' => true |
|
273 | - ), |
|
274 | - 'map_meta_cap' => true, |
|
275 | - 'capability_type' => 'quiz', |
|
276 | - 'has_archive' => false, |
|
277 | - 'hierarchical' => false, |
|
278 | - 'menu_position' => 20, // Below "Pages" |
|
279 | - 'supports' => array( '' ) |
|
256 | + 'labels' => $this->create_post_type_labels( |
|
257 | + $this->labels['quiz']['singular'], |
|
258 | + $this->labels['quiz']['plural'], |
|
259 | + $this->labels['quiz']['menu'] |
|
260 | + ), |
|
261 | + 'public' => true, |
|
262 | + 'publicly_queryable' => true, |
|
263 | + 'show_ui' => true, |
|
264 | + 'show_in_menu' => false, |
|
265 | + 'show_in_nav_menus' => false, |
|
266 | + 'query_var' => true, |
|
267 | + 'exclude_from_search' => true, |
|
268 | + 'rewrite' => array( |
|
269 | + 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
270 | + 'with_front' => true, |
|
271 | + 'feeds' => true, |
|
272 | + 'pages' => true |
|
273 | + ), |
|
274 | + 'map_meta_cap' => true, |
|
275 | + 'capability_type' => 'quiz', |
|
276 | + 'has_archive' => false, |
|
277 | + 'hierarchical' => false, |
|
278 | + 'menu_position' => 20, // Below "Pages" |
|
279 | + 'supports' => array( '' ) |
|
280 | 280 | ); |
281 | 281 | |
282 | - /** |
|
283 | - * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
284 | - * |
|
285 | - * @since 1.9.0 |
|
286 | - * @param array $args |
|
287 | - */ |
|
282 | + /** |
|
283 | + * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
284 | + * |
|
285 | + * @since 1.9.0 |
|
286 | + * @param array $args |
|
287 | + */ |
|
288 | 288 | register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
289 | 289 | |
290 | 290 | } // End setup_quiz_post_type() |
@@ -298,34 +298,34 @@ discard block |
||
298 | 298 | public function setup_question_post_type () { |
299 | 299 | |
300 | 300 | $args = array( |
301 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
302 | - 'public' => false, |
|
303 | - 'publicly_queryable' => true, |
|
304 | - 'show_ui' => true, |
|
305 | - 'show_in_menu' => true, |
|
306 | - 'show_in_nav_menus' => false, |
|
307 | - 'query_var' => true, |
|
308 | - 'exclude_from_search' => true, |
|
309 | - 'rewrite' => array( |
|
310 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
311 | - 'with_front' => true, |
|
312 | - 'feeds' => true, |
|
313 | - 'pages' => true |
|
314 | - ), |
|
315 | - 'map_meta_cap' => true, |
|
316 | - 'capability_type' => 'question', |
|
317 | - 'has_archive' => true, |
|
318 | - 'hierarchical' => false, |
|
319 | - 'menu_position' => 51, |
|
320 | - 'supports' => array( 'title' ) |
|
301 | + 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
302 | + 'public' => false, |
|
303 | + 'publicly_queryable' => true, |
|
304 | + 'show_ui' => true, |
|
305 | + 'show_in_menu' => true, |
|
306 | + 'show_in_nav_menus' => false, |
|
307 | + 'query_var' => true, |
|
308 | + 'exclude_from_search' => true, |
|
309 | + 'rewrite' => array( |
|
310 | + 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
311 | + 'with_front' => true, |
|
312 | + 'feeds' => true, |
|
313 | + 'pages' => true |
|
314 | + ), |
|
315 | + 'map_meta_cap' => true, |
|
316 | + 'capability_type' => 'question', |
|
317 | + 'has_archive' => true, |
|
318 | + 'hierarchical' => false, |
|
319 | + 'menu_position' => 51, |
|
320 | + 'supports' => array( 'title' ) |
|
321 | 321 | ); |
322 | 322 | |
323 | - /** |
|
324 | - * Filter the arguments passed in when registering the Sensei Question post type. |
|
325 | - * |
|
326 | - * @since 1.9.0 |
|
327 | - * @param array $args |
|
328 | - */ |
|
323 | + /** |
|
324 | + * Filter the arguments passed in when registering the Sensei Question post type. |
|
325 | + * |
|
326 | + * @since 1.9.0 |
|
327 | + * @param array $args |
|
328 | + */ |
|
329 | 329 | register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
330 | 330 | |
331 | 331 | } // End setup_question_post_type() |
@@ -338,26 +338,26 @@ discard block |
||
338 | 338 | public function setup_multiple_question_post_type () { |
339 | 339 | |
340 | 340 | $args = array( |
341 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
342 | - 'public' => false, |
|
343 | - 'publicly_queryable' => false, |
|
344 | - 'show_ui' => false, |
|
345 | - 'show_in_menu' => false, |
|
346 | - 'show_in_nav_menus' => false, |
|
347 | - 'query_var' => false, |
|
348 | - 'exclude_from_search' => true, |
|
349 | - 'rewrite' => array( |
|
350 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
351 | - 'with_front' => false, |
|
352 | - 'feeds' => false, |
|
353 | - 'pages' => false |
|
354 | - ), |
|
355 | - 'map_meta_cap' => true, |
|
356 | - 'capability_type' => 'question', |
|
357 | - 'has_archive' => false, |
|
358 | - 'hierarchical' => false, |
|
359 | - 'menu_position' => 51, |
|
360 | - 'supports' => array( 'title', 'custom-fields' ) |
|
341 | + 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
342 | + 'public' => false, |
|
343 | + 'publicly_queryable' => false, |
|
344 | + 'show_ui' => false, |
|
345 | + 'show_in_menu' => false, |
|
346 | + 'show_in_nav_menus' => false, |
|
347 | + 'query_var' => false, |
|
348 | + 'exclude_from_search' => true, |
|
349 | + 'rewrite' => array( |
|
350 | + 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
351 | + 'with_front' => false, |
|
352 | + 'feeds' => false, |
|
353 | + 'pages' => false |
|
354 | + ), |
|
355 | + 'map_meta_cap' => true, |
|
356 | + 'capability_type' => 'question', |
|
357 | + 'has_archive' => false, |
|
358 | + 'hierarchical' => false, |
|
359 | + 'menu_position' => 51, |
|
360 | + 'supports' => array( 'title', 'custom-fields' ) |
|
361 | 361 | ); |
362 | 362 | |
363 | 363 | register_post_type( 'multiple_question', $args ); |
@@ -374,34 +374,34 @@ discard block |
||
374 | 374 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
375 | 375 | |
376 | 376 | $args = array( |
377 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
378 | - 'public' => true, |
|
379 | - 'publicly_queryable' => true, |
|
380 | - 'show_ui' => true, |
|
381 | - 'show_in_menu' => 'sensei', |
|
382 | - 'show_in_nav_menus' => true, |
|
383 | - 'query_var' => true, |
|
384 | - 'exclude_from_search' => true, |
|
385 | - 'rewrite' => array( |
|
386 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
387 | - 'with_front' => false, |
|
388 | - 'feeds' => false, |
|
389 | - 'pages' => true |
|
390 | - ), |
|
391 | - 'map_meta_cap' => true, |
|
392 | - 'capability_type' => 'question', |
|
393 | - 'has_archive' => true, |
|
394 | - 'hierarchical' => false, |
|
395 | - 'menu_position' => 50, |
|
396 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
377 | + 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
378 | + 'public' => true, |
|
379 | + 'publicly_queryable' => true, |
|
380 | + 'show_ui' => true, |
|
381 | + 'show_in_menu' => 'sensei', |
|
382 | + 'show_in_nav_menus' => true, |
|
383 | + 'query_var' => true, |
|
384 | + 'exclude_from_search' => true, |
|
385 | + 'rewrite' => array( |
|
386 | + 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
387 | + 'with_front' => false, |
|
388 | + 'feeds' => false, |
|
389 | + 'pages' => true |
|
390 | + ), |
|
391 | + 'map_meta_cap' => true, |
|
392 | + 'capability_type' => 'question', |
|
393 | + 'has_archive' => true, |
|
394 | + 'hierarchical' => false, |
|
395 | + 'menu_position' => 50, |
|
396 | + 'supports' => array( 'title', 'editor', 'comments' ), |
|
397 | 397 | ); |
398 | 398 | |
399 | - /** |
|
400 | - * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
401 | - * |
|
402 | - * @since 1.9.0 |
|
403 | - * @param array $args |
|
404 | - */ |
|
399 | + /** |
|
400 | + * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
401 | + * |
|
402 | + * @since 1.9.0 |
|
403 | + * @param array $args |
|
404 | + */ |
|
405 | 405 | register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
406 | 406 | } |
407 | 407 | } // End setup_sensei_message_post_type() |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | 'show_ui' => true, |
435 | 435 | 'query_var' => true, |
436 | 436 | 'show_in_nav_menus' => true, |
437 | - 'capabilities' => array( |
|
438 | - 'manage_terms' => 'manage_categories', |
|
439 | - 'edit_terms' => 'edit_courses', |
|
440 | - 'delete_terms' => 'manage_categories', |
|
441 | - 'assign_terms' => 'edit_courses',), |
|
437 | + 'capabilities' => array( |
|
438 | + 'manage_terms' => 'manage_categories', |
|
439 | + 'edit_terms' => 'edit_courses', |
|
440 | + 'delete_terms' => 'manage_categories', |
|
441 | + 'assign_terms' => 'edit_courses',), |
|
442 | 442 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
443 | 443 | ); |
444 | 444 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | 'show_ui' => true, /* TO DO - future releases */ |
475 | 475 | 'query_var' => true, |
476 | 476 | 'show_in_nav_menus' => false, |
477 | - 'public' => false, |
|
477 | + 'public' => false, |
|
478 | 478 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
479 | 479 | ); |
480 | 480 | |
@@ -546,11 +546,11 @@ discard block |
||
546 | 546 | 'query_var' => false, |
547 | 547 | 'show_in_nav_menus' => false, |
548 | 548 | 'show_admin_column' => true, |
549 | - 'capabilities' => array( |
|
550 | - 'manage_terms' => 'manage_categories', |
|
551 | - 'edit_terms' => 'edit_questions', |
|
552 | - 'delete_terms' => 'manage_categories', |
|
553 | - 'assign_terms' => 'edit_questions',), |
|
549 | + 'capabilities' => array( |
|
550 | + 'manage_terms' => 'manage_categories', |
|
551 | + 'edit_terms' => 'edit_questions', |
|
552 | + 'delete_terms' => 'manage_categories', |
|
553 | + 'assign_terms' => 'edit_questions',), |
|
554 | 554 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
555 | 555 | ); |
556 | 556 | |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | 'show_ui' => true, |
585 | 585 | 'query_var' => true, |
586 | 586 | 'show_in_nav_menus' => true, |
587 | - 'capabilities' => array( |
|
588 | - 'manage_terms' => 'manage_categories', |
|
589 | - 'edit_terms' => 'edit_lessons', |
|
590 | - 'delete_terms' => 'manage_categories', |
|
591 | - 'assign_terms' => 'edit_lessons',), |
|
587 | + 'capabilities' => array( |
|
588 | + 'manage_terms' => 'manage_categories', |
|
589 | + 'edit_terms' => 'edit_lessons', |
|
590 | + 'delete_terms' => 'manage_categories', |
|
591 | + 'assign_terms' => 'edit_lessons',), |
|
592 | 592 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
593 | 593 | ); |
594 | 594 | |
@@ -622,19 +622,19 @@ discard block |
||
622 | 622 | */ |
623 | 623 | private function create_post_type_labels ( $singular, $plural, $menu ) { |
624 | 624 | $labels = array( |
625 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
626 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
627 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
628 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
629 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
630 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
631 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
632 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
633 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
634 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
635 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
636 | - 'parent_item_colon' => '', |
|
637 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
625 | + 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
626 | + 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
627 | + 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
628 | + 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
629 | + 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
630 | + 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
631 | + 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
632 | + 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
633 | + 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
634 | + 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
635 | + 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
636 | + 'parent_item_colon' => '', |
|
637 | + 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
638 | 638 | ); |
639 | 639 | |
640 | 640 | return $labels; |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | * Assigns the defaults for each user role capabilities. |
708 | 708 | * |
709 | 709 | * @since 1.1.0 |
710 | - * |
|
710 | + * |
|
711 | 711 | * @param array $post_types |
712 | 712 | * @return void |
713 | 713 | */ |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | * Adds a 'Edit Quiz' link to the admin bar when viewing a Quiz linked to a corresponding Lesson |
776 | 776 | * |
777 | 777 | * @since 1.7.0 |
778 | - * @param WP_Admin_Bar $bar |
|
778 | + * @param WP_Admin_Bar $bar |
|
779 | 779 | * @return void |
780 | 780 | */ |
781 | 781 | public function quiz_admin_bar_menu( $bar ) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Post Types Class |
@@ -41,43 +41,43 @@ discard block |
||
41 | 41 | * Constructor |
42 | 42 | * @since 1.0.0 |
43 | 43 | */ |
44 | - public function __construct () { |
|
44 | + public function __construct() { |
|
45 | 45 | |
46 | 46 | // Setup Post Types |
47 | 47 | $this->labels = array(); |
48 | 48 | $this->token = 'woothemes-sensei-posttypes'; |
49 | 49 | |
50 | 50 | $this->setup_post_type_labels_base(); |
51 | - add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
|
52 | - add_action( 'init', array( $this, 'setup_lesson_post_type' ), 100 ); |
|
53 | - add_action( 'init', array( $this, 'setup_quiz_post_type' ), 100 ); |
|
54 | - add_action( 'init', array( $this, 'setup_question_post_type' ), 100 ); |
|
55 | - add_action( 'init', array( $this, 'setup_multiple_question_post_type' ), 100 ); |
|
56 | - add_action( 'init', array( $this, 'setup_sensei_message_post_type' ), 100 ); |
|
51 | + add_action('init', array($this, 'setup_course_post_type'), 100); |
|
52 | + add_action('init', array($this, 'setup_lesson_post_type'), 100); |
|
53 | + add_action('init', array($this, 'setup_quiz_post_type'), 100); |
|
54 | + add_action('init', array($this, 'setup_question_post_type'), 100); |
|
55 | + add_action('init', array($this, 'setup_multiple_question_post_type'), 100); |
|
56 | + add_action('init', array($this, 'setup_sensei_message_post_type'), 100); |
|
57 | 57 | |
58 | 58 | // Setup Taxonomies |
59 | - add_action( 'init', array( $this, 'setup_course_category_taxonomy' ), 100 ); |
|
60 | - add_action( 'init', array( $this, 'setup_quiz_type_taxonomy' ), 100 ); |
|
61 | - add_action( 'init', array( $this, 'setup_question_type_taxonomy' ), 100 ); |
|
62 | - add_action( 'init', array( $this, 'setup_question_category_taxonomy' ), 100 ); |
|
63 | - add_action( 'init', array( $this, 'setup_lesson_tag_taxonomy' ), 100 ); |
|
59 | + add_action('init', array($this, 'setup_course_category_taxonomy'), 100); |
|
60 | + add_action('init', array($this, 'setup_quiz_type_taxonomy'), 100); |
|
61 | + add_action('init', array($this, 'setup_question_type_taxonomy'), 100); |
|
62 | + add_action('init', array($this, 'setup_question_category_taxonomy'), 100); |
|
63 | + add_action('init', array($this, 'setup_lesson_tag_taxonomy'), 100); |
|
64 | 64 | |
65 | 65 | // Load Post Type Objects |
66 | - $default_post_types = array( 'course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages' ) ; |
|
67 | - $this->load_posttype_objects( $default_post_types ); |
|
66 | + $default_post_types = array('course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages'); |
|
67 | + $this->load_posttype_objects($default_post_types); |
|
68 | 68 | |
69 | 69 | // Admin functions |
70 | - if ( is_admin() ) { |
|
71 | - $this->set_role_cap_defaults( $default_post_types ); |
|
70 | + if (is_admin()) { |
|
71 | + $this->set_role_cap_defaults($default_post_types); |
|
72 | 72 | global $pagenow; |
73 | - if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) { |
|
74 | - add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 10 ); |
|
75 | - add_filter( 'post_updated_messages', array( $this, 'setup_post_type_messages' ) ); |
|
73 | + if (($pagenow == 'post.php' || $pagenow == 'post-new.php')) { |
|
74 | + add_filter('enter_title_here', array($this, 'enter_title_here'), 10); |
|
75 | + add_filter('post_updated_messages', array($this, 'setup_post_type_messages')); |
|
76 | 76 | } // End If Statement |
77 | 77 | } // End If Statement |
78 | 78 | |
79 | 79 | // Add 'Edit Quiz' link to admin bar |
80 | - add_action( 'admin_bar_menu', array( $this, 'quiz_admin_bar_menu' ), 81 ); |
|
80 | + add_action('admin_bar_menu', array($this, 'quiz_admin_bar_menu'), 81); |
|
81 | 81 | |
82 | 82 | } // End __construct() |
83 | 83 | |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | * @param array $posttypes (default: array()) |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function load_posttype_objects( $posttypes = array() ) { |
|
91 | + public function load_posttype_objects($posttypes = array()) { |
|
92 | 92 | |
93 | - foreach ( $posttypes as $posttype_token => $posttype_name ) { |
|
93 | + foreach ($posttypes as $posttype_token => $posttype_name) { |
|
94 | 94 | |
95 | 95 | // Load the files |
96 | - $class_name = 'WooThemes_Sensei_' . $posttype_name; |
|
96 | + $class_name = 'WooThemes_Sensei_'.$posttype_name; |
|
97 | 97 | $this->$posttype_token = new $class_name(); |
98 | 98 | $this->$posttype_token->token = $posttype_token; |
99 | 99 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | * @uses Sensei() |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - public function setup_course_post_type () { |
|
110 | + public function setup_course_post_type() { |
|
111 | 111 | |
112 | 112 | $args = array( |
113 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
113 | + 'labels' => $this->create_post_type_labels($this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu']), |
|
114 | 114 | 'public' => true, |
115 | 115 | 'publicly_queryable' => true, |
116 | 116 | 'show_ui' => true, |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | 'show_in_admin_bar' => true, |
119 | 119 | 'query_var' => true, |
120 | 120 | 'rewrite' => array( |
121 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
121 | + 'slug' => esc_attr(apply_filters('sensei_course_slug', _x('course', 'post type single url base', 'woothemes-sensei'))), |
|
122 | 122 | 'with_front' => true, |
123 | 123 | 'feeds' => true, |
124 | 124 | 'pages' => true |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | 'has_archive' => $this->get_course_post_type_archive_slug(), |
129 | 129 | 'hierarchical' => false, |
130 | 130 | 'menu_position' => 51, |
131 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
131 | + 'supports' => array('title', 'editor', 'excerpt', 'thumbnail') |
|
132 | 132 | ); |
133 | 133 | |
134 | 134 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @since 1.9.0 |
138 | 138 | * @param array $args |
139 | 139 | */ |
140 | - register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
|
140 | + register_post_type('course', apply_filters('sensei_register_post_type_course', $args)); |
|
141 | 141 | |
142 | 142 | } // End setup_course_post_type() |
143 | 143 | |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return false|string |
158 | 158 | */ |
159 | - public function get_course_post_type_archive_slug(){ |
|
159 | + public function get_course_post_type_archive_slug() { |
|
160 | 160 | |
161 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
161 | + $settings_course_page = get_post(Sensei()->settings->get('course_page')); |
|
162 | 162 | |
163 | 163 | // for a valid post that doesn't have any of the old short codes set the archive the same |
164 | 164 | // as the page URI |
165 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
165 | + if (is_a($settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes($settings_course_page->post_content)) { |
|
166 | 166 | |
167 | - return get_page_uri( $settings_course_page->ID ); |
|
167 | + return get_page_uri($settings_course_page->ID); |
|
168 | 168 | |
169 | - }else{ |
|
169 | + } else { |
|
170 | 170 | |
171 | 171 | return 'courses'; |
172 | 172 | |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return bool |
186 | 186 | */ |
187 | - public function has_old_shortcodes( $content ){ |
|
187 | + public function has_old_shortcodes($content) { |
|
188 | 188 | |
189 | - return ( has_shortcode( $content, 'newcourses') |
|
190 | - || has_shortcode( $content, 'featuredcourses') |
|
191 | - || has_shortcode( $content, 'freecourses') |
|
192 | - || has_shortcode( $content, 'paidcourses') ); |
|
189 | + return (has_shortcode($content, 'newcourses') |
|
190 | + || has_shortcode($content, 'featuredcourses') |
|
191 | + || has_shortcode($content, 'freecourses') |
|
192 | + || has_shortcode($content, 'paidcourses')); |
|
193 | 193 | |
194 | 194 | }// end has old shortcodes |
195 | 195 | |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * @uses Sensei() |
201 | 201 | * @return void |
202 | 202 | */ |
203 | - public function setup_lesson_post_type () { |
|
203 | + public function setup_lesson_post_type() { |
|
204 | 204 | |
205 | 205 | |
206 | - $supports_array = array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ); |
|
206 | + $supports_array = array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes'); |
|
207 | 207 | $allow_comments = false; |
208 | - if ( isset( Sensei()->settings->settings[ 'lesson_comments' ] ) ) { |
|
209 | - $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ]; |
|
208 | + if (isset(Sensei()->settings->settings['lesson_comments'])) { |
|
209 | + $allow_comments = Sensei()->settings->settings['lesson_comments']; |
|
210 | 210 | } // End If Statement |
211 | - if ( $allow_comments ) { |
|
212 | - array_push( $supports_array, 'comments' ); |
|
211 | + if ($allow_comments) { |
|
212 | + array_push($supports_array, 'comments'); |
|
213 | 213 | } // End If Statement |
214 | 214 | |
215 | 215 | $args = array( |
216 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
216 | + 'labels' => $this->create_post_type_labels($this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu']), |
|
217 | 217 | 'public' => true, |
218 | 218 | 'publicly_queryable' => true, |
219 | 219 | 'show_ui' => true, |
220 | 220 | 'show_in_menu' => true, |
221 | 221 | 'query_var' => true, |
222 | 222 | 'rewrite' => array( |
223 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
223 | + 'slug' => esc_attr(apply_filters('sensei_lesson_slug', _x('lesson', 'post type single slug', 'woothemes-sensei'))), |
|
224 | 224 | 'with_front' => true, |
225 | 225 | 'feeds' => true, |
226 | 226 | 'pages' => true |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @since 1.9.0 |
240 | 240 | * @param array $args |
241 | 241 | */ |
242 | - register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
|
242 | + register_post_type('lesson', apply_filters('sensei_register_post_type_lesson', $args)); |
|
243 | 243 | |
244 | 244 | } // End setup_lesson_post_type() |
245 | 245 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @uses Sensei() |
250 | 250 | * @return void |
251 | 251 | */ |
252 | - public function setup_quiz_post_type () { |
|
252 | + public function setup_quiz_post_type() { |
|
253 | 253 | |
254 | 254 | |
255 | 255 | $args = array( |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | 'query_var' => true, |
267 | 267 | 'exclude_from_search' => true, |
268 | 268 | 'rewrite' => array( |
269 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
269 | + 'slug' => esc_attr(apply_filters('sensei_quiz_slug', _x('quiz', 'post type single slug', 'woothemes-sensei'))), |
|
270 | 270 | 'with_front' => true, |
271 | 271 | 'feeds' => true, |
272 | 272 | 'pages' => true |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | 'has_archive' => false, |
277 | 277 | 'hierarchical' => false, |
278 | 278 | 'menu_position' => 20, // Below "Pages" |
279 | - 'supports' => array( '' ) |
|
279 | + 'supports' => array('') |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @since 1.9.0 |
286 | 286 | * @param array $args |
287 | 287 | */ |
288 | - register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
|
288 | + register_post_type('quiz', apply_filters('sensei_register_post_type_quiz', $args)); |
|
289 | 289 | |
290 | 290 | } // End setup_quiz_post_type() |
291 | 291 | |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | * @since 1.0.0 |
296 | 296 | * @return void |
297 | 297 | */ |
298 | - public function setup_question_post_type () { |
|
298 | + public function setup_question_post_type() { |
|
299 | 299 | |
300 | 300 | $args = array( |
301 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
301 | + 'labels' => $this->create_post_type_labels($this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu']), |
|
302 | 302 | 'public' => false, |
303 | 303 | 'publicly_queryable' => true, |
304 | 304 | 'show_ui' => true, |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | 'query_var' => true, |
308 | 308 | 'exclude_from_search' => true, |
309 | 309 | 'rewrite' => array( |
310 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
310 | + 'slug' => esc_attr(apply_filters('sensei_question_slug', _x('question', 'post type single slug', 'woothemes-sensei'))), |
|
311 | 311 | 'with_front' => true, |
312 | 312 | 'feeds' => true, |
313 | 313 | 'pages' => true |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | 'has_archive' => true, |
318 | 318 | 'hierarchical' => false, |
319 | 319 | 'menu_position' => 51, |
320 | - 'supports' => array( 'title' ) |
|
320 | + 'supports' => array('title') |
|
321 | 321 | ); |
322 | 322 | |
323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @since 1.9.0 |
327 | 327 | * @param array $args |
328 | 328 | */ |
329 | - register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
|
329 | + register_post_type('question', apply_filters('sensei_register_post_type_question', $args)); |
|
330 | 330 | |
331 | 331 | } // End setup_question_post_type() |
332 | 332 | |
@@ -335,10 +335,10 @@ discard block |
||
335 | 335 | * @since 1.6.0 |
336 | 336 | * @return void |
337 | 337 | */ |
338 | - public function setup_multiple_question_post_type () { |
|
338 | + public function setup_multiple_question_post_type() { |
|
339 | 339 | |
340 | 340 | $args = array( |
341 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
341 | + 'labels' => $this->create_post_type_labels($this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu']), |
|
342 | 342 | 'public' => false, |
343 | 343 | 'publicly_queryable' => false, |
344 | 344 | 'show_ui' => false, |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | 'query_var' => false, |
348 | 348 | 'exclude_from_search' => true, |
349 | 349 | 'rewrite' => array( |
350 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
350 | + 'slug' => esc_attr(apply_filters('sensei_multiple_question_slug', _x('multiple_question', 'post type single slug', 'woothemes-sensei'))), |
|
351 | 351 | 'with_front' => false, |
352 | 352 | 'feeds' => false, |
353 | 353 | 'pages' => false |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | 'has_archive' => false, |
358 | 358 | 'hierarchical' => false, |
359 | 359 | 'menu_position' => 51, |
360 | - 'supports' => array( 'title', 'custom-fields' ) |
|
360 | + 'supports' => array('title', 'custom-fields') |
|
361 | 361 | ); |
362 | 362 | |
363 | - register_post_type( 'multiple_question', $args ); |
|
363 | + register_post_type('multiple_question', $args); |
|
364 | 364 | } // End setup_multiple_question_post_type() |
365 | 365 | |
366 | 366 | /** |
@@ -368,13 +368,13 @@ discard block |
||
368 | 368 | * @since 1.6.0 |
369 | 369 | * @return void |
370 | 370 | */ |
371 | - public function setup_sensei_message_post_type () { |
|
371 | + public function setup_sensei_message_post_type() { |
|
372 | 372 | |
373 | 373 | |
374 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
374 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
375 | 375 | |
376 | 376 | $args = array( |
377 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
377 | + 'labels' => $this->create_post_type_labels($this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu']), |
|
378 | 378 | 'public' => true, |
379 | 379 | 'publicly_queryable' => true, |
380 | 380 | 'show_ui' => true, |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | 'query_var' => true, |
384 | 384 | 'exclude_from_search' => true, |
385 | 385 | 'rewrite' => array( |
386 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
386 | + 'slug' => esc_attr(apply_filters('sensei_messages_slug', _x('messages', 'post type single slug', 'woothemes-sensei'))), |
|
387 | 387 | 'with_front' => false, |
388 | 388 | 'feeds' => false, |
389 | 389 | 'pages' => true |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | 'has_archive' => true, |
394 | 394 | 'hierarchical' => false, |
395 | 395 | 'menu_position' => 50, |
396 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
396 | + 'supports' => array('title', 'editor', 'comments'), |
|
397 | 397 | ); |
398 | 398 | |
399 | 399 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @since 1.9.0 |
403 | 403 | * @param array $args |
404 | 404 | */ |
405 | - register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
|
405 | + register_post_type('sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args)); |
|
406 | 406 | } |
407 | 407 | } // End setup_sensei_message_post_type() |
408 | 408 | |
@@ -411,20 +411,20 @@ discard block |
||
411 | 411 | * @since 1.1.0 |
412 | 412 | * @return void |
413 | 413 | */ |
414 | - public function setup_course_category_taxonomy () { |
|
414 | + public function setup_course_category_taxonomy() { |
|
415 | 415 | // "Course Categories" Custom Taxonomy |
416 | 416 | $labels = array( |
417 | - 'name' => _x( 'Course Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
418 | - 'singular_name' => _x( 'Course Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
419 | - 'search_items' => __( 'Search Course Categories', 'woothemes-sensei' ), |
|
420 | - 'all_items' => __( 'All Course Categories', 'woothemes-sensei' ), |
|
421 | - 'parent_item' => __( 'Parent Course Category', 'woothemes-sensei' ), |
|
422 | - 'parent_item_colon' => __( 'Parent Course Category:', 'woothemes-sensei' ), |
|
423 | - 'edit_item' => __( 'Edit Course Category', 'woothemes-sensei' ), |
|
424 | - 'update_item' => __( 'Update Course Category', 'woothemes-sensei' ), |
|
425 | - 'add_new_item' => __( 'Add New Course Category', 'woothemes-sensei' ), |
|
426 | - 'new_item_name' => __( 'New Course Category Name', 'woothemes-sensei' ), |
|
427 | - 'menu_name' => __( 'Course Categories', 'woothemes-sensei' ), |
|
417 | + 'name' => _x('Course Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
418 | + 'singular_name' => _x('Course Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
419 | + 'search_items' => __('Search Course Categories', 'woothemes-sensei'), |
|
420 | + 'all_items' => __('All Course Categories', 'woothemes-sensei'), |
|
421 | + 'parent_item' => __('Parent Course Category', 'woothemes-sensei'), |
|
422 | + 'parent_item_colon' => __('Parent Course Category:', 'woothemes-sensei'), |
|
423 | + 'edit_item' => __('Edit Course Category', 'woothemes-sensei'), |
|
424 | + 'update_item' => __('Update Course Category', 'woothemes-sensei'), |
|
425 | + 'add_new_item' => __('Add New Course Category', 'woothemes-sensei'), |
|
426 | + 'new_item_name' => __('New Course Category Name', 'woothemes-sensei'), |
|
427 | + 'menu_name' => __('Course Categories', 'woothemes-sensei'), |
|
428 | 428 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
429 | 429 | ); |
430 | 430 | |
@@ -439,10 +439,10 @@ discard block |
||
439 | 439 | 'edit_terms' => 'edit_courses', |
440 | 440 | 'delete_terms' => 'manage_categories', |
441 | 441 | 'assign_terms' => 'edit_courses',), |
442 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
442 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_course_category_slug', _x('course-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
443 | 443 | ); |
444 | 444 | |
445 | - register_taxonomy( 'course-category', array( 'course' ), $args ); |
|
445 | + register_taxonomy('course-category', array('course'), $args); |
|
446 | 446 | |
447 | 447 | } // End setup_course_category_taxonomy() |
448 | 448 | |
@@ -451,20 +451,20 @@ discard block |
||
451 | 451 | * @since 1.0.0 |
452 | 452 | * @return void |
453 | 453 | */ |
454 | - public function setup_quiz_type_taxonomy () { |
|
454 | + public function setup_quiz_type_taxonomy() { |
|
455 | 455 | // "Quiz Types" Custom Taxonomy |
456 | 456 | $labels = array( |
457 | - 'name' => _x( 'Quiz Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
458 | - 'singular_name' => _x( 'Quiz Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
459 | - 'search_items' => __( 'Search Quiz Types', 'woothemes-sensei' ), |
|
460 | - 'all_items' => __( 'All Quiz Types', 'woothemes-sensei' ), |
|
461 | - 'parent_item' => __( 'Parent Quiz Type', 'woothemes-sensei' ), |
|
462 | - 'parent_item_colon' => __( 'Parent Quiz Type:', 'woothemes-sensei' ), |
|
463 | - 'edit_item' => __( 'Edit Quiz Type', 'woothemes-sensei' ), |
|
464 | - 'update_item' => __( 'Update Quiz Type', 'woothemes-sensei' ), |
|
465 | - 'add_new_item' => __( 'Add New Quiz Type', 'woothemes-sensei' ), |
|
466 | - 'new_item_name' => __( 'New Quiz Type Name', 'woothemes-sensei' ), |
|
467 | - 'menu_name' => __( 'Quiz Types', 'woothemes-sensei' ), |
|
457 | + 'name' => _x('Quiz Types', 'taxonomy general name', 'woothemes-sensei'), |
|
458 | + 'singular_name' => _x('Quiz Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
459 | + 'search_items' => __('Search Quiz Types', 'woothemes-sensei'), |
|
460 | + 'all_items' => __('All Quiz Types', 'woothemes-sensei'), |
|
461 | + 'parent_item' => __('Parent Quiz Type', 'woothemes-sensei'), |
|
462 | + 'parent_item_colon' => __('Parent Quiz Type:', 'woothemes-sensei'), |
|
463 | + 'edit_item' => __('Edit Quiz Type', 'woothemes-sensei'), |
|
464 | + 'update_item' => __('Update Quiz Type', 'woothemes-sensei'), |
|
465 | + 'add_new_item' => __('Add New Quiz Type', 'woothemes-sensei'), |
|
466 | + 'new_item_name' => __('New Quiz Type Name', 'woothemes-sensei'), |
|
467 | + 'menu_name' => __('Quiz Types', 'woothemes-sensei'), |
|
468 | 468 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
469 | 469 | ); |
470 | 470 | |
@@ -475,10 +475,10 @@ discard block |
||
475 | 475 | 'query_var' => true, |
476 | 476 | 'show_in_nav_menus' => false, |
477 | 477 | 'public' => false, |
478 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
478 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_quiz_type_slug', _x('quiz-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
479 | 479 | ); |
480 | 480 | |
481 | - register_taxonomy( 'quiz-type', array( 'quiz' ), $args ); |
|
481 | + register_taxonomy('quiz-type', array('quiz'), $args); |
|
482 | 482 | } // End setup_quiz_type_taxonomy() |
483 | 483 | |
484 | 484 | /** |
@@ -486,20 +486,20 @@ discard block |
||
486 | 486 | * @since 1.3.0 |
487 | 487 | * @return void |
488 | 488 | */ |
489 | - public function setup_question_type_taxonomy () { |
|
489 | + public function setup_question_type_taxonomy() { |
|
490 | 490 | // "Question Types" Custom Taxonomy |
491 | 491 | $labels = array( |
492 | - 'name' => _x( 'Question Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
493 | - 'singular_name' => _x( 'Question Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
494 | - 'search_items' => __( 'Search Question Types', 'woothemes-sensei' ), |
|
495 | - 'all_items' => __( 'All Question Types', 'woothemes-sensei' ), |
|
496 | - 'parent_item' => __( 'Parent Question Type', 'woothemes-sensei' ), |
|
497 | - 'parent_item_colon' => __( 'Parent Question Type:', 'woothemes-sensei' ), |
|
498 | - 'edit_item' => __( 'Edit Question Type', 'woothemes-sensei' ), |
|
499 | - 'update_item' => __( 'Update Question Type', 'woothemes-sensei' ), |
|
500 | - 'add_new_item' => __( 'Add New Question Type', 'woothemes-sensei' ), |
|
501 | - 'new_item_name' => __( 'New Question Type Name', 'woothemes-sensei' ), |
|
502 | - 'menu_name' => __( 'Question Types', 'woothemes-sensei' ), |
|
492 | + 'name' => _x('Question Types', 'taxonomy general name', 'woothemes-sensei'), |
|
493 | + 'singular_name' => _x('Question Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
494 | + 'search_items' => __('Search Question Types', 'woothemes-sensei'), |
|
495 | + 'all_items' => __('All Question Types', 'woothemes-sensei'), |
|
496 | + 'parent_item' => __('Parent Question Type', 'woothemes-sensei'), |
|
497 | + 'parent_item_colon' => __('Parent Question Type:', 'woothemes-sensei'), |
|
498 | + 'edit_item' => __('Edit Question Type', 'woothemes-sensei'), |
|
499 | + 'update_item' => __('Update Question Type', 'woothemes-sensei'), |
|
500 | + 'add_new_item' => __('Add New Question Type', 'woothemes-sensei'), |
|
501 | + 'new_item_name' => __('New Question Type Name', 'woothemes-sensei'), |
|
502 | + 'menu_name' => __('Question Types', 'woothemes-sensei'), |
|
503 | 503 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
504 | 504 | ); |
505 | 505 | |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | 'query_var' => false, |
512 | 512 | 'show_in_nav_menus' => false, |
513 | 513 | 'show_admin_column' => true, |
514 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_type_slug', _x( 'question-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
514 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_type_slug', _x('question-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
515 | 515 | ); |
516 | 516 | |
517 | - register_taxonomy( 'question-type', array( 'question' ), $args ); |
|
517 | + register_taxonomy('question-type', array('question'), $args); |
|
518 | 518 | } // End setup_question_type_taxonomy() |
519 | 519 | |
520 | 520 | /** |
@@ -522,20 +522,20 @@ discard block |
||
522 | 522 | * @since 1.3.0 |
523 | 523 | * @return void |
524 | 524 | */ |
525 | - public function setup_question_category_taxonomy () { |
|
525 | + public function setup_question_category_taxonomy() { |
|
526 | 526 | // "Question Categories" Custom Taxonomy |
527 | 527 | $labels = array( |
528 | - 'name' => _x( 'Question Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
529 | - 'singular_name' => _x( 'Question Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
530 | - 'search_items' => __( 'Search Question Categories', 'woothemes-sensei' ), |
|
531 | - 'all_items' => __( 'All Question Categories', 'woothemes-sensei' ), |
|
532 | - 'parent_item' => __( 'Parent Question Category', 'woothemes-sensei' ), |
|
533 | - 'parent_item_colon' => __( 'Parent Question Category:', 'woothemes-sensei' ), |
|
534 | - 'edit_item' => __( 'Edit Question Category', 'woothemes-sensei' ), |
|
535 | - 'update_item' => __( 'Update Question Category', 'woothemes-sensei' ), |
|
536 | - 'add_new_item' => __( 'Add New Question Category', 'woothemes-sensei' ), |
|
537 | - 'new_item_name' => __( 'New Question Category Name', 'woothemes-sensei' ), |
|
538 | - 'menu_name' => __( 'Categories', 'woothemes-sensei' ), |
|
528 | + 'name' => _x('Question Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
529 | + 'singular_name' => _x('Question Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
530 | + 'search_items' => __('Search Question Categories', 'woothemes-sensei'), |
|
531 | + 'all_items' => __('All Question Categories', 'woothemes-sensei'), |
|
532 | + 'parent_item' => __('Parent Question Category', 'woothemes-sensei'), |
|
533 | + 'parent_item_colon' => __('Parent Question Category:', 'woothemes-sensei'), |
|
534 | + 'edit_item' => __('Edit Question Category', 'woothemes-sensei'), |
|
535 | + 'update_item' => __('Update Question Category', 'woothemes-sensei'), |
|
536 | + 'add_new_item' => __('Add New Question Category', 'woothemes-sensei'), |
|
537 | + 'new_item_name' => __('New Question Category Name', 'woothemes-sensei'), |
|
538 | + 'menu_name' => __('Categories', 'woothemes-sensei'), |
|
539 | 539 | ); |
540 | 540 | |
541 | 541 | $args = array( |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | 'edit_terms' => 'edit_questions', |
552 | 552 | 'delete_terms' => 'manage_categories', |
553 | 553 | 'assign_terms' => 'edit_questions',), |
554 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
554 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_category_slug', _x('question-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
555 | 555 | ); |
556 | 556 | |
557 | - register_taxonomy( 'question-category', array( 'question' ), $args ); |
|
557 | + register_taxonomy('question-category', array('question'), $args); |
|
558 | 558 | } // End setup_question_type_taxonomy() |
559 | 559 | |
560 | 560 | /** |
@@ -562,20 +562,20 @@ discard block |
||
562 | 562 | * @since 1.5.0 |
563 | 563 | * @return void |
564 | 564 | */ |
565 | - public function setup_lesson_tag_taxonomy () { |
|
565 | + public function setup_lesson_tag_taxonomy() { |
|
566 | 566 | // "Lesson Tags" Custom Taxonomy |
567 | 567 | $labels = array( |
568 | - 'name' => _x( 'Lesson Tags', 'taxonomy general name', 'woothemes-sensei' ), |
|
569 | - 'singular_name' => _x( 'Lesson Tag', 'taxonomy singular name', 'woothemes-sensei' ), |
|
570 | - 'search_items' => __( 'Search Lesson Tags', 'woothemes-sensei' ), |
|
571 | - 'all_items' => __( 'All Lesson Tags', 'woothemes-sensei' ), |
|
572 | - 'parent_item' => __( 'Parent Tag', 'woothemes-sensei' ), |
|
573 | - 'parent_item_colon' => __( 'Parent Tag:', 'woothemes-sensei' ), |
|
574 | - 'edit_item' => __( 'Edit Lesson Tag', 'woothemes-sensei' ), |
|
575 | - 'update_item' => __( 'Update Lesson Tag', 'woothemes-sensei' ), |
|
576 | - 'add_new_item' => __( 'Add New Lesson Tag', 'woothemes-sensei' ), |
|
577 | - 'new_item_name' => __( 'New Tag Name', 'woothemes-sensei' ), |
|
578 | - 'menu_name' => __( 'Lesson Tags', 'woothemes-sensei' ) |
|
568 | + 'name' => _x('Lesson Tags', 'taxonomy general name', 'woothemes-sensei'), |
|
569 | + 'singular_name' => _x('Lesson Tag', 'taxonomy singular name', 'woothemes-sensei'), |
|
570 | + 'search_items' => __('Search Lesson Tags', 'woothemes-sensei'), |
|
571 | + 'all_items' => __('All Lesson Tags', 'woothemes-sensei'), |
|
572 | + 'parent_item' => __('Parent Tag', 'woothemes-sensei'), |
|
573 | + 'parent_item_colon' => __('Parent Tag:', 'woothemes-sensei'), |
|
574 | + 'edit_item' => __('Edit Lesson Tag', 'woothemes-sensei'), |
|
575 | + 'update_item' => __('Update Lesson Tag', 'woothemes-sensei'), |
|
576 | + 'add_new_item' => __('Add New Lesson Tag', 'woothemes-sensei'), |
|
577 | + 'new_item_name' => __('New Tag Name', 'woothemes-sensei'), |
|
578 | + 'menu_name' => __('Lesson Tags', 'woothemes-sensei') |
|
579 | 579 | ); |
580 | 580 | |
581 | 581 | $args = array( |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | 'edit_terms' => 'edit_lessons', |
590 | 590 | 'delete_terms' => 'manage_categories', |
591 | 591 | 'assign_terms' => 'edit_lessons',), |
592 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
592 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_lesson_tag_slug', _x('lesson-tag', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
593 | 593 | ); |
594 | 594 | |
595 | - register_taxonomy( 'lesson-tag', array( 'lesson' ), $args ); |
|
595 | + register_taxonomy('lesson-tag', array('lesson'), $args); |
|
596 | 596 | } // End setup_lesson_tag_taxonomy() |
597 | 597 | |
598 | 598 | /** |
@@ -600,15 +600,15 @@ discard block |
||
600 | 600 | * @since 1.0.0 |
601 | 601 | * @return void |
602 | 602 | */ |
603 | - private function setup_post_type_labels_base () { |
|
604 | - $this->labels = array( 'course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array() ); |
|
603 | + private function setup_post_type_labels_base() { |
|
604 | + $this->labels = array('course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array()); |
|
605 | 605 | |
606 | - $this->labels['course'] = array( 'singular' => __( 'Course', 'woothemes-sensei' ), 'plural' => __( 'Courses', 'woothemes-sensei' ), 'menu' => __( 'Courses', 'woothemes-sensei' ) ); |
|
607 | - $this->labels['lesson'] = array( 'singular' => __( 'Lesson', 'woothemes-sensei' ), 'plural' => __( 'Lessons', 'woothemes-sensei' ), 'menu' => __( 'Lessons', 'woothemes-sensei' ) ); |
|
608 | - $this->labels['quiz'] = array( 'singular' => __( 'Quiz', 'woothemes-sensei' ), 'plural' => __( 'Quizzes', 'woothemes-sensei' ), 'menu' => __( 'Quizzes', 'woothemes-sensei' ) ); |
|
609 | - $this->labels['question'] = array( 'singular' => __( 'Question', 'woothemes-sensei' ), 'plural' => __( 'Questions', 'woothemes-sensei' ), 'menu' => __( 'Questions', 'woothemes-sensei' ) ); |
|
610 | - $this->labels['multiple_question'] = array( 'singular' => __( 'Multiple Question', 'woothemes-sensei' ), 'plural' => __( 'Multiple Questions', 'woothemes-sensei' ), 'menu' => __( 'Multiple Questions', 'woothemes-sensei' ) ); |
|
611 | - $this->labels['sensei_message'] = array( 'singular' => __( 'Message', 'woothemes-sensei' ), 'plural' => __( 'Messages', 'woothemes-sensei' ), 'menu' => __( 'Messages', 'woothemes-sensei' ) ); |
|
606 | + $this->labels['course'] = array('singular' => __('Course', 'woothemes-sensei'), 'plural' => __('Courses', 'woothemes-sensei'), 'menu' => __('Courses', 'woothemes-sensei')); |
|
607 | + $this->labels['lesson'] = array('singular' => __('Lesson', 'woothemes-sensei'), 'plural' => __('Lessons', 'woothemes-sensei'), 'menu' => __('Lessons', 'woothemes-sensei')); |
|
608 | + $this->labels['quiz'] = array('singular' => __('Quiz', 'woothemes-sensei'), 'plural' => __('Quizzes', 'woothemes-sensei'), 'menu' => __('Quizzes', 'woothemes-sensei')); |
|
609 | + $this->labels['question'] = array('singular' => __('Question', 'woothemes-sensei'), 'plural' => __('Questions', 'woothemes-sensei'), 'menu' => __('Questions', 'woothemes-sensei')); |
|
610 | + $this->labels['multiple_question'] = array('singular' => __('Multiple Question', 'woothemes-sensei'), 'plural' => __('Multiple Questions', 'woothemes-sensei'), 'menu' => __('Multiple Questions', 'woothemes-sensei')); |
|
611 | + $this->labels['sensei_message'] = array('singular' => __('Message', 'woothemes-sensei'), 'plural' => __('Messages', 'woothemes-sensei'), 'menu' => __('Messages', 'woothemes-sensei')); |
|
612 | 612 | |
613 | 613 | } // End setup_post_type_labels_base() |
614 | 614 | |
@@ -620,21 +620,21 @@ discard block |
||
620 | 620 | * @param string $menu The menu item label |
621 | 621 | * @return array An array of the labels to be used |
622 | 622 | */ |
623 | - private function create_post_type_labels ( $singular, $plural, $menu ) { |
|
623 | + private function create_post_type_labels($singular, $plural, $menu) { |
|
624 | 624 | $labels = array( |
625 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
626 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
627 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
628 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
629 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
630 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
631 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
632 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
633 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
634 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
635 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
625 | + 'name' => sprintf(_x('%s', 'post type general name', 'woothemes-sensei'), $plural), |
|
626 | + 'singular_name' => sprintf(_x('%s', 'post type singular name', 'woothemes-sensei'), $singular), |
|
627 | + 'add_new' => __('Add New', 'woothemes-sensei'), |
|
628 | + 'add_new_item' => sprintf(__('Add New %s', 'woothemes-sensei'), $singular), |
|
629 | + 'edit_item' => sprintf(__('Edit %s', 'woothemes-sensei'), $singular), |
|
630 | + 'new_item' => sprintf(__('New %s', 'woothemes-sensei'), $singular), |
|
631 | + 'all_items' => sprintf(__('All %s', 'woothemes-sensei'), $plural), |
|
632 | + 'view_item' => sprintf(__('View %s', 'woothemes-sensei'), $singular), |
|
633 | + 'search_items' => sprintf(__('Search %s', 'woothemes-sensei'), $plural), |
|
634 | + 'not_found' => sprintf(__('No %s found', 'woothemes-sensei'), mb_strtolower($plural, 'UTF-8')), |
|
635 | + 'not_found_in_trash' => sprintf(__('No %s found in Trash', 'woothemes-sensei'), mb_strtolower($plural, 'UTF-8')), |
|
636 | 636 | 'parent_item_colon' => '', |
637 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
637 | + 'menu_name' => sprintf(__('%s', 'woothemes-sensei'), $menu) |
|
638 | 638 | ); |
639 | 639 | |
640 | 640 | return $labels; |
@@ -646,14 +646,14 @@ discard block |
||
646 | 646 | * @param array $messages The existing array of messages for post types. |
647 | 647 | * @return array The modified array of messages for post types. |
648 | 648 | */ |
649 | - public function setup_post_type_messages ( $messages ) { |
|
649 | + public function setup_post_type_messages($messages) { |
|
650 | 650 | global $post, $post_ID; |
651 | 651 | |
652 | - $messages['course'] = $this->create_post_type_messages( 'course' ); |
|
653 | - $messages['lesson'] = $this->create_post_type_messages( 'lesson' ); |
|
654 | - $messages['quiz'] = $this->create_post_type_messages( 'quiz' ); |
|
655 | - $messages['question'] = $this->create_post_type_messages( 'question' ); |
|
656 | - $messages['multiple_question'] = $this->create_post_type_messages( 'multiple_question' ); |
|
652 | + $messages['course'] = $this->create_post_type_messages('course'); |
|
653 | + $messages['lesson'] = $this->create_post_type_messages('lesson'); |
|
654 | + $messages['quiz'] = $this->create_post_type_messages('quiz'); |
|
655 | + $messages['question'] = $this->create_post_type_messages('question'); |
|
656 | + $messages['multiple_question'] = $this->create_post_type_messages('multiple_question'); |
|
657 | 657 | |
658 | 658 | return $messages; |
659 | 659 | } // End setup_post_type_messages() |
@@ -664,23 +664,23 @@ discard block |
||
664 | 664 | * @param string $post_type The post type for which to create messages. |
665 | 665 | * @return array An array of messages (empty array if the post type isn't one we're looking to work with). |
666 | 666 | */ |
667 | - private function create_post_type_messages ( $post_type ) { |
|
667 | + private function create_post_type_messages($post_type) { |
|
668 | 668 | global $post, $post_ID; |
669 | 669 | |
670 | - if ( ! isset( $this->labels[$post_type] ) ) { return array(); } |
|
670 | + if ( ! isset($this->labels[$post_type])) { return array(); } |
|
671 | 671 | |
672 | 672 | $messages = array( |
673 | 673 | 0 => '', |
674 | - 1 => sprintf( __( '%1$s updated. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
675 | - 2 => __( 'Custom field updated.' , 'woothemes-sensei' ), |
|
676 | - 3 => __( 'Custom field deleted.' , 'woothemes-sensei' ), |
|
677 | - 4 => sprintf( __( '%1$s updated.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
678 | - 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
679 | - 6 => sprintf( __( '%1$s published. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
680 | - 7 => sprintf( __( '%1$s saved.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
681 | - 8 => sprintf( __( '%1$s submitted. %2$sPreview %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ), |
|
682 | - 9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<strong>' . date_i18n( __( 'M j, Y @ G:i' , 'woothemes-sensei' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
683 | - 10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
674 | + 1 => sprintf(__('%1$s updated. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
675 | + 2 => __('Custom field updated.', 'woothemes-sensei'), |
|
676 | + 3 => __('Custom field deleted.', 'woothemes-sensei'), |
|
677 | + 4 => sprintf(__('%1$s updated.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
678 | + 5 => isset($_GET['revision']) ? sprintf(__('%1$s restored to revision from %2$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
679 | + 6 => sprintf(__('%1$s published. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
680 | + 7 => sprintf(__('%1$s saved.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
681 | + 8 => sprintf(__('%1$s submitted. %2$sPreview %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', '</a>'), |
|
682 | + 9 => sprintf(__('%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<strong>'.date_i18n(__('M j, Y @ G:i', 'woothemes-sensei'), strtotime($post->post_date)).'</strong>', '<a target="_blank" href="'.esc_url(get_permalink($post_ID)).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
683 | + 10 => sprintf(__('%1$s draft updated. %2$sPreview %3$s%4$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
684 | 684 | ); |
685 | 685 | |
686 | 686 | return $messages; |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | * @param string $title |
694 | 694 | * @return string $title |
695 | 695 | */ |
696 | - public function enter_title_here ( $title ) { |
|
697 | - if ( get_post_type() == 'course' ) { |
|
698 | - $title = __( 'Enter a title for this course here', 'woothemes-sensei' ); |
|
699 | - } elseif ( get_post_type() == 'lesson' ) { |
|
700 | - $title = __( 'Enter a title for this lesson here', 'woothemes-sensei' ); |
|
696 | + public function enter_title_here($title) { |
|
697 | + if (get_post_type() == 'course') { |
|
698 | + $title = __('Enter a title for this course here', 'woothemes-sensei'); |
|
699 | + } elseif (get_post_type() == 'lesson') { |
|
700 | + $title = __('Enter a title for this lesson here', 'woothemes-sensei'); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | return $title; |
@@ -711,60 +711,60 @@ discard block |
||
711 | 711 | * @param array $post_types |
712 | 712 | * @return void |
713 | 713 | */ |
714 | - public function set_role_cap_defaults( $post_types = array() ) { |
|
714 | + public function set_role_cap_defaults($post_types = array()) { |
|
715 | 715 | |
716 | - foreach ( $post_types as $post_type_item => $post_type_name ) { |
|
716 | + foreach ($post_types as $post_type_item => $post_type_name) { |
|
717 | 717 | // Super Admin |
718 | - $this->role_caps[] = array( 'administrator' => array( 'edit_' . $post_type_item, |
|
719 | - 'read_' . $post_type_item, |
|
720 | - 'delete_' . $post_type_item, |
|
721 | - 'create_' . $post_type_item . 's', |
|
722 | - 'edit_' . $post_type_item . 's', |
|
723 | - 'edit_others_' . $post_type_item . 's', |
|
724 | - 'publish_' . $post_type_item . 's', |
|
725 | - 'read_private_' . $post_type_item . 's', |
|
718 | + $this->role_caps[] = array('administrator' => array('edit_'.$post_type_item, |
|
719 | + 'read_'.$post_type_item, |
|
720 | + 'delete_'.$post_type_item, |
|
721 | + 'create_'.$post_type_item.'s', |
|
722 | + 'edit_'.$post_type_item.'s', |
|
723 | + 'edit_others_'.$post_type_item.'s', |
|
724 | + 'publish_'.$post_type_item.'s', |
|
725 | + 'read_private_'.$post_type_item.'s', |
|
726 | 726 | 'read', |
727 | - 'delete_' . $post_type_item . 's', |
|
728 | - 'delete_private_' . $post_type_item . 's', |
|
729 | - 'delete_published_' . $post_type_item . 's', |
|
730 | - 'delete_others_' . $post_type_item . 's', |
|
731 | - 'edit_private_' . $post_type_item . 's', |
|
732 | - 'edit_published_' . $post_type_item . 's', |
|
727 | + 'delete_'.$post_type_item.'s', |
|
728 | + 'delete_private_'.$post_type_item.'s', |
|
729 | + 'delete_published_'.$post_type_item.'s', |
|
730 | + 'delete_others_'.$post_type_item.'s', |
|
731 | + 'edit_private_'.$post_type_item.'s', |
|
732 | + 'edit_published_'.$post_type_item.'s', |
|
733 | 733 | 'manage_sensei', |
734 | - 'manage_sensei_grades' ), |
|
735 | - 'editor' => array( 'edit_' . $post_type_item, |
|
736 | - 'read_' . $post_type_item, |
|
737 | - 'delete_' . $post_type_item, |
|
738 | - 'create_' . $post_type_item . 's', |
|
739 | - 'edit_' . $post_type_item . 's', |
|
740 | - 'edit_others_' . $post_type_item . 's', |
|
741 | - 'publish_' . $post_type_item . 's', |
|
742 | - 'read_private_' . $post_type_item . 's', |
|
734 | + 'manage_sensei_grades'), |
|
735 | + 'editor' => array('edit_'.$post_type_item, |
|
736 | + 'read_'.$post_type_item, |
|
737 | + 'delete_'.$post_type_item, |
|
738 | + 'create_'.$post_type_item.'s', |
|
739 | + 'edit_'.$post_type_item.'s', |
|
740 | + 'edit_others_'.$post_type_item.'s', |
|
741 | + 'publish_'.$post_type_item.'s', |
|
742 | + 'read_private_'.$post_type_item.'s', |
|
743 | 743 | 'read', |
744 | - 'delete_' . $post_type_item . 's', |
|
745 | - 'delete_private_' . $post_type_item . 's', |
|
746 | - 'delete_published_' . $post_type_item . 's', |
|
747 | - 'delete_others_' . $post_type_item . 's', |
|
748 | - 'edit_private_' . $post_type_item . 's', |
|
749 | - 'edit_published_' . $post_type_item . 's' ), |
|
750 | - 'author' => array( 'edit_' . $post_type_item, |
|
751 | - 'read_' . $post_type_item, |
|
752 | - 'delete_' . $post_type_item, |
|
753 | - 'create_' . $post_type_item . 's', |
|
754 | - 'edit_' . $post_type_item . 's', |
|
755 | - 'publish_' . $post_type_item . 's', |
|
744 | + 'delete_'.$post_type_item.'s', |
|
745 | + 'delete_private_'.$post_type_item.'s', |
|
746 | + 'delete_published_'.$post_type_item.'s', |
|
747 | + 'delete_others_'.$post_type_item.'s', |
|
748 | + 'edit_private_'.$post_type_item.'s', |
|
749 | + 'edit_published_'.$post_type_item.'s'), |
|
750 | + 'author' => array('edit_'.$post_type_item, |
|
751 | + 'read_'.$post_type_item, |
|
752 | + 'delete_'.$post_type_item, |
|
753 | + 'create_'.$post_type_item.'s', |
|
754 | + 'edit_'.$post_type_item.'s', |
|
755 | + 'publish_'.$post_type_item.'s', |
|
756 | 756 | 'read', |
757 | - 'delete_' . $post_type_item . 's', |
|
758 | - 'delete_published_' . $post_type_item . 's', |
|
759 | - 'edit_published_' . $post_type_item . 's' ), |
|
760 | - 'contributor' => array( 'edit_' . $post_type_item, |
|
761 | - 'read_' . $post_type_item, |
|
762 | - 'delete_' . $post_type_item, |
|
763 | - 'create_' . $post_type_item . 's', |
|
764 | - 'edit_' . $post_type_item . 's', |
|
757 | + 'delete_'.$post_type_item.'s', |
|
758 | + 'delete_published_'.$post_type_item.'s', |
|
759 | + 'edit_published_'.$post_type_item.'s'), |
|
760 | + 'contributor' => array('edit_'.$post_type_item, |
|
761 | + 'read_'.$post_type_item, |
|
762 | + 'delete_'.$post_type_item, |
|
763 | + 'create_'.$post_type_item.'s', |
|
764 | + 'edit_'.$post_type_item.'s', |
|
765 | 765 | 'read', |
766 | - 'delete_' . $post_type_item . 's' ), |
|
767 | - 'subscriber' => array( 'read' ) |
|
766 | + 'delete_'.$post_type_item.'s'), |
|
767 | + 'subscriber' => array('read') |
|
768 | 768 | |
769 | 769 | ); |
770 | 770 | } // End For Loop |
@@ -778,16 +778,16 @@ discard block |
||
778 | 778 | * @param WP_Admin_Bar $bar |
779 | 779 | * @return void |
780 | 780 | */ |
781 | - public function quiz_admin_bar_menu( $bar ) { |
|
782 | - if ( is_single() && 'quiz' == get_queried_object()->post_type ) { |
|
783 | - $lesson_id = get_post_meta( get_queried_object()->ID, '_quiz_lesson', true ); |
|
784 | - if ( $lesson_id ) { |
|
781 | + public function quiz_admin_bar_menu($bar) { |
|
782 | + if (is_single() && 'quiz' == get_queried_object()->post_type) { |
|
783 | + $lesson_id = get_post_meta(get_queried_object()->ID, '_quiz_lesson', true); |
|
784 | + if ($lesson_id) { |
|
785 | 785 | $object_type = get_post_type_object('quiz'); |
786 | - $bar->add_menu( array( |
|
786 | + $bar->add_menu(array( |
|
787 | 787 | 'id' => 'edit', |
788 | 788 | 'title' => $object_type->labels->edit_item, |
789 | - 'href' => get_edit_post_link( $lesson_id ), |
|
790 | - ) ); |
|
789 | + 'href' => get_edit_post_link($lesson_id), |
|
790 | + )); |
|
791 | 791 | } |
792 | 792 | } |
793 | 793 | } |
@@ -799,4 +799,4 @@ discard block |
||
799 | 799 | * for backward compatibility |
800 | 800 | * @since 1.9.0 |
801 | 801 | */ |
802 | -class WooThemes_Sensei_PostTypes extends Sensei_PostTypes{} |
|
802 | +class WooThemes_Sensei_PostTypes extends Sensei_PostTypes {} |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
7 | 7 | |
8 | 8 | if ( class_exists( 'Teacher_New_Course_Assignment' ) ){ |
9 | - return; |
|
9 | + return; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -40,40 +40,40 @@ discard block |
||
40 | 40 | */ |
41 | 41 | function __construct() { |
42 | 42 | |
43 | - $this->template = 'teacher-new-course-assignment'; |
|
43 | + $this->template = 'teacher-new-course-assignment'; |
|
44 | 44 | $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have been assigned to a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
45 | 45 | $this->heading = apply_filters( 'sensei_email_heading', __( 'Course assigned to you', 'woothemes-sensei' ), $this->template ); |
46 | - return; |
|
46 | + return; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * trigger function. |
51 | 51 | * |
52 | 52 | * @access public |
53 | - * @param $teacher_id |
|
54 | - * @param $course_id |
|
53 | + * @param $teacher_id |
|
54 | + * @param $course_id |
|
55 | 55 | * @return void |
56 | 56 | */ |
57 | 57 | function trigger( $teacher_id = 0, $course_id = 0 ) { |
58 | 58 | global $sensei_email_data; |
59 | 59 | |
60 | 60 | $this->teacher = new WP_User( $teacher_id ); |
61 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
62 | - $this->subject = __( 'New course assigned to you', 'woothemes-sensei' ); |
|
61 | + $this->recipient = stripslashes( $this->teacher->user_email ); |
|
62 | + $this->subject = __( 'New course assigned to you', 'woothemes-sensei' ); |
|
63 | 63 | |
64 | - //course edit link |
|
65 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
64 | + //course edit link |
|
65 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
66 | 66 | |
67 | - // Course name |
|
68 | - $course = get_post( $course_id); |
|
67 | + // Course name |
|
68 | + $course = get_post( $course_id); |
|
69 | 69 | // Construct data array |
70 | 70 | $sensei_email_data = apply_filters( 'sensei_email_data', array( |
71 | 71 | 'template' => $this->template, |
72 | 72 | 'heading' => $this->heading, |
73 | 73 | 'teacher_id' => $teacher_id, |
74 | 74 | 'course_id' => $course_id, |
75 | - 'course_name' => $course->post_title, |
|
76 | - 'course_edit_link' => $course_edit_link, |
|
75 | + 'course_name' => $course->post_title, |
|
76 | + 'course_edit_link' => $course_edit_link, |
|
77 | 77 | ), $this->template ); |
78 | 78 | |
79 | 79 | // Send mail |
@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | * This email will be sent to a teacher when a course is assigned to them. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
6 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
7 | 7 | |
8 | -if ( class_exists( 'Teacher_New_Course_Assignment' ) ){ |
|
8 | +if (class_exists('Teacher_New_Course_Assignment')) { |
|
9 | 9 | return; |
10 | 10 | } |
11 | 11 | |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | function __construct() { |
42 | 42 | |
43 | 43 | $this->template = 'teacher-new-course-assignment'; |
44 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have been assigned to a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
45 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Course assigned to you', 'woothemes-sensei' ), $this->template ); |
|
44 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have been assigned to a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
45 | + $this->heading = apply_filters('sensei_email_heading', __('Course assigned to you', 'woothemes-sensei'), $this->template); |
|
46 | 46 | return; |
47 | 47 | } |
48 | 48 | |
@@ -54,29 +54,29 @@ discard block |
||
54 | 54 | * @param $course_id |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - function trigger( $teacher_id = 0, $course_id = 0 ) { |
|
57 | + function trigger($teacher_id = 0, $course_id = 0) { |
|
58 | 58 | global $sensei_email_data; |
59 | 59 | |
60 | - $this->teacher = new WP_User( $teacher_id ); |
|
61 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
62 | - $this->subject = __( 'New course assigned to you', 'woothemes-sensei' ); |
|
60 | + $this->teacher = new WP_User($teacher_id); |
|
61 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
62 | + $this->subject = __('New course assigned to you', 'woothemes-sensei'); |
|
63 | 63 | |
64 | 64 | //course edit link |
65 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
65 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
66 | 66 | |
67 | 67 | // Course name |
68 | - $course = get_post( $course_id); |
|
68 | + $course = get_post($course_id); |
|
69 | 69 | // Construct data array |
70 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
70 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
71 | 71 | 'template' => $this->template, |
72 | 72 | 'heading' => $this->heading, |
73 | 73 | 'teacher_id' => $teacher_id, |
74 | 74 | 'course_id' => $course_id, |
75 | 75 | 'course_name' => $course->post_title, |
76 | 76 | 'course_edit_link' => $course_edit_link, |
77 | - ), $this->template ); |
|
77 | + ), $this->template); |
|
78 | 78 | |
79 | 79 | // Send mail |
80 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
80 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | \ No newline at end of file |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' ); |
52 | 52 | $this->teacher = new WP_User( $teacher_id ); |
53 | 53 | |
54 | - // Construct data array |
|
54 | + // Construct data array |
|
55 | 55 | $sensei_email_data = apply_filters( 'sensei_email_data', array( |
56 | 56 | 'template' => $this->template, |
57 | 57 | 'heading' => $this->heading, |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $this->recipient = stripslashes( $this->teacher->user_email ); |
66 | 66 | |
67 | 67 | // Send mail |
68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
68 | + Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Lesson' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_Teacher_Completed_Lesson')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Teacher Completed Lesson |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function __construct() { |
33 | 33 | $this->template = 'teacher-completed-lesson'; |
34 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a lesson', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
35 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a lesson', 'woothemes-sensei' ), $this->template ); |
|
34 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your student has completed a lesson', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
35 | + $this->heading = apply_filters('sensei_email_heading', __('Your student has completed a lesson', 'woothemes-sensei'), $this->template); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,31 +41,31 @@ discard block |
||
41 | 41 | * @access public |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - function trigger( $learner_id = 0, $lesson_id = 0 ) { |
|
44 | + function trigger($learner_id = 0, $lesson_id = 0) { |
|
45 | 45 | global $sensei_email_data; |
46 | 46 | |
47 | 47 | // Get learner user object |
48 | - $this->learner = new WP_User( $learner_id ); |
|
48 | + $this->learner = new WP_User($learner_id); |
|
49 | 49 | |
50 | 50 | // Get teacher ID and user object |
51 | - $teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' ); |
|
52 | - $this->teacher = new WP_User( $teacher_id ); |
|
51 | + $teacher_id = get_post_field('post_author', $lesson_id, 'raw'); |
|
52 | + $this->teacher = new WP_User($teacher_id); |
|
53 | 53 | |
54 | 54 | // Construct data array |
55 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
55 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
56 | 56 | 'template' => $this->template, |
57 | 57 | 'heading' => $this->heading, |
58 | 58 | 'teacher_id' => $teacher_id, |
59 | 59 | 'learner_id' => $learner_id, |
60 | 60 | 'learner_name' => $this->learner->display_name, |
61 | 61 | 'lesson_id' => $lesson_id, |
62 | - ), $this->template ); |
|
62 | + ), $this->template); |
|
63 | 63 | |
64 | 64 | // Set recipient (teacher) |
65 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
65 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
66 | 66 | |
67 | 67 | // Send mail |
68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
68 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Sensei Analysis User Profile List Table Class |