@@ -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 Learners Class |
@@ -22,30 +22,30 @@ discard block |
||
22 | 22 | * @since 1.6.0 |
23 | 23 | * @return void |
24 | 24 | */ |
25 | - public function __construct ( $file ) { |
|
26 | - $this->name = __( 'Learner Management', 'woothemes-sensei' );; |
|
25 | + public function __construct($file) { |
|
26 | + $this->name = __('Learner Management', 'woothemes-sensei'); ; |
|
27 | 27 | $this->file = $file; |
28 | 28 | $this->page_slug = 'sensei_learners'; |
29 | 29 | |
30 | 30 | // Admin functions |
31 | - if ( is_admin() ) { |
|
32 | - add_action( 'admin_menu', array( $this, 'learners_admin_menu' ), 30); |
|
33 | - add_action( 'learners_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
34 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
35 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
36 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
31 | + if (is_admin()) { |
|
32 | + add_action('admin_menu', array($this, 'learners_admin_menu'), 30); |
|
33 | + add_action('learners_wrapper_container', array($this, 'wrapper_container')); |
|
34 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
35 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
36 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
37 | 37 | } |
38 | 38 | |
39 | - add_action( 'admin_init', array( $this, 'add_new_learners' ) ); |
|
39 | + add_action('admin_init', array($this, 'add_new_learners')); |
|
40 | 40 | |
41 | - add_action( 'admin_notices', array( $this, 'add_learner_notices' ) ); |
|
41 | + add_action('admin_notices', array($this, 'add_learner_notices')); |
|
42 | 42 | } // End If Statement |
43 | 43 | |
44 | 44 | // Ajax functions |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'wp_ajax_get_redirect_url_learners', array( $this, 'get_redirect_url' ) ); |
|
47 | - add_action( 'wp_ajax_remove_user_from_post', array( $this, 'remove_user_from_post' ) ); |
|
48 | - add_action( 'wp_ajax_sensei_json_search_users', array( $this, 'json_search_users' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('wp_ajax_get_redirect_url_learners', array($this, 'get_redirect_url')); |
|
47 | + add_action('wp_ajax_remove_user_from_post', array($this, 'remove_user_from_post')); |
|
48 | + add_action('wp_ajax_sensei_json_search_users', array($this, 'json_search_users')); |
|
49 | 49 | } |
50 | 50 | } // End __construct() |
51 | 51 | |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | public function learners_admin_menu() { |
59 | 59 | global $menu; |
60 | 60 | |
61 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
62 | - $learners_page = add_submenu_page( 'sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array( $this, 'learners_page' ) ); |
|
61 | + if (current_user_can('manage_sensei_grades')) { |
|
62 | + $learners_page = add_submenu_page('sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array($this, 'learners_page')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | } // End learners_admin_menu() |
@@ -72,25 +72,25 @@ discard block |
||
72 | 72 | * @since 1.6.0 |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function enqueue_scripts () { |
|
75 | + public function enqueue_scripts() { |
|
76 | 76 | |
77 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
77 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
78 | 78 | |
79 | 79 | // Load Learners JS |
80 | - wp_enqueue_script( 'sensei-learners-general', |
|
81 | - Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | - array('jquery','sensei-core-select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
80 | + wp_enqueue_script('sensei-learners-general', |
|
81 | + Sensei()->plugin_url.'assets/js/learners-general'.$suffix.'.js', |
|
82 | + array('jquery', 'sensei-core-select2', 'sensei-chosen-ajax'), Sensei()->version, true); |
|
83 | 83 | |
84 | 84 | $data = array( |
85 | - 'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ), |
|
86 | - 'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ), |
|
87 | - 'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ), |
|
88 | - 'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ), |
|
89 | - 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | - 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
85 | + 'remove_generic_confirm' => __('Are you sure you want to remove this user?', 'woothemes-sensei'), |
|
86 | + 'remove_from_lesson_confirm' => __('Are you sure you want to remove the user from this lesson?', 'woothemes-sensei'), |
|
87 | + 'remove_from_course_confirm' => __('Are you sure you want to remove the user from this course?', 'woothemes-sensei'), |
|
88 | + 'remove_user_from_post_nonce' => wp_create_nonce('remove_user_from_post_nonce'), |
|
89 | + 'search_users_nonce' => wp_create_nonce('search-users'), |
|
90 | + 'selectplaceholder'=> __('Select Learner', 'woothemes-sensei') |
|
91 | 91 | ); |
92 | 92 | |
93 | - wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data ); |
|
93 | + wp_localize_script('sensei-learners-general', 'woo_learners_general_data', $data); |
|
94 | 94 | |
95 | 95 | } // End enqueue_scripts() |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * @since 1.6.0 |
103 | 103 | * @return void |
104 | 104 | */ |
105 | - public function enqueue_styles () { |
|
105 | + public function enqueue_styles() { |
|
106 | 106 | |
107 | - wp_enqueue_style( 'woothemes-sensei-admin' ); |
|
107 | + wp_enqueue_style('woothemes-sensei-admin'); |
|
108 | 108 | |
109 | 109 | } // End enqueue_styles() |
110 | 110 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | public function load_data_table_files() { |
117 | 117 | |
118 | 118 | // Load Learners Classes |
119 | - $classes_to_load = array( 'list-table', |
|
119 | + $classes_to_load = array('list-table', |
|
120 | 120 | 'learners-main', |
121 | 121 | ); |
122 | - foreach ( $classes_to_load as $class_file ) { |
|
123 | - Sensei()->load_class( $class_file ); |
|
122 | + foreach ($classes_to_load as $class_file) { |
|
123 | + Sensei()->load_class($class_file); |
|
124 | 124 | } // End For Loop |
125 | 125 | |
126 | 126 | } // End load_data_table_files() |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | * @param undefined $optional_data optional constructor arguments |
134 | 134 | * @return object class instance object |
135 | 135 | */ |
136 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
136 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
137 | 137 | // Load Analysis data |
138 | - $object_name = 'WooThemes_Sensei_Learners_' . $name; |
|
139 | - if ( is_null($optional_data) ) { |
|
140 | - $sensei_learners_object = new $object_name( $data ); |
|
138 | + $object_name = 'WooThemes_Sensei_Learners_'.$name; |
|
139 | + if (is_null($optional_data)) { |
|
140 | + $sensei_learners_object = new $object_name($data); |
|
141 | 141 | } else { |
142 | - $sensei_learners_object = new $object_name( $data, $optional_data ); |
|
142 | + $sensei_learners_object = new $object_name($data, $optional_data); |
|
143 | 143 | } // End If Statement |
144 | - if ( 'Main' == $name ) { |
|
144 | + if ('Main' == $name) { |
|
145 | 145 | $sensei_learners_object->prepare_items(); |
146 | 146 | } // End If Statement |
147 | 147 | return $sensei_learners_object; |
@@ -158,16 +158,16 @@ discard block |
||
158 | 158 | // Load Learners data |
159 | 159 | $course_id = 0; |
160 | 160 | $lesson_id = 0; |
161 | - if( isset( $_GET['course_id'] ) ) { |
|
162 | - $course_id = intval( $_GET['course_id'] ); |
|
161 | + if (isset($_GET['course_id'])) { |
|
162 | + $course_id = intval($_GET['course_id']); |
|
163 | 163 | } |
164 | - if( isset( $_GET['lesson_id'] ) ) { |
|
165 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
164 | + if (isset($_GET['lesson_id'])) { |
|
165 | + $lesson_id = intval($_GET['lesson_id']); |
|
166 | 166 | } |
167 | - $sensei_learners_main = $this->load_data_object( 'Main', $course_id, $lesson_id ); |
|
167 | + $sensei_learners_main = $this->load_data_object('Main', $course_id, $lesson_id); |
|
168 | 168 | // Wrappers |
169 | - do_action( 'learners_before_container' ); |
|
170 | - do_action( 'learners_wrapper_container', 'top' ); |
|
169 | + do_action('learners_before_container'); |
|
170 | + do_action('learners_wrapper_container', 'top'); |
|
171 | 171 | $this->learners_headers(); |
172 | 172 | ?> |
173 | 173 | <div id="poststuff" class="sensei-learners-wrap"> |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | <?php $sensei_learners_main->display(); ?> |
176 | 176 | </div> |
177 | 177 | <div class="sensei-learners-extra"> |
178 | - <?php do_action( 'sensei_learners_extra' ); ?> |
|
178 | + <?php do_action('sensei_learners_extra'); ?> |
|
179 | 179 | </div> |
180 | 180 | </div> |
181 | 181 | <?php |
182 | - do_action( 'learners_wrapper_container', 'bottom' ); |
|
183 | - do_action( 'learners_after_container' ); |
|
182 | + do_action('learners_wrapper_container', 'bottom'); |
|
183 | + do_action('learners_after_container'); |
|
184 | 184 | } // End learners_default_view() |
185 | 185 | |
186 | 186 | /** |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | * @param array $args |
190 | 190 | * @return void |
191 | 191 | */ |
192 | - public function learners_headers( $args = array( 'nav' => 'default' ) ) { |
|
192 | + public function learners_headers($args = array('nav' => 'default')) { |
|
193 | 193 | |
194 | - $function = 'learners_' . $args['nav'] . '_nav'; |
|
194 | + $function = 'learners_'.$args['nav'].'_nav'; |
|
195 | 195 | $this->$function(); |
196 | 196 | ?> |
197 | - <p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
197 | + <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
198 | 198 | <?php |
199 | - do_action( 'sensei_learners_after_headers' ); |
|
199 | + do_action('sensei_learners_after_headers'); |
|
200 | 200 | |
201 | 201 | } // End learners_headers() |
202 | 202 | |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | * @param $which string |
207 | 207 | * @return void |
208 | 208 | */ |
209 | - public function wrapper_container( $which ) { |
|
210 | - if ( 'top' == $which ) { |
|
209 | + public function wrapper_container($which) { |
|
210 | + if ('top' == $which) { |
|
211 | 211 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php |
212 | - } elseif ( 'bottom' == $which ) { |
|
212 | + } elseif ('bottom' == $which) { |
|
213 | 213 | ?></div><!--/#woothemes-sensei--><?php |
214 | 214 | } // End If Statement |
215 | 215 | } // End wrapper_container() |
@@ -220,18 +220,18 @@ discard block |
||
220 | 220 | * @return void |
221 | 221 | */ |
222 | 222 | public function learners_default_nav() { |
223 | - $title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
224 | - if ( isset( $_GET['course_id'] ) ) { |
|
225 | - $course_id = intval( $_GET['course_id'] ); |
|
226 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) ); |
|
227 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
223 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
224 | + if (isset($_GET['course_id'])) { |
|
225 | + $course_id = intval($_GET['course_id']); |
|
226 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners'), admin_url('admin.php')); |
|
227 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
228 | 228 | } |
229 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
230 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
231 | - $title .= ' <span class="lesson-title">> ' . get_the_title( intval( $lesson_id ) ) . '</span>'; |
|
229 | + if (isset($_GET['lesson_id'])) { |
|
230 | + $lesson_id = intval($_GET['lesson_id']); |
|
231 | + $title .= ' <span class="lesson-title">> '.get_the_title(intval($lesson_id)).'</span>'; |
|
232 | 232 | } |
233 | 233 | ?> |
234 | - <h2><?php echo apply_filters( 'sensei_learners_nav_title', $title ); ?></h2> |
|
234 | + <h2><?php echo apply_filters('sensei_learners_nav_title', $title); ?></h2> |
|
235 | 235 | <?php |
236 | 236 | } // End learners_default_nav() |
237 | 237 | |
@@ -240,22 +240,22 @@ discard block |
||
240 | 240 | // Parse POST data |
241 | 241 | $data = $_POST['data']; |
242 | 242 | $course_data = array(); |
243 | - parse_str( $data, $course_data ); |
|
243 | + parse_str($data, $course_data); |
|
244 | 244 | |
245 | - $course_cat = intval( $course_data['course_cat'] ); |
|
245 | + $course_cat = intval($course_data['course_cat']); |
|
246 | 246 | |
247 | - $redirect_url = apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'course_cat' => $course_cat ), admin_url( 'admin.php' ) ) ); |
|
247 | + $redirect_url = apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'course_cat' => $course_cat), admin_url('admin.php'))); |
|
248 | 248 | |
249 | - echo esc_url_raw( $redirect_url ); |
|
249 | + echo esc_url_raw($redirect_url); |
|
250 | 250 | die(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | public function remove_user_from_post() { |
254 | 254 | |
255 | 255 | // Parse POST data |
256 | - $data = sanitize_text_field( $_POST['data'] ); |
|
256 | + $data = sanitize_text_field($_POST['data']); |
|
257 | 257 | $action_data = array(); |
258 | - parse_str( $data, $action_data ); |
|
258 | + parse_str($data, $action_data); |
|
259 | 259 | |
260 | 260 | // Security checks |
261 | 261 | // ensure the current user may remove users from post |
@@ -263,54 +263,54 @@ discard block |
||
263 | 263 | |
264 | 264 | // check the nonce, valid post |
265 | 265 | $nonce = ''; |
266 | - if ( isset($_POST['remove_user_from_post_nonce']) ) { |
|
267 | - $nonce = esc_html( $_POST['remove_user_from_post_nonce'] ); |
|
266 | + if (isset($_POST['remove_user_from_post_nonce'])) { |
|
267 | + $nonce = esc_html($_POST['remove_user_from_post_nonce']); |
|
268 | 268 | } |
269 | - $post = get_post( intval( $action_data[ 'post_id' ] ) ); |
|
269 | + $post = get_post(intval($action_data['post_id'])); |
|
270 | 270 | |
271 | 271 | // validate the user |
272 | 272 | $may_remove_user = false; |
273 | - if( current_user_can('manage_sensei') |
|
274 | - || $post->post_author == get_current_user_id() ){ |
|
273 | + if (current_user_can('manage_sensei') |
|
274 | + || $post->post_author == get_current_user_id()) { |
|
275 | 275 | |
276 | 276 | $may_remove_user = true; |
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | - if( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' ) |
|
281 | - || ! is_a( $post ,'WP_Post' ) |
|
282 | - || ! $may_remove_user ){ |
|
280 | + if ( ! wp_verify_nonce($nonce, 'remove_user_from_post_nonce') |
|
281 | + || ! is_a($post, 'WP_Post') |
|
282 | + || ! $may_remove_user) { |
|
283 | 283 | |
284 | 284 | die(''); |
285 | 285 | |
286 | 286 | } |
287 | 287 | |
288 | - if( $action_data['user_id'] && $action_data['post_id'] && $action_data['post_type'] ) { |
|
288 | + if ($action_data['user_id'] && $action_data['post_id'] && $action_data['post_type']) { |
|
289 | 289 | |
290 | - $user_id = intval( $action_data['user_id'] ); |
|
291 | - $post_id = intval( $action_data['post_id'] ); |
|
292 | - $post_type = sanitize_text_field( $action_data['post_type'] ); |
|
290 | + $user_id = intval($action_data['user_id']); |
|
291 | + $post_id = intval($action_data['post_id']); |
|
292 | + $post_type = sanitize_text_field($action_data['post_type']); |
|
293 | 293 | |
294 | - $user = get_userdata( $user_id ); |
|
294 | + $user = get_userdata($user_id); |
|
295 | 295 | |
296 | - switch( $post_type ) { |
|
296 | + switch ($post_type) { |
|
297 | 297 | |
298 | 298 | case 'course': |
299 | 299 | |
300 | - $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
300 | + $removed = Sensei_Utils::sensei_remove_user_from_course($post_id, $user_id); |
|
301 | 301 | |
302 | 302 | break; |
303 | 303 | |
304 | 304 | case 'lesson': |
305 | 305 | |
306 | - $removed = Sensei_Utils::sensei_remove_user_from_lesson( $post_id, $user_id ); |
|
306 | + $removed = Sensei_Utils::sensei_remove_user_from_lesson($post_id, $user_id); |
|
307 | 307 | |
308 | 308 | break; |
309 | 309 | |
310 | 310 | } |
311 | 311 | |
312 | - if( $removed ) { |
|
313 | - die( 'removed' ); |
|
312 | + if ($removed) { |
|
313 | + die('removed'); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | } |
@@ -321,109 +321,109 @@ discard block |
||
321 | 321 | public function json_search_users() { |
322 | 322 | |
323 | 323 | |
324 | - check_ajax_referer( 'search-users', 'security' ); |
|
324 | + check_ajax_referer('search-users', 'security'); |
|
325 | 325 | |
326 | - $term = sanitize_text_field( stripslashes( $_GET['term'] ) ); |
|
326 | + $term = sanitize_text_field(stripslashes($_GET['term'])); |
|
327 | 327 | |
328 | - if ( empty( $term ) ) { |
|
328 | + if (empty($term)) { |
|
329 | 329 | die(); |
330 | 330 | } |
331 | 331 | |
332 | - $default = isset( $_GET['default'] ) ? $_GET['default'] : __( 'None', 'woocommerce' ); |
|
332 | + $default = isset($_GET['default']) ? $_GET['default'] : __('None', 'woocommerce'); |
|
333 | 333 | |
334 | - $found_users = array( '' => $default ); |
|
334 | + $found_users = array('' => $default); |
|
335 | 335 | |
336 | - $users_query = new WP_User_Query( apply_filters( 'sensei_json_search_users_query', array( |
|
336 | + $users_query = new WP_User_Query(apply_filters('sensei_json_search_users_query', array( |
|
337 | 337 | 'fields' => 'all', |
338 | 338 | 'orderby' => 'display_name', |
339 | - 'search' => '*' . $term . '*', |
|
340 | - 'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename','user_firstname','user_lastname' ) |
|
341 | - ), $term ) ); |
|
339 | + 'search' => '*'.$term.'*', |
|
340 | + 'search_columns' => array('ID', 'user_login', 'user_email', 'user_nicename', 'user_firstname', 'user_lastname') |
|
341 | + ), $term)); |
|
342 | 342 | |
343 | 343 | $users = $users_query->get_results(); |
344 | 344 | |
345 | - if ( $users ) { |
|
346 | - foreach ( $users as $user ) { |
|
347 | - $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
345 | + if ($users) { |
|
346 | + foreach ($users as $user) { |
|
347 | + $full_name = Sensei_Learner::get_full_name($user->ID); |
|
348 | 348 | |
349 | - if( trim($user->display_name ) == trim( $full_name ) ){ |
|
349 | + if (trim($user->display_name) == trim($full_name)) { |
|
350 | 350 | |
351 | 351 | $name = $full_name; |
352 | 352 | |
353 | - }else{ |
|
353 | + } else { |
|
354 | 354 | |
355 | - $name = $full_name . ' ['. $user->display_name .']'; |
|
355 | + $name = $full_name.' ['.$user->display_name.']'; |
|
356 | 356 | |
357 | 357 | } |
358 | 358 | |
359 | - $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
359 | + $found_users[$user->ID] = $name.' (#'.$user->ID.' – '.sanitize_email($user->user_email).')'; |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | - wp_send_json( $found_users ); |
|
363 | + wp_send_json($found_users); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | public function add_new_learners() { |
367 | 367 | |
368 | 368 | $result = false; |
369 | 369 | |
370 | - if( ! isset( $_POST['add_learner_submit'] ) ) return $result; |
|
370 | + if ( ! isset($_POST['add_learner_submit'])) return $result; |
|
371 | 371 | |
372 | - if ( ! isset( $_POST['add_learner_nonce'] ) || ! wp_verify_nonce( $_POST['add_learner_nonce'], 'add_learner_to_sensei' ) ) return $result; |
|
372 | + if ( ! isset($_POST['add_learner_nonce']) || ! wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) return $result; |
|
373 | 373 | |
374 | - if( ( ! isset( $_POST['add_user_id'] ) || '' == $_POST['add_user_id'] ) || ! isset( $_POST['add_post_type'] ) || ! isset( $_POST['add_course_id'] ) || ! isset( $_POST['add_lesson_id'] ) ) return $result; |
|
374 | + if (( ! isset($_POST['add_user_id']) || '' == $_POST['add_user_id']) || ! isset($_POST['add_post_type']) || ! isset($_POST['add_course_id']) || ! isset($_POST['add_lesson_id'])) return $result; |
|
375 | 375 | |
376 | 376 | $post_type = $_POST['add_post_type']; |
377 | - $user_id = absint( $_POST['add_user_id'] ); |
|
378 | - $course_id = absint( $_POST['add_course_id'] ); |
|
377 | + $user_id = absint($_POST['add_user_id']); |
|
378 | + $course_id = absint($_POST['add_course_id']); |
|
379 | 379 | |
380 | - switch( $post_type ) { |
|
380 | + switch ($post_type) { |
|
381 | 381 | case 'course': |
382 | 382 | |
383 | - $result = Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
383 | + $result = Sensei_Utils::user_start_course($user_id, $course_id); |
|
384 | 384 | |
385 | 385 | // Complete each lesson if course is set to be completed |
386 | - if( isset( $_POST['add_complete_course'] ) && 'yes' == $_POST['add_complete_course'] ) { |
|
386 | + if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) { |
|
387 | 387 | |
388 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
388 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
389 | 389 | |
390 | - foreach( $lesson_ids as $id ) { |
|
391 | - Sensei_Utils::sensei_start_lesson( $id, $user_id, true ); |
|
390 | + foreach ($lesson_ids as $id) { |
|
391 | + Sensei_Utils::sensei_start_lesson($id, $user_id, true); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Updates the Course status and it's meta data |
395 | - Sensei_Utils::user_complete_course( $course_id, $user_id ); |
|
395 | + Sensei_Utils::user_complete_course($course_id, $user_id); |
|
396 | 396 | |
397 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
397 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | break; |
401 | 401 | |
402 | 402 | case 'lesson': |
403 | - $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
403 | + $lesson_id = absint($_POST['add_lesson_id']); |
|
404 | 404 | $complete = false; |
405 | - if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) { |
|
405 | + if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) { |
|
406 | 406 | $complete = true; |
407 | 407 | } |
408 | 408 | |
409 | - $result = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
409 | + $result = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
410 | 410 | |
411 | 411 | // Updates the Course status and it's meta data |
412 | - Sensei_Utils::user_complete_course( $course_id, $user_id ); |
|
412 | + Sensei_Utils::user_complete_course($course_id, $user_id); |
|
413 | 413 | |
414 | 414 | break; |
415 | 415 | } |
416 | 416 | |
417 | 417 | // Set redirect URL after adding user to course/lesson |
418 | - $query_args = array( 'page' => $this->page_slug, 'view' => 'learners' ); |
|
418 | + $query_args = array('page' => $this->page_slug, 'view' => 'learners'); |
|
419 | 419 | |
420 | - if( $result ) { |
|
420 | + if ($result) { |
|
421 | 421 | |
422 | - if( $course_id ) { |
|
422 | + if ($course_id) { |
|
423 | 423 | $query_args['course_id'] = $course_id; |
424 | 424 | } |
425 | 425 | |
426 | - if( $lesson_id ) { |
|
426 | + if ($lesson_id) { |
|
427 | 427 | $query_args['lesson_id'] = $lesson_id; |
428 | 428 | } |
429 | 429 | |
@@ -433,23 +433,23 @@ discard block |
||
433 | 433 | $query_args['message'] = 'error'; |
434 | 434 | } |
435 | 435 | |
436 | - $redirect_url = apply_filters( 'sensei_learners_add_learner_redirect_url', add_query_arg( $query_args, admin_url( 'admin.php' ) ) ); |
|
436 | + $redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php'))); |
|
437 | 437 | |
438 | - wp_safe_redirect( esc_url_raw( $redirect_url ) ); |
|
438 | + wp_safe_redirect(esc_url_raw($redirect_url)); |
|
439 | 439 | exit; |
440 | 440 | } |
441 | 441 | |
442 | 442 | public function add_learner_notices() { |
443 | - if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { |
|
444 | - if( 'success' == $_GET['message'] ) { |
|
443 | + if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { |
|
444 | + if ('success' == $_GET['message']) { |
|
445 | 445 | $msg = array( |
446 | 446 | 'updated', |
447 | - __( 'Learner added successfully!', 'woothemes-sensei' ), |
|
447 | + __('Learner added successfully!', 'woothemes-sensei'), |
|
448 | 448 | ); |
449 | 449 | } else { |
450 | 450 | $msg = array( |
451 | 451 | 'error', |
452 | - __( 'Error adding learner.', 'woothemes-sensei' ), |
|
452 | + __('Error adding learner.', 'woothemes-sensei'), |
|
453 | 453 | ); |
454 | 454 | } |
455 | 455 | ?> |
@@ -472,9 +472,9 @@ discard block |
||
472 | 472 | * |
473 | 473 | * @return string $full_name |
474 | 474 | */ |
475 | - public function get_learner_full_name( $user_id ){ |
|
475 | + public function get_learner_full_name($user_id) { |
|
476 | 476 | |
477 | - return Sensei_Learner::get_full_name( $user_id ); |
|
477 | + return Sensei_Learner::get_full_name($user_id); |
|
478 | 478 | |
479 | 479 | } // end get_learner_full_name |
480 | 480 | |
@@ -485,4 +485,4 @@ discard block |
||
485 | 485 | * @ignore only for backward compatibility |
486 | 486 | * @since 1.9.0 |
487 | 487 | */ |
488 | -class WooThemes_Sensei_Learners extends Sensei_Learner_Management{} |
|
488 | +class WooThemes_Sensei_Learners extends Sensei_Learner_Management {} |
@@ -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 Question Class |
@@ -19,35 +19,35 @@ discard block |
||
19 | 19 | * Constructor. |
20 | 20 | * @since 1.0.0 |
21 | 21 | */ |
22 | - public function __construct () { |
|
22 | + public function __construct() { |
|
23 | 23 | $this->token = 'question'; |
24 | 24 | $this->question_types = $this->question_types(); |
25 | - $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
|
26 | - if ( is_admin() ) { |
|
25 | + $this->meta_fields = array('question_right_answer', 'question_wrong_answers'); |
|
26 | + if (is_admin()) { |
|
27 | 27 | // Custom Write Panel Columns |
28 | - add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
|
29 | - add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 ); |
|
30 | - add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 ); |
|
28 | + add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1); |
|
29 | + add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2); |
|
30 | + add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2); |
|
31 | 31 | |
32 | 32 | // Quesitno list table filters |
33 | - add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) ); |
|
34 | - add_filter( 'request', array( $this, 'filter_actions' ) ); |
|
33 | + add_action('restrict_manage_posts', array($this, 'filter_options')); |
|
34 | + add_filter('request', array($this, 'filter_actions')); |
|
35 | 35 | |
36 | - add_action( 'save_post', array( $this, 'save_question' ), 10, 1 ); |
|
36 | + add_action('save_post', array($this, 'save_question'), 10, 1); |
|
37 | 37 | } // End If Statement |
38 | 38 | } // End __construct() |
39 | 39 | |
40 | 40 | public function question_types() { |
41 | 41 | $types = array( |
42 | - 'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ), |
|
43 | - 'boolean' => __( 'True/False', 'woothemes-sensei' ), |
|
44 | - 'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ), |
|
45 | - 'single-line' => __( 'Single Line', 'woothemes-sensei' ), |
|
46 | - 'multi-line' => __( 'Multi Line', 'woothemes-sensei' ), |
|
47 | - 'file-upload' => __( 'File Upload', 'woothemes-sensei' ), |
|
42 | + 'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'), |
|
43 | + 'boolean' => __('True/False', 'woothemes-sensei'), |
|
44 | + 'gap-fill' => __('Gap Fill', 'woothemes-sensei'), |
|
45 | + 'single-line' => __('Single Line', 'woothemes-sensei'), |
|
46 | + 'multi-line' => __('Multi Line', 'woothemes-sensei'), |
|
47 | + 'file-upload' => __('File Upload', 'woothemes-sensei'), |
|
48 | 48 | ); |
49 | 49 | |
50 | - return apply_filters( 'sensei_question_types', $types ); |
|
50 | + return apply_filters('sensei_question_types', $types); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * @param array $defaults |
58 | 58 | * @return array $new_columns |
59 | 59 | */ |
60 | - public function add_column_headings ( $defaults ) { |
|
60 | + public function add_column_headings($defaults) { |
|
61 | 61 | $new_columns['cb'] = '<input type="checkbox" />'; |
62 | - $new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' ); |
|
63 | - $new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' ); |
|
64 | - $new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' ); |
|
65 | - if ( isset( $defaults['date'] ) ) { |
|
62 | + $new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei'); |
|
63 | + $new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei'); |
|
64 | + $new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei'); |
|
65 | + if (isset($defaults['date'])) { |
|
66 | 66 | $new_columns['date'] = $defaults['date']; |
67 | 67 | } |
68 | 68 | |
@@ -77,27 +77,27 @@ discard block |
||
77 | 77 | * @param int $id |
78 | 78 | * @return void |
79 | 79 | */ |
80 | - public function add_column_data ( $column_name, $id ) { |
|
80 | + public function add_column_data($column_name, $id) { |
|
81 | 81 | global $wpdb, $post; |
82 | 82 | |
83 | - switch ( $column_name ) { |
|
83 | + switch ($column_name) { |
|
84 | 84 | |
85 | 85 | case 'id': |
86 | 86 | echo $id; |
87 | 87 | break; |
88 | 88 | |
89 | 89 | case 'question-type': |
90 | - $question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) ); |
|
90 | + $question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', '')); |
|
91 | 91 | $output = '—'; |
92 | - if( isset( $this->question_types[ $question_type ] ) ) { |
|
93 | - $output = $this->question_types[ $question_type ]; |
|
92 | + if (isset($this->question_types[$question_type])) { |
|
93 | + $output = $this->question_types[$question_type]; |
|
94 | 94 | } |
95 | 95 | echo $output; |
96 | 96 | break; |
97 | 97 | |
98 | 98 | case 'question-category': |
99 | - $output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) ); |
|
100 | - if( ! $output ) { |
|
99 | + $output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', '')); |
|
100 | + if ( ! $output) { |
|
101 | 101 | $output = '—'; |
102 | 102 | } |
103 | 103 | echo $output; |
@@ -110,49 +110,49 @@ discard block |
||
110 | 110 | |
111 | 111 | } // End add_column_data() |
112 | 112 | |
113 | - public function question_edit_panel_metabox( $post_type, $post ) { |
|
114 | - if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) { |
|
113 | + public function question_edit_panel_metabox($post_type, $post) { |
|
114 | + if (in_array($post_type, array('question', 'multiple_question'))) { |
|
115 | 115 | |
116 | - $metabox_title = __( 'Question', 'woothemes-sensei' ); |
|
116 | + $metabox_title = __('Question', 'woothemes-sensei'); |
|
117 | 117 | |
118 | - if( isset( $post->ID ) ) { |
|
118 | + if (isset($post->ID)) { |
|
119 | 119 | |
120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
120 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
121 | 121 | |
122 | - if( $question_type ) { |
|
123 | - $type = $this->question_types[ $question_type ]; |
|
124 | - if( $type ) { |
|
122 | + if ($question_type) { |
|
123 | + $type = $this->question_types[$question_type]; |
|
124 | + if ($type) { |
|
125 | 125 | $metabox_title = $type; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
129 | - add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' ); |
|
130 | - add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' ); |
|
131 | - add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' ); |
|
129 | + add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high'); |
|
130 | + add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default'); |
|
131 | + add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default'); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | public function question_edit_panel() { |
136 | 136 | global $post, $pagenow; |
137 | 137 | |
138 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) ); |
|
139 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) ); |
|
138 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts')); |
|
139 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles')); |
|
140 | 140 | |
141 | 141 | $html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">'; |
142 | 142 | |
143 | - if( 'post-new.php' == $pagenow ) { |
|
143 | + if ('post-new.php' == $pagenow) { |
|
144 | 144 | |
145 | 145 | $html .= '<div id="add-question-actions">'; |
146 | - $html .= Sensei()->lesson->quiz_panel_add( 'question' ); |
|
146 | + $html .= Sensei()->lesson->quiz_panel_add('question'); |
|
147 | 147 | $html .= '</div>'; |
148 | 148 | |
149 | 149 | } else { |
150 | 150 | $question_id = $post->ID; |
151 | 151 | |
152 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
152 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
153 | 153 | |
154 | 154 | $html .= '<div id="add-question-metadata"><table class="widefat">'; |
155 | - $html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' ); |
|
155 | + $html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question'); |
|
156 | 156 | $html .= '</table></div>'; |
157 | 157 | } |
158 | 158 | |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | public function question_lessons_panel() { |
165 | 165 | global $post; |
166 | 166 | |
167 | - $no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' ); |
|
167 | + $no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>'); |
|
168 | 168 | |
169 | - if( ! isset( $post->ID ) ) { |
|
169 | + if ( ! isset($post->ID)) { |
|
170 | 170 | echo $no_lessons; |
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | 174 | // This retrieves those quizzes the question is directly connected to. |
175 | - $quizzes = get_post_meta( $post->ID, '_quiz_id', false ); |
|
175 | + $quizzes = get_post_meta($post->ID, '_quiz_id', false); |
|
176 | 176 | |
177 | 177 | // Collate all 'multiple_question' quizzes the question is part of. |
178 | - $categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) ); |
|
179 | - if ( ! empty( $categories_of_question ) ) { |
|
180 | - foreach ( $categories_of_question as $term_id ) { |
|
178 | + $categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids')); |
|
179 | + if ( ! empty($categories_of_question)) { |
|
180 | + foreach ($categories_of_question as $term_id) { |
|
181 | 181 | $qargs = array( |
182 | 182 | 'fields' => 'ids', |
183 | 183 | 'post_type' => 'multiple_question', |
@@ -191,41 +191,41 @@ discard block |
||
191 | 191 | 'post_status' => 'any', |
192 | 192 | 'suppress_filters' => 0, |
193 | 193 | ); |
194 | - $cat_question_ids = get_posts( $qargs ); |
|
195 | - foreach( $cat_question_ids as $cat_question_id ) { |
|
196 | - $cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false ); |
|
197 | - $quizzes = array_merge( $quizzes, $cat_quizzes ); |
|
194 | + $cat_question_ids = get_posts($qargs); |
|
195 | + foreach ($cat_question_ids as $cat_question_id) { |
|
196 | + $cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false); |
|
197 | + $quizzes = array_merge($quizzes, $cat_quizzes); |
|
198 | 198 | } |
199 | 199 | } |
200 | - $quizzes = array_unique( array_filter( $quizzes ) ); |
|
200 | + $quizzes = array_unique(array_filter($quizzes)); |
|
201 | 201 | } |
202 | 202 | |
203 | - if( 0 == count( $quizzes ) ) { |
|
203 | + if (0 == count($quizzes)) { |
|
204 | 204 | echo $no_lessons; |
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $lessons = false; |
209 | 209 | |
210 | - foreach( $quizzes as $quiz ) { |
|
210 | + foreach ($quizzes as $quiz) { |
|
211 | 211 | |
212 | - $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
|
212 | + $lesson_id = get_post_meta($quiz, '_quiz_lesson', true); |
|
213 | 213 | |
214 | - if( ! $lesson_id ) continue; |
|
214 | + if ( ! $lesson_id) continue; |
|
215 | 215 | |
216 | - $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
|
217 | - $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
|
216 | + $lessons[$lesson_id]['title'] = get_the_title($lesson_id); |
|
217 | + $lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit'); |
|
218 | 218 | } |
219 | 219 | |
220 | - if( ! $lessons ) { |
|
220 | + if ( ! $lessons) { |
|
221 | 221 | echo $no_lessons; |
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | 225 | $html = '<ul>'; |
226 | 226 | |
227 | - foreach( $lessons as $id => $lesson ) { |
|
228 | - $html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>'; |
|
227 | + foreach ($lessons as $id => $lesson) { |
|
228 | + $html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>'; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $html .= '</ul>'; |
@@ -234,30 +234,30 @@ discard block |
||
234 | 234 | |
235 | 235 | } |
236 | 236 | |
237 | - public function save_question( $post_id = 0 ) { |
|
237 | + public function save_question($post_id = 0) { |
|
238 | 238 | |
239 | - if( ! isset( $_POST['post_type'] |
|
240 | - ) || 'question' != $_POST['post_type'] ) { |
|
239 | + if ( ! isset($_POST['post_type'] |
|
240 | + ) || 'question' != $_POST['post_type']) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | 244 | |
245 | 245 | |
246 | 246 | //setup the data for saving |
247 | - $data = $_POST ; |
|
247 | + $data = $_POST; |
|
248 | 248 | $data['quiz_id'] = 0; |
249 | 249 | $data['question_id'] = $post_id; |
250 | 250 | |
251 | - if ( ! wp_is_post_revision( $post_id ) ){ |
|
251 | + if ( ! wp_is_post_revision($post_id)) { |
|
252 | 252 | |
253 | 253 | // Unhook function to prevent infinite loops |
254 | - remove_action( 'save_post', array( $this, 'save_question' ) ); |
|
254 | + remove_action('save_post', array($this, 'save_question')); |
|
255 | 255 | |
256 | 256 | // Update question data |
257 | - $question_id = Sensei()->lesson->lesson_save_question( $data, 'question' ); |
|
257 | + $question_id = Sensei()->lesson->lesson_save_question($data, 'question'); |
|
258 | 258 | |
259 | 259 | // Re-hook same function |
260 | - add_action( 'save_post', array( $this, 'save_question' ) ); |
|
260 | + add_action('save_post', array($this, 'save_question')); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | return; |
@@ -270,15 +270,15 @@ discard block |
||
270 | 270 | public function filter_options() { |
271 | 271 | global $typenow; |
272 | 272 | |
273 | - if( is_admin() && 'question' == $typenow ) { |
|
273 | + if (is_admin() && 'question' == $typenow) { |
|
274 | 274 | |
275 | 275 | $output = ''; |
276 | 276 | |
277 | 277 | // Question type |
278 | - $selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
279 | - $type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>'; |
|
280 | - foreach( $this->question_types as $label => $type ) { |
|
281 | - $type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>'; |
|
278 | + $selected = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
279 | + $type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>'; |
|
280 | + foreach ($this->question_types as $label => $type) { |
|
281 | + $type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>'; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | $output .= '<select name="question_type" id="dropdown_question_type">'; |
@@ -286,12 +286,12 @@ discard block |
||
286 | 286 | $output .= '</select>'; |
287 | 287 | |
288 | 288 | // Question category |
289 | - $cats = get_terms( 'question-category', array( 'hide_empty' => false ) ); |
|
290 | - if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { |
|
291 | - $selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
292 | - $cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>'; |
|
293 | - foreach( $cats as $cat ) { |
|
294 | - $cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>'; |
|
289 | + $cats = get_terms('question-category', array('hide_empty' => false)); |
|
290 | + if ( ! empty($cats) && ! is_wp_error($cats)) { |
|
291 | + $selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
292 | + $cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>'; |
|
293 | + foreach ($cats as $cat) { |
|
294 | + $cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>'; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | $output .= '<select name="question_cat" id="dropdown_question_cat">'; |
@@ -308,14 +308,14 @@ discard block |
||
308 | 308 | * @param array $request Current request |
309 | 309 | * @return array Modified request |
310 | 310 | */ |
311 | - public function filter_actions( $request ) { |
|
311 | + public function filter_actions($request) { |
|
312 | 312 | global $typenow; |
313 | 313 | |
314 | - if( is_admin() && 'question' == $typenow ) { |
|
314 | + if (is_admin() && 'question' == $typenow) { |
|
315 | 315 | |
316 | 316 | // Question type |
317 | - $question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
318 | - if( $question_type ) { |
|
317 | + $question_type = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
318 | + if ($question_type) { |
|
319 | 319 | $type_query = array( |
320 | 320 | 'taxonomy' => 'question-type', |
321 | 321 | 'terms' => $question_type, |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | // Question category |
328 | - $question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
329 | - if( $question_cat ) { |
|
328 | + $question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
329 | + if ($question_cat) { |
|
330 | 330 | $cat_query = array( |
331 | 331 | 'taxonomy' => 'question-category', |
332 | 332 | 'terms' => $question_cat, |
@@ -351,16 +351,16 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return string $question_type | bool |
353 | 353 | */ |
354 | - public function get_question_type( $question_id ){ |
|
354 | + public function get_question_type($question_id) { |
|
355 | 355 | |
356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
357 | - || 'question' != get_post_type( $question_id ) ){ |
|
356 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
357 | + || 'question' != get_post_type($question_id)) { |
|
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $question_type = 'multiple-choice'; |
362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
363 | - foreach( $question_types as $type ) { |
|
362 | + $question_types = wp_get_post_terms($question_id, 'question-type'); |
|
363 | + foreach ($question_types as $type) { |
|
364 | 364 | $question_type = $type->slug; |
365 | 365 | } |
366 | 366 | |
@@ -377,21 +377,21 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return int $question_grade | bool |
379 | 379 | */ |
380 | - public function get_question_grade( $question_id ) { |
|
380 | + public function get_question_grade($question_id) { |
|
381 | 381 | |
382 | - if ( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
383 | - || 'question' != get_post_type( $question_id ) ) { |
|
382 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
383 | + || 'question' != get_post_type($question_id)) { |
|
384 | 384 | return false; |
385 | 385 | } |
386 | 386 | |
387 | - $question_grade_raw = get_post_meta( $question_id, '_question_grade', true ); |
|
387 | + $question_grade_raw = get_post_meta($question_id, '_question_grade', true); |
|
388 | 388 | // If not set then default to 1... |
389 | - if ( false === $question_grade_raw || $question_grade_raw == '' ) { |
|
389 | + if (false === $question_grade_raw || $question_grade_raw == '') { |
|
390 | 390 | $question_grade = 1; |
391 | 391 | } |
392 | 392 | // ...but allow a grade of 0 for non-marked questions |
393 | 393 | else { |
394 | - $question_grade = intval( $question_grade_raw ); |
|
394 | + $question_grade = intval($question_grade_raw); |
|
395 | 395 | } |
396 | 396 | return $question_grade; |
397 | 397 | |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | * @since 1.9.0 |
405 | 405 | * @param $question_type |
406 | 406 | */ |
407 | - public static function load_question_template( $question_type ){ |
|
407 | + public static function load_question_template($question_type) { |
|
408 | 408 | |
409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
409 | + Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php'); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * @since 1.9.0 |
418 | 418 | * @param $question_id |
419 | 419 | */ |
420 | - public static function the_question_title( $question_id ){ |
|
420 | + public static function the_question_title($question_id) { |
|
421 | 421 | |
422 | - echo self::get_the_question_title( $question_id ); |
|
422 | + echo self::get_the_question_title($question_id); |
|
423 | 423 | |
424 | 424 | }// end the_question_title |
425 | 425 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @param $question_id |
432 | 432 | * @return string |
433 | 433 | */ |
434 | - public static function get_the_question_title( $question_id ){ |
|
434 | + public static function get_the_question_title($question_id) { |
|
435 | 435 | |
436 | 436 | /** |
437 | 437 | * Filter the sensei question title |
@@ -439,17 +439,17 @@ discard block |
||
439 | 439 | * @since 1.3.0 |
440 | 440 | * @param $question_title |
441 | 441 | */ |
442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
442 | + $title = apply_filters('sensei_question_title', get_the_title($question_id)); |
|
443 | 443 | |
444 | 444 | /** |
445 | 445 | * hook document in class-woothemes-sensei-message.php the_title() |
446 | 446 | */ |
447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
447 | + $title = apply_filters('sensei_single_title', $title, 'question'); |
|
448 | 448 | |
449 | 449 | $title_html = '<span class="question question-title">'; |
450 | 450 | $title_html .= $title; |
451 | 451 | $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
452 | - $title_html .='</span>'; |
|
452 | + $title_html .= '</span>'; |
|
453 | 453 | |
454 | 454 | return $title_html; |
455 | 455 | } |
@@ -460,14 +460,14 @@ discard block |
||
460 | 460 | * @param $question_id |
461 | 461 | * @return string |
462 | 462 | */ |
463 | - public static function get_the_question_description( $question_id ){ |
|
463 | + public static function get_the_question_description($question_id) { |
|
464 | 464 | |
465 | - $question = get_post( $question_id ); |
|
465 | + $question = get_post($question_id); |
|
466 | 466 | |
467 | 467 | /** |
468 | 468 | * Already documented within WordPress Core |
469 | 469 | */ |
470 | - return apply_filters( 'the_content', $question->post_content ); |
|
470 | + return apply_filters('the_content', $question->post_content); |
|
471 | 471 | |
472 | 472 | } |
473 | 473 | |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | * @since 1.9.0 |
478 | 478 | * @param $question_id |
479 | 479 | */ |
480 | - public static function the_question_description( $question_id ){ |
|
480 | + public static function the_question_description($question_id) { |
|
481 | 481 | |
482 | - echo self::get_the_question_description( $question_id ); |
|
482 | + echo self::get_the_question_description($question_id); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -490,38 +490,38 @@ discard block |
||
490 | 490 | * @param $question_id |
491 | 491 | * @return string |
492 | 492 | */ |
493 | - public static function get_the_question_media( $question_id ){ |
|
493 | + public static function get_the_question_media($question_id) { |
|
494 | 494 | |
495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
495 | + $question_media = get_post_meta($question_id, '_question_media', true); |
|
496 | 496 | $question_media_link = ''; |
497 | - if( 0 < intval( $question_media ) ) { |
|
498 | - $mimetype = get_post_mime_type( $question_media ); |
|
499 | - if( $mimetype ) { |
|
500 | - $mimetype_array = explode( '/', $mimetype); |
|
501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
497 | + if (0 < intval($question_media)) { |
|
498 | + $mimetype = get_post_mime_type($question_media); |
|
499 | + if ($mimetype) { |
|
500 | + $mimetype_array = explode('/', $mimetype); |
|
501 | + if (isset($mimetype_array[0]) && $mimetype_array[0]) { |
|
502 | 502 | $question_media_type = $mimetype_array[0]; |
503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
504 | - $attachment = get_post( $question_media ); |
|
503 | + $question_media_url = wp_get_attachment_url($question_media); |
|
504 | + $attachment = get_post($question_media); |
|
505 | 505 | $question_media_title = $attachment->post_title; |
506 | 506 | $question_media_description = $attachment->post_content; |
507 | - switch( $question_media_type ) { |
|
507 | + switch ($question_media_type) { |
|
508 | 508 | case 'image': |
509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
509 | + $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id); |
|
510 | + $attachment_src = wp_get_attachment_image_src($question_media, $image_size); |
|
511 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>'; |
|
512 | 512 | break; |
513 | 513 | |
514 | 514 | case 'audio': |
515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
515 | + $question_media_link = wp_audio_shortcode(array('src' => $question_media_url)); |
|
516 | 516 | break; |
517 | 517 | |
518 | 518 | case 'video': |
519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
519 | + $question_media_link = wp_video_shortcode(array('src' => $question_media_url)); |
|
520 | 520 | break; |
521 | 521 | |
522 | 522 | default: |
523 | - $question_media_filename = basename( $question_media_url ); |
|
524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
523 | + $question_media_filename = basename($question_media_url); |
|
524 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>'; |
|
525 | 525 | break; |
526 | 526 | } |
527 | 527 | } |
@@ -529,21 +529,21 @@ discard block |
||
529 | 529 | } |
530 | 530 | |
531 | 531 | $output = ''; |
532 | - if( $question_media_link ) { |
|
532 | + if ($question_media_link) { |
|
533 | 533 | |
534 | 534 | $output .= '<div class="question_media_display">'; |
535 | - $output .= $question_media_link; |
|
535 | + $output .= $question_media_link; |
|
536 | 536 | $output .= '<dl>'; |
537 | 537 | |
538 | - if( $question_media_title ) { |
|
538 | + if ($question_media_title) { |
|
539 | 539 | |
540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
540 | + $output .= '<dt>'.$question_media_title.'</dt>'; |
|
541 | 541 | |
542 | 542 | } |
543 | 543 | |
544 | - if( $question_media_description ) { |
|
544 | + if ($question_media_description) { |
|
545 | 545 | |
546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
546 | + $output .= '<dd>'.$question_media_description.'</dd>'; |
|
547 | 547 | |
548 | 548 | } |
549 | 549 | |
@@ -564,9 +564,9 @@ discard block |
||
564 | 564 | * @since 1.9.0 |
565 | 565 | * @param string $question_id |
566 | 566 | */ |
567 | - public static function the_question_media( $question_id ){ |
|
567 | + public static function the_question_media($question_id) { |
|
568 | 568 | |
569 | - echo self::get_the_question_media( $question_id ); |
|
569 | + echo self::get_the_question_media($question_id); |
|
570 | 570 | |
571 | 571 | } |
572 | 572 | |
@@ -577,11 +577,11 @@ discard block |
||
577 | 577 | * |
578 | 578 | * @param $question_id |
579 | 579 | */ |
580 | - public static function the_question_hidden_fields( $question_id ){ |
|
580 | + public static function the_question_hidden_fields($question_id) { |
|
581 | 581 | ?> |
582 | 582 | |
583 | - <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
|
584 | - <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
583 | + <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" /> |
|
584 | + <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" /> |
|
585 | 585 | |
586 | 586 | <?php |
587 | 587 | } |
@@ -592,27 +592,27 @@ discard block |
||
592 | 592 | * @since 1.9.0 |
593 | 593 | * @param $question_id |
594 | 594 | */ |
595 | - public static function answer_feedback_notes( $question_id ){ |
|
595 | + public static function answer_feedback_notes($question_id) { |
|
596 | 596 | |
597 | 597 | //IDS |
598 | 598 | $quiz_id = get_the_ID(); |
599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
599 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
600 | 600 | |
601 | 601 | // Data to check before showing feedback |
602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
602 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id()); |
|
603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
604 | + $not_empty_user_quiz_grade = ! empty($user_quiz_grade); |
|
605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
606 | + $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id); |
|
607 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
608 | 608 | |
609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
609 | + if (($lesson_completed && $not_empty_user_quiz_grade) |
|
610 | + || ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type) |
|
611 | + || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) { |
|
612 | 612 | |
613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id()); |
|
614 | 614 | |
615 | - if( $answer_notes ) { ?> |
|
615 | + if ($answer_notes) { ?> |
|
616 | 616 | |
617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
618 | 618 | |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | * @param string $question_id |
627 | 627 | * @param string $lesson_id |
628 | 628 | */ |
629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
629 | + echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id); |
|
630 | 630 | |
631 | 631 | ?> |
632 | 632 | |
@@ -645,72 +645,72 @@ discard block |
||
645 | 645 | * @since 1.9.0 |
646 | 646 | * @param string $question_id |
647 | 647 | */ |
648 | - public static function the_answer_result_indication( $question_id ){ |
|
648 | + public static function the_answer_result_indication($question_id) { |
|
649 | 649 | |
650 | - global $post, $current_user, $sensei_question_loop; |
|
650 | + global $post, $current_user, $sensei_question_loop; |
|
651 | 651 | |
652 | 652 | // Post Data |
653 | 653 | $quiz_id = $sensei_question_loop['quiz_id']; |
654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
654 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
655 | 655 | $question_item = $sensei_question_loop['current_question']; |
656 | 656 | |
657 | 657 | // Setup variable needed to determine if the message should show and what it should show |
658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
659 | + $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id()); |
|
660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
661 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
662 | 662 | |
663 | 663 | // retrieve the question total grade |
664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
664 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
665 | 665 | |
666 | 666 | // retrieve grade the user achieved |
667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
668 | 668 | |
669 | 669 | // Question ID |
670 | 670 | $question_id = $question_item->ID; |
671 | 671 | |
672 | 672 | // conditions to check |
673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != ''; |
|
674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed; |
|
675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != ''; |
|
676 | 676 | |
677 | - if ( $completed_with_valid_grade |
|
677 | + if ($completed_with_valid_grade |
|
678 | 678 | || $completed_with_valid_grade_and_reset_not_allowed |
679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed) { |
|
680 | 680 | |
681 | 681 | $user_correct = false; |
682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
682 | + $answer_message = __('Incorrect', 'woothemes-sensei'); |
|
683 | 683 | $answer_message_class = 'user_wrong'; |
684 | 684 | // For zero grade mark as 'correct' but add no classes |
685 | - if ( 0 == $question_grade ) { |
|
685 | + if (0 == $question_grade) { |
|
686 | 686 | |
687 | 687 | $user_correct = true; |
688 | 688 | $answer_message = ''; |
689 | 689 | $answer_message_class = ''; |
690 | 690 | |
691 | - } else if( $user_question_grade > 0 ) { |
|
691 | + } else if ($user_question_grade > 0) { |
|
692 | 692 | |
693 | 693 | $user_correct = true; |
694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
694 | + $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade); |
|
695 | 695 | $answer_message_class = 'user_right'; |
696 | 696 | |
697 | 697 | } |
698 | 698 | |
699 | 699 | // attach the correct answer if the question is auto gradable and user got it wrong |
700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
700 | + if ( ! $reset_quiz_allowed && ! $user_correct) { |
|
701 | 701 | |
702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
702 | + $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID); |
|
703 | 703 | |
704 | 704 | } |
705 | 705 | |
706 | 706 | // answer feedback |
707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
708 | - if( $answer_notes ) { |
|
707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID); |
|
708 | + if ($answer_notes) { |
|
709 | 709 | $answer_message_class .= ' has_notes'; |
710 | 710 | } |
711 | 711 | ?> |
712 | 712 | |
713 | - <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
|
713 | + <div class="answer_message <?php esc_attr_e($answer_message_class); ?>"> |
|
714 | 714 | |
715 | 715 | <span><?php echo $answer_message; ?></span> |
716 | 716 | |
@@ -731,39 +731,39 @@ discard block |
||
731 | 731 | * @param $quiz_id |
732 | 732 | * @return array $question_data |
733 | 733 | */ |
734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
734 | + public static function get_template_data($question_id, $quiz_id) { |
|
735 | 735 | |
736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
737 | 737 | |
738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
738 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
739 | 739 | //backwards compatibility |
740 | - if( 'on' == $reset_allowed ) { |
|
740 | + if ('on' == $reset_allowed) { |
|
741 | 741 | $reset_allowed = 1; |
742 | 742 | } |
743 | 743 | |
744 | 744 | // Check again that the lesson is complete |
745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id()); |
|
746 | 746 | $user_lesson_complete = false; |
747 | - if ( $user_lesson_end ) { |
|
747 | + if ($user_lesson_end) { |
|
748 | 748 | $user_lesson_complete = true; |
749 | 749 | } |
750 | 750 | |
751 | 751 | //setup the question data |
752 | - $data[ 'ID' ] = $question_id; |
|
753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
752 | + $data['ID'] = $question_id; |
|
753 | + $data['title'] = get_the_title($question_id); |
|
754 | + $data['content'] = get_post($question_id)->post_content; |
|
755 | + $data['quiz_id'] = $quiz_id; |
|
756 | + $data['lesson_id'] = Sensei()->quiz->get_lesson_id($quiz_id); |
|
757 | + $data['type'] = Sensei()->question->get_question_type($question_id); |
|
758 | + $data['question_grade'] = Sensei()->question->get_question_grade($question_id); |
|
759 | + $data['user_question_grade'] = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
760 | + $data['question_right_answer'] = get_post_meta($question_id, '_question_right_answer', true); |
|
761 | + $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true); |
|
762 | + $data['user_answer_entry'] = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id()); |
|
763 | + $data['lesson_completed'] = Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( )); |
|
764 | + $data['quiz_grade_type'] = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
765 | + $data['reset_quiz_allowed'] = $reset_allowed; |
|
766 | + $data['lesson_complete'] = $user_lesson_complete; |
|
767 | 767 | |
768 | 768 | /** |
769 | 769 | * Filter the question template data. This filter fires in |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * @param string $question_id |
778 | 778 | * @param string $quiz_id |
779 | 779 | */ |
780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
780 | + return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id); |
|
781 | 781 | |
782 | 782 | } |
783 | 783 | |
@@ -793,28 +793,28 @@ discard block |
||
793 | 793 | * |
794 | 794 | * @return array() |
795 | 795 | */ |
796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
796 | + public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) { |
|
797 | 797 | |
798 | 798 | |
799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
799 | + if ('file-upload' == Sensei()->question->get_question_type($question_id)) { |
|
800 | 800 | |
801 | 801 | // Get uploaded file |
802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
802 | + $attachment_id = $question_data['user_answer_entry']; |
|
803 | 803 | $answer_media_url = $answer_media_filename = ''; |
804 | 804 | |
805 | 805 | |
806 | 806 | $question_helptext = ''; |
807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
807 | + if (isset($question_data['question_wrong_answers'][0])) { |
|
808 | 808 | |
809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
810 | 810 | |
811 | 811 | } |
812 | 812 | |
813 | 813 | |
814 | - if( 0 < intval( $attachment_id ) ) { |
|
814 | + if (0 < intval($attachment_id)) { |
|
815 | 815 | |
816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
817 | - $answer_media_filename = basename( $answer_media_url ); |
|
816 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
817 | + $answer_media_filename = basename($answer_media_url); |
|
818 | 818 | |
819 | 819 | } |
820 | 820 | |
@@ -822,11 +822,11 @@ discard block |
||
822 | 822 | // Get max upload file size, formatted for display |
823 | 823 | // Code copied from wp-admin/includes/media.php:1515 |
824 | 824 | $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
825 | + $sizes = array('KB', 'MB', 'GB'); |
|
826 | + for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) { |
|
827 | 827 | $upload_size_unit /= 1024; |
828 | 828 | } |
829 | - if ( $u < 0 ) { |
|
829 | + if ($u < 0) { |
|
830 | 830 | |
831 | 831 | $upload_size_unit = 0; |
832 | 832 | $u = 0; |
@@ -836,14 +836,14 @@ discard block |
||
836 | 836 | $upload_size_unit = (int) $upload_size_unit; |
837 | 837 | |
838 | 838 | } |
839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
839 | + $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u])); |
|
840 | 840 | |
841 | 841 | // Assemble all the data needed by the file upload template |
842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
842 | + $question_data['answer_media_url'] = $answer_media_url; |
|
843 | + $question_data['answer_media_filename'] = $answer_media_filename; |
|
844 | + $question_data['max_upload_size'] = $max_upload_size; |
|
845 | 845 | |
846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
846 | + $question_data['question_helptext'] = $question_helptext; |
|
847 | 847 | |
848 | 848 | }// end if is file upload type |
849 | 849 | |
@@ -863,27 +863,27 @@ discard block |
||
863 | 863 | * |
864 | 864 | * @return array() |
865 | 865 | */ |
866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
866 | + public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) { |
|
867 | 867 | |
868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
868 | + if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) { |
|
869 | 869 | |
870 | 870 | |
871 | 871 | $answer_type = 'radio'; |
872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
872 | + if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) { |
|
873 | 873 | |
874 | 874 | $answer_type = 'checkbox'; |
875 | 875 | |
876 | 876 | } |
877 | 877 | |
878 | 878 | // Merge right and wrong answers |
879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
879 | + if (is_array($question_data['question_right_answer'])) { |
|
880 | 880 | |
881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
881 | + $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
882 | 882 | |
883 | - } else { |
|
883 | + } else { |
|
884 | 884 | |
885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
885 | + array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
886 | + $merged_options = $question_data['question_wrong_answers']; |
|
887 | 887 | |
888 | 888 | } |
889 | 889 | |
@@ -891,24 +891,24 @@ discard block |
||
891 | 891 | $question_answers_options = array(); |
892 | 892 | $count = 0; |
893 | 893 | |
894 | - foreach( $merged_options as $answer ) { |
|
894 | + foreach ($merged_options as $answer) { |
|
895 | 895 | |
896 | 896 | $count++; |
897 | 897 | $question_option = array(); |
898 | 898 | |
899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
899 | + if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '') |
|
900 | + || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '') |
|
901 | + || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) { |
|
902 | 902 | |
903 | 903 | $user_correct = false; |
904 | 904 | |
905 | 905 | |
906 | 906 | // For zero grade mark as 'correct' but add no classes |
907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
907 | + if (0 == $question_data['question_grade']) { |
|
908 | 908 | |
909 | 909 | $user_correct = true; |
910 | 910 | |
911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
911 | + } else if ($question_data['user_question_grade'] > 0) { |
|
912 | 912 | |
913 | 913 | $user_correct = true; |
914 | 914 | |
@@ -918,20 +918,20 @@ discard block |
||
918 | 918 | |
919 | 919 | // setup the option specific classes |
920 | 920 | $answer_class = ''; |
921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
921 | + if (isset($user_correct) && 0 < $question_data['question_grade']) { |
|
922 | + if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) { |
|
923 | 923 | |
924 | 924 | $answer_class .= ' right_answer'; |
925 | 925 | |
926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
926 | + } elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) { |
|
927 | 927 | |
928 | 928 | $answer_class .= ' right_answer'; |
929 | 929 | |
930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
930 | + } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) |
|
931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) { |
|
932 | 932 | |
933 | 933 | $answer_class = 'user_wrong'; |
934 | - if( $user_correct ) { |
|
934 | + if ($user_correct) { |
|
935 | 935 | |
936 | 936 | $answer_class = 'user_right'; |
937 | 937 | |
@@ -943,76 +943,76 @@ discard block |
||
943 | 943 | |
944 | 944 | // determine if the current option must be checked |
945 | 945 | $checked = ''; |
946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
946 | + if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) { |
|
947 | + if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) { |
|
948 | 948 | |
949 | 949 | $checked = 'checked="checked"'; |
950 | 950 | |
951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
951 | + } elseif ( ! is_array($question_data['user_answer_entry'])) { |
|
952 | 952 | |
953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
953 | + $checked = checked($answer, $question_data['user_answer_entry'], false); |
|
954 | 954 | |
955 | 955 | } |
956 | 956 | |
957 | 957 | } // End If Statement |
958 | 958 | |
959 | 959 | //Load the answer option data |
960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
961 | - $question_option[ 'answer' ] = $answer; |
|
962 | - $question_option[ 'option_class'] = $answer_class; |
|
963 | - $question_option[ 'checked'] = $checked; |
|
964 | - $question_option[ 'count' ] = $count; |
|
965 | - $question_option[ 'type' ] = $answer_type; |
|
960 | + $question_option['ID'] = Sensei()->lesson->get_answer_id($answer); |
|
961 | + $question_option['answer'] = $answer; |
|
962 | + $question_option['option_class'] = $answer_class; |
|
963 | + $question_option['checked'] = $checked; |
|
964 | + $question_option['count'] = $count; |
|
965 | + $question_option['type'] = $answer_type; |
|
966 | 966 | |
967 | 967 | // add the speci fic option to the list of options for this question |
968 | - $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
968 | + $question_answers_options[$question_option['ID']] = $question_option; |
|
969 | 969 | |
970 | 970 | } // end for each option |
971 | 971 | |
972 | 972 | |
973 | 973 | // Shuffle the array depending on the settings |
974 | 974 | $answer_options_sorted = array(); |
975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
976 | - if( $random_order && $random_order == 'yes' ) { |
|
975 | + $random_order = get_post_meta($question_data['ID'], '_random_order', true); |
|
976 | + if ($random_order && $random_order == 'yes') { |
|
977 | 977 | |
978 | 978 | $answer_options_sorted = $question_answers_options; |
979 | - shuffle( $answer_options_sorted ); |
|
979 | + shuffle($answer_options_sorted); |
|
980 | 980 | |
981 | 981 | } else { |
982 | 982 | |
983 | 983 | $answer_order = array(); |
984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
985 | - if( $answer_order_string ) { |
|
984 | + $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true); |
|
985 | + if ($answer_order_string) { |
|
986 | 986 | |
987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
988 | - if( count( $answer_order ) > 0 ) { |
|
987 | + $answer_order = array_filter(explode(',', $answer_order_string)); |
|
988 | + if (count($answer_order) > 0) { |
|
989 | 989 | |
990 | - foreach( $answer_order as $answer_id ) { |
|
990 | + foreach ($answer_order as $answer_id) { |
|
991 | 991 | |
992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
992 | + if (isset($question_answers_options[$answer_id])) { |
|
993 | 993 | |
994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
995 | - unset( $question_answers_options[ $answer_id ] ); |
|
994 | + $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id]; |
|
995 | + unset($question_answers_options[$answer_id]); |
|
996 | 996 | |
997 | 997 | } |
998 | 998 | |
999 | 999 | } |
1000 | 1000 | |
1001 | - if( count( $question_answers_options ) > 0 ) { |
|
1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
1001 | + if (count($question_answers_options) > 0) { |
|
1002 | + foreach ($question_answers_options as $id => $answer) { |
|
1003 | 1003 | |
1004 | - $answer_options_sorted[ $id ] = $answer; |
|
1004 | + $answer_options_sorted[$id] = $answer; |
|
1005 | 1005 | |
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - }else{ |
|
1009 | + } else { |
|
1010 | 1010 | |
1011 | 1011 | $answer_options_sorted = $question_answers_options; |
1012 | 1012 | |
1013 | 1013 | } |
1014 | 1014 | |
1015 | - }else{ |
|
1015 | + } else { |
|
1016 | 1016 | |
1017 | 1017 | $answer_options_sorted = $question_answers_options; |
1018 | 1018 | |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | |
1023 | 1023 | |
1024 | 1024 | // assemble and setup the data for the templates data array |
1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
1025 | + $question_data['answer_options'] = $answer_options_sorted; |
|
1026 | 1026 | |
1027 | 1027 | } |
1028 | 1028 | |
@@ -1042,14 +1042,14 @@ discard block |
||
1042 | 1042 | * |
1043 | 1043 | * @return array() |
1044 | 1044 | */ |
1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
1045 | + public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) { |
|
1046 | 1046 | |
1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
1047 | + if ('gap-fill' == Sensei()->question->get_question_type($question_id)) { |
|
1048 | 1048 | |
1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
1049 | + $gapfill_array = explode('||', $question_data['question_right_answer']); |
|
1050 | + $question_data['gapfill_pre'] = isset($gapfill_array[0]) ? $gapfill_array[0] : ''; |
|
1051 | + $question_data['gapfill_gap'] = isset($gapfill_array[1]) ? $gapfill_array[1] : ''; |
|
1052 | + $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : ''; |
|
1053 | 1053 | |
1054 | 1054 | } |
1055 | 1055 | |
@@ -1064,32 +1064,32 @@ discard block |
||
1064 | 1064 | * @param $question_id |
1065 | 1065 | * @return string $correct_answer or empty |
1066 | 1066 | */ |
1067 | - public static function get_correct_answer( $question_id ){ |
|
1067 | + public static function get_correct_answer($question_id) { |
|
1068 | 1068 | |
1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
1069 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
1070 | + $type = Sensei()->question->get_question_type($question_id); |
|
1071 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
1072 | 1072 | $grade_type = 'manual-grade'; |
1073 | 1073 | |
1074 | - if ('boolean'== $type ) { |
|
1074 | + if ('boolean' == $type) { |
|
1075 | 1075 | |
1076 | 1076 | $right_answer = ucfirst($right_answer); |
1077 | 1077 | |
1078 | - }elseif( 'multiple-choice' == $type ) { |
|
1078 | + }elseif ('multiple-choice' == $type) { |
|
1079 | 1079 | |
1080 | 1080 | $right_answer = (array) $right_answer; |
1081 | - $right_answer = implode( ', ', $right_answer ); |
|
1081 | + $right_answer = implode(', ', $right_answer); |
|
1082 | 1082 | |
1083 | - }elseif( 'gap-fill' == $type ) { |
|
1083 | + }elseif ('gap-fill' == $type) { |
|
1084 | 1084 | |
1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
1085 | + $right_answer_array = explode('||', $right_answer); |
|
1086 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
1087 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
1088 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
1089 | 1089 | |
1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
1090 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
1091 | 1091 | |
1092 | - }else{ |
|
1092 | + } else { |
|
1093 | 1093 | |
1094 | 1094 | // for non auto gradable question types no answer should be returned. |
1095 | 1095 | $right_answer = ''; |
@@ -1107,4 +1107,4 @@ discard block |
||
1107 | 1107 | * @ignore only for backward compatibility |
1108 | 1108 | * @since 1.9.0 |
1109 | 1109 | */ |
1110 | -class WooThemes_Sensei_Question extends Sensei_Question{} |
|
1110 | +class WooThemes_Sensei_Question extends Sensei_Question {} |
@@ -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 | * All functionality pertaining to the Admin Analysis in Sensei. |
@@ -19,24 +19,24 @@ discard block |
||
19 | 19 | * @since 1.0.0 |
20 | 20 | * @param string $file |
21 | 21 | */ |
22 | - public function __construct ( $file ) { |
|
22 | + public function __construct($file) { |
|
23 | 23 | $this->name = __('Analysis', 'woothemes-sensei'); |
24 | 24 | $this->file = $file; |
25 | 25 | $this->page_slug = 'sensei_analysis'; |
26 | 26 | |
27 | 27 | // Admin functions |
28 | - if ( is_admin() ) { |
|
29 | - add_action( 'admin_menu', array( $this, 'analysis_admin_menu' ), 10); |
|
30 | - add_action( 'analysis_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
31 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
28 | + if (is_admin()) { |
|
29 | + add_action('admin_menu', array($this, 'analysis_admin_menu'), 10); |
|
30 | + add_action('analysis_wrapper_container', array($this, 'wrapper_container')); |
|
31 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
32 | 32 | |
33 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
33 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | |
37 | - add_action( 'admin_init', array( $this, 'report_download_page' ) ); |
|
37 | + add_action('admin_init', array($this, 'report_download_page')); |
|
38 | 38 | |
39 | - add_filter( 'user_search_columns', array( $this, 'user_search_columns_filter' ), 10, 3 ); |
|
39 | + add_filter('user_search_columns', array($this, 'user_search_columns_filter'), 10, 3); |
|
40 | 40 | } // End If Statement |
41 | 41 | } // End __construct() |
42 | 42 | |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | public function analysis_admin_menu() { |
51 | 51 | global $menu, $woocommerce; |
52 | 52 | |
53 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
53 | + if (current_user_can('manage_sensei_grades')) { |
|
54 | 54 | |
55 | - add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'), __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) ); |
|
55 | + add_submenu_page('sensei', __('Analysis', 'woothemes-sensei'), __('Analysis', 'woothemes-sensei'), 'manage_sensei_grades', 'sensei_analysis', array($this, 'analysis_page')); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @since 1.0.0 |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - public function enqueue_styles () { |
|
69 | + public function enqueue_styles() { |
|
70 | 70 | |
71 | - wp_enqueue_style( 'woothemes-sensei-admin' ); |
|
71 | + wp_enqueue_style('woothemes-sensei-admin'); |
|
72 | 72 | |
73 | - wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version ); |
|
73 | + wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version); |
|
74 | 74 | |
75 | 75 | } // End enqueue_styles() |
76 | 76 | |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | public function load_data_table_files() { |
83 | 83 | |
84 | 84 | // Load Analysis Classes |
85 | - $classes_to_load = array( 'list-table', |
|
85 | + $classes_to_load = array('list-table', |
|
86 | 86 | 'analysis-overview', |
87 | 87 | 'analysis-user-profile', |
88 | 88 | 'analysis-course', |
89 | 89 | 'analysis-lesson' |
90 | 90 | ); |
91 | - foreach ( $classes_to_load as $class_file ) { |
|
92 | - Sensei()->load_class( $class_file ); |
|
91 | + foreach ($classes_to_load as $class_file) { |
|
92 | + Sensei()->load_class($class_file); |
|
93 | 93 | } // End For Loop |
94 | 94 | } // End load_data_table_files() |
95 | 95 | |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | * @param undefined $optional_data optional constructor arguments |
101 | 101 | * @return object class instance object |
102 | 102 | */ |
103 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
103 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
104 | 104 | // Load Analysis data |
105 | - $object_name = 'Sensei_Analysis_' . $name . '_List_Table'; |
|
106 | - if ( is_null($optional_data) ) { |
|
107 | - $sensei_analysis_object = new $object_name( $data ); |
|
105 | + $object_name = 'Sensei_Analysis_'.$name.'_List_Table'; |
|
106 | + if (is_null($optional_data)) { |
|
107 | + $sensei_analysis_object = new $object_name($data); |
|
108 | 108 | } else { |
109 | - $sensei_analysis_object = new $object_name( $data, $optional_data ); |
|
109 | + $sensei_analysis_object = new $object_name($data, $optional_data); |
|
110 | 110 | } |
111 | 111 | $sensei_analysis_object->prepare_items(); |
112 | 112 | return $sensei_analysis_object; |
@@ -123,40 +123,40 @@ discard block |
||
123 | 123 | $course_id = 0; |
124 | 124 | $lesson_id = 0; |
125 | 125 | $user_id = 0; |
126 | - if( isset( $_GET['course_id'] ) ) { |
|
127 | - $course_id = intval( $_GET['course_id'] ); |
|
126 | + if (isset($_GET['course_id'])) { |
|
127 | + $course_id = intval($_GET['course_id']); |
|
128 | 128 | } |
129 | - if( isset( $_GET['lesson_id'] ) ) { |
|
130 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
129 | + if (isset($_GET['lesson_id'])) { |
|
130 | + $lesson_id = intval($_GET['lesson_id']); |
|
131 | 131 | } |
132 | - if( isset( $_GET['user_id'] ) ) { |
|
133 | - $user_id = intval( $_GET['user_id'] ); |
|
132 | + if (isset($_GET['user_id'])) { |
|
133 | + $user_id = intval($_GET['user_id']); |
|
134 | 134 | } |
135 | - $type = isset( $_GET['view'] ) ? esc_html( $_GET['view'] ) : false; |
|
135 | + $type = isset($_GET['view']) ? esc_html($_GET['view']) : false; |
|
136 | 136 | |
137 | - if ( 0 < $lesson_id ) { |
|
137 | + if (0 < $lesson_id) { |
|
138 | 138 | // Viewing a specific Lesson and all its Learners |
139 | - $this->analysis_lesson_users_view( $lesson_id ); |
|
139 | + $this->analysis_lesson_users_view($lesson_id); |
|
140 | 140 | } |
141 | - elseif ( 0 < $course_id && !$user_id && 'user' == $type ) { |
|
141 | + elseif (0 < $course_id && ! $user_id && 'user' == $type) { |
|
142 | 142 | // Viewing a specific Course and all its Learners |
143 | - $this->analysis_course_users_view( $course_id ); |
|
143 | + $this->analysis_course_users_view($course_id); |
|
144 | 144 | } |
145 | - elseif ( 0 < $course_id && 0 < $user_id ) { |
|
145 | + elseif (0 < $course_id && 0 < $user_id) { |
|
146 | 146 | // Viewing a specific Learner on a specific Course, showing their Lessons |
147 | - $this->analysis_user_course_view( $course_id, $user_id ); |
|
147 | + $this->analysis_user_course_view($course_id, $user_id); |
|
148 | 148 | } |
149 | - elseif( 0 < $course_id ) { |
|
149 | + elseif (0 < $course_id) { |
|
150 | 150 | // Viewing a specific Course and all it's Lessons |
151 | - $this->analysis_course_view( $course_id ); |
|
151 | + $this->analysis_course_view($course_id); |
|
152 | 152 | } |
153 | - elseif ( 0 < $user_id ) { |
|
153 | + elseif (0 < $user_id) { |
|
154 | 154 | // Viewing a specific Learner, and their Courses |
155 | - $this->analysis_user_profile_view( $user_id ); |
|
155 | + $this->analysis_user_profile_view($user_id); |
|
156 | 156 | } |
157 | 157 | else { |
158 | 158 | // Overview of all Learners, all Courses, or all Lessons |
159 | - $this->analysis_default_view( $type ); |
|
159 | + $this->analysis_default_view($type); |
|
160 | 160 | } // End If Statement |
161 | 161 | } // End analysis_page() |
162 | 162 | |
@@ -165,35 +165,35 @@ discard block |
||
165 | 165 | * @since 1.2.0 |
166 | 166 | * @return void |
167 | 167 | */ |
168 | - public function analysis_default_view( $type ) { |
|
168 | + public function analysis_default_view($type) { |
|
169 | 169 | |
170 | 170 | // Load Analysis data |
171 | - $sensei_analysis_overview = $this->load_data_object( 'Overview', $type ); |
|
171 | + $sensei_analysis_overview = $this->load_data_object('Overview', $type); |
|
172 | 172 | // Wrappers |
173 | - do_action( 'analysis_before_container' ); |
|
174 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
173 | + do_action('analysis_before_container'); |
|
174 | + do_action('analysis_wrapper_container', 'top'); |
|
175 | 175 | $this->analysis_headers(); |
176 | 176 | ?> |
177 | 177 | <div id="poststuff" class="sensei-analysis-wrap"> |
178 | 178 | <div class="sensei-analysis-sidebar"> |
179 | 179 | <?php |
180 | - do_action( 'sensei_analysis_before_stats_boxes' ); |
|
181 | - foreach ( $sensei_analysis_overview->stats_boxes() as $key => $value ) { |
|
182 | - $this->render_stats_box( esc_html( $key ), esc_html( $value ) ); |
|
180 | + do_action('sensei_analysis_before_stats_boxes'); |
|
181 | + foreach ($sensei_analysis_overview->stats_boxes() as $key => $value) { |
|
182 | + $this->render_stats_box(esc_html($key), esc_html($value)); |
|
183 | 183 | } // End For Loop |
184 | - do_action( 'sensei_analysis_after_stats_boxes' ); |
|
184 | + do_action('sensei_analysis_after_stats_boxes'); |
|
185 | 185 | ?> |
186 | 186 | </div> |
187 | 187 | <div class="sensei-analysis-main"> |
188 | 188 | <?php $sensei_analysis_overview->display(); ?> |
189 | 189 | </div> |
190 | 190 | <div class="sensei-analysis-extra"> |
191 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
191 | + <?php do_action('sensei_analysis_extra'); ?> |
|
192 | 192 | </div> |
193 | 193 | </div> |
194 | 194 | <?php |
195 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
196 | - do_action( 'analysis_after_container' ); |
|
195 | + do_action('analysis_wrapper_container', 'bottom'); |
|
196 | + do_action('analysis_after_container'); |
|
197 | 197 | } // End analysis_default_view() |
198 | 198 | |
199 | 199 | /** |
@@ -202,26 +202,26 @@ discard block |
||
202 | 202 | * @param integer $user_id |
203 | 203 | * @return void |
204 | 204 | */ |
205 | - public function analysis_user_profile_view( $user_id ) { |
|
205 | + public function analysis_user_profile_view($user_id) { |
|
206 | 206 | |
207 | 207 | // Load Analysis data |
208 | - $sensei_analysis_user_profile = $this->load_data_object( 'User_Profile', $user_id ); |
|
208 | + $sensei_analysis_user_profile = $this->load_data_object('User_Profile', $user_id); |
|
209 | 209 | // Wrappers |
210 | - do_action( 'analysis_before_container' ); |
|
211 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
212 | - $this->analysis_headers( array( 'nav' => 'user_profile' ) ); |
|
210 | + do_action('analysis_before_container'); |
|
211 | + do_action('analysis_wrapper_container', 'top'); |
|
212 | + $this->analysis_headers(array('nav' => 'user_profile')); |
|
213 | 213 | ?> |
214 | 214 | <div id="poststuff" class="sensei-analysis-wrap user-profile"> |
215 | 215 | <div class="sensei-analysis-main"> |
216 | 216 | <?php $sensei_analysis_user_profile->display(); ?> |
217 | 217 | </div> |
218 | 218 | <div class="sensei-analysis-extra"> |
219 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
219 | + <?php do_action('sensei_analysis_extra'); ?> |
|
220 | 220 | </div> |
221 | 221 | </div> |
222 | 222 | <?php |
223 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
224 | - do_action( 'analysis_after_container' ); |
|
223 | + do_action('analysis_wrapper_container', 'bottom'); |
|
224 | + do_action('analysis_after_container'); |
|
225 | 225 | } // End analysis_user_profile_view() |
226 | 226 | |
227 | 227 | /** |
@@ -230,26 +230,26 @@ discard block |
||
230 | 230 | * @param integer $course_id |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function analysis_course_view( $course_id ) { |
|
233 | + public function analysis_course_view($course_id) { |
|
234 | 234 | |
235 | 235 | // Load Analysis data |
236 | - $sensei_analysis_course = $this->load_data_object( 'Course', $course_id ); |
|
236 | + $sensei_analysis_course = $this->load_data_object('Course', $course_id); |
|
237 | 237 | // Wrappers |
238 | - do_action( 'analysis_before_container' ); |
|
239 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
240 | - $this->analysis_headers( array( 'nav' => 'course' ) ); |
|
238 | + do_action('analysis_before_container'); |
|
239 | + do_action('analysis_wrapper_container', 'top'); |
|
240 | + $this->analysis_headers(array('nav' => 'course')); |
|
241 | 241 | ?> |
242 | 242 | <div id="poststuff" class="sensei-analysis-wrap course-profile"> |
243 | 243 | <div class="sensei-analysis-main"> |
244 | 244 | <?php $sensei_analysis_course->display(); ?> |
245 | 245 | </div> |
246 | 246 | <div class="sensei-analysis-extra"> |
247 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
247 | + <?php do_action('sensei_analysis_extra'); ?> |
|
248 | 248 | </div> |
249 | 249 | </div> |
250 | 250 | <?php |
251 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
252 | - do_action( 'analysis_after_container' ); |
|
251 | + do_action('analysis_wrapper_container', 'bottom'); |
|
252 | + do_action('analysis_after_container'); |
|
253 | 253 | } // End analysis_course_view() |
254 | 254 | |
255 | 255 | /** |
@@ -259,26 +259,26 @@ discard block |
||
259 | 259 | * @param integer $user_id |
260 | 260 | * @return void |
261 | 261 | */ |
262 | - public function analysis_user_course_view( $course_id, $user_id ) { |
|
262 | + public function analysis_user_course_view($course_id, $user_id) { |
|
263 | 263 | |
264 | 264 | // Load Analysis data |
265 | - $sensei_analysis_user_course = $this->load_data_object( 'Course', $course_id, $user_id ); |
|
265 | + $sensei_analysis_user_course = $this->load_data_object('Course', $course_id, $user_id); |
|
266 | 266 | // Wrappers |
267 | - do_action( 'analysis_before_container' ); |
|
268 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
269 | - $this->analysis_headers( array( 'nav' => 'user_course' ) ); |
|
267 | + do_action('analysis_before_container'); |
|
268 | + do_action('analysis_wrapper_container', 'top'); |
|
269 | + $this->analysis_headers(array('nav' => 'user_course')); |
|
270 | 270 | ?> |
271 | 271 | <div id="poststuff" class="sensei-analysis-wrap course-profile"> |
272 | 272 | <div class="sensei-analysis-main"> |
273 | 273 | <?php $sensei_analysis_user_course->display(); ?> |
274 | 274 | </div> |
275 | 275 | <div class="sensei-analysis-extra"> |
276 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
276 | + <?php do_action('sensei_analysis_extra'); ?> |
|
277 | 277 | </div> |
278 | 278 | </div> |
279 | 279 | <?php |
280 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
281 | - do_action( 'analysis_after_container' ); |
|
280 | + do_action('analysis_wrapper_container', 'bottom'); |
|
281 | + do_action('analysis_after_container'); |
|
282 | 282 | } // End analysis_user_course_view() |
283 | 283 | |
284 | 284 | /** |
@@ -287,26 +287,26 @@ discard block |
||
287 | 287 | * @param integer $course_id |
288 | 288 | * @return void |
289 | 289 | */ |
290 | - public function analysis_course_users_view( $course_id ) { |
|
290 | + public function analysis_course_users_view($course_id) { |
|
291 | 291 | |
292 | 292 | // Load Analysis data |
293 | - $sensei_analysis_course_users = $this->load_data_object( 'Course', $course_id ); |
|
293 | + $sensei_analysis_course_users = $this->load_data_object('Course', $course_id); |
|
294 | 294 | // Wrappers |
295 | - do_action( 'analysis_before_container' ); |
|
296 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
297 | - $this->analysis_headers( array( 'nav' => 'course_users' ) ); |
|
295 | + do_action('analysis_before_container'); |
|
296 | + do_action('analysis_wrapper_container', 'top'); |
|
297 | + $this->analysis_headers(array('nav' => 'course_users')); |
|
298 | 298 | ?> |
299 | 299 | <div id="poststuff" class="sensei-analysis-wrap course-profile"> |
300 | 300 | <div class="sensei-analysis-main"> |
301 | 301 | <?php $sensei_analysis_course_users->display(); ?> |
302 | 302 | </div> |
303 | 303 | <div class="sensei-analysis-extra"> |
304 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
304 | + <?php do_action('sensei_analysis_extra'); ?> |
|
305 | 305 | </div> |
306 | 306 | </div> |
307 | 307 | <?php |
308 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
309 | - do_action( 'analysis_after_container' ); |
|
308 | + do_action('analysis_wrapper_container', 'bottom'); |
|
309 | + do_action('analysis_after_container'); |
|
310 | 310 | } // End analysis_course_users_view() |
311 | 311 | |
312 | 312 | /** |
@@ -315,26 +315,26 @@ discard block |
||
315 | 315 | * @param integer $lesson_id |
316 | 316 | * @return void |
317 | 317 | */ |
318 | - public function analysis_lesson_users_view( $lesson_id ) { |
|
318 | + public function analysis_lesson_users_view($lesson_id) { |
|
319 | 319 | |
320 | 320 | // Load Analysis data |
321 | - $sensei_analysis_lesson_users = $this->load_data_object( 'Lesson', $lesson_id ); |
|
321 | + $sensei_analysis_lesson_users = $this->load_data_object('Lesson', $lesson_id); |
|
322 | 322 | // Wrappers |
323 | - do_action( 'analysis_before_container' ); |
|
324 | - do_action( 'analysis_wrapper_container', 'top' ); |
|
325 | - $this->analysis_headers( array( 'nav' => 'lesson_users' ) ); |
|
323 | + do_action('analysis_before_container'); |
|
324 | + do_action('analysis_wrapper_container', 'top'); |
|
325 | + $this->analysis_headers(array('nav' => 'lesson_users')); |
|
326 | 326 | ?> |
327 | 327 | <div id="poststuff" class="sensei-analysis-wrap course-profile"> |
328 | 328 | <div class="sensei-analysis-main"> |
329 | 329 | <?php $sensei_analysis_lesson_users->display(); ?> |
330 | 330 | </div> |
331 | 331 | <div class="sensei-analysis-extra"> |
332 | - <?php do_action( 'sensei_analysis_extra' ); ?> |
|
332 | + <?php do_action('sensei_analysis_extra'); ?> |
|
333 | 333 | </div> |
334 | 334 | </div> |
335 | 335 | <?php |
336 | - do_action( 'analysis_wrapper_container', 'bottom' ); |
|
337 | - do_action( 'analysis_after_container' ); |
|
336 | + do_action('analysis_wrapper_container', 'bottom'); |
|
337 | + do_action('analysis_after_container'); |
|
338 | 338 | } // End analysis_lesson_users_view() |
339 | 339 | |
340 | 340 | /** |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @param $data string stats data |
345 | 345 | * @return void |
346 | 346 | */ |
347 | - public function render_stats_box( $title, $data ) { |
|
347 | + public function render_stats_box($title, $data) { |
|
348 | 348 | ?><div class="postbox"> |
349 | 349 | <h2><span><?php echo $title; ?></span></h2> |
350 | 350 | <div class="inside"> |
@@ -358,14 +358,14 @@ discard block |
||
358 | 358 | * @since 1.2.0 |
359 | 359 | * @return void |
360 | 360 | */ |
361 | - public function analysis_headers( $args = array( 'nav' => 'default' ) ) { |
|
361 | + public function analysis_headers($args = array('nav' => 'default')) { |
|
362 | 362 | |
363 | - $function = 'analysis_' . $args['nav'] . '_nav'; |
|
363 | + $function = 'analysis_'.$args['nav'].'_nav'; |
|
364 | 364 | $this->$function(); |
365 | 365 | ?> |
366 | 366 | <p class="powered-by-woo"> |
367 | 367 | |
368 | - <?php _e( 'Powered by', 'woothemes-sensei' ); ?> |
|
368 | + <?php _e('Powered by', 'woothemes-sensei'); ?> |
|
369 | 369 | |
370 | 370 | <a href="http://www.woothemes.com/" title="WooThemes"> |
371 | 371 | |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | </p> |
377 | 377 | |
378 | 378 | <?php |
379 | - do_action( 'sensei_analysis_after_headers' ); |
|
379 | + do_action('sensei_analysis_after_headers'); |
|
380 | 380 | } // End analysis_headers() |
381 | 381 | |
382 | 382 | /** |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | * @param $which string |
386 | 386 | * @return void |
387 | 387 | */ |
388 | - public function wrapper_container( $which ) { |
|
389 | - if ( 'top' == $which ) { |
|
388 | + public function wrapper_container($which) { |
|
389 | + if ('top' == $which) { |
|
390 | 390 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php |
391 | - } elseif ( 'bottom' == $which ) { |
|
391 | + } elseif ('bottom' == $which) { |
|
392 | 392 | ?></div><!--/#woothemes-sensei--><?php |
393 | 393 | } // End If Statement |
394 | 394 | } // End wrapper_container() |
@@ -400,24 +400,24 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function analysis_default_nav() { |
402 | 402 | |
403 | - $title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
404 | - $view = isset($_GET['view']) ? esc_html( $_GET['view'] ) : ''; |
|
405 | - switch ( $view ) { |
|
403 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
404 | + $view = isset($_GET['view']) ? esc_html($_GET['view']) : ''; |
|
405 | + switch ($view) { |
|
406 | 406 | case 'courses' : |
407 | - $title .= sprintf( ' <span class="course-title">> %s</span>', __( 'Courses', 'woothemes-sensei' ) ); |
|
407 | + $title .= sprintf(' <span class="course-title">> %s</span>', __('Courses', 'woothemes-sensei')); |
|
408 | 408 | break; |
409 | 409 | |
410 | 410 | case 'lessons' : |
411 | - $title .= sprintf( ' <span class="lesson-title">> %s</span>', __( 'Lessons', 'woothemes-sensei' ) ); |
|
411 | + $title .= sprintf(' <span class="lesson-title">> %s</span>', __('Lessons', 'woothemes-sensei')); |
|
412 | 412 | break; |
413 | 413 | |
414 | 414 | case 'users' : |
415 | 415 | default : |
416 | - $title .= sprintf( ' <span class="user-title">> %s</span>', __( 'Learners', 'woothemes-sensei' ) ); |
|
416 | + $title .= sprintf(' <span class="user-title">> %s</span>', __('Learners', 'woothemes-sensei')); |
|
417 | 417 | break; |
418 | 418 | } |
419 | 419 | ?> |
420 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
420 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
421 | 421 | <?php |
422 | 422 | } // End analysis_default_nav() |
423 | 423 | |
@@ -428,17 +428,17 @@ discard block |
||
428 | 428 | */ |
429 | 429 | public function analysis_user_profile_nav() { |
430 | 430 | |
431 | - $title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
432 | - if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
|
431 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
432 | + if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { |
|
433 | 433 | |
434 | - $user_id = intval( $_GET['user_id'] ); |
|
435 | - $url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) ); |
|
436 | - $user_name = Sensei_Learner::get_full_name( $user_id ); |
|
437 | - $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name ); |
|
434 | + $user_id = intval($_GET['user_id']); |
|
435 | + $url = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $user_id), admin_url('admin.php'))); |
|
436 | + $user_name = Sensei_Learner::get_full_name($user_id); |
|
437 | + $title .= sprintf(' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name); |
|
438 | 438 | |
439 | 439 | } // End If Statement |
440 | 440 | ?> |
441 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
441 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
442 | 442 | <?php |
443 | 443 | } // End analysis_user_profile_nav() |
444 | 444 | |
@@ -449,22 +449,22 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function analysis_user_course_nav() { |
451 | 451 | |
452 | - $title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
453 | - if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
|
454 | - $user_id = intval( $_GET['user_id'] ); |
|
455 | - $user_data = get_userdata( $user_id ); |
|
456 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) ); |
|
457 | - $user_name = Sensei_Learner::get_full_name( $user_id ); |
|
458 | - $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name ); |
|
459 | - $title .= sprintf( ' <span class="user-title">> <a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name ); |
|
452 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
453 | + if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { |
|
454 | + $user_id = intval($_GET['user_id']); |
|
455 | + $user_data = get_userdata($user_id); |
|
456 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $user_id), admin_url('admin.php')); |
|
457 | + $user_name = Sensei_Learner::get_full_name($user_id); |
|
458 | + $title .= sprintf(' <span class="user-title">> <a href="%s">%s</a></span>', $url, $user_name); |
|
459 | + $title .= sprintf(' <span class="user-title">> <a href="%s">%s</a></span>', esc_url($url), $user_data->display_name); |
|
460 | 460 | } // End If Statement |
461 | - if ( isset( $_GET['course_id'] ) ) { |
|
462 | - $course_id = intval( $_GET['course_id'] ); |
|
463 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
464 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
461 | + if (isset($_GET['course_id'])) { |
|
462 | + $course_id = intval($_GET['course_id']); |
|
463 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
464 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
465 | 465 | } |
466 | 466 | ?> |
467 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
467 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
468 | 468 | <?php |
469 | 469 | } // End analysis_user_course_nav() |
470 | 470 | |
@@ -475,14 +475,14 @@ discard block |
||
475 | 475 | */ |
476 | 476 | public function analysis_course_nav() { |
477 | 477 | |
478 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
479 | - if ( isset( $_GET['course_id'] ) ) { |
|
480 | - $course_id = intval( $_GET['course_id'] ); |
|
481 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
482 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>',esc_url( $url ), get_the_title( $course_id ) ); |
|
478 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
479 | + if (isset($_GET['course_id'])) { |
|
480 | + $course_id = intval($_GET['course_id']); |
|
481 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
482 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
483 | 483 | } |
484 | 484 | ?> |
485 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
485 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
486 | 486 | <?php |
487 | 487 | } // End analysis_course_nav() |
488 | 488 | |
@@ -493,14 +493,14 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function analysis_course_users_nav() { |
495 | 495 | |
496 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
497 | - if ( isset( $_GET['course_id'] ) ) { |
|
498 | - $course_id = intval( $_GET['course_id'] ); |
|
499 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
500 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
496 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
497 | + if (isset($_GET['course_id'])) { |
|
498 | + $course_id = intval($_GET['course_id']); |
|
499 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
500 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
501 | 501 | } |
502 | 502 | ?> |
503 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
503 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
504 | 504 | <?php |
505 | 505 | } // End analysis_course_users_nav() |
506 | 506 | |
@@ -511,17 +511,17 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function analysis_lesson_users_nav() { |
513 | 513 | |
514 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
515 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
516 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
517 | - $course_id = intval( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
518 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
519 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
520 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); |
|
521 | - $title .= sprintf( ' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) ); |
|
514 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
515 | + if (isset($_GET['lesson_id'])) { |
|
516 | + $lesson_id = intval($_GET['lesson_id']); |
|
517 | + $course_id = intval(get_post_meta($lesson_id, '_lesson_course', true)); |
|
518 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
519 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
520 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php')); |
|
521 | + $title .= sprintf(' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id)); |
|
522 | 522 | } |
523 | 523 | ?> |
524 | - <h1><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h1> |
|
524 | + <h1><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h1> |
|
525 | 525 | <?php |
526 | 526 | } // End analysis_lesson_users_nav() |
527 | 527 | |
@@ -532,59 +532,59 @@ discard block |
||
532 | 532 | */ |
533 | 533 | public function report_download_page() { |
534 | 534 | // Check if is a report |
535 | - if ( !empty( $_GET['sensei_report_download'] ) ) { |
|
536 | - $report = sanitize_text_field( $_GET['sensei_report_download'] ); |
|
535 | + if ( ! empty($_GET['sensei_report_download'])) { |
|
536 | + $report = sanitize_text_field($_GET['sensei_report_download']); |
|
537 | 537 | |
538 | 538 | // Simple verification to ensure intent, Note that a Nonce is per user, so the URL can't be shared |
539 | - if ( !wp_verify_nonce( $_REQUEST['_sdl_nonce'], 'sensei_csv_download-' . $report ) ) { |
|
540 | - wp_die( __('Invalid request', 'woothemes-sensei') ); |
|
539 | + if ( ! wp_verify_nonce($_REQUEST['_sdl_nonce'], 'sensei_csv_download-'.$report)) { |
|
540 | + wp_die(__('Invalid request', 'woothemes-sensei')); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | // Setup the variables we might need |
544 | - $filename = apply_filters( 'sensei_csv_export_filename', $report ); |
|
544 | + $filename = apply_filters('sensei_csv_export_filename', $report); |
|
545 | 545 | $course_id = 0; |
546 | 546 | $lesson_id = 0; |
547 | 547 | $user_id = 0; |
548 | - if( isset( $_GET['course_id'] ) ) { |
|
549 | - $course_id = intval( $_GET['course_id'] ); |
|
548 | + if (isset($_GET['course_id'])) { |
|
549 | + $course_id = intval($_GET['course_id']); |
|
550 | 550 | } |
551 | - if( isset( $_GET['lesson_id'] ) ) { |
|
552 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
551 | + if (isset($_GET['lesson_id'])) { |
|
552 | + $lesson_id = intval($_GET['lesson_id']); |
|
553 | 553 | } |
554 | - if( isset( $_GET['user_id'] ) ) { |
|
555 | - $user_id = intval( $_GET['user_id'] ); |
|
554 | + if (isset($_GET['user_id'])) { |
|
555 | + $user_id = intval($_GET['user_id']); |
|
556 | 556 | } |
557 | - $type = isset( $_GET['view'] ) ? esc_html( $_GET['view'] ) : false; |
|
557 | + $type = isset($_GET['view']) ? esc_html($_GET['view']) : false; |
|
558 | 558 | |
559 | - if ( 0 < $lesson_id ) { |
|
559 | + if (0 < $lesson_id) { |
|
560 | 560 | // Viewing a specific Lesson and all its Learners |
561 | - $sensei_analysis_report_object = $this->load_report_object( 'Lesson', $lesson_id ); |
|
561 | + $sensei_analysis_report_object = $this->load_report_object('Lesson', $lesson_id); |
|
562 | 562 | } |
563 | - elseif ( 0 < $course_id && 0 < $user_id ) { |
|
563 | + elseif (0 < $course_id && 0 < $user_id) { |
|
564 | 564 | // Viewing a specific User on a specific Course |
565 | - $sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id, $user_id ); |
|
565 | + $sensei_analysis_report_object = $this->load_report_object('Course', $course_id, $user_id); |
|
566 | 566 | } |
567 | - elseif( 0 < $course_id ) { |
|
567 | + elseif (0 < $course_id) { |
|
568 | 568 | // Viewing a specific Course and all it's Lessons, or it's Learners |
569 | - $sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id ); |
|
569 | + $sensei_analysis_report_object = $this->load_report_object('Course', $course_id); |
|
570 | 570 | } |
571 | - elseif ( 0 < $user_id ) { |
|
571 | + elseif (0 < $user_id) { |
|
572 | 572 | // Viewing a specific Learner, and their Courses |
573 | - $sensei_analysis_report_object = $this->load_report_object( 'User_Profile', $user_id ); |
|
573 | + $sensei_analysis_report_object = $this->load_report_object('User_Profile', $user_id); |
|
574 | 574 | } |
575 | 575 | else { |
576 | 576 | // Overview of all Learners, all Courses, or all Lessons |
577 | - $sensei_analysis_report_object = $this->load_report_object( 'Overview', $type ); |
|
577 | + $sensei_analysis_report_object = $this->load_report_object('Overview', $type); |
|
578 | 578 | } // End If Statement |
579 | 579 | |
580 | 580 | // Handle the headers |
581 | - $this->report_set_headers( $filename ); |
|
581 | + $this->report_set_headers($filename); |
|
582 | 582 | |
583 | 583 | // Collate the data, there could be many different reports for a single object |
584 | - $report_data_array = $sensei_analysis_report_object->generate_report( $report ); |
|
584 | + $report_data_array = $sensei_analysis_report_object->generate_report($report); |
|
585 | 585 | |
586 | 586 | // Output the data |
587 | - $this->report_write_download( $report_data_array ); |
|
587 | + $this->report_write_download($report_data_array); |
|
588 | 588 | |
589 | 589 | // Cleanly exit |
590 | 590 | exit; |
@@ -597,9 +597,9 @@ discard block |
||
597 | 597 | * @param string $filename name of report file |
598 | 598 | * @return void |
599 | 599 | */ |
600 | - public function report_set_headers( $filename = '' ) { |
|
601 | - header( 'Content-Type: text/csv' ); |
|
602 | - header( 'Content-Disposition: attachment;filename=' . $filename . '.csv'); |
|
600 | + public function report_set_headers($filename = '') { |
|
601 | + header('Content-Type: text/csv'); |
|
602 | + header('Content-Disposition: attachment;filename='.$filename.'.csv'); |
|
603 | 603 | } // End report_set_headers() |
604 | 604 | |
605 | 605 | /** |
@@ -610,12 +610,12 @@ discard block |
||
610 | 610 | * @param undefined $optional_data optional constructor arguments |
611 | 611 | * @return object class instance object |
612 | 612 | */ |
613 | - public function load_report_object( $name = '', $data = 0, $optional_data = null ) { |
|
614 | - $object_name = 'WooThemes_Sensei_Analysis_' . $name . '_List_Table'; |
|
615 | - if ( is_null($optional_data) ) { |
|
616 | - $sensei_analysis_report_object = new $object_name( $data ); |
|
613 | + public function load_report_object($name = '', $data = 0, $optional_data = null) { |
|
614 | + $object_name = 'WooThemes_Sensei_Analysis_'.$name.'_List_Table'; |
|
615 | + if (is_null($optional_data)) { |
|
616 | + $sensei_analysis_report_object = new $object_name($data); |
|
617 | 617 | } else { |
618 | - $sensei_analysis_report_object = new $object_name( $data, $optional_data ); |
|
618 | + $sensei_analysis_report_object = new $object_name($data, $optional_data); |
|
619 | 619 | } |
620 | 620 | return $sensei_analysis_report_object; |
621 | 621 | } // End load_report_object() |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | * @param array $report_data data array |
627 | 627 | * @return void |
628 | 628 | */ |
629 | - public function report_write_download( $report_data = array() ) { |
|
629 | + public function report_write_download($report_data = array()) { |
|
630 | 630 | $fp = fopen('php://output', 'w'); |
631 | 631 | foreach ($report_data as $row) { |
632 | 632 | fputcsv($fp, $row); |
@@ -642,9 +642,9 @@ discard block |
||
642 | 642 | * @param object $user_query_object WP_User_Query Object |
643 | 643 | * @return array $search_columns array of user columns to search |
644 | 644 | */ |
645 | - public function user_search_columns_filter( $search_columns, $search, $user_query_object ) { |
|
645 | + public function user_search_columns_filter($search_columns, $search, $user_query_object) { |
|
646 | 646 | // Alter $search_columns to include the fields you want to search on |
647 | - array_push( $search_columns, 'display_name' ); |
|
647 | + array_push($search_columns, 'display_name'); |
|
648 | 648 | return $search_columns; |
649 | 649 | } |
650 | 650 |
@@ -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 | * Generic Data Table parent Class in Sensei. |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | * @since 1.2.0 |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function __construct ( $token ) { |
|
59 | + public function __construct($token) { |
|
60 | 60 | // Class Variables |
61 | 61 | $this->token = $token; |
62 | 62 | |
63 | - parent::__construct( array( |
|
64 | - 'singular' => 'wp_list_table_' . $this->token, // Singular label |
|
65 | - 'plural' => 'wp_list_table_' . $this->token . 's', // Plural label |
|
63 | + parent::__construct(array( |
|
64 | + 'singular' => 'wp_list_table_'.$this->token, // Singular label |
|
65 | + 'plural' => 'wp_list_table_'.$this->token.'s', // Plural label |
|
66 | 66 | 'ajax' => false // No Ajax for this table |
67 | - ) ); |
|
67 | + )); |
|
68 | 68 | |
69 | 69 | // Actions |
70 | - add_action( 'sensei_before_list_table', array( $this, 'table_search_form' ), 5 ); |
|
70 | + add_action('sensei_before_list_table', array($this, 'table_search_form'), 5); |
|
71 | 71 | |
72 | 72 | } // End __construct() |
73 | 73 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param array $columns Existing columns |
77 | 77 | * @return array Modified columns |
78 | 78 | */ |
79 | - public function remove_sortable_columns( $columns ) { |
|
79 | + public function remove_sortable_columns($columns) { |
|
80 | 80 | return array(); |
81 | 81 | } |
82 | 82 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | * @since 1.2.0 |
86 | 86 | * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list |
87 | 87 | */ |
88 | - public function extra_tablenav( $which ) { |
|
89 | - if ( $which == "top" ){ |
|
88 | + public function extra_tablenav($which) { |
|
89 | + if ($which == "top") { |
|
90 | 90 | //The code that goes before the table is here |
91 | - do_action( 'sensei_before_list_table' ); |
|
91 | + do_action('sensei_before_list_table'); |
|
92 | 92 | } // End If Statement |
93 | - if ( $which == "bottom" ){ |
|
93 | + if ($which == "bottom") { |
|
94 | 94 | //The code that goes after the table is there |
95 | - do_action( 'sensei_after_list_table' ); |
|
95 | + do_action('sensei_after_list_table'); |
|
96 | 96 | } // End If Statement |
97 | 97 | } // End extra_tablenav() |
98 | 98 | |
@@ -102,22 +102,22 @@ discard block |
||
102 | 102 | * @return void |
103 | 103 | */ |
104 | 104 | public function table_search_form() { |
105 | - if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) { |
|
105 | + if (empty($_REQUEST['s']) && ! $this->has_items()) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | ?><form method="get"> |
109 | 109 | <?php |
110 | - if( isset( $_GET ) && count( $_GET ) > 0 ) { |
|
111 | - foreach( $_GET as $k => $v ) { |
|
112 | - if( 's' != $k ) { ?> |
|
110 | + if (isset($_GET) && count($_GET) > 0) { |
|
111 | + foreach ($_GET as $k => $v) { |
|
112 | + if ('s' != $k) { ?> |
|
113 | 113 | |
114 | - <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" /> |
|
114 | + <input type="hidden" name="<?php echo esc_attr($k); ?>" value="<?php echo esc_attr($v); ?>" /> |
|
115 | 115 | |
116 | 116 | <?php } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | ?> |
120 | - <?php $this->search_box( __( 'Search Users' ,'woothemes-sensei' ), 'search_id'); ?> |
|
120 | + <?php $this->search_box(__('Search Users', 'woothemes-sensei'), 'search_id'); ?> |
|
121 | 121 | </form><?php |
122 | 122 | } // End table_search_form() |
123 | 123 | |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | * @return array |
146 | 146 | */ |
147 | 147 | function get_column_info() { |
148 | - if ( isset( $this->_column_headers ) ) |
|
148 | + if (isset($this->_column_headers)) |
|
149 | 149 | return $this->_column_headers; |
150 | 150 | |
151 | 151 | $columns = $this->get_columns(); |
152 | - $hidden = get_hidden_columns( $this->screen ); |
|
152 | + $hidden = get_hidden_columns($this->screen); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Filter the list table sortable columns for a specific screen. |
@@ -161,22 +161,22 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param array $sortable_columns An array of sortable columns. |
163 | 163 | */ |
164 | - $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $this->get_sortable_columns() ); |
|
164 | + $_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $this->get_sortable_columns()); |
|
165 | 165 | |
166 | 166 | $sortable = array(); |
167 | - foreach ( $_sortable as $id => $data ) { |
|
168 | - if ( empty( $data ) ) |
|
167 | + foreach ($_sortable as $id => $data) { |
|
168 | + if (empty($data)) |
|
169 | 169 | continue; |
170 | 170 | |
171 | 171 | $data = (array) $data; |
172 | - if ( !isset( $data[1] ) ) |
|
172 | + if ( ! isset($data[1])) |
|
173 | 173 | $data[1] = false; |
174 | 174 | |
175 | 175 | $sortable[$id] = $data; |
176 | 176 | } |
177 | 177 | |
178 | 178 | $primary = $this->get_primary_column_name(); |
179 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
179 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
180 | 180 | |
181 | 181 | return $this->_column_headers; |
182 | 182 | } |
@@ -187,27 +187,27 @@ discard block |
||
187 | 187 | * @since 1.7.0 |
188 | 188 | * @param object $item The current item |
189 | 189 | */ |
190 | - function single_row( $item ) { |
|
190 | + function single_row($item) { |
|
191 | 191 | static $row_class = ''; |
192 | - $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); |
|
192 | + $row_class = ($row_class == '' ? ' class="alternate"' : ''); |
|
193 | 193 | |
194 | - echo '<tr' . $row_class . '>'; |
|
194 | + echo '<tr'.$row_class.'>'; |
|
195 | 195 | |
196 | - $column_data = $this->get_row_data( $item ); |
|
196 | + $column_data = $this->get_row_data($item); |
|
197 | 197 | |
198 | - list( $columns, $hidden ) = $this->get_column_info(); |
|
198 | + list($columns, $hidden) = $this->get_column_info(); |
|
199 | 199 | |
200 | - foreach ( $columns as $column_name => $column_display_name ) { |
|
200 | + foreach ($columns as $column_name => $column_display_name) { |
|
201 | 201 | $class = "class='$column_name column-$column_name'"; |
202 | 202 | |
203 | 203 | $style = ''; |
204 | - if ( in_array( $column_name, $hidden ) ) |
|
204 | + if (in_array($column_name, $hidden)) |
|
205 | 205 | $style = ' style="display:none;"'; |
206 | 206 | |
207 | 207 | $attributes = "$class$style"; |
208 | 208 | |
209 | 209 | echo "<td $attributes>"; |
210 | - if ( isset($column_data[$column_name]) ) { |
|
210 | + if (isset($column_data[$column_name])) { |
|
211 | 211 | echo $column_data[$column_name]; |
212 | 212 | } |
213 | 213 | echo "</td>"; |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @access public |
222 | 222 | * @abstract |
223 | 223 | */ |
224 | - protected function get_row_data( $item ) { |
|
225 | - die( 'either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.' ); |
|
224 | + protected function get_row_data($item) { |
|
225 | + die('either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | function no_items() { |
235 | 235 | |
236 | - _e( 'No items found.', 'woothemes-sensei' ); |
|
236 | + _e('No items found.', 'woothemes-sensei'); |
|
237 | 237 | |
238 | 238 | } // End no_items() |
239 | 239 | |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | * @since 1.2.0 |
252 | 252 | * @return void |
253 | 253 | */ |
254 | - public function bulk_actions( $which = '' ) { |
|
254 | + public function bulk_actions($which = '') { |
|
255 | 255 | // This will be output Above the table headers on the left |
256 | - echo apply_filters( 'sensei_list_bulk_actions', '' ); |
|
256 | + echo apply_filters('sensei_list_bulk_actions', ''); |
|
257 | 257 | } // End bulk_actions() |
258 | 258 | |
259 | 259 | } // End Class |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Updates Class |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | // Setup object data |
33 | 33 | $this->parent = $parent; |
34 | - $this->updates_run = get_option( 'woothemes-sensei-upgrades', array() ); |
|
34 | + $this->updates_run = get_option('woothemes-sensei-upgrades', array()); |
|
35 | 35 | |
36 | 36 | // The list of upgrades to run |
37 | 37 | $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | ), |
76 | 76 | ); |
77 | 77 | |
78 | - $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
|
79 | - $this->version = get_option( 'woothemes-sensei-version' ); |
|
78 | + $this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates); |
|
79 | + $this->version = get_option('woothemes-sensei-version'); |
|
80 | 80 | |
81 | 81 | // Manual Update Screen |
82 | 82 | add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | <h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2> |
121 | 121 | |
122 | 122 | <?php |
123 | - $function_name= ''; |
|
124 | - if ( isset($_GET['action']) && $_GET['action'] == 'update' |
|
123 | + $function_name = ''; |
|
124 | + if (isset($_GET['action']) && $_GET['action'] == 'update' |
|
125 | 125 | && isset($_GET['n']) && intval($_GET['n']) >= 0 |
126 | - && ( (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
126 | + && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
127 | 127 | |
128 | 128 | // Setup the data variables |
129 | 129 | $n = intval($_GET['n']); |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | |
136 | 136 | foreach ($_POST['checked'] as $key => $function_name) { |
137 | 137 | |
138 | - if( ! isset( $_POST[ $function_name.'_nonce_field' ] ) |
|
139 | - || ! wp_verify_nonce( $_POST[ $function_name.'_nonce_field' ] , 'run_'.$function_name ) ){ |
|
138 | + if ( ! isset($_POST[$function_name.'_nonce_field']) |
|
139 | + || ! wp_verify_nonce($_POST[$function_name.'_nonce_field'], 'run_'.$function_name)) { |
|
140 | 140 | |
141 | 141 | wp_die( |
142 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
143 | - '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
142 | + '<h1>'.__('Cheatin’ uh?').'</h1>'. |
|
143 | + '<p>'.__('The nonce supplied in order to run this update function is invalid', 'woothemes-sensei').'</p>', |
|
144 | 144 | 403 |
145 | 145 | ); |
146 | 146 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | } else { |
159 | 159 | |
160 | - _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
160 | + _doing_it_wrong(esc_html($function_name), 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
161 | 161 | return; |
162 | 162 | |
163 | 163 | }// End If Statement |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | if ('' == $functions_list) { |
167 | 167 | $functions_list .= $function_name; |
168 | 168 | } else { |
169 | - $functions_list .= '+' . $function_name; |
|
169 | + $functions_list .= '+'.$function_name; |
|
170 | 170 | } // End If Statement |
171 | 171 | |
172 | 172 | // Mark update has having been run |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | |
185 | 185 | foreach ($functions_array as $key => $function_name) { |
186 | 186 | |
187 | - if( ! isset( $_GET[ $function_name.'_nonce' ] ) |
|
188 | - || ! wp_verify_nonce( $_GET[ $function_name.'_nonce' ] , 'run_'.$function_name ) ){ |
|
187 | + if ( ! isset($_GET[$function_name.'_nonce']) |
|
188 | + || ! wp_verify_nonce($_GET[$function_name.'_nonce'], 'run_'.$function_name)) { |
|
189 | 189 | |
190 | 190 | wp_die( |
191 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
192 | - '<p>' . __( 'The nonce supplied in order to run this update function is invalid','woothemes-sensei') . '</p>', |
|
191 | + '<h1>'.__('Cheatin’ uh?').'</h1>'. |
|
192 | + '<p>'.__('The nonce supplied in order to run this update function is invalid', 'woothemes-sensei').'</p>', |
|
193 | 193 | 403 |
194 | 194 | ); |
195 | 195 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | } else { |
208 | 208 | |
209 | - _doing_it_wrong( esc_html( $function_name) , 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
209 | + _doing_it_wrong(esc_html($function_name), 'Is not a valid Sensei updater function', 'Sensei 1.9.0'); |
|
210 | 210 | return; |
211 | 211 | |
212 | 212 | } // End If Statement |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | if ('' == $functions_list) { |
216 | 216 | $functions_list .= $function_name; |
217 | 217 | } else { |
218 | - $functions_list .= '+' . $function_name; |
|
218 | + $functions_list .= '+'.$function_name; |
|
219 | 219 | } // End If Statement |
220 | 220 | |
221 | 221 | $this->set_update_run($function_name); |
@@ -224,27 +224,27 @@ discard block |
||
224 | 224 | |
225 | 225 | } // End If Statement |
226 | 226 | |
227 | - if (!$done_processing) { ?> |
|
227 | + if ( ! $done_processing) { ?> |
|
228 | 228 | |
229 | 229 | <h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3> |
230 | 230 | |
231 | 231 | <p> |
232 | 232 | |
233 | - <?php _e( "If your browser doesn't start loading the next page automatically, click this button:", 'woothemes-sensei' ); ?> |
|
233 | + <?php _e("If your browser doesn't start loading the next page automatically, click this button:", 'woothemes-sensei'); ?> |
|
234 | 234 | |
235 | 235 | <?php |
236 | - $next_action_url = add_query_arg( array( |
|
236 | + $next_action_url = add_query_arg(array( |
|
237 | 237 | 'page' => 'sensei_updates', |
238 | 238 | 'action' => 'update', |
239 | 239 | 'n' => $n + 50, |
240 | - 'functions' => array( $functions_list ), |
|
241 | - $function_name.'_nonce' => wp_create_nonce( 'run_'. $function_name ), |
|
242 | - ), admin_url( 'admin.php' ) ); |
|
240 | + 'functions' => array($functions_list), |
|
241 | + $function_name.'_nonce' => wp_create_nonce('run_'.$function_name), |
|
242 | + ), admin_url('admin.php')); |
|
243 | 243 | ?> |
244 | 244 | |
245 | - <a class="button" href="<?php echo esc_url( $next_action_url ); ?>"> |
|
245 | + <a class="button" href="<?php echo esc_url($next_action_url); ?>"> |
|
246 | 246 | |
247 | - <?php _e( 'Next', 'woothemes-sensei' ); ?> |
|
247 | + <?php _e('Next', 'woothemes-sensei'); ?> |
|
248 | 248 | |
249 | 249 | </a> |
250 | 250 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | <script type='text/javascript'> |
253 | 253 | <!-- |
254 | 254 | function js_sensei_nextpage() { |
255 | - location.href = "<?php echo esc_url_raw( $next_action_url );?>"; |
|
255 | + location.href = "<?php echo esc_url_raw($next_action_url); ?>"; |
|
256 | 256 | } |
257 | 257 | setTimeout( "js_sensei_nextpage()", 250 ); |
258 | 258 | //--> |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | <td><p><?php echo $type_label; ?></p></td> |
332 | 332 | <td> |
333 | 333 | <p> |
334 | - <input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" |
|
334 | + <input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" |
|
335 | 335 | id="update-sensei" |
336 | - class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" |
|
336 | + class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" |
|
337 | 337 | type="submit" |
338 | - value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" |
|
338 | + value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" |
|
339 | 339 | name="update"> |
340 | 340 | |
341 | 341 | <?php |
342 | 342 | $nonce_action = 'run_'.$update; |
343 | 343 | $nonce_field_name = $update.'_nonce_field'; |
344 | - wp_nonce_field( $nonce_action, $nonce_field_name, false, true ); |
|
344 | + wp_nonce_field($nonce_action, $nonce_field_name, false, true); |
|
345 | 345 | ?> |
346 | 346 | </p> |
347 | 347 | </td> |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * |
376 | 376 | * @param string $function_name |
377 | 377 | */ |
378 | - public function function_in_whitelist( $function_name ){ |
|
378 | + public function function_in_whitelist($function_name) { |
|
379 | 379 | |
380 | 380 | $function_whitelist = array( |
381 | 381 | 'status_changes_convert_questions', |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | |
387 | 387 | ); |
388 | 388 | |
389 | - return in_array($function_name, $function_whitelist ); |
|
389 | + return in_array($function_name, $function_whitelist); |
|
390 | 390 | |
391 | 391 | }// end function_in_whitelist |
392 | 392 | |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | * @param string $b Second key |
398 | 398 | * @return integer |
399 | 399 | */ |
400 | - private function sort_updates( $a, $b ) { |
|
401 | - return strcmp( $a, $b ); |
|
400 | + private function sort_updates($a, $b) { |
|
401 | + return strcmp($a, $b); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -409,39 +409,39 @@ discard block |
||
409 | 409 | * @access public |
410 | 410 | * @return boolean |
411 | 411 | */ |
412 | - public function update ( $type = 'auto' ) { |
|
412 | + public function update($type = 'auto') { |
|
413 | 413 | |
414 | 414 | // Only allow admins to run update functions |
415 | - if( ! current_user_can( 'manage_options' ) ) { |
|
415 | + if ( ! current_user_can('manage_options')) { |
|
416 | 416 | return false; |
417 | 417 | } |
418 | 418 | |
419 | 419 | $this->force_updates(); |
420 | 420 | |
421 | 421 | // Run through all functions |
422 | - foreach ( $this->updates as $version => $value ) { |
|
423 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
424 | - if ( $upgrade_type == $type ) { |
|
422 | + foreach ($this->updates as $version => $value) { |
|
423 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
424 | + if ($upgrade_type == $type) { |
|
425 | 425 | $updated = false; |
426 | 426 | // Run the update function |
427 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
428 | - if ( isset( $function_name ) && '' != $function_name ) { |
|
429 | - if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
427 | + foreach ($function_to_run as $function_name => $update_data) { |
|
428 | + if (isset($function_name) && '' != $function_name) { |
|
429 | + if ( ! in_array($function_name, $this->updates_run)) { |
|
430 | 430 | $updated = false; |
431 | - if ( method_exists( $this, $function_name ) ) { |
|
431 | + if (method_exists($this, $function_name)) { |
|
432 | 432 | |
433 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
434 | - update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
|
433 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
434 | + update_option(Sensei()->token.'-upgrades', $this->updates_run); |
|
435 | 435 | return true; |
436 | 436 | |
437 | - } elseif( $this->function_in_whitelist( $function_name ) ) { |
|
437 | + } elseif ($this->function_in_whitelist($function_name)) { |
|
438 | 438 | |
439 | - $updated = call_user_func( $function_name ); |
|
439 | + $updated = call_user_func($function_name); |
|
440 | 440 | |
441 | 441 | } // End If Statement |
442 | 442 | |
443 | - if ( $updated ) { |
|
444 | - array_push( $this->updates_run, $function_name ); |
|
443 | + if ($updated) { |
|
444 | + array_push($this->updates_run, $function_name); |
|
445 | 445 | } // End If Statement |
446 | 446 | } |
447 | 447 | } // End If Statement |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | } // End For Loop |
451 | 451 | } // End For Loop |
452 | 452 | |
453 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
454 | - update_option( $this->token . '-upgrades', $this->updates_run ); |
|
453 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
454 | + update_option($this->token.'-upgrades', $this->updates_run); |
|
455 | 455 | |
456 | 456 | return true; |
457 | 457 | |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | |
460 | 460 | private function force_updates() { |
461 | 461 | |
462 | - if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) { |
|
462 | + if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) { |
|
463 | 463 | |
464 | 464 | // $skip_forced_updates = false; |
465 | 465 | // if( ! get_option( 'woothemes-sensei-force-updates', false ) ) { |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | |
469 | 469 | // Force critical updates if only if lessons already exist |
470 | 470 | $skip_forced_updates = false; |
471 | - $lesson_posts = wp_count_posts( 'lesson' ); |
|
472 | - if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) { |
|
471 | + $lesson_posts = wp_count_posts('lesson'); |
|
472 | + if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) { |
|
473 | 473 | $skip_forced_updates = true; |
474 | 474 | } |
475 | 475 | |
@@ -477,69 +477,69 @@ discard block |
||
477 | 477 | |
478 | 478 | $updates_to_run = array(); |
479 | 479 | |
480 | - foreach ( $this->updates as $version => $value ) { |
|
481 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
482 | - if ( $upgrade_type == 'forced' ) { |
|
483 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
480 | + foreach ($this->updates as $version => $value) { |
|
481 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
482 | + if ($upgrade_type == 'forced') { |
|
483 | + foreach ($function_to_run as $function_name => $update_data) { |
|
484 | 484 | |
485 | - if( $skip_forced_updates ) { |
|
486 | - $this->set_update_run( $function_name ); |
|
485 | + if ($skip_forced_updates) { |
|
486 | + $this->set_update_run($function_name); |
|
487 | 487 | continue; |
488 | 488 | } |
489 | 489 | |
490 | - $update_run = $this->has_update_run( $function_name ); |
|
490 | + $update_run = $this->has_update_run($function_name); |
|
491 | 491 | |
492 | - if( ! $update_run ) { |
|
492 | + if ( ! $update_run) { |
|
493 | 493 | $use_the_force = true; |
494 | - $updates_to_run[ $function_name ] = $update_data; |
|
494 | + $updates_to_run[$function_name] = $update_data; |
|
495 | 495 | } |
496 | 496 | } |
497 | 497 | } |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - if( $skip_forced_updates ) { |
|
501 | + if ($skip_forced_updates) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | - if( $use_the_force && 0 < count( $updates_to_run ) ) { |
|
505 | + if ($use_the_force && 0 < count($updates_to_run)) { |
|
506 | 506 | |
507 | - $update_title = __( 'Important Sensei updates required', 'woothemes-sensei' ); |
|
507 | + $update_title = __('Important Sensei updates required', 'woothemes-sensei'); |
|
508 | 508 | |
509 | - $update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n"; |
|
509 | + $update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n"; |
|
510 | 510 | |
511 | 511 | // $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n"; |
512 | 512 | |
513 | - $update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
513 | + $update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n"; |
|
514 | 514 | |
515 | - $update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
515 | + $update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n"; |
|
516 | 516 | |
517 | - $update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
517 | + $update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n"; |
|
518 | 518 | |
519 | - $update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
519 | + $update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n"; |
|
520 | 520 | |
521 | - $update_message .= '<ol>' . "\n"; |
|
521 | + $update_message .= '<ol>'."\n"; |
|
522 | 522 | |
523 | - foreach( $updates_to_run as $function => $data ) { |
|
523 | + foreach ($updates_to_run as $function => $data) { |
|
524 | 524 | |
525 | - if( ! isset( $data['title'] ) ) { |
|
525 | + if ( ! isset($data['title'])) { |
|
526 | 526 | break; |
527 | 527 | } |
528 | 528 | |
529 | - $update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>'; |
|
529 | + $update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>'; |
|
530 | 530 | } |
531 | 531 | |
532 | - $update_message .= '</ol>' . "\n"; |
|
532 | + $update_message .= '</ol>'."\n"; |
|
533 | 533 | |
534 | - switch( $version ) { |
|
534 | + switch ($version) { |
|
535 | 535 | |
536 | 536 | case '1.7.0': |
537 | - $update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n"; |
|
537 | + $update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n"; |
|
538 | 538 | break; |
539 | 539 | |
540 | 540 | } |
541 | 541 | |
542 | - wp_die( $update_message, $update_title ); |
|
542 | + wp_die($update_message, $update_title); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | } |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | * @since 1.4.0 |
552 | 552 | * @return boolean |
553 | 553 | */ |
554 | - private function has_update_run( $update ) { |
|
555 | - if ( in_array( $update, $this->updates_run ) ) { |
|
554 | + private function has_update_run($update) { |
|
555 | + if (in_array($update, $this->updates_run)) { |
|
556 | 556 | return true; |
557 | 557 | } |
558 | 558 | return false; |
@@ -564,10 +564,10 @@ discard block |
||
564 | 564 | * @param string $update Update to process |
565 | 565 | * @since 1.4.0 |
566 | 566 | */ |
567 | - private function set_update_run( $update ) { |
|
568 | - array_push( $this->updates_run, $update ); |
|
569 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
570 | - update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
|
567 | + private function set_update_run($update) { |
|
568 | + array_push($this->updates_run, $update); |
|
569 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
570 | + update_option(Sensei()->token.'-upgrades', $this->updates_run); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -578,15 +578,15 @@ discard block |
||
578 | 578 | * @return void |
579 | 579 | */ |
580 | 580 | public function assign_role_caps() { |
581 | - foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
|
582 | - foreach ( $role_cap_set as $role_key => $capabilities_array ) { |
|
581 | + foreach ($this->parent->post_types->role_caps as $role_cap_set) { |
|
582 | + foreach ($role_cap_set as $role_key => $capabilities_array) { |
|
583 | 583 | /* Get the role. */ |
584 | - $role = get_role( $role_key ); |
|
585 | - foreach ( $capabilities_array as $cap_name ) { |
|
584 | + $role = get_role($role_key); |
|
585 | + foreach ($capabilities_array as $cap_name) { |
|
586 | 586 | /* If the role exists, add required capabilities for the plugin. */ |
587 | - if ( !empty( $role ) ) { |
|
588 | - if ( !$role->has_cap( $cap_name ) ) { |
|
589 | - $role->add_cap( $cap_name ); |
|
587 | + if ( ! empty($role)) { |
|
588 | + if ( ! $role->has_cap($cap_name)) { |
|
589 | + $role->add_cap($cap_name); |
|
590 | 590 | } // End If Statement |
591 | 591 | } // End If Statement |
592 | 592 | } // End For Loop |
@@ -602,16 +602,16 @@ discard block |
||
602 | 602 | * @return void |
603 | 603 | */ |
604 | 604 | public function set_default_quiz_grade_type() { |
605 | - $args = array( 'post_type' => 'quiz', |
|
605 | + $args = array('post_type' => 'quiz', |
|
606 | 606 | 'posts_per_page' => -1, |
607 | 607 | 'post_status' => 'publish', |
608 | 608 | 'suppress_filters' => 0 |
609 | 609 | ); |
610 | - $quizzes = get_posts( $args ); |
|
610 | + $quizzes = get_posts($args); |
|
611 | 611 | |
612 | - foreach( $quizzes as $quiz ) { |
|
613 | - update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' ); |
|
614 | - update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' ); |
|
612 | + foreach ($quizzes as $quiz) { |
|
613 | + update_post_meta($quiz->ID, '_quiz_grade_type', 'auto'); |
|
614 | + update_post_meta($quiz->ID, '_quiz_grade_type_disabled', ''); |
|
615 | 615 | } |
616 | 616 | } // End set_default_quiz_grade_type |
617 | 617 | |
@@ -623,23 +623,23 @@ discard block |
||
623 | 623 | * @return void |
624 | 624 | */ |
625 | 625 | public function set_default_question_type() { |
626 | - $args = array( 'post_type' => 'question', |
|
626 | + $args = array('post_type' => 'question', |
|
627 | 627 | 'posts_per_page' => -1, |
628 | 628 | 'post_status' => 'publish', |
629 | 629 | 'suppress_filters' => 0 |
630 | 630 | ); |
631 | - $questions = get_posts( $args ); |
|
631 | + $questions = get_posts($args); |
|
632 | 632 | |
633 | 633 | $already_run = true; |
634 | - foreach( $questions as $question ) { |
|
635 | - if( $already_run ) { |
|
636 | - $terms = wp_get_post_terms( $question->ID, 'question-type' ); |
|
637 | - if( is_array( $terms ) && count( $terms ) > 0 ) { |
|
634 | + foreach ($questions as $question) { |
|
635 | + if ($already_run) { |
|
636 | + $terms = wp_get_post_terms($question->ID, 'question-type'); |
|
637 | + if (is_array($terms) && count($terms) > 0) { |
|
638 | 638 | break; |
639 | 639 | } |
640 | 640 | } |
641 | 641 | $already_run = false; |
642 | - wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' ); |
|
642 | + wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type'); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | } // End set_default_question_type |
@@ -651,90 +651,90 @@ discard block |
||
651 | 651 | * @access public |
652 | 652 | * @return boolean |
653 | 653 | */ |
654 | - public function update_question_answer_data( $n = 50, $offset = 0 ) { |
|
654 | + public function update_question_answer_data($n = 50, $offset = 0) { |
|
655 | 655 | |
656 | 656 | // Get Total Number of Updates to run |
657 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
657 | + $quiz_count_object = wp_count_posts('quiz'); |
|
658 | 658 | $quiz_count_published = $quiz_count_object->publish; |
659 | 659 | |
660 | 660 | // Calculate if this is the last page |
661 | - if ( 0 == $offset ) { |
|
661 | + if (0 == $offset) { |
|
662 | 662 | $current_page = 1; |
663 | 663 | } else { |
664 | - $current_page = intval( $offset / $n ); |
|
664 | + $current_page = intval($offset / $n); |
|
665 | 665 | } // End If Statement |
666 | - $total_pages = intval( $quiz_count_published / $n ); |
|
666 | + $total_pages = intval($quiz_count_published / $n); |
|
667 | 667 | |
668 | 668 | |
669 | - $args = array( 'post_type' => 'quiz', |
|
669 | + $args = array('post_type' => 'quiz', |
|
670 | 670 | 'posts_per_page' => $n, |
671 | 671 | 'offset' => $offset, |
672 | 672 | 'post_status' => 'publish', |
673 | 673 | 'suppress_filters' => 0 |
674 | 674 | ); |
675 | - $quizzes = get_posts( $args ); |
|
675 | + $quizzes = get_posts($args); |
|
676 | 676 | |
677 | 677 | $old_answers = array(); |
678 | 678 | $right_answers = array(); |
679 | 679 | $old_user_answers = array(); |
680 | 680 | |
681 | - if( is_array( $quizzes ) ) { |
|
682 | - foreach( $quizzes as $quiz ) { |
|
681 | + if (is_array($quizzes)) { |
|
682 | + foreach ($quizzes as $quiz) { |
|
683 | 683 | $quiz_id = $quiz->ID; |
684 | 684 | |
685 | 685 | // Get current user answers |
686 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true ); |
|
686 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true); |
|
687 | 687 | // Need to always return an array, even with only 1 item |
688 | - if ( !is_array($comments) ) { |
|
689 | - $comments = array( $comments ); |
|
688 | + if ( ! is_array($comments)) { |
|
689 | + $comments = array($comments); |
|
690 | 690 | } |
691 | - foreach ( $comments as $comment ) { |
|
691 | + foreach ($comments as $comment) { |
|
692 | 692 | $user_id = $comment->user_id; |
693 | - $content = maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
694 | - $old_user_answers[ $quiz_id ][ $user_id ] = $content; |
|
693 | + $content = maybe_unserialize(base64_decode($comment->comment_content)); |
|
694 | + $old_user_answers[$quiz_id][$user_id] = $content; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | // Get correct answers |
698 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
699 | - if( is_array( $questions ) ) { |
|
700 | - foreach( $questions as $question ) { |
|
701 | - $right_answer = get_post_meta( $question->ID, '_question_right_answer', true ); |
|
702 | - $right_answers[ $quiz_id ][ $question->ID ] = $right_answer; |
|
698 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
699 | + if (is_array($questions)) { |
|
700 | + foreach ($questions as $question) { |
|
701 | + $right_answer = get_post_meta($question->ID, '_question_right_answer', true); |
|
702 | + $right_answers[$quiz_id][$question->ID] = $right_answer; |
|
703 | 703 | } |
704 | 704 | } |
705 | 705 | } |
706 | 706 | } |
707 | 707 | |
708 | - if( is_array( $right_answers ) ) { |
|
709 | - foreach( $right_answers as $quiz_id => $question ) { |
|
708 | + if (is_array($right_answers)) { |
|
709 | + foreach ($right_answers as $quiz_id => $question) { |
|
710 | 710 | $count = 0; |
711 | - if( is_array( $question ) ) { |
|
712 | - foreach( $question as $question_id => $answer ) { |
|
711 | + if (is_array($question)) { |
|
712 | + foreach ($question as $question_id => $answer) { |
|
713 | 713 | ++$count; |
714 | - if( isset( $old_user_answers[ $quiz_id ] ) ) { |
|
715 | - $answers_linkup[ $quiz_id ][ $count ] = $question_id; |
|
714 | + if (isset($old_user_answers[$quiz_id])) { |
|
715 | + $answers_linkup[$quiz_id][$count] = $question_id; |
|
716 | 716 | } |
717 | 717 | } |
718 | 718 | } |
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
722 | - if( is_array( $old_user_answers ) ) { |
|
723 | - foreach( $old_user_answers as $quiz_id => $user_answers ) { |
|
724 | - foreach( $user_answers as $user_id => $answers ) { |
|
725 | - foreach( $answers as $answer_id => $user_answer ) { |
|
726 | - $question_id = $answers_linkup[ $quiz_id ][ $answer_id ]; |
|
727 | - $new_user_answers[ $question_id ] = $user_answer; |
|
728 | - Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id ); |
|
722 | + if (is_array($old_user_answers)) { |
|
723 | + foreach ($old_user_answers as $quiz_id => $user_answers) { |
|
724 | + foreach ($user_answers as $user_id => $answers) { |
|
725 | + foreach ($answers as $answer_id => $user_answer) { |
|
726 | + $question_id = $answers_linkup[$quiz_id][$answer_id]; |
|
727 | + $new_user_answers[$question_id] = $user_answer; |
|
728 | + Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id); |
|
729 | 729 | } |
730 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
731 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
732 | - Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id ); |
|
730 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
731 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
732 | + Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id); |
|
733 | 733 | } |
734 | 734 | } |
735 | 735 | } |
736 | 736 | |
737 | - if ( $current_page == $total_pages ) { |
|
737 | + if ($current_page == $total_pages) { |
|
738 | 738 | return true; |
739 | 739 | } else { |
740 | 740 | return false; |
@@ -749,15 +749,15 @@ discard block |
||
749 | 749 | * @return boolean |
750 | 750 | */ |
751 | 751 | public function update_question_grade_points() { |
752 | - $args = array( 'post_type' => 'question', |
|
752 | + $args = array('post_type' => 'question', |
|
753 | 753 | 'posts_per_page' => -1, |
754 | 754 | 'post_status' => 'publish', |
755 | 755 | 'suppress_filters' => 0 |
756 | 756 | ); |
757 | - $questions = get_posts( $args ); |
|
757 | + $questions = get_posts($args); |
|
758 | 758 | |
759 | - foreach( $questions as $question ) { |
|
760 | - update_post_meta( $question->ID, '_question_grade', '1' ); |
|
759 | + foreach ($questions as $question) { |
|
760 | + update_post_meta($question->ID, '_question_grade', '1'); |
|
761 | 761 | } |
762 | 762 | return true; |
763 | 763 | } // End update_question_grade_points |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | * @return boolean |
770 | 770 | */ |
771 | 771 | public function convert_essay_paste_questions() { |
772 | - $args = array( 'post_type' => 'question', |
|
772 | + $args = array('post_type' => 'question', |
|
773 | 773 | 'posts_per_page' => -1, |
774 | 774 | 'post_status' => 'publish', |
775 | 775 | 'tax_query' => array( |
@@ -781,14 +781,14 @@ discard block |
||
781 | 781 | ), |
782 | 782 | 'suppress_filters' => 0 |
783 | 783 | ); |
784 | - $questions = get_posts( $args ); |
|
784 | + $questions = get_posts($args); |
|
785 | 785 | |
786 | - foreach( $questions as $question ) { |
|
787 | - wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false ); |
|
786 | + foreach ($questions as $question) { |
|
787 | + wp_set_object_terms($question->ID, 'multi-line', 'question-type', false); |
|
788 | 788 | |
789 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
790 | - if( 0 < intval( $quiz_id ) ) { |
|
791 | - add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true ); |
|
789 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
790 | + if (0 < intval($quiz_id)) { |
|
791 | + add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true); |
|
792 | 792 | } |
793 | 793 | } |
794 | 794 | return true; |
@@ -800,33 +800,33 @@ discard block |
||
800 | 800 | * @since 1.5.0 |
801 | 801 | * @return boolean |
802 | 802 | */ |
803 | - public function set_random_question_order( $n = 50, $offset = 0 ) { |
|
803 | + public function set_random_question_order($n = 50, $offset = 0) { |
|
804 | 804 | |
805 | 805 | // Get Total Number of Updates to run |
806 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
806 | + $quiz_count_object = wp_count_posts('quiz'); |
|
807 | 807 | $quiz_count_published = $quiz_count_object->publish; |
808 | 808 | |
809 | 809 | // Calculate if this is the last page |
810 | - if ( 0 == $offset ) { |
|
810 | + if (0 == $offset) { |
|
811 | 811 | $current_page = 1; |
812 | 812 | } else { |
813 | - $current_page = intval( $offset / $n ); |
|
813 | + $current_page = intval($offset / $n); |
|
814 | 814 | } // End If Statement |
815 | - $total_pages = intval( $quiz_count_published / $n ); |
|
815 | + $total_pages = intval($quiz_count_published / $n); |
|
816 | 816 | |
817 | - $args = array( 'post_type' => 'quiz', |
|
817 | + $args = array('post_type' => 'quiz', |
|
818 | 818 | 'post_status' => 'any', |
819 | 819 | 'posts_per_page' => $n, |
820 | 820 | 'offset' => $offset, |
821 | 821 | 'suppress_filters' => 0 |
822 | 822 | ); |
823 | - $quizzes = get_posts( $args ); |
|
823 | + $quizzes = get_posts($args); |
|
824 | 824 | |
825 | - foreach( $quizzes as $quiz ) { |
|
826 | - update_post_meta( $quiz->ID, '_random_question_order', 'yes' ); |
|
825 | + foreach ($quizzes as $quiz) { |
|
826 | + update_post_meta($quiz->ID, '_random_question_order', 'yes'); |
|
827 | 827 | } |
828 | 828 | |
829 | - if ( $current_page == $total_pages ) { |
|
829 | + if ($current_page == $total_pages) { |
|
830 | 830 | return true; |
831 | 831 | } else { |
832 | 832 | return false; |
@@ -840,37 +840,37 @@ discard block |
||
840 | 840 | * @since 1.5.0 |
841 | 841 | * @return boolean |
842 | 842 | */ |
843 | - public function set_default_show_question_count( $n = 50, $offset = 0 ) { |
|
843 | + public function set_default_show_question_count($n = 50, $offset = 0) { |
|
844 | 844 | |
845 | - $args = array( 'post_type' => 'quiz', |
|
845 | + $args = array('post_type' => 'quiz', |
|
846 | 846 | 'post_status' => 'any', |
847 | 847 | 'posts_per_page' => $n, |
848 | 848 | 'offset' => $offset, |
849 | 849 | 'meta_key' => '_show_questions', |
850 | 850 | 'suppress_filters' => 0 |
851 | 851 | ); |
852 | - $quizzes = get_posts( $args ); |
|
852 | + $quizzes = get_posts($args); |
|
853 | 853 | |
854 | - $total_quizzes = count( $quizzes ); |
|
854 | + $total_quizzes = count($quizzes); |
|
855 | 855 | |
856 | - if( 0 == intval( $total_quizzes ) ) { |
|
856 | + if (0 == intval($total_quizzes)) { |
|
857 | 857 | return true; |
858 | 858 | } |
859 | 859 | |
860 | - foreach( $quizzes as $quiz ) { |
|
861 | - delete_post_meta( $quiz->ID, '_show_questions' ); |
|
860 | + foreach ($quizzes as $quiz) { |
|
861 | + delete_post_meta($quiz->ID, '_show_questions'); |
|
862 | 862 | } |
863 | 863 | |
864 | - $total_pages = intval( $total_quizzes / $n ); |
|
864 | + $total_pages = intval($total_quizzes / $n); |
|
865 | 865 | |
866 | 866 | // Calculate if this is the last page |
867 | - if ( 0 == $offset ) { |
|
867 | + if (0 == $offset) { |
|
868 | 868 | $current_page = 1; |
869 | 869 | } else { |
870 | - $current_page = intval( $offset / $n ); |
|
870 | + $current_page = intval($offset / $n); |
|
871 | 871 | } // End If Statement |
872 | 872 | |
873 | - if ( $current_page == $total_pages ) { |
|
873 | + if ($current_page == $total_pages) { |
|
874 | 874 | return true; |
875 | 875 | } else { |
876 | 876 | return false; |
@@ -878,14 +878,14 @@ discard block |
||
878 | 878 | |
879 | 879 | } |
880 | 880 | |
881 | - public function remove_deleted_user_activity( $n = 50, $offset = 0 ) { |
|
881 | + public function remove_deleted_user_activity($n = 50, $offset = 0) { |
|
882 | 882 | |
883 | - $all_activity = get_comments( array( 'status' => 'approve' ) ); |
|
883 | + $all_activity = get_comments(array('status' => 'approve')); |
|
884 | 884 | $activity_count = array(); |
885 | - foreach( $all_activity as $activity ) { |
|
886 | - if( '' == $activity->comment_type ) continue; |
|
887 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
888 | - if( 0 == $activity->user_id ) continue; |
|
885 | + foreach ($all_activity as $activity) { |
|
886 | + if ('' == $activity->comment_type) continue; |
|
887 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
888 | + if (0 == $activity->user_id) continue; |
|
889 | 889 | $activity_count[] = $activity->comment_ID; |
890 | 890 | } |
891 | 891 | |
@@ -895,33 +895,33 @@ discard block |
||
895 | 895 | 'status' => 'approve' |
896 | 896 | ); |
897 | 897 | |
898 | - $activities = get_comments( $args ); |
|
898 | + $activities = get_comments($args); |
|
899 | 899 | |
900 | - foreach( $activities as $activity ) { |
|
901 | - if( '' == $activity->comment_type ) continue; |
|
902 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
903 | - if( 0 == $activity->user_id ) continue; |
|
900 | + foreach ($activities as $activity) { |
|
901 | + if ('' == $activity->comment_type) continue; |
|
902 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
903 | + if (0 == $activity->user_id) continue; |
|
904 | 904 | |
905 | - $user_exists = get_userdata( $activity->user_id ); |
|
905 | + $user_exists = get_userdata($activity->user_id); |
|
906 | 906 | |
907 | - if( ! $user_exists ) { |
|
908 | - wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
907 | + if ( ! $user_exists) { |
|
908 | + wp_delete_comment(intval($activity->comment_ID), true); |
|
909 | 909 | wp_cache_flush(); |
910 | 910 | } |
911 | 911 | } |
912 | 912 | |
913 | - $total_activities = count( $activity_count ); |
|
913 | + $total_activities = count($activity_count); |
|
914 | 914 | |
915 | - $total_pages = intval( $total_activities / $n ); |
|
915 | + $total_pages = intval($total_activities / $n); |
|
916 | 916 | |
917 | 917 | // Calculate if this is the last page |
918 | - if ( 0 == $offset ) { |
|
918 | + if (0 == $offset) { |
|
919 | 919 | $current_page = 1; |
920 | 920 | } else { |
921 | - $current_page = intval( $offset / $n ); |
|
921 | + $current_page = intval($offset / $n); |
|
922 | 922 | } // End If Statement |
923 | 923 | |
924 | - if ( $current_page >= $total_pages ) { |
|
924 | + if ($current_page >= $total_pages) { |
|
925 | 925 | return true; |
926 | 926 | } else { |
927 | 927 | return false; |
@@ -930,16 +930,16 @@ discard block |
||
930 | 930 | } |
931 | 931 | |
932 | 932 | public function add_teacher_role() { |
933 | - add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) ); |
|
933 | + add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true)); |
|
934 | 934 | return true; |
935 | 935 | } |
936 | 936 | |
937 | 937 | public function add_sensei_caps() { |
938 | - $role = get_role( 'administrator' ); |
|
938 | + $role = get_role('administrator'); |
|
939 | 939 | |
940 | - if( ! is_null( $role ) ) { |
|
941 | - $role->add_cap( 'manage_sensei' ); |
|
942 | - $role->add_cap( 'manage_sensei_grades' ); |
|
940 | + if ( ! is_null($role)) { |
|
941 | + $role->add_cap('manage_sensei'); |
|
942 | + $role->add_cap('manage_sensei_grades'); |
|
943 | 943 | } |
944 | 944 | |
945 | 945 | return true; |
@@ -953,16 +953,16 @@ discard block |
||
953 | 953 | 'suppress_filters' => 0 |
954 | 954 | ); |
955 | 955 | |
956 | - $questions = get_posts( $args ); |
|
956 | + $questions = get_posts($args); |
|
957 | 957 | |
958 | - foreach( $questions as $question ) { |
|
958 | + foreach ($questions as $question) { |
|
959 | 959 | |
960 | - if( ! isset( $question->ID ) ) continue; |
|
960 | + if ( ! isset($question->ID)) continue; |
|
961 | 961 | |
962 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
962 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
963 | 963 | |
964 | - $question_order = get_post_meta( $question->ID, '_quiz_question_order', true ); |
|
965 | - update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order ); |
|
964 | + $question_order = get_post_meta($question->ID, '_quiz_question_order', true); |
|
965 | + update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order); |
|
966 | 966 | |
967 | 967 | } |
968 | 968 | |
@@ -971,15 +971,15 @@ discard block |
||
971 | 971 | |
972 | 972 | public function update_quiz_settings() { |
973 | 973 | |
974 | - $settings = get_option( 'woothemes-sensei-settings', array() ); |
|
974 | + $settings = get_option('woothemes-sensei-settings', array()); |
|
975 | 975 | |
976 | 976 | $lesson_completion = false; |
977 | - if( isset( $settings['lesson_completion'] ) ) { |
|
977 | + if (isset($settings['lesson_completion'])) { |
|
978 | 978 | $lesson_completion = $settings['lesson_completion']; |
979 | 979 | } |
980 | 980 | |
981 | 981 | $reset_quiz_allowed = false; |
982 | - if( isset( $settings['quiz_reset_allowed'] ) ) { |
|
982 | + if (isset($settings['quiz_reset_allowed'])) { |
|
983 | 983 | $reset_quiz_allowed = $settings['quiz_reset_allowed']; |
984 | 984 | } |
985 | 985 | |
@@ -990,20 +990,20 @@ discard block |
||
990 | 990 | 'suppress_filters' => 0 |
991 | 991 | ); |
992 | 992 | |
993 | - $quizzes = get_posts( $args ); |
|
993 | + $quizzes = get_posts($args); |
|
994 | 994 | |
995 | - foreach( $quizzes as $quiz ) { |
|
995 | + foreach ($quizzes as $quiz) { |
|
996 | 996 | |
997 | - if( ! isset( $quiz->ID ) ) continue; |
|
997 | + if ( ! isset($quiz->ID)) continue; |
|
998 | 998 | |
999 | - if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
|
1000 | - update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
|
999 | + if (isset($lesson_completion) && 'passed' == $lesson_completion) { |
|
1000 | + update_post_meta($quiz->ID, '_pass_required', 'on'); |
|
1001 | 1001 | } else { |
1002 | - update_post_meta( $quiz->ID, '_quiz_passmark', 0 ); |
|
1002 | + update_post_meta($quiz->ID, '_quiz_passmark', 0); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { |
|
1006 | - update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' ); |
|
1005 | + if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { |
|
1006 | + update_post_meta($quiz->ID, '_enable_quiz_reset', 'on'); |
|
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | |
@@ -1018,22 +1018,22 @@ discard block |
||
1018 | 1018 | 'suppress_filters' => 0 |
1019 | 1019 | ); |
1020 | 1020 | |
1021 | - $lessons = get_posts( $args ); |
|
1021 | + $lessons = get_posts($args); |
|
1022 | 1022 | |
1023 | - foreach( $lessons as $lesson ) { |
|
1023 | + foreach ($lessons as $lesson) { |
|
1024 | 1024 | |
1025 | - if( ! isset( $lesson->ID ) ) continue; |
|
1025 | + if ( ! isset($lesson->ID)) continue; |
|
1026 | 1026 | |
1027 | - $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
|
1027 | + $course_id = get_post_meta($lesson->ID, '_lesson_course', true); |
|
1028 | 1028 | |
1029 | - if( $course_id ) { |
|
1030 | - update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
|
1029 | + if ($course_id) { |
|
1030 | + update_post_meta($lesson->ID, '_order_'.$course_id, 0); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
1033 | + $module = Sensei()->modules->get_lesson_module($lesson->ID); |
|
1034 | 1034 | |
1035 | - if( $module ) { |
|
1036 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
1035 | + if ($module) { |
|
1036 | + update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | } |
@@ -1042,10 +1042,10 @@ discard block |
||
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | public function add_editor_caps() { |
1045 | - $role = get_role( 'editor' ); |
|
1045 | + $role = get_role('editor'); |
|
1046 | 1046 | |
1047 | - if( ! is_null( $role ) ) { |
|
1048 | - $role->add_cap( 'manage_sensei_grades' ); |
|
1047 | + if ( ! is_null($role)) { |
|
1048 | + $role->add_cap('manage_sensei_grades'); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | return true; |
@@ -1064,26 +1064,26 @@ discard block |
||
1064 | 1064 | WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%' |
1065 | 1065 | AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id |
1066 | 1066 | AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'"; |
1067 | - $wpdb->query( $sql ); |
|
1067 | + $wpdb->query($sql); |
|
1068 | 1068 | |
1069 | 1069 | return true; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | - public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) { |
|
1073 | - $count_object = wp_count_posts( 'quiz' ); |
|
1072 | + public function update_quiz_lesson_relationship($n = 50, $offset = 0) { |
|
1073 | + $count_object = wp_count_posts('quiz'); |
|
1074 | 1074 | |
1075 | 1075 | $count_published = 0; |
1076 | - foreach ( $count_object AS $status => $count ) { |
|
1076 | + foreach ($count_object AS $status => $count) { |
|
1077 | 1077 | $count_published += $count; |
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | // Calculate if this is the last page |
1081 | - if ( 0 == $offset ) { |
|
1081 | + if (0 == $offset) { |
|
1082 | 1082 | $current_page = 1; |
1083 | 1083 | } else { |
1084 | - $current_page = intval( $offset / $n ); |
|
1084 | + $current_page = intval($offset / $n); |
|
1085 | 1085 | } |
1086 | - $total_pages = ceil( $count_published / $n ); |
|
1086 | + $total_pages = ceil($count_published / $n); |
|
1087 | 1087 | |
1088 | 1088 | $args = array( |
1089 | 1089 | 'post_type' => 'quiz', |
@@ -1092,52 +1092,52 @@ discard block |
||
1092 | 1092 | 'post_status' => 'any' |
1093 | 1093 | ); |
1094 | 1094 | |
1095 | - $quizzes = get_posts( $args ); |
|
1095 | + $quizzes = get_posts($args); |
|
1096 | 1096 | |
1097 | - foreach( $quizzes as $quiz ) { |
|
1097 | + foreach ($quizzes as $quiz) { |
|
1098 | 1098 | |
1099 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
1099 | + if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue; |
|
1100 | 1100 | |
1101 | - $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
|
1101 | + $lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true); |
|
1102 | 1102 | |
1103 | - if( empty( $lesson_id ) ) continue; |
|
1103 | + if (empty($lesson_id)) continue; |
|
1104 | 1104 | |
1105 | 1105 | $data = array( |
1106 | 1106 | 'ID' => $quiz->ID, |
1107 | 1107 | 'post_parent' => $lesson_id, |
1108 | 1108 | ); |
1109 | - wp_update_post( $data ); |
|
1109 | + wp_update_post($data); |
|
1110 | 1110 | |
1111 | - update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID ); |
|
1111 | + update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | - if ( $current_page == $total_pages || 0 == $total_pages ) { |
|
1114 | + if ($current_page == $total_pages || 0 == $total_pages) { |
|
1115 | 1115 | return true; |
1116 | 1116 | } else { |
1117 | 1117 | return false; |
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - function status_changes_fix_lessons( $n = 50, $offset = 0 ) { |
|
1121 | + function status_changes_fix_lessons($n = 50, $offset = 0) { |
|
1122 | 1122 | global $wpdb; |
1123 | 1123 | |
1124 | - $count_object = wp_count_posts( 'lesson' ); |
|
1124 | + $count_object = wp_count_posts('lesson'); |
|
1125 | 1125 | $count_published = 0; |
1126 | - foreach ( $count_object AS $status => $count ) { |
|
1126 | + foreach ($count_object AS $status => $count) { |
|
1127 | 1127 | $count_published += $count; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - if ( 0 == $count_published ) { |
|
1130 | + if (0 == $count_published) { |
|
1131 | 1131 | return true; |
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | // Calculate if this is the last page |
1135 | - if ( 0 == $offset ) { |
|
1135 | + if (0 == $offset) { |
|
1136 | 1136 | $current_page = 1; |
1137 | 1137 | } else { |
1138 | - $current_page = intval( $offset / $n ); |
|
1138 | + $current_page = intval($offset / $n); |
|
1139 | 1139 | } |
1140 | - $total_pages = ceil( $count_published / $n ); |
|
1140 | + $total_pages = ceil($count_published / $n); |
|
1141 | 1141 | |
1142 | 1142 | // Get all Lessons with (and without) Quizzes... |
1143 | 1143 | $args = array( |
@@ -1147,26 +1147,26 @@ discard block |
||
1147 | 1147 | 'offset' => $offset, |
1148 | 1148 | 'fields' => 'ids' |
1149 | 1149 | ); |
1150 | - $lesson_ids = get_posts( $args ); |
|
1150 | + $lesson_ids = get_posts($args); |
|
1151 | 1151 | |
1152 | 1152 | // ...get all Quiz IDs for the above Lessons |
1153 | - $id_list = join( ',', $lesson_ids ); |
|
1154 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
1153 | + $id_list = join(',', $lesson_ids); |
|
1154 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
1155 | 1155 | $lesson_quiz_ids = array(); |
1156 | - if ( !empty($meta_list) ) { |
|
1157 | - foreach ( $meta_list as $metarow ) { |
|
1156 | + if ( ! empty($meta_list)) { |
|
1157 | + foreach ($meta_list as $metarow) { |
|
1158 | 1158 | $lesson_id = $metarow['meta_value']; |
1159 | 1159 | $quiz_id = $metarow['post_id']; |
1160 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
1160 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
1161 | 1161 | } |
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | // ...check all Quiz IDs for questions |
1165 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
1166 | - $meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A ); |
|
1165 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
1166 | + $meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A); |
|
1167 | 1167 | $lesson_quiz_ids_with_questions = array(); |
1168 | - if ( !empty($meta_list) ) { |
|
1169 | - foreach ( $meta_list as $metarow ) { |
|
1168 | + if ( ! empty($meta_list)) { |
|
1169 | + foreach ($meta_list as $metarow) { |
|
1170 | 1170 | $quiz_id = $metarow['meta_value']; |
1171 | 1171 | $lesson_quiz_ids_with_questions[] = $quiz_id; |
1172 | 1172 | } |
@@ -1174,49 +1174,49 @@ discard block |
||
1174 | 1174 | |
1175 | 1175 | // For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons |
1176 | 1176 | // if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons |
1177 | - $d_count = $a_count =0; |
|
1178 | - foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) { |
|
1179 | - if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
1177 | + $d_count = $a_count = 0; |
|
1178 | + foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) { |
|
1179 | + if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
1180 | 1180 | |
1181 | 1181 | // Quiz has no questions, drop the corresponding data |
1182 | - delete_post_meta( $quiz_id, '_pass_required' ); |
|
1183 | - delete_post_meta( $quiz_id, '_quiz_passmark' ); |
|
1184 | - delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
|
1182 | + delete_post_meta($quiz_id, '_pass_required'); |
|
1183 | + delete_post_meta($quiz_id, '_quiz_passmark'); |
|
1184 | + delete_post_meta($lesson_id, '_quiz_has_questions'); |
|
1185 | 1185 | $d_count++; |
1186 | 1186 | } |
1187 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
1187 | + else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
1188 | 1188 | |
1189 | 1189 | // Quiz has no questions, drop the corresponding data |
1190 | - update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1190 | + update_post_meta($lesson_id, '_quiz_has_questions', true); |
|
1191 | 1191 | $a_count++; |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | - if ( $current_page == $total_pages ) { |
|
1195 | + if ($current_page == $total_pages) { |
|
1196 | 1196 | return true; |
1197 | 1197 | } else { |
1198 | 1198 | return false; |
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | |
1202 | - function status_changes_convert_lessons( $n = 50, $offset = 0 ) { |
|
1202 | + function status_changes_convert_lessons($n = 50, $offset = 0) { |
|
1203 | 1203 | global $wpdb; |
1204 | 1204 | |
1205 | - wp_defer_comment_counting( true ); |
|
1205 | + wp_defer_comment_counting(true); |
|
1206 | 1206 | |
1207 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
1207 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
1208 | 1208 | |
1209 | - if ( 0 == $user_count_result ) { |
|
1209 | + if (0 == $user_count_result) { |
|
1210 | 1210 | return true; |
1211 | 1211 | } |
1212 | 1212 | |
1213 | - if ( 0 == $offset ) { |
|
1213 | + if (0 == $offset) { |
|
1214 | 1214 | $current_page = 1; |
1215 | 1215 | } else { |
1216 | - $current_page = intval( $offset / $n ); |
|
1216 | + $current_page = intval($offset / $n); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | - $total_pages = ceil( $user_count_result / $n ); |
|
1219 | + $total_pages = ceil($user_count_result / $n); |
|
1220 | 1220 | |
1221 | 1221 | // Get all Lessons with Quizzes... |
1222 | 1222 | $args = array( |
@@ -1231,34 +1231,34 @@ discard block |
||
1231 | 1231 | ), |
1232 | 1232 | 'fields' => 'ids' |
1233 | 1233 | ); |
1234 | - $lesson_ids_with_quizzes = get_posts( $args ); |
|
1234 | + $lesson_ids_with_quizzes = get_posts($args); |
|
1235 | 1235 | // ...get all Quiz IDs for the above Lessons |
1236 | - $id_list = join( ',', $lesson_ids_with_quizzes ); |
|
1237 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
1236 | + $id_list = join(',', $lesson_ids_with_quizzes); |
|
1237 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
1238 | 1238 | $lesson_quiz_ids = array(); |
1239 | - if ( !empty($meta_list) ) { |
|
1240 | - foreach ( $meta_list as $metarow ) { |
|
1239 | + if ( ! empty($meta_list)) { |
|
1240 | + foreach ($meta_list as $metarow) { |
|
1241 | 1241 | $lesson_id = $metarow['meta_value']; |
1242 | 1242 | $quiz_id = $metarow['post_id']; |
1243 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
1243 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
1244 | 1244 | } |
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | // ...get all Pass Required & Passmarks for the above Lesson/Quizzes |
1248 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
1249 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A ); |
|
1248 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
1249 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A); |
|
1250 | 1250 | $quizzes_pass_required = $quizzes_passmarks = array(); |
1251 | - if ( !empty($meta_list) ) { |
|
1252 | - foreach ( $meta_list as $metarow ) { |
|
1253 | - if ( !empty($metarow['meta_value']) ) { |
|
1251 | + if ( ! empty($meta_list)) { |
|
1252 | + foreach ($meta_list as $metarow) { |
|
1253 | + if ( ! empty($metarow['meta_value'])) { |
|
1254 | 1254 | $quiz_id = $metarow['post_id']; |
1255 | 1255 | $key = $metarow['meta_key']; |
1256 | 1256 | $value = $metarow['meta_value']; |
1257 | - if ( '_pass_required' == $key ) { |
|
1258 | - $quizzes_pass_required[ $quiz_id ] = $value; |
|
1257 | + if ('_pass_required' == $key) { |
|
1258 | + $quizzes_pass_required[$quiz_id] = $value; |
|
1259 | 1259 | } |
1260 | - if ( '_quiz_passmark' == $key ) { |
|
1261 | - $quizzes_passmarks[ $quiz_id ] = $value; |
|
1260 | + if ('_quiz_passmark' == $key) { |
|
1261 | + $quizzes_passmarks[$quiz_id] = $value; |
|
1262 | 1262 | } |
1263 | 1263 | } |
1264 | 1264 | } |
@@ -1272,41 +1272,41 @@ discard block |
||
1272 | 1272 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' "; |
1273 | 1273 | |
1274 | 1274 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
1275 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
1275 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
1276 | 1276 | |
1277 | - foreach ( $user_ids AS $user_id ) { |
|
1277 | + foreach ($user_ids AS $user_id) { |
|
1278 | 1278 | |
1279 | 1279 | $lesson_ends = $lesson_grades = $lesson_answers = array(); |
1280 | 1280 | |
1281 | 1281 | // Pre-process the lesson ends |
1282 | - $_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A ); |
|
1283 | - foreach ( $_lesson_ends as $lesson_end ) { |
|
1282 | + $_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A); |
|
1283 | + foreach ($_lesson_ends as $lesson_end) { |
|
1284 | 1284 | // This will overwrite existing entries with the newer ones |
1285 | - $lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date']; |
|
1285 | + $lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date']; |
|
1286 | 1286 | } |
1287 | - unset( $_lesson_ends ); |
|
1287 | + unset($_lesson_ends); |
|
1288 | 1288 | |
1289 | 1289 | // Pre-process the lesson grades |
1290 | - $_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A ); |
|
1291 | - foreach ( $_lesson_grades as $lesson_grade ) { |
|
1290 | + $_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A); |
|
1291 | + foreach ($_lesson_grades as $lesson_grade) { |
|
1292 | 1292 | // This will overwrite existing entries with the newer ones (assuming the grade is higher) |
1293 | - if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) { |
|
1294 | - $lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content']; |
|
1293 | + if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) { |
|
1294 | + $lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content']; |
|
1295 | 1295 | } |
1296 | 1296 | } |
1297 | - unset( $_lesson_grades ); |
|
1297 | + unset($_lesson_grades); |
|
1298 | 1298 | |
1299 | 1299 | // Pre-process the lesson answers |
1300 | - $_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A ); |
|
1301 | - foreach ( $_lesson_answers as $lesson_answer ) { |
|
1300 | + $_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A); |
|
1301 | + foreach ($_lesson_answers as $lesson_answer) { |
|
1302 | 1302 | // This will overwrite existing entries with the newer ones |
1303 | - $lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content']; |
|
1303 | + $lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content']; |
|
1304 | 1304 | } |
1305 | - unset( $_lesson_answers ); |
|
1305 | + unset($_lesson_answers); |
|
1306 | 1306 | |
1307 | 1307 | // Grab all the lesson starts for the user |
1308 | - $lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
1309 | - foreach ( $lesson_starts as $lesson_log ) { |
|
1308 | + $lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
1309 | + foreach ($lesson_starts as $lesson_log) { |
|
1310 | 1310 | |
1311 | 1311 | $lesson_id = $lesson_log['comment_post_ID']; |
1312 | 1312 | |
@@ -1319,23 +1319,23 @@ discard block |
||
1319 | 1319 | 'start' => $status_date, |
1320 | 1320 | ); |
1321 | 1321 | // Check if there is a lesson end |
1322 | - if ( !empty($lesson_ends[$lesson_id]) ) { |
|
1322 | + if ( ! empty($lesson_ends[$lesson_id])) { |
|
1323 | 1323 | $status_date = $lesson_ends[$lesson_id]; |
1324 | 1324 | // Check lesson has quiz |
1325 | - if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) { |
|
1325 | + if ( ! empty($lesson_quiz_ids[$lesson_id])) { |
|
1326 | 1326 | // Check for the quiz answers |
1327 | - if ( !empty($lesson_answers[$quiz_id]) ) { |
|
1327 | + if ( ! empty($lesson_answers[$quiz_id])) { |
|
1328 | 1328 | $meta_data['questions_asked'] = $lesson_answers[$quiz_id]; |
1329 | 1329 | } |
1330 | 1330 | // Check if there is a quiz grade |
1331 | 1331 | $quiz_id = $lesson_quiz_ids[$lesson_id]; |
1332 | - if ( !empty($lesson_grades[$quiz_id]) ) { |
|
1332 | + if ( ! empty($lesson_grades[$quiz_id])) { |
|
1333 | 1333 | $meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id]; |
1334 | 1334 | // Check if the user has to get the passmark and has or not |
1335 | - if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
|
1335 | + if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) { |
|
1336 | 1336 | $status = 'passed'; |
1337 | 1337 | } |
1338 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
1338 | + elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) { |
|
1339 | 1339 | $status = 'failed'; |
1340 | 1340 | } |
1341 | 1341 | else { |
@@ -1363,26 +1363,26 @@ discard block |
||
1363 | 1363 | 'comment_author' => '', |
1364 | 1364 | ); |
1365 | 1365 | // Check it doesn't already exist |
1366 | - $sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id ); |
|
1367 | - $comment_ID = $wpdb->get_var( $sql ); |
|
1368 | - if ( !$comment_ID ) { |
|
1366 | + $sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id); |
|
1367 | + $comment_ID = $wpdb->get_var($sql); |
|
1368 | + if ( ! $comment_ID) { |
|
1369 | 1369 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
1370 | 1370 | $wpdb->insert($wpdb->comments, $data); |
1371 | 1371 | $comment_ID = (int) $wpdb->insert_id; |
1372 | 1372 | |
1373 | - if ( $comment_ID && !empty($meta_data) ) { |
|
1374 | - foreach ( $meta_data as $key => $value ) { |
|
1373 | + if ($comment_ID && ! empty($meta_data)) { |
|
1374 | + foreach ($meta_data as $key => $value) { |
|
1375 | 1375 | // Bypassing WP add_comment_meta(() so no actions/filters are run |
1376 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
1376 | + if ($wpdb->get_var($wpdb->prepare( |
|
1377 | 1377 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
1378 | - $comment_ID, $key ) ) ) { |
|
1378 | + $comment_ID, $key ))) { |
|
1379 | 1379 | continue; // Found the meta data already |
1380 | 1380 | } |
1381 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
1381 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
1382 | 1382 | 'comment_id' => $comment_ID, |
1383 | 1383 | 'meta_key' => $key, |
1384 | 1384 | 'meta_value' => $value |
1385 | - ) ); |
|
1385 | + )); |
|
1386 | 1386 | } |
1387 | 1387 | } |
1388 | 1388 | } |
@@ -1390,40 +1390,40 @@ discard block |
||
1390 | 1390 | } |
1391 | 1391 | $wpdb->flush(); |
1392 | 1392 | |
1393 | - if ( $current_page == $total_pages ) { |
|
1393 | + if ($current_page == $total_pages) { |
|
1394 | 1394 | return true; |
1395 | 1395 | } else { |
1396 | 1396 | return false; |
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - function status_changes_convert_courses( $n = 50, $offset = 0 ) { |
|
1400 | + function status_changes_convert_courses($n = 50, $offset = 0) { |
|
1401 | 1401 | global $wpdb; |
1402 | 1402 | |
1403 | - wp_defer_comment_counting( true ); |
|
1403 | + wp_defer_comment_counting(true); |
|
1404 | 1404 | |
1405 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
1405 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
1406 | 1406 | |
1407 | - if ( 0 == $user_count_result ) { |
|
1407 | + if (0 == $user_count_result) { |
|
1408 | 1408 | return true; |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - if ( 0 == $offset ) { |
|
1411 | + if (0 == $offset) { |
|
1412 | 1412 | $current_page = 1; |
1413 | 1413 | } else { |
1414 | - $current_page = intval( $offset / $n ); |
|
1414 | + $current_page = intval($offset / $n); |
|
1415 | 1415 | } |
1416 | 1416 | |
1417 | - $total_pages = ceil( $user_count_result / $n ); |
|
1417 | + $total_pages = ceil($user_count_result / $n); |
|
1418 | 1418 | |
1419 | 1419 | // Get all Lesson => Course relationships |
1420 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A ); |
|
1420 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A); |
|
1421 | 1421 | $course_lesson_ids = array(); |
1422 | - if ( !empty($meta_list) ) { |
|
1423 | - foreach ( $meta_list as $metarow ) { |
|
1422 | + if ( ! empty($meta_list)) { |
|
1423 | + foreach ($meta_list as $metarow) { |
|
1424 | 1424 | $lesson_id = $metarow['post_id']; |
1425 | 1425 | $course_id = $metarow['meta_value']; |
1426 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
1426 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
1427 | 1427 | } |
1428 | 1428 | } |
1429 | 1429 | |
@@ -1433,13 +1433,13 @@ discard block |
||
1433 | 1433 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' "; |
1434 | 1434 | |
1435 | 1435 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
1436 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
1436 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
1437 | 1437 | |
1438 | - foreach ( $user_ids AS $user_id ) { |
|
1438 | + foreach ($user_ids AS $user_id) { |
|
1439 | 1439 | |
1440 | 1440 | // Grab all the course starts for the user |
1441 | - $course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
1442 | - foreach ( $course_starts as $course_log ) { |
|
1441 | + $course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
1442 | + foreach ($course_starts as $course_log) { |
|
1443 | 1443 | |
1444 | 1444 | $course_id = $course_log['comment_post_ID']; |
1445 | 1445 | |
@@ -1454,23 +1454,23 @@ discard block |
||
1454 | 1454 | 'percent' => 0, |
1455 | 1455 | ); |
1456 | 1456 | // Check if the course has lessons |
1457 | - if ( !empty( $course_lesson_ids[$course_id] ) ) { |
|
1457 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
1458 | 1458 | |
1459 | 1459 | $lessons_completed = 0; |
1460 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
1460 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
1461 | 1461 | |
1462 | 1462 | // Don't use prepare as we need to provide the id join |
1463 | - $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) ); |
|
1463 | + $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id])); |
|
1464 | 1464 | // Get all lesson statuses for this Courses' lessons |
1465 | - $lesson_statuses = $wpdb->get_results( $sql, ARRAY_A ); |
|
1465 | + $lesson_statuses = $wpdb->get_results($sql, ARRAY_A); |
|
1466 | 1466 | // Not enough lesson statuses, thus cannot be complete |
1467 | - if ( $total_lessons > count($lesson_statuses) ) { |
|
1467 | + if ($total_lessons > count($lesson_statuses)) { |
|
1468 | 1468 | $status = 'in-progress'; |
1469 | 1469 | } |
1470 | 1470 | // Count each lesson to work out the overall percentage |
1471 | - foreach ( $lesson_statuses as $lesson_status ) { |
|
1471 | + foreach ($lesson_statuses as $lesson_status) { |
|
1472 | 1472 | $status_date = $lesson_status['comment_date']; |
1473 | - switch ( $lesson_status['status'] ) { |
|
1473 | + switch ($lesson_status['status']) { |
|
1474 | 1474 | case 'complete': // Lesson has no quiz/questions |
1475 | 1475 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
1476 | 1476 | case 'passed': |
@@ -1485,7 +1485,7 @@ discard block |
||
1485 | 1485 | } |
1486 | 1486 | } |
1487 | 1487 | $meta_data['complete'] = $lessons_completed; |
1488 | - $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
1488 | + $meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
1489 | 1489 | } |
1490 | 1490 | else { |
1491 | 1491 | // Course has no lessons, therefore cannot be 'complete' |
@@ -1502,26 +1502,26 @@ discard block |
||
1502 | 1502 | 'comment_author' => '', |
1503 | 1503 | ); |
1504 | 1504 | // Check it doesn't already exist |
1505 | - $sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id ); |
|
1506 | - $comment_ID = $wpdb->get_var( $sql ); |
|
1507 | - if ( !$comment_ID ) { |
|
1505 | + $sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id); |
|
1506 | + $comment_ID = $wpdb->get_var($sql); |
|
1507 | + if ( ! $comment_ID) { |
|
1508 | 1508 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
1509 | 1509 | $wpdb->insert($wpdb->comments, $data); |
1510 | 1510 | $comment_ID = (int) $wpdb->insert_id; |
1511 | 1511 | |
1512 | - if ( $comment_ID && !empty($meta_data) ) { |
|
1513 | - foreach ( $meta_data as $key => $value ) { |
|
1512 | + if ($comment_ID && ! empty($meta_data)) { |
|
1513 | + foreach ($meta_data as $key => $value) { |
|
1514 | 1514 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
1515 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
1515 | + if ($wpdb->get_var($wpdb->prepare( |
|
1516 | 1516 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
1517 | - $comment_ID, $key ) ) ) { |
|
1517 | + $comment_ID, $key ))) { |
|
1518 | 1518 | continue; // Found the meta data already |
1519 | 1519 | } |
1520 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
1520 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
1521 | 1521 | 'comment_id' => $comment_ID, |
1522 | 1522 | 'meta_key' => $key, |
1523 | 1523 | 'meta_value' => $value |
1524 | - ) ); |
|
1524 | + )); |
|
1525 | 1525 | } |
1526 | 1526 | } |
1527 | 1527 | } |
@@ -1529,7 +1529,7 @@ discard block |
||
1529 | 1529 | } |
1530 | 1530 | $wpdb->flush(); |
1531 | 1531 | |
1532 | - if ( $current_page == $total_pages ) { |
|
1532 | + if ($current_page == $total_pages) { |
|
1533 | 1533 | return true; |
1534 | 1534 | } else { |
1535 | 1535 | return false; |
@@ -1545,70 +1545,70 @@ discard block |
||
1545 | 1545 | * @param type $offset |
1546 | 1546 | * @return boolean |
1547 | 1547 | */ |
1548 | - function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
|
1548 | + function status_changes_repair_course_statuses($n = 50, $offset = 0) { |
|
1549 | 1549 | global $wpdb; |
1550 | 1550 | |
1551 | - $count_object = wp_count_posts( 'lesson' ); |
|
1551 | + $count_object = wp_count_posts('lesson'); |
|
1552 | 1552 | $count_published = $count_object->publish; |
1553 | 1553 | |
1554 | - if ( 0 == $count_published ) { |
|
1554 | + if (0 == $count_published) { |
|
1555 | 1555 | return true; |
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | // Calculate if this is the last page |
1559 | - if ( 0 == $offset ) { |
|
1559 | + if (0 == $offset) { |
|
1560 | 1560 | $current_page = 1; |
1561 | 1561 | } else { |
1562 | - $current_page = intval( $offset / $n ); |
|
1562 | + $current_page = intval($offset / $n); |
|
1563 | 1563 | } |
1564 | - $total_pages = ceil( $count_published / $n ); |
|
1564 | + $total_pages = ceil($count_published / $n); |
|
1565 | 1565 | |
1566 | 1566 | $course_lesson_ids = $lesson_user_statuses = array(); |
1567 | 1567 | |
1568 | 1568 | // Get all Lesson => Course relationships |
1569 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A ); |
|
1570 | - if ( !empty($meta_list) ) { |
|
1571 | - foreach ( $meta_list as $metarow ) { |
|
1569 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A); |
|
1570 | + if ( ! empty($meta_list)) { |
|
1571 | + foreach ($meta_list as $metarow) { |
|
1572 | 1572 | $lesson_id = $metarow['post_id']; |
1573 | 1573 | $course_id = $metarow['meta_value']; |
1574 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
1574 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
1575 | 1575 | } |
1576 | 1576 | } |
1577 | 1577 | |
1578 | 1578 | // Get all Lesson => Course relationships |
1579 | - $status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A ); |
|
1580 | - if ( !empty($status_list) ) { |
|
1581 | - foreach ( $status_list as $status ) { |
|
1582 | - $lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved']; |
|
1579 | + $status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A); |
|
1580 | + if ( ! empty($status_list)) { |
|
1581 | + foreach ($status_list as $status) { |
|
1582 | + $lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved']; |
|
1583 | 1583 | } |
1584 | 1584 | } |
1585 | 1585 | |
1586 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
1586 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
1587 | 1587 | |
1588 | 1588 | $per_page = 40; |
1589 | 1589 | $comment_id_offset = $count = 0; |
1590 | 1590 | |
1591 | 1591 | $course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page"; |
1592 | 1592 | // $per_page users at a time |
1593 | - while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) { |
|
1593 | + while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) { |
|
1594 | 1594 | |
1595 | - foreach ( $course_statuses AS $course_status ) { |
|
1595 | + foreach ($course_statuses AS $course_status) { |
|
1596 | 1596 | $user_id = $course_status->user_id; |
1597 | 1597 | $course_id = $course_status->comment_post_ID; |
1598 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
1599 | - if ( $total_lessons <= 0 ) { |
|
1598 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
1599 | + if ($total_lessons <= 0) { |
|
1600 | 1600 | $total_lessons = 1; // Fix division of zero error, some courses have no lessons |
1601 | 1601 | } |
1602 | 1602 | $lessons_completed = 0; |
1603 | 1603 | $status = 'in-progress'; |
1604 | 1604 | |
1605 | 1605 | // Some Courses have no lessons... (can they ever be complete?) |
1606 | - if ( !empty($course_lesson_ids[ $course_id ]) ) { |
|
1607 | - foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) { |
|
1608 | - $lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ]; |
|
1606 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
1607 | + foreach ($course_lesson_ids[$course_id] AS $lesson_id) { |
|
1608 | + $lesson_status = $lesson_user_statuses[$lesson_id][$user_id]; |
|
1609 | 1609 | // If lessons are complete without needing quizzes to be passed |
1610 | - if ( 'passed' != $course_completion ) { |
|
1611 | - switch ( $lesson_status ) { |
|
1610 | + if ('passed' != $course_completion) { |
|
1611 | + switch ($lesson_status) { |
|
1612 | 1612 | // A user cannot 'complete' a course if a lesson... |
1613 | 1613 | case 'in-progress': // ...is still in progress |
1614 | 1614 | case 'ungraded': // ...hasn't yet been graded |
@@ -1620,7 +1620,7 @@ discard block |
||
1620 | 1620 | } |
1621 | 1621 | } |
1622 | 1622 | else { |
1623 | - switch ( $lesson_status ) { |
|
1623 | + switch ($lesson_status) { |
|
1624 | 1624 | case 'complete': // Lesson has no quiz/questions |
1625 | 1625 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
1626 | 1626 | case 'passed': // Lesson has quiz and the user passed |
@@ -1635,79 +1635,79 @@ discard block |
||
1635 | 1635 | } |
1636 | 1636 | } // Each lesson |
1637 | 1637 | } // Check for lessons |
1638 | - if ( $lessons_completed == $total_lessons ) { |
|
1638 | + if ($lessons_completed == $total_lessons) { |
|
1639 | 1639 | $status = 'complete'; |
1640 | 1640 | } |
1641 | 1641 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
1642 | 1642 | $metadata = array( |
1643 | 1643 | 'complete' => $lessons_completed, |
1644 | - 'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ), |
|
1644 | + 'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)), |
|
1645 | 1645 | ); |
1646 | - Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata ); |
|
1646 | + Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata); |
|
1647 | 1647 | $count++; |
1648 | 1648 | |
1649 | 1649 | } // per course status |
1650 | 1650 | $comment_id_offset = $course_status->comment_ID; |
1651 | 1651 | } // all course statuses |
1652 | 1652 | |
1653 | - if ( $current_page == $total_pages ) { |
|
1653 | + if ($current_page == $total_pages) { |
|
1654 | 1654 | return true; |
1655 | 1655 | } else { |
1656 | 1656 | return false; |
1657 | 1657 | } |
1658 | 1658 | } |
1659 | 1659 | |
1660 | - function status_changes_convert_questions( $n = 50, $offset = 0 ) { |
|
1660 | + function status_changes_convert_questions($n = 50, $offset = 0) { |
|
1661 | 1661 | global $wpdb; |
1662 | 1662 | |
1663 | - wp_defer_comment_counting( true ); |
|
1663 | + wp_defer_comment_counting(true); |
|
1664 | 1664 | |
1665 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
1665 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
1666 | 1666 | |
1667 | - if ( 0 == $user_count_result ) { |
|
1667 | + if (0 == $user_count_result) { |
|
1668 | 1668 | return true; |
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | // Calculate if this is the last page |
1672 | - if ( 0 == $offset ) { |
|
1672 | + if (0 == $offset) { |
|
1673 | 1673 | $current_page = 1; |
1674 | 1674 | } else { |
1675 | - $current_page = intval( $offset / $n ); |
|
1675 | + $current_page = intval($offset / $n); |
|
1676 | 1676 | } |
1677 | 1677 | |
1678 | - $total_pages = ceil( $user_count_result / $n ); |
|
1678 | + $total_pages = ceil($user_count_result / $n); |
|
1679 | 1679 | |
1680 | 1680 | $users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d"; |
1681 | 1681 | $answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID "; |
1682 | 1682 | $grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID "; |
1683 | 1683 | $notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID "; |
1684 | 1684 | |
1685 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
1685 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
1686 | 1686 | |
1687 | - foreach ( $user_ids AS $user_id ) { |
|
1687 | + foreach ($user_ids AS $user_id) { |
|
1688 | 1688 | |
1689 | 1689 | $answer_grades = $answer_notes = array(); |
1690 | 1690 | |
1691 | 1691 | // Pre-process the answer grades |
1692 | - $_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A ); |
|
1693 | - foreach ( $_answer_grades as $answer_grade ) { |
|
1692 | + $_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A); |
|
1693 | + foreach ($_answer_grades as $answer_grade) { |
|
1694 | 1694 | // This will overwrite existing entries with the newer ones |
1695 | - $answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content']; |
|
1695 | + $answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content']; |
|
1696 | 1696 | } |
1697 | - unset( $_answer_grades ); |
|
1697 | + unset($_answer_grades); |
|
1698 | 1698 | |
1699 | 1699 | // Pre-process the answer notes |
1700 | - $_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A ); |
|
1701 | - foreach ( $_answer_notes as $answer_note ) { |
|
1700 | + $_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A); |
|
1701 | + foreach ($_answer_notes as $answer_note) { |
|
1702 | 1702 | // This will overwrite existing entries with the newer ones |
1703 | - $answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content']; |
|
1703 | + $answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content']; |
|
1704 | 1704 | } |
1705 | - unset( $_answer_notes ); |
|
1705 | + unset($_answer_notes); |
|
1706 | 1706 | |
1707 | 1707 | // Grab all the questions for the user |
1708 | 1708 | $sql = $wpdb->prepare($answers_sql, $user_id); |
1709 | - $answers = $wpdb->get_results( $sql, ARRAY_A ); |
|
1710 | - foreach ( $answers as $answer ) { |
|
1709 | + $answers = $wpdb->get_results($sql, ARRAY_A); |
|
1710 | + foreach ($answers as $answer) { |
|
1711 | 1711 | |
1712 | 1712 | // Excape data |
1713 | 1713 | $answer = wp_slash($answer); |
@@ -1717,12 +1717,12 @@ discard block |
||
1717 | 1717 | $meta_data = array(); |
1718 | 1718 | |
1719 | 1719 | // Check if the question has been graded, add as meta |
1720 | - if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) { |
|
1721 | - $meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ]; |
|
1720 | + if ( ! empty($answer_grades[$answer['comment_post_ID']])) { |
|
1721 | + $meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']]; |
|
1722 | 1722 | } |
1723 | 1723 | // Check if there is an answer note, add as meta |
1724 | - if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) { |
|
1725 | - $meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ]; |
|
1724 | + if ( ! empty($answer_notes[$answer['comment_post_ID']])) { |
|
1725 | + $meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']]; |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | // Wipe the unnessary data from the main comment |
@@ -1735,21 +1735,21 @@ discard block |
||
1735 | 1735 | ); |
1736 | 1736 | $data = array_merge($answer, $data); |
1737 | 1737 | |
1738 | - $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
|
1739 | - if ( $rval ) { |
|
1740 | - if ( !empty($meta_data) ) { |
|
1741 | - foreach ( $meta_data as $key => $value ) { |
|
1738 | + $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID')); |
|
1739 | + if ($rval) { |
|
1740 | + if ( ! empty($meta_data)) { |
|
1741 | + foreach ($meta_data as $key => $value) { |
|
1742 | 1742 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
1743 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
1743 | + if ($wpdb->get_var($wpdb->prepare( |
|
1744 | 1744 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
1745 | - $comment_ID, $key ) ) ) { |
|
1745 | + $comment_ID, $key ))) { |
|
1746 | 1746 | continue; // Found the meta data already |
1747 | 1747 | } |
1748 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
1748 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
1749 | 1749 | 'comment_id' => $comment_ID, |
1750 | 1750 | 'meta_key' => $key, |
1751 | 1751 | 'meta_value' => $value |
1752 | - ) ); |
|
1752 | + )); |
|
1753 | 1753 | } |
1754 | 1754 | } |
1755 | 1755 | } |
@@ -1757,7 +1757,7 @@ discard block |
||
1757 | 1757 | } |
1758 | 1758 | $wpdb->flush(); |
1759 | 1759 | |
1760 | - if ( $current_page == $total_pages ) { |
|
1760 | + if ($current_page == $total_pages) { |
|
1761 | 1761 | return true; |
1762 | 1762 | } else { |
1763 | 1763 | return false; |
@@ -1774,10 +1774,10 @@ discard block |
||
1774 | 1774 | global $wpdb; |
1775 | 1775 | |
1776 | 1776 | // Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts |
1777 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " ); |
|
1777 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' "); |
|
1778 | 1778 | |
1779 | 1779 | // Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required |
1780 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " ); |
|
1780 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') "); |
|
1781 | 1781 | |
1782 | 1782 | return true; |
1783 | 1783 | } |
@@ -1790,50 +1790,50 @@ discard block |
||
1790 | 1790 | * @param type $offset |
1791 | 1791 | * @return boolean |
1792 | 1792 | */ |
1793 | - public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
|
1793 | + public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) { |
|
1794 | 1794 | global $wpdb; |
1795 | 1795 | |
1796 | - $item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " ); |
|
1796 | + $item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') "); |
|
1797 | 1797 | |
1798 | - if ( 0 == $item_count_result ) { |
|
1798 | + if (0 == $item_count_result) { |
|
1799 | 1799 | return true; |
1800 | 1800 | } |
1801 | 1801 | |
1802 | 1802 | // Calculate if this is the last page |
1803 | - if ( 0 == $offset ) { |
|
1803 | + if (0 == $offset) { |
|
1804 | 1804 | $current_page = 1; |
1805 | 1805 | } else { |
1806 | - $current_page = intval( $offset / $n ); |
|
1806 | + $current_page = intval($offset / $n); |
|
1807 | 1807 | } |
1808 | 1808 | |
1809 | - $total_pages = ceil( $item_count_result / $n ); |
|
1809 | + $total_pages = ceil($item_count_result / $n); |
|
1810 | 1810 | |
1811 | 1811 | // Recalculate all counts |
1812 | - $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) ); |
|
1813 | - foreach ( (array) $items as $post ) { |
|
1812 | + $items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset)); |
|
1813 | + foreach ((array) $items as $post) { |
|
1814 | 1814 | // Code copied from wp_update_comment_count_now() |
1815 | - $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) ); |
|
1816 | - $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) ); |
|
1815 | + $new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID)); |
|
1816 | + $wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID)); |
|
1817 | 1817 | |
1818 | - clean_post_cache( $post->ID ); |
|
1818 | + clean_post_cache($post->ID); |
|
1819 | 1819 | } |
1820 | 1820 | |
1821 | - if ( $current_page == $total_pages ) { |
|
1821 | + if ($current_page == $total_pages) { |
|
1822 | 1822 | return true; |
1823 | 1823 | } else { |
1824 | 1824 | return false; |
1825 | 1825 | } |
1826 | 1826 | } |
1827 | 1827 | |
1828 | - public function remove_legacy_comments () { |
|
1828 | + public function remove_legacy_comments() { |
|
1829 | 1829 | global $wpdb; |
1830 | 1830 | |
1831 | - $result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) ); |
|
1831 | + $result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy')); |
|
1832 | 1832 | |
1833 | 1833 | return true; |
1834 | 1834 | } |
1835 | 1835 | |
1836 | - public function index_comment_status_field () { |
|
1836 | + public function index_comment_status_field() { |
|
1837 | 1837 | global $wpdb; |
1838 | 1838 | |
1839 | 1839 | $wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )"); |
@@ -1852,7 +1852,7 @@ discard block |
||
1852 | 1852 | * @since 1.8.0 |
1853 | 1853 | * @return bool; |
1854 | 1854 | */ |
1855 | - public function enhance_teacher_role ( ) { |
|
1855 | + public function enhance_teacher_role( ) { |
|
1856 | 1856 | |
1857 | 1857 | require_once('class-sensei-teacher.php'); |
1858 | 1858 | $teacher = new Sensei_Teacher(); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | /** |
4 | 4 | * The Template for displaying all single course meta information. |
5 | 5 | * |
@@ -22,17 +22,17 @@ discard block |
||
22 | 22 | * @hooked WooThemes_Sensei_Course::load_single_course_lessons_query |
23 | 23 | * @since 1.9.0 |
24 | 24 | */ |
25 | - do_action( 'sensei_single_course_lessons_before' ); |
|
25 | + do_action('sensei_single_course_lessons_before'); |
|
26 | 26 | |
27 | 27 | ?> |
28 | 28 | |
29 | 29 | <?php |
30 | 30 | |
31 | 31 | //lessons loaded into loop in the sensei_single_course_lessons_before hook |
32 | - if( have_posts() ): |
|
32 | + if (have_posts()): |
|
33 | 33 | |
34 | 34 | // start course lessons loop |
35 | - while ( have_posts() ): the_post(); ?> |
|
35 | + while (have_posts()): the_post(); ?> |
|
36 | 36 | |
37 | 37 | <article <?php post_class(); ?> > |
38 | 38 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @hooked WooThemes_Sensei_Lesson::the_lesson_thumbnail - 8 |
51 | 51 | * |
52 | 52 | */ |
53 | - do_action( 'sensei_single_course_inside_before_lesson', get_the_ID() ); |
|
53 | + do_action('sensei_single_course_inside_before_lesson', get_the_ID()); |
|
54 | 54 | |
55 | 55 | ?> |
56 | 56 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @since 1.9.0 |
77 | 77 | */ |
78 | - do_action( 'sensei_single_course_inside_after_lesson', get_the_ID() ); |
|
78 | + do_action('sensei_single_course_inside_after_lesson', get_the_ID()); |
|
79 | 79 | |
80 | 80 | ?> |
81 | 81 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @since 1.9.0 |
96 | 96 | */ |
97 | - do_action( 'sensei_single_course_lessons_after' ); |
|
97 | + do_action('sensei_single_course_lessons_after'); |
|
98 | 98 | |
99 | 99 | ?> |
100 | 100 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | ?> |
13 | 13 | |
14 | -<?php get_sensei_header(); ?> |
|
14 | +<?php get_sensei_header(); ?> |
|
15 | 15 | |
16 | 16 | <?php |
17 | 17 | /** |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20 |
23 | 23 | */ |
24 | -do_action( 'sensei_course_results_content_before' ); |
|
24 | +do_action('sensei_course_results_content_before'); |
|
25 | 25 | ?> |
26 | 26 | |
27 | 27 | <?php |
28 | 28 | global $course; |
29 | -$course = get_page_by_path( $wp_query->query_vars['course_results'], OBJECT, 'course' ); |
|
29 | +$course = get_page_by_path($wp_query->query_vars['course_results'], OBJECT, 'course'); |
|
30 | 30 | ?> |
31 | 31 | |
32 | -<article <?php post_class( array( 'course', 'post','course-results' ) ); ?> > |
|
32 | +<article <?php post_class(array('course', 'post', 'course-results')); ?> > |
|
33 | 33 | |
34 | 34 | <section class="entry fix"> |
35 | 35 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param integer $course_id |
43 | 43 | * |
44 | 44 | */ |
45 | - do_action( 'sensei_course_results_content_inside_before', $course->ID ); |
|
45 | + do_action('sensei_course_results_content_inside_before', $course->ID); |
|
46 | 46 | ?> |
47 | 47 | |
48 | 48 | <header> |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | </header> |
55 | 55 | |
56 | - <?php if ( is_user_logged_in() ):?> |
|
56 | + <?php if (is_user_logged_in()):?> |
|
57 | 57 | |
58 | 58 | <?php |
59 | 59 | /** |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @hooked Sensei_Course_Results::course_info() - 20 |
67 | 67 | */ |
68 | - do_action( 'sensei_course_results_content_inside_before_lessons', $course->ID ); |
|
68 | + do_action('sensei_course_results_content_inside_before_lessons', $course->ID); |
|
69 | 69 | ?> |
70 | 70 | |
71 | 71 | |
72 | 72 | <section class="course-results-lessons"> |
73 | 73 | <?php |
74 | - $started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
75 | - if( $started_course ) { |
|
74 | + $started_course = Sensei_Utils::user_started_course($course->ID, get_current_user_id()); |
|
75 | + if ($started_course) { |
|
76 | 76 | |
77 | 77 | sensei_the_course_results_lessons(); |
78 | 78 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @hooked Sensei()->course_results->course_info - 20 |
94 | 94 | */ |
95 | - do_action( 'sensei_course_results_content_inside_after', $course->ID ); |
|
95 | + do_action('sensei_course_results_content_inside_after', $course->ID); |
|
96 | 96 | ?> |
97 | 97 | |
98 | 98 | </section> |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @since 1.9.0 |
107 | 107 | * |
108 | 108 | */ |
109 | -do_action( 'sensei_course_results_content_after' ); |
|
109 | +do_action('sensei_course_results_content_after'); |
|
110 | 110 | ?> |
111 | 111 | |
112 | 112 |
@@ -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 | * This class is loaded int WP by the shortcode loader class. |
5 | 5 | * |
@@ -61,28 +61,28 @@ discard block |
||
61 | 61 | * @param string $content |
62 | 62 | * @param string $shortcode the shortcode that was called for this instance |
63 | 63 | */ |
64 | - public function __construct( $attributes, $content, $shortcode ){ |
|
64 | + public function __construct($attributes, $content, $shortcode) { |
|
65 | 65 | |
66 | - if(! is_user_logged_in() ) { |
|
66 | + if ( ! is_user_logged_in()) { |
|
67 | 67 | // show the login form |
68 | 68 | Sensei_Templates::get_template('user/login-form.php'); |
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // set up all argument need for constructing the course query |
73 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
74 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
75 | - $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
73 | + $this->number = isset($attributes['number']) ? $attributes['number'] : '10'; |
|
74 | + $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title'; |
|
75 | + $this->status = isset($attributes['status']) ? $attributes['status'] : 'all'; |
|
76 | 76 | |
77 | 77 | // set the default for menu_order to be ASC |
78 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
78 | + if ('menu_order' == $this->orderby && ! isset($attributes['order'])) { |
|
79 | 79 | |
80 | - $this->order = 'ASC'; |
|
80 | + $this->order = 'ASC'; |
|
81 | 81 | |
82 | - }else{ |
|
82 | + } else { |
|
83 | 83 | |
84 | 84 | // for everything else use the value passed or the default DESC |
85 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
85 | + $this->order = isset($attributes['order']) ? $attributes['order'] : 'ASC'; |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | |
@@ -96,20 +96,20 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @since 1.9.0 |
98 | 98 | */ |
99 | - protected function setup_course_query(){ |
|
99 | + protected function setup_course_query() { |
|
100 | 100 | |
101 | - $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
102 | - $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
103 | - if ( !is_array($user_courses_logs) ) { |
|
101 | + $status_query = array('user_id' => get_current_user_id(), 'type' => 'sensei_course_status'); |
|
102 | + $user_courses_logs = Sensei_Utils::sensei_check_for_activity($status_query, true); |
|
103 | + if ( ! is_array($user_courses_logs)) { |
|
104 | 104 | |
105 | - $user_courses_logs = array( $user_courses_logs ); |
|
105 | + $user_courses_logs = array($user_courses_logs); |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
109 | 109 | $completed_ids = $active_ids = array(); |
110 | - foreach( $user_courses_logs as $course_status ) { |
|
110 | + foreach ($user_courses_logs as $course_status) { |
|
111 | 111 | |
112 | - if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
112 | + if (Sensei_Utils::user_completed_course($course_status, get_current_user_id())) { |
|
113 | 113 | |
114 | 114 | $completed_ids[] = $course_status->comment_post_ID; |
115 | 115 | |
@@ -120,34 +120,34 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if( 'completed' == $this->status ){ |
|
123 | + if ('completed' == $this->status) { |
|
124 | 124 | |
125 | - $included_courses = $completed_ids; |
|
125 | + $included_courses = $completed_ids; |
|
126 | 126 | |
127 | 127 | |
128 | - }elseif( 'active'==$this->status ){ |
|
128 | + }elseif ('active' == $this->status) { |
|
129 | 129 | |
130 | - $included_courses = $active_ids; |
|
130 | + $included_courses = $active_ids; |
|
131 | 131 | |
132 | - }else{ // all courses |
|
132 | + } else { // all courses |
|
133 | 133 | |
134 | - if( empty( $completed_ids ) ){ |
|
134 | + if (empty($completed_ids)) { |
|
135 | 135 | |
136 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
136 | + add_action('sensei_loop_course_inside_before', array($this, 'completed_no_course_message_output')); |
|
137 | 137 | } |
138 | 138 | |
139 | - if( empty( $active_ids ) ){ |
|
139 | + if (empty($active_ids)) { |
|
140 | 140 | |
141 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
141 | + add_action('sensei_loop_course_inside_before', array($this, 'active_no_course_message_output')); |
|
142 | 142 | |
143 | 143 | } |
144 | 144 | |
145 | - if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
145 | + if (empty($completed_ids) && empty($active_ids)) { |
|
146 | 146 | |
147 | 147 | $included_courses = array('-1000'); // don't show any courses |
148 | 148 | |
149 | - }else{ |
|
150 | - $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
149 | + } else { |
|
150 | + $included_courses = Sensei_Utils::array_zip_merge((array) $active_ids, (array) $completed_ids); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | // if the shortcode is not active or in active and the active and completed |
159 | 159 | // tabs show up. |
160 | 160 | $number_of_posts = $this->number; |
161 | - if( 'active' != $this->status && 'complete' != $this->status ){ |
|
161 | + if ('active' != $this->status && 'complete' != $this->status) { |
|
162 | 162 | $number_of_posts = 1000; |
163 | 163 | } |
164 | 164 | |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | 'post_status' => 'publish', |
170 | 170 | 'orderby' => $this->orderby, |
171 | 171 | 'order' => $this->order, |
172 | - 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
172 | + 'paged' => empty($query_var_paged) ? 1 : $query_var_paged, |
|
173 | 173 | 'posts_per_page' => $number_of_posts, |
174 | 174 | 'post__in' => $included_courses, |
175 | 175 | ); |
176 | 176 | |
177 | - $this->query = new WP_Query( $query_args ); |
|
177 | + $this->query = new WP_Query($query_args); |
|
178 | 178 | |
179 | 179 | }// end setup _course_query |
180 | 180 | |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @since 1.9.0 |
186 | 186 | */ |
187 | - public function completed_no_course_message_output(){ |
|
187 | + public function completed_no_course_message_output() { |
|
188 | 188 | ?> |
189 | 189 | <li class="user-completed"> |
190 | 190 | <div class="sensei-message info"> |
191 | 191 | |
192 | - <?php _e( 'You have not completed any courses yet.', 'woothemes-sensei' ); ?> |
|
192 | + <?php _e('You have not completed any courses yet.', 'woothemes-sensei'); ?> |
|
193 | 193 | |
194 | 194 | </div> |
195 | 195 | </li> |
@@ -202,17 +202,17 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @since 1.9.0 |
204 | 204 | */ |
205 | - public function active_no_course_message_output(){ |
|
205 | + public function active_no_course_message_output() { |
|
206 | 206 | ?> |
207 | 207 | |
208 | 208 | <li class="user-active"> |
209 | 209 | <div class="sensei-message info"> |
210 | 210 | |
211 | - <?php _e( 'You have no active courses.', 'woothemes-sensei' ); ?> |
|
211 | + <?php _e('You have no active courses.', 'woothemes-sensei'); ?> |
|
212 | 212 | |
213 | - <a href="<?php esc_attr_e( Sensei_Course::get_courses_page_url() ); ?>"> |
|
213 | + <a href="<?php esc_attr_e(Sensei_Course::get_courses_page_url()); ?>"> |
|
214 | 214 | |
215 | - <?php _e( 'Start a Course!', 'woothemes-sensei' ); ?> |
|
215 | + <?php _e('Start a Course!', 'woothemes-sensei'); ?> |
|
216 | 216 | |
217 | 217 | </a> |
218 | 218 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return string $content |
228 | 228 | */ |
229 | - public function render(){ |
|
229 | + public function render() { |
|
230 | 230 | |
231 | 231 | global $wp_query; |
232 | 232 | |
233 | - if(! is_user_logged_in() ) { |
|
233 | + if ( ! is_user_logged_in()) { |
|
234 | 234 | return ''; |
235 | 235 | } |
236 | 236 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | Sensei_Templates::get_template('globals/pagination.php'); |
250 | 250 | echo '</section>'; |
251 | 251 | |
252 | - $shortcode_output = ob_get_clean(); |
|
252 | + $shortcode_output = ob_get_clean(); |
|
253 | 253 | |
254 | 254 | $this->detach_shortcode_hooks(); |
255 | 255 | |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @since 1.9.0 |
267 | 267 | */ |
268 | - public function attach_shortcode_hooks(){ |
|
268 | + public function attach_shortcode_hooks() { |
|
269 | 269 | |
270 | 270 | // attach the toggle functionality |
271 | 271 | // don't show the toggle action if the user specified complete or active for this shortcode |
272 | - if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
272 | + if ( ! in_array($this->status, array('active', 'complete'))) { |
|
273 | 273 | |
274 | - add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
275 | - add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
274 | + add_action('sensei_loop_course_before', array($this, 'course_toggle_actions')); |
|
275 | + add_action('wp_footer', array($this, 'print_course_toggle_actions_inline_script'), 90); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | 279 | // add extra classes to distinguish the course based on user completed or active |
280 | - add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
280 | + add_filter('sensei_course_loop_content_class', array($this, 'course_status_class_tagging'), 20, 2); |
|
281 | 281 | |
282 | 282 | // attach progress meter below course |
283 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
284 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
283 | + add_action('sensei_course_content_inside_after', array($this, 'attach_course_progress')); |
|
284 | + add_action('sensei_course_content_inside_after', array($this, 'attach_course_buttons')); |
|
285 | 285 | |
286 | 286 | } |
287 | 287 | |
@@ -290,13 +290,13 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @since 1.9.0 |
292 | 292 | */ |
293 | - public function detach_shortcode_hooks(){ |
|
293 | + public function detach_shortcode_hooks() { |
|
294 | 294 | |
295 | 295 | //remove all hooks after the output is generated |
296 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
297 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
298 | - remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
299 | - remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
296 | + remove_action('sensei_course_content_inside_after', array($this, 'attach_course_progress')); |
|
297 | + remove_action('sensei_course_content_inside_after', array($this, 'attach_course_buttons')); |
|
298 | + remove_filter('sensei_course_loop_content_class', array($this, 'course_status_class_tagging'), 20, 2); |
|
299 | + remove_action('sensei_loop_course_before', array($this, 'course_toggle_actions')); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @param $course |
306 | 306 | */ |
307 | - public function attach_course_progress( $course_id ){ |
|
307 | + public function attach_course_progress($course_id) { |
|
308 | 308 | |
309 | - $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() ); |
|
310 | - echo Sensei()->course->get_progress_meter( $percentage ); |
|
309 | + $percentage = Sensei()->course->get_completion_percentage($course_id, get_current_user_id()); |
|
310 | + echo Sensei()->course->get_progress_meter($percentage); |
|
311 | 311 | |
312 | 312 | }// attach_course_progress |
313 | 313 | |
@@ -319,9 +319,9 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @param integer $course_id |
321 | 321 | */ |
322 | - public function attach_course_buttons( $course_id ){ |
|
322 | + public function attach_course_buttons($course_id) { |
|
323 | 323 | |
324 | - Sensei()->course->the_course_action_buttons( get_post( $course_id ) ); |
|
324 | + Sensei()->course->the_course_action_buttons(get_post($course_id)); |
|
325 | 325 | |
326 | 326 | }// attach_course_buttons |
327 | 327 | |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | * @param WP_Post $course |
335 | 335 | * @return array $classes |
336 | 336 | */ |
337 | - public function course_status_class_tagging($classes, $course){ |
|
337 | + public function course_status_class_tagging($classes, $course) { |
|
338 | 338 | |
339 | - if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
339 | + if (Sensei_Utils::user_completed_course($course, get_current_user_id())) { |
|
340 | 340 | |
341 | 341 | $classes[] = 'user-completed'; |
342 | 342 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | /** |
354 | 354 | * Output the course toggle functionality |
355 | 355 | */ |
356 | - public function course_toggle_actions(){ ?> |
|
356 | + public function course_toggle_actions() { ?> |
|
357 | 357 | |
358 | 358 | <section id="user-course-status-toggle"> |
359 | 359 | <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a> |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @since 1.9.0 |
24 | 24 | */ |
25 | - public static function init(){ |
|
25 | + public static function init() { |
|
26 | 26 | |
27 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
28 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
29 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
30 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
31 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
32 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
27 | + add_shortcode('allcourses', array(__CLASS__, 'all_courses')); |
|
28 | + add_shortcode('newcourses', array(__CLASS__, 'new_courses')); |
|
29 | + add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses')); |
|
30 | + add_shortcode('freecourses', array(__CLASS__, 'free_courses')); |
|
31 | + add_shortcode('paidcourses', array(__CLASS__, 'paid_courses')); |
|
32 | + add_shortcode('usercourses', array(__CLASS__, 'user_courses')); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | /** |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * @param mixed $content (default: null) |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public static function all_courses( $atts, $content = null ) { |
|
45 | + public static function all_courses($atts, $content = null) { |
|
46 | 46 | |
47 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
47 | + return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title |
|
48 | 48 | |
49 | 49 | } // all_courses() |
50 | 50 | |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @param mixed $content (default: null) |
57 | 57 | * @return string |
58 | 58 | */ |
59 | - public static function paid_courses( $atts, $content = null ) { |
|
59 | + public static function paid_courses($atts, $content = null) { |
|
60 | 60 | |
61 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
61 | + return self::generate_shortcode_courses('Paid Courses', 'paidcourses'); |
|
62 | 62 | |
63 | 63 | } // End paid_courses() |
64 | 64 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @param mixed $content (default: null) |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - public static function featured_courses( $atts, $content = null ) { |
|
74 | + public static function featured_courses($atts, $content = null) { |
|
75 | 75 | |
76 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
76 | + return self::generate_shortcode_courses('Featured Courses', 'featuredcourses'); |
|
77 | 77 | |
78 | 78 | } // End featured_courses() |
79 | 79 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * @param mixed $content (default: null) |
86 | 86 | * @return string |
87 | 87 | */ |
88 | - public static function free_courses( $atts, $content = null ) { |
|
88 | + public static function free_courses($atts, $content = null) { |
|
89 | 89 | |
90 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
90 | + return self::generate_shortcode_courses('Free Courses', 'freecourses'); |
|
91 | 91 | |
92 | 92 | } // End free_courses() |
93 | 93 | |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * @param mixed $content (default: null) |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - public static function new_courses( $atts, $content = null ) { |
|
102 | + public static function new_courses($atts, $content = null) { |
|
103 | 103 | |
104 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
104 | + return self::generate_shortcode_courses('New Courses', 'newcourses'); |
|
105 | 105 | |
106 | 106 | } // End new_courses() |
107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param $shortcode_specific_override |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
117 | + public static function generate_shortcode_courses($title, $shortcode_specific_override) { |
|
118 | 118 | |
119 | 119 | global $shortcode_override, $posts_array; |
120 | 120 | |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | |
123 | 123 | // do not show this short code if there is a shortcode int he url and |
124 | 124 | // this specific shortcode is not the one requested in the ur. |
125 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
126 | - if( ! empty( $specific_shortcode_requested) && |
|
127 | - $specific_shortcode_requested != $shortcode_override ){ |
|
125 | + $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
126 | + if ( ! empty($specific_shortcode_requested) && |
|
127 | + $specific_shortcode_requested != $shortcode_override) { |
|
128 | 128 | |
129 | 129 | return ''; |
130 | 130 | |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | $courses = ob_get_clean(); |
137 | 137 | |
138 | 138 | $content = ''; |
139 | - if( count( $posts_array ) > 0 ){ |
|
139 | + if (count($posts_array) > 0) { |
|
140 | 140 | |
141 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
141 | + $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>'; |
|
142 | 142 | $before .= '<section id="main-course" class="course-container">'; |
143 | 143 | |
144 | 144 | $after = '</section>'; |
145 | 145 | |
146 | 146 | //assemble |
147 | - $content = $before . $courses . $after; |
|
147 | + $content = $before.$courses.$after; |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * @param mixed $content (default: null) |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public static function user_courses( $atts, $content = null ) { |
|
164 | + public static function user_courses($atts, $content = null) { |
|
165 | 165 | global $shortcode_override; |
166 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
166 | + extract(shortcode_atts(array('amount' => 0), $atts)); |
|
167 | 167 | |
168 | 168 | $shortcode_override = 'usercourses'; |
169 | 169 | |
170 | 170 | ob_start(); |
171 | 171 | |
172 | - if( is_user_logged_in() ){ |
|
172 | + if (is_user_logged_in()) { |
|
173 | 173 | |
174 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
174 | + Sensei_Templates::get_template('user/my-courses.php'); |
|
175 | 175 | |
176 | - }else{ |
|
176 | + } else { |
|
177 | 177 | |
178 | 178 | Sensei()->frontend->sensei_login_form(); |
179 | 179 | |
@@ -189,54 +189,54 @@ discard block |
||
189 | 189 | * loop-course.php for the old shortcodes. |
190 | 190 | * @since 1.9.0 |
191 | 191 | */ |
192 | - public static function initialise_legacy_course_loop(){ |
|
192 | + public static function initialise_legacy_course_loop() { |
|
193 | 193 | |
194 | 194 | global $post, $wp_query, $shortcode_override, $course_excludes; |
195 | 195 | |
196 | 196 | // Handle Query Type |
197 | 197 | $query_type = ''; |
198 | 198 | |
199 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
200 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
199 | + if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) { |
|
200 | + $query_type = esc_html($_GET['action']); |
|
201 | 201 | } // End If Statement |
202 | 202 | |
203 | - if ( '' != $shortcode_override ) { |
|
203 | + if ('' != $shortcode_override) { |
|
204 | 204 | $query_type = $shortcode_override; |
205 | 205 | } // End If Statement |
206 | 206 | |
207 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
207 | + if ( ! is_array($course_excludes)) { $course_excludes = array(); } |
|
208 | 208 | |
209 | 209 | // Check that query returns results |
210 | 210 | // Handle Pagination |
211 | - $paged = $wp_query->get( 'paged' ); |
|
212 | - $paged = empty( $paged ) ? 1 : $paged; |
|
211 | + $paged = $wp_query->get('paged'); |
|
212 | + $paged = empty($paged) ? 1 : $paged; |
|
213 | 213 | |
214 | 214 | |
215 | 215 | // Check for pagination settings |
216 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
216 | + if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { |
|
217 | 217 | |
218 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
218 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
219 | 219 | |
220 | 220 | } else { |
221 | 221 | |
222 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
222 | + $amount = $wp_query->get('posts_per_page'); |
|
223 | 223 | |
224 | 224 | } // End If Statement |
225 | 225 | |
226 | 226 | // This is not a paginated page (or it's simply the first page of a paginated page/post) |
227 | 227 | |
228 | 228 | global $posts_array; |
229 | - $course_includes = array(); |
|
229 | + $course_includes = array(); |
|
230 | 230 | |
231 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
232 | - $course_query = new WP_Query( $query_args ); |
|
231 | + $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes); |
|
232 | + $course_query = new WP_Query($query_args); |
|
233 | 233 | $posts_array = $course_query->get_posts(); |
234 | 234 | |
235 | 235 | // output the courses |
236 | - if( ! empty( $posts_array ) ) { |
|
236 | + if ( ! empty($posts_array)) { |
|
237 | 237 | |
238 | 238 | //output all courses for current query |
239 | - self::loop_courses( $course_query, $amount ); |
|
239 | + self::loop_courses($course_query, $amount); |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | |
@@ -249,31 +249,31 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param WP_Query $course_query |
251 | 251 | */ |
252 | - public static function loop_courses( $course_query, $amount ){ |
|
252 | + public static function loop_courses($course_query, $amount) { |
|
253 | 253 | |
254 | 254 | global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
255 | 255 | |
256 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
256 | + if (count($course_query->get_posts()) > 0) { |
|
257 | 257 | |
258 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
258 | + do_action('sensei_course_archive_header', $shortcode_override); |
|
259 | 259 | |
260 | - foreach ( $course_query->get_posts() as $course){ |
|
260 | + foreach ($course_query->get_posts() as $course) { |
|
261 | 261 | |
262 | 262 | // Make sure the other loops dont include the same post twice! |
263 | - array_push( $course_excludes, $course->ID ); |
|
263 | + array_push($course_excludes, $course->ID); |
|
264 | 264 | |
265 | 265 | // output the course markup |
266 | - self::the_course( $course->ID ); |
|
266 | + self::the_course($course->ID); |
|
267 | 267 | |
268 | 268 | } // End For Loop |
269 | 269 | |
270 | 270 | // More and Prev links |
271 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
271 | + $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes)); |
|
272 | 272 | $posts_array = $posts_array_query->get_posts(); |
273 | 273 | $max_pages = $course_query->found_posts / $amount; |
274 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
274 | + if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) { |
|
275 | 275 | |
276 | - switch( $shortcode_override ){ |
|
276 | + switch ($shortcode_override) { |
|
277 | 277 | case 'paidcourses': |
278 | 278 | $filter = 'paid'; |
279 | 279 | break; |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | $quer_args = array(); |
292 | - $quer_args[ 'paged' ] = '2'; |
|
293 | - if( !empty( $filter ) ){ |
|
294 | - $quer_args[ 'course_filter' ] = $filter; |
|
292 | + $quer_args['paged'] = '2'; |
|
293 | + if ( ! empty($filter)) { |
|
294 | + $quer_args['course_filter'] = $filter; |
|
295 | 295 | } |
296 | 296 | |
297 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
298 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
299 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
297 | + $course_pagination_link = get_post_type_archive_link('course'); |
|
298 | + $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']); |
|
299 | + $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link)); |
|
300 | 300 | |
301 | 301 | // next/more |
302 | 302 | $html = '<div class="navigation"><div class="nav-next">'; |
303 | - $html .= '<a href="' . $more_link_url . '">'; |
|
303 | + $html .= '<a href="'.$more_link_url.'">'; |
|
304 | 304 | $html .= $more_link_text; |
305 | 305 | $html .= '<span class="meta-nav"></span></a></div>'; |
306 | 306 | |
307 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
307 | + echo apply_filters('course_archive_next_link', $html); |
|
308 | 308 | |
309 | 309 | } // End If Statement |
310 | 310 | |
@@ -316,23 +316,23 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @param $course_id |
318 | 318 | */ |
319 | - public static function the_course( $course_id ){ |
|
319 | + public static function the_course($course_id) { |
|
320 | 320 | |
321 | 321 | // Get meta data |
322 | - $course = get_post( $course_id ); |
|
323 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
324 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
322 | + $course = get_post($course_id); |
|
323 | + $user_info = get_userdata(absint($course->post_author)); |
|
324 | + $author_link = get_author_posts_url(absint($course->post_author)); |
|
325 | 325 | $author_display_name = $user_info->display_name; |
326 | 326 | $author_id = $course->post_author; |
327 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
328 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
329 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
327 | + $category_output = get_the_term_list($course_id, 'course-category', '', ', ', ''); |
|
328 | + $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id)); |
|
329 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
330 | 330 | ?> |
331 | 331 | |
332 | - <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
|
332 | + <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>"> |
|
333 | 333 | <?php |
334 | 334 | // so that legacy shortcodes work with the party plugins that wants to hook in |
335 | - do_action('sensei_course_content_before',$course->ID ); |
|
335 | + do_action('sensei_course_content_before', $course->ID); |
|
336 | 336 | ?> |
337 | 337 | <div class="course-content"> |
338 | 338 | |
@@ -348,19 +348,19 @@ discard block |
||
348 | 348 | |
349 | 349 | <p class="sensei-course-meta"> |
350 | 350 | |
351 | - <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> |
|
352 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span> |
|
351 | + <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> |
|
352 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span> |
|
353 | 353 | <?php } // End If Statement ?> |
354 | 354 | |
355 | 355 | <span class="course-lesson-count"> |
356 | - <?php echo Sensei()->course->course_lesson_count( $course_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?> |
|
356 | + <?php echo Sensei()->course->course_lesson_count($course_id).' '.__('Lessons', 'woothemes-sensei'); ?> |
|
357 | 357 | </span> |
358 | 358 | |
359 | - <?php if ( '' != $category_output ) { ?> |
|
360 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
359 | + <?php if ('' != $category_output) { ?> |
|
360 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
361 | 361 | <?php } // End If Statement ?> |
362 | 362 | |
363 | - <?php sensei_simple_course_price( $course_id ); ?> |
|
363 | + <?php sensei_simple_course_price($course_id); ?> |
|
364 | 364 | |
365 | 365 | </p> |
366 | 366 | |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | |
369 | 369 | </p> |
370 | 370 | |
371 | - <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
372 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
371 | + <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) { |
|
372 | + $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> |
|
373 | 373 | <p class="sensei-free-lessons"> |
374 | - <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
|
374 | + <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?> |
|
375 | 375 | </a> - <?php echo $preview_lessons; ?> |
376 | 376 | </p> |
377 | 377 | <?php } ?> |