@@ -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 | * Analysis User Profile Data Table in Sensei. |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | * @since 1.2.0 |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function __construct ( $user_id = 0 ) { |
|
22 | - $this->user_id = intval( $user_id ); |
|
21 | + public function __construct($user_id = 0) { |
|
22 | + $this->user_id = intval($user_id); |
|
23 | 23 | |
24 | 24 | // Load Parent token into constructor |
25 | - parent::__construct( 'analysis_user_profile' ); |
|
25 | + parent::__construct('analysis_user_profile'); |
|
26 | 26 | |
27 | 27 | // Actions |
28 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
29 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
28 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
29 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
30 | 30 | |
31 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
31 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
32 | 32 | } // End __construct() |
33 | 33 | |
34 | 34 | /** |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function get_columns() { |
40 | 40 | $columns = array( |
41 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
42 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
43 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
44 | - 'status' => __( 'Status', 'woothemes-sensei' ), |
|
41 | + 'title' => __('Course', 'woothemes-sensei'), |
|
42 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
43 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
44 | + 'status' => __('Status', 'woothemes-sensei'), |
|
45 | 45 | // 'grade' => __( 'Grade', 'woothemes-sensei' ), |
46 | - 'percent' => __( 'Percent Complete', 'woothemes-sensei' ), |
|
46 | + 'percent' => __('Percent Complete', 'woothemes-sensei'), |
|
47 | 47 | ); |
48 | - $columns = apply_filters( 'sensei_analysis_user_profile_columns', $columns ); |
|
48 | + $columns = apply_filters('sensei_analysis_user_profile_columns', $columns); |
|
49 | 49 | return $columns; |
50 | 50 | } |
51 | 51 | |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | */ |
57 | 57 | function get_sortable_columns() { |
58 | 58 | $columns = array( |
59 | - 'title' => array( 'title', false ), |
|
60 | - 'started' => array( 'started', false ), |
|
61 | - 'completed' => array( 'completed', false ), |
|
62 | - 'status' => array( 'status', false ), |
|
59 | + 'title' => array('title', false), |
|
60 | + 'started' => array('started', false), |
|
61 | + 'completed' => array('completed', false), |
|
62 | + 'status' => array('status', false), |
|
63 | 63 | // 'grade' => array( 'grade', false ), |
64 | - 'percent' => array( 'percent', false ) |
|
64 | + 'percent' => array('percent', false) |
|
65 | 65 | ); |
66 | - $columns = apply_filters( 'sensei_analysis_user_profile_columns_sortable', $columns ); |
|
66 | + $columns = apply_filters('sensei_analysis_user_profile_columns_sortable', $columns); |
|
67 | 67 | return $columns; |
68 | 68 | } |
69 | 69 | |
@@ -77,32 +77,32 @@ discard block |
||
77 | 77 | |
78 | 78 | // Handle orderby (needs work) |
79 | 79 | $orderby = ''; |
80 | - if ( !empty( $_GET['orderby'] ) ) { |
|
81 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
82 | - $orderby = esc_html( $_GET['orderby'] ); |
|
80 | + if ( ! empty($_GET['orderby'])) { |
|
81 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
82 | + $orderby = esc_html($_GET['orderby']); |
|
83 | 83 | } // End If Statement |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Handle order |
87 | 87 | $order = 'ASC'; |
88 | - if ( !empty( $_GET['order'] ) ) { |
|
89 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
88 | + if ( ! empty($_GET['order'])) { |
|
89 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // Handle search, need 4.1 version of WP to be able to restrict statuses to known post_ids |
93 | 93 | $search = false; |
94 | - if ( !empty( $_GET['s'] ) ) { |
|
95 | - $search = esc_html( $_GET['s'] ); |
|
94 | + if ( ! empty($_GET['s'])) { |
|
95 | + $search = esc_html($_GET['s']); |
|
96 | 96 | } // End If Statement |
97 | 97 | $this->search = $search; |
98 | 98 | |
99 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
100 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
99 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
100 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
101 | 101 | |
102 | 102 | $paged = $this->get_pagenum(); |
103 | 103 | $offset = 0; |
104 | - if ( !empty($paged) ) { |
|
105 | - $offset = $per_page * ( $paged - 1 ); |
|
104 | + if ( ! empty($paged)) { |
|
105 | + $offset = $per_page * ($paged - 1); |
|
106 | 106 | } // End If Statement |
107 | 107 | |
108 | 108 | $args = array( |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | 'orderby' => $orderby, |
112 | 112 | 'order' => $order, |
113 | 113 | ); |
114 | - if ( $this->search ) { |
|
114 | + if ($this->search) { |
|
115 | 115 | $args['search'] = $this->search; |
116 | 116 | } // End If Statement |
117 | 117 | |
118 | - $this->items = $this->get_course_statuses( $args ); |
|
118 | + $this->items = $this->get_course_statuses($args); |
|
119 | 119 | |
120 | 120 | $total_items = $this->total_items; |
121 | - $total_pages = ceil( $total_items / $per_page ); |
|
122 | - $this->set_pagination_args( array( |
|
121 | + $total_pages = ceil($total_items / $per_page); |
|
122 | + $this->set_pagination_args(array( |
|
123 | 123 | 'total_items' => $total_items, |
124 | 124 | 'total_pages' => $total_pages, |
125 | 125 | 'per_page' => $per_page |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @since 1.7.0 |
132 | 132 | * @return data |
133 | 133 | */ |
134 | - public function generate_report( $report ) { |
|
134 | + public function generate_report($report) { |
|
135 | 135 | |
136 | 136 | $data = array(); |
137 | 137 | |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | |
140 | 140 | // Handle orderby |
141 | 141 | $orderby = ''; |
142 | - if ( !empty( $_GET['orderby'] ) ) { |
|
143 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
144 | - $orderby = esc_html( $_GET['orderby'] ); |
|
142 | + if ( ! empty($_GET['orderby'])) { |
|
143 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
144 | + $orderby = esc_html($_GET['orderby']); |
|
145 | 145 | } // End If Statement |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Handle order |
149 | 149 | $order = 'ASC'; |
150 | - if ( !empty( $_GET['order'] ) ) { |
|
151 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
150 | + if ( ! empty($_GET['order'])) { |
|
151 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Handle search |
155 | 155 | $search = false; |
156 | - if ( !empty( $_GET['s'] ) ) { |
|
157 | - $search = esc_html( $_GET['s'] ); |
|
156 | + if ( ! empty($_GET['s'])) { |
|
157 | + $search = esc_html($_GET['s']); |
|
158 | 158 | } // End If Statement |
159 | 159 | $this->search = $search; |
160 | 160 | |
@@ -162,23 +162,23 @@ discard block |
||
162 | 162 | 'orderby' => $orderby, |
163 | 163 | 'order' => $order, |
164 | 164 | ); |
165 | - if ( $this->search ) { |
|
165 | + if ($this->search) { |
|
166 | 166 | $args['search'] = $this->search; |
167 | 167 | } // End If Statement |
168 | 168 | |
169 | 169 | // Start the csv with the column headings |
170 | 170 | $column_headers = array(); |
171 | 171 | $columns = $this->get_columns(); |
172 | - foreach( $columns AS $key => $title ) { |
|
172 | + foreach ($columns AS $key => $title) { |
|
173 | 173 | $column_headers[] = $title; |
174 | 174 | } |
175 | 175 | $data[] = $column_headers; |
176 | 176 | |
177 | - $this->items = $this->get_course_statuses( $args ); |
|
177 | + $this->items = $this->get_course_statuses($args); |
|
178 | 178 | |
179 | 179 | // Process each row |
180 | - foreach( $this->items AS $item) { |
|
181 | - $data[] = $this->get_row_data( $item ); |
|
180 | + foreach ($this->items AS $item) { |
|
181 | + $data[] = $this->get_row_data($item); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $data; |
@@ -189,43 +189,43 @@ discard block |
||
189 | 189 | * @since 1.7.0 |
190 | 190 | * @param object $item The current item |
191 | 191 | */ |
192 | - protected function get_row_data( $item ) { |
|
192 | + protected function get_row_data($item) { |
|
193 | 193 | |
194 | - $course_title = get_the_title( $item->comment_post_ID ); |
|
195 | - $course_percent = get_comment_meta( $item->comment_ID, 'percent', true ); |
|
196 | - $course_start_date = get_comment_meta( $item->comment_ID, 'start', true ); |
|
194 | + $course_title = get_the_title($item->comment_post_ID); |
|
195 | + $course_percent = get_comment_meta($item->comment_ID, 'percent', true); |
|
196 | + $course_start_date = get_comment_meta($item->comment_ID, 'start', true); |
|
197 | 197 | $course_end_date = ''; |
198 | 198 | |
199 | - if( 'complete' == $item->comment_approved ) { |
|
199 | + if ('complete' == $item->comment_approved) { |
|
200 | 200 | |
201 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
201 | + $status = __('Completed', 'woothemes-sensei'); |
|
202 | 202 | $status_class = 'graded'; |
203 | 203 | |
204 | 204 | $course_end_date = $item->comment_date; |
205 | 205 | |
206 | 206 | } else { |
207 | 207 | |
208 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
208 | + $status = __('In Progress', 'woothemes-sensei'); |
|
209 | 209 | $status_class = 'in-progress'; |
210 | 210 | |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Output users data |
214 | - if ( !$this->csv_output ) { |
|
215 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $this->user_id, 'course_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ); |
|
214 | + if ( ! $this->csv_output) { |
|
215 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $this->user_id, 'course_id' => $item->comment_post_ID), admin_url('admin.php')); |
|
216 | 216 | |
217 | - $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $course_title . '</a></strong>'; |
|
218 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
219 | - if ( is_numeric($course_percent) ) { |
|
217 | + $course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.$course_title.'</a></strong>'; |
|
218 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
219 | + if (is_numeric($course_percent)) { |
|
220 | 220 | $course_percent .= '%'; |
221 | 221 | } |
222 | 222 | } // End If Statement |
223 | - $column_data = apply_filters( 'sensei_analysis_user_profile_column_data', array( 'title' => $course_title, |
|
223 | + $column_data = apply_filters('sensei_analysis_user_profile_column_data', array('title' => $course_title, |
|
224 | 224 | 'started' => $course_start_date, |
225 | 225 | 'completed' => $course_end_date, |
226 | 226 | 'status' => $status, |
227 | 227 | 'percent' => $course_percent, |
228 | - ), $item ); |
|
228 | + ), $item); |
|
229 | 229 | |
230 | 230 | return $column_data; |
231 | 231 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @since 1.7.0 |
236 | 236 | * @return array statuses |
237 | 237 | */ |
238 | - private function get_course_statuses( $args ) { |
|
238 | + private function get_course_statuses($args) { |
|
239 | 239 | |
240 | 240 | $activity_args = array( |
241 | 241 | 'user_id' => $this->user_id, |
@@ -247,23 +247,23 @@ discard block |
||
247 | 247 | 'status' => 'any', |
248 | 248 | ); |
249 | 249 | |
250 | - $activity_args = apply_filters( 'sensei_analysis_user_profile_filter_statuses', $activity_args ); |
|
250 | + $activity_args = apply_filters('sensei_analysis_user_profile_filter_statuses', $activity_args); |
|
251 | 251 | |
252 | 252 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
253 | - $this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
253 | + $this->total_items = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
254 | 254 | |
255 | 255 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
256 | - if ( $this->total_items < $activity_args['offset'] ) { |
|
256 | + if ($this->total_items < $activity_args['offset']) { |
|
257 | 257 | |
258 | - $new_paged = floor( $this->total_items / $activity_args['number'] ); |
|
258 | + $new_paged = floor($this->total_items / $activity_args['number']); |
|
259 | 259 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
260 | 260 | |
261 | 261 | } |
262 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
262 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
263 | 263 | |
264 | 264 | // Need to always return an array, even with only 1 item |
265 | - if ( !is_array($statuses) ) { |
|
266 | - $statuses = array( $statuses ); |
|
265 | + if ( ! is_array($statuses)) { |
|
266 | + $statuses = array($statuses); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $statuses; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @return void |
277 | 277 | */ |
278 | 278 | public function no_items() { |
279 | - echo __( 'No courses found.', 'woothemes-sensei' ); |
|
279 | + echo __('No courses found.', 'woothemes-sensei'); |
|
280 | 280 | } // End no_items() |
281 | 281 | |
282 | 282 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @return void |
286 | 286 | */ |
287 | 287 | public function data_table_header() { |
288 | - echo '<strong>' . __( 'Courses', 'woothemes-sensei' ) . '</strong>'; |
|
288 | + echo '<strong>'.__('Courses', 'woothemes-sensei').'</strong>'; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | * @return void |
295 | 295 | */ |
296 | 296 | public function data_table_footer() { |
297 | - $user = get_user_by( 'id', $this->user_id ); |
|
298 | - $report = sanitize_title( $user->display_name ) . '-course-overview'; |
|
299 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $this->user_id, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
300 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
297 | + $user = get_user_by('id', $this->user_id); |
|
298 | + $report = sanitize_title($user->display_name).'-course-overview'; |
|
299 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $this->user_id, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
300 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @since 1.7.0 |
306 | 306 | * @return string |
307 | 307 | */ |
308 | - public function search_button( $text = '' ) { |
|
309 | - return __( 'Search Courses', 'woothemes-sensei' ); |
|
308 | + public function search_button($text = '') { |
|
309 | + return __('Search Courses', 'woothemes-sensei'); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | } // End Class |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_New_Message_Reply' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_New_Message_Reply')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Teacher New Message |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | function __construct() { |
59 | 59 | $this->template = 'new-message-reply'; |
60 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have a new message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
61 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have received a reply to your private message', 'woothemes-sensei' ), $this->template ); |
|
60 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have a new message', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
61 | + $this->heading = apply_filters('sensei_email_heading', __('You have received a reply to your private message', 'woothemes-sensei'), $this->template); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -69,35 +69,35 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - function trigger ( $comment, $message ) { |
|
72 | + function trigger($comment, $message) { |
|
73 | 73 | |
74 | 74 | global $sensei_email_data; |
75 | 75 | |
76 | 76 | $this->comment = $comment; |
77 | 77 | $this->message = $message; |
78 | 78 | |
79 | - $this->commenter = get_userdata( $comment->user_id ); |
|
79 | + $this->commenter = get_userdata($comment->user_id); |
|
80 | 80 | |
81 | - $original_sender = get_post_meta( $this->message->ID, '_sender', true ); |
|
82 | - $this->original_sender = get_user_by( 'login', $original_sender ); |
|
81 | + $original_sender = get_post_meta($this->message->ID, '_sender', true); |
|
82 | + $this->original_sender = get_user_by('login', $original_sender); |
|
83 | 83 | |
84 | - $original_receiver = get_post_meta( $this->message->ID, '_receiver', true ); |
|
85 | - $this->original_receiver = get_user_by( 'login', $original_receiver ); |
|
84 | + $original_receiver = get_post_meta($this->message->ID, '_receiver', true); |
|
85 | + $this->original_receiver = get_user_by('login', $original_receiver); |
|
86 | 86 | |
87 | - $content_type = get_post_meta( $this->message->ID, '_posttype', true ); |
|
88 | - $content_id = get_post_meta( $this->message->ID, '_post', true ); |
|
89 | - $content_title = get_the_title( $content_id ); |
|
87 | + $content_type = get_post_meta($this->message->ID, '_posttype', true); |
|
88 | + $content_id = get_post_meta($this->message->ID, '_post', true); |
|
89 | + $content_title = get_the_title($content_id); |
|
90 | 90 | |
91 | - $comment_link = get_comment_link( $comment ); |
|
91 | + $comment_link = get_comment_link($comment); |
|
92 | 92 | |
93 | 93 | // setup the post type parameter |
94 | - $content_type = get_post_type( $content_id ); |
|
95 | - if( !$content_type ){ |
|
96 | - $content_type =''; |
|
94 | + $content_type = get_post_type($content_id); |
|
95 | + if ( ! $content_type) { |
|
96 | + $content_type = ''; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Construct data array |
100 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
100 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
101 | 101 | 'template' => $this->template, |
102 | 102 | $content_type.'_id' => $content_id, |
103 | 103 | 'heading' => $this->heading, |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | 'comment_link' => $comment_link, |
107 | 107 | 'content_title' => $content_title, |
108 | 108 | 'content_type' => $content_type, |
109 | - ), $this->template ); |
|
109 | + ), $this->template); |
|
110 | 110 | |
111 | 111 | // Set recipient |
112 | - if( $this->commenter->user_login == $original_sender ) { |
|
113 | - $this->recipient = stripslashes( $this->original_receiver->user_email ); |
|
112 | + if ($this->commenter->user_login == $original_sender) { |
|
113 | + $this->recipient = stripslashes($this->original_receiver->user_email); |
|
114 | 114 | } else { |
115 | - $this->recipient = stripslashes( $this->original_sender->user_email ); |
|
115 | + $this->recipient = stripslashes($this->original_sender->user_email); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Send mail |
119 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
119 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Graded_Quiz' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_Learner_Graded_Quiz')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Learner Graded Quiz |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function __construct() { |
31 | 31 | $this->template = 'learner-graded-quiz'; |
32 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your quiz has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
33 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your quiz has been graded', 'woothemes-sensei' ), $this->template ); |
|
32 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your quiz has been graded', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
33 | + $this->heading = apply_filters('sensei_email_heading', __('Your quiz has been graded', 'woothemes-sensei'), $this->template); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -43,48 +43,48 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return void |
45 | 45 | */ |
46 | - function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) { |
|
46 | + function trigger($user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0) { |
|
47 | 47 | |
48 | 48 | global $sensei_email_data; |
49 | 49 | |
50 | 50 | // Get learner user object |
51 | - $this->user = new WP_User( $user_id ); |
|
51 | + $this->user = new WP_User($user_id); |
|
52 | 52 | |
53 | 53 | // Get passed flag |
54 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
55 | - if( $grade >= $passmark ) { |
|
56 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
54 | + $passed = __('failed', 'woothemes-sensei'); |
|
55 | + if ($grade >= $passmark) { |
|
56 | + $passed = __('passed', 'woothemes-sensei'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // Get grade tye (auto/manual) |
60 | - $grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
60 | + $grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
61 | 61 | |
62 | - if( 'auto' == $grade_type ) { |
|
63 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a quiz', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
64 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a quiz', 'woothemes-sensei' ), $this->template ); |
|
62 | + if ('auto' == $grade_type) { |
|
63 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a quiz', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
64 | + $this->heading = apply_filters('sensei_email_heading', __('You have completed a quiz', 'woothemes-sensei'), $this->template); |
|
65 | 65 | } |
66 | 66 | |
67 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
67 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
68 | 68 | |
69 | 69 | // Construct data array |
70 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
70 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
71 | 71 | 'template' => $this->template, |
72 | 72 | 'heading' => $this->heading, |
73 | 73 | 'user_id' => $user_id, |
74 | - 'user_name' => stripslashes( $this->user->display_name ), |
|
74 | + 'user_name' => stripslashes($this->user->display_name), |
|
75 | 75 | 'lesson_id' => $lesson_id, |
76 | 76 | 'quiz_id' => $quiz_id, |
77 | 77 | 'grade' => $grade, |
78 | 78 | 'passmark' => $passmark, |
79 | 79 | 'passed' => $passed, |
80 | 80 | 'grade_type' => $grade_type, |
81 | - ), $this->template ); |
|
81 | + ), $this->template); |
|
82 | 82 | |
83 | 83 | // Set recipient (learner) |
84 | - $this->recipient = stripslashes( $this->user->user_email ); |
|
84 | + $this->recipient = stripslashes($this->user->user_email); |
|
85 | 85 | |
86 | 86 | // Send mail |
87 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
87 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 |
@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | * This email will be sent to a teacher when a course is assigned to them. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
6 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
7 | 7 | |
8 | -if ( class_exists('Sensei_Email_Teacher_New_Course_Assignment') ){ |
|
8 | +if (class_exists('Sensei_Email_Teacher_New_Course_Assignment')) { |
|
9 | 9 | return; |
10 | 10 | } |
11 | 11 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | function __construct() { |
37 | 37 | |
38 | 38 | $this->template = 'teacher-new-course-assignment'; |
39 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have been assigned to a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
40 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Course assigned to you', 'woothemes-sensei' ), $this->template ); |
|
39 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have been assigned to a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
40 | + $this->heading = apply_filters('sensei_email_heading', __('Course assigned to you', 'woothemes-sensei'), $this->template); |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | * @param $course_id |
50 | 50 | * @return void |
51 | 51 | */ |
52 | - function trigger( $teacher_id = 0, $course_id = 0 ) { |
|
52 | + function trigger($teacher_id = 0, $course_id = 0) { |
|
53 | 53 | global $sensei_email_data; |
54 | 54 | |
55 | - $this->teacher = new WP_User( $teacher_id ); |
|
56 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
57 | - $this->subject = __( 'New course assigned to you', 'woothemes-sensei' ); |
|
55 | + $this->teacher = new WP_User($teacher_id); |
|
56 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
57 | + $this->subject = __('New course assigned to you', 'woothemes-sensei'); |
|
58 | 58 | |
59 | 59 | //course edit link |
60 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
60 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
61 | 61 | |
62 | 62 | // Course name |
63 | - $course = get_post( $course_id); |
|
63 | + $course = get_post($course_id); |
|
64 | 64 | // Construct data array |
65 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
65 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
66 | 66 | 'template' => $this->template, |
67 | 67 | 'heading' => $this->heading, |
68 | 68 | 'teacher_id' => $teacher_id, |
69 | 69 | 'course_id' => $course_id, |
70 | 70 | 'course_name' => $course->post_title, |
71 | 71 | 'course_edit_link' => $course_edit_link, |
72 | - ), $this->template ); |
|
72 | + ), $this->template); |
|
73 | 73 | |
74 | 74 | // Send mail |
75 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
75 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Teacher class |
@@ -40,58 +40,58 @@ discard block |
||
40 | 40 | * @since 1.8.0 |
41 | 41 | * @access public |
42 | 42 | */ |
43 | - public function __construct ( ) { |
|
43 | + public function __construct( ) { |
|
44 | 44 | |
45 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
46 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
47 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
48 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
49 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
45 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
46 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
47 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
48 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
49 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
50 | 50 | |
51 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
51 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
52 | 52 | |
53 | 53 | //filter the quiz submissions |
54 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
54 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
55 | 55 | |
56 | 56 | //grading totals count only those belonging to the teacher |
57 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
57 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
58 | 58 | |
59 | 59 | // show the courses owned by a user on his author archive page |
60 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
60 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
61 | 61 | |
62 | 62 | // notify admin when a teacher creates a course |
63 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
63 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
64 | 64 | |
65 | 65 | // limit the analysis view to only the users taking courses belong to this teacher |
66 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
66 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
67 | 67 | |
68 | 68 | // give teacher access to question post type |
69 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
69 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
70 | 70 | |
71 | 71 | // Teacher column on the courses list on the admin edit screen |
72 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
73 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
72 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
73 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
74 | 74 | |
75 | 75 | //admin edit messages query limit teacher |
76 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
76 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
77 | 77 | |
78 | 78 | //add filter by teacher on courses list |
79 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
80 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
79 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
80 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
81 | 81 | |
82 | 82 | // Handle media library restrictions |
83 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
84 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
83 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
84 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
85 | 85 | |
86 | 86 | // update lesson owner to course teacher when saved |
87 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
87 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
88 | 88 | |
89 | 89 | // If a Teacher logs in, redirect to /wp-admin/ |
90 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
90 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
91 | 91 | |
92 | 92 | |
93 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
94 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
93 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
94 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
95 | 95 | |
96 | 96 | |
97 | 97 | } // end __constructor() |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * @access public |
107 | 107 | * @return void |
108 | 108 | */ |
109 | - public function create_role ( ) { |
|
109 | + public function create_role( ) { |
|
110 | 110 | |
111 | 111 | // check if the role exists |
112 | - $this->teacher_role = get_role( 'teacher' ); |
|
112 | + $this->teacher_role = get_role('teacher'); |
|
113 | 113 | |
114 | 114 | // if the the teacher is not a valid WordPress role create it |
115 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
115 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
116 | 116 | // create the role |
117 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
117 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // add the capabilities before returning |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | * @since 1.8.0 |
129 | 129 | * @access protected |
130 | 130 | */ |
131 | - protected function add_capabilities ( ) { |
|
131 | + protected function add_capabilities( ) { |
|
132 | 132 | |
133 | 133 | // if this is not a valid WP_Role object exit without adding anything |
134 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
134 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | 137 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param array $capabilities |
143 | 143 | * keys: (string) $cap_name => (bool) $grant |
144 | 144 | */ |
145 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
145 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
146 | 146 | // General access rules |
147 | 147 | 'read' => true, |
148 | 148 | 'manage_sensei_grades' => true, |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | )); |
201 | 201 | |
202 | - foreach ( $caps as $cap => $grant ) { |
|
202 | + foreach ($caps as $cap => $grant) { |
|
203 | 203 | |
204 | 204 | // load the capability on to the teacher role |
205 | 205 | $this->teacher_role->add_cap($cap, $grant); |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | * @parameter WP_Post $post |
220 | 220 | * @return void |
221 | 221 | */ |
222 | - public function add_teacher_meta_boxes ( $post ) { |
|
222 | + public function add_teacher_meta_boxes($post) { |
|
223 | 223 | |
224 | - if( !current_user_can('manage_options') ){ |
|
224 | + if ( ! current_user_can('manage_options')) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
227 | + add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'), |
|
228 | 228 | 'course', |
229 | 229 | 'side', |
230 | 230 | 'core' |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @access public |
242 | 242 | * @parameters |
243 | 243 | */ |
244 | - public function teacher_meta_box_content ( $post ) { |
|
244 | + public function teacher_meta_box_content($post) { |
|
245 | 245 | |
246 | 246 | // get the current author |
247 | 247 | $current_author = $post->post_author; |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
254 | 254 | |
255 | - <?php foreach ( $users as $user_id ) { ?> |
|
255 | + <?php foreach ($users as $user_id) { ?> |
|
256 | 256 | |
257 | 257 | <?php |
258 | 258 | $user = get_user_by('id', $user_id); |
259 | 259 | ?> |
260 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
260 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
261 | 261 | <?php echo $user->display_name; ?> |
262 | 262 | </option> |
263 | 263 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @parameters |
280 | 280 | * @return array $users user id array |
281 | 281 | */ |
282 | - public function get_teachers_and_authors ( ){ |
|
282 | + public function get_teachers_and_authors( ) { |
|
283 | 283 | |
284 | 284 | $author_query_args = array( |
285 | 285 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | 'who' => 'authors' |
288 | 288 | ); |
289 | 289 | |
290 | - $authors = get_users( $author_query_args ); |
|
290 | + $authors = get_users($author_query_args); |
|
291 | 291 | |
292 | 292 | $teacher_query_args = array( |
293 | 293 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | 'role' => 'teacher', |
296 | 296 | ); |
297 | 297 | |
298 | - $teachers = get_users( $teacher_query_args ); |
|
298 | + $teachers = get_users($teacher_query_args); |
|
299 | 299 | |
300 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
300 | + return array_unique(array_merge($teachers, $authors)); |
|
301 | 301 | |
302 | 302 | }// end get_teachers_and_authors |
303 | 303 | |
@@ -313,43 +313,43 @@ discard block |
||
313 | 313 | * @parameters |
314 | 314 | * @return array $users user id array |
315 | 315 | */ |
316 | - public function save_teacher_meta_box ( $course_id ){ |
|
316 | + public function save_teacher_meta_box($course_id) { |
|
317 | 317 | |
318 | 318 | // check if this is a post from saving the teacher, if not exit early |
319 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
319 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | 323 | //don't fire this hook again |
324 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
324 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
325 | 325 | |
326 | 326 | // get the current post object |
327 | - $post = get_post( $course_id ); |
|
327 | + $post = get_post($course_id); |
|
328 | 328 | |
329 | 329 | // get the current teacher/author |
330 | - $current_author = absint( $post->post_author ); |
|
331 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
330 | + $current_author = absint($post->post_author); |
|
331 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
332 | 332 | |
333 | 333 | // loop through all post lessons to update their authors as well |
334 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
334 | + $this->update_course_lessons_author($course_id, $new_author); |
|
335 | 335 | |
336 | 336 | // do not do any processing if the selected author is the same as the current author |
337 | - if( $current_author == $new_author ){ |
|
337 | + if ($current_author == $new_author) { |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | |
341 | 341 | // save the course author |
342 | 342 | $post_updates = array( |
343 | - 'ID' => $post->ID , |
|
343 | + 'ID' => $post->ID, |
|
344 | 344 | 'post_author' => $new_author |
345 | 345 | ); |
346 | - wp_update_post( $post_updates ); |
|
346 | + wp_update_post($post_updates); |
|
347 | 347 | |
348 | 348 | // ensure the the modules are update so that then new teacher has access to them |
349 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
349 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
350 | 350 | |
351 | 351 | // notify the new teacher |
352 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
352 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
353 | 353 | |
354 | 354 | } // end save_teacher_meta_box |
355 | 355 | |
@@ -363,56 +363,56 @@ discard block |
||
363 | 363 | * @param $new_teacher_id |
364 | 364 | * @return void |
365 | 365 | */ |
366 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
366 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
367 | 367 | |
368 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
368 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
372 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
373 | 373 | |
374 | - if( empty( $terms_selected_on_course ) ){ |
|
374 | + if (empty($terms_selected_on_course)) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - foreach( $terms_selected_on_course as $term ){ |
|
378 | + foreach ($terms_selected_on_course as $term) { |
|
379 | 379 | |
380 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
381 | - if( $new_teacher_id != $term_author->ID ){ |
|
380 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
381 | + if ($new_teacher_id != $term_author->ID) { |
|
382 | 382 | |
383 | 383 | $new_term = ''; |
384 | 384 | |
385 | 385 | //if the new teacher is admin first check to see if the term with this name already exists |
386 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
386 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
387 | 387 | |
388 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
389 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
390 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
391 | - if( !empty( $existing_admin_terms ) ){ |
|
388 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
389 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
390 | + $existing_admin_terms = get_terms('module', $term_args); |
|
391 | + if ( ! empty($existing_admin_terms)) { |
|
392 | 392 | // insert it even if it exists |
393 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
393 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - if( empty ( $new_term ) ){ |
|
397 | + if (empty ($new_term)) { |
|
398 | 398 | |
399 | 399 | //setup the new slug |
400 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
400 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
401 | 401 | |
402 | 402 | // create new term and set it |
403 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
403 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
404 | 404 | |
405 | 405 | } |
406 | 406 | |
407 | 407 | |
408 | 408 | |
409 | 409 | // if term exists |
410 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
410 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
411 | 411 | |
412 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
412 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
413 | 413 | $term_id = $existing_term->term_id; |
414 | 414 | |
415 | - }else{ |
|
415 | + } else { |
|
416 | 416 | |
417 | 417 | // for a new term simply get the term from the returned value |
418 | 418 | $term_id = $new_term['term_id']; |
@@ -420,21 +420,21 @@ discard block |
||
420 | 420 | } // end if term exist |
421 | 421 | |
422 | 422 | // set the terms selected on the course |
423 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
423 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
424 | 424 | |
425 | 425 | // remove old term |
426 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
426 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
427 | 427 | |
428 | 428 | // update the lessons within the current module term |
429 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
430 | - foreach( $lessons as $lesson ){ |
|
429 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
430 | + foreach ($lessons as $lesson) { |
|
431 | 431 | |
432 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
432 | + if (has_term($term->slug, 'module', $lesson)) { |
|
433 | 433 | |
434 | 434 | // add the new term, the false at the end says to replace all terms on this module |
435 | 435 | // with the new term. |
436 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
437 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
436 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
437 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | }// end for each |
@@ -454,50 +454,50 @@ discard block |
||
454 | 454 | * @parameters |
455 | 455 | * @return array $users user id array |
456 | 456 | */ |
457 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
457 | + public function update_course_lessons_author($course_id, $new_author) { |
|
458 | 458 | |
459 | 459 | |
460 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
460 | + if (empty($course_id) || empty($new_author)) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
464 | 464 | //get a list of course lessons |
465 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
465 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
466 | 466 | |
467 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
467 | + if (empty($lessons) || ! is_array($lessons)) { |
|
468 | 468 | return false; |
469 | 469 | } |
470 | 470 | |
471 | 471 | // update each lesson and quiz author |
472 | - foreach( $lessons as $lesson ){ |
|
472 | + foreach ($lessons as $lesson) { |
|
473 | 473 | |
474 | 474 | // don't update if the author is tha same as the new author |
475 | - if( $new_author == $lesson->post_author ){ |
|
475 | + if ($new_author == $lesson->post_author) { |
|
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // update lesson author |
480 | - wp_update_post( array( |
|
480 | + wp_update_post(array( |
|
481 | 481 | 'ID'=> $lesson->ID, |
482 | 482 | 'post_author' => $new_author |
483 | - ) ); |
|
483 | + )); |
|
484 | 484 | |
485 | 485 | // update quiz author |
486 | 486 | //get the lessons quiz |
487 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
488 | - if( is_array( $lesson_quizzes ) ){ |
|
489 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
487 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
488 | + if (is_array($lesson_quizzes)) { |
|
489 | + foreach ($lesson_quizzes as $quiz_id) { |
|
490 | 490 | // update quiz with new author |
491 | - wp_update_post( array( |
|
491 | + wp_update_post(array( |
|
492 | 492 | 'ID' => $quiz_id, |
493 | 493 | 'post_author' => $new_author |
494 | - ) ); |
|
494 | + )); |
|
495 | 495 | } |
496 | - }else{ |
|
497 | - wp_update_post( array( |
|
496 | + } else { |
|
497 | + wp_update_post(array( |
|
498 | 498 | 'ID' => $lesson_quizzes, |
499 | 499 | 'post_author' => $new_author |
500 | - ) ); |
|
500 | + )); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } // end for each lessons |
@@ -518,30 +518,30 @@ discard block |
||
518 | 518 | * @parameters $query |
519 | 519 | * @return array $users user id array |
520 | 520 | */ |
521 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
521 | + public function course_analysis_teacher_access_limit($query) { |
|
522 | 522 | |
523 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
523 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
524 | 524 | return $query; |
525 | 525 | } |
526 | 526 | |
527 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
527 | + if ( ! function_exists('get_current_screen')) { |
|
528 | 528 | return $query; |
529 | 529 | } |
530 | 530 | |
531 | 531 | $screen = get_current_screen(); |
532 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
532 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
533 | 533 | |
534 | 534 | // exit early for the following conditions |
535 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
535 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
536 | 536 | |
537 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
538 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
537 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
538 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
539 | 539 | return $query; |
540 | 540 | } |
541 | 541 | |
542 | 542 | global $current_user; |
543 | 543 | // set the query author to the current user to only show those those posts |
544 | - $query->set( 'author', $current_user->ID ); |
|
544 | + $query->set('author', $current_user->ID); |
|
545 | 545 | return $query; |
546 | 546 | |
547 | 547 | }// end course_analysis_teacher_access_limit |
@@ -557,14 +557,14 @@ discard block |
||
557 | 557 | * @parameters array $wp_query |
558 | 558 | * @return bool $is_admin_teacher |
559 | 559 | */ |
560 | - public function is_admin_teacher ( ){ |
|
560 | + public function is_admin_teacher( ) { |
|
561 | 561 | |
562 | - if( ! is_user_logged_in()){ |
|
562 | + if ( ! is_user_logged_in()) { |
|
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | $is_admin_teacher = false; |
566 | 566 | |
567 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
567 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
568 | 568 | |
569 | 569 | $is_admin_teacher = true; |
570 | 570 | |
@@ -584,14 +584,14 @@ discard block |
||
584 | 584 | * @param string $perm User permission level |
585 | 585 | * @return object Modified status counts |
586 | 586 | */ |
587 | - public function list_table_counts( $counts, $type, $perm ) { |
|
587 | + public function list_table_counts($counts, $type, $perm) { |
|
588 | 588 | global $current_user; |
589 | 589 | |
590 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
590 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
591 | 591 | return $counts; |
592 | 592 | } |
593 | 593 | |
594 | - if( ! $this->is_admin_teacher() ) { |
|
594 | + if ( ! $this->is_admin_teacher()) { |
|
595 | 595 | return $counts; |
596 | 596 | } |
597 | 597 | |
@@ -605,10 +605,10 @@ discard block |
||
605 | 605 | $stati = get_post_stati(); |
606 | 606 | |
607 | 607 | // Update count object |
608 | - foreach( $stati as $status ) { |
|
608 | + foreach ($stati as $status) { |
|
609 | 609 | $args['post_status'] = $status; |
610 | - $posts = get_posts( $args ); |
|
611 | - $counts->$status = count( $posts ); |
|
610 | + $posts = get_posts($args); |
|
611 | + $counts->$status = count($posts); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | return $counts; |
@@ -622,22 +622,22 @@ discard block |
||
622 | 622 | * @since 1.8.0 |
623 | 623 | * |
624 | 624 | */ |
625 | - public function filter_queries ( $query ) { |
|
625 | + public function filter_queries($query) { |
|
626 | 626 | global $current_user; |
627 | 627 | |
628 | - if( ! $this->is_admin_teacher() ) { |
|
628 | + if ( ! $this->is_admin_teacher()) { |
|
629 | 629 | return; |
630 | 630 | } |
631 | 631 | |
632 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
632 | + if ( ! function_exists('get_current_screen')) { |
|
633 | 633 | return; |
634 | 634 | } |
635 | 635 | |
636 | 636 | $screen = get_current_screen(); |
637 | - if( empty( $screen ) ) { |
|
637 | + if (empty($screen)) { |
|
638 | 638 | return $query; |
639 | 639 | } |
640 | - switch( $screen->id ) { |
|
640 | + switch ($screen->id) { |
|
641 | 641 | case 'sensei_page_sensei_grading': |
642 | 642 | case 'sensei_page_sensei_analysis': |
643 | 643 | case 'sensei_page_sensei_learners': |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * @param string $screen_id |
657 | 657 | * |
658 | 658 | */ |
659 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
659 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
660 | 660 | break; |
661 | 661 | } |
662 | 662 | } |
@@ -671,31 +671,31 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return array $comments |
673 | 673 | */ |
674 | - public function filter_grading_activity_queries( $comments ){ |
|
674 | + public function filter_grading_activity_queries($comments) { |
|
675 | 675 | |
676 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
677 | - return $comments ; |
|
676 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
677 | + return $comments; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | //check if we're on the grading screen |
681 | 681 | $screen = get_current_screen(); |
682 | 682 | |
683 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
683 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
684 | 684 | return $comments; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // get the course and determine if the current teacher is the owner |
688 | 688 | // if not remove it from the list of comments to be returned |
689 | - foreach( $comments as $key => $comment){ |
|
690 | - $lesson = get_post( $comment->comment_post_ID ); |
|
691 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
692 | - $course = get_post( $course_id ); |
|
693 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
689 | + foreach ($comments as $key => $comment) { |
|
690 | + $lesson = get_post($comment->comment_post_ID); |
|
691 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
692 | + $course = get_post($course_id); |
|
693 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
694 | 694 | //remove this as the teacher should see this. |
695 | - unset( $comments[ $key ] ); |
|
695 | + unset($comments[$key]); |
|
696 | 696 | } |
697 | 697 | } |
698 | - return $comments ; |
|
698 | + return $comments; |
|
699 | 699 | |
700 | 700 | }// end function filter grading |
701 | 701 | |
@@ -711,34 +711,34 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @return array $args |
713 | 713 | */ |
714 | - public function limit_grading_totals( $args ){ |
|
714 | + public function limit_grading_totals($args) { |
|
715 | 715 | |
716 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
717 | - return $args ; |
|
716 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
717 | + return $args; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | //get the teachers courses |
721 | 721 | // the query is already filtered to only the teacher |
722 | - $courses = Sensei()->course->get_all_courses(); |
|
722 | + $courses = Sensei()->course->get_all_courses(); |
|
723 | 723 | |
724 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
724 | + if (empty($courses) || ! is_array($courses)) { |
|
725 | 725 | return $args; |
726 | 726 | } |
727 | 727 | |
728 | 728 | //setup the lessons quizzes to limit the grading totals to |
729 | 729 | $quiz_scope = array(); |
730 | - foreach( $courses as $course ){ |
|
730 | + foreach ($courses as $course) { |
|
731 | 731 | |
732 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
732 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
733 | 733 | |
734 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
734 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
735 | 735 | |
736 | - foreach( $course_lessons as $lesson ){ |
|
736 | + foreach ($course_lessons as $lesson) { |
|
737 | 737 | |
738 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
739 | - if( !empty( $quiz_id ) ) { |
|
738 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
739 | + if ( ! empty($quiz_id)) { |
|
740 | 740 | |
741 | - array_push( $quiz_scope, $quiz_id ); |
|
741 | + array_push($quiz_scope, $quiz_id); |
|
742 | 742 | |
743 | 743 | } |
744 | 744 | |
@@ -761,41 +761,41 @@ discard block |
||
761 | 761 | * @param WP_Query $query |
762 | 762 | * @return WP_Query $query |
763 | 763 | */ |
764 | - public function add_courses_to_author_archive( $query ) { |
|
764 | + public function add_courses_to_author_archive($query) { |
|
765 | 765 | |
766 | - if ( is_admin() || ! $query->is_author() ){ |
|
766 | + if (is_admin() || ! $query->is_author()) { |
|
767 | 767 | return $query; |
768 | 768 | } |
769 | 769 | |
770 | 770 | // this should only apply to users with the teacher role |
771 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
772 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
771 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
772 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
773 | 773 | |
774 | 774 | return $query; |
775 | 775 | |
776 | 776 | } |
777 | 777 | |
778 | 778 | // Change post types depending on what is set already |
779 | - $current_post_types = $query->get( 'post_type' ); |
|
780 | - if( empty( $current_post_types ) ){ |
|
779 | + $current_post_types = $query->get('post_type'); |
|
780 | + if (empty($current_post_types)) { |
|
781 | 781 | |
782 | 782 | // if empty it means post by default, so add post so that it also includes that for now |
783 | - $new_post_types = array( 'post', 'course' ); |
|
783 | + $new_post_types = array('post', 'course'); |
|
784 | 784 | |
785 | - } elseif( is_array( $current_post_types ) ) { |
|
785 | + } elseif (is_array($current_post_types)) { |
|
786 | 786 | |
787 | 787 | // merge the post types instead of overwriting it |
788 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
788 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
789 | 789 | |
790 | - }else{ |
|
790 | + } else { |
|
791 | 791 | |
792 | 792 | // in this instance it is probably just one post type in string format |
793 | - $new_post_types = array( $current_post_types , 'course'); |
|
793 | + $new_post_types = array($current_post_types, 'course'); |
|
794 | 794 | |
795 | 795 | } |
796 | 796 | |
797 | 797 | // change the query before returning it |
798 | - $query->set('post_type', $new_post_types ); |
|
798 | + $query->set('post_type', $new_post_types); |
|
799 | 799 | |
800 | 800 | /** |
801 | 801 | * Change the query on the teacher author archive template |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | * @since 1.8.4 |
804 | 804 | * @param WP_Query $query |
805 | 805 | */ |
806 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
806 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
807 | 807 | |
808 | 808 | } |
809 | 809 | |
@@ -816,21 +816,21 @@ discard block |
||
816 | 816 | * @param $course_id |
817 | 817 | * @return bool |
818 | 818 | */ |
819 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
819 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
820 | 820 | |
821 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
821 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | |
825 | 825 | // if new user is the same as the current logged user, they don't need an email |
826 | - if( $teacher_id == get_current_user_id() ){ |
|
826 | + if ($teacher_id == get_current_user_id()) { |
|
827 | 827 | return true; |
828 | 828 | } |
829 | 829 | |
830 | 830 | // load the email class |
831 | 831 | include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
832 | 832 | $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
833 | - $email->trigger( $teacher_id, $course_id ); |
|
833 | + $email->trigger($teacher_id, $course_id); |
|
834 | 834 | |
835 | 835 | return true; |
836 | 836 | } // end teacher_course_assigned_notification |
@@ -844,12 +844,12 @@ discard block |
||
844 | 844 | * @param int $course_id |
845 | 845 | * @return bool |
846 | 846 | */ |
847 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
847 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
848 | 848 | |
849 | 849 | $course_id = $post->ID; |
850 | 850 | |
851 | - if( 'publish'== $old_status || 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
852 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
851 | + if ('publish' == $old_status || 'course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
852 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
853 | 853 | |
854 | 854 | return false; |
855 | 855 | |
@@ -863,19 +863,19 @@ discard block |
||
863 | 863 | * |
864 | 864 | * @param bool $on default true |
865 | 865 | */ |
866 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
866 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | 870 | // setting up the data needed by the email template |
871 | 871 | global $sensei_email_data; |
872 | 872 | $template = 'admin-teacher-new-course-created'; |
873 | - $course = get_post( $course_id ); |
|
874 | - $teacher = new WP_User( $course->post_author ); |
|
873 | + $course = get_post($course_id); |
|
874 | + $teacher = new WP_User($course->post_author); |
|
875 | 875 | $recipient = get_option('admin_email', true); |
876 | 876 | |
877 | 877 | // don't send if the course is created by admin |
878 | - if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
878 | + if ($recipient == $teacher->user_email || current_user_can('manage_options')) { |
|
879 | 879 | return false; |
880 | 880 | } |
881 | 881 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | * @since 1.8.0 |
886 | 886 | * @param string $template |
887 | 887 | */ |
888 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
888 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
889 | 889 | |
890 | 890 | /** |
891 | 891 | * Filter the email subject for the the |
@@ -896,11 +896,11 @@ discard block |
||
896 | 896 | * @param string $template |
897 | 897 | */ |
898 | 898 | $subject = apply_filters('sensei_email_subject', |
899 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
900 | - $template ); |
|
899 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
900 | + $template); |
|
901 | 901 | |
902 | 902 | //course edit link |
903 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
903 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
904 | 904 | |
905 | 905 | // Construct data array |
906 | 906 | $email_data = array( |
@@ -919,10 +919,10 @@ discard block |
||
919 | 919 | * @param array $email_data |
920 | 920 | * @param string $template |
921 | 921 | */ |
922 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
922 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
923 | 923 | |
924 | 924 | // Send mail |
925 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
925 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
926 | 926 | |
927 | 927 | }// end notify admin of course creation |
928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
933 | 933 | * @param array $args WP_User_Query arguments |
934 | 934 | * @return array $learners_query_results |
935 | 935 | */ |
936 | - public function limit_analysis_learners( $args ){ |
|
936 | + public function limit_analysis_learners($args) { |
|
937 | 937 | |
938 | 938 | // show default for none teachers |
939 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
939 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
940 | 940 | return $args; |
941 | 941 | } |
942 | 942 | |
@@ -945,31 +945,31 @@ discard block |
||
945 | 945 | $teacher_courses = Sensei()->course->get_all_courses(); |
946 | 946 | |
947 | 947 | // if the user has no courses they should see no users |
948 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
948 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
949 | 949 | // tell the query to return 0 students |
950 | - $args[ 'include'] = array( 0 ); |
|
950 | + $args['include'] = array(0); |
|
951 | 951 | return $args; |
952 | 952 | |
953 | 953 | } |
954 | 954 | |
955 | 955 | $learner_ids_for_teacher_courses = array(); |
956 | - foreach( $teacher_courses as $course ){ |
|
956 | + foreach ($teacher_courses as $course) { |
|
957 | 957 | |
958 | 958 | $course_learner_ids = array(); |
959 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
959 | + $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
960 | 960 | |
961 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
961 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
962 | 962 | continue; // skip to the next course as there are no users on this course |
963 | 963 | } |
964 | 964 | |
965 | 965 | // it could be an array of comments or a single comment |
966 | - if( is_array( $activity_comments ) ){ |
|
966 | + if (is_array($activity_comments)) { |
|
967 | 967 | |
968 | - foreach( $activity_comments as $comment ){ |
|
968 | + foreach ($activity_comments as $comment) { |
|
969 | 969 | |
970 | - $user = get_userdata( $comment->user_id ); |
|
970 | + $user = get_userdata($comment->user_id); |
|
971 | 971 | |
972 | - if( empty( $user ) ){ |
|
972 | + if (empty($user)) { |
|
973 | 973 | // next comment in this array |
974 | 974 | continue; |
975 | 975 | } |
@@ -977,26 +977,26 @@ discard block |
||
977 | 977 | $course_learner_ids[] = $user->ID; |
978 | 978 | } |
979 | 979 | |
980 | - }else{ |
|
980 | + } else { |
|
981 | 981 | |
982 | - $user = get_userdata( $activity_comments->user_id ); |
|
982 | + $user = get_userdata($activity_comments->user_id); |
|
983 | 983 | $course_learner_ids[] = $user->ID; |
984 | 984 | |
985 | 985 | } |
986 | 986 | |
987 | 987 | // add learners on this course to the all courses learner list |
988 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
988 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
989 | 989 | |
990 | 990 | } |
991 | 991 | |
992 | 992 | // if there are no students taking the courses by this teacher don't show them any of the other users |
993 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
993 | + if (empty($learner_ids_for_teacher_courses)) { |
|
994 | 994 | |
995 | - $args[ 'include'] = array( 0 ); |
|
995 | + $args['include'] = array(0); |
|
996 | 996 | |
997 | - }else{ |
|
997 | + } else { |
|
998 | 998 | |
999 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
999 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
1000 | 1000 | |
1001 | 1001 | } |
1002 | 1002 | |
@@ -1013,35 +1013,35 @@ discard block |
||
1013 | 1013 | * @param $questions |
1014 | 1014 | * @return mixed |
1015 | 1015 | */ |
1016 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
1016 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
1017 | 1017 | |
1018 | - if( ! $this->is_admin_teacher() ){ |
|
1018 | + if ( ! $this->is_admin_teacher()) { |
|
1019 | 1019 | return $questions; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | $screen = get_current_screen(); |
1023 | 1023 | |
1024 | 1024 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
1025 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
1025 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
1026 | 1026 | |
1027 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
1027 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
1028 | 1028 | |
1029 | 1029 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1030 | - if( ! empty($admin_user) ){ |
|
1030 | + if ( ! empty($admin_user)) { |
|
1031 | 1031 | |
1032 | 1032 | $current_teacher_id = get_current_user_id(); |
1033 | 1033 | |
1034 | 1034 | // set current user to admin so teacher can view all questions |
1035 | - wp_set_current_user( $admin_user->ID ); |
|
1036 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
1035 | + wp_set_current_user($admin_user->ID); |
|
1036 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
1037 | 1037 | |
1038 | 1038 | // set the teacher as the current use again |
1039 | - wp_set_current_user( $current_teacher_id ); |
|
1039 | + wp_set_current_user($current_teacher_id); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | } |
1043 | 1043 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
1044 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
1044 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
1045 | 1045 | |
1046 | 1046 | return $questions; |
1047 | 1047 | } |
@@ -1053,30 +1053,30 @@ discard block |
||
1053 | 1053 | * @param $wp_query |
1054 | 1054 | * @return mixed |
1055 | 1055 | */ |
1056 | - public function give_access_to_all_questions( $wp_query ){ |
|
1056 | + public function give_access_to_all_questions($wp_query) { |
|
1057 | 1057 | |
1058 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
1058 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
1059 | 1059 | |
1060 | 1060 | return $wp_query; |
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | $screen = get_current_screen(); |
1064 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
1065 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
1064 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
1065 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
1066 | 1066 | |
1067 | 1067 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1068 | - if( ! empty($admin_user) ){ |
|
1068 | + if ( ! empty($admin_user)) { |
|
1069 | 1069 | |
1070 | 1070 | $current_teacher_id = get_current_user_id(); |
1071 | 1071 | |
1072 | 1072 | // set current user to admin so teacher can view all questions |
1073 | - wp_set_current_user( $admin_user->ID ); |
|
1073 | + wp_set_current_user($admin_user->ID); |
|
1074 | 1074 | |
1075 | 1075 | //run new query as admin |
1076 | - $wp_query = new WP_Query( $wp_query->query ); |
|
1076 | + $wp_query = new WP_Query($wp_query->query); |
|
1077 | 1077 | |
1078 | 1078 | //set the teache as current use again |
1079 | - wp_set_current_user( $current_teacher_id ); |
|
1079 | + wp_set_current_user($current_teacher_id); |
|
1080 | 1080 | |
1081 | 1081 | } |
1082 | 1082 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | */ |
1094 | 1094 | public function course_column_heading($columns) { |
1095 | 1095 | |
1096 | - if( $this->is_admin_teacher() ){ |
|
1096 | + if ($this->is_admin_teacher()) { |
|
1097 | 1097 | return $columns; |
1098 | 1098 | } |
1099 | 1099 | $new_columns = array( |
@@ -1110,20 +1110,20 @@ discard block |
||
1110 | 1110 | * @param $column |
1111 | 1111 | * @param $course_id |
1112 | 1112 | */ |
1113 | - public function course_column_data( $column, $course_id ){ |
|
1113 | + public function course_column_data($column, $course_id) { |
|
1114 | 1114 | |
1115 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
1115 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
1116 | 1116 | return; |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - $course = get_post( $course_id ); |
|
1120 | - $teacher = get_userdata( $course->post_author ); |
|
1119 | + $course = get_post($course_id); |
|
1120 | + $teacher = get_userdata($course->post_author); |
|
1121 | 1121 | |
1122 | - if( !$teacher ){ |
|
1122 | + if ( ! $teacher) { |
|
1123 | 1123 | return; |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
1126 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
1127 | 1127 | |
1128 | 1128 | }// end course_column_ data |
1129 | 1129 | |
@@ -1138,31 +1138,31 @@ discard block |
||
1138 | 1138 | * |
1139 | 1139 | * @return array $teachers_courses |
1140 | 1140 | */ |
1141 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
1141 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
1142 | 1142 | |
1143 | 1143 | $teachers_courses = array(); |
1144 | 1144 | |
1145 | - if( empty( $teacher_id ) ){ |
|
1145 | + if (empty($teacher_id)) { |
|
1146 | 1146 | $teacher_id = get_current_user_id(); |
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | $all_courses = Sensei()->course->get_all_courses(); |
1150 | 1150 | |
1151 | - if( empty( $all_courses ) ){ |
|
1151 | + if (empty($all_courses)) { |
|
1152 | 1152 | return $all_courses; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - foreach( $all_courses as $course ){ |
|
1155 | + foreach ($all_courses as $course) { |
|
1156 | 1156 | |
1157 | - if( $course->post_author != $teacher_id ){ |
|
1157 | + if ($course->post_author != $teacher_id) { |
|
1158 | 1158 | continue; |
1159 | 1159 | } |
1160 | 1160 | |
1161 | - if( $return_ids_only ){ |
|
1161 | + if ($return_ids_only) { |
|
1162 | 1162 | |
1163 | 1163 | $teachers_courses[] = $course->ID; |
1164 | 1164 | |
1165 | - }else{ |
|
1165 | + } else { |
|
1166 | 1166 | |
1167 | 1167 | $teachers_courses[] = $course; |
1168 | 1168 | |
@@ -1182,21 +1182,21 @@ discard block |
||
1182 | 1182 | * @param $query |
1183 | 1183 | * @return mixed |
1184 | 1184 | */ |
1185 | - public function limit_edit_messages_query( $query ){ |
|
1186 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
1185 | + public function limit_edit_messages_query($query) { |
|
1186 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
1187 | 1187 | return $query; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | $teacher = wp_get_current_user(); |
1191 | 1191 | |
1192 | - $query->set( 'meta_key', '_receiver' ); |
|
1192 | + $query->set('meta_key', '_receiver'); |
|
1193 | 1193 | $meta_query_args = array( |
1194 | 1194 | 'key' => '_receiver', |
1195 | - 'value' => $teacher->get('user_login') , |
|
1195 | + 'value' => $teacher->get('user_login'), |
|
1196 | 1196 | 'compare' => '=' |
1197 | 1197 | ); |
1198 | 1198 | |
1199 | - $query->set('meta_query', $meta_query_args ); |
|
1199 | + $query->set('meta_query', $meta_query_args); |
|
1200 | 1200 | |
1201 | 1201 | return $query; |
1202 | 1202 | } |
@@ -1212,7 +1212,7 @@ discard block |
||
1212 | 1212 | public function course_teacher_filter_options() { |
1213 | 1213 | global $typenow; |
1214 | 1214 | |
1215 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1215 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1216 | 1216 | return; |
1217 | 1217 | } |
1218 | 1218 | |
@@ -1222,31 +1222,31 @@ discard block |
||
1222 | 1222 | // get roles with the course edit capability |
1223 | 1223 | // and then get the users with those roles |
1224 | 1224 | $users_who_can_edit_courses = array(); |
1225 | - foreach( $roles as $role_item ){ |
|
1225 | + foreach ($roles as $role_item) { |
|
1226 | 1226 | |
1227 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
1227 | + $role = get_role(strtolower($role_item['name'])); |
|
1228 | 1228 | |
1229 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
1229 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
1230 | 1230 | |
1231 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
1232 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
1231 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
1232 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
1233 | 1233 | |
1234 | 1234 | // add user from the current $user_role to all users |
1235 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
1235 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
1236 | 1236 | |
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | // Create the select element with the given users who can edit course |
1242 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1242 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1243 | 1243 | $course_options = ''; |
1244 | - foreach( $users_who_can_edit_courses as $user ) { |
|
1245 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
1244 | + foreach ($users_who_can_edit_courses as $user) { |
|
1245 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | 1248 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
1249 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
1249 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
1250 | 1250 | $output .= $course_options; |
1251 | 1251 | $output .= '</select>'; |
1252 | 1252 | |
@@ -1261,15 +1261,15 @@ discard block |
||
1261 | 1261 | * @param $query |
1262 | 1262 | * @return $query |
1263 | 1263 | */ |
1264 | - public function teacher_filter_query_modify( $query ){ |
|
1264 | + public function teacher_filter_query_modify($query) { |
|
1265 | 1265 | global $typenow; |
1266 | 1266 | |
1267 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1267 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1268 | 1268 | return $query; |
1269 | 1269 | } |
1270 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1270 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1271 | 1271 | |
1272 | - if( empty( $course_teacher ) ) { |
|
1272 | + if (empty($course_teacher)) { |
|
1273 | 1273 | return $query; |
1274 | 1274 | } |
1275 | 1275 | |
@@ -1282,23 +1282,23 @@ discard block |
||
1282 | 1282 | * @param array $request Default request arguments |
1283 | 1283 | * @return array Modified request arguments |
1284 | 1284 | */ |
1285 | - public function restrict_media_library( $request = array() ) { |
|
1285 | + public function restrict_media_library($request = array()) { |
|
1286 | 1286 | |
1287 | - if( ! is_admin() ) { |
|
1287 | + if ( ! is_admin()) { |
|
1288 | 1288 | return $request; |
1289 | 1289 | } |
1290 | 1290 | |
1291 | - if( ! $this->is_admin_teacher() ) { |
|
1291 | + if ( ! $this->is_admin_teacher()) { |
|
1292 | 1292 | return $request; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | $screen = get_current_screen(); |
1296 | 1296 | |
1297 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
1298 | - $teacher = intval( get_current_user_id() ); |
|
1297 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
1298 | + $teacher = intval(get_current_user_id()); |
|
1299 | 1299 | |
1300 | - if( $teacher ) { |
|
1301 | - $request['author__in'] = array( $teacher ); |
|
1300 | + if ($teacher) { |
|
1301 | + $request['author__in'] = array($teacher); |
|
1302 | 1302 | } |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1310,20 +1310,20 @@ discard block |
||
1310 | 1310 | * @param array $query Default query arguments |
1311 | 1311 | * @return array Modified query arguments |
1312 | 1312 | */ |
1313 | - public function restrict_media_library_modal( $query = array() ) { |
|
1313 | + public function restrict_media_library_modal($query = array()) { |
|
1314 | 1314 | |
1315 | - if( ! is_admin() ) { |
|
1315 | + if ( ! is_admin()) { |
|
1316 | 1316 | return $query; |
1317 | 1317 | } |
1318 | 1318 | |
1319 | - if( ! $this->is_admin_teacher() ) { |
|
1319 | + if ( ! $this->is_admin_teacher()) { |
|
1320 | 1320 | return $query; |
1321 | 1321 | } |
1322 | 1322 | |
1323 | - $teacher = intval( get_current_user_id() ); |
|
1323 | + $teacher = intval(get_current_user_id()); |
|
1324 | 1324 | |
1325 | - if( $teacher ) { |
|
1326 | - $query['author__in'] = array( $teacher ); |
|
1325 | + if ($teacher) { |
|
1326 | + $query['author__in'] = array($teacher); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | return $query; |
@@ -1336,28 +1336,28 @@ discard block |
||
1336 | 1336 | * |
1337 | 1337 | * @param int $lesson_id |
1338 | 1338 | */ |
1339 | - public function update_lesson_teacher( $lesson_id ){ |
|
1339 | + public function update_lesson_teacher($lesson_id) { |
|
1340 | 1340 | |
1341 | - if( 'lesson'!= get_post_type() ){ |
|
1341 | + if ('lesson' != get_post_type()) { |
|
1342 | 1342 | return; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | 1345 | // this should only run once per request cycle |
1346 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
1346 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
1347 | 1347 | |
1348 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1348 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
1349 | 1349 | |
1350 | - if( empty( $course_id ) || ! $course_id ){ |
|
1350 | + if (empty($course_id) || ! $course_id) { |
|
1351 | 1351 | return; |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - $course = get_post( $course_id ); |
|
1354 | + $course = get_post($course_id); |
|
1355 | 1355 | |
1356 | - $lesson_update_args= array( |
|
1357 | - 'ID' => $lesson_id , |
|
1356 | + $lesson_update_args = array( |
|
1357 | + 'ID' => $lesson_id, |
|
1358 | 1358 | 'post_author' => $course->post_author |
1359 | 1359 | ); |
1360 | - wp_update_post( $lesson_update_args ); |
|
1360 | + wp_update_post($lesson_update_args); |
|
1361 | 1361 | |
1362 | 1362 | } // end update_lesson_teacher |
1363 | 1363 | |
@@ -1371,21 +1371,21 @@ discard block |
||
1371 | 1371 | * @parameters array $wp_query |
1372 | 1372 | * @return WP_Query $wp_query |
1373 | 1373 | */ |
1374 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
1374 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
1375 | 1375 | global $current_user; |
1376 | 1376 | |
1377 | 1377 | //exit early |
1378 | - if( ! $this->is_admin_teacher() ){ |
|
1378 | + if ( ! $this->is_admin_teacher()) { |
|
1379 | 1379 | return $wp_query; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
1382 | + if ( ! function_exists('get_current_screen')) { |
|
1383 | 1383 | return $wp_query; |
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | $screen = get_current_screen(); |
1387 | 1387 | |
1388 | - if( empty( $screen ) ){ |
|
1388 | + if (empty($screen)) { |
|
1389 | 1389 | return $wp_query; |
1390 | 1390 | } |
1391 | 1391 | |
@@ -1398,10 +1398,10 @@ discard block |
||
1398 | 1398 | 'lesson_page_lesson-order', |
1399 | 1399 | ); |
1400 | 1400 | |
1401 | - if( in_array($screen->id , $limit_screens ) ) { |
|
1401 | + if (in_array($screen->id, $limit_screens)) { |
|
1402 | 1402 | |
1403 | 1403 | // set the query author to the current user to only show those those posts |
1404 | - $wp_query->set( 'author', $current_user->ID ); |
|
1404 | + $wp_query->set('author', $current_user->ID); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | return $wp_query; |
@@ -1421,7 +1421,7 @@ discard block |
||
1421 | 1421 | * @return void |
1422 | 1422 | */ |
1423 | 1423 | |
1424 | - public function teacher_login_redirect( $user_login, $user ) { |
|
1424 | + public function teacher_login_redirect($user_login, $user) { |
|
1425 | 1425 | |
1426 | 1426 | if (user_can($user, 'edit_courses')) { |
1427 | 1427 | |
@@ -1471,9 +1471,9 @@ discard block |
||
1471 | 1471 | * @param bool $restrict default true |
1472 | 1472 | */ |
1473 | 1473 | |
1474 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
1474 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
1475 | 1475 | |
1476 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
1476 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
1477 | 1477 | |
1478 | 1478 | remove_menu_page('edit.php'); |
1479 | 1479 | |
@@ -1503,11 +1503,11 @@ discard block |
||
1503 | 1503 | * @return WP_Comment_Query $clauses |
1504 | 1504 | */ |
1505 | 1505 | |
1506 | - public function restrict_comment_moderation ( $clauses ) { |
|
1506 | + public function restrict_comment_moderation($clauses) { |
|
1507 | 1507 | |
1508 | 1508 | global $pagenow; |
1509 | 1509 | |
1510 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
1510 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
1511 | 1511 | |
1512 | 1512 | $clauses->query_vars['post_author'] = get_current_user_id(); |
1513 | 1513 | |
@@ -1524,15 +1524,15 @@ discard block |
||
1524 | 1524 | * |
1525 | 1525 | * @return bool |
1526 | 1526 | */ |
1527 | - public static function is_a_teacher( $user_id ){ |
|
1527 | + public static function is_a_teacher($user_id) { |
|
1528 | 1528 | |
1529 | 1529 | $user = get_user_by('id', $user_id); |
1530 | 1530 | |
1531 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
1531 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
1532 | 1532 | |
1533 | 1533 | return true; |
1534 | 1534 | |
1535 | - }else{ |
|
1535 | + } else { |
|
1536 | 1536 | |
1537 | 1537 | return false; |
1538 | 1538 | |
@@ -1545,14 +1545,14 @@ discard block |
||
1545 | 1545 | * |
1546 | 1546 | * @since 1.9.0 |
1547 | 1547 | */ |
1548 | - public static function archive_title(){ |
|
1548 | + public static function archive_title() { |
|
1549 | 1549 | |
1550 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
1550 | + $author = get_user_by('id', get_query_var('author')); |
|
1551 | 1551 | $author_name = $author->display_name; |
1552 | 1552 | ?> |
1553 | 1553 | <h2 class="teacher-archive-title"> |
1554 | 1554 | |
1555 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
1555 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
1556 | 1556 | |
1557 | 1557 | </h2> |
1558 | 1558 | <?php |
@@ -1564,9 +1564,9 @@ discard block |
||
1564 | 1564 | * |
1565 | 1565 | * @since 1.9.0 |
1566 | 1566 | */ |
1567 | - public static function remove_course_meta_on_teacher_archive(){ |
|
1567 | + public static function remove_course_meta_on_teacher_archive() { |
|
1568 | 1568 | |
1569 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1569 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
1570 | 1570 | |
1571 | 1571 | } |
1572 | 1572 |
@@ -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 |