| @@ -40,6 +40,7 @@ discard block | ||
| 40 | 40 | * Constructor for the email class hooks in all emails that can be sent. | 
| 41 | 41 | * | 
| 42 | 42 | * @access public | 
| 43 | + * @param string $file | |
| 43 | 44 | * @return void | 
| 44 | 45 | */ | 
| 45 | 46 |  	function __construct( $file ) { | 
| @@ -140,7 +141,7 @@ discard block | ||
| 140 | 141 | * Wraps a message in the sensei mail template. | 
| 141 | 142 | * | 
| 142 | 143 | * @access public | 
| 143 | - * @param mixed $content | |
| 144 | + * @param null|string $content | |
| 144 | 145 | * @return string | 
| 145 | 146 | */ | 
| 146 | 147 |  	function wrap_message( $content ) { | 
| @@ -198,6 +199,9 @@ discard block | ||
| 198 | 199 | remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | 
| 199 | 200 | } | 
| 200 | 201 | |
| 202 | + /** | |
| 203 | + * @param string $email_template | |
| 204 | + */ | |
| 201 | 205 |  	function get_content( $email_template ) { | 
| 202 | 206 | |
| 203 | 207 | $message = $this->load_template( $email_template ); | 
| @@ -42,22 +42,22 @@ discard block | ||
| 42 | 42 | * @access public | 
| 43 | 43 | * @return void | 
| 44 | 44 | */ | 
| 45 | -	function __construct( $file ) { | |
| 45 | +	function __construct($file) { | |
| 46 | 46 | |
| 47 | 47 | $this->init(); | 
| 48 | 48 | |
| 49 | 49 | // Hooks for sending emails during Sensei events | 
| 50 | - add_action( 'sensei_user_quiz_grade', array( $this, 'learner_graded_quiz' ), 10, 4 ); | |
| 51 | - add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); | |
| 52 | - add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); | |
| 53 | - add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); | |
| 54 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); | |
| 55 | - add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); | |
| 56 | - add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); | |
| 57 | - add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); | |
| 50 | +		add_action('sensei_user_quiz_grade', array($this, 'learner_graded_quiz'), 10, 4); | |
| 51 | +		add_action('sensei_course_status_updated', array($this, 'learner_completed_course'), 10, 4); | |
| 52 | +		add_action('sensei_course_status_updated', array($this, 'teacher_completed_course'), 10, 4); | |
| 53 | +		add_action('sensei_user_course_start', array($this, 'teacher_started_course'), 10, 2); | |
| 54 | +        add_action('sensei_user_lesson_end', array($this, 'teacher_completed_lesson'), 10, 2); | |
| 55 | +		add_action('sensei_user_quiz_submitted', array($this, 'teacher_quiz_submitted'), 10, 5); | |
| 56 | +		add_action('sensei_new_private_message', array($this, 'teacher_new_message'), 10, 1); | |
| 57 | +		add_action('sensei_private_message_reply', array($this, 'new_message_reply'), 10, 2); | |
| 58 | 58 | |
| 59 | 59 | // Let 3rd parties unhook the above via this hook | 
| 60 | - do_action( 'sensei_emails', $this ); | |
| 60 | +		do_action('sensei_emails', $this); | |
| 61 | 61 | } | 
| 62 | 62 | |
| 63 | 63 | /** | 
| @@ -65,15 +65,15 @@ discard block | ||
| 65 | 65 | */ | 
| 66 | 66 |  	function init() { | 
| 67 | 67 | |
| 68 | - $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); | |
| 69 | - $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); | |
| 70 | - $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); | |
| 71 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); | |
| 72 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); | |
| 73 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); | |
| 74 | - $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); | |
| 75 | - $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); | |
| 76 | - $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); | |
| 68 | +		$this->emails['learner-graded-quiz'] = include('emails/class-woothemes-sensei-email-learner-graded-quiz.php'); | |
| 69 | +		$this->emails['learner-completed-course'] = include('emails/class-woothemes-sensei-email-learner-completed-course.php'); | |
| 70 | +		$this->emails['teacher-completed-course'] = include('emails/class-woothemes-sensei-email-teacher-completed-course.php'); | |
| 71 | +        $this->emails['teacher-started-course'] = include('emails/class-woothemes-sensei-email-teacher-started-course.php'); | |
| 72 | +        $this->emails['teacher-completed-lesson'] = include('emails/class-woothemes-sensei-email-teacher-completed-lesson.php'); | |
| 73 | +        $this->emails['teacher-quiz-submitted'] = include('emails/class-woothemes-sensei-email-teacher-quiz-submitted.php'); | |
| 74 | +		$this->emails['teacher-new-message'] = include('emails/class-woothemes-sensei-email-teacher-new-message.php'); | |
| 75 | +		$this->emails['new-message-reply'] = include('emails/class-woothemes-sensei-email-new-message-reply.php'); | |
| 76 | +		$this->emails = apply_filters('sensei_email_classes', $this->emails); | |
| 77 | 77 | } | 
| 78 | 78 | |
| 79 | 79 | /** | 
| @@ -95,15 +95,15 @@ discard block | ||
| 95 | 95 |  	function get_from_name() { | 
| 96 | 96 | |
| 97 | 97 | |
| 98 | -		if ( ! $this->_from_name ) { | |
| 99 | -			if( isset( Sensei()->settings->settings['email_from_name'] ) && '' != Sensei()->settings->settings['email_from_name'] ) { | |
| 98 | +		if ( ! $this->_from_name) { | |
| 99 | +			if (isset(Sensei()->settings->settings['email_from_name']) && '' != Sensei()->settings->settings['email_from_name']) { | |
| 100 | 100 | $this->_from_name = Sensei()->settings->settings['email_from_name']; | 
| 101 | 101 |  			} else { | 
| 102 | - $this->_from_name = get_bloginfo( 'name' ); | |
| 102 | +				$this->_from_name = get_bloginfo('name'); | |
| 103 | 103 | } | 
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | - return wp_specialchars_decode( $this->_from_name ); | |
| 106 | + return wp_specialchars_decode($this->_from_name); | |
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | 109 | /** | 
| @@ -115,11 +115,11 @@ discard block | ||
| 115 | 115 |  	function get_from_address() { | 
| 116 | 116 | |
| 117 | 117 | |
| 118 | -		if ( ! $this->_from_address ) { | |
| 119 | -			if( isset( Sensei()->settings->settings['email_from_address'] ) && '' != Sensei()->settings->settings['email_from_address'] ) { | |
| 118 | +		if ( ! $this->_from_address) { | |
| 119 | +			if (isset(Sensei()->settings->settings['email_from_address']) && '' != Sensei()->settings->settings['email_from_address']) { | |
| 120 | 120 | $this->_from_address = Sensei()->settings->settings['email_from_address']; | 
| 121 | 121 |  			} else { | 
| 122 | - $this->_from_address = get_bloginfo( 'admin_email' ); | |
| 122 | +				$this->_from_address = get_bloginfo('admin_email'); | |
| 123 | 123 | } | 
| 124 | 124 | } | 
| 125 | 125 | |
| @@ -143,13 +143,13 @@ discard block | ||
| 143 | 143 | * @param mixed $content | 
| 144 | 144 | * @return string | 
| 145 | 145 | */ | 
| 146 | -	function wrap_message( $content ) { | |
| 146 | +	function wrap_message($content) { | |
| 147 | 147 | |
| 148 | 148 | $html = ''; | 
| 149 | 149 | |
| 150 | - $html .= $this->load_template( 'header' ); | |
| 151 | - $html .= wpautop( wptexturize( $content ) ); | |
| 152 | - $html .= $this->load_template( 'footer' ); | |
| 150 | +		$html .= $this->load_template('header'); | |
| 151 | + $html .= wpautop(wptexturize($content)); | |
| 152 | +		$html .= $this->load_template('footer'); | |
| 153 | 153 | |
| 154 | 154 | return $html; | 
| 155 | 155 | } | 
| @@ -166,16 +166,16 @@ discard block | ||
| 166 | 166 | * @param string $content_type (default: "text/html") | 
| 167 | 167 | * @return void | 
| 168 | 168 | */ | 
| 169 | -	function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html' ) { | |
| 169 | +	function send($to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html') { | |
| 170 | 170 | global $email_template; | 
| 171 | 171 | |
| 172 | 172 | // Set content type | 
| 173 | 173 | $this->_content_type = $content_type; | 
| 174 | 174 | |
| 175 | 175 | // Filters for the email | 
| 176 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | |
| 177 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | |
| 178 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | |
| 176 | +		add_filter('wp_mail_from', array($this, 'get_from_address')); | |
| 177 | +		add_filter('wp_mail_from_name', array($this, 'get_from_name')); | |
| 178 | +		add_filter('wp_mail_content_type', array($this, 'get_content_type')); | |
| 179 | 179 | |
| 180 | 180 | // Send | 
| 181 | 181 | $send_email = true; | 
| @@ -186,40 +186,40 @@ discard block | ||
| 186 | 186 | * @since 1.8.0 | 
| 187 | 187 | * @param bool $send_email default true | 
| 188 | 188 | */ | 
| 189 | -        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){ | |
| 189 | +        if (apply_filters('sensei_send_emails', $send_email, $to, $subject, $message)) { | |
| 190 | 190 | |
| 191 | - wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 191 | + wp_mail($to, $subject, $message, $headers, $attachments); | |
| 192 | 192 | |
| 193 | 193 | } | 
| 194 | 194 | |
| 195 | 195 | // Unhook filters | 
| 196 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | |
| 197 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | |
| 198 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | |
| 196 | +		remove_filter('wp_mail_from', array($this, 'get_from_address')); | |
| 197 | +		remove_filter('wp_mail_from_name', array($this, 'get_from_name')); | |
| 198 | +		remove_filter('wp_mail_content_type', array($this, 'get_content_type')); | |
| 199 | 199 | } | 
| 200 | 200 | |
| 201 | -	function get_content( $email_template ) { | |
| 201 | +	function get_content($email_template) { | |
| 202 | 202 | |
| 203 | - $message = $this->load_template( $email_template ); | |
| 203 | + $message = $this->load_template($email_template); | |
| 204 | 204 | |
| 205 | - $html = $this->wrap_message( $message ); | |
| 205 | + $html = $this->wrap_message($message); | |
| 206 | 206 | |
| 207 | - return apply_filters( 'sensei_email', $html, $email_template ); | |
| 207 | +		return apply_filters('sensei_email', $html, $email_template); | |
| 208 | 208 | } | 
| 209 | 209 | |
| 210 | -	function load_template( $template = '' ) { | |
| 210 | +	function load_template($template = '') { | |
| 211 | 211 | global $email_template; | 
| 212 | 212 | |
| 213 | - if( ! $template ) return; | |
| 213 | + if ( ! $template) return; | |
| 214 | 214 | |
| 215 | - $email_template = $template . '.php'; | |
| 216 | - $template = Sensei_Templates::template_loader( '' ); | |
| 215 | + $email_template = $template.'.php'; | |
| 216 | +		$template = Sensei_Templates::template_loader(''); | |
| 217 | 217 | |
| 218 | 218 | ob_start(); | 
| 219 | 219 | |
| 220 | - do_action( 'sensei_before_email_template', $email_template ); | |
| 221 | - include( $template ); | |
| 222 | - do_action( 'sensei_after_email_template', $email_template ); | |
| 220 | +		do_action('sensei_before_email_template', $email_template); | |
| 221 | + include($template); | |
| 222 | +		do_action('sensei_after_email_template', $email_template); | |
| 223 | 223 | |
| 224 | 224 | return ob_get_clean(); | 
| 225 | 225 | } | 
| @@ -230,22 +230,22 @@ discard block | ||
| 230 | 230 | * @access public | 
| 231 | 231 | * @return void | 
| 232 | 232 | */ | 
| 233 | -	function learner_graded_quiz( $user_id, $quiz_id, $grade, $passmark ) { | |
| 233 | +	function learner_graded_quiz($user_id, $quiz_id, $grade, $passmark) { | |
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | $send = false; | 
| 237 | 237 | |
| 238 | -		if( isset( Sensei()->settings->settings['email_learners'] ) ) { | |
| 239 | -			if( in_array( 'learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'] ) ) { | |
| 238 | +		if (isset(Sensei()->settings->settings['email_learners'])) { | |
| 239 | +			if (in_array('learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'])) { | |
| 240 | 240 | $send = true; | 
| 241 | 241 | } | 
| 242 | 242 |  		} else { | 
| 243 | 243 | $send = true; | 
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | -		if( $send ) { | |
| 246 | +		if ($send) { | |
| 247 | 247 | $email = $this->emails['learner-graded-quiz']; | 
| 248 | - $email->trigger( $user_id, $quiz_id, $grade, $passmark ); | |
| 248 | + $email->trigger($user_id, $quiz_id, $grade, $passmark); | |
| 249 | 249 | } | 
| 250 | 250 | } | 
| 251 | 251 | |
| @@ -255,26 +255,26 @@ discard block | ||
| 255 | 255 | * @access public | 
| 256 | 256 | * @return void | 
| 257 | 257 | */ | 
| 258 | -	function learner_completed_course( $status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0 ) { | |
| 258 | +	function learner_completed_course($status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0) { | |
| 259 | 259 | |
| 260 | 260 | |
| 261 | -		if( 'complete' != $status ) { | |
| 261 | +		if ('complete' != $status) { | |
| 262 | 262 | return; | 
| 263 | 263 | } | 
| 264 | 264 | |
| 265 | 265 | $send = false; | 
| 266 | 266 | |
| 267 | -		if( isset( Sensei()->settings->settings['email_learners'] ) ) { | |
| 268 | -			if( in_array( 'learner-completed-course', (array) Sensei()->settings->settings['email_learners'] ) ) { | |
| 267 | +		if (isset(Sensei()->settings->settings['email_learners'])) { | |
| 268 | +			if (in_array('learner-completed-course', (array) Sensei()->settings->settings['email_learners'])) { | |
| 269 | 269 | $send = true; | 
| 270 | 270 | } | 
| 271 | 271 |  		} else { | 
| 272 | 272 | $send = true; | 
| 273 | 273 | } | 
| 274 | 274 | |
| 275 | -		if( $send ) { | |
| 275 | +		if ($send) { | |
| 276 | 276 | $email = $this->emails['learner-completed-course']; | 
| 277 | - $email->trigger( $user_id, $course_id ); | |
| 277 | + $email->trigger($user_id, $course_id); | |
| 278 | 278 | } | 
| 279 | 279 | } | 
| 280 | 280 | |
| @@ -284,26 +284,26 @@ discard block | ||
| 284 | 284 | * @access public | 
| 285 | 285 | * @return void | 
| 286 | 286 | */ | 
| 287 | -	function teacher_completed_course( $status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0 ) { | |
| 287 | +	function teacher_completed_course($status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0) { | |
| 288 | 288 | |
| 289 | 289 | |
| 290 | -		if( 'complete' != $status ) { | |
| 290 | +		if ('complete' != $status) { | |
| 291 | 291 | return; | 
| 292 | 292 | } | 
| 293 | 293 | |
| 294 | 294 | $send = false; | 
| 295 | 295 | |
| 296 | -		if( isset( Sensei()->settings->settings['email_teachers'] ) ) { | |
| 297 | -			if( in_array( 'teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'] ) ) { | |
| 296 | +		if (isset(Sensei()->settings->settings['email_teachers'])) { | |
| 297 | +			if (in_array('teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'])) { | |
| 298 | 298 | $send = true; | 
| 299 | 299 | } | 
| 300 | 300 |  		} else { | 
| 301 | 301 | $send = true; | 
| 302 | 302 | } | 
| 303 | 303 | |
| 304 | -		if( $send ) { | |
| 304 | +		if ($send) { | |
| 305 | 305 | $email = $this->emails['teacher-completed-course']; | 
| 306 | - $email->trigger( $learner_id, $course_id ); | |
| 306 | + $email->trigger($learner_id, $course_id); | |
| 307 | 307 | } | 
| 308 | 308 | } | 
| 309 | 309 | |
| @@ -313,22 +313,22 @@ discard block | ||
| 313 | 313 | * @access public | 
| 314 | 314 | * @return void | 
| 315 | 315 | */ | 
| 316 | -	function teacher_started_course( $learner_id = 0, $course_id = 0 ) { | |
| 316 | +	function teacher_started_course($learner_id = 0, $course_id = 0) { | |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | $send = false; | 
| 320 | 320 | |
| 321 | -		if( isset( Sensei()->settings->settings['email_teachers'] ) ) { | |
| 322 | -			if( in_array( 'teacher-started-course', (array) Sensei()->settings->settings['email_teachers'] ) ) { | |
| 321 | +		if (isset(Sensei()->settings->settings['email_teachers'])) { | |
| 322 | +			if (in_array('teacher-started-course', (array) Sensei()->settings->settings['email_teachers'])) { | |
| 323 | 323 | $send = true; | 
| 324 | 324 | } | 
| 325 | 325 |  		} else { | 
| 326 | 326 | $send = true; | 
| 327 | 327 | } | 
| 328 | 328 | |
| 329 | -		if( $send ) { | |
| 329 | +		if ($send) { | |
| 330 | 330 | $email = $this->emails['teacher-started-course']; | 
| 331 | - $email->trigger( $learner_id, $course_id ); | |
| 331 | + $email->trigger($learner_id, $course_id); | |
| 332 | 332 | } | 
| 333 | 333 | } | 
| 334 | 334 | |
| @@ -341,22 +341,22 @@ discard block | ||
| 341 | 341 | * @return void | 
| 342 | 342 | * @since 1.9.0 | 
| 343 | 343 | */ | 
| 344 | -    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { | |
| 344 | +    function teacher_completed_lesson($learner_id = 0, $lesson_id = 0) { | |
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | $send = false; | 
| 348 | 348 | |
| 349 | -        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { | |
| 350 | -            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { | |
| 349 | +        if (isset(Sensei()->settings->settings['email_teachers'])) { | |
| 350 | +            if (in_array('teacher-completed-lesson', (array) Sensei()->settings->settings['email_teachers'])) { | |
| 351 | 351 | $send = true; | 
| 352 | 352 | } | 
| 353 | 353 |          } else { | 
| 354 | 354 | $send = true; | 
| 355 | 355 | } | 
| 356 | 356 | |
| 357 | -        if( $send ) { | |
| 357 | +        if ($send) { | |
| 358 | 358 | $email = $this->emails['teacher-completed-lesson']; | 
| 359 | - $email->trigger( $learner_id, $lesson_id ); | |
| 359 | + $email->trigger($learner_id, $lesson_id); | |
| 360 | 360 | } | 
| 361 | 361 | } | 
| 362 | 362 | |
| @@ -366,25 +366,25 @@ discard block | ||
| 366 | 366 | * @access public | 
| 367 | 367 | * @return void | 
| 368 | 368 | */ | 
| 369 | -	function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) { | |
| 369 | +	function teacher_quiz_submitted($learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual') { | |
| 370 | 370 | |
| 371 | 371 | |
| 372 | 372 | |
| 373 | 373 | $send = false; | 
| 374 | 374 | |
| 375 | 375 | // Only trigger if the quiz was marked as manual grading, or auto grading didn't complete | 
| 376 | -		if( 'manual' == $quiz_grade_type || is_wp_error( $grade ) ) { | |
| 377 | -			if( isset( Sensei()->settings->settings['email_teachers'] ) ) { | |
| 378 | -				if( in_array( 'teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'] ) ) { | |
| 376 | +		if ('manual' == $quiz_grade_type || is_wp_error($grade)) { | |
| 377 | +			if (isset(Sensei()->settings->settings['email_teachers'])) { | |
| 378 | +				if (in_array('teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'])) { | |
| 379 | 379 | $send = true; | 
| 380 | 380 | } | 
| 381 | 381 |  			} else { | 
| 382 | 382 | $send = true; | 
| 383 | 383 | } | 
| 384 | 384 | |
| 385 | -			if( $send ) { | |
| 385 | +			if ($send) { | |
| 386 | 386 | $email = $this->emails['teacher-quiz-submitted']; | 
| 387 | - $email->trigger( $learner_id, $quiz_id ); | |
| 387 | + $email->trigger($learner_id, $quiz_id); | |
| 388 | 388 | } | 
| 389 | 389 | |
| 390 | 390 | } | 
| @@ -396,22 +396,22 @@ discard block | ||
| 396 | 396 | * @access public | 
| 397 | 397 | * @return void | 
| 398 | 398 | */ | 
| 399 | -	function teacher_new_message( $message_id = 0 ) { | |
| 399 | +	function teacher_new_message($message_id = 0) { | |
| 400 | 400 | |
| 401 | 401 | |
| 402 | 402 | $send = false; | 
| 403 | 403 | |
| 404 | -		if( isset( Sensei()->settings->settings['email_teachers'] ) ) { | |
| 405 | -			if( in_array( 'teacher-new-message', (array) Sensei()->settings->settings['email_teachers'] ) ) { | |
| 404 | +		if (isset(Sensei()->settings->settings['email_teachers'])) { | |
| 405 | +			if (in_array('teacher-new-message', (array) Sensei()->settings->settings['email_teachers'])) { | |
| 406 | 406 | $send = true; | 
| 407 | 407 | } | 
| 408 | 408 |  		} else { | 
| 409 | 409 | $send = true; | 
| 410 | 410 | } | 
| 411 | 411 | |
| 412 | -		if( $send ) { | |
| 412 | +		if ($send) { | |
| 413 | 413 | $email = $this->emails['teacher-new-message']; | 
| 414 | - $email->trigger( $message_id ); | |
| 414 | + $email->trigger($message_id); | |
| 415 | 415 | } | 
| 416 | 416 | } | 
| 417 | 417 | |
| @@ -421,22 +421,22 @@ discard block | ||
| 421 | 421 | * @access public | 
| 422 | 422 | * @return void | 
| 423 | 423 | */ | 
| 424 | -	function new_message_reply( $comment, $message ) { | |
| 424 | +	function new_message_reply($comment, $message) { | |
| 425 | 425 | |
| 426 | 426 | |
| 427 | 427 | $send = false; | 
| 428 | 428 | |
| 429 | -		if( isset( Sensei()->settings->settings['email_global'] ) ) { | |
| 430 | -			if( in_array( 'new-message-reply', (array) Sensei()->settings->settings['email_global'] ) ) { | |
| 429 | +		if (isset(Sensei()->settings->settings['email_global'])) { | |
| 430 | +			if (in_array('new-message-reply', (array) Sensei()->settings->settings['email_global'])) { | |
| 431 | 431 | $send = true; | 
| 432 | 432 | } | 
| 433 | 433 |  		} else { | 
| 434 | 434 | $send = true; | 
| 435 | 435 | } | 
| 436 | 436 | |
| 437 | -		if( $send ) { | |
| 437 | +		if ($send) { | |
| 438 | 438 | $email = $this->emails['new-message-reply']; | 
| 439 | - $email->trigger( $comment, $message ); | |
| 439 | + $email->trigger($comment, $message); | |
| 440 | 440 | } | 
| 441 | 441 | } | 
| 442 | 442 | |
| @@ -447,4 +447,4 @@ discard block | ||
| 447 | 447 | * for backward compatibility | 
| 448 | 448 | * @since 1.9.0 | 
| 449 | 449 | */ | 
| 450 | -class WooThemes_Sensei_Emails extends Sensei_Emails{} | |
| 450 | +class WooThemes_Sensei_Emails extends Sensei_Emails {} | |
| @@ -210,7 +210,9 @@ | ||
| 210 | 210 |  	function load_template( $template = '' ) { | 
| 211 | 211 | global $email_template; | 
| 212 | 212 | |
| 213 | - if( ! $template ) return; | |
| 213 | +		if( ! $template ) { | |
| 214 | + return; | |
| 215 | + } | |
| 214 | 216 | |
| 215 | 217 | $email_template = $template . '.php'; | 
| 216 | 218 | $template = Sensei_Templates::template_loader( '' ); | 
| @@ -45,7 +45,7 @@ discard block | ||
| 45 | 45 | add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); | 
| 46 | 46 | add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); | 
| 47 | 47 | add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); | 
| 48 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); | |
| 48 | + add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); | |
| 49 | 49 | add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); | 
| 50 | 50 | add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); | 
| 51 | 51 | add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); | 
| @@ -62,9 +62,9 @@ discard block | ||
| 62 | 62 | $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); | 
| 63 | 63 | $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); | 
| 64 | 64 | $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); | 
| 65 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); | |
| 66 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); | |
| 67 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); | |
| 65 | + $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); | |
| 66 | + $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); | |
| 67 | + $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); | |
| 68 | 68 | $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); | 
| 69 | 69 | $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); | 
| 70 | 70 | $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); | 
| @@ -171,20 +171,20 @@ discard block | ||
| 171 | 171 | add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | 
| 172 | 172 | add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | 
| 173 | 173 | |
| 174 | - // Send | |
| 175 | - $send_email = true; | |
| 174 | + // Send | |
| 175 | + $send_email = true; | |
| 176 | 176 | |
| 177 | - /** | |
| 178 | - * Filter Sensei's ability to send out emails. | |
| 179 | - * | |
| 180 | - * @since 1.8.0 | |
| 181 | - * @param bool $send_email default true | |
| 182 | - */ | |
| 183 | -        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){ | |
| 177 | + /** | |
| 178 | + * Filter Sensei's ability to send out emails. | |
| 179 | + * | |
| 180 | + * @since 1.8.0 | |
| 181 | + * @param bool $send_email default true | |
| 182 | + */ | |
| 183 | +		if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){ | |
| 184 | 184 | |
| 185 | - wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 185 | + wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 186 | 186 | |
| 187 | - } | |
| 187 | + } | |
| 188 | 188 | |
| 189 | 189 | // Unhook filters | 
| 190 | 190 | remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | 
| @@ -326,44 +326,44 @@ discard block | ||
| 326 | 326 | } | 
| 327 | 327 | } | 
| 328 | 328 | |
| 329 | - /** | |
| 330 | - * teacher_completed_lesson() | |
| 331 | - * | |
| 332 | - * Send email to teacher on student completing lesson | |
| 333 | - * | |
| 334 | - * @access public | |
| 335 | - * @return void | |
| 336 | - * @since 1.9.0 | |
| 337 | - */ | |
| 338 | -    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { | |
| 339 | - | |
| 340 | - | |
| 341 | - $send = false; | |
| 342 | - | |
| 343 | -        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { | |
| 344 | -            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { | |
| 345 | - $send = true; | |
| 346 | - } | |
| 347 | -        } else { | |
| 348 | - $send = true; | |
| 349 | - } | |
| 350 | - | |
| 351 | -        if( $send ) { | |
| 352 | - $email = $this->emails['teacher-completed-lesson']; | |
| 353 | - $email->trigger( $learner_id, $lesson_id ); | |
| 354 | - } | |
| 355 | - } | |
| 329 | + /** | |
| 330 | + * teacher_completed_lesson() | |
| 331 | + * | |
| 332 | + * Send email to teacher on student completing lesson | |
| 333 | + * | |
| 334 | + * @access public | |
| 335 | + * @return void | |
| 336 | + * @since 1.9.0 | |
| 337 | + */ | |
| 338 | +	function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { | |
| 339 | + | |
| 340 | + | |
| 341 | + $send = false; | |
| 342 | + | |
| 343 | +		if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { | |
| 344 | +			if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { | |
| 345 | + $send = true; | |
| 346 | + } | |
| 347 | +		} else { | |
| 348 | + $send = true; | |
| 349 | + } | |
| 350 | + | |
| 351 | +		if( $send ) { | |
| 352 | + $email = $this->emails['teacher-completed-lesson']; | |
| 353 | + $email->trigger( $learner_id, $lesson_id ); | |
| 354 | + } | |
| 355 | + } | |
| 356 | 356 | |
| 357 | 357 | /** | 
| 358 | 358 | * Send email to teacher on quiz submission | 
| 359 | 359 | * | 
| 360 | 360 | * | 
| 361 | - * @param int $learner_id | |
| 362 | - * @param int $quiz_id | |
| 363 | - * @param int $grade | |
| 364 | - * @param int $passmark | |
| 365 | - * @param string $quiz_grade_type | |
| 366 | - */ | |
| 361 | + * @param int $learner_id | |
| 362 | + * @param int $quiz_id | |
| 363 | + * @param int $grade | |
| 364 | + * @param int $passmark | |
| 365 | + * @param string $quiz_grade_type | |
| 366 | + */ | |
| 367 | 367 |  	function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) { | 
| 368 | 368 | |
| 369 | 369 | $send = false; | 
| @@ -22,7 +22,7 @@ discard block | ||
| 22 | 22 | * Constructor | 
| 23 | 23 | * @since 1.3.0 | 
| 24 | 24 | * | 
| 25 | - * @param $file | |
| 25 | + * @param string $file | |
| 26 | 26 | */ | 
| 27 | 27 |  	public function __construct ( $file ) { | 
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); | 
| @@ -330,6 +330,7 @@ discard block | ||
| 330 | 330 | /** | 
| 331 | 331 | * Return array of valid statuses for either Course or Lesson | 
| 332 | 332 | * @since 1.7.0 | 
| 333 | + * @param string $type | |
| 333 | 334 | * @return array | 
| 334 | 335 | */ | 
| 335 | 336 |  	public function get_stati( $type ) { | 
| @@ -529,7 +530,7 @@ discard block | ||
| 529 | 530 | * the grades as the Grader selected theme and saves the total grade and | 
| 530 | 531 | * individual question grades. | 
| 531 | 532 | * | 
| 532 | - * @return bool | |
| 533 | + * @return false|null | |
| 533 | 534 | */ | 
| 534 | 535 |      public function admin_process_grading_submission() { | 
| 535 | 536 | |
| @@ -906,8 +907,8 @@ discard block | ||
| 906 | 907 | * Grading logic specifically for the gap fill questions | 
| 907 | 908 | * | 
| 908 | 909 | * @since 1.9.0 | 
| 909 | - * @param $question_id | |
| 910 | - * @param $user_answer | |
| 910 | + * @param integer $question_id | |
| 911 | + * @param string $user_answer | |
| 911 | 912 | * | 
| 912 | 913 | * @return bool | int false or the grade given to the user answer | 
| 913 | 914 | */ | 
| @@ -1,5 +1,8 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Grading Class | 
| @@ -130,8 +133,7 @@ discard block | ||
| 130 | 133 | $object_name = 'WooThemes_Sensei_Grading_' . $name; | 
| 131 | 134 |  		if ( is_null($optional_data) ) { | 
| 132 | 135 | $sensei_grading_object = new $object_name( $data ); | 
| 133 | - } | |
| 134 | -		else { | |
| 136 | +		} else { | |
| 135 | 137 | $sensei_grading_object = new $object_name( $data, $optional_data ); | 
| 136 | 138 | } // End If Statement | 
| 137 | 139 |  		if ( 'Main' == $name ) { | 
| @@ -150,8 +152,7 @@ discard block | ||
| 150 | 152 | |
| 151 | 153 |  		if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { | 
| 152 | 154 | $this->grading_user_quiz_view(); | 
| 153 | - } | |
| 154 | -		else { | |
| 155 | +		} else { | |
| 155 | 156 | $this->grading_default_view(); | 
| 156 | 157 | } // End If Statement | 
| 157 | 158 | } // End grading_page() | 
| @@ -273,8 +274,7 @@ discard block | ||
| 273 | 274 |  			if ( version_compare($wp_version, '4.1', '>=') ) { | 
| 274 | 275 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); | 
| 275 | 276 | $title .= sprintf( '  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); | 
| 276 | - } | |
| 277 | -			else { | |
| 277 | +			} else { | |
| 278 | 278 | $title .= sprintf( '  <span class="course-title">>  %s</span>', get_the_title( $course_id ) ); | 
| 279 | 279 | } | 
| 280 | 280 | } | 
| @@ -309,8 +309,7 @@ discard block | ||
| 309 | 309 |  			if ( version_compare($wp_version, '4.1', '>=') ) { | 
| 310 | 310 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); | 
| 311 | 311 | $title .= sprintf( '  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); | 
| 312 | - } | |
| 313 | -			else { | |
| 312 | +			} else { | |
| 314 | 313 | $title .= sprintf( '  <span class="course-title">>  %s</span>', get_the_title( $course_id ) ); | 
| 315 | 314 | } | 
| 316 | 315 | $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); | 
| @@ -379,8 +378,7 @@ discard block | ||
| 379 | 378 | |
| 380 | 379 |  		if ( 'course' == $args['type'] ) { | 
| 381 | 380 | $type = 'sensei_course_status'; | 
| 382 | - } | |
| 383 | -		else { | |
| 381 | +		} else { | |
| 384 | 382 | $type = 'sensei_lesson_status'; | 
| 385 | 383 | } | 
| 386 | 384 | $cache_key = 'sensei-' . $args['type'] . '-statuses'; | 
| @@ -390,15 +388,13 @@ discard block | ||
| 390 | 388 | // Restrict to specific posts | 
| 391 | 389 |  		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { | 
| 392 | 390 |  			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; | 
| 393 | - } | |
| 394 | -		elseif ( !empty( $args['post_id'] ) ) { | |
| 391 | +		} elseif ( !empty( $args['post_id'] ) ) { | |
| 395 | 392 | $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); | 
| 396 | 393 | } | 
| 397 | 394 | // Restrict to specific users | 
| 398 | 395 |  		if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { | 
| 399 | 396 |  			$query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; | 
| 400 | - } | |
| 401 | -		elseif ( !empty( $args['user_id'] ) ) { | |
| 397 | +		} elseif ( !empty( $args['user_id'] ) ) { | |
| 402 | 398 | $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); | 
| 403 | 399 | } | 
| 404 | 400 | $query .= ' GROUP BY comment_approved'; | 
| @@ -601,8 +597,7 @@ discard block | ||
| 601 | 597 | // set the users total quiz grade | 
| 602 | 598 |  			if ( 0 < intval( $quiz_grade_total ) ) { | 
| 603 | 599 | $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | 
| 604 | - } | |
| 605 | -			else { | |
| 600 | +			} else { | |
| 606 | 601 | $grade = 0; | 
| 607 | 602 | } | 
| 608 | 603 | WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | 
| @@ -615,8 +610,7 @@ discard block | ||
| 615 | 610 | // Student has reached the pass mark and lesson is complete | 
| 616 | 611 |                  if ( $quiz_passmark <= $grade ) { | 
| 617 | 612 | $lesson_status = 'passed'; | 
| 618 | - } | |
| 619 | -                else { | |
| 613 | +                } else { | |
| 620 | 614 | $lesson_status = 'failed'; | 
| 621 | 615 | } // End If Statement | 
| 622 | 616 | } | 
| @@ -761,8 +755,7 @@ discard block | ||
| 761 | 755 | // Question has a zero grade, so skip grading | 
| 762 | 756 |  			if ( 0 == $achievable_grade ) { | 
| 763 | 757 | $all_question_grades[ $question_id ] = $achievable_grade; | 
| 764 | - } | |
| 765 | -            elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 758 | +			} elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 766 | 759 | // Get user question grade | 
| 767 | 760 | $question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | 
| 768 | 761 | $all_question_grades[ $question_id ] = $question_grade; | 
| @@ -784,8 +777,7 @@ discard block | ||
| 784 | 777 | // Check for zero total from grades | 
| 785 | 778 |  			if ( 0 < $quiz_total ) { | 
| 786 | 779 | $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | 
| 787 | - } | |
| 788 | -			else { | |
| 780 | +			} else { | |
| 789 | 781 | $grade = 0; | 
| 790 | 782 | } | 
| 791 | 783 | WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | 
| @@ -945,19 +937,19 @@ discard block | ||
| 945 | 937 | |
| 946 | 938 | return Sensei()->question->get_question_grade($question_id); | 
| 947 | 939 | |
| 948 | -                }else{ | |
| 940 | +                } else{ | |
| 949 | 941 | |
| 950 | 942 | return false; | 
| 951 | 943 | |
| 952 | 944 | } | 
| 953 | 945 | |
| 954 | -            }else{ | |
| 946 | +            } else{ | |
| 955 | 947 | |
| 956 | 948 | return false; | 
| 957 | 949 | |
| 958 | 950 | } | 
| 959 | 951 | |
| 960 | -        }else{ | |
| 952 | +        } else{ | |
| 961 | 953 | |
| 962 | 954 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | 
| 963 | 955 |              if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | 
| @@ -970,13 +962,13 @@ discard block | ||
| 970 | 962 | |
| 971 | 963 | return Sensei()->question->get_question_grade( $question_id ); | 
| 972 | 964 | |
| 973 | -                }else{ | |
| 965 | +                } else{ | |
| 974 | 966 | |
| 975 | 967 | return false; | 
| 976 | 968 | |
| 977 | 969 | } | 
| 978 | 970 | |
| 979 | -            }else{ | |
| 971 | +            } else{ | |
| 980 | 972 | |
| 981 | 973 | return false; | 
| 982 | 974 | |
| @@ -20,8 +20,8 @@ discard block | ||
| 20 | 20 | /** | 
| 21 | 21 | * Constructor | 
| 22 | 22 | * @since 1.3.0 | 
| 23 | - * | |
| 24 | - * @param $file | |
| 23 | + * | |
| 24 | + * @param $file | |
| 25 | 25 | */ | 
| 26 | 26 |  	public function __construct ( $file ) { | 
| 27 | 27 | $this->name = __( 'Grading', 'woothemes-sensei' ); | 
| @@ -230,7 +230,7 @@ discard block | ||
| 230 | 230 | /** | 
| 231 | 231 | * Outputs Grading general headers | 
| 232 | 232 | * @since 1.3.0 | 
| 233 | - * @param array $args | |
| 233 | + * @param array $args | |
| 234 | 234 | * @return void | 
| 235 | 235 | */ | 
| 236 | 236 |  	public function grading_headers( $args = array( 'nav' => 'default' ) ) { | 
| @@ -282,7 +282,7 @@ discard block | ||
| 282 | 282 | } | 
| 283 | 283 |  		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { | 
| 284 | 284 | |
| 285 | - $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); | |
| 285 | + $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); | |
| 286 | 286 | $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | 
| 287 | 287 | |
| 288 | 288 | } // End If Statement | 
| @@ -316,7 +316,7 @@ discard block | ||
| 316 | 316 | } | 
| 317 | 317 |  		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { | 
| 318 | 318 | |
| 319 | - $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); | |
| 319 | + $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); | |
| 320 | 320 | $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | 
| 321 | 321 | |
| 322 | 322 | } // End If Statement | 
| @@ -365,15 +365,15 @@ discard block | ||
| 365 | 365 |  	public function count_statuses( $args = array() ) { | 
| 366 | 366 | global $wpdb; | 
| 367 | 367 | |
| 368 | - /** | |
| 369 | - * Filter fires inside Sensei_Grading::count_statuses | |
| 370 | - * | |
| 371 | - * Alter the the post_in array to determine which posts the | |
| 372 | - * comment query should be limited to. | |
| 373 | - * @since 1.8.0 | |
| 374 | - * @param array $args | |
| 375 | - */ | |
| 376 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); | |
| 368 | + /** | |
| 369 | + * Filter fires inside Sensei_Grading::count_statuses | |
| 370 | + * | |
| 371 | + * Alter the the post_in array to determine which posts the | |
| 372 | + * comment query should be limited to. | |
| 373 | + * @since 1.8.0 | |
| 374 | + * @param array $args | |
| 375 | + */ | |
| 376 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); | |
| 377 | 377 | |
| 378 | 378 |  		if ( 'course' == $args['type'] ) { | 
| 379 | 379 | $type = 'sensei_course_status'; | 
| @@ -385,7 +385,7 @@ discard block | ||
| 385 | 385 | |
| 386 | 386 |  		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; | 
| 387 | 387 | |
| 388 | - // Restrict to specific posts | |
| 388 | + // Restrict to specific posts | |
| 389 | 389 |  		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { | 
| 390 | 390 |  			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; | 
| 391 | 391 | } | 
| @@ -520,148 +520,148 @@ discard block | ||
| 520 | 520 | return $html; | 
| 521 | 521 | } // End lessons_drop_down_html() | 
| 522 | 522 | |
| 523 | - /** | |
| 524 | - * The process grading function handles admin grading submissions. | |
| 525 | - * | |
| 526 | - * This function is hooked on to admin_init. It simply accepts | |
| 527 | - * the grades as the Grader selected theme and saves the total grade and | |
| 528 | - * individual question grades. | |
| 529 | - * | |
| 530 | - * @return bool | |
| 531 | - */ | |
| 532 | -    public function admin_process_grading_submission() { | |
| 523 | + /** | |
| 524 | + * The process grading function handles admin grading submissions. | |
| 525 | + * | |
| 526 | + * This function is hooked on to admin_init. It simply accepts | |
| 527 | + * the grades as the Grader selected theme and saves the total grade and | |
| 528 | + * individual question grades. | |
| 529 | + * | |
| 530 | + * @return bool | |
| 531 | + */ | |
| 532 | +	public function admin_process_grading_submission() { | |
| 533 | 533 | |
| 534 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry | |
| 535 | - if( ! isset( $_POST['sensei_manual_grade'] ) | |
| 536 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) | |
| 537 | - || ! isset( $_GET['quiz_id'] ) | |
| 538 | -            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { | |
| 534 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry | |
| 535 | + if( ! isset( $_POST['sensei_manual_grade'] ) | |
| 536 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) | |
| 537 | + || ! isset( $_GET['quiz_id'] ) | |
| 538 | +			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { | |
| 539 | 539 | |
| 540 | - return false; //exit and do not grade | |
| 540 | + return false; //exit and do not grade | |
| 541 | 541 | |
| 542 | - } | |
| 542 | + } | |
| 543 | 543 | |
| 544 | - $quiz_id = $_GET['quiz_id']; | |
| 545 | - $user_id = $_GET['user']; | |
| 544 | + $quiz_id = $_GET['quiz_id']; | |
| 545 | + $user_id = $_GET['user']; | |
| 546 | 546 | |
| 547 | 547 | |
| 548 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); | |
| 549 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 550 | - $quiz_grade = 0; | |
| 551 | - $count = 0; | |
| 552 | - $quiz_grade_total = $_POST['quiz_grade_total']; | |
| 553 | - $all_question_grades = array(); | |
| 554 | - $all_answers_feedback = array(); | |
| 548 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); | |
| 549 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 550 | + $quiz_grade = 0; | |
| 551 | + $count = 0; | |
| 552 | + $quiz_grade_total = $_POST['quiz_grade_total']; | |
| 553 | + $all_question_grades = array(); | |
| 554 | + $all_answers_feedback = array(); | |
| 555 | 555 | |
| 556 | -        foreach( $questions as $question ) { | |
| 556 | +		foreach( $questions as $question ) { | |
| 557 | 557 | |
| 558 | - ++$count; | |
| 559 | - $question_id = $question->ID; | |
| 558 | + ++$count; | |
| 559 | + $question_id = $question->ID; | |
| 560 | 560 | |
| 561 | -            if( isset( $_POST[ 'question_' . $question_id ] ) ) { | |
| 561 | +			if( isset( $_POST[ 'question_' . $question_id ] ) ) { | |
| 562 | 562 | |
| 563 | - $question_grade = 0; | |
| 564 | -                if( $_POST[ 'question_' . $question_id ] == 'right' ) { | |
| 563 | + $question_grade = 0; | |
| 564 | +				if( $_POST[ 'question_' . $question_id ] == 'right' ) { | |
| 565 | 565 | |
| 566 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; | |
| 566 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; | |
| 567 | 567 | |
| 568 | - } | |
| 568 | + } | |
| 569 | 569 | |
| 570 | - // add data to the array that will, after the loop, be stored on the lesson status | |
| 571 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 570 | + // add data to the array that will, after the loop, be stored on the lesson status | |
| 571 | + $all_question_grades[ $question_id ] = $question_grade; | |
| 572 | 572 | |
| 573 | - // tally up the total quiz grade | |
| 574 | - $quiz_grade += $question_grade; | |
| 573 | + // tally up the total quiz grade | |
| 574 | + $quiz_grade += $question_grade; | |
| 575 | 575 | |
| 576 | - } // endif | |
| 576 | + } // endif | |
| 577 | 577 | |
| 578 | - // Question answer feedback / notes | |
| 579 | - $question_feedback = ''; | |
| 580 | -            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ | |
| 578 | + // Question answer feedback / notes | |
| 579 | + $question_feedback = ''; | |
| 580 | +			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ | |
| 581 | 581 | |
| 582 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); | |
| 582 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); | |
| 583 | 583 | |
| 584 | - } | |
| 585 | - $all_answers_feedback[ $question_id ] = $question_feedback; | |
| 584 | + } | |
| 585 | + $all_answers_feedback[ $question_id ] = $question_feedback; | |
| 586 | 586 | |
| 587 | - } // end for each $questions | |
| 587 | + } // end for each $questions | |
| 588 | 588 | |
| 589 | - //store all question grades on the lesson status | |
| 590 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); | |
| 589 | + //store all question grades on the lesson status | |
| 590 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); | |
| 591 | 591 | |
| 592 | - //store the feedback from grading | |
| 593 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); | |
| 592 | + //store the feedback from grading | |
| 593 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); | |
| 594 | 594 | |
| 595 | - // $_POST['all_questions_graded'] is set when all questions have been graded | |
| 596 | - // in the class sensei grading user quiz -> display() | |
| 597 | -        if( $_POST['all_questions_graded'] == 'yes' ) { | |
| 595 | + // $_POST['all_questions_graded'] is set when all questions have been graded | |
| 596 | + // in the class sensei grading user quiz -> display() | |
| 597 | +		if( $_POST['all_questions_graded'] == 'yes' ) { | |
| 598 | 598 | |
| 599 | - // set the users total quiz grade | |
| 599 | + // set the users total quiz grade | |
| 600 | 600 |  			if ( 0 < intval( $quiz_grade_total ) ) { | 
| 601 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | |
| 601 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | |
| 602 | 602 | } | 
| 603 | 603 |  			else { | 
| 604 | 604 | $grade = 0; | 
| 605 | 605 | } | 
| 606 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | |
| 607 | - | |
| 608 | - // Duplicating what Frontend->sensei_complete_quiz() does | |
| 609 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 610 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 611 | - $lesson_metadata = array(); | |
| 612 | -            if ( $pass_required ) { | |
| 613 | - // Student has reached the pass mark and lesson is complete | |
| 614 | -                if ( $quiz_passmark <= $grade ) { | |
| 615 | - $lesson_status = 'passed'; | |
| 616 | - } | |
| 617 | -                else { | |
| 618 | - $lesson_status = 'failed'; | |
| 619 | - } // End If Statement | |
| 620 | - } | |
| 621 | - // Student only has to partake the quiz | |
| 622 | -            else { | |
| 623 | - $lesson_status = 'graded'; | |
| 624 | - } | |
| 625 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above | |
| 606 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | |
| 607 | + | |
| 608 | + // Duplicating what Frontend->sensei_complete_quiz() does | |
| 609 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 610 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 611 | + $lesson_metadata = array(); | |
| 612 | +			if ( $pass_required ) { | |
| 613 | + // Student has reached the pass mark and lesson is complete | |
| 614 | +				if ( $quiz_passmark <= $grade ) { | |
| 615 | + $lesson_status = 'passed'; | |
| 616 | + } | |
| 617 | +				else { | |
| 618 | + $lesson_status = 'failed'; | |
| 619 | + } // End If Statement | |
| 620 | + } | |
| 621 | + // Student only has to partake the quiz | |
| 622 | +			else { | |
| 623 | + $lesson_status = 'graded'; | |
| 624 | + } | |
| 625 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above | |
| 626 | 626 | |
| 627 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); | |
| 627 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); | |
| 628 | 628 | |
| 629 | -            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) { | |
| 629 | +			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) { | |
| 630 | 630 | |
| 631 | - /** | |
| 632 | - * Summary. | |
| 633 | - * | |
| 634 | - * Description. | |
| 635 | - * | |
| 636 | - * @since 1.7.0 | |
| 637 | - * | |
| 638 | - * @param int $user_id | |
| 639 | - * @param int $quiz_lesson_id | |
| 640 | - */ | |
| 641 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); | |
| 631 | + /** | |
| 632 | + * Summary. | |
| 633 | + * | |
| 634 | + * Description. | |
| 635 | + * | |
| 636 | + * @since 1.7.0 | |
| 637 | + * | |
| 638 | + * @param int $user_id | |
| 639 | + * @param int $quiz_lesson_id | |
| 640 | + */ | |
| 641 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); | |
| 642 | 642 | |
| 643 | - } // end if in_array | |
| 643 | + } // end if in_array | |
| 644 | 644 | |
| 645 | - }// end if $_POST['all_que... | |
| 645 | + }// end if $_POST['all_que... | |
| 646 | 646 | |
| 647 | -        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { | |
| 647 | +		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { | |
| 648 | 648 | |
| 649 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 649 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 650 | 650 | |
| 651 | -        } elseif ( isset( $_POST['_wp_http_referer'] ) ) { | |
| 651 | +		} elseif ( isset( $_POST['_wp_http_referer'] ) ) { | |
| 652 | 652 | |
| 653 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); | |
| 653 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); | |
| 654 | 654 | |
| 655 | -        } else { | |
| 655 | +		} else { | |
| 656 | 656 | |
| 657 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 657 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 658 | 658 | |
| 659 | - } | |
| 659 | + } | |
| 660 | 660 | |
| 661 | - wp_safe_redirect( esc_url_raw( $load_url ) ); | |
| 662 | - exit; | |
| 661 | + wp_safe_redirect( esc_url_raw( $load_url ) ); | |
| 662 | + exit; | |
| 663 | 663 | |
| 664 | - } // end admin_process_grading_submission | |
| 664 | + } // end admin_process_grading_submission | |
| 665 | 665 | |
| 666 | 666 |  	public function get_redirect_url() { | 
| 667 | 667 | // Parse POST data | 
| @@ -706,283 +706,283 @@ discard block | ||
| 706 | 706 | } // End If Statement | 
| 707 | 707 | } // End sensei_grading_notices() | 
| 708 | 708 | |
| 709 | - /** | |
| 710 | - * Grade quiz automatically | |
| 711 | - * | |
| 712 | - * This function grades each question automatically if there all questions are auto gradable. If not | |
| 713 | - * the quiz will not be auto gradable. | |
| 714 | - * | |
| 715 | - * @since 1.7.4 | |
| 716 | - * | |
| 717 | - * @param integer $quiz_id ID of quiz | |
| 718 | -     * @param  array $submitted questions id ans answers { | |
| 719 | - * @type int $question_id | |
| 720 | - * @type mixed $answer | |
| 721 | - * } | |
| 722 | - * @param integer $total_questions Total questions in quiz (not used) | |
| 723 | - * @param string $quiz_grade_type Optional defaults to auto | |
| 724 | - * | |
| 725 | - * @return int $quiz_grade total sum of all question grades | |
| 726 | - */ | |
| 727 | -    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { | |
| 728 | - | |
| 729 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted | |
| 730 | -            || $quiz_grade_type != 'auto' ) { | |
| 731 | - return false; // exit early | |
| 732 | - } | |
| 733 | - | |
| 734 | - | |
| 735 | - $user_id = get_current_user_id(); | |
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; | |
| 737 | - $quiz_autogradable = true; | |
| 738 | - | |
| 739 | - /** | |
| 740 | - * Filter the types of question types that can be automatically graded. | |
| 741 | - * | |
| 742 | - * This filter fires inside the auto grade quiz function and provides you with the default list. | |
| 743 | - * | |
| 744 | -         * @param array { | |
| 745 | - * 'multiple-choice', | |
| 746 | - * 'boolean', | |
| 747 | - * 'gap-fill'. | |
| 748 | - * } | |
| 749 | - */ | |
| 750 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); | |
| 751 | - | |
| 752 | - $grade_total = 0; | |
| 753 | - $all_question_grades = array(); | |
| 754 | -        foreach( $submitted as $question_id => $answer ) { | |
| 755 | - | |
| 756 | - // check if the question is autogradable, either by type, or because the grade is 0 | |
| 757 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 709 | + /** | |
| 710 | + * Grade quiz automatically | |
| 711 | + * | |
| 712 | + * This function grades each question automatically if there all questions are auto gradable. If not | |
| 713 | + * the quiz will not be auto gradable. | |
| 714 | + * | |
| 715 | + * @since 1.7.4 | |
| 716 | + * | |
| 717 | + * @param integer $quiz_id ID of quiz | |
| 718 | +	 * @param  array $submitted questions id ans answers { | |
| 719 | + * @type int $question_id | |
| 720 | + * @type mixed $answer | |
| 721 | + * } | |
| 722 | + * @param integer $total_questions Total questions in quiz (not used) | |
| 723 | + * @param string $quiz_grade_type Optional defaults to auto | |
| 724 | + * | |
| 725 | + * @return int $quiz_grade total sum of all question grades | |
| 726 | + */ | |
| 727 | +	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { | |
| 728 | + | |
| 729 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted | |
| 730 | +			|| $quiz_grade_type != 'auto' ) { | |
| 731 | + return false; // exit early | |
| 732 | + } | |
| 733 | + | |
| 734 | + | |
| 735 | + $user_id = get_current_user_id(); | |
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; | |
| 737 | + $quiz_autogradable = true; | |
| 738 | + | |
| 739 | + /** | |
| 740 | + * Filter the types of question types that can be automatically graded. | |
| 741 | + * | |
| 742 | + * This filter fires inside the auto grade quiz function and provides you with the default list. | |
| 743 | + * | |
| 744 | +		 * @param array { | |
| 745 | + * 'multiple-choice', | |
| 746 | + * 'boolean', | |
| 747 | + * 'gap-fill'. | |
| 748 | + * } | |
| 749 | + */ | |
| 750 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); | |
| 751 | + | |
| 752 | + $grade_total = 0; | |
| 753 | + $all_question_grades = array(); | |
| 754 | +		foreach( $submitted as $question_id => $answer ) { | |
| 755 | + | |
| 756 | + // check if the question is autogradable, either by type, or because the grade is 0 | |
| 757 | + $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 758 | 758 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); | 
| 759 | 759 | // Question has a zero grade, so skip grading | 
| 760 | 760 |  			if ( 0 == $achievable_grade ) { | 
| 761 | 761 | $all_question_grades[ $question_id ] = $achievable_grade; | 
| 762 | 762 | } | 
| 763 | -            elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 764 | - // Get user question grade | |
| 765 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | |
| 766 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 767 | - $grade_total += $question_grade; | |
| 763 | +			elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 764 | + // Get user question grade | |
| 765 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | |
| 766 | + $all_question_grades[ $question_id ] = $question_grade; | |
| 767 | + $grade_total += $question_grade; | |
| 768 | 768 | |
| 769 | -            } else { | |
| 769 | +			} else { | |
| 770 | 770 | |
| 771 | - // There is a question that cannot be autograded | |
| 772 | - $quiz_autogradable = false; | |
| 771 | + // There is a question that cannot be autograded | |
| 772 | + $quiz_autogradable = false; | |
| 773 | 773 | |
| 774 | - } // end if in_array( $question_type... | |
| 774 | + } // end if in_array( $question_type... | |
| 775 | 775 | |
| 776 | - }// end for each question | |
| 776 | + }// end for each question | |
| 777 | 777 | |
| 778 | - // Only if the whole quiz was autogradable do we set a grade | |
| 779 | -        if ( $quiz_autogradable ) { | |
| 778 | + // Only if the whole quiz was autogradable do we set a grade | |
| 779 | +		if ( $quiz_autogradable ) { | |
| 780 | 780 | |
| 781 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); | |
| 781 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); | |
| 782 | 782 | // Check for zero total from grades | 
| 783 | 783 |  			if ( 0 < $quiz_total ) { | 
| 784 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | |
| 784 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | |
| 785 | 785 | } | 
| 786 | 786 |  			else { | 
| 787 | 787 | $grade = 0; | 
| 788 | 788 | } | 
| 789 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | |
| 789 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | |
| 790 | 790 | |
| 791 | -        } else { | |
| 791 | +		} else { | |
| 792 | 792 | |
| 793 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); | |
| 793 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); | |
| 794 | 794 | |
| 795 | - } | |
| 796 | - | |
| 797 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default | |
| 798 | - // when doing manual grading. | |
| 799 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); | |
| 795 | + } | |
| 800 | 796 | |
| 801 | - return $grade; | |
| 797 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default | |
| 798 | + // when doing manual grading. | |
| 799 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); | |
| 802 | 800 | |
| 803 | - } // End grade_quiz_auto() | |
| 801 | + return $grade; | |
| 804 | 802 | |
| 805 | - /** | |
| 806 | - * Grade question automatically | |
| 807 | - * | |
| 808 | - * This function checks the question typ and then grades it accordingly. | |
| 809 | - * | |
| 810 | - * @since 1.7.4 | |
| 811 | - * | |
| 812 | - * @param integer $question_id | |
| 813 | - * @param string $question_type of the standard Sensei question types | |
| 814 | - * @param string $answer | |
| 815 | - * @param int $user_id | |
| 816 | - * | |
| 817 | - * @return int $question_grade | |
| 818 | - */ | |
| 819 | -    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { | |
| 820 | - | |
| 821 | -        if( intval( $user_id ) == 0 ) { | |
| 822 | - | |
| 823 | - $user_id = get_current_user_id(); | |
| 824 | - | |
| 825 | - } | |
| 826 | - | |
| 827 | -        if( ! ( intval( $question_id ) > 0 ) ) { | |
| 828 | - | |
| 829 | - return false; | |
| 830 | - | |
| 831 | - } | |
| 832 | - | |
| 833 | - | |
| 834 | - Sensei()->question->get_question_type( $question_id ); | |
| 835 | - | |
| 836 | - /** | |
| 837 | - * Applying a grade before the auto grading takes place. | |
| 838 | - * | |
| 839 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question | |
| 840 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value | |
| 841 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. | |
| 842 | - * | |
| 843 | - * @param int $question_grade default false | |
| 844 | - * @param int $question_id | |
| 845 | - * @param string $question_type one of the Sensei question type. | |
| 846 | - * @param string $answer user supplied question answer | |
| 847 | - */ | |
| 848 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); | |
| 803 | + } // End grade_quiz_auto() | |
| 849 | 804 | |
| 850 | -        if ( false !== $question_grade ) { | |
| 805 | + /** | |
| 806 | + * Grade question automatically | |
| 807 | + * | |
| 808 | + * This function checks the question typ and then grades it accordingly. | |
| 809 | + * | |
| 810 | + * @since 1.7.4 | |
| 811 | + * | |
| 812 | + * @param integer $question_id | |
| 813 | + * @param string $question_type of the standard Sensei question types | |
| 814 | + * @param string $answer | |
| 815 | + * @param int $user_id | |
| 816 | + * | |
| 817 | + * @return int $question_grade | |
| 818 | + */ | |
| 819 | +	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { | |
| 820 | + | |
| 821 | +		if( intval( $user_id ) == 0 ) { | |
| 822 | + | |
| 823 | + $user_id = get_current_user_id(); | |
| 824 | + | |
| 825 | + } | |
| 826 | + | |
| 827 | +		if( ! ( intval( $question_id ) > 0 ) ) { | |
| 828 | + | |
| 829 | + return false; | |
| 830 | + | |
| 831 | + } | |
| 832 | + | |
| 833 | + | |
| 834 | + Sensei()->question->get_question_type( $question_id ); | |
| 835 | + | |
| 836 | + /** | |
| 837 | + * Applying a grade before the auto grading takes place. | |
| 838 | + * | |
| 839 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question | |
| 840 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value | |
| 841 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. | |
| 842 | + * | |
| 843 | + * @param int $question_grade default false | |
| 844 | + * @param int $question_id | |
| 845 | + * @param string $question_type one of the Sensei question type. | |
| 846 | + * @param string $answer user supplied question answer | |
| 847 | + */ | |
| 848 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); | |
| 851 | 849 | |
| 852 | - return $question_grade; | |
| 850 | +		if ( false !== $question_grade ) { | |
| 853 | 851 | |
| 854 | - } | |
| 852 | + return $question_grade; | |
| 855 | 853 | |
| 856 | - // auto grading core | |
| 857 | -        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){ | |
| 854 | + } | |
| 858 | 855 | |
| 859 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); | |
| 856 | + // auto grading core | |
| 857 | +		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){ | |
| 860 | 858 | |
| 861 | -            if( 0 == get_magic_quotes_gpc() ) { | |
| 862 | - $answer = wp_unslash( $answer ); | |
| 863 | - } | |
| 864 | - $answer = (array) $answer; | |
| 865 | -            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { | |
| 866 | - // Loop through all answers ensure none are 'missing' | |
| 867 | - $all_correct = true; | |
| 868 | -                foreach ( $answer as $check_answer ) { | |
| 869 | -                    if ( !in_array( $check_answer, $right_answer ) ) { | |
| 870 | - $all_correct = false; | |
| 871 | - } | |
| 872 | - } | |
| 873 | - // If all correct then grade | |
| 874 | -                if ( $all_correct ) { | |
| 875 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 876 | - } | |
| 877 | - } | |
| 859 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); | |
| 878 | 860 | |
| 879 | -        } elseif( 'gap-fill' == $question_type ){ | |
| 861 | +			if( 0 == get_magic_quotes_gpc() ) { | |
| 862 | + $answer = wp_unslash( $answer ); | |
| 863 | + } | |
| 864 | + $answer = (array) $answer; | |
| 865 | +			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { | |
| 866 | + // Loop through all answers ensure none are 'missing' | |
| 867 | + $all_correct = true; | |
| 868 | +				foreach ( $answer as $check_answer ) { | |
| 869 | +					if ( !in_array( $check_answer, $right_answer ) ) { | |
| 870 | + $all_correct = false; | |
| 871 | + } | |
| 872 | + } | |
| 873 | + // If all correct then grade | |
| 874 | +				if ( $all_correct ) { | |
| 875 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 876 | + } | |
| 877 | + } | |
| 880 | 878 | |
| 881 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); | |
| 879 | +		} elseif( 'gap-fill' == $question_type ){ | |
| 882 | 880 | |
| 883 | -        } else{ | |
| 881 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); | |
| 884 | 882 | |
| 885 | - /** | |
| 886 | - * Grading questions that are not auto gradable. | |
| 887 | - * | |
| 888 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. | |
| 889 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. | |
| 890 | - * | |
| 891 | - * @param int $question_grade default zero | |
| 892 | - * @param int $question_id | |
| 893 | - * @param string $question_type one of the Sensei question type. | |
| 894 | - * @param string $answer user supplied question answer | |
| 895 | - */ | |
| 896 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); | |
| 883 | +		} else{ | |
| 897 | 884 | |
| 898 | - } // end if $question_type | |
| 885 | + /** | |
| 886 | + * Grading questions that are not auto gradable. | |
| 887 | + * | |
| 888 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. | |
| 889 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. | |
| 890 | + * | |
| 891 | + * @param int $question_grade default zero | |
| 892 | + * @param int $question_id | |
| 893 | + * @param string $question_type one of the Sensei question type. | |
| 894 | + * @param string $answer user supplied question answer | |
| 895 | + */ | |
| 896 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); | |
| 899 | 897 | |
| 900 | - return $question_grade; | |
| 901 | - } // end grade_question_auto | |
| 898 | + } // end if $question_type | |
| 902 | 899 | |
| 903 | - /** | |
| 904 | - * Grading logic specifically for the gap fill questions | |
| 905 | - * | |
| 906 | - * @since 1.9.0 | |
| 907 | - * @param $question_id | |
| 908 | - * @param $user_answer | |
| 909 | - * | |
| 910 | - * @return bool | int false or the grade given to the user answer | |
| 911 | - */ | |
| 912 | -    public static function grade_gap_fill_question( $question_id, $user_answer ){ | |
| 900 | + return $question_grade; | |
| 901 | + } // end grade_question_auto | |
| 913 | 902 | |
| 914 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 915 | - $gapfill_array = explode( '||', $right_answer ); | |
| 903 | + /** | |
| 904 | + * Grading logic specifically for the gap fill questions | |
| 905 | + * | |
| 906 | + * @since 1.9.0 | |
| 907 | + * @param $question_id | |
| 908 | + * @param $user_answer | |
| 909 | + * | |
| 910 | + * @return bool | int false or the grade given to the user answer | |
| 911 | + */ | |
| 912 | +	public static function grade_gap_fill_question( $question_id, $user_answer ){ | |
| 916 | 913 | |
| 917 | -        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 918 | - $user_answer = wp_unslash( $user_answer ); | |
| 919 | - } | |
| 914 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 915 | + $gapfill_array = explode( '||', $right_answer ); | |
| 920 | 916 | |
| 921 | - /** | |
| 922 | - * case sensitive grading filter | |
| 923 | - * | |
| 924 | - * alter the value simply use this code in your plugin or the themes functions.php | |
| 925 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); | |
| 926 | - * | |
| 927 | - * @param bool $do_case_sensitive_comparison default false. | |
| 928 | - * | |
| 929 | - * @since 1.9.0 | |
| 930 | - */ | |
| 931 | -        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); | |
| 917 | +		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 918 | + $user_answer = wp_unslash( $user_answer ); | |
| 919 | + } | |
| 920 | + | |
| 921 | + /** | |
| 922 | + * case sensitive grading filter | |
| 923 | + * | |
| 924 | + * alter the value simply use this code in your plugin or the themes functions.php | |
| 925 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); | |
| 926 | + * | |
| 927 | + * @param bool $do_case_sensitive_comparison default false. | |
| 928 | + * | |
| 929 | + * @since 1.9.0 | |
| 930 | + */ | |
| 931 | +		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); | |
| 932 | 932 | |
| 933 | -        if( $do_case_sensitive_comparison ){ | |
| 933 | +		if( $do_case_sensitive_comparison ){ | |
| 934 | 934 | |
| 935 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 936 | -            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { | |
| 935 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 936 | +			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { | |
| 937 | 937 | |
| 938 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 938 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 939 | 939 | |
| 940 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 940 | +			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 941 | 941 | |
| 942 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 942 | +				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 943 | 943 | |
| 944 | - return Sensei()->question->get_question_grade($question_id); | |
| 944 | + return Sensei()->question->get_question_grade($question_id); | |
| 945 | 945 | |
| 946 | -                }else{ | |
| 946 | +				}else{ | |
| 947 | 947 | |
| 948 | - return false; | |
| 948 | + return false; | |
| 949 | 949 | |
| 950 | - } | |
| 950 | + } | |
| 951 | 951 | |
| 952 | -            }else{ | |
| 952 | +			}else{ | |
| 953 | 953 | |
| 954 | - return false; | |
| 954 | + return false; | |
| 955 | 955 | |
| 956 | - } | |
| 956 | + } | |
| 957 | 957 | |
| 958 | -        }else{ | |
| 958 | +		}else{ | |
| 959 | 959 | |
| 960 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 961 | -            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | |
| 960 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 961 | +			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | |
| 962 | 962 | |
| 963 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 963 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 964 | 964 | |
| 965 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 965 | +			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 966 | 966 | |
| 967 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 967 | +				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 968 | 968 | |
| 969 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 969 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 970 | 970 | |
| 971 | -                }else{ | |
| 971 | +				}else{ | |
| 972 | 972 | |
| 973 | - return false; | |
| 973 | + return false; | |
| 974 | 974 | |
| 975 | - } | |
| 975 | + } | |
| 976 | 976 | |
| 977 | -            }else{ | |
| 977 | +			}else{ | |
| 978 | 978 | |
| 979 | - return false; | |
| 979 | + return false; | |
| 980 | 980 | |
| 981 | - } | |
| 981 | + } | |
| 982 | 982 | |
| 983 | - } | |
| 983 | + } | |
| 984 | 984 | |
| 985 | - } | |
| 985 | + } | |
| 986 | 986 | |
| 987 | 987 | } // End Class | 
| 988 | 988 | |
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly | |
| 3 | 3 | |
| 4 | 4 | /** | 
| 5 | 5 | * Sensei Grading Class | 
| @@ -23,30 +23,30 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @param $file | 
| 25 | 25 | */ | 
| 26 | -	public function __construct ( $file ) { | |
| 27 | - $this->name = __( 'Grading', 'woothemes-sensei' ); | |
| 26 | +	public function __construct($file) { | |
| 27 | +		$this->name = __('Grading', 'woothemes-sensei'); | |
| 28 | 28 | $this->file = $file; | 
| 29 | 29 | $this->page_slug = 'sensei_grading'; | 
| 30 | 30 | |
| 31 | 31 | // Admin functions | 
| 32 | -		if ( is_admin() ) { | |
| 33 | - add_action( 'admin_menu', array( $this, 'grading_admin_menu' ), 20); | |
| 34 | - add_action( 'grading_wrapper_container', array( $this, 'wrapper_container' ) ); | |
| 35 | -			if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { | |
| 36 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 37 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); | |
| 32 | +		if (is_admin()) { | |
| 33 | +			add_action('admin_menu', array($this, 'grading_admin_menu'), 20); | |
| 34 | +			add_action('grading_wrapper_container', array($this, 'wrapper_container')); | |
| 35 | +			if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { | |
| 36 | +				add_action('admin_print_scripts', array($this, 'enqueue_scripts')); | |
| 37 | +				add_action('admin_print_styles', array($this, 'enqueue_styles')); | |
| 38 | 38 | } | 
| 39 | 39 | |
| 40 | - add_action( 'admin_init', array( $this, 'admin_process_grading_submission' ) ); | |
| 40 | +			add_action('admin_init', array($this, 'admin_process_grading_submission')); | |
| 41 | 41 | |
| 42 | - add_action( 'admin_notices', array( $this, 'add_grading_notices' ) ); | |
| 42 | +			add_action('admin_notices', array($this, 'add_grading_notices')); | |
| 43 | 43 | // add_action( 'sensei_grading_notices', array( $this, 'sensei_grading_notices' ) ); | 
| 44 | 44 | } // End If Statement | 
| 45 | 45 | |
| 46 | 46 | // Ajax functions | 
| 47 | -		if ( is_admin() ) { | |
| 48 | - add_action( 'wp_ajax_get_lessons_dropdown', array( $this, 'get_lessons_dropdown' ) ); | |
| 49 | - add_action( 'wp_ajax_get_redirect_url', array( $this, 'get_redirect_url' ) ); | |
| 47 | +		if (is_admin()) { | |
| 48 | +			add_action('wp_ajax_get_lessons_dropdown', array($this, 'get_lessons_dropdown')); | |
| 49 | +			add_action('wp_ajax_get_redirect_url', array($this, 'get_redirect_url')); | |
| 50 | 50 | } // End If Statement | 
| 51 | 51 | } // End __construct() | 
| 52 | 52 | |
| @@ -59,8 +59,8 @@ discard block | ||
| 59 | 59 |  	public function grading_admin_menu() { | 
| 60 | 60 | global $menu; | 
| 61 | 61 | |
| 62 | -		if ( current_user_can( 'manage_sensei_grades' ) ) { | |
| 63 | -			$grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'),  __('Grading', 'woothemes-sensei') , 'manage_sensei_grades', $this->page_slug, array( $this, 'grading_page' ) ); | |
| 62 | +		if (current_user_can('manage_sensei_grades')) { | |
| 63 | +			$grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei'), 'manage_sensei_grades', $this->page_slug, array($this, 'grading_page')); | |
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | } // End grading_admin_menu() | 
| @@ -73,12 +73,12 @@ discard block | ||
| 73 | 73 | * @since 1.3.0 | 
| 74 | 74 | * @return void | 
| 75 | 75 | */ | 
| 76 | -	public function enqueue_scripts () { | |
| 76 | +	public function enqueue_scripts() { | |
| 77 | 77 | |
| 78 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 78 | +		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; | |
| 79 | 79 | |
| 80 | 80 | // Load Grading JS | 
| 81 | - wp_enqueue_script( 'sensei-grading-general', Sensei()->plugin_url . 'assets/js/grading-general' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); | |
| 81 | +		wp_enqueue_script('sensei-grading-general', Sensei()->plugin_url.'assets/js/grading-general'.$suffix.'.js', array('jquery'), Sensei()->version); | |
| 82 | 82 | |
| 83 | 83 | } // End enqueue_scripts() | 
| 84 | 84 | |
| @@ -90,11 +90,11 @@ discard block | ||
| 90 | 90 | * @since 1.0.0 | 
| 91 | 91 | * @return void | 
| 92 | 92 | */ | 
| 93 | -	public function enqueue_styles () { | |
| 93 | +	public function enqueue_styles() { | |
| 94 | 94 | |
| 95 | - wp_enqueue_style( Sensei()->token . '-admin' ); | |
| 95 | + wp_enqueue_style(Sensei()->token.'-admin'); | |
| 96 | 96 | |
| 97 | - wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version ); | |
| 97 | +		wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version); | |
| 98 | 98 | |
| 99 | 99 | } // End enqueue_styles() | 
| 100 | 100 | |
| @@ -106,12 +106,12 @@ discard block | ||
| 106 | 106 |  	public function load_data_table_files() { | 
| 107 | 107 | |
| 108 | 108 | // Load Grading Classes | 
| 109 | - $classes_to_load = array( 'list-table', | |
| 109 | +		$classes_to_load = array('list-table', | |
| 110 | 110 | 'grading-main', | 
| 111 | 111 | 'grading-user-quiz' | 
| 112 | 112 | ); | 
| 113 | -		foreach ( $classes_to_load as $class_file ) { | |
| 114 | - Sensei()->load_class( $class_file ); | |
| 113 | +		foreach ($classes_to_load as $class_file) { | |
| 114 | + Sensei()->load_class($class_file); | |
| 115 | 115 | } // End For Loop | 
| 116 | 116 | } // End load_data_table_files() | 
| 117 | 117 | |
| @@ -123,16 +123,16 @@ discard block | ||
| 123 | 123 | * @param undefined $optional_data optional constructor arguments | 
| 124 | 124 | * @return object class instance object | 
| 125 | 125 | */ | 
| 126 | -	public function load_data_object( $name = '', $data = 0, $optional_data = null ) { | |
| 126 | +	public function load_data_object($name = '', $data = 0, $optional_data = null) { | |
| 127 | 127 | // Load Analysis data | 
| 128 | - $object_name = 'WooThemes_Sensei_Grading_' . $name; | |
| 129 | -		if ( is_null($optional_data) ) { | |
| 130 | - $sensei_grading_object = new $object_name( $data ); | |
| 128 | + $object_name = 'WooThemes_Sensei_Grading_'.$name; | |
| 129 | +		if (is_null($optional_data)) { | |
| 130 | + $sensei_grading_object = new $object_name($data); | |
| 131 | 131 | } | 
| 132 | 132 |  		else { | 
| 133 | - $sensei_grading_object = new $object_name( $data, $optional_data ); | |
| 133 | + $sensei_grading_object = new $object_name($data, $optional_data); | |
| 134 | 134 | } // End If Statement | 
| 135 | -		if ( 'Main' == $name ) { | |
| 135 | +		if ('Main' == $name) { | |
| 136 | 136 | $sensei_grading_object->prepare_items(); | 
| 137 | 137 | } // End If Statement | 
| 138 | 138 | return $sensei_grading_object; | 
| @@ -146,7 +146,7 @@ discard block | ||
| 146 | 146 | */ | 
| 147 | 147 |  	public function grading_page() { | 
| 148 | 148 | |
| 149 | -		if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { | |
| 149 | +		if (isset($_GET['quiz_id']) && 0 < intval($_GET['quiz_id']) && isset($_GET['user']) && 0 < intval($_GET['user'])) { | |
| 150 | 150 | $this->grading_user_quiz_view(); | 
| 151 | 151 | } | 
| 152 | 152 |  		else { | 
| @@ -162,23 +162,23 @@ discard block | ||
| 162 | 162 |  	public function grading_default_view() { | 
| 163 | 163 | |
| 164 | 164 | // Load Grading data | 
| 165 | -		if( !empty( $_GET['course_id'] ) ) { | |
| 166 | - $course_id = intval( $_GET['course_id'] ); | |
| 165 | +		if ( ! empty($_GET['course_id'])) { | |
| 166 | + $course_id = intval($_GET['course_id']); | |
| 167 | 167 | } | 
| 168 | -		if( !empty( $_GET['lesson_id'] ) ) { | |
| 169 | - $lesson_id = intval( $_GET['lesson_id'] ); | |
| 168 | +		if ( ! empty($_GET['lesson_id'])) { | |
| 169 | + $lesson_id = intval($_GET['lesson_id']); | |
| 170 | 170 | } | 
| 171 | -		if( !empty( $_GET['user_id'] ) ) { | |
| 172 | - $user_id = intval( $_GET['user_id'] ); | |
| 171 | +		if ( ! empty($_GET['user_id'])) { | |
| 172 | + $user_id = intval($_GET['user_id']); | |
| 173 | 173 | } | 
| 174 | -		if( !empty( $_GET['view'] ) ) { | |
| 175 | - $view = esc_html( $_GET['view'] ); | |
| 174 | +		if ( ! empty($_GET['view'])) { | |
| 175 | + $view = esc_html($_GET['view']); | |
| 176 | 176 | } | 
| 177 | - $sensei_grading_overview = $this->load_data_object( 'Main', compact( 'course_id', 'lesson_id', 'user_id', 'view' ) ); | |
| 177 | +		$sensei_grading_overview = $this->load_data_object('Main', compact('course_id', 'lesson_id', 'user_id', 'view')); | |
| 178 | 178 | |
| 179 | 179 | // Wrappers | 
| 180 | - do_action( 'grading_before_container' ); | |
| 181 | - do_action( 'grading_wrapper_container', 'top' ); | |
| 180 | +		do_action('grading_before_container'); | |
| 181 | +		do_action('grading_wrapper_container', 'top'); | |
| 182 | 182 | $this->grading_headers(); | 
| 183 | 183 | ?> | 
| 184 | 184 | <div id="poststuff" class="sensei-grading-wrap"> | 
| @@ -186,12 +186,12 @@ discard block | ||
| 186 | 186 | <?php $sensei_grading_overview->display(); ?> | 
| 187 | 187 | </div> | 
| 188 | 188 | <div class="sensei-grading-extra"> | 
| 189 | - <?php do_action( 'sensei_grading_extra' ); ?> | |
| 189 | +				<?php do_action('sensei_grading_extra'); ?> | |
| 190 | 190 | </div> | 
| 191 | 191 | </div> | 
| 192 | 192 | <?php | 
| 193 | - do_action( 'grading_wrapper_container', 'bottom' ); | |
| 194 | - do_action( 'grading_after_container' ); | |
| 193 | +		do_action('grading_wrapper_container', 'bottom'); | |
| 194 | +		do_action('grading_after_container'); | |
| 195 | 195 | } // End grading_default_view() | 
| 196 | 196 | |
| 197 | 197 | /** | 
| @@ -204,17 +204,17 @@ discard block | ||
| 204 | 204 | // Load Grading data | 
| 205 | 205 | $user_id = 0; | 
| 206 | 206 | $quiz_id = 0; | 
| 207 | -		if( isset( $_GET['user'] ) ) { | |
| 208 | - $user_id = intval( $_GET['user'] ); | |
| 207 | +		if (isset($_GET['user'])) { | |
| 208 | + $user_id = intval($_GET['user']); | |
| 209 | 209 | } | 
| 210 | -		if( isset( $_GET['quiz_id'] ) ) { | |
| 211 | - $quiz_id = intval( $_GET['quiz_id'] ); | |
| 210 | +		if (isset($_GET['quiz_id'])) { | |
| 211 | + $quiz_id = intval($_GET['quiz_id']); | |
| 212 | 212 | } | 
| 213 | - $sensei_grading_user_profile = $this->load_data_object( 'User_Quiz', $user_id, $quiz_id ); | |
| 213 | +		$sensei_grading_user_profile = $this->load_data_object('User_Quiz', $user_id, $quiz_id); | |
| 214 | 214 | // Wrappers | 
| 215 | - do_action( 'grading_before_container' ); | |
| 216 | - do_action( 'grading_wrapper_container', 'top' ); | |
| 217 | - $this->grading_headers( array( 'nav' => 'user_quiz' ) ); | |
| 215 | +		do_action('grading_before_container'); | |
| 216 | +		do_action('grading_wrapper_container', 'top'); | |
| 217 | +		$this->grading_headers(array('nav' => 'user_quiz')); | |
| 218 | 218 | ?> | 
| 219 | 219 | <div id="poststuff" class="sensei-grading-wrap user-profile"> | 
| 220 | 220 | <div class="sensei-grading-main"> | 
| @@ -223,8 +223,8 @@ discard block | ||
| 223 | 223 | </div> | 
| 224 | 224 | </div> | 
| 225 | 225 | <?php | 
| 226 | - do_action( 'grading_wrapper_container', 'bottom' ); | |
| 227 | - do_action( 'grading_after_container' ); | |
| 226 | +		do_action('grading_wrapper_container', 'bottom'); | |
| 227 | +		do_action('grading_after_container'); | |
| 228 | 228 | } // End grading_user_quiz_view() | 
| 229 | 229 | |
| 230 | 230 | /** | 
| @@ -233,14 +233,14 @@ discard block | ||
| 233 | 233 | * @param array $args | 
| 234 | 234 | * @return void | 
| 235 | 235 | */ | 
| 236 | -	public function grading_headers( $args = array( 'nav' => 'default' ) ) { | |
| 236 | +	public function grading_headers($args = array('nav' => 'default')) { | |
| 237 | 237 | |
| 238 | - $function = 'grading_' . $args['nav'] . '_nav'; | |
| 238 | + $function = 'grading_'.$args['nav'].'_nav'; | |
| 239 | 239 | $this->$function(); | 
| 240 | 240 | ?> | 
| 241 | - <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> | |
| 241 | +			<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> | |
| 242 | 242 | <?php | 
| 243 | - do_action( 'sensei_grading_after_headers' ); | |
| 243 | +		do_action('sensei_grading_after_headers'); | |
| 244 | 244 | } // End grading_headers() | 
| 245 | 245 | |
| 246 | 246 | /** | 
| @@ -249,10 +249,10 @@ discard block | ||
| 249 | 249 | * @param $which string | 
| 250 | 250 | * @return void | 
| 251 | 251 | */ | 
| 252 | -	public function wrapper_container( $which ) { | |
| 253 | -		if ( 'top' == $which ) { | |
| 252 | +	public function wrapper_container($which) { | |
| 253 | +		if ('top' == $which) { | |
| 254 | 254 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php | 
| 255 | -		} elseif ( 'bottom' == $which ) { | |
| 255 | +		} elseif ('bottom' == $which) { | |
| 256 | 256 | ?></div><!--/#woothemes-sensei--><?php | 
| 257 | 257 | } // End If Statement | 
| 258 | 258 | } // End wrapper_container() | 
| @@ -265,29 +265,29 @@ discard block | ||
| 265 | 265 |  	public function grading_default_nav() { | 
| 266 | 266 | global $wp_version; | 
| 267 | 267 | |
| 268 | - $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 ) ); | |
| 269 | -		if ( isset( $_GET['course_id'] ) ) {  | |
| 270 | - $course_id = intval( $_GET['course_id'] ); | |
| 271 | -			if ( version_compare($wp_version, '4.1', '>=') ) { | |
| 272 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); | |
| 273 | - $title .= sprintf( '  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); | |
| 268 | +		$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)); | |
| 269 | +		if (isset($_GET['course_id'])) {  | |
| 270 | + $course_id = intval($_GET['course_id']); | |
| 271 | +			if (version_compare($wp_version, '4.1', '>=')) { | |
| 272 | +				$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); | |
| 273 | +				$title .= sprintf('  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); | |
| 274 | 274 | } | 
| 275 | 275 |  			else { | 
| 276 | - $title .= sprintf( '  <span class="course-title">>  %s</span>', get_the_title( $course_id ) ); | |
| 276 | +				$title .= sprintf('  <span class="course-title">>  %s</span>', get_the_title($course_id));  | |
| 277 | 277 | } | 
| 278 | 278 | } | 
| 279 | -		if ( isset( $_GET['lesson_id'] ) ) {  | |
| 280 | - $lesson_id = intval( $_GET['lesson_id'] ); | |
| 281 | - $title .= '  <span class="lesson-title">>  ' . get_the_title( intval( $lesson_id ) ) . '</span>'; | |
| 279 | +		if (isset($_GET['lesson_id'])) {  | |
| 280 | + $lesson_id = intval($_GET['lesson_id']); | |
| 281 | + $title .= '  <span class="lesson-title">>  '.get_the_title(intval($lesson_id)).'</span>'; | |
| 282 | 282 | } | 
| 283 | -		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { | |
| 283 | +		if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { | |
| 284 | 284 | |
| 285 | - $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); | |
| 286 | - $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | |
| 285 | + $user_name = Sensei_Learner::get_full_name($_GET['user_id']); | |
| 286 | + $title .= '  <span class="user-title">>  '.$user_name.'</span>'; | |
| 287 | 287 | |
| 288 | 288 | } // End If Statement | 
| 289 | 289 | ?> | 
| 290 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> | |
| 290 | +			<h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> | |
| 291 | 291 | <?php | 
| 292 | 292 | } // End grading_default_nav() | 
| 293 | 293 | |
| @@ -299,29 +299,29 @@ discard block | ||
| 299 | 299 |  	public function grading_user_quiz_nav() { | 
| 300 | 300 | global $wp_version; | 
| 301 | 301 | |
| 302 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); | |
| 303 | -		if ( isset( $_GET['quiz_id'] ) ) {  | |
| 304 | - $quiz_id = intval( $_GET['quiz_id'] ); | |
| 305 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); | |
| 306 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 307 | -			if ( version_compare($wp_version, '4.1', '>=') ) { | |
| 308 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); | |
| 309 | - $title .= sprintf( '  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); | |
| 302 | +		$title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); | |
| 303 | +		if (isset($_GET['quiz_id'])) {  | |
| 304 | + $quiz_id = intval($_GET['quiz_id']); | |
| 305 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); | |
| 306 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); | |
| 307 | +			if (version_compare($wp_version, '4.1', '>=')) { | |
| 308 | +				$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); | |
| 309 | +				$title .= sprintf('  <span class="course-title">>  <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); | |
| 310 | 310 | } | 
| 311 | 311 |  			else { | 
| 312 | - $title .= sprintf( '  <span class="course-title">>  %s</span>', get_the_title( $course_id ) ); | |
| 312 | +				$title .= sprintf('  <span class="course-title">>  %s</span>', get_the_title($course_id));  | |
| 313 | 313 | } | 
| 314 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); | |
| 315 | - $title .= sprintf( '  <span class="lesson-title">>  <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) ); | |
| 314 | +			$url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php')); | |
| 315 | +			$title .= sprintf('  <span class="lesson-title">>  <a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id)); | |
| 316 | 316 | } | 
| 317 | -		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { | |
| 317 | +		if (isset($_GET['user']) && 0 < intval($_GET['user'])) { | |
| 318 | 318 | |
| 319 | - $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); | |
| 320 | - $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | |
| 319 | + $user_name = Sensei_Learner::get_full_name($_GET['user']); | |
| 320 | + $title .= '  <span class="user-title">>  '.$user_name.'</span>'; | |
| 321 | 321 | |
| 322 | 322 | } // End If Statement | 
| 323 | 323 | ?> | 
| 324 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> | |
| 324 | +			<h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> | |
| 325 | 325 | <?php | 
| 326 | 326 | } // End grading_user_quiz_nav() | 
| 327 | 327 | |
| @@ -330,9 +330,9 @@ discard block | ||
| 330 | 330 | * @since 1.7.0 | 
| 331 | 331 | * @return array | 
| 332 | 332 | */ | 
| 333 | -	public function get_stati( $type ) { | |
| 333 | +	public function get_stati($type) { | |
| 334 | 334 | $statuses = array(); | 
| 335 | -		switch( $type ) { | |
| 335 | +		switch ($type) { | |
| 336 | 336 | case 'course' : | 
| 337 | 337 | $statuses = array( | 
| 338 | 338 | 'in-progress', | 
| @@ -362,7 +362,7 @@ discard block | ||
| 362 | 362 | * @param array $args (default: array()) | 
| 363 | 363 | * @return object | 
| 364 | 364 | */ | 
| 365 | -	public function count_statuses( $args = array() ) { | |
| 365 | +	public function count_statuses($args = array()) { | |
| 366 | 366 | global $wpdb; | 
| 367 | 367 | |
| 368 | 368 | /** | 
| @@ -373,71 +373,71 @@ discard block | ||
| 373 | 373 | * @since 1.8.0 | 
| 374 | 374 | * @param array $args | 
| 375 | 375 | */ | 
| 376 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); | |
| 376 | +        $args = apply_filters('sensei_count_statuses_args', $args); | |
| 377 | 377 | |
| 378 | -		if ( 'course' == $args['type'] ) { | |
| 378 | +		if ('course' == $args['type']) { | |
| 379 | 379 | $type = 'sensei_course_status'; | 
| 380 | 380 | } | 
| 381 | 381 |  		else { | 
| 382 | 382 | $type = 'sensei_lesson_status'; | 
| 383 | 383 | } | 
| 384 | - $cache_key = 'sensei-' . $args['type'] . '-statuses'; | |
| 384 | + $cache_key = 'sensei-'.$args['type'].'-statuses'; | |
| 385 | 385 | |
| 386 | 386 |  		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; | 
| 387 | 387 | |
| 388 | 388 | // Restrict to specific posts | 
| 389 | -		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { | |
| 390 | -			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; | |
| 389 | +		if (isset($args['post__in']) && ! empty($args['post__in']) && is_array($args['post__in'])) { | |
| 390 | +			$query .= ' AND comment_post_ID IN ('.implode(',', array_map('absint', $args['post__in'])).')'; | |
| 391 | 391 | } | 
| 392 | -		elseif ( !empty( $args['post_id'] ) ) { | |
| 393 | - $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); | |
| 392 | +		elseif ( ! empty($args['post_id'])) { | |
| 393 | +			$query .= $wpdb->prepare(' AND comment_post_ID = %d', $args['post_id']); | |
| 394 | 394 | } | 
| 395 | 395 | // Restrict to specific users | 
| 396 | -		if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { | |
| 397 | -			$query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; | |
| 396 | +		if (isset($args['user_id']) && is_array($args['user_id'])) { | |
| 397 | +			$query .= ' AND user_id IN ('.implode(',', array_map('absint', $args['user_id'])).')'; | |
| 398 | 398 | } | 
| 399 | -		elseif ( !empty( $args['user_id'] ) ) { | |
| 400 | - $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); | |
| 399 | +		elseif ( ! empty($args['user_id'])) { | |
| 400 | +			$query .= $wpdb->prepare(' AND user_id = %d', $args['user_id']); | |
| 401 | 401 | } | 
| 402 | 402 | $query .= ' GROUP BY comment_approved'; | 
| 403 | 403 | |
| 404 | - $counts = wp_cache_get( $cache_key, 'counts' ); | |
| 405 | -		if ( false === $counts ) { | |
| 406 | - $sql = $wpdb->prepare( $query, $type ); | |
| 407 | - $results = (array) $wpdb->get_results( $sql, ARRAY_A ); | |
| 408 | - $counts = array_fill_keys( $this->get_stati( $type ), 0 ); | |
| 404 | + $counts = wp_cache_get($cache_key, 'counts'); | |
| 405 | +		if (false === $counts) { | |
| 406 | + $sql = $wpdb->prepare($query, $type); | |
| 407 | + $results = (array) $wpdb->get_results($sql, ARRAY_A); | |
| 408 | + $counts = array_fill_keys($this->get_stati($type), 0); | |
| 409 | 409 | |
| 410 | -			foreach ( $results as $row ) { | |
| 411 | - $counts[ $row['comment_approved'] ] = $row['total']; | |
| 410 | +			foreach ($results as $row) { | |
| 411 | + $counts[$row['comment_approved']] = $row['total']; | |
| 412 | 412 | } | 
| 413 | - wp_cache_set( $cache_key, $counts, 'counts' ); | |
| 413 | + wp_cache_set($cache_key, $counts, 'counts'); | |
| 414 | 414 | } | 
| 415 | 415 | |
| 416 | -		if( ! isset( $counts['graded'] ) ) { | |
| 416 | +		if ( ! isset($counts['graded'])) { | |
| 417 | 417 | $counts['graded'] = 0; | 
| 418 | 418 | } | 
| 419 | 419 | |
| 420 | -		if( ! isset( $counts['ungraded'] ) ) { | |
| 420 | +		if ( ! isset($counts['ungraded'])) { | |
| 421 | 421 | $counts['ungraded'] = 0; | 
| 422 | 422 | } | 
| 423 | 423 | |
| 424 | -		if( ! isset( $counts['passed'] ) ) { | |
| 424 | +		if ( ! isset($counts['passed'])) { | |
| 425 | 425 | $counts['passed'] = 0; | 
| 426 | 426 | } | 
| 427 | 427 | |
| 428 | -		if( ! isset( $counts['failed'] ) ) { | |
| 428 | +		if ( ! isset($counts['failed'])) { | |
| 429 | 429 | $counts['failed'] = 0; | 
| 430 | 430 | } | 
| 431 | 431 | |
| 432 | -		if( ! isset( $counts['in-progress'] ) ) { | |
| 432 | +		if ( ! isset($counts['in-progress'])) { | |
| 433 | 433 | $counts['in-progress'] = 0; | 
| 434 | 434 | } | 
| 435 | 435 | |
| 436 | -		if( ! isset( $counts['complete'] ) ) { | |
| 436 | +		if ( ! isset($counts['complete'])) { | |
| 437 | 437 | $counts['complete'] = 0; | 
| 438 | 438 | } | 
| 439 | 439 | |
| 440 | - return apply_filters( 'sensei_count_statuses', $counts, $type ); | |
| 440 | +		return apply_filters('sensei_count_statuses', $counts, $type); | |
| 441 | 441 | } // End sensei_count_statuses() | 
| 442 | 442 | |
| 443 | 443 | /** | 
| @@ -445,11 +445,11 @@ discard block | ||
| 445 | 445 | * @since 1.7.0 | 
| 446 | 446 | * @return string | 
| 447 | 447 | */ | 
| 448 | -	public function courses_drop_down_html( $selected_course_id = 0 ) { | |
| 448 | +	public function courses_drop_down_html($selected_course_id = 0) { | |
| 449 | 449 | |
| 450 | 450 | $html = ''; | 
| 451 | 451 | |
| 452 | - $course_args = array( 'post_type' => 'course', | |
| 452 | +		$course_args = array('post_type'         => 'course', | |
| 453 | 453 | 'posts_per_page' => -1, | 
| 454 | 454 | 'orderby' => 'title', | 
| 455 | 455 | 'order' => 'ASC', | 
| @@ -457,12 +457,12 @@ discard block | ||
| 457 | 457 | 'suppress_filters' => 0, | 
| 458 | 458 | 'fields' => 'ids', | 
| 459 | 459 | ); | 
| 460 | - $courses = get_posts( apply_filters( 'sensei_grading_filter_courses', $course_args ) ); | |
| 460 | +		$courses = get_posts(apply_filters('sensei_grading_filter_courses', $course_args)); | |
| 461 | 461 | |
| 462 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>'; | |
| 463 | -		if ( count( $courses ) > 0 ) { | |
| 464 | -			foreach ($courses as $course_id){ | |
| 465 | - $html .= '<option value="' . esc_attr( absint( $course_id ) ) . '" ' . selected( $course_id, $selected_course_id, false ) . '>' . esc_html( get_the_title( $course_id ) ) . '</option>' . "\n"; | |
| 462 | +		$html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'; | |
| 463 | +		if (count($courses) > 0) { | |
| 464 | +			foreach ($courses as $course_id) { | |
| 465 | + $html .= '<option value="'.esc_attr(absint($course_id)).'" '.selected($course_id, $selected_course_id, false).'>'.esc_html(get_the_title($course_id)).'</option>'."\n"; | |
| 466 | 466 | } // End For Loop | 
| 467 | 467 | } // End If Statement | 
| 468 | 468 | |
| @@ -483,20 +483,20 @@ discard block | ||
| 483 | 483 | $course_data = array(); | 
| 484 | 484 | parse_str($data, $course_data); | 
| 485 | 485 | |
| 486 | - $course_id = intval( $course_data['course_id'] ); | |
| 486 | + $course_id = intval($course_data['course_id']); | |
| 487 | 487 | |
| 488 | - $html = $this->lessons_drop_down_html( $course_id ); | |
| 488 | + $html = $this->lessons_drop_down_html($course_id); | |
| 489 | 489 | |
| 490 | 490 | echo $html; | 
| 491 | 491 | die(); // WordPress may print out a spurious zero without this can be particularly bad if using JSON | 
| 492 | 492 | } | 
| 493 | 493 | |
| 494 | -	public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0 ) { | |
| 494 | +	public function lessons_drop_down_html($course_id = 0, $selected_lesson_id = 0) { | |
| 495 | 495 | |
| 496 | 496 | $html = ''; | 
| 497 | -		if ( 0 < intval( $course_id ) ) { | |
| 497 | +		if (0 < intval($course_id)) { | |
| 498 | 498 | |
| 499 | - $lesson_args = array( 'post_type' => 'lesson', | |
| 499 | +			$lesson_args = array('post_type'       => 'lesson', | |
| 500 | 500 | 'posts_per_page' => -1, | 
| 501 | 501 | 'orderby' => 'title', | 
| 502 | 502 | 'order' => 'ASC', | 
| @@ -506,12 +506,12 @@ discard block | ||
| 506 | 506 | 'suppress_filters' => 0, | 
| 507 | 507 | 'fields' => 'ids', | 
| 508 | 508 | ); | 
| 509 | - $lessons = get_posts( apply_filters( 'sensei_grading_filter_lessons', $lesson_args ) ); | |
| 509 | +			$lessons = get_posts(apply_filters('sensei_grading_filter_lessons', $lesson_args)); | |
| 510 | 510 | |
| 511 | - $html .= '<option value="">' . __( 'Select a lesson', 'woothemes-sensei' ) . '</option>'; | |
| 512 | -			if ( count( $lessons ) > 0 ) { | |
| 513 | -				foreach ( $lessons as $lesson_id ){ | |
| 514 | - $html .= '<option value="' . esc_attr( absint( $lesson_id ) ) . '" ' . selected( $lesson_id, $selected_lesson_id, false ) . '>' . esc_html( get_the_title( $lesson_id ) ) . '</option>' . "\n"; | |
| 511 | +			$html .= '<option value="">'.__('Select a lesson', 'woothemes-sensei').'</option>'; | |
| 512 | +			if (count($lessons) > 0) { | |
| 513 | +				foreach ($lessons as $lesson_id) { | |
| 514 | + $html .= '<option value="'.esc_attr(absint($lesson_id)).'" '.selected($lesson_id, $selected_lesson_id, false).'>'.esc_html(get_the_title($lesson_id)).'</option>'."\n"; | |
| 515 | 515 | } // End For Loop | 
| 516 | 516 | } // End If Statement | 
| 517 | 517 | |
| @@ -532,10 +532,10 @@ discard block | ||
| 532 | 532 |      public function admin_process_grading_submission() { | 
| 533 | 533 | |
| 534 | 534 | // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry | 
| 535 | - if( ! isset( $_POST['sensei_manual_grade'] ) | |
| 536 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) | |
| 537 | - || ! isset( $_GET['quiz_id'] ) | |
| 538 | -            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { | |
| 535 | + if ( ! isset($_POST['sensei_manual_grade']) | |
| 536 | + || ! wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading') | |
| 537 | + || ! isset($_GET['quiz_id']) | |
| 538 | +            || $_GET['quiz_id'] != $_POST['sensei_manual_grade']) { | |
| 539 | 539 | |
| 540 | 540 | return false; //exit and do not grade | 
| 541 | 541 | |
| @@ -545,30 +545,30 @@ discard block | ||
| 545 | 545 | $user_id = $_GET['user']; | 
| 546 | 546 | |
| 547 | 547 | |
| 548 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); | |
| 549 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 548 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); | |
| 549 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); | |
| 550 | 550 | $quiz_grade = 0; | 
| 551 | 551 | $count = 0; | 
| 552 | 552 | $quiz_grade_total = $_POST['quiz_grade_total']; | 
| 553 | 553 | $all_question_grades = array(); | 
| 554 | 554 | $all_answers_feedback = array(); | 
| 555 | 555 | |
| 556 | -        foreach( $questions as $question ) { | |
| 556 | +        foreach ($questions as $question) { | |
| 557 | 557 | |
| 558 | 558 | ++$count; | 
| 559 | 559 | $question_id = $question->ID; | 
| 560 | 560 | |
| 561 | -            if( isset( $_POST[ 'question_' . $question_id ] ) ) { | |
| 561 | +            if (isset($_POST['question_'.$question_id])) { | |
| 562 | 562 | |
| 563 | 563 | $question_grade = 0; | 
| 564 | -                if( $_POST[ 'question_' . $question_id ] == 'right' ) { | |
| 564 | +                if ($_POST['question_'.$question_id] == 'right') { | |
| 565 | 565 | |
| 566 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; | |
| 566 | + $question_grade = $_POST['question_'.$question_id.'_grade']; | |
| 567 | 567 | |
| 568 | 568 | } | 
| 569 | 569 | |
| 570 | 570 | // add data to the array that will, after the loop, be stored on the lesson status | 
| 571 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 571 | + $all_question_grades[$question_id] = $question_grade; | |
| 572 | 572 | |
| 573 | 573 | // tally up the total quiz grade | 
| 574 | 574 | $quiz_grade += $question_grade; | 
| @@ -577,41 +577,41 @@ discard block | ||
| 577 | 577 | |
| 578 | 578 | // Question answer feedback / notes | 
| 579 | 579 | $question_feedback = ''; | 
| 580 | -            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ | |
| 580 | +            if (isset($_POST['questions_feedback'][$question_id])) { | |
| 581 | 581 | |
| 582 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); | |
| 582 | + $question_feedback = wp_unslash($_POST['questions_feedback'][$question_id]); | |
| 583 | 583 | |
| 584 | 584 | } | 
| 585 | - $all_answers_feedback[ $question_id ] = $question_feedback; | |
| 585 | + $all_answers_feedback[$question_id] = $question_feedback; | |
| 586 | 586 | |
| 587 | 587 | } // end for each $questions | 
| 588 | 588 | |
| 589 | 589 | //store all question grades on the lesson status | 
| 590 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); | |
| 590 | + Sensei()->quiz->set_user_grades($all_question_grades, $quiz_lesson_id, $user_id); | |
| 591 | 591 | |
| 592 | 592 | //store the feedback from grading | 
| 593 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); | |
| 593 | + Sensei()->quiz->save_user_answers_feedback($all_answers_feedback, $quiz_lesson_id, $user_id); | |
| 594 | 594 | |
| 595 | 595 | // $_POST['all_questions_graded'] is set when all questions have been graded | 
| 596 | 596 | // in the class sensei grading user quiz -> display() | 
| 597 | -        if( $_POST['all_questions_graded'] == 'yes' ) { | |
| 597 | +        if ($_POST['all_questions_graded'] == 'yes') { | |
| 598 | 598 | |
| 599 | 599 | // set the users total quiz grade | 
| 600 | -			if ( 0 < intval( $quiz_grade_total ) ) { | |
| 601 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | |
| 600 | +			if (0 < intval($quiz_grade_total)) { | |
| 601 | + $grade = abs(round((doubleval($quiz_grade) * 100) / ($quiz_grade_total), 2)); | |
| 602 | 602 | } | 
| 603 | 603 |  			else { | 
| 604 | 604 | $grade = 0; | 
| 605 | 605 | } | 
| 606 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | |
| 606 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id); | |
| 607 | 607 | |
| 608 | 608 | // Duplicating what Frontend->sensei_complete_quiz() does | 
| 609 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 610 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 609 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); | |
| 610 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); | |
| 611 | 611 | $lesson_metadata = array(); | 
| 612 | -            if ( $pass_required ) { | |
| 612 | +            if ($pass_required) { | |
| 613 | 613 | // Student has reached the pass mark and lesson is complete | 
| 614 | -                if ( $quiz_passmark <= $grade ) { | |
| 614 | +                if ($quiz_passmark <= $grade) { | |
| 615 | 615 | $lesson_status = 'passed'; | 
| 616 | 616 | } | 
| 617 | 617 |                  else { | 
| @@ -624,9 +624,9 @@ discard block | ||
| 624 | 624 | } | 
| 625 | 625 | $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above | 
| 626 | 626 | |
| 627 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); | |
| 627 | + Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata); | |
| 628 | 628 | |
| 629 | -            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) { | |
| 629 | +            if (in_array($lesson_status, array('passed', 'graded'))) { | |
| 630 | 630 | |
| 631 | 631 | /** | 
| 632 | 632 | * Summary. | 
| @@ -638,27 +638,27 @@ discard block | ||
| 638 | 638 | * @param int $user_id | 
| 639 | 639 | * @param int $quiz_lesson_id | 
| 640 | 640 | */ | 
| 641 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); | |
| 641 | +                do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id); | |
| 642 | 642 | |
| 643 | 643 | } // end if in_array | 
| 644 | 644 | |
| 645 | 645 | }// end if $_POST['all_que... | 
| 646 | 646 | |
| 647 | -        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { | |
| 647 | +        if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) { | |
| 648 | 648 | |
| 649 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 649 | +            $load_url = add_query_arg(array('message' => 'graded')); | |
| 650 | 650 | |
| 651 | -        } elseif ( isset( $_POST['_wp_http_referer'] ) ) { | |
| 651 | +        } elseif (isset($_POST['_wp_http_referer'])) { | |
| 652 | 652 | |
| 653 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); | |
| 653 | +            $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']); | |
| 654 | 654 | |
| 655 | 655 |          } else { | 
| 656 | 656 | |
| 657 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 657 | +            $load_url = add_query_arg(array('message' => 'graded')); | |
| 658 | 658 | |
| 659 | 659 | } | 
| 660 | 660 | |
| 661 | - wp_safe_redirect( esc_url_raw( $load_url ) ); | |
| 661 | + wp_safe_redirect(esc_url_raw($load_url)); | |
| 662 | 662 | exit; | 
| 663 | 663 | |
| 664 | 664 | } // end admin_process_grading_submission | 
| @@ -669,13 +669,13 @@ discard block | ||
| 669 | 669 | $lesson_data = array(); | 
| 670 | 670 | parse_str($data, $lesson_data); | 
| 671 | 671 | |
| 672 | - $lesson_id = intval( $lesson_data['lesson_id'] ); | |
| 673 | - $course_id = intval( $lesson_data['course_id'] ); | |
| 674 | - $grading_view = sanitize_text_field( $lesson_data['view'] ); | |
| 672 | + $lesson_id = intval($lesson_data['lesson_id']); | |
| 673 | + $course_id = intval($lesson_data['course_id']); | |
| 674 | + $grading_view = sanitize_text_field($lesson_data['view']); | |
| 675 | 675 | |
| 676 | 676 | $redirect_url = ''; | 
| 677 | -		if ( 0 < $lesson_id && 0 < $course_id ) { | |
| 678 | - $redirect_url = esc_url_raw( apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view ), admin_url( 'admin.php' ) ) ) ); | |
| 677 | +		if (0 < $lesson_id && 0 < $course_id) { | |
| 678 | +			$redirect_url = esc_url_raw(apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view), admin_url('admin.php')))); | |
| 679 | 679 | } // End If Statement | 
| 680 | 680 | |
| 681 | 681 | echo $redirect_url; | 
| @@ -683,11 +683,11 @@ discard block | ||
| 683 | 683 | } | 
| 684 | 684 | |
| 685 | 685 |  	public function add_grading_notices() { | 
| 686 | -		if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { | |
| 687 | -			if( 'graded' == $_GET['message'] ) { | |
| 686 | +		if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { | |
| 687 | +			if ('graded' == $_GET['message']) { | |
| 688 | 688 | $msg = array( | 
| 689 | 689 | 'updated', | 
| 690 | - __( 'Quiz Graded Successfully!', 'woothemes-sensei' ), | |
| 690 | +					__('Quiz Graded Successfully!', 'woothemes-sensei'), | |
| 691 | 691 | ); | 
| 692 | 692 | } | 
| 693 | 693 | ?> | 
| @@ -699,9 +699,9 @@ discard block | ||
| 699 | 699 | } | 
| 700 | 700 | |
| 701 | 701 |  	public function sensei_grading_notices() { | 
| 702 | -		if ( isset( $_GET['action'] ) && 'graded' == $_GET['action'] ) { | |
| 702 | +		if (isset($_GET['action']) && 'graded' == $_GET['action']) { | |
| 703 | 703 | echo '<div class="grading-notice updated">'; | 
| 704 | - echo '<p>' . __( 'Quiz Graded Successfully!', 'woothemes-sensei' ) . '</p>'; | |
| 704 | +				echo '<p>'.__('Quiz Graded Successfully!', 'woothemes-sensei').'</p>'; | |
| 705 | 705 | echo '</div>'; | 
| 706 | 706 | } // End If Statement | 
| 707 | 707 | } // End sensei_grading_notices() | 
| @@ -724,16 +724,16 @@ discard block | ||
| 724 | 724 | * | 
| 725 | 725 | * @return int $quiz_grade total sum of all question grades | 
| 726 | 726 | */ | 
| 727 | -    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { | |
| 727 | +    public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { | |
| 728 | 728 | |
| 729 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted | |
| 730 | -            || $quiz_grade_type != 'auto' ) { | |
| 729 | + if ( ! (intval($quiz_id) > 0) || ! $submitted | |
| 730 | +            || $quiz_grade_type != 'auto') { | |
| 731 | 731 | return false; // exit early | 
| 732 | 732 | } | 
| 733 | 733 | |
| 734 | 734 | |
| 735 | 735 | $user_id = get_current_user_id(); | 
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; | |
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); | |
| 737 | 737 | $quiz_autogradable = true; | 
| 738 | 738 | |
| 739 | 739 | /** | 
| @@ -747,23 +747,23 @@ discard block | ||
| 747 | 747 | * 'gap-fill'. | 
| 748 | 748 | * } | 
| 749 | 749 | */ | 
| 750 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); | |
| 750 | +        $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill')); | |
| 751 | 751 | |
| 752 | 752 | $grade_total = 0; | 
| 753 | 753 | $all_question_grades = array(); | 
| 754 | -        foreach( $submitted as $question_id => $answer ) { | |
| 754 | +        foreach ($submitted as $question_id => $answer) { | |
| 755 | 755 | |
| 756 | 756 | // check if the question is autogradable, either by type, or because the grade is 0 | 
| 757 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 758 | - $achievable_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 757 | + $question_type = Sensei()->question->get_question_type($question_id); | |
| 758 | + $achievable_grade = Sensei()->question->get_question_grade($question_id); | |
| 759 | 759 | // Question has a zero grade, so skip grading | 
| 760 | -			if ( 0 == $achievable_grade ) { | |
| 761 | - $all_question_grades[ $question_id ] = $achievable_grade; | |
| 760 | +			if (0 == $achievable_grade) { | |
| 761 | + $all_question_grades[$question_id] = $achievable_grade; | |
| 762 | 762 | } | 
| 763 | -            elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 763 | +            elseif (in_array($question_type, $autogradable_question_types)) { | |
| 764 | 764 | // Get user question grade | 
| 765 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | |
| 766 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 765 | + $question_grade = Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id); | |
| 766 | + $all_question_grades[$question_id] = $question_grade; | |
| 767 | 767 | $grade_total += $question_grade; | 
| 768 | 768 | |
| 769 | 769 |              } else { | 
| @@ -776,27 +776,27 @@ discard block | ||
| 776 | 776 | }// end for each question | 
| 777 | 777 | |
| 778 | 778 | // Only if the whole quiz was autogradable do we set a grade | 
| 779 | -        if ( $quiz_autogradable ) { | |
| 779 | +        if ($quiz_autogradable) { | |
| 780 | 780 | |
| 781 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); | |
| 781 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total($quiz_id); | |
| 782 | 782 | // Check for zero total from grades | 
| 783 | -			if ( 0 < $quiz_total ) { | |
| 784 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | |
| 783 | +			if (0 < $quiz_total) { | |
| 784 | + $grade = abs(round((doubleval($grade_total) * 100) / ($quiz_total), 2)); | |
| 785 | 785 | } | 
| 786 | 786 |  			else { | 
| 787 | 787 | $grade = 0; | 
| 788 | 788 | } | 
| 789 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | |
| 789 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type); | |
| 790 | 790 | |
| 791 | 791 |          } else { | 
| 792 | 792 | |
| 793 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); | |
| 793 | +            $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei')); | |
| 794 | 794 | |
| 795 | 795 | } | 
| 796 | 796 | |
| 797 | 797 | // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default | 
| 798 | 798 | // when doing manual grading. | 
| 799 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); | |
| 799 | + Sensei()->quiz-> set_user_grades($all_question_grades, $lesson_id, $user_id); | |
| 800 | 800 | |
| 801 | 801 | return $grade; | 
| 802 | 802 | |
| @@ -816,22 +816,22 @@ discard block | ||
| 816 | 816 | * | 
| 817 | 817 | * @return int $question_grade | 
| 818 | 818 | */ | 
| 819 | -    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { | |
| 819 | +    public static function grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { | |
| 820 | 820 | |
| 821 | -        if( intval( $user_id ) == 0 ) { | |
| 821 | +        if (intval($user_id) == 0) { | |
| 822 | 822 | |
| 823 | 823 | $user_id = get_current_user_id(); | 
| 824 | 824 | |
| 825 | 825 | } | 
| 826 | 826 | |
| 827 | -        if( ! ( intval( $question_id ) > 0 ) ) { | |
| 827 | +        if ( ! (intval($question_id) > 0)) { | |
| 828 | 828 | |
| 829 | 829 | return false; | 
| 830 | 830 | |
| 831 | 831 | } | 
| 832 | 832 | |
| 833 | 833 | |
| 834 | - Sensei()->question->get_question_type( $question_id ); | |
| 834 | + Sensei()->question->get_question_type($question_id); | |
| 835 | 835 | |
| 836 | 836 | /** | 
| 837 | 837 | * Applying a grade before the auto grading takes place. | 
| @@ -845,42 +845,42 @@ discard block | ||
| 845 | 845 | * @param string $question_type one of the Sensei question type. | 
| 846 | 846 | * @param string $answer user supplied question answer | 
| 847 | 847 | */ | 
| 848 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); | |
| 848 | +        $question_grade = apply_filters('sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer); | |
| 849 | 849 | |
| 850 | -        if ( false !== $question_grade ) { | |
| 850 | +        if (false !== $question_grade) { | |
| 851 | 851 | |
| 852 | 852 | return $question_grade; | 
| 853 | 853 | |
| 854 | 854 | } | 
| 855 | 855 | |
| 856 | 856 | // auto grading core | 
| 857 | -        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){ | |
| 857 | +        if (in_array($question_type, array('multiple-choice', 'boolean'))) { | |
| 858 | 858 | |
| 859 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); | |
| 859 | + $right_answer = (array) get_post_meta($question_id, '_question_right_answer', true); | |
| 860 | 860 | |
| 861 | -            if( 0 == get_magic_quotes_gpc() ) { | |
| 862 | - $answer = wp_unslash( $answer ); | |
| 861 | +            if (0 == get_magic_quotes_gpc()) { | |
| 862 | + $answer = wp_unslash($answer); | |
| 863 | 863 | } | 
| 864 | 864 | $answer = (array) $answer; | 
| 865 | -            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { | |
| 865 | +            if (is_array($right_answer) && count($right_answer) == count($answer)) { | |
| 866 | 866 | // Loop through all answers ensure none are 'missing' | 
| 867 | 867 | $all_correct = true; | 
| 868 | -                foreach ( $answer as $check_answer ) { | |
| 869 | -                    if ( !in_array( $check_answer, $right_answer ) ) { | |
| 868 | +                foreach ($answer as $check_answer) { | |
| 869 | +                    if ( ! in_array($check_answer, $right_answer)) { | |
| 870 | 870 | $all_correct = false; | 
| 871 | 871 | } | 
| 872 | 872 | } | 
| 873 | 873 | // If all correct then grade | 
| 874 | -                if ( $all_correct ) { | |
| 875 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 874 | +                if ($all_correct) { | |
| 875 | + $question_grade = Sensei()->question->get_question_grade($question_id); | |
| 876 | 876 | } | 
| 877 | 877 | } | 
| 878 | 878 | |
| 879 | -        } elseif( 'gap-fill' == $question_type ){ | |
| 879 | +        } elseif ('gap-fill' == $question_type) { | |
| 880 | 880 | |
| 881 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); | |
| 881 | + $question_grade = self::grade_gap_fill_question($question_id, $answer); | |
| 882 | 882 | |
| 883 | -        } else{ | |
| 883 | +        } else { | |
| 884 | 884 | |
| 885 | 885 | /** | 
| 886 | 886 | * Grading questions that are not auto gradable. | 
| @@ -893,7 +893,7 @@ discard block | ||
| 893 | 893 | * @param string $question_type one of the Sensei question type. | 
| 894 | 894 | * @param string $answer user supplied question answer | 
| 895 | 895 | */ | 
| 896 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); | |
| 896 | +            $question_grade = (int) apply_filters('sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer); | |
| 897 | 897 | |
| 898 | 898 | } // end if $question_type | 
| 899 | 899 | |
| @@ -909,13 +909,13 @@ discard block | ||
| 909 | 909 | * | 
| 910 | 910 | * @return bool | int false or the grade given to the user answer | 
| 911 | 911 | */ | 
| 912 | -    public static function grade_gap_fill_question( $question_id, $user_answer ){ | |
| 912 | +    public static function grade_gap_fill_question($question_id, $user_answer) { | |
| 913 | 913 | |
| 914 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 915 | - $gapfill_array = explode( '||', $right_answer ); | |
| 914 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); | |
| 915 | +        $gapfill_array = explode('||', $right_answer); | |
| 916 | 916 | |
| 917 | -        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 918 | - $user_answer = wp_unslash( $user_answer ); | |
| 917 | +        if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 918 | + $user_answer = wp_unslash($user_answer); | |
| 919 | 919 | } | 
| 920 | 920 | |
| 921 | 921 | /** | 
| @@ -928,53 +928,53 @@ discard block | ||
| 928 | 928 | * | 
| 929 | 929 | * @since 1.9.0 | 
| 930 | 930 | */ | 
| 931 | -        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); | |
| 931 | +        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false); | |
| 932 | 932 | |
| 933 | -        if( $do_case_sensitive_comparison ){ | |
| 933 | +        if ($do_case_sensitive_comparison) { | |
| 934 | 934 | |
| 935 | 935 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | 
| 936 | -            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { | |
| 936 | +            if (trim(($gapfill_array[1])) == trim($user_answer)) { | |
| 937 | 937 | |
| 938 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 938 | + return Sensei()->question->get_question_grade($question_id); | |
| 939 | 939 | |
| 940 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 940 | +            } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { | |
| 941 | 941 | |
| 942 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 942 | +                if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { | |
| 943 | 943 | |
| 944 | 944 | return Sensei()->question->get_question_grade($question_id); | 
| 945 | 945 | |
| 946 | -                }else{ | |
| 946 | +                } else { | |
| 947 | 947 | |
| 948 | 948 | return false; | 
| 949 | 949 | |
| 950 | 950 | } | 
| 951 | 951 | |
| 952 | -            }else{ | |
| 952 | +            } else { | |
| 953 | 953 | |
| 954 | 954 | return false; | 
| 955 | 955 | |
| 956 | 956 | } | 
| 957 | 957 | |
| 958 | -        }else{ | |
| 958 | +        } else { | |
| 959 | 959 | |
| 960 | 960 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | 
| 961 | -            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | |
| 961 | +            if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) { | |
| 962 | 962 | |
| 963 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 963 | + return Sensei()->question->get_question_grade($question_id); | |
| 964 | 964 | |
| 965 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 965 | +            } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { | |
| 966 | 966 | |
| 967 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 967 | +                if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { | |
| 968 | 968 | |
| 969 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 969 | + return Sensei()->question->get_question_grade($question_id); | |
| 970 | 970 | |
| 971 | -                }else{ | |
| 971 | +                } else { | |
| 972 | 972 | |
| 973 | 973 | return false; | 
| 974 | 974 | |
| 975 | 975 | } | 
| 976 | 976 | |
| 977 | -            }else{ | |
| 977 | +            } else { | |
| 978 | 978 | |
| 979 | 979 | return false; | 
| 980 | 980 | |
| @@ -991,4 +991,4 @@ discard block | ||
| 991 | 991 | * @ignore only for backward compatibility | 
| 992 | 992 | * @since 1.9.0 | 
| 993 | 993 | */ | 
| 994 | -class WooThemes_Sensei_Grading extends Sensei_Grading{} | |
| 994 | +class WooThemes_Sensei_Grading extends Sensei_Grading {} | |
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | /** | 
| 45 | 45 | * Constructor | 
| 46 | 46 | * @since 1.2.0 | 
| 47 | + * @param string $token | |
| 47 | 48 | * @return void | 
| 48 | 49 | */ | 
| 49 | 50 |  	public function __construct ( $token ) { | 
| @@ -162,8 +162,8 @@ | ||
| 162 | 162 | $sortable[$id] = $data; | 
| 163 | 163 | } | 
| 164 | 164 | |
| 165 | - $primary = $this->get_primary_column_name(); | |
| 166 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
| 165 | + $primary = $this->get_primary_column_name(); | |
| 166 | + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
| 167 | 167 | |
| 168 | 168 | return $this->_column_headers; | 
| 169 | 169 | } | 
| @@ -1,5 +1,8 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Generic List Table Class | 
| @@ -131,8 +134,9 @@ discard block | ||
| 131 | 134 | * @return array | 
| 132 | 135 | */ | 
| 133 | 136 |  	function get_column_info() { | 
| 134 | - if ( isset( $this->_column_headers ) ) | |
| 135 | - return $this->_column_headers; | |
| 137 | +		if ( isset( $this->_column_headers ) ) { | |
| 138 | + return $this->_column_headers; | |
| 139 | + } | |
| 136 | 140 | |
| 137 | 141 | $columns = $this->get_columns(); | 
| 138 | 142 | $hidden = get_hidden_columns( $this->screen ); | 
| @@ -152,12 +156,14 @@ discard block | ||
| 152 | 156 | |
| 153 | 157 | $sortable = array(); | 
| 154 | 158 |  		foreach ( $_sortable as $id => $data ) { | 
| 155 | - if ( empty( $data ) ) | |
| 156 | - continue; | |
| 159 | +			if ( empty( $data ) ) { | |
| 160 | + continue; | |
| 161 | + } | |
| 157 | 162 | |
| 158 | 163 | $data = (array) $data; | 
| 159 | - if ( !isset( $data[1] ) ) | |
| 160 | - $data[1] = false; | |
| 164 | +			if ( !isset( $data[1] ) ) { | |
| 165 | + $data[1] = false; | |
| 166 | + } | |
| 161 | 167 | |
| 162 | 168 | $sortable[$id] = $data; | 
| 163 | 169 | } | 
| @@ -188,8 +194,9 @@ discard block | ||
| 188 | 194 | $class = "class='$column_name column-$column_name'"; | 
| 189 | 195 | |
| 190 | 196 | $style = ''; | 
| 191 | - if ( in_array( $column_name, $hidden ) ) | |
| 192 | - $style = ' style="display:none;"'; | |
| 197 | +			if ( in_array( $column_name, $hidden ) ) { | |
| 198 | + $style = ' style="display:none;"'; | |
| 199 | + } | |
| 193 | 200 | |
| 194 | 201 | $attributes = "$class$style"; | 
| 195 | 202 | |
| @@ -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. | 
| @@ -44,17 +44,17 @@ discard block | ||
| 44 | 44 | * @since 1.2.0 | 
| 45 | 45 | * @return void | 
| 46 | 46 | */ | 
| 47 | -	public function __construct ( $token ) { | |
| 47 | +	public function __construct($token) { | |
| 48 | 48 | // Class Variables | 
| 49 | 49 | $this->token = $token; | 
| 50 | 50 | |
| 51 | - parent::__construct( array( | |
| 52 | - 'singular' => 'wp_list_table_' . $this->token, // Singular label | |
| 53 | - 'plural' => 'wp_list_table_' . $this->token . 's', // Plural label | |
| 51 | + parent::__construct(array( | |
| 52 | + 'singular' => 'wp_list_table_'.$this->token, // Singular label | |
| 53 | + 'plural' => 'wp_list_table_'.$this->token.'s', // Plural label | |
| 54 | 54 | 'ajax' => false // No Ajax for this table | 
| 55 | - ) ); | |
| 55 | + )); | |
| 56 | 56 | // Actions | 
| 57 | - add_action( 'sensei_before_list_table', array( $this, 'table_search_form' ), 5 ); | |
| 57 | +		add_action('sensei_before_list_table', array($this, 'table_search_form'), 5); | |
| 58 | 58 | } // End __construct() | 
| 59 | 59 | |
| 60 | 60 | /** | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | * @param array $columns Existing columns | 
| 63 | 63 | * @return array Modified columns | 
| 64 | 64 | */ | 
| 65 | -	public function remove_sortable_columns( $columns ) { | |
| 65 | +	public function remove_sortable_columns($columns) { | |
| 66 | 66 | return array(); | 
| 67 | 67 | } | 
| 68 | 68 | |
| @@ -71,14 +71,14 @@ discard block | ||
| 71 | 71 | * @since 1.2.0 | 
| 72 | 72 | * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list | 
| 73 | 73 | */ | 
| 74 | -	public function extra_tablenav( $which ) { | |
| 75 | -		if ( $which == "top" ){ | |
| 74 | +	public function extra_tablenav($which) { | |
| 75 | +		if ($which == "top") { | |
| 76 | 76 | //The code that goes before the table is here | 
| 77 | - do_action( 'sensei_before_list_table' ); | |
| 77 | +			do_action('sensei_before_list_table'); | |
| 78 | 78 | } // End If Statement | 
| 79 | -		if ( $which == "bottom" ){ | |
| 79 | +		if ($which == "bottom") { | |
| 80 | 80 | //The code that goes after the table is there | 
| 81 | - do_action( 'sensei_after_list_table' ); | |
| 81 | +			do_action('sensei_after_list_table'); | |
| 82 | 82 | } // End If Statement | 
| 83 | 83 | } // End extra_tablenav() | 
| 84 | 84 | |
| @@ -88,22 +88,22 @@ discard block | ||
| 88 | 88 | * @return void | 
| 89 | 89 | */ | 
| 90 | 90 |  	public function table_search_form() { | 
| 91 | -		if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) { | |
| 91 | +		if (empty($_REQUEST['s']) && ! $this->has_items()) { | |
| 92 | 92 | return; | 
| 93 | 93 | } | 
| 94 | 94 | ?><form method="get"> | 
| 95 | 95 | <?php | 
| 96 | -			if( isset( $_GET ) && count( $_GET ) > 0 ) { | |
| 97 | -				foreach( $_GET as $k => $v ) { | |
| 98 | -					if( 's' != $k ) { ?> | |
| 96 | +			if (isset($_GET) && count($_GET) > 0) { | |
| 97 | +				foreach ($_GET as $k => $v) { | |
| 98 | +					if ('s' != $k) { ?> | |
| 99 | 99 | |
| 100 | - <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" /> | |
| 100 | + <input type="hidden" name="<?php echo esc_attr($k); ?>" value="<?php echo esc_attr($v); ?>" /> | |
| 101 | 101 | |
| 102 | 102 | <?php } | 
| 103 | 103 | } | 
| 104 | 104 | } | 
| 105 | 105 | ?> | 
| 106 | - <?php $this->search_box( __( 'Search Users' ,'woothemes-sensei' ), 'search_id'); ?> | |
| 106 | +			<?php $this->search_box(__('Search Users', 'woothemes-sensei'), 'search_id'); ?> | |
| 107 | 107 | </form><?php | 
| 108 | 108 | } // End table_search_form() | 
| 109 | 109 | |
| @@ -131,11 +131,11 @@ discard block | ||
| 131 | 131 | * @return array | 
| 132 | 132 | */ | 
| 133 | 133 |  	function get_column_info() { | 
| 134 | - if ( isset( $this->_column_headers ) ) | |
| 134 | + if (isset($this->_column_headers)) | |
| 135 | 135 | return $this->_column_headers; | 
| 136 | 136 | |
| 137 | 137 | $columns = $this->get_columns(); | 
| 138 | - $hidden = get_hidden_columns( $this->screen ); | |
| 138 | + $hidden = get_hidden_columns($this->screen); | |
| 139 | 139 | |
| 140 | 140 | $sortable_columns = $this->get_sortable_columns(); | 
| 141 | 141 | /** | 
| @@ -148,22 +148,22 @@ discard block | ||
| 148 | 148 | * | 
| 149 | 149 | * @param array $sortable_columns An array of sortable columns. | 
| 150 | 150 | */ | 
| 151 | -		$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns ); | |
| 151 | +		$_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $sortable_columns); | |
| 152 | 152 | |
| 153 | 153 | $sortable = array(); | 
| 154 | -		foreach ( $_sortable as $id => $data ) { | |
| 155 | - if ( empty( $data ) ) | |
| 154 | +		foreach ($_sortable as $id => $data) { | |
| 155 | + if (empty($data)) | |
| 156 | 156 | continue; | 
| 157 | 157 | |
| 158 | 158 | $data = (array) $data; | 
| 159 | - if ( !isset( $data[1] ) ) | |
| 159 | + if ( ! isset($data[1])) | |
| 160 | 160 | $data[1] = false; | 
| 161 | 161 | |
| 162 | 162 | $sortable[$id] = $data; | 
| 163 | 163 | } | 
| 164 | 164 | |
| 165 | 165 | $primary = $this->get_primary_column_name(); | 
| 166 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
| 166 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); | |
| 167 | 167 | |
| 168 | 168 | return $this->_column_headers; | 
| 169 | 169 | } | 
| @@ -174,27 +174,27 @@ discard block | ||
| 174 | 174 | * @since 1.7.0 | 
| 175 | 175 | * @param object $item The current item | 
| 176 | 176 | */ | 
| 177 | -	function single_row( $item ) { | |
| 177 | +	function single_row($item) { | |
| 178 | 178 | static $row_class = ''; | 
| 179 | - $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); | |
| 179 | + $row_class = ($row_class == '' ? ' class="alternate"' : ''); | |
| 180 | 180 | |
| 181 | - echo '<tr' . $row_class . '>'; | |
| 181 | + echo '<tr'.$row_class.'>'; | |
| 182 | 182 | |
| 183 | - $column_data = $this->get_row_data( $item ); | |
| 183 | + $column_data = $this->get_row_data($item); | |
| 184 | 184 | |
| 185 | - list( $columns, $hidden ) = $this->get_column_info(); | |
| 185 | + list($columns, $hidden) = $this->get_column_info(); | |
| 186 | 186 | |
| 187 | -		foreach ( $columns as $column_name => $column_display_name ) { | |
| 187 | +		foreach ($columns as $column_name => $column_display_name) { | |
| 188 | 188 | $class = "class='$column_name column-$column_name'"; | 
| 189 | 189 | |
| 190 | 190 | $style = ''; | 
| 191 | - if ( in_array( $column_name, $hidden ) ) | |
| 191 | + if (in_array($column_name, $hidden)) | |
| 192 | 192 | $style = ' style="display:none;"'; | 
| 193 | 193 | |
| 194 | 194 | $attributes = "$class$style"; | 
| 195 | 195 | |
| 196 | 196 | echo "<td $attributes>"; | 
| 197 | -			if ( isset($column_data[$column_name]) ) { | |
| 197 | +			if (isset($column_data[$column_name])) { | |
| 198 | 198 | echo $column_data[$column_name]; | 
| 199 | 199 | } | 
| 200 | 200 | echo "</td>"; | 
| @@ -208,8 +208,8 @@ discard block | ||
| 208 | 208 | * @access public | 
| 209 | 209 | * @abstract | 
| 210 | 210 | */ | 
| 211 | -	protected function get_row_data( $item ) { | |
| 212 | - 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.' ); | |
| 211 | +	protected function get_row_data($item) { | |
| 212 | +		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.'); | |
| 213 | 213 | } | 
| 214 | 214 | |
| 215 | 215 | /** | 
| @@ -220,7 +220,7 @@ discard block | ||
| 220 | 220 | */ | 
| 221 | 221 |  	function no_items() { | 
| 222 | 222 | |
| 223 | - _e( 'No items found.', 'woothemes-sensei' ); | |
| 223 | +		 _e('No items found.', 'woothemes-sensei'); | |
| 224 | 224 | |
| 225 | 225 | } // End no_items() | 
| 226 | 226 | |
| @@ -238,9 +238,9 @@ discard block | ||
| 238 | 238 | * @since 1.2.0 | 
| 239 | 239 | * @return void | 
| 240 | 240 | */ | 
| 241 | -	public function bulk_actions( $which = '' ) { | |
| 241 | +	public function bulk_actions($which = '') { | |
| 242 | 242 | // This will be output Above the table headers on the left | 
| 243 | - echo apply_filters( 'sensei_list_bulk_actions', '' ); | |
| 243 | +		echo apply_filters('sensei_list_bulk_actions', ''); | |
| 244 | 244 | } // End bulk_actions() | 
| 245 | 245 | |
| 246 | 246 | } // End Class | 
| @@ -299,7 +299,7 @@ | ||
| 299 | 299 | * @param integer $sender_id ID of sender | 
| 300 | 300 | * @param integer $receiver_id ID of receiver | 
| 301 | 301 | * @param string $message Message content | 
| 302 | - * @param string $post_id ID of post related to message | |
| 302 | + * @param integer $post_id ID of post related to message | |
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure | 
| 304 | 304 | */ | 
| 305 | 305 |      private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | 
| @@ -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 Messages Class | 
| @@ -21,61 +21,61 @@ discard block | ||
| 21 | 21 | * Constructor. | 
| 22 | 22 | * @since 1.6.0 | 
| 23 | 23 | */ | 
| 24 | -	public function __construct () { | |
| 24 | +	public function __construct() { | |
| 25 | 25 | $this->post_type = 'sensei_message'; | 
| 26 | - $this->meta_fields = array( 'sender', 'receiver' ); | |
| 26 | +		$this->meta_fields = array('sender', 'receiver'); | |
| 27 | 27 | |
| 28 | 28 | // Add Messages page to admin menu | 
| 29 | - add_action( 'admin_menu', array( $this, 'add_menu_item' ), 40 ); | |
| 30 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10, 2 ); | |
| 31 | - add_action( 'admin_menu', array( $this, 'remove_meta_box' ) ); | |
| 29 | +		add_action('admin_menu', array($this, 'add_menu_item'), 40); | |
| 30 | +		add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 2); | |
| 31 | +		add_action('admin_menu', array($this, 'remove_meta_box')); | |
| 32 | 32 | |
| 33 | 33 | // Save new private message | 
| 34 | - add_action( 'init', array( $this, 'save_new_message' ), 1 ); | |
| 34 | +		add_action('init', array($this, 'save_new_message'), 1); | |
| 35 | 35 | |
| 36 | 36 | // Monitor when new reply is posted | 
| 37 | - add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); | |
| 37 | +		add_action('comment_post', array($this, 'message_reply_received'), 10, 1); | |
| 38 | 38 | |
| 39 | 39 | // Block WordPress from sending comment update emails for the messages post type | 
| 40 | -        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 40 | +        add_filter('comment_notification_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); | |
| 41 | 41 | |
| 42 | 42 | // Block WordPress from sending comment moderator emails on the sensei messages post types | 
| 43 | -        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 43 | +        add_filter('comment_moderation_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); | |
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts | 
| 46 | - add_action( 'save_post', array( $this, 'save_message' ) ); | |
| 46 | +		add_action('save_post', array($this, 'save_message')); | |
| 47 | 47 | |
| 48 | 48 | // Add message links to courses & lessons | 
| 49 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); | |
| 49 | +		add_action('sensei_single_course_content_inside_before', array($this, 'send_message_link'), 35); | |
| 50 | 50 | |
| 51 | 51 | // add message link to lesson | 
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); | |
| 52 | +        add_action('sensei_single_lesson_content_inside_before', array($this, 'send_message_link'), 30, 2); | |
| 53 | 53 | |
| 54 | 54 | // add message link to lesson | 
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); | |
| 55 | +        add_action('sensei_single_quiz_questions_before', array($this, 'send_message_link'), 10, 2); | |
| 56 | 56 | |
| 57 | 57 | // Hide messages and replies from users who do not have access | 
| 58 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); | |
| 59 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); | |
| 60 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); | |
| 61 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); | |
| 62 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); | |
| 63 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); | |
| 64 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); | |
| 58 | +        add_action('template_redirect', array($this, 'message_login'), 10, 1); | |
| 59 | +        add_action('pre_get_posts', array($this, 'message_list'), 10, 1); | |
| 60 | +        add_filter('the_title', array($this, 'message_title'), 10, 2); | |
| 61 | +        add_filter('the_content', array($this, 'message_content'), 10, 1); | |
| 62 | +        add_filter('comments_array', array($this, 'message_replies'), 100, 1); | |
| 63 | +        add_filter('get_comments_number', array($this, 'message_reply_count'), 100, 2); | |
| 64 | +        add_filter('comments_open', array($this, 'message_replies_open'), 100, 2); | |
| 65 | 65 | } // End __construct() | 
| 66 | 66 | |
| 67 | 67 |  	public function add_menu_item() { | 
| 68 | 68 | |
| 69 | -		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { | |
| 70 | - add_submenu_page( 'sensei', __( 'Messages', 'woothemes-sensei'), __( 'Messages', 'woothemes-sensei') , 'edit_courses', 'edit.php?post_type=sensei_message' ); | |
| 69 | +		if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { | |
| 70 | +			add_submenu_page('sensei', __('Messages', 'woothemes-sensei'), __('Messages', 'woothemes-sensei'), 'edit_courses', 'edit.php?post_type=sensei_message'); | |
| 71 | 71 | } | 
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | -	public function add_meta_box( $post_type, $post ) { | |
| 74 | +	public function add_meta_box($post_type, $post) { | |
| 75 | 75 | |
| 76 | - if( ! $post_type == $this->post_type ) return; | |
| 76 | + if ( ! $post_type == $this->post_type) return; | |
| 77 | 77 | |
| 78 | - add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); | |
| 78 | +		add_meta_box($this->post_type.'-data', __('Message Information', 'woothemes-sensei'), array($this, 'meta_box_content'), $this->post_type, 'normal', 'default'); | |
| 79 | 79 | |
| 80 | 80 | } | 
| 81 | 81 | |
| @@ -85,25 +85,25 @@ discard block | ||
| 85 | 85 | $settings = array( | 
| 86 | 86 | array( | 
| 87 | 87 | 'id' => 'sender', | 
| 88 | - 'label' => __( 'Message sent by:', 'woothemes-sensei' ), | |
| 89 | - 'description' => __( 'The username of the learner who sent this message.', 'woothemes-sensei' ), | |
| 88 | +				'label'			=> __('Message sent by:', 'woothemes-sensei'), | |
| 89 | +				'description'	=> __('The username of the learner who sent this message.', 'woothemes-sensei'), | |
| 90 | 90 | 'type' => 'text', | 
| 91 | 91 | 'default' => '', | 
| 92 | - 'placeholder' => __( 'Learner username', 'woothemes-sensei' ), | |
| 92 | +				'placeholder'	=> __('Learner username', 'woothemes-sensei'), | |
| 93 | 93 | ), | 
| 94 | 94 | array( | 
| 95 | 95 | 'id' => 'receiver', | 
| 96 | - 'label' => __( 'Message received by:', 'woothemes-sensei' ), | |
| 97 | - 'description' => __( 'The username of the teacher who received this message.', 'woothemes-sensei' ), | |
| 96 | +				'label'			=> __('Message received by:', 'woothemes-sensei'), | |
| 97 | +				'description'	=> __('The username of the teacher who received this message.', 'woothemes-sensei'), | |
| 98 | 98 | 'type' => 'text', | 
| 99 | 99 | 'default' => '', | 
| 100 | - 'placeholder' => __( 'Teacher username', 'woothemes-sensei' ), | |
| 100 | +				'placeholder'	=> __('Teacher username', 'woothemes-sensei'), | |
| 101 | 101 | ), | 
| 102 | 102 | ); | 
| 103 | 103 | |
| 104 | - $message_posttype = get_post_meta( $post->ID, '_posttype', true ); | |
| 104 | + $message_posttype = get_post_meta($post->ID, '_posttype', true); | |
| 105 | 105 | |
| 106 | -		if( isset( $message_posttype ) && $message_posttype ) { | |
| 106 | +		if (isset($message_posttype) && $message_posttype) { | |
| 107 | 107 | |
| 108 | 108 | $args = array( | 
| 109 | 109 | 'post_type' => $message_posttype, | 
| @@ -113,58 +113,58 @@ discard block | ||
| 113 | 113 | 'post_status' => 'publish', | 
| 114 | 114 | ); | 
| 115 | 115 | |
| 116 | - $posts = get_posts( $args ); | |
| 116 | + $posts = get_posts($args); | |
| 117 | 117 | |
| 118 | - $post_options[0] = sprintf( __( 'Select %1$s', 'woothemes-sensei' ), $message_posttype ); | |
| 119 | -			foreach( $posts as $post_item ) { | |
| 120 | - $post_options[ $post_item->ID ] = $post_item->post_title; | |
| 118 | +			$post_options[0] = sprintf(__('Select %1$s', 'woothemes-sensei'), $message_posttype); | |
| 119 | +			foreach ($posts as $post_item) { | |
| 120 | + $post_options[$post_item->ID] = $post_item->post_title; | |
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | $settings[] = array( | 
| 124 | 124 | 'id' => 'post', | 
| 125 | - 'label' => sprintf( __( 'Message from %1$s:', 'woothemes-sensei' ), $message_posttype ), | |
| 126 | - 'description' => sprintf( __( 'The %1$s to which this message relates.', 'woothemes-sensei' ), $message_posttype ), | |
| 125 | +				'label'			=> sprintf(__('Message from %1$s:', 'woothemes-sensei'), $message_posttype), | |
| 126 | +				'description'	=> sprintf(__('The %1$s to which this message relates.', 'woothemes-sensei'), $message_posttype), | |
| 127 | 127 | 'type' => 'select', | 
| 128 | 128 | 'default' => 0, | 
| 129 | 129 | 'options' => $post_options, | 
| 130 | 130 | ); | 
| 131 | 131 | } | 
| 132 | 132 | |
| 133 | - $html = Sensei()->admin->render_settings( $settings, $post->ID, 'message-info' ); | |
| 133 | + $html = Sensei()->admin->render_settings($settings, $post->ID, 'message-info'); | |
| 134 | 134 | |
| 135 | 135 | echo $html; | 
| 136 | 136 | } | 
| 137 | 137 | |
| 138 | -	public function save_message( $post_id = 0 ) { | |
| 138 | +	public function save_message($post_id = 0) { | |
| 139 | 139 | global $post; | 
| 140 | 140 | |
| 141 | - if( $this->post_type != get_post_type() ) return; | |
| 141 | + if ($this->post_type != get_post_type()) return; | |
| 142 | 142 | |
| 143 | -		if( isset( $_POST['sender'] ) && $_POST['sender'] ) { | |
| 144 | - update_post_meta( $post_id, '_sender', $_POST['sender'] ); | |
| 143 | +		if (isset($_POST['sender']) && $_POST['sender']) { | |
| 144 | + update_post_meta($post_id, '_sender', $_POST['sender']); | |
| 145 | 145 | } | 
| 146 | 146 | |
| 147 | -		if( isset( $_POST['receiver'] ) && $_POST['receiver'] ) { | |
| 148 | - update_post_meta( $post_id, '_receiver', $_POST['receiver'] ); | |
| 147 | +		if (isset($_POST['receiver']) && $_POST['receiver']) { | |
| 148 | + update_post_meta($post_id, '_receiver', $_POST['receiver']); | |
| 149 | 149 | } | 
| 150 | 150 | |
| 151 | -		if( isset( $_POST['post'] ) && $_POST['post'] ) { | |
| 152 | - update_post_meta( $post_id, '_post', $_POST['post'] ); | |
| 151 | +		if (isset($_POST['post']) && $_POST['post']) { | |
| 152 | + update_post_meta($post_id, '_post', $_POST['post']); | |
| 153 | 153 | } | 
| 154 | 154 | |
| 155 | - remove_action( 'save_post', array( $this, 'save_message' ) ); | |
| 155 | +		remove_action('save_post', array($this, 'save_message')); | |
| 156 | 156 | |
| 157 | - wp_update_post( array( 'ID' => $post_id, 'comment_status' => 'open' ) ); | |
| 157 | +		wp_update_post(array('ID' => $post_id, 'comment_status' => 'open')); | |
| 158 | 158 | |
| 159 | - add_action( 'save_post', array( $this, 'save_message' ) ); | |
| 159 | +		add_action('save_post', array($this, 'save_message')); | |
| 160 | 160 | } | 
| 161 | 161 | |
| 162 | -	public function send_message_link( $post_id = 0, $user_id = 0 ) { | |
| 162 | +	public function send_message_link($post_id = 0, $user_id = 0) { | |
| 163 | 163 | global $post; | 
| 164 | 164 | |
| 165 | 165 | // only show the link for the allowed post types: | 
| 166 | 166 |          $allowed_post_types = array('lesson', 'course', 'quiz'); | 
| 167 | -		if ( ! in_array( get_post_type() , $allowed_post_types ) ) { | |
| 167 | +		if ( ! in_array(get_post_type(), $allowed_post_types)) { | |
| 168 | 168 | |
| 169 | 169 | return; | 
| 170 | 170 | |
| @@ -172,28 +172,28 @@ discard block | ||
| 172 | 172 | |
| 173 | 173 | $html = ''; | 
| 174 | 174 | |
| 175 | -		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { | |
| 175 | +		if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { | |
| 176 | 176 | |
| 177 | - if( ! is_user_logged_in() ) return; | |
| 177 | + if ( ! is_user_logged_in()) return; | |
| 178 | 178 | |
| 179 | -			if( isset( $_GET['contact'] ) ) { | |
| 180 | - $html .= $this->teacher_contact_form( $post ); | |
| 179 | +			if (isset($_GET['contact'])) { | |
| 180 | + $html .= $this->teacher_contact_form($post); | |
| 181 | 181 |  			} else { | 
| 182 | - $href = add_query_arg( array( 'contact' => $post->post_type ) ); | |
| 183 | - | |
| 184 | -				if( 'lesson' == $post->post_type ) { | |
| 185 | - $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); | |
| 186 | -				} elseif( 'course' == $post->post_type ) { | |
| 187 | - $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); | |
| 188 | -				}else{ | |
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | |
| 182 | +				$href = add_query_arg(array('contact' => $post->post_type)); | |
| 183 | + | |
| 184 | +				if ('lesson' == $post->post_type) { | |
| 185 | +					$contact_button_text = __('Contact Lesson Teacher', 'woothemes-sensei'); | |
| 186 | +				} elseif ('course' == $post->post_type) { | |
| 187 | +					$contact_button_text = __('Contact Course Teacher', 'woothemes-sensei'); | |
| 188 | +				} else { | |
| 189 | +                    $contact_button_text = __('Contact Teacher', 'woothemes-sensei'); | |
| 190 | 190 | } | 
| 191 | 191 | |
| 192 | - $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; | |
| 192 | + $html .= '<p><a class="button send-message-button" href="'.esc_url($href).'#private_message">'.$contact_button_text.'</a></p>'; | |
| 193 | 193 | } | 
| 194 | 194 | |
| 195 | -			if( isset( $this->message_notice ) && isset( $this->message_notice['type'] ) && isset( $this->message_notice['notice'] ) ) { | |
| 196 | - $html .= '<div class="sensei-message ' . $this->message_notice['type'] . '">' . $this->message_notice['notice'] . '</div>'; | |
| 195 | +			if (isset($this->message_notice) && isset($this->message_notice['type']) && isset($this->message_notice['notice'])) { | |
| 196 | + $html .= '<div class="sensei-message '.$this->message_notice['type'].'">'.$this->message_notice['notice'].'</div>'; | |
| 197 | 197 | } | 
| 198 | 198 | |
| 199 | 199 | } | 
| @@ -201,40 +201,40 @@ discard block | ||
| 201 | 201 | echo $html; | 
| 202 | 202 | } | 
| 203 | 203 | |
| 204 | -	public function teacher_contact_form( $post ) { | |
| 204 | +	public function teacher_contact_form($post) { | |
| 205 | 205 | |
| 206 | - if( ! is_user_logged_in() ) return; | |
| 206 | + if ( ! is_user_logged_in()) return; | |
| 207 | 207 | |
| 208 | 208 | global $current_user; | 
| 209 | 209 | wp_get_current_user(); | 
| 210 | 210 | |
| 211 | 211 | $html = ''; | 
| 212 | 212 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; | |
| 213 | + if ( ! isset($post->ID)) return $html; | |
| 214 | 214 | |
| 215 | 215 | //confirm private message | 
| 216 | 216 | $confirmation = ''; | 
| 217 | -        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { | |
| 217 | +        if (isset($_GET['send']) && 'complete' == $_GET['send']) { | |
| 218 | 218 | |
| 219 | 219 |              $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); | 
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; | |
| 220 | + $confirmation = '<div class="sensei-message tick">'.$confirmation_message.'</div>'; | |
| 221 | 221 | |
| 222 | 222 | } | 
| 223 | 223 | |
| 224 | - $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; | |
| 224 | +		$html .= '<h3 id="private_message">'.__('Send Private Message', 'woothemes-sensei').'</h3>'; | |
| 225 | 225 | $html .= '<p>'; | 
| 226 | - $html .= $confirmation; | |
| 226 | + $html .= $confirmation; | |
| 227 | 227 | $html .= '</p>'; | 
| 228 | 228 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; | 
| 229 | 229 | $html .= '<p class="form-row form-row-wide">'; | 
| 230 | - $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; | |
| 230 | +				$html .= '<textarea name="contact_message" placeholder="'.__('Enter your private message.', 'woothemes-sensei').'"></textarea>'; | |
| 231 | 231 | $html .= '</p>'; | 
| 232 | 232 | $html .= '<p class="form-row">'; | 
| 233 | - $html .= '<input type="hidden" name="post_id" value="' . $post->ID . '" />'; | |
| 234 | - $html .= '<input type="hidden" name="sender_id" value="' . $current_user->ID . '" />'; | |
| 235 | - $html .= '<input type="hidden" name="receiver_id" value="' . $post->post_author . '" />'; | |
| 236 | - $html .= wp_nonce_field( 'message_teacher', 'sensei_message_teacher_nonce', true, false ); | |
| 237 | - $html .= '<input type="submit" class="send_message" value="' . __( 'Send Message', 'woothemes-sensei' ) . '" />'; | |
| 233 | + $html .= '<input type="hidden" name="post_id" value="'.$post->ID.'" />'; | |
| 234 | + $html .= '<input type="hidden" name="sender_id" value="'.$current_user->ID.'" />'; | |
| 235 | + $html .= '<input type="hidden" name="receiver_id" value="'.$post->post_author.'" />'; | |
| 236 | +				$html .= wp_nonce_field('message_teacher', 'sensei_message_teacher_nonce', true, false); | |
| 237 | +				$html .= '<input type="submit" class="send_message" value="'.__('Send Message', 'woothemes-sensei').'" />'; | |
| 238 | 238 | $html .= '</p>'; | 
| 239 | 239 | $html .= '<div class="fix"></div>'; | 
| 240 | 240 | $html .= '</form>'; | 
| @@ -244,30 +244,30 @@ discard block | ||
| 244 | 244 | |
| 245 | 245 |  	public function save_new_message() { | 
| 246 | 246 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; | |
| 247 | + if ( ! isset($_POST['sensei_message_teacher_nonce'])) return; | |
| 248 | 248 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; | |
| 249 | + if ( ! wp_verify_nonce($_POST['sensei_message_teacher_nonce'], 'message_teacher')) return; | |
| 250 | 250 | |
| 251 | - $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); | |
| 251 | + $message_id = $this->save_new_message_post($_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id']); | |
| 252 | 252 | |
| 253 | 253 | } | 
| 254 | 254 | |
| 255 | -	public function message_reply_received( $comment_id = 0 ) { | |
| 255 | +	public function message_reply_received($comment_id = 0) { | |
| 256 | 256 | |
| 257 | 257 | // Get comment object | 
| 258 | - $comment = get_comment( $comment_id ); | |
| 258 | + $comment = get_comment($comment_id); | |
| 259 | 259 | |
| 260 | - if( is_null( $comment ) ) return; | |
| 260 | + if (is_null($comment)) return; | |
| 261 | 261 | |
| 262 | 262 | // Get message post object | 
| 263 | - $message = get_post( $comment->comment_post_ID ); | |
| 263 | + $message = get_post($comment->comment_post_ID); | |
| 264 | 264 | |
| 265 | - if( $message->post_type != $this->post_type ) return; | |
| 265 | + if ($message->post_type != $this->post_type) return; | |
| 266 | 266 | |
| 267 | 267 | // Force comment to be approved | 
| 268 | - wp_set_comment_status( $comment_id, 'approve' ); | |
| 268 | + wp_set_comment_status($comment_id, 'approve'); | |
| 269 | 269 | |
| 270 | - do_action( 'sensei_private_message_reply', $comment, $message ); | |
| 270 | +		do_action('sensei_private_message_reply', $comment, $message); | |
| 271 | 271 | } | 
| 272 | 272 | |
| 273 | 273 | /** | 
| @@ -280,11 +280,11 @@ discard block | ||
| 280 | 280 | * @param int $comment_id | 
| 281 | 281 | * @return array; | 
| 282 | 282 | */ | 
| 283 | -    public function stop_wp_comment_emails( $emails , $comment_id ){ | |
| 283 | +    public function stop_wp_comment_emails($emails, $comment_id) { | |
| 284 | 284 | |
| 285 | - $comment = get_comment( $comment_id ); | |
| 286 | - if( isset( $comment->comment_post_ID ) && | |
| 287 | -            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){ | |
| 285 | + $comment = get_comment($comment_id); | |
| 286 | + if (isset($comment->comment_post_ID) && | |
| 287 | +            'sensei_message' == get_post_type($comment->comment_post_ID)) { | |
| 288 | 288 | |
| 289 | 289 | // empty the emails array to ensure no emails are sent for this comment | 
| 290 | 290 | $emails = array(); | 
| @@ -302,45 +302,45 @@ discard block | ||
| 302 | 302 | * @param string $post_id ID of post related to message | 
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure | 
| 304 | 304 | */ | 
| 305 | -    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | |
| 305 | +    private function save_new_message_post($sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0) { | |
| 306 | 306 | |
| 307 | 307 | $message_id = false; | 
| 308 | 308 | |
| 309 | -    	if( $sender_id && $receiver_id && $message && $post_id ) { | |
| 309 | +    	if ($sender_id && $receiver_id && $message && $post_id) { | |
| 310 | 310 | |
| 311 | - $title = wp_trim_words( $message, 8, '...' ); | |
| 311 | + $title = wp_trim_words($message, 8, '...'); | |
| 312 | 312 | |
| 313 | 313 | // Set up post data for message | 
| 314 | 314 | $message_data = array( | 
| 315 | 315 | 'post_type' => $this->post_type, | 
| 316 | - 'post_title' => esc_html( $title ), | |
| 317 | - 'post_content' => esc_html( $message ), | |
| 316 | + 'post_title' => esc_html($title), | |
| 317 | + 'post_content' => esc_html($message), | |
| 318 | 318 | 'post_status' => 'publish', | 
| 319 | 319 | 'ping_status' => 'closed', | 
| 320 | 320 | 'comment_status' => 'open', | 
| 321 | 321 | 'post_excerpt' => '', | 
| 322 | - 'post_author' => intval( $sender_id ) | |
| 322 | + 'post_author' => intval($sender_id) | |
| 323 | 323 | ); | 
| 324 | 324 | |
| 325 | 325 | // Insert post | 
| 326 | - $message_id = wp_insert_post( $message_data ); | |
| 326 | + $message_id = wp_insert_post($message_data); | |
| 327 | 327 | |
| 328 | -	        if( ! is_wp_error( $message_id ) ) { | |
| 328 | +	        if ( ! is_wp_error($message_id)) { | |
| 329 | 329 | |
| 330 | 330 | // Add sender to message meta | 
| 331 | - $sender = get_userdata( $sender_id ); | |
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); | |
| 331 | + $sender = get_userdata($sender_id); | |
| 332 | + add_post_meta($message_id, '_sender', $sender->user_login); | |
| 333 | 333 | |
| 334 | 334 | // Add receiver to message meta | 
| 335 | - $receiver = get_userdata( $receiver_id ); | |
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); | |
| 335 | + $receiver = get_userdata($receiver_id); | |
| 336 | + add_post_meta($message_id, '_receiver', $receiver->user_login); | |
| 337 | 337 | |
| 338 | 338 | // Add lesson/course ID to message meta | 
| 339 | - $post = get_post( $post_id ); | |
| 340 | - add_post_meta( $message_id, '_posttype', $post->post_type ); | |
| 341 | - add_post_meta( $message_id, '_post', $post->ID ); | |
| 339 | + $post = get_post($post_id); | |
| 340 | + add_post_meta($message_id, '_posttype', $post->post_type); | |
| 341 | + add_post_meta($message_id, '_post', $post->ID); | |
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); | |
| 343 | +		        do_action('sensei_new_private_message', $message_id); | |
| 344 | 344 | |
| 345 | 345 |  		    } else { | 
| 346 | 346 | |
| @@ -358,22 +358,22 @@ discard block | ||
| 358 | 358 | * @param integer $user_id ID of user | 
| 359 | 359 | * @return boolean True if user has access to this message | 
| 360 | 360 | */ | 
| 361 | -	private function view_message( $message_id, $user_id = 0) { | |
| 361 | +	private function view_message($message_id, $user_id = 0) { | |
| 362 | 362 | |
| 363 | - if( ! is_user_logged_in() ) return false; | |
| 363 | + if ( ! is_user_logged_in()) return false; | |
| 364 | 364 | |
| 365 | -		if( $user_id == 0 ) { | |
| 365 | +		if ($user_id == 0) { | |
| 366 | 366 | global $current_user; | 
| 367 | 367 | wp_get_current_user(); | 
| 368 | 368 | $user_login = $current_user->user_login; | 
| 369 | 369 | } | 
| 370 | 370 | |
| 371 | 371 | // Get allowed users | 
| 372 | - $receiver = get_post_meta( $message_id, '_receiver', true ); | |
| 373 | - $sender = get_post_meta( $message_id, '_sender', true ); | |
| 372 | + $receiver = get_post_meta($message_id, '_receiver', true); | |
| 373 | + $sender = get_post_meta($message_id, '_sender', true); | |
| 374 | 374 | |
| 375 | 375 | // Check if user is allowed to view the message | 
| 376 | -		if( in_array( $user_login, array( $receiver, $sender ) ) ) { | |
| 376 | +		if (in_array($user_login, array($receiver, $sender))) { | |
| 377 | 377 | return true; | 
| 378 | 378 | } | 
| 379 | 379 | |
| @@ -400,27 +400,27 @@ discard block | ||
| 400 | 400 | * @return void | 
| 401 | 401 | */ | 
| 402 | 402 | |
| 403 | -    public function message_login () { | |
| 403 | +    public function message_login() { | |
| 404 | 404 | |
| 405 | -        if ( is_user_logged_in() ) { | |
| 405 | +        if (is_user_logged_in()) { | |
| 406 | 406 | |
| 407 | 407 | return; | 
| 408 | 408 | } | 
| 409 | 409 | |
| 410 | 410 | $settings = Sensei()->settings->get_settings(); | 
| 411 | - if( isset( $settings[ 'my_course_page' ] ) | |
| 412 | -            && 0 < intval( $settings[ 'my_course_page' ] ) ){ | |
| 411 | + if (isset($settings['my_course_page']) | |
| 412 | +            && 0 < intval($settings['my_course_page'])) { | |
| 413 | 413 | |
| 414 | - $my_courses_page_id = $settings[ 'my_course_page' ]; | |
| 414 | + $my_courses_page_id = $settings['my_course_page']; | |
| 415 | 415 | |
| 416 | 416 | $my_courses_url = get_permalink($my_courses_page_id); | 
| 417 | 417 | |
| 418 | 418 | } | 
| 419 | 419 | |
| 420 | - if ( is_single() && is_singular( $this->post_type ) | |
| 421 | -            || is_post_type_archive( $this->post_type ) ) { | |
| 420 | + if (is_single() && is_singular($this->post_type) | |
| 421 | +            || is_post_type_archive($this->post_type)) { | |
| 422 | 422 | |
| 423 | -            if ( isset($my_courses_url) ) { | |
| 423 | +            if (isset($my_courses_url)) { | |
| 424 | 424 | |
| 425 | 425 | wp_redirect($my_courses_url, 303); | 
| 426 | 426 | exit; | 
| @@ -439,12 +439,12 @@ discard block | ||
| 439 | 439 | * @param array $query Original query | 
| 440 | 440 | * @return void | 
| 441 | 441 | */ | 
| 442 | -	public function message_list( $query ) { | |
| 442 | +	public function message_list($query) { | |
| 443 | 443 | global $current_user; | 
| 444 | 444 | |
| 445 | - if( is_admin() ) return; | |
| 445 | + if (is_admin()) return; | |
| 446 | 446 | |
| 447 | -		if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { | |
| 447 | +		if (is_post_type_archive($this->post_type) && $query->is_main_query()) { | |
| 448 | 448 | wp_get_current_user(); | 
| 449 | 449 | $username = $current_user->user_login; | 
| 450 | 450 | |
| @@ -462,7 +462,7 @@ discard block | ||
| 462 | 462 | 'compare' => '=' | 
| 463 | 463 | ); | 
| 464 | 464 | |
| 465 | - $query->set( 'meta_query', $meta_query ); | |
| 465 | +			$query->set('meta_query', $meta_query); | |
| 466 | 466 | |
| 467 | 467 | return; | 
| 468 | 468 | } | 
| @@ -474,11 +474,11 @@ discard block | ||
| 474 | 474 | * @param integer $post_id ID of post | 
| 475 | 475 | * @return string Modified string if user does not have access to this message | 
| 476 | 476 | */ | 
| 477 | -	public function message_title( $title = '', $post_id = null ) { | |
| 477 | +	public function message_title($title = '', $post_id = null) { | |
| 478 | 478 | |
| 479 | -		if( is_single() && is_singular( $this->post_type ) && in_the_loop() && get_post_type( $post_id ) == $this->post_type ) { | |
| 480 | -			if( ! is_user_logged_in() || ! $this->view_message( $post_id ) ) { | |
| 481 | - $title = __( 'You are not allowed to view this message.', 'woothemes-sensei' ); | |
| 479 | +		if (is_single() && is_singular($this->post_type) && in_the_loop() && get_post_type($post_id) == $this->post_type) { | |
| 480 | +			if ( ! is_user_logged_in() || ! $this->view_message($post_id)) { | |
| 481 | +				$title = __('You are not allowed to view this message.', 'woothemes-sensei'); | |
| 482 | 482 | } | 
| 483 | 483 | } | 
| 484 | 484 | |
| @@ -490,12 +490,12 @@ discard block | ||
| 490 | 490 | * @param string $content Original message content | 
| 491 | 491 | * @return string Empty string if user does not have access to this message | 
| 492 | 492 | */ | 
| 493 | -	public function message_content( $content ) { | |
| 493 | +	public function message_content($content) { | |
| 494 | 494 | global $post; | 
| 495 | 495 | |
| 496 | -		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { | |
| 497 | -			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { | |
| 498 | - $content = __( 'Please log in to view your messages.', 'woothemes-sensei' ); | |
| 496 | +		if (is_single() && is_singular($this->post_type) && in_the_loop()) { | |
| 497 | +			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { | |
| 498 | +				$content = __('Please log in to view your messages.', 'woothemes-sensei'); | |
| 499 | 499 | } | 
| 500 | 500 | } | 
| 501 | 501 | |
| @@ -507,11 +507,11 @@ discard block | ||
| 507 | 507 | * @param array $comments Array of replies | 
| 508 | 508 | * @return array Empty array if user does not have access to this message | 
| 509 | 509 | */ | 
| 510 | -	public function message_replies( $comments ) { | |
| 510 | +	public function message_replies($comments) { | |
| 511 | 511 | global $post; | 
| 512 | 512 | |
| 513 | -		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { | |
| 514 | -			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { | |
| 513 | +		if (is_single() && is_singular($this->post_type) && in_the_loop()) { | |
| 514 | +			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { | |
| 515 | 515 | $comments = array(); | 
| 516 | 516 | } | 
| 517 | 517 | } | 
| @@ -525,11 +525,11 @@ discard block | ||
| 525 | 525 | * @param integer $post_id ID of post | 
| 526 | 526 | * @return integer 0 if user does not have access to this message | 
| 527 | 527 | */ | 
| 528 | -	public function message_reply_count( $count, $post_id ) { | |
| 528 | +	public function message_reply_count($count, $post_id) { | |
| 529 | 529 | global $post; | 
| 530 | 530 | |
| 531 | -		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { | |
| 532 | -			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { | |
| 531 | +		if (is_single() && is_singular($this->post_type) && in_the_loop()) { | |
| 532 | +			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { | |
| 533 | 533 | $count = 0; | 
| 534 | 534 | } | 
| 535 | 535 | } | 
| @@ -543,11 +543,11 @@ discard block | ||
| 543 | 543 | * @param integer $post_id ID of post | 
| 544 | 544 | * @return boolean False if user does not have access to this message | 
| 545 | 545 | */ | 
| 546 | -	public function message_replies_open( $open, $post_id ) { | |
| 546 | +	public function message_replies_open($open, $post_id) { | |
| 547 | 547 | global $post; | 
| 548 | 548 | |
| 549 | -		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { | |
| 550 | -			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { | |
| 549 | +		if (is_single() && is_singular($this->post_type) && in_the_loop()) { | |
| 550 | +			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { | |
| 551 | 551 | $open = false; | 
| 552 | 552 | } | 
| 553 | 553 | } | 
| @@ -560,17 +560,17 @@ discard block | ||
| 560 | 560 | * | 
| 561 | 561 | * @since 1.9.0 | 
| 562 | 562 | */ | 
| 563 | -    public static function the_message_sent_by_title(){ | |
| 563 | +    public static function the_message_sent_by_title() { | |
| 564 | 564 | |
| 565 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); | |
| 566 | -        if( $sender_username ) { | |
| 565 | + $sender_username = get_post_meta(get_the_ID(), '_sender', true); | |
| 566 | +        if ($sender_username) { | |
| 567 | 567 | |
| 568 | - $sender = get_user_by( 'login', $sender_username ); ?> | |
| 568 | +            $sender = get_user_by('login', $sender_username); ?> | |
| 569 | 569 | |
| 570 | 570 | <p class="message-meta"> | 
| 571 | 571 | <small> | 
| 572 | 572 | <em> | 
| 573 | - <?php printf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); ?> | |
| 573 | +                        <?php printf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); ?> | |
| 574 | 574 | </em> | 
| 575 | 575 | </small> | 
| 576 | 576 | </p> | 
| @@ -589,11 +589,11 @@ discard block | ||
| 589 | 589 | |
| 590 | 590 | global $post; | 
| 591 | 591 | |
| 592 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); | |
| 593 | -        if( $content_post_id ) { | |
| 594 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); | |
| 592 | + $content_post_id = get_post_meta($post->ID, '_post', true); | |
| 593 | +        if ($content_post_id) { | |
| 594 | +            $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), '<a href="'.get_permalink($content_post_id).'">'.get_the_title($content_post_id).'</a>'); | |
| 595 | 595 |          } else { | 
| 596 | - $title = get_the_title( $post->ID ); | |
| 596 | + $title = get_the_title($post->ID); | |
| 597 | 597 | } | 
| 598 | 598 | |
| 599 | 599 | ?> | 
| @@ -610,7 +610,7 @@ discard block | ||
| 610 | 610 | * @param string $template | 
| 611 | 611 | * @param string $post_type | 
| 612 | 612 | */ | 
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); | |
| 613 | +                echo apply_filters('sensei_single_title', $title, $post->post_type); | |
| 614 | 614 | ?> | 
| 615 | 615 | |
| 616 | 616 | </h1> | 
| @@ -629,18 +629,18 @@ discard block | ||
| 629 | 629 | * | 
| 630 | 630 | * @return string | 
| 631 | 631 | */ | 
| 632 | -    public static function the_archive_header( ){ | |
| 632 | +    public static function the_archive_header( ) { | |
| 633 | 633 | |
| 634 | 634 | $html = ''; | 
| 635 | 635 | $html .= '<header class="archive-header"><h1>'; | 
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); | |
| 636 | +        $html .= __('My Messages', 'woothemes-sensei'); | |
| 637 | 637 | $html .= '</h1></header>'; | 
| 638 | 638 | |
| 639 | 639 | /** | 
| 640 | 640 | * Filter the sensei messages archive title. | 
| 641 | 641 | * @since 1.0.0 | 
| 642 | 642 | */ | 
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); | |
| 643 | +        echo apply_filters('sensei_message_archive_title', $html); | |
| 644 | 644 | |
| 645 | 645 | } // get_archive_header() | 
| 646 | 646 | |
| @@ -650,23 +650,23 @@ discard block | ||
| 650 | 650 | * @since 1.9.0 | 
| 651 | 651 | * @param $post_id | 
| 652 | 652 | */ | 
| 653 | -    public static function the_message_title( $message_post_id ){ | |
| 653 | +    public static function the_message_title($message_post_id) { | |
| 654 | 654 | |
| 655 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); | |
| 655 | + $content_post_id = get_post_meta($message_post_id, '_post', true); | |
| 656 | 656 | |
| 657 | -        if( $content_post_id ) { | |
| 657 | +        if ($content_post_id) { | |
| 658 | 658 | |
| 659 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); | |
| 659 | +            $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), get_the_title($content_post_id)); | |
| 660 | 660 | |
| 661 | 661 |          } else { | 
| 662 | 662 | |
| 663 | - $title = get_the_title( $message_post_id ); | |
| 663 | + $title = get_the_title($message_post_id); | |
| 664 | 664 | |
| 665 | 665 | } | 
| 666 | 666 | |
| 667 | 667 | ?> | 
| 668 | 668 | <h2> | 
| 669 | - <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> | |
| 669 | + <a href="<?php esc_url(get_permalink($message_post_id)); ?>"> | |
| 670 | 670 | <?php echo $title; ?> | 
| 671 | 671 | </a> | 
| 672 | 672 | |
| @@ -680,13 +680,13 @@ discard block | ||
| 680 | 680 | * | 
| 681 | 681 | * @param $message_post_id | 
| 682 | 682 | */ | 
| 683 | -    public  static function the_message_sender( $message_post_id ){ | |
| 683 | +    public  static function the_message_sender($message_post_id) { | |
| 684 | 684 | |
| 685 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); | |
| 686 | - $sender = get_user_by( 'login', $sender_username ); | |
| 685 | + $sender_username = get_post_meta($message_post_id, '_sender', true); | |
| 686 | +        $sender = get_user_by('login', $sender_username); | |
| 687 | 687 | |
| 688 | -        if( $sender_username && $sender instanceof WP_User ) { | |
| 689 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); | |
| 688 | +        if ($sender_username && $sender instanceof WP_User) { | |
| 689 | +            $sender_display_name = sprintf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); | |
| 690 | 690 | ?> | 
| 691 | 691 | <p class="message-meta"> | 
| 692 | 692 | <small> | 
| @@ -704,13 +704,13 @@ discard block | ||
| 704 | 704 | * | 
| 705 | 705 | * @since 1.9.0 | 
| 706 | 706 | */ | 
| 707 | -    public static function the_my_messages_link(){ | |
| 708 | -        if( ! Sensei()->settings->get('messages_disable')  ) { | |
| 707 | +    public static function the_my_messages_link() { | |
| 708 | +        if ( ! Sensei()->settings->get('messages_disable')) { | |
| 709 | 709 | ?> | 
| 710 | 710 | <p class="my-messages-link-container"> | 
| 711 | - <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" | |
| 712 | - title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> | |
| 713 | - <?php _e( 'My Messages', 'woothemes-sensei' ); ?> | |
| 711 | +                <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>" | |
| 712 | +                   title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>"> | |
| 713 | +                    <?php _e('My Messages', 'woothemes-sensei'); ?> | |
| 714 | 714 | </a> | 
| 715 | 715 | </p> | 
| 716 | 716 | <?php | 
| @@ -724,4 +724,4 @@ discard block | ||
| 724 | 724 | * for backward compatibility | 
| 725 | 725 | * @since 1.9.0 | 
| 726 | 726 | */ | 
| 727 | -class WooThemes_Sensei_Messages extends Sensei_Messages{} | |
| 727 | +class WooThemes_Sensei_Messages extends Sensei_Messages {} | |
| @@ -1,5 +1,8 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Messages Class | 
| @@ -73,7 +76,9 @@ discard block | ||
| 73 | 76 | |
| 74 | 77 |  	public function add_meta_box( $post_type, $post ) { | 
| 75 | 78 | |
| 76 | - if( ! $post_type == $this->post_type ) return; | |
| 79 | +		if( ! $post_type == $this->post_type ) { | |
| 80 | + return; | |
| 81 | + } | |
| 77 | 82 | |
| 78 | 83 | add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); | 
| 79 | 84 | |
| @@ -138,7 +143,9 @@ discard block | ||
| 138 | 143 |  	public function save_message( $post_id = 0 ) { | 
| 139 | 144 | global $post; | 
| 140 | 145 | |
| 141 | - if( $this->post_type != get_post_type() ) return; | |
| 146 | +		if( $this->post_type != get_post_type() ) { | |
| 147 | + return; | |
| 148 | + } | |
| 142 | 149 | |
| 143 | 150 |  		if( isset( $_POST['sender'] ) && $_POST['sender'] ) { | 
| 144 | 151 | update_post_meta( $post_id, '_sender', $_POST['sender'] ); | 
| @@ -174,7 +181,9 @@ discard block | ||
| 174 | 181 | |
| 175 | 182 |  		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { | 
| 176 | 183 | |
| 177 | - if( ! is_user_logged_in() ) return; | |
| 184 | +			if( ! is_user_logged_in() ) { | |
| 185 | + return; | |
| 186 | + } | |
| 178 | 187 | |
| 179 | 188 |  			if( isset( $_GET['contact'] ) ) { | 
| 180 | 189 | $html .= $this->teacher_contact_form( $post ); | 
| @@ -185,7 +194,7 @@ discard block | ||
| 185 | 194 | $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); | 
| 186 | 195 |  				} elseif( 'course' == $post->post_type ) { | 
| 187 | 196 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); | 
| 188 | -				}else{ | |
| 197 | +				} else{ | |
| 189 | 198 | $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | 
| 190 | 199 | } | 
| 191 | 200 | |
| @@ -203,14 +212,18 @@ discard block | ||
| 203 | 212 | |
| 204 | 213 |  	public function teacher_contact_form( $post ) { | 
| 205 | 214 | |
| 206 | - if( ! is_user_logged_in() ) return; | |
| 215 | +		if( ! is_user_logged_in() ) { | |
| 216 | + return; | |
| 217 | + } | |
| 207 | 218 | |
| 208 | 219 | global $current_user; | 
| 209 | 220 | wp_get_current_user(); | 
| 210 | 221 | |
| 211 | 222 | $html = ''; | 
| 212 | 223 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; | |
| 224 | +		if( ! isset( $post->ID ) ) { | |
| 225 | + return $html; | |
| 226 | + } | |
| 214 | 227 | |
| 215 | 228 | //confirm private message | 
| 216 | 229 | $confirmation = ''; | 
| @@ -244,9 +257,13 @@ discard block | ||
| 244 | 257 | |
| 245 | 258 |  	public function save_new_message() { | 
| 246 | 259 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; | |
| 260 | +		if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) { | |
| 261 | + return; | |
| 262 | + } | |
| 248 | 263 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; | |
| 264 | +		if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) { | |
| 265 | + return; | |
| 266 | + } | |
| 250 | 267 | |
| 251 | 268 | $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); | 
| 252 | 269 | |
| @@ -257,12 +274,16 @@ discard block | ||
| 257 | 274 | // Get comment object | 
| 258 | 275 | $comment = get_comment( $comment_id ); | 
| 259 | 276 | |
| 260 | - if( is_null( $comment ) ) return; | |
| 277 | +		if( is_null( $comment ) ) { | |
| 278 | + return; | |
| 279 | + } | |
| 261 | 280 | |
| 262 | 281 | // Get message post object | 
| 263 | 282 | $message = get_post( $comment->comment_post_ID ); | 
| 264 | 283 | |
| 265 | - if( $message->post_type != $this->post_type ) return; | |
| 284 | +		if( $message->post_type != $this->post_type ) { | |
| 285 | + return; | |
| 286 | + } | |
| 266 | 287 | |
| 267 | 288 | // Force comment to be approved | 
| 268 | 289 | wp_set_comment_status( $comment_id, 'approve' ); | 
| @@ -360,7 +381,9 @@ discard block | ||
| 360 | 381 | */ | 
| 361 | 382 |  	private function view_message( $message_id, $user_id = 0) { | 
| 362 | 383 | |
| 363 | - if( ! is_user_logged_in() ) return false; | |
| 384 | +		if( ! is_user_logged_in() ) { | |
| 385 | + return false; | |
| 386 | + } | |
| 364 | 387 | |
| 365 | 388 |  		if( $user_id == 0 ) { | 
| 366 | 389 | global $current_user; | 
| @@ -424,9 +447,7 @@ discard block | ||
| 424 | 447 | |
| 425 | 448 | wp_redirect($my_courses_url, 303); | 
| 426 | 449 | exit; | 
| 427 | - } | |
| 428 | - | |
| 429 | -            else { | |
| 450 | +            } else { | |
| 430 | 451 | |
| 431 | 452 |                  wp_redirect(home_url('/wp-login.php'), 303); | 
| 432 | 453 | exit; | 
| @@ -442,7 +463,9 @@ discard block | ||
| 442 | 463 |  	public function message_list( $query ) { | 
| 443 | 464 | global $current_user; | 
| 444 | 465 | |
| 445 | - if( is_admin() ) return; | |
| 466 | +		if( is_admin() ) { | |
| 467 | + return; | |
| 468 | + } | |
| 446 | 469 | |
| 447 | 470 |  		if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { | 
| 448 | 471 | wp_get_current_user(); | 
| @@ -21,7 +21,7 @@ discard block | ||
| 21 | 21 | * @since 1.6.0 | 
| 22 | 22 | */ | 
| 23 | 23 |  	public function __construct () { | 
| 24 | - $this->token = 'messages'; | |
| 24 | + $this->token = 'messages'; | |
| 25 | 25 | $this->post_type = 'sensei_message'; | 
| 26 | 26 | $this->meta_fields = array( 'sender', 'receiver' ); | 
| 27 | 27 | |
| @@ -36,11 +36,11 @@ discard block | ||
| 36 | 36 | // Monitor when new reply is posted | 
| 37 | 37 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); | 
| 38 | 38 | |
| 39 | - // Block WordPress from sending comment update emails for the messages post type | |
| 40 | -        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 39 | + // Block WordPress from sending comment update emails for the messages post type | |
| 40 | +		add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 41 | 41 | |
| 42 | - // Block WordPress from sending comment moderator emails on the sensei messages post types | |
| 43 | -        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 42 | + // Block WordPress from sending comment moderator emails on the sensei messages post types | |
| 43 | +		add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts | 
| 46 | 46 | add_action( 'save_post', array( $this, 'save_message' ) ); | 
| @@ -48,20 +48,20 @@ discard block | ||
| 48 | 48 | // Add message links to courses & lessons | 
| 49 | 49 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); | 
| 50 | 50 | |
| 51 | - // add message link to lesson | |
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); | |
| 51 | + // add message link to lesson | |
| 52 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); | |
| 53 | 53 | |
| 54 | - // add message link to lesson | |
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); | |
| 54 | + // add message link to lesson | |
| 55 | + add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); | |
| 56 | 56 | |
| 57 | 57 | // Hide messages and replies from users who do not have access | 
| 58 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); | |
| 59 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); | |
| 60 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); | |
| 61 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); | |
| 62 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); | |
| 63 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); | |
| 64 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); | |
| 58 | + add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); | |
| 59 | + add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); | |
| 60 | + add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); | |
| 61 | + add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); | |
| 62 | + add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); | |
| 63 | + add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); | |
| 64 | + add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); | |
| 65 | 65 | } // End __construct() | 
| 66 | 66 | |
| 67 | 67 |  	public function add_menu_item() { | 
| @@ -162,8 +162,8 @@ discard block | ||
| 162 | 162 |  	public function send_message_link( $post_id = 0, $user_id = 0 ) { | 
| 163 | 163 | global $post; | 
| 164 | 164 | |
| 165 | - // only show the link for the allowed post types: | |
| 166 | -        $allowed_post_types = array('lesson', 'course', 'quiz'); | |
| 165 | + // only show the link for the allowed post types: | |
| 166 | +		$allowed_post_types = array('lesson', 'course', 'quiz'); | |
| 167 | 167 |  		if ( ! in_array( get_post_type() , $allowed_post_types ) ) { | 
| 168 | 168 | |
| 169 | 169 | return; | 
| @@ -186,8 +186,8 @@ discard block | ||
| 186 | 186 |  				} elseif( 'course' == $post->post_type ) { | 
| 187 | 187 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); | 
| 188 | 188 |  				}else{ | 
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | |
| 190 | - } | |
| 189 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | |
| 190 | + } | |
| 191 | 191 | |
| 192 | 192 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; | 
| 193 | 193 | } | 
| @@ -212,19 +212,19 @@ discard block | ||
| 212 | 212 | |
| 213 | 213 | if( ! isset( $post->ID ) ) return $html; | 
| 214 | 214 | |
| 215 | - //confirm private message | |
| 216 | - $confirmation = ''; | |
| 217 | -        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { | |
| 215 | + //confirm private message | |
| 216 | + $confirmation = ''; | |
| 217 | +		if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { | |
| 218 | 218 | |
| 219 | -            $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); | |
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; | |
| 219 | +			$confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); | |
| 220 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; | |
| 221 | 221 | |
| 222 | - } | |
| 222 | + } | |
| 223 | 223 | |
| 224 | 224 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; | 
| 225 | - $html .= '<p>'; | |
| 226 | - $html .= $confirmation; | |
| 227 | - $html .= '</p>'; | |
| 225 | + $html .= '<p>'; | |
| 226 | + $html .= $confirmation; | |
| 227 | + $html .= '</p>'; | |
| 228 | 228 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; | 
| 229 | 229 | $html .= '<p class="form-row form-row-wide">'; | 
| 230 | 230 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; | 
| @@ -255,7 +255,7 @@ discard block | ||
| 255 | 255 |  	public function message_reply_received( $comment_id = 0 ) { | 
| 256 | 256 | |
| 257 | 257 | // Get comment object | 
| 258 | - $comment = get_comment( $comment_id ); | |
| 258 | + $comment = get_comment( $comment_id ); | |
| 259 | 259 | |
| 260 | 260 | if( is_null( $comment ) ) return; | 
| 261 | 261 | |
| @@ -270,87 +270,87 @@ discard block | ||
| 270 | 270 | do_action( 'sensei_private_message_reply', $comment, $message ); | 
| 271 | 271 | } | 
| 272 | 272 | |
| 273 | - /** | |
| 274 | - * This function stops WordPress from sending the default comment update emails. | |
| 275 | - * | |
| 276 | - * This function is hooked into comment_notification_recipients. It will simply return | |
| 277 | - * an empty array if the current passed in comment is on a message post type. | |
| 278 | - * | |
| 279 | - * @param array $emails | |
| 280 | - * @param int $comment_id | |
| 281 | - * @return array; | |
| 282 | - */ | |
| 283 | -    public function stop_wp_comment_emails( $emails , $comment_id ){ | |
| 273 | + /** | |
| 274 | + * This function stops WordPress from sending the default comment update emails. | |
| 275 | + * | |
| 276 | + * This function is hooked into comment_notification_recipients. It will simply return | |
| 277 | + * an empty array if the current passed in comment is on a message post type. | |
| 278 | + * | |
| 279 | + * @param array $emails | |
| 280 | + * @param int $comment_id | |
| 281 | + * @return array; | |
| 282 | + */ | |
| 283 | +	public function stop_wp_comment_emails( $emails , $comment_id ){ | |
| 284 | 284 | |
| 285 | - $comment = get_comment( $comment_id ); | |
| 286 | - if( isset( $comment->comment_post_ID ) && | |
| 287 | -            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){ | |
| 285 | + $comment = get_comment( $comment_id ); | |
| 286 | + if( isset( $comment->comment_post_ID ) && | |
| 287 | +			'sensei_message' == get_post_type( $comment->comment_post_ID )  ){ | |
| 288 | 288 | |
| 289 | - // empty the emails array to ensure no emails are sent for this comment | |
| 290 | - $emails = array(); | |
| 289 | + // empty the emails array to ensure no emails are sent for this comment | |
| 290 | + $emails = array(); | |
| 291 | 291 | |
| 292 | - } | |
| 293 | - return $emails; | |
| 292 | + } | |
| 293 | + return $emails; | |
| 294 | 294 | |
| 295 | - }// end stop_wp_comment_emails | |
| 295 | + }// end stop_wp_comment_emails | |
| 296 | 296 | |
| 297 | 297 | /** | 
| 298 | - * Save new message post | |
| 299 | - * @param integer $sender_id ID of sender | |
| 300 | - * @param integer $receiver_id ID of receiver | |
| 301 | - * @param string $message Message content | |
| 302 | - * @param string $post_id ID of post related to message | |
| 303 | - * @return mixed Message ID on success, boolean false on failure | |
| 304 | - */ | |
| 305 | -    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | |
| 298 | + * Save new message post | |
| 299 | + * @param integer $sender_id ID of sender | |
| 300 | + * @param integer $receiver_id ID of receiver | |
| 301 | + * @param string $message Message content | |
| 302 | + * @param string $post_id ID of post related to message | |
| 303 | + * @return mixed Message ID on success, boolean false on failure | |
| 304 | + */ | |
| 305 | +	private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | |
| 306 | 306 | |
| 307 | - $message_id = false; | |
| 307 | + $message_id = false; | |
| 308 | 308 | |
| 309 | -    	if( $sender_id && $receiver_id && $message && $post_id ) { | |
| 309 | +		if( $sender_id && $receiver_id && $message && $post_id ) { | |
| 310 | 310 | |
| 311 | - $title = wp_trim_words( $message, 8, '...' ); | |
| 311 | + $title = wp_trim_words( $message, 8, '...' ); | |
| 312 | 312 | |
| 313 | - // Set up post data for message | |
| 314 | - $message_data = array( | |
| 315 | - 'post_type' => $this->post_type, | |
| 316 | - 'post_title' => esc_html( $title ), | |
| 317 | - 'post_content' => esc_html( $message ), | |
| 318 | - 'post_status' => 'publish', | |
| 319 | - 'ping_status' => 'closed', | |
| 320 | - 'comment_status' => 'open', | |
| 321 | - 'post_excerpt' => '', | |
| 322 | - 'post_author' => intval( $sender_id ) | |
| 323 | - ); | |
| 313 | + // Set up post data for message | |
| 314 | + $message_data = array( | |
| 315 | + 'post_type' => $this->post_type, | |
| 316 | + 'post_title' => esc_html( $title ), | |
| 317 | + 'post_content' => esc_html( $message ), | |
| 318 | + 'post_status' => 'publish', | |
| 319 | + 'ping_status' => 'closed', | |
| 320 | + 'comment_status' => 'open', | |
| 321 | + 'post_excerpt' => '', | |
| 322 | + 'post_author' => intval( $sender_id ) | |
| 323 | + ); | |
| 324 | 324 | |
| 325 | - // Insert post | |
| 326 | - $message_id = wp_insert_post( $message_data ); | |
| 325 | + // Insert post | |
| 326 | + $message_id = wp_insert_post( $message_data ); | |
| 327 | 327 | |
| 328 | -	        if( ! is_wp_error( $message_id ) ) { | |
| 328 | +			if( ! is_wp_error( $message_id ) ) { | |
| 329 | 329 | |
| 330 | - // Add sender to message meta | |
| 331 | - $sender = get_userdata( $sender_id ); | |
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); | |
| 330 | + // Add sender to message meta | |
| 331 | + $sender = get_userdata( $sender_id ); | |
| 332 | + add_post_meta( $message_id, '_sender', $sender->user_login ); | |
| 333 | 333 | |
| 334 | - // Add receiver to message meta | |
| 335 | - $receiver = get_userdata( $receiver_id ); | |
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); | |
| 334 | + // Add receiver to message meta | |
| 335 | + $receiver = get_userdata( $receiver_id ); | |
| 336 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); | |
| 337 | 337 | |
| 338 | - // Add lesson/course ID to message meta | |
| 339 | - $post = get_post( $post_id ); | |
| 340 | - add_post_meta( $message_id, '_posttype', $post->post_type ); | |
| 341 | - add_post_meta( $message_id, '_post', $post->ID ); | |
| 338 | + // Add lesson/course ID to message meta | |
| 339 | + $post = get_post( $post_id ); | |
| 340 | + add_post_meta( $message_id, '_posttype', $post->post_type ); | |
| 341 | + add_post_meta( $message_id, '_post', $post->ID ); | |
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); | |
| 343 | + do_action( 'sensei_new_private_message', $message_id ); | |
| 344 | 344 | |
| 345 | -		    } else { | |
| 345 | +			} else { | |
| 346 | 346 | |
| 347 | - $message_id = false; | |
| 347 | + $message_id = false; | |
| 348 | 348 | |
| 349 | - } | |
| 350 | - } | |
| 349 | + } | |
| 350 | + } | |
| 351 | 351 | |
| 352 | - return $message_id; | |
| 353 | - } | |
| 352 | + return $message_id; | |
| 353 | + } | |
| 354 | 354 | |
| 355 | 355 | /** | 
| 356 | 356 | * Check if user has access to view this message | 
| @@ -389,56 +389,56 @@ discard block | ||
| 389 | 389 |  		remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); | 
| 390 | 390 | } | 
| 391 | 391 | |
| 392 | - /** | |
| 393 | - * Function message_login() | |
| 394 | - * | |
| 395 | - * Only show /messages/* to logged in users, and | |
| 396 | - * redirect logged out users to wp-login.php | |
| 397 | - * | |
| 398 | - * @since 1.9.0 | |
| 399 | - * @param none | |
| 400 | - * @return void | |
| 401 | - */ | |
| 392 | + /** | |
| 393 | + * Function message_login() | |
| 394 | + * | |
| 395 | + * Only show /messages/* to logged in users, and | |
| 396 | + * redirect logged out users to wp-login.php | |
| 397 | + * | |
| 398 | + * @since 1.9.0 | |
| 399 | + * @param none | |
| 400 | + * @return void | |
| 401 | + */ | |
| 402 | 402 | |
| 403 | -    public function message_login () { | |
| 403 | +	public function message_login () { | |
| 404 | 404 | |
| 405 | -        if ( is_user_logged_in() ) { | |
| 405 | +		if ( is_user_logged_in() ) { | |
| 406 | 406 | |
| 407 | - return; | |
| 408 | - } | |
| 407 | + return; | |
| 408 | + } | |
| 409 | 409 | |
| 410 | - $settings = Sensei()->settings->get_settings(); | |
| 411 | - if( isset( $settings[ 'my_course_page' ] ) | |
| 412 | -            && 0 < intval( $settings[ 'my_course_page' ] ) ){ | |
| 410 | + $settings = Sensei()->settings->get_settings(); | |
| 411 | + if( isset( $settings[ 'my_course_page' ] ) | |
| 412 | +			&& 0 < intval( $settings[ 'my_course_page' ] ) ){ | |
| 413 | 413 | |
| 414 | - $my_courses_page_id = $settings[ 'my_course_page' ]; | |
| 414 | + $my_courses_page_id = $settings[ 'my_course_page' ]; | |
| 415 | 415 | |
| 416 | - $my_courses_url = get_permalink($my_courses_page_id); | |
| 416 | + $my_courses_url = get_permalink($my_courses_page_id); | |
| 417 | 417 | |
| 418 | - } | |
| 418 | + } | |
| 419 | 419 | |
| 420 | - if ( is_single() && is_singular( $this->post_type ) | |
| 421 | -            || is_post_type_archive( $this->post_type ) ) { | |
| 420 | + if ( is_single() && is_singular( $this->post_type ) | |
| 421 | +			|| is_post_type_archive( $this->post_type ) ) { | |
| 422 | 422 | |
| 423 | -            if ( isset($my_courses_url) ) { | |
| 423 | +			if ( isset($my_courses_url) ) { | |
| 424 | 424 | |
| 425 | - wp_redirect($my_courses_url, 303); | |
| 426 | - exit; | |
| 427 | - } | |
| 425 | + wp_redirect($my_courses_url, 303); | |
| 426 | + exit; | |
| 427 | + } | |
| 428 | 428 | |
| 429 | -            else { | |
| 429 | +			else { | |
| 430 | 430 | |
| 431 | -                wp_redirect(home_url('/wp-login.php'), 303); | |
| 432 | - exit; | |
| 433 | - } | |
| 431 | +				wp_redirect(home_url('/wp-login.php'), 303); | |
| 432 | + exit; | |
| 433 | + } | |
| 434 | 434 | |
| 435 | - } | |
| 436 | - } | |
| 435 | + } | |
| 436 | + } | |
| 437 | 437 | /** | 
| 438 | - * Only show allowed messages in messages archive | |
| 439 | - * @param WP_Query $query Original query | |
| 440 | - * @return void | |
| 441 | - */ | |
| 438 | + * Only show allowed messages in messages archive | |
| 439 | + * @param WP_Query $query Original query | |
| 440 | + * @return void | |
| 441 | + */ | |
| 442 | 442 |  	public function message_list( $query ) { | 
| 443 | 443 | global $current_user; | 
| 444 | 444 | |
| @@ -555,17 +555,17 @@ discard block | ||
| 555 | 555 | return $open; | 
| 556 | 556 | } | 
| 557 | 557 | |
| 558 | - /** | |
| 559 | - * Print outthe message was sent by $sender_username on the | |
| 560 | - * | |
| 561 | - * @since 1.9.0 | |
| 562 | - */ | |
| 563 | -    public static function the_message_sent_by_title(){ | |
| 558 | + /** | |
| 559 | + * Print outthe message was sent by $sender_username on the | |
| 560 | + * | |
| 561 | + * @since 1.9.0 | |
| 562 | + */ | |
| 563 | +	public static function the_message_sent_by_title(){ | |
| 564 | 564 | |
| 565 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); | |
| 566 | -        if( $sender_username ) { | |
| 565 | + $sender_username = get_post_meta( get_the_ID() , '_sender', true ); | |
| 566 | +		if( $sender_username ) { | |
| 567 | 567 | |
| 568 | - $sender = get_user_by( 'login', $sender_username ); ?> | |
| 568 | + $sender = get_user_by( 'login', $sender_username ); ?> | |
| 569 | 569 | |
| 570 | 570 | <p class="message-meta"> | 
| 571 | 571 | <small> | 
| @@ -577,41 +577,41 @@ discard block | ||
| 577 | 577 | |
| 578 | 578 | <?php } | 
| 579 | 579 | |
| 580 | - } | |
| 580 | + } | |
| 581 | 581 | |
| 582 | - /** | |
| 583 | - * sensei_single_title output for single page title | |
| 584 | - * @since 1.1.0 | |
| 585 | - * @return void | |
| 586 | - * @deprecate | |
| 587 | - */ | |
| 588 | -    public static function the_title() { | |
| 582 | + /** | |
| 583 | + * sensei_single_title output for single page title | |
| 584 | + * @since 1.1.0 | |
| 585 | + * @return void | |
| 586 | + * @deprecate | |
| 587 | + */ | |
| 588 | +	public static function the_title() { | |
| 589 | 589 | |
| 590 | - global $post; | |
| 590 | + global $post; | |
| 591 | 591 | |
| 592 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); | |
| 593 | -        if( $content_post_id ) { | |
| 594 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); | |
| 595 | -        } else { | |
| 596 | - $title = get_the_title( $post->ID ); | |
| 597 | - } | |
| 592 | + $content_post_id = get_post_meta( $post->ID, '_post', true ); | |
| 593 | +		if( $content_post_id ) { | |
| 594 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); | |
| 595 | +		} else { | |
| 596 | + $title = get_the_title( $post->ID ); | |
| 597 | + } | |
| 598 | 598 | |
| 599 | - ?> | |
| 599 | + ?> | |
| 600 | 600 | <header> | 
| 601 | 601 | |
| 602 | 602 | <h1> | 
| 603 | 603 | |
| 604 | 604 | <?php | 
| 605 | - /** | |
| 606 | - * Filter Sensei single title | |
| 607 | - * | |
| 608 | - * @since 1.8.0 | |
| 609 | - * @param string $title | |
| 610 | - * @param string $template | |
| 611 | - * @param string $post_type | |
| 612 | - */ | |
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); | |
| 614 | - ?> | |
| 605 | + /** | |
| 606 | + * Filter Sensei single title | |
| 607 | + * | |
| 608 | + * @since 1.8.0 | |
| 609 | + * @param string $title | |
| 610 | + * @param string $template | |
| 611 | + * @param string $post_type | |
| 612 | + */ | |
| 613 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); | |
| 614 | + ?> | |
| 615 | 615 | |
| 616 | 616 | </h1> | 
| 617 | 617 | |
| @@ -619,52 +619,52 @@ discard block | ||
| 619 | 619 | |
| 620 | 620 | <?php | 
| 621 | 621 | |
| 622 | - } // End sensei_single_title() | |
| 622 | + } // End sensei_single_title() | |
| 623 | 623 | |
| 624 | - /** | |
| 625 | - * Generates the my messages | |
| 626 | - * archive header. | |
| 627 | - * | |
| 628 | - * @since 1.9.0 | |
| 629 | - * | |
| 630 | - * @return string | |
| 631 | - */ | |
| 632 | -    public static function the_archive_header( ){ | |
| 624 | + /** | |
| 625 | + * Generates the my messages | |
| 626 | + * archive header. | |
| 627 | + * | |
| 628 | + * @since 1.9.0 | |
| 629 | + * | |
| 630 | + * @return string | |
| 631 | + */ | |
| 632 | +	public static function the_archive_header( ){ | |
| 633 | 633 | |
| 634 | - $html = ''; | |
| 635 | - $html .= '<header class="archive-header"><h1>'; | |
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); | |
| 637 | - $html .= '</h1></header>'; | |
| 634 | + $html = ''; | |
| 635 | + $html .= '<header class="archive-header"><h1>'; | |
| 636 | + $html .= __( 'My Messages', 'woothemes-sensei' ); | |
| 637 | + $html .= '</h1></header>'; | |
| 638 | 638 | |
| 639 | - /** | |
| 640 | - * Filter the sensei messages archive title. | |
| 641 | - * @since 1.0.0 | |
| 642 | - */ | |
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); | |
| 639 | + /** | |
| 640 | + * Filter the sensei messages archive title. | |
| 641 | + * @since 1.0.0 | |
| 642 | + */ | |
| 643 | + echo apply_filters( 'sensei_message_archive_title', $html ); | |
| 644 | 644 | |
| 645 | - } // get_archive_header() | |
| 645 | + } // get_archive_header() | |
| 646 | 646 | |
| 647 | - /** | |
| 648 | - * Output the title for a message given the post_id. | |
| 649 | - * | |
| 650 | - * @since 1.9.0 | |
| 651 | - * @param $post_id | |
| 652 | - */ | |
| 653 | -    public static function the_message_title( $message_post_id ){ | |
| 647 | + /** | |
| 648 | + * Output the title for a message given the post_id. | |
| 649 | + * | |
| 650 | + * @since 1.9.0 | |
| 651 | + * @param $post_id | |
| 652 | + */ | |
| 653 | +	public static function the_message_title( $message_post_id ){ | |
| 654 | 654 | |
| 655 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); | |
| 655 | + $content_post_id = get_post_meta( $message_post_id, '_post', true ); | |
| 656 | 656 | |
| 657 | -        if( $content_post_id ) { | |
| 657 | +		if( $content_post_id ) { | |
| 658 | 658 | |
| 659 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); | |
| 659 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); | |
| 660 | 660 | |
| 661 | -        } else { | |
| 661 | +		} else { | |
| 662 | 662 | |
| 663 | - $title = get_the_title( $message_post_id ); | |
| 663 | + $title = get_the_title( $message_post_id ); | |
| 664 | 664 | |
| 665 | - } | |
| 665 | + } | |
| 666 | 666 | |
| 667 | - ?> | |
| 667 | + ?> | |
| 668 | 668 | <h2> | 
| 669 | 669 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> | 
| 670 | 670 | <?php echo $title; ?> | 
| @@ -673,21 +673,21 @@ discard block | ||
| 673 | 673 | </h2> | 
| 674 | 674 | |
| 675 | 675 | <?php | 
| 676 | - } //end the_message_header | |
| 676 | + } //end the_message_header | |
| 677 | 677 | |
| 678 | - /** | |
| 679 | - * Output the message sender given the post id. | |
| 680 | - * | |
| 681 | - * @param $message_post_id | |
| 682 | - */ | |
| 683 | -    public  static function the_message_sender( $message_post_id ){ | |
| 678 | + /** | |
| 679 | + * Output the message sender given the post id. | |
| 680 | + * | |
| 681 | + * @param $message_post_id | |
| 682 | + */ | |
| 683 | +	public  static function the_message_sender( $message_post_id ){ | |
| 684 | 684 | |
| 685 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); | |
| 686 | - $sender = get_user_by( 'login', $sender_username ); | |
| 685 | + $sender_username = get_post_meta( $message_post_id, '_sender', true ); | |
| 686 | + $sender = get_user_by( 'login', $sender_username ); | |
| 687 | 687 | |
| 688 | -        if( $sender_username && $sender instanceof WP_User ) { | |
| 689 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); | |
| 690 | - ?> | |
| 688 | +		if( $sender_username && $sender instanceof WP_User ) { | |
| 689 | + $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); | |
| 690 | + ?> | |
| 691 | 691 | <p class="message-meta"> | 
| 692 | 692 | <small> | 
| 693 | 693 | <em> <?php echo $sender_display_name; ?> </em> | 
| @@ -695,18 +695,18 @@ discard block | ||
| 695 | 695 | </p> | 
| 696 | 696 | |
| 697 | 697 | <?php | 
| 698 | - } // end if | |
| 699 | - | |
| 700 | - } // end the_message_archive_sender | |
| 701 | - | |
| 702 | - /** | |
| 703 | - * Link to the users my messages page | |
| 704 | - * | |
| 705 | - * @since 1.9.0 | |
| 706 | - */ | |
| 707 | -    public static function the_my_messages_link(){ | |
| 708 | -        if( ! Sensei()->settings->get('messages_disable')  ) { | |
| 709 | - ?> | |
| 698 | + } // end if | |
| 699 | + | |
| 700 | + } // end the_message_archive_sender | |
| 701 | + | |
| 702 | + /** | |
| 703 | + * Link to the users my messages page | |
| 704 | + * | |
| 705 | + * @since 1.9.0 | |
| 706 | + */ | |
| 707 | +	public static function the_my_messages_link(){ | |
| 708 | +		if( ! Sensei()->settings->get('messages_disable')  ) { | |
| 709 | + ?> | |
| 710 | 710 | <p class="my-messages-link-container"> | 
| 711 | 711 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" | 
| 712 | 712 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> | 
| @@ -714,8 +714,8 @@ discard block | ||
| 714 | 714 | </a> | 
| 715 | 715 | </p> | 
| 716 | 716 | <?php | 
| 717 | - } | |
| 718 | - } | |
| 717 | + } | |
| 718 | + } | |
| 719 | 719 | |
| 720 | 720 | } // End Class | 
| 721 | 721 | |
| @@ -402,7 +402,7 @@ discard block | ||
| 402 | 402 | * This function simply loads the question type template | 
| 403 | 403 | * | 
| 404 | 404 | * @since 1.9.0 | 
| 405 | - * @param $question_type | |
| 405 | + * @param string $question_type | |
| 406 | 406 | */ | 
| 407 | 407 |      public static function load_question_template( $question_type ){ | 
| 408 | 408 | |
| @@ -487,7 +487,7 @@ discard block | ||
| 487 | 487 | * Get the questions media markup | 
| 488 | 488 | * | 
| 489 | 489 | * @since 1.9.0 | 
| 490 | - * @param $question_id | |
| 490 | + * @param string $question_id | |
| 491 | 491 | * @return string | 
| 492 | 492 | */ | 
| 493 | 493 |      public static function get_the_question_media( $question_id ){ | 
| @@ -1,5 +1,8 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Question Class | 
| @@ -211,7 +214,9 @@ discard block | ||
| 211 | 214 | |
| 212 | 215 | $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); | 
| 213 | 216 | |
| 214 | - if( ! $lesson_id ) continue; | |
| 217 | +			if( ! $lesson_id ) { | |
| 218 | + continue; | |
| 219 | + } | |
| 215 | 220 | |
| 216 | 221 | $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); | 
| 217 | 222 | $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); | 
| @@ -880,7 +885,7 @@ discard block | ||
| 880 | 885 | |
| 881 | 886 | $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | 
| 882 | 887 | |
| 883 | -            }  else { | |
| 888 | +            } else { | |
| 884 | 889 | |
| 885 | 890 | array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | 
| 886 | 891 | $merged_options = $question_data[ 'question_wrong_answers' ]; | 
| @@ -908,7 +913,7 @@ discard block | ||
| 908 | 913 | |
| 909 | 914 | $user_correct = true; | 
| 910 | 915 | |
| 911 | -                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 916 | +                    } else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 912 | 917 | |
| 913 | 918 | $user_correct = true; | 
| 914 | 919 | |
| @@ -923,7 +928,7 @@ discard block | ||
| 923 | 928 | |
| 924 | 929 | $answer_class .= ' right_answer'; | 
| 925 | 930 | |
| 926 | -                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 931 | +                    } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 927 | 932 | |
| 928 | 933 | $answer_class .= ' right_answer'; | 
| 929 | 934 | |
| @@ -1006,13 +1011,13 @@ discard block | ||
| 1006 | 1011 | } | 
| 1007 | 1012 | } | 
| 1008 | 1013 | |
| 1009 | -                    }else{ | |
| 1014 | +                    } else{ | |
| 1010 | 1015 | |
| 1011 | 1016 | $answer_options_sorted = $question_answers_options; | 
| 1012 | 1017 | |
| 1013 | 1018 | } | 
| 1014 | 1019 | |
| 1015 | -                }else{ | |
| 1020 | +                } else{ | |
| 1016 | 1021 | |
| 1017 | 1022 | $answer_options_sorted = $question_answers_options; | 
| 1018 | 1023 | |
| @@ -1075,12 +1080,12 @@ discard block | ||
| 1075 | 1080 | |
| 1076 | 1081 | $right_answer = ucfirst($right_answer); | 
| 1077 | 1082 | |
| 1078 | -        }elseif( 'multiple-choice' == $type ) { | |
| 1083 | +        } elseif( 'multiple-choice' == $type ) { | |
| 1079 | 1084 | |
| 1080 | 1085 | $right_answer = (array) $right_answer; | 
| 1081 | 1086 | $right_answer = implode( ', ', $right_answer ); | 
| 1082 | 1087 | |
| 1083 | -        }elseif( 'gap-fill' == $type ) { | |
| 1088 | +        } elseif( 'gap-fill' == $type ) { | |
| 1084 | 1089 | |
| 1085 | 1090 | $right_answer_array = explode( '||', $right_answer ); | 
| 1086 | 1091 |              if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } | 
| @@ -1089,7 +1094,7 @@ discard block | ||
| 1089 | 1094 | |
| 1090 | 1095 | $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; | 
| 1091 | 1096 | |
| 1092 | -        }else{ | |
| 1097 | +        } else{ | |
| 1093 | 1098 | |
| 1094 | 1099 | // for non auto gradable question types no answer should be returned. | 
| 1095 | 1100 | $right_answer = ''; | 
| @@ -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 | 
| @@ -20,34 +20,34 @@ discard block | ||
| 20 | 20 | * Constructor. | 
| 21 | 21 | * @since 1.0.0 | 
| 22 | 22 | */ | 
| 23 | -	public function __construct () { | |
| 23 | +	public function __construct() { | |
| 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,26 +943,26 @@ 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 | 968 | $question_answers_options[] = $question_option; | 
| @@ -972,47 +972,47 @@ discard block | ||
| 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 | * 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 {} | |
| @@ -21,7 +21,7 @@ discard block | ||
| 21 | 21 | * @since 1.0.0 | 
| 22 | 22 | */ | 
| 23 | 23 |  	public function __construct () { | 
| 24 | - $this->token = 'question'; | |
| 24 | + $this->token = 'question'; | |
| 25 | 25 | $this->question_types = $this->question_types(); | 
| 26 | 26 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); | 
| 27 | 27 |  		if ( is_admin() ) { | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | |
| 119 | 119 |  			if( isset( $post->ID ) ) { | 
| 120 | 120 | |
| 121 | - $question_type = Sensei()->question->get_question_type( $post->ID ); | |
| 121 | + $question_type = Sensei()->question->get_question_type( $post->ID ); | |
| 122 | 122 | |
| 123 | 123 |  				if( $question_type ) { | 
| 124 | 124 | $type = $this->question_types[ $question_type ]; | 
| @@ -238,15 +238,15 @@ discard block | ||
| 238 | 238 |  	public function save_question( $post_id = 0 ) { | 
| 239 | 239 | |
| 240 | 240 | if( ! isset( $_POST['post_type'] | 
| 241 | -            ) || 'question' != $_POST['post_type'] ) { | |
| 242 | - return; | |
| 243 | - } | |
| 241 | +			) || 'question' != $_POST['post_type'] ) { | |
| 242 | + return; | |
| 243 | + } | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |
| 247 | - //setup the data for saving | |
| 247 | + //setup the data for saving | |
| 248 | 248 | $data = $_POST ; | 
| 249 | - $data['quiz_id'] = 0; | |
| 249 | + $data['quiz_id'] = 0; | |
| 250 | 250 | $data['question_id'] = $post_id; | 
| 251 | 251 | |
| 252 | 252 |  		if ( ! wp_is_post_revision( $post_id ) ){ | 
| @@ -340,34 +340,34 @@ discard block | ||
| 340 | 340 | return $request; | 
| 341 | 341 | } | 
| 342 | 342 | |
| 343 | - /** | |
| 344 | - * Get the type of question by id | |
| 345 | - * | |
| 346 | - * This function uses the post terms to determine which question type | |
| 347 | - * the passed question id belongs to. | |
| 348 | - * | |
| 349 | - * @since 1.7.4 | |
| 350 | - * | |
| 351 | - * @param int $question_id | |
| 352 | - * | |
| 353 | - * @return string $question_type | bool | |
| 354 | - */ | |
| 355 | -    public function get_question_type( $question_id ){ | |
| 356 | - | |
| 357 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 | |
| 358 | -            || 'question' != get_post_type( $question_id )   ){ | |
| 359 | - return false; | |
| 360 | - } | |
| 361 | - | |
| 362 | - $question_type = 'multiple-choice'; | |
| 363 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); | |
| 364 | -        foreach( $question_types as $type ) { | |
| 365 | - $question_type = $type->slug; | |
| 366 | - } | |
| 367 | - | |
| 368 | - return $question_type; | |
| 369 | - | |
| 370 | - }// end get_question_type | |
| 343 | + /** | |
| 344 | + * Get the type of question by id | |
| 345 | + * | |
| 346 | + * This function uses the post terms to determine which question type | |
| 347 | + * the passed question id belongs to. | |
| 348 | + * | |
| 349 | + * @since 1.7.4 | |
| 350 | + * | |
| 351 | + * @param int $question_id | |
| 352 | + * | |
| 353 | + * @return string $question_type | bool | |
| 354 | + */ | |
| 355 | +	public function get_question_type( $question_id ){ | |
| 356 | + | |
| 357 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 | |
| 358 | +			|| 'question' != get_post_type( $question_id )   ){ | |
| 359 | + return false; | |
| 360 | + } | |
| 361 | + | |
| 362 | + $question_type = 'multiple-choice'; | |
| 363 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); | |
| 364 | +		foreach( $question_types as $type ) { | |
| 365 | + $question_type = $type->slug; | |
| 366 | + } | |
| 367 | + | |
| 368 | + return $question_type; | |
| 369 | + | |
| 370 | + }// end get_question_type | |
| 371 | 371 | |
| 372 | 372 | /** | 
| 373 | 373 | * Given a question ID, return the grade that can be achieved. | 
| @@ -399,317 +399,317 @@ discard block | ||
| 399 | 399 | } // end get_question_grade | 
| 400 | 400 | |
| 401 | 401 | |
| 402 | - /** | |
| 403 | - * This function simply loads the question type template | |
| 404 | - * | |
| 405 | - * @since 1.9.0 | |
| 406 | - * @param $question_type | |
| 407 | - */ | |
| 408 | -    public static function load_question_template( $question_type ){ | |
| 409 | - | |
| 410 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); | |
| 411 | - } | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * Echo the sensei question title. | |
| 415 | - * | |
| 416 | - * @uses WooThemes_Sensei_Question::get_the_question_title | |
| 417 | - * | |
| 418 | - * @since 1.9.0 | |
| 419 | - * @param $question_id | |
| 420 | - */ | |
| 421 | -    public static function the_question_title( $question_id ){ | |
| 422 | - | |
| 423 | - echo self::get_the_question_title( $question_id ); | |
| 424 | - | |
| 425 | - }// end the_question_title | |
| 426 | - | |
| 427 | - /** | |
| 428 | - * Generate the question title with it's grade. | |
| 429 | - * | |
| 430 | - * @since 1.9.0 | |
| 431 | - * | |
| 432 | - * @param $question_id | |
| 433 | - * @return string | |
| 434 | - */ | |
| 435 | -    public static function get_the_question_title( $question_id ){ | |
| 436 | - | |
| 437 | - /** | |
| 438 | - * Filter the sensei question title | |
| 439 | - * | |
| 440 | - * @since 1.3.0 | |
| 441 | - * @param $question_title | |
| 442 | - */ | |
| 443 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); | |
| 444 | - | |
| 445 | - /** | |
| 446 | - * hook document in class-woothemes-sensei-message.php the_title() | |
| 447 | - */ | |
| 448 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); | |
| 449 | - | |
| 450 | - $title_html = '<span class="question question-title">'; | |
| 451 | - $title_html .= $title; | |
| 452 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; | |
| 453 | - $title_html .='</span>'; | |
| 454 | - | |
| 455 | - return $title_html; | |
| 456 | - } | |
| 457 | - | |
| 458 | - /** | |
| 459 | - * Tech the question description | |
| 460 | - * | |
| 461 | - * @param $question_id | |
| 462 | - * @return string | |
| 463 | - */ | |
| 464 | -    public static function get_the_question_description( $question_id ){ | |
| 465 | - | |
| 466 | - $question = get_post( $question_id ); | |
| 467 | - | |
| 468 | - /** | |
| 469 | - * Already documented within WordPress Core | |
| 470 | - */ | |
| 471 | - return apply_filters( 'the_content', $question->post_content ); | |
| 472 | - | |
| 473 | - } | |
| 474 | - | |
| 475 | - /** | |
| 476 | - * Output the question description | |
| 477 | - * | |
| 478 | - * @since 1.9.0 | |
| 479 | - * @param $question_id | |
| 480 | - */ | |
| 481 | -    public static function the_question_description( $question_id  ){ | |
| 482 | - | |
| 483 | - echo self::get_the_question_description( $question_id ); | |
| 484 | - | |
| 485 | - } | |
| 486 | - | |
| 487 | - /** | |
| 488 | - * Get the questions media markup | |
| 489 | - * | |
| 490 | - * @since 1.9.0 | |
| 491 | - * @param $question_id | |
| 492 | - * @return string | |
| 493 | - */ | |
| 494 | -    public static function get_the_question_media( $question_id ){ | |
| 495 | - | |
| 496 | - $question_media = get_post_meta( $question_id, '_question_media', true ); | |
| 497 | - $question_media_link = ''; | |
| 498 | -        if( 0 < intval( $question_media ) ) { | |
| 499 | - $mimetype = get_post_mime_type( $question_media ); | |
| 500 | -            if( $mimetype ) { | |
| 501 | - $mimetype_array = explode( '/', $mimetype); | |
| 502 | -                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { | |
| 503 | - $question_media_type = $mimetype_array[0]; | |
| 504 | - $question_media_url = wp_get_attachment_url( $question_media ); | |
| 505 | - $attachment = get_post( $question_media ); | |
| 506 | - $question_media_title = $attachment->post_title; | |
| 507 | - $question_media_description = $attachment->post_content; | |
| 508 | -                    switch( $question_media_type ) { | |
| 509 | - case 'image': | |
| 510 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); | |
| 511 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); | |
| 512 | - $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>'; | |
| 513 | - break; | |
| 514 | - | |
| 515 | - case 'audio': | |
| 516 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); | |
| 517 | - break; | |
| 518 | - | |
| 519 | - case 'video': | |
| 520 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); | |
| 521 | - break; | |
| 522 | - | |
| 523 | - default: | |
| 524 | - $question_media_filename = basename( $question_media_url ); | |
| 525 | - $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>'; | |
| 526 | - break; | |
| 527 | - } | |
| 528 | - } | |
| 529 | - } | |
| 530 | - } | |
| 531 | - | |
| 532 | - $output = ''; | |
| 533 | -        if( $question_media_link ) { | |
| 534 | - | |
| 535 | - $output .= '<div class="question_media_display">'; | |
| 536 | - $output .= $question_media_link; | |
| 537 | - $output .= '<dl>'; | |
| 538 | - | |
| 539 | -                if( $question_media_title ) { | |
| 540 | - | |
| 541 | - $output .= '<dt>'. $question_media_title. '</dt>'; | |
| 542 | - | |
| 543 | - } | |
| 544 | - | |
| 545 | -                if( $question_media_description ) { | |
| 546 | - | |
| 547 | - $output .= '<dd>' . $question_media_description . '</dd>'; | |
| 548 | - | |
| 549 | - } | |
| 550 | - | |
| 551 | - $output .= '</dl>'; | |
| 552 | - $output .= '</div>'; | |
| 402 | + /** | |
| 403 | + * This function simply loads the question type template | |
| 404 | + * | |
| 405 | + * @since 1.9.0 | |
| 406 | + * @param $question_type | |
| 407 | + */ | |
| 408 | +	public static function load_question_template( $question_type ){ | |
| 409 | + | |
| 410 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); | |
| 411 | + } | |
| 412 | + | |
| 413 | + /** | |
| 414 | + * Echo the sensei question title. | |
| 415 | + * | |
| 416 | + * @uses WooThemes_Sensei_Question::get_the_question_title | |
| 417 | + * | |
| 418 | + * @since 1.9.0 | |
| 419 | + * @param $question_id | |
| 420 | + */ | |
| 421 | +	public static function the_question_title( $question_id ){ | |
| 422 | + | |
| 423 | + echo self::get_the_question_title( $question_id ); | |
| 424 | + | |
| 425 | + }// end the_question_title | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * Generate the question title with it's grade. | |
| 429 | + * | |
| 430 | + * @since 1.9.0 | |
| 431 | + * | |
| 432 | + * @param $question_id | |
| 433 | + * @return string | |
| 434 | + */ | |
| 435 | +	public static function get_the_question_title( $question_id ){ | |
| 436 | + | |
| 437 | + /** | |
| 438 | + * Filter the sensei question title | |
| 439 | + * | |
| 440 | + * @since 1.3.0 | |
| 441 | + * @param $question_title | |
| 442 | + */ | |
| 443 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * hook document in class-woothemes-sensei-message.php the_title() | |
| 447 | + */ | |
| 448 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); | |
| 449 | + | |
| 450 | + $title_html = '<span class="question question-title">'; | |
| 451 | + $title_html .= $title; | |
| 452 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; | |
| 453 | + $title_html .='</span>'; | |
| 454 | + | |
| 455 | + return $title_html; | |
| 456 | + } | |
| 457 | + | |
| 458 | + /** | |
| 459 | + * Tech the question description | |
| 460 | + * | |
| 461 | + * @param $question_id | |
| 462 | + * @return string | |
| 463 | + */ | |
| 464 | +	public static function get_the_question_description( $question_id ){ | |
| 465 | + | |
| 466 | + $question = get_post( $question_id ); | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Already documented within WordPress Core | |
| 470 | + */ | |
| 471 | + return apply_filters( 'the_content', $question->post_content ); | |
| 472 | + | |
| 473 | + } | |
| 474 | + | |
| 475 | + /** | |
| 476 | + * Output the question description | |
| 477 | + * | |
| 478 | + * @since 1.9.0 | |
| 479 | + * @param $question_id | |
| 480 | + */ | |
| 481 | +	public static function the_question_description( $question_id  ){ | |
| 482 | + | |
| 483 | + echo self::get_the_question_description( $question_id ); | |
| 484 | + | |
| 485 | + } | |
| 486 | + | |
| 487 | + /** | |
| 488 | + * Get the questions media markup | |
| 489 | + * | |
| 490 | + * @since 1.9.0 | |
| 491 | + * @param $question_id | |
| 492 | + * @return string | |
| 493 | + */ | |
| 494 | +	public static function get_the_question_media( $question_id ){ | |
| 495 | + | |
| 496 | + $question_media = get_post_meta( $question_id, '_question_media', true ); | |
| 497 | + $question_media_link = ''; | |
| 498 | +		if( 0 < intval( $question_media ) ) { | |
| 499 | + $mimetype = get_post_mime_type( $question_media ); | |
| 500 | +			if( $mimetype ) { | |
| 501 | + $mimetype_array = explode( '/', $mimetype); | |
| 502 | +				if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { | |
| 503 | + $question_media_type = $mimetype_array[0]; | |
| 504 | + $question_media_url = wp_get_attachment_url( $question_media ); | |
| 505 | + $attachment = get_post( $question_media ); | |
| 506 | + $question_media_title = $attachment->post_title; | |
| 507 | + $question_media_description = $attachment->post_content; | |
| 508 | +					switch( $question_media_type ) { | |
| 509 | + case 'image': | |
| 510 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); | |
| 511 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); | |
| 512 | + $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>'; | |
| 513 | + break; | |
| 514 | + | |
| 515 | + case 'audio': | |
| 516 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); | |
| 517 | + break; | |
| 518 | + | |
| 519 | + case 'video': | |
| 520 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); | |
| 521 | + break; | |
| 522 | + | |
| 523 | + default: | |
| 524 | + $question_media_filename = basename( $question_media_url ); | |
| 525 | + $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>'; | |
| 526 | + break; | |
| 527 | + } | |
| 528 | + } | |
| 529 | + } | |
| 530 | + } | |
| 531 | + | |
| 532 | + $output = ''; | |
| 533 | +		if( $question_media_link ) { | |
| 553 | 534 | |
| 535 | + $output .= '<div class="question_media_display">'; | |
| 536 | + $output .= $question_media_link; | |
| 537 | + $output .= '<dl>'; | |
| 554 | 538 | |
| 555 | - } | |
| 556 | - | |
| 557 | - return $output; | |
| 558 | - | |
| 559 | - } // end get_the_question_media | |
| 560 | - | |
| 539 | +				if( $question_media_title ) { | |
| 561 | 540 | |
| 562 | - /** | |
| 563 | - * Output the question media | |
| 564 | - * | |
| 565 | - * @since 1.9.0 | |
| 566 | - * @param string $question_id | |
| 567 | - */ | |
| 568 | -    public static function the_question_media( $question_id ){ | |
| 541 | + $output .= '<dt>'. $question_media_title. '</dt>'; | |
| 569 | 542 | |
| 570 | - echo self::get_the_question_media( $question_id ); | |
| 543 | + } | |
| 571 | 544 | |
| 572 | - } | |
| 545 | +				if( $question_media_description ) { | |
| 573 | 546 | |
| 574 | - /** | |
| 575 | - * Output a special field for the question needed for question submission. | |
| 576 | - * | |
| 577 | - * @since 1.9.0 | |
| 578 | - * | |
| 579 | - * @param $question_id | |
| 580 | - */ | |
| 581 | -    public static function the_question_hidden_fields( $question_id ){ | |
| 582 | - ?> | |
| 547 | + $output .= '<dd>' . $question_media_description . '</dd>'; | |
| 548 | + | |
| 549 | + } | |
| 550 | + | |
| 551 | + $output .= '</dl>'; | |
| 552 | + $output .= '</div>'; | |
| 553 | + | |
| 554 | + | |
| 555 | + } | |
| 556 | + | |
| 557 | + return $output; | |
| 558 | + | |
| 559 | + } // end get_the_question_media | |
| 560 | + | |
| 561 | + | |
| 562 | + /** | |
| 563 | + * Output the question media | |
| 564 | + * | |
| 565 | + * @since 1.9.0 | |
| 566 | + * @param string $question_id | |
| 567 | + */ | |
| 568 | +	public static function the_question_media( $question_id ){ | |
| 569 | + | |
| 570 | + echo self::get_the_question_media( $question_id ); | |
| 571 | + | |
| 572 | + } | |
| 573 | + | |
| 574 | + /** | |
| 575 | + * Output a special field for the question needed for question submission. | |
| 576 | + * | |
| 577 | + * @since 1.9.0 | |
| 578 | + * | |
| 579 | + * @param $question_id | |
| 580 | + */ | |
| 581 | +	public static function the_question_hidden_fields( $question_id ){ | |
| 582 | + ?> | |
| 583 | 583 | |
| 584 | 584 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> | 
| 585 | 585 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> | 
| 586 | 586 | |
| 587 | 587 | <?php | 
| 588 | - } | |
| 588 | + } | |
| 589 | 589 | |
| 590 | - /** | |
| 591 | - * This function can only be run withing the single quiz question loop | |
| 592 | - * | |
| 593 | - * @since 1.9.0 | |
| 594 | - * @param $question_id | |
| 595 | - */ | |
| 596 | -    public static function answer_feedback_notes( $question_id ){ | |
| 590 | + /** | |
| 591 | + * This function can only be run withing the single quiz question loop | |
| 592 | + * | |
| 593 | + * @since 1.9.0 | |
| 594 | + * @param $question_id | |
| 595 | + */ | |
| 596 | +	public static function answer_feedback_notes( $question_id ){ | |
| 597 | 597 | |
| 598 | - //IDS | |
| 599 | - $quiz_id = get_the_ID(); | |
| 600 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 598 | + //IDS | |
| 599 | + $quiz_id = get_the_ID(); | |
| 600 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 601 | 601 | |
| 602 | - // Data to check before showing feedback | |
| 603 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); | |
| 604 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 605 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); | |
| 606 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 607 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); | |
| 608 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 602 | + // Data to check before showing feedback | |
| 603 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); | |
| 604 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 605 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); | |
| 606 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 607 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); | |
| 608 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 609 | 609 | |
| 610 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) | |
| 611 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) | |
| 612 | -            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { | |
| 610 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) | |
| 611 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) | |
| 612 | +			|| ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { | |
| 613 | 613 | |
| 614 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); | |
| 614 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); | |
| 615 | 615 | |
| 616 | -            if( $answer_notes ) { ?> | |
| 616 | +			if( $answer_notes ) { ?> | |
| 617 | 617 | |
| 618 | 618 | <div class="sensei-message info info-special answer-feedback"> | 
| 619 | 619 | |
| 620 | 620 | <?php | 
| 621 | 621 | |
| 622 | - /** | |
| 623 | - * Filter the answer feedback | |
| 624 | - * Since 1.9.0 | |
| 625 | - * | |
| 626 | - * @param string $answer_notes | |
| 627 | - * @param string $question_id | |
| 628 | - * @param string $lesson_id | |
| 629 | - */ | |
| 630 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); | |
| 622 | + /** | |
| 623 | + * Filter the answer feedback | |
| 624 | + * Since 1.9.0 | |
| 625 | + * | |
| 626 | + * @param string $answer_notes | |
| 627 | + * @param string $question_id | |
| 628 | + * @param string $lesson_id | |
| 629 | + */ | |
| 630 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); | |
| 631 | 631 | |
| 632 | - ?> | |
| 632 | + ?> | |
| 633 | 633 | |
| 634 | 634 | </div> | 
| 635 | 635 | |
| 636 | 636 | <?php } | 
| 637 | 637 | |
| 638 | - }// end if we can show answer feedback | |
| 638 | + }// end if we can show answer feedback | |
| 639 | 639 | |
| 640 | - }// end answer_feedback_notes | |
| 640 | + }// end answer_feedback_notes | |
| 641 | 641 | |
| 642 | - /** | |
| 643 | - * This function has to be run inside the quiz question loop on the single quiz page. | |
| 644 | - * | |
| 645 | - * | |
| 646 | - * @since 1.9.0 | |
| 647 | - * @param string $question_id | |
| 648 | - */ | |
| 649 | -    public static function the_answer_result_indication( $question_id ){ | |
| 642 | + /** | |
| 643 | + * This function has to be run inside the quiz question loop on the single quiz page. | |
| 644 | + * | |
| 645 | + * | |
| 646 | + * @since 1.9.0 | |
| 647 | + * @param string $question_id | |
| 648 | + */ | |
| 649 | +	public static function the_answer_result_indication( $question_id ){ | |
| 650 | 650 | |
| 651 | - global $post, $current_user, $sensei_question_loop; | |
| 651 | + global $post, $current_user, $sensei_question_loop; | |
| 652 | 652 | |
| 653 | - // Post Data | |
| 654 | - $quiz_id = $sensei_question_loop['quiz_id']; | |
| 655 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 656 | - $question_item = $sensei_question_loop['current_question']; | |
| 653 | + // Post Data | |
| 654 | + $quiz_id = $sensei_question_loop['quiz_id']; | |
| 655 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 656 | + $question_item = $sensei_question_loop['current_question']; | |
| 657 | 657 | |
| 658 | - // Setup variable needed to determine if the message should show and what it should show | |
| 659 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 660 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 661 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 662 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 658 | + // Setup variable needed to determine if the message should show and what it should show | |
| 659 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 660 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 661 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 662 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 663 | 663 | |
| 664 | - // retrieve the question total grade | |
| 665 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 664 | + // retrieve the question total grade | |
| 665 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 666 | 666 | |
| 667 | - // retrieve grade the user achieved | |
| 668 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); | |
| 667 | + // retrieve grade the user achieved | |
| 668 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); | |
| 669 | 669 | |
| 670 | - // Question ID | |
| 671 | - $question_id = $question_item->ID; | |
| 670 | + // Question ID | |
| 671 | + $question_id = $question_item->ID; | |
| 672 | 672 | |
| 673 | - // conditions to check | |
| 674 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; | |
| 675 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; | |
| 676 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; | |
| 673 | + // conditions to check | |
| 674 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; | |
| 675 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; | |
| 676 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; | |
| 677 | 677 | |
| 678 | - if ( $completed_with_valid_grade | |
| 679 | - || $completed_with_valid_grade_and_reset_not_allowed | |
| 680 | -            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) { | |
| 678 | + if ( $completed_with_valid_grade | |
| 679 | + || $completed_with_valid_grade_and_reset_not_allowed | |
| 680 | +			|| $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) { | |
| 681 | 681 | |
| 682 | - $user_correct = false; | |
| 683 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); | |
| 684 | - $answer_message_class = 'user_wrong'; | |
| 685 | - // For zero grade mark as 'correct' but add no classes | |
| 686 | -            if ( 0 == $question_grade ) { | |
| 682 | + $user_correct = false; | |
| 683 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); | |
| 684 | + $answer_message_class = 'user_wrong'; | |
| 685 | + // For zero grade mark as 'correct' but add no classes | |
| 686 | +			if ( 0 == $question_grade ) { | |
| 687 | 687 | |
| 688 | - $user_correct = true; | |
| 689 | - $answer_message = ''; | |
| 690 | - $answer_message_class = ''; | |
| 688 | + $user_correct = true; | |
| 689 | + $answer_message = ''; | |
| 690 | + $answer_message_class = ''; | |
| 691 | 691 | |
| 692 | -            } else if( $user_question_grade > 0 ) { | |
| 692 | +			} else if( $user_question_grade > 0 ) { | |
| 693 | 693 | |
| 694 | - $user_correct = true; | |
| 695 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); | |
| 696 | - $answer_message_class = 'user_right'; | |
| 694 | + $user_correct = true; | |
| 695 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); | |
| 696 | + $answer_message_class = 'user_right'; | |
| 697 | 697 | |
| 698 | - } | |
| 698 | + } | |
| 699 | 699 | |
| 700 | - // attach the correct answer if the question is auto gradable and user got it wrong | |
| 701 | -            if( !$reset_quiz_allowed && !$user_correct ){ | |
| 700 | + // attach the correct answer if the question is auto gradable and user got it wrong | |
| 701 | +			if( !$reset_quiz_allowed && !$user_correct ){ | |
| 702 | 702 | |
| 703 | -                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); | |
| 703 | +				$answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); | |
| 704 | 704 | |
| 705 | - } | |
| 705 | + } | |
| 706 | 706 | |
| 707 | - // answer feedback | |
| 708 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); | |
| 709 | -            if( $answer_notes ) { | |
| 710 | - $answer_message_class .= ' has_notes'; | |
| 711 | - } | |
| 712 | - ?> | |
| 707 | + // answer feedback | |
| 708 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); | |
| 709 | +			if( $answer_notes ) { | |
| 710 | + $answer_message_class .= ' has_notes'; | |
| 711 | + } | |
| 712 | + ?> | |
| 713 | 713 | |
| 714 | 714 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> | 
| 715 | 715 | |
| @@ -719,387 +719,387 @@ discard block | ||
| 719 | 719 | |
| 720 | 720 | <?php | 
| 721 | 721 | |
| 722 | - } // end if user can see all the goodies | |
| 723 | - | |
| 724 | - }// end the_answer_result_indication | |
| 725 | - | |
| 726 | - /** | |
| 727 | - * Generate the question template data and return it as an array. | |
| 728 | - * | |
| 729 | - * @since 1.9.0 | |
| 730 | - * | |
| 731 | - * @param string $question_id | |
| 732 | - * @param $quiz_id | |
| 733 | - * @return array $question_data | |
| 734 | - */ | |
| 735 | -    public static function get_template_data( $question_id, $quiz_id ){ | |
| 736 | - | |
| 737 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 738 | - | |
| 739 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 740 | - //backwards compatibility | |
| 741 | -        if( 'on' == $reset_allowed ) { | |
| 742 | - $reset_allowed = 1; | |
| 743 | - } | |
| 744 | - | |
| 745 | - // Check again that the lesson is complete | |
| 746 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); | |
| 747 | - $user_lesson_complete = false; | |
| 748 | -        if ( $user_lesson_end ) { | |
| 749 | - $user_lesson_complete = true; | |
| 750 | - } | |
| 751 | - | |
| 752 | - //setup the question data | |
| 753 | - $data[ 'ID' ] = $question_id; | |
| 754 | - $data[ 'title' ] = get_the_title( $question_id ); | |
| 755 | - $data[ 'content' ] = get_post( $question_id )->post_content; | |
| 756 | - $data[ 'quiz_id' ] = $quiz_id; | |
| 757 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 758 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); | |
| 759 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); | |
| 760 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); | |
| 761 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); | |
| 762 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); | |
| 763 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); | |
| 764 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); | |
| 765 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 766 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; | |
| 767 | - $data[ 'lesson_complete' ] = $user_lesson_complete; | |
| 768 | - | |
| 769 | - /** | |
| 770 | - * Filter the question template data. This filter fires in | |
| 771 | - * the get_template_data function | |
| 772 | - * | |
| 773 | - * @hooked self::boolean_load_question_data | |
| 774 | - * | |
| 775 | - * @since 1.9.0 | |
| 776 | - * | |
| 777 | - * @param array $data | |
| 778 | - * @param string $question_id | |
| 779 | - * @param string $quiz_id | |
| 780 | - */ | |
| 781 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); | |
| 722 | + } // end if user can see all the goodies | |
| 782 | 723 | |
| 783 | - } | |
| 724 | + }// end the_answer_result_indication | |
| 784 | 725 | |
| 785 | - /** | |
| 786 | - * Load multiple choice question data on the sensei_get_question_template_data | |
| 787 | - * filter. | |
| 788 | - * | |
| 789 | - * @since 1.9.0 | |
| 790 | - * | |
| 791 | - * @param $question_data | |
| 792 | - * @param $question_id | |
| 793 | - * @param $quiz_id | |
| 794 | - * | |
| 795 | - * @return array() | |
| 796 | - */ | |
| 797 | -    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ | |
| 726 | + /** | |
| 727 | + * Generate the question template data and return it as an array. | |
| 728 | + * | |
| 729 | + * @since 1.9.0 | |
| 730 | + * | |
| 731 | + * @param string $question_id | |
| 732 | + * @param $quiz_id | |
| 733 | + * @return array $question_data | |
| 734 | + */ | |
| 735 | +	public static function get_template_data( $question_id, $quiz_id ){ | |
| 798 | 736 | |
| 737 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 799 | 738 | |
| 800 | -        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 739 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 740 | + //backwards compatibility | |
| 741 | +		if( 'on' == $reset_allowed ) { | |
| 742 | + $reset_allowed = 1; | |
| 743 | + } | |
| 801 | 744 | |
| 802 | - // Get uploaded file | |
| 803 | - $attachment_id = $question_data[ 'user_answer_entry' ]; | |
| 804 | - $answer_media_url = $answer_media_filename = ''; | |
| 745 | + // Check again that the lesson is complete | |
| 746 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); | |
| 747 | + $user_lesson_complete = false; | |
| 748 | +		if ( $user_lesson_end ) { | |
| 749 | + $user_lesson_complete = true; | |
| 750 | + } | |
| 805 | 751 | |
| 752 | + //setup the question data | |
| 753 | + $data[ 'ID' ] = $question_id; | |
| 754 | + $data[ 'title' ] = get_the_title( $question_id ); | |
| 755 | + $data[ 'content' ] = get_post( $question_id )->post_content; | |
| 756 | + $data[ 'quiz_id' ] = $quiz_id; | |
| 757 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 758 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); | |
| 759 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); | |
| 760 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); | |
| 761 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); | |
| 762 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); | |
| 763 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); | |
| 764 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); | |
| 765 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 766 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; | |
| 767 | + $data[ 'lesson_complete' ] = $user_lesson_complete; | |
| 768 | + | |
| 769 | + /** | |
| 770 | + * Filter the question template data. This filter fires in | |
| 771 | + * the get_template_data function | |
| 772 | + * | |
| 773 | + * @hooked self::boolean_load_question_data | |
| 774 | + * | |
| 775 | + * @since 1.9.0 | |
| 776 | + * | |
| 777 | + * @param array $data | |
| 778 | + * @param string $question_id | |
| 779 | + * @param string $quiz_id | |
| 780 | + */ | |
| 781 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); | |
| 806 | 782 | |
| 807 | - $question_helptext = ''; | |
| 808 | -            if( isset( $question_data['question_wrong_answers'][0] ) ) { | |
| 783 | + } | |
| 809 | 784 | |
| 810 | - $question_helptext = $question_data['question_wrong_answers'][0]; | |
| 785 | + /** | |
| 786 | + * Load multiple choice question data on the sensei_get_question_template_data | |
| 787 | + * filter. | |
| 788 | + * | |
| 789 | + * @since 1.9.0 | |
| 790 | + * | |
| 791 | + * @param $question_data | |
| 792 | + * @param $question_id | |
| 793 | + * @param $quiz_id | |
| 794 | + * | |
| 795 | + * @return array() | |
| 796 | + */ | |
| 797 | +	public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ | |
| 811 | 798 | |
| 812 | - } | |
| 813 | 799 | |
| 800 | +		if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 814 | 801 | |
| 815 | -            if( 0 < intval( $attachment_id ) ) { | |
| 802 | + // Get uploaded file | |
| 803 | + $attachment_id = $question_data[ 'user_answer_entry' ]; | |
| 804 | + $answer_media_url = $answer_media_filename = ''; | |
| 816 | 805 | |
| 817 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); | |
| 818 | - $answer_media_filename = basename( $answer_media_url ); | |
| 819 | 806 | |
| 820 | - } | |
| 807 | + $question_helptext = ''; | |
| 808 | +			if( isset( $question_data['question_wrong_answers'][0] ) ) { | |
| 821 | 809 | |
| 810 | + $question_helptext = $question_data['question_wrong_answers'][0]; | |
| 822 | 811 | |
| 823 | - // Get max upload file size, formatted for display | |
| 824 | - // Code copied from wp-admin/includes/media.php:1515 | |
| 825 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); | |
| 826 | - $sizes = array( 'KB', 'MB', 'GB' ); | |
| 827 | -            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { | |
| 828 | - $upload_size_unit /= 1024; | |
| 829 | - } | |
| 830 | -            if ( $u < 0 ) { | |
| 812 | + } | |
| 831 | 813 | |
| 832 | - $upload_size_unit = 0; | |
| 833 | - $u = 0; | |
| 834 | 814 | |
| 835 | -            } else { | |
| 815 | +			if( 0 < intval( $attachment_id ) ) { | |
| 836 | 816 | |
| 837 | - $upload_size_unit = (int) $upload_size_unit; | |
| 817 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); | |
| 818 | + $answer_media_filename = basename( $answer_media_url ); | |
| 838 | 819 | |
| 839 | - } | |
| 840 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); | |
| 820 | + } | |
| 841 | 821 | |
| 842 | - // Assemble all the data needed by the file upload template | |
| 843 | - $question_data[ 'answer_media_url' ] = $answer_media_url; | |
| 844 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; | |
| 845 | - $question_data[ 'max_upload_size' ] = $max_upload_size; | |
| 846 | 822 | |
| 847 | - $question_data[ 'question_helptext' ] = $question_helptext; | |
| 823 | + // Get max upload file size, formatted for display | |
| 824 | + // Code copied from wp-admin/includes/media.php:1515 | |
| 825 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); | |
| 826 | + $sizes = array( 'KB', 'MB', 'GB' ); | |
| 827 | +			for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { | |
| 828 | + $upload_size_unit /= 1024; | |
| 829 | + } | |
| 830 | +			if ( $u < 0 ) { | |
| 848 | 831 | |
| 849 | - }// end if is file upload type | |
| 832 | + $upload_size_unit = 0; | |
| 833 | + $u = 0; | |
| 850 | 834 | |
| 851 | - return $question_data; | |
| 835 | +			} else { | |
| 852 | 836 | |
| 853 | - }// end file_upload_load_question_data | |
| 837 | + $upload_size_unit = (int) $upload_size_unit; | |
| 854 | 838 | |
| 855 | - /** | |
| 856 | - * Load multiple choice question data on the sensei_get_question_template_data | |
| 857 | - * filter. | |
| 858 | - * | |
| 859 | - * @since 1.9.0 | |
| 860 | - * | |
| 861 | - * @param $question_data | |
| 862 | - * @param $question_id | |
| 863 | - * @param $quiz_id | |
| 864 | - * | |
| 865 | - * @return array() | |
| 866 | - */ | |
| 867 | -    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 839 | + } | |
| 840 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); | |
| 868 | 841 | |
| 869 | -        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 842 | + // Assemble all the data needed by the file upload template | |
| 843 | + $question_data[ 'answer_media_url' ] = $answer_media_url; | |
| 844 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; | |
| 845 | + $question_data[ 'max_upload_size' ] = $max_upload_size; | |
| 870 | 846 | |
| 847 | + $question_data[ 'question_helptext' ] = $question_helptext; | |
| 871 | 848 | |
| 872 | - $answer_type = 'radio'; | |
| 873 | -            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { | |
| 849 | + }// end if is file upload type | |
| 874 | 850 | |
| 875 | - $answer_type = 'checkbox'; | |
| 851 | + return $question_data; | |
| 876 | 852 | |
| 877 | - } | |
| 853 | + }// end file_upload_load_question_data | |
| 878 | 854 | |
| 879 | - // Merge right and wrong answers | |
| 880 | -            if ( is_array( $question_data[ 'question_right_answer' ] ) ) { | |
| 855 | + /** | |
| 856 | + * Load multiple choice question data on the sensei_get_question_template_data | |
| 857 | + * filter. | |
| 858 | + * | |
| 859 | + * @since 1.9.0 | |
| 860 | + * | |
| 861 | + * @param $question_data | |
| 862 | + * @param $question_id | |
| 863 | + * @param $quiz_id | |
| 864 | + * | |
| 865 | + * @return array() | |
| 866 | + */ | |
| 867 | +	public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 881 | 868 | |
| 882 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 869 | +		if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 883 | 870 | |
| 884 | -            }  else { | |
| 885 | 871 | |
| 886 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 887 | - $merged_options = $question_data[ 'question_wrong_answers' ]; | |
| 872 | + $answer_type = 'radio'; | |
| 873 | +			if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { | |
| 888 | 874 | |
| 889 | - } | |
| 875 | + $answer_type = 'checkbox'; | |
| 890 | 876 | |
| 891 | - // Setup answer options array. | |
| 892 | - $question_answers_options = array(); | |
| 893 | - $count = 0; | |
| 877 | + } | |
| 894 | 878 | |
| 895 | -            foreach( $merged_options as $answer ) { | |
| 879 | + // Merge right and wrong answers | |
| 880 | +			if ( is_array( $question_data[ 'question_right_answer' ] ) ) { | |
| 896 | 881 | |
| 897 | - $count++; | |
| 898 | - $question_option = array(); | |
| 882 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 899 | 883 | |
| 900 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 901 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 902 | -                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { | |
| 884 | +			}  else { | |
| 903 | 885 | |
| 904 | - $user_correct = false; | |
| 886 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 887 | + $merged_options = $question_data[ 'question_wrong_answers' ]; | |
| 905 | 888 | |
| 889 | + } | |
| 906 | 890 | |
| 907 | - // For zero grade mark as 'correct' but add no classes | |
| 908 | -                    if ( 0 == $question_data[ 'question_grade' ] ) { | |
| 891 | + // Setup answer options array. | |
| 892 | + $question_answers_options = array(); | |
| 893 | + $count = 0; | |
| 909 | 894 | |
| 910 | - $user_correct = true; | |
| 895 | +			foreach( $merged_options as $answer ) { | |
| 911 | 896 | |
| 912 | -                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 897 | + $count++; | |
| 898 | + $question_option = array(); | |
| 913 | 899 | |
| 914 | - $user_correct = true; | |
| 900 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 901 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 902 | +					|| ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { | |
| 915 | 903 | |
| 916 | - } | |
| 904 | + $user_correct = false; | |
| 917 | 905 | |
| 918 | - } | |
| 919 | 906 | |
| 920 | - // setup the option specific classes | |
| 921 | - $answer_class = ''; | |
| 922 | -                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { | |
| 923 | -                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { | |
| 907 | + // For zero grade mark as 'correct' but add no classes | |
| 908 | +					if ( 0 == $question_data[ 'question_grade' ] ) { | |
| 924 | 909 | |
| 925 | - $answer_class .= ' right_answer'; | |
| 910 | + $user_correct = true; | |
| 926 | 911 | |
| 927 | -                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 912 | +					}  else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 928 | 913 | |
| 929 | - $answer_class .= ' right_answer'; | |
| 914 | + $user_correct = true; | |
| 930 | 915 | |
| 931 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) | |
| 932 | -                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) { | |
| 916 | + } | |
| 933 | 917 | |
| 934 | - $answer_class = 'user_wrong'; | |
| 935 | -                        if( $user_correct ) { | |
| 918 | + } | |
| 936 | 919 | |
| 937 | - $answer_class = 'user_right'; | |
| 920 | + // setup the option specific classes | |
| 921 | + $answer_class = ''; | |
| 922 | +				if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { | |
| 923 | +					if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { | |
| 938 | 924 | |
| 939 | - } | |
| 925 | + $answer_class .= ' right_answer'; | |
| 940 | 926 | |
| 941 | - } | |
| 927 | +					}  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 942 | 928 | |
| 943 | - } | |
| 929 | + $answer_class .= ' right_answer'; | |
| 944 | 930 | |
| 945 | - // determine if the current option must be checked | |
| 946 | - $checked = ''; | |
| 947 | -                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { | |
| 948 | -                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { | |
| 931 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) | |
| 932 | +						||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) { | |
| 949 | 933 | |
| 950 | - $checked = 'checked="checked"'; | |
| 934 | + $answer_class = 'user_wrong'; | |
| 935 | +						if( $user_correct ) { | |
| 951 | 936 | |
| 952 | -                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { | |
| 937 | + $answer_class = 'user_right'; | |
| 953 | 938 | |
| 954 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); | |
| 939 | + } | |
| 955 | 940 | |
| 956 | - } | |
| 941 | + } | |
| 957 | 942 | |
| 958 | - } // End If Statement | |
| 943 | + } | |
| 959 | 944 | |
| 960 | - //Load the answer option data | |
| 961 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); | |
| 962 | - $question_option[ 'answer' ] = $answer; | |
| 963 | - $question_option[ 'option_class'] = $answer_class; | |
| 964 | - $question_option[ 'checked'] = $checked; | |
| 965 | - $question_option[ 'count' ] = $count; | |
| 966 | - $question_option[ 'type' ] = $answer_type; | |
| 945 | + // determine if the current option must be checked | |
| 946 | + $checked = ''; | |
| 947 | +				if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { | |
| 948 | +					if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { | |
| 967 | 949 | |
| 968 | - // add the speci fic option to the list of options for this question | |
| 969 | - $question_answers_options[] = $question_option; | |
| 950 | + $checked = 'checked="checked"'; | |
| 970 | 951 | |
| 971 | - } // end for each option | |
| 952 | +					} elseif ( !is_array( $question_data['user_answer_entry'] ) ) { | |
| 972 | 953 | |
| 954 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); | |
| 973 | 955 | |
| 974 | - // Shuffle the array depending on the settings | |
| 975 | - $answer_options_sorted = array(); | |
| 976 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); | |
| 977 | -            if(  $random_order && $random_order == 'yes' ) { | |
| 956 | + } | |
| 978 | 957 | |
| 979 | - $answer_options_sorted = $question_answers_options; | |
| 980 | - shuffle( $answer_options_sorted ); | |
| 958 | + } // End If Statement | |
| 981 | 959 | |
| 982 | -            } else { | |
| 960 | + //Load the answer option data | |
| 961 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); | |
| 962 | + $question_option[ 'answer' ] = $answer; | |
| 963 | + $question_option[ 'option_class'] = $answer_class; | |
| 964 | + $question_option[ 'checked'] = $checked; | |
| 965 | + $question_option[ 'count' ] = $count; | |
| 966 | + $question_option[ 'type' ] = $answer_type; | |
| 983 | 967 | |
| 984 | - $answer_order = array(); | |
| 985 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); | |
| 986 | -                if( $answer_order_string ) { | |
| 968 | + // add the speci fic option to the list of options for this question | |
| 969 | + $question_answers_options[] = $question_option; | |
| 987 | 970 | |
| 988 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); | |
| 989 | -                    if( count( $answer_order ) > 0 ) { | |
| 971 | + } // end for each option | |
| 990 | 972 | |
| 991 | -                        foreach( $answer_order as $answer_id ) { | |
| 992 | 973 | |
| 993 | -                            if( isset( $question_answers_options[ $answer_id ] ) ) { | |
| 974 | + // Shuffle the array depending on the settings | |
| 975 | + $answer_options_sorted = array(); | |
| 976 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); | |
| 977 | +			if(  $random_order && $random_order == 'yes' ) { | |
| 994 | 978 | |
| 995 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; | |
| 996 | - unset( $question_answers_options[ $answer_id ] ); | |
| 979 | + $answer_options_sorted = $question_answers_options; | |
| 980 | + shuffle( $answer_options_sorted ); | |
| 997 | 981 | |
| 998 | - } | |
| 982 | +			} else { | |
| 999 | 983 | |
| 1000 | - } | |
| 984 | + $answer_order = array(); | |
| 985 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); | |
| 986 | +				if( $answer_order_string ) { | |
| 1001 | 987 | |
| 1002 | -                        if( count( $question_answers_options ) > 0 ) { | |
| 1003 | -                            foreach( $question_answers_options as $id => $answer ) { | |
| 988 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); | |
| 989 | +					if( count( $answer_order ) > 0 ) { | |
| 1004 | 990 | |
| 1005 | - $answer_options_sorted[ $id ] = $answer; | |
| 991 | +						foreach( $answer_order as $answer_id ) { | |
| 1006 | 992 | |
| 1007 | - } | |
| 1008 | - } | |
| 993 | +							if( isset( $question_answers_options[ $answer_id ] ) ) { | |
| 1009 | 994 | |
| 1010 | -                    }else{ | |
| 995 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; | |
| 996 | + unset( $question_answers_options[ $answer_id ] ); | |
| 1011 | 997 | |
| 1012 | - $answer_options_sorted = $question_answers_options; | |
| 998 | + } | |
| 1013 | 999 | |
| 1014 | - } | |
| 1000 | + } | |
| 1015 | 1001 | |
| 1016 | -                }else{ | |
| 1002 | +						if( count( $question_answers_options ) > 0 ) { | |
| 1003 | +							foreach( $question_answers_options as $id => $answer ) { | |
| 1017 | 1004 | |
| 1018 | - $answer_options_sorted = $question_answers_options; | |
| 1005 | + $answer_options_sorted[ $id ] = $answer; | |
| 1019 | 1006 | |
| 1020 | - } // end if $answer_order_string | |
| 1007 | + } | |
| 1008 | + } | |
| 1021 | 1009 | |
| 1022 | - } // end if random order | |
| 1010 | +					}else{ | |
| 1023 | 1011 | |
| 1012 | + $answer_options_sorted = $question_answers_options; | |
| 1024 | 1013 | |
| 1025 | - // assemble and setup the data for the templates data array | |
| 1026 | - $question_data[ 'answer_options' ] = $answer_options_sorted; | |
| 1014 | + } | |
| 1027 | 1015 | |
| 1028 | - } | |
| 1016 | +				}else{ | |
| 1029 | 1017 | |
| 1030 | - return $question_data; | |
| 1018 | + $answer_options_sorted = $question_answers_options; | |
| 1031 | 1019 | |
| 1032 | - }// end multiple_choice_load_question_data | |
| 1020 | + } // end if $answer_order_string | |
| 1033 | 1021 | |
| 1034 | - /** | |
| 1035 | - * Load the gap fill question data on the sensei_get_question_template_data | |
| 1036 | - * filter. | |
| 1037 | - * | |
| 1038 | - * @since 1.9.0 | |
| 1039 | - * | |
| 1040 | - * @param $question_data | |
| 1041 | - * @param $question_id | |
| 1042 | - * @param $quiz_id | |
| 1043 | - * | |
| 1044 | - * @return array() | |
| 1045 | - */ | |
| 1046 | -    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 1022 | + } // end if random order | |
| 1047 | 1023 | |
| 1048 | -        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 1049 | 1024 | |
| 1050 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); | |
| 1051 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; | |
| 1052 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; | |
| 1053 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; | |
| 1025 | + // assemble and setup the data for the templates data array | |
| 1026 | + $question_data[ 'answer_options' ] = $answer_options_sorted; | |
| 1054 | 1027 | |
| 1055 | - } | |
| 1028 | + } | |
| 1056 | 1029 | |
| 1057 | - return $question_data; | |
| 1030 | + return $question_data; | |
| 1058 | 1031 | |
| 1059 | - }// end gap_fill_load_question_data | |
| 1032 | + }// end multiple_choice_load_question_data | |
| 1033 | + | |
| 1034 | + /** | |
| 1035 | + * Load the gap fill question data on the sensei_get_question_template_data | |
| 1036 | + * filter. | |
| 1037 | + * | |
| 1038 | + * @since 1.9.0 | |
| 1039 | + * | |
| 1040 | + * @param $question_data | |
| 1041 | + * @param $question_id | |
| 1042 | + * @param $quiz_id | |
| 1043 | + * | |
| 1044 | + * @return array() | |
| 1045 | + */ | |
| 1046 | +	public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 1047 | + | |
| 1048 | +		if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 1049 | + | |
| 1050 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); | |
| 1051 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; | |
| 1052 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; | |
| 1053 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; | |
| 1054 | + | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + return $question_data; | |
| 1058 | + | |
| 1059 | + }// end gap_fill_load_question_data | |
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /** | |
| 1063 | - * Get the correct answer for a question | |
| 1064 | - * | |
| 1065 | - * @param $question_id | |
| 1066 | - * @return string $correct_answer or empty | |
| 1067 | - */ | |
| 1068 | -    public static function get_correct_answer( $question_id ){ | |
| 1062 | + /** | |
| 1063 | + * Get the correct answer for a question | |
| 1064 | + * | |
| 1065 | + * @param $question_id | |
| 1066 | + * @return string $correct_answer or empty | |
| 1067 | + */ | |
| 1068 | +	public static function get_correct_answer( $question_id ){ | |
| 1069 | 1069 | |
| 1070 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 1071 | - $type = Sensei()->question->get_question_type( $question_id ); | |
| 1072 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); | |
| 1073 | - $grade_type = 'manual-grade'; | |
| 1070 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 1071 | + $type = Sensei()->question->get_question_type( $question_id ); | |
| 1072 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); | |
| 1073 | + $grade_type = 'manual-grade'; | |
| 1074 | 1074 | |
| 1075 | -        if ('boolean'== $type ) { | |
| 1075 | +		if ('boolean'== $type ) { | |
| 1076 | 1076 | |
| 1077 | - $right_answer = ucfirst($right_answer); | |
| 1077 | + $right_answer = ucfirst($right_answer); | |
| 1078 | 1078 | |
| 1079 | -        }elseif( 'multiple-choice' == $type ) { | |
| 1079 | +		}elseif( 'multiple-choice' == $type ) { | |
| 1080 | 1080 | |
| 1081 | - $right_answer = (array) $right_answer; | |
| 1082 | - $right_answer = implode( ', ', $right_answer ); | |
| 1081 | + $right_answer = (array) $right_answer; | |
| 1082 | + $right_answer = implode( ', ', $right_answer ); | |
| 1083 | 1083 | |
| 1084 | -        }elseif( 'gap-fill' == $type ) { | |
| 1084 | +		}elseif( 'gap-fill' == $type ) { | |
| 1085 | 1085 | |
| 1086 | - $right_answer_array = explode( '||', $right_answer ); | |
| 1087 | -            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } | |
| 1088 | -            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } | |
| 1089 | -            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } | |
| 1086 | + $right_answer_array = explode( '||', $right_answer ); | |
| 1087 | +			if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } | |
| 1088 | +			if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } | |
| 1089 | +			if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } | |
| 1090 | 1090 | |
| 1091 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; | |
| 1091 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; | |
| 1092 | 1092 | |
| 1093 | -        }else{ | |
| 1093 | +		}else{ | |
| 1094 | 1094 | |
| 1095 | - // for non auto gradable question types no answer should be returned. | |
| 1096 | - $right_answer = ''; | |
| 1095 | + // for non auto gradable question types no answer should be returned. | |
| 1096 | + $right_answer = ''; | |
| 1097 | 1097 | |
| 1098 | - } | |
| 1098 | + } | |
| 1099 | 1099 | |
| 1100 | - return $right_answer; | |
| 1100 | + return $right_answer; | |
| 1101 | 1101 | |
| 1102 | - } // get_correct_answer | |
| 1102 | + } // get_correct_answer | |
| 1103 | 1103 | |
| 1104 | 1104 | } // End Class | 
| 1105 | 1105 | |
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | * | 
| 124 | 124 | * This function hooks into the quiz page and accepts the answer form save post. | 
| 125 | 125 | * @since 1.7.3 | 
| 126 | - * @return bool $saved; | |
| 126 | + * @return boolean|null $saved; | |
| 127 | 127 | */ | 
| 128 | 128 |      public function user_save_quiz_answers_listener(){ | 
| 129 | 129 | |
| @@ -214,7 +214,7 @@ discard block | ||
| 214 | 214 | * @param int $lesson_id | 
| 215 | 215 | * @param int $user_id | 
| 216 | 216 | * | 
| 217 | - * @return array $answers or false | |
| 217 | + * @return boolean $answers or false | |
| 218 | 218 | */ | 
| 219 | 219 |  	public function get_user_answers( $lesson_id, $user_id ){ | 
| 220 | 220 | |
| @@ -707,7 +707,7 @@ discard block | ||
| 707 | 707 | * @type int $question_id | 
| 708 | 708 | * @type int $question_grade | 
| 709 | 709 | * } | 
| 710 | - * @param $lesson_id | |
| 710 | + * @param integer $lesson_id | |
| 711 | 711 | * @param $user_id (Optional) will use the current user if not supplied | 
| 712 | 712 | * | 
| 713 | 713 | * @return bool | 
| @@ -754,7 +754,7 @@ discard block | ||
| 754 | 754 | * | 
| 755 | 755 | * @since 1.7.4 | 
| 756 | 756 | * | 
| 757 | - * @param $lesson_id | |
| 757 | + * @param integer $lesson_id | |
| 758 | 758 | * @param $user_id (Optional) will use the current user if not supplied | 
| 759 | 759 | * | 
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users | 
| @@ -1090,7 +1090,6 @@ discard block | ||
| 1090 | 1090 | * Filter the single title and add the Quiz to it. | 
| 1091 | 1091 | * | 
| 1092 | 1092 | * @param string $title | 
| 1093 | - * @param int $id title post id | |
| 1094 | 1093 | * @return string $quiz_title | 
| 1095 | 1094 | */ | 
| 1096 | 1095 |       public static function single_quiz_title( $title, $post_id ){ | 
| @@ -1,5 +1,8 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Quiz Class | 
| @@ -104,7 +107,7 @@ discard block | ||
| 104 | 107 | global $post; | 
| 105 | 108 |  			if( 'quiz' == get_post_type( $post ) ){ | 
| 106 | 109 | $quiz_id = $post->ID; | 
| 107 | -			}else{ | |
| 110 | +			} else{ | |
| 108 | 111 | return false; | 
| 109 | 112 | } | 
| 110 | 113 | |
| @@ -234,7 +237,7 @@ discard block | ||
| 234 | 237 | |
| 235 | 238 | $encoded_user_answers = $transient_cached_answers; | 
| 236 | 239 | |
| 237 | -        }else{ | |
| 240 | +        } else{ | |
| 238 | 241 | |
| 239 | 242 | $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | 
| 240 | 243 | |
| @@ -424,7 +427,7 @@ discard block | ||
| 424 | 427 | // compress the answer for saving | 
| 425 | 428 |  			if( 'multi-line' == $question_type ) { | 
| 426 | 429 | $answer = esc_html( $answer ); | 
| 427 | -            }elseif( 'file-upload' == $question_type  ){ | |
| 430 | +            } elseif( 'file-upload' == $question_type  ){ | |
| 428 | 431 | $file_key = 'file_upload_' . $question_id; | 
| 429 | 432 |                  if( isset( $files[ $file_key ] ) ) { | 
| 430 | 433 | $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); | 
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly | |
| 3 | 3 | |
| 4 | 4 | /** | 
| 5 | 5 | * Sensei Quiz Class | 
| @@ -23,24 +23,24 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @param $file | 
| 25 | 25 | */ | 
| 26 | -	public function __construct ( $file = __FILE__ ) { | |
| 26 | +	public function __construct($file = __FILE__) { | |
| 27 | 27 | $this->file = $file; | 
| 28 | - $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); | |
| 29 | - add_action( 'save_post', array( $this, 'update_author' )); | |
| 28 | +		$this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset'); | |
| 29 | +		add_action('save_post', array($this, 'update_author')); | |
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click | 
| 32 | - add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | |
| 32 | +		add_action('template_redirect', array($this, 'reset_button_click_listener')); | |
| 33 | 33 | |
| 34 | 34 | // fire the complete quiz button submit for grading action | 
| 35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); | |
| 35 | +        add_action('sensei_complete_quiz', array($this, 'user_quiz_submit_listener')); | |
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder | 
| 38 | - add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); | |
| 38 | +		add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener')); | |
| 39 | 39 | |
| 40 | 40 | // fire the load global data function | 
| 41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); | |
| 41 | +        add_action('sensei_complete_quiz', array($this, 'load_global_quiz_data'), 80); | |
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); | |
| 43 | +        add_action('template_redirect', array($this, 'quiz_has_no_questions')); | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | } // End __construct() | 
| @@ -51,26 +51,26 @@ discard block | ||
| 51 | 51 | * @param int $post_id | 
| 52 | 52 | * @return void | 
| 53 | 53 | */ | 
| 54 | -	public function update_author( $post_id ){ | |
| 54 | +	public function update_author($post_id) { | |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // If this isn't a 'lesson' post, don't update it. | 
| 58 | 58 | // if this is a revision don't save it | 
| 59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] | |
| 60 | -            || wp_is_post_revision( $post_id ) ) { | |
| 59 | + if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type'] | |
| 60 | +            || wp_is_post_revision($post_id)) { | |
| 61 | 61 | |
| 62 | 62 | return; | 
| 63 | 63 | |
| 64 | 64 | } | 
| 65 | 65 | // get the lesson author id to be use late | 
| 66 | - $saved_post = get_post( $post_id ); | |
| 67 | - $new_lesson_author_id = $saved_post->post_author; | |
| 66 | + $saved_post = get_post($post_id); | |
| 67 | + $new_lesson_author_id = $saved_post->post_author; | |
| 68 | 68 | |
| 69 | 69 | //get the lessons quiz | 
| 70 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); | |
| 71 | -	    foreach ( (array) $lesson_quizzes as $quiz_item ) { | |
| 70 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id); | |
| 71 | +	    foreach ((array) $lesson_quizzes as $quiz_item) { | |
| 72 | 72 | |
| 73 | -	    	if( ! $quiz_item ) { | |
| 73 | +	    	if ( ! $quiz_item) { | |
| 74 | 74 | continue; | 
| 75 | 75 | } | 
| 76 | 76 | |
| @@ -81,10 +81,10 @@ discard block | ||
| 81 | 81 | ); | 
| 82 | 82 | |
| 83 | 83 | // remove the action so that it doesn't fire again | 
| 84 | - remove_action( 'save_post', array( $this, 'update_author' )); | |
| 84 | +            remove_action('save_post', array($this, 'update_author')); | |
| 85 | 85 | |
| 86 | 86 | // Update the post into the database | 
| 87 | - wp_update_post( $my_post ); | |
| 87 | + wp_update_post($my_post); | |
| 88 | 88 | } | 
| 89 | 89 | |
| 90 | 90 | return; | 
| @@ -98,19 +98,19 @@ discard block | ||
| 98 | 98 | * @param int $quiz_id | 
| 99 | 99 | * @return int @lesson_id | 
| 100 | 100 | */ | 
| 101 | -	public function get_lesson_id( $quiz_id ){ | |
| 101 | +	public function get_lesson_id($quiz_id) { | |
| 102 | 102 | |
| 103 | -		if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){ | |
| 103 | +		if (empty($quiz_id) || ! intval($quiz_id) > 0) { | |
| 104 | 104 | global $post; | 
| 105 | -			if( 'quiz' == get_post_type( $post ) ){ | |
| 105 | +			if ('quiz' == get_post_type($post)) { | |
| 106 | 106 | $quiz_id = $post->ID; | 
| 107 | -			}else{ | |
| 107 | +			} else { | |
| 108 | 108 | return false; | 
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | - $quiz = get_post( $quiz_id ); | |
| 113 | + $quiz = get_post($quiz_id); | |
| 114 | 114 | $lesson_id = $quiz->post_parent; | 
| 115 | 115 | |
| 116 | 116 | return $lesson_id; | 
| @@ -125,23 +125,23 @@ discard block | ||
| 125 | 125 | * @since 1.7.3 | 
| 126 | 126 | * @return bool $saved; | 
| 127 | 127 | */ | 
| 128 | -    public function user_save_quiz_answers_listener(){ | |
| 128 | +    public function user_save_quiz_answers_listener() { | |
| 129 | 129 | |
| 130 | - if( ! isset( $_POST[ 'quiz_save' ]) | |
| 131 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 132 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 133 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) { | |
| 130 | + if ( ! isset($_POST['quiz_save']) | |
| 131 | + || ! isset($_POST['sensei_question']) | |
| 132 | + || empty($_POST['sensei_question']) | |
| 133 | +            ||  ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) { | |
| 134 | 134 | return; | 
| 135 | 135 | } | 
| 136 | 136 | |
| 137 | 137 | global $post; | 
| 138 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 139 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 138 | + $lesson_id = $this->get_lesson_id($post->ID); | |
| 139 | + $quiz_answers = $_POST['sensei_question']; | |
| 140 | 140 | // call the save function | 
| 141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); | |
| 141 | + self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id()); | |
| 142 | 142 | |
| 143 | 143 | // remove the hook as it should only fire once per click | 
| 144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); | |
| 144 | +        remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener'); | |
| 145 | 145 | |
| 146 | 146 | } // end user_save_quiz_answers_listener | 
| 147 | 147 | |
| @@ -160,17 +160,17 @@ discard block | ||
| 160 | 160 | * | 
| 161 | 161 | * @return false or int $answers_saved | 
| 162 | 162 | */ | 
| 163 | -	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ | |
| 163 | +	public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { | |
| 164 | 164 | |
| 165 | -        if( ! ( $user_id > 0 ) ){ | |
| 165 | +        if ( ! ($user_id > 0)) { | |
| 166 | 166 | $user_id = get_current_user_id(); | 
| 167 | 167 | } | 
| 168 | 168 | |
| 169 | 169 | // make sure the parameters are valid before continuing | 
| 170 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 171 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 172 | - ||!get_userdata( $user_id ) | |
| 173 | -			|| !is_array( $quiz_answers ) ){ | |
| 170 | + if (empty($lesson_id) || empty($user_id) | |
| 171 | + || 'lesson' != get_post_type($lesson_id) | |
| 172 | + ||! get_userdata($user_id) | |
| 173 | +			|| ! is_array($quiz_answers)) { | |
| 174 | 174 | |
| 175 | 175 | return false; | 
| 176 | 176 | |
| @@ -178,23 +178,23 @@ discard block | ||
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | // start the lesson before saving the data in case the user has not started the lesson | 
| 181 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 181 | + $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); | |
| 182 | 182 | |
| 183 | 183 | //prepare the answers | 
| 184 | - $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); | |
| 184 | + $prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files); | |
| 185 | 185 | |
| 186 | 186 | // save the user data | 
| 187 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; | |
| 187 | +        $answers_saved = Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id); | |
| 188 | 188 | |
| 189 | 189 | // were the answers saved correctly? | 
| 190 | -		if( intval( $answers_saved ) > 0){ | |
| 190 | +		if (intval($answers_saved) > 0) { | |
| 191 | 191 | |
| 192 | 192 | // save transient to make retrieval faster | 
| 193 | 193 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | 
| 194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); | |
| 194 | + set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS); | |
| 195 | 195 | |
| 196 | 196 | // update the message showed to user | 
| 197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 197 | +            Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>'; | |
| 198 | 198 | } | 
| 199 | 199 | |
| 200 | 200 | return $answers_saved; | 
| @@ -216,41 +216,41 @@ discard block | ||
| 216 | 216 | * | 
| 217 | 217 | * @return array $answers or false | 
| 218 | 218 | */ | 
| 219 | -	public function get_user_answers( $lesson_id, $user_id ){ | |
| 219 | +	public function get_user_answers($lesson_id, $user_id) { | |
| 220 | 220 | |
| 221 | 221 | $answers = false; | 
| 222 | 222 | |
| 223 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 224 | -		|| ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 223 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) | |
| 224 | +		|| ! intval($user_id) > 0 || ! get_userdata($user_id)) { | |
| 225 | 225 | return false; | 
| 226 | 226 | } | 
| 227 | 227 | |
| 228 | 228 | // save some time and get the transient cached data | 
| 229 | 229 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | 
| 230 | - $transient_cached_answers = get_transient( $transient_key ); | |
| 230 | + $transient_cached_answers = get_transient($transient_key); | |
| 231 | 231 | |
| 232 | 232 | // return the transient or get the values get the values from the comment meta | 
| 233 | -        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){ | |
| 233 | +        if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) { | |
| 234 | 234 | |
| 235 | 235 | $encoded_user_answers = $transient_cached_answers; | 
| 236 | 236 | |
| 237 | -        }else{ | |
| 237 | +        } else { | |
| 238 | 238 | |
| 239 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | |
| 239 | +            $encoded_user_answers = Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id); | |
| 240 | 240 | |
| 241 | 241 | } // end if transient check | 
| 242 | 242 | |
| 243 | -		if( ! is_array( $encoded_user_answers ) ){ | |
| 243 | +		if ( ! is_array($encoded_user_answers)) { | |
| 244 | 244 | return false; | 
| 245 | 245 | } | 
| 246 | 246 | |
| 247 | 247 | //set the transient with the new valid data for faster retrieval in future | 
| 248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 248 | + set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 249 | 249 | |
| 250 | 250 | // decode an unserialize all answers | 
| 251 | -		foreach( $encoded_user_answers as $question_id => $encoded_answer ) { | |
| 252 | - $decoded_answer = base64_decode( $encoded_answer ); | |
| 253 | - $answers[$question_id] = maybe_unserialize( $decoded_answer ); | |
| 251 | +		foreach ($encoded_user_answers as $question_id => $encoded_answer) { | |
| 252 | + $decoded_answer = base64_decode($encoded_answer); | |
| 253 | + $answers[$question_id] = maybe_unserialize($decoded_answer); | |
| 254 | 254 | } | 
| 255 | 255 | |
| 256 | 256 | return $answers; | 
| @@ -267,23 +267,23 @@ discard block | ||
| 267 | 267 | * | 
| 268 | 268 | * @return void; | 
| 269 | 269 | */ | 
| 270 | -	public function reset_button_click_listener( ){ | |
| 270 | +	public function reset_button_click_listener( ) { | |
| 271 | 271 | |
| 272 | - if( ! isset( $_POST[ 'quiz_reset' ]) | |
| 273 | -			||  ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce'  ) > 1 ) { | |
| 272 | + if ( ! isset($_POST['quiz_reset']) | |
| 273 | +			||  ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) { | |
| 274 | 274 | |
| 275 | 275 | return; // exit | 
| 276 | 276 | } | 
| 277 | 277 | |
| 278 | 278 | global $post; | 
| 279 | 279 | $current_quiz_id = $post->ID; | 
| 280 | - $lesson_id = $this->get_lesson_id( $current_quiz_id ); | |
| 280 | + $lesson_id = $this->get_lesson_id($current_quiz_id); | |
| 281 | 281 | |
| 282 | 282 | // reset all user data | 
| 283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); | |
| 283 | + $this->reset_user_lesson_data($lesson_id, get_current_user_id()); | |
| 284 | 284 | |
| 285 | 285 | //this function should only run once | 
| 286 | - remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | |
| 286 | +		remove_action('template_redirect', array($this, 'reset_button_click_listener')); | |
| 287 | 287 | |
| 288 | 288 | } // end reset_button_click_listener | 
| 289 | 289 | |
| @@ -302,18 +302,18 @@ discard block | ||
| 302 | 302 |  	public function user_quiz_submit_listener() { | 
| 303 | 303 | |
| 304 | 304 | // only respond to valid quiz completion submissions | 
| 305 | - if( ! isset( $_POST[ 'quiz_complete' ]) | |
| 306 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 307 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 308 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) { | |
| 305 | + if ( ! isset($_POST['quiz_complete']) | |
| 306 | + || ! isset($_POST['sensei_question']) | |
| 307 | + || empty($_POST['sensei_question']) | |
| 308 | +            ||  ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) { | |
| 309 | 309 | return; | 
| 310 | 310 | } | 
| 311 | 311 | |
| 312 | 312 | global $post, $current_user; | 
| 313 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 314 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 313 | + $lesson_id = $this->get_lesson_id($post->ID); | |
| 314 | + $quiz_answers = $_POST['sensei_question']; | |
| 315 | 315 | |
| 316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); | |
| 316 | + self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID); | |
| 317 | 317 | |
| 318 | 318 | } // End sensei_complete_quiz() | 
| 319 | 319 | |
| @@ -327,7 +327,7 @@ discard block | ||
| 327 | 327 | * @access public | 
| 328 | 328 | * | 
| 329 | 329 | */ | 
| 330 | -    public function load_global_quiz_data(){ | |
| 330 | +    public function load_global_quiz_data() { | |
| 331 | 331 | |
| 332 | 332 | global $post, $current_user; | 
| 333 | 333 | $this->data = new stdClass(); | 
| @@ -336,46 +336,46 @@ discard block | ||
| 336 | 336 | $grade = 0; | 
| 337 | 337 | |
| 338 | 338 | // Get Quiz Questions | 
| 339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); | |
| 339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID); | |
| 340 | 340 | |
| 341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); | |
| 341 | + $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true)); | |
| 342 | 342 | |
| 343 | 343 | // Get quiz grade type | 
| 344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); | |
| 344 | + $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true); | |
| 345 | 345 | |
| 346 | 346 | // Get quiz pass setting | 
| 347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); | |
| 347 | + $pass_required = get_post_meta($post->ID, '_pass_required', true); | |
| 348 | 348 | |
| 349 | 349 | // Get quiz pass mark | 
| 350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); | |
| 350 | + $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2)); | |
| 351 | 351 | |
| 352 | 352 | // Get latest quiz answers and grades | 
| 353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); | |
| 354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); | |
| 355 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); | |
| 353 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); | |
| 354 | + $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id()); | |
| 355 | + $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID); | |
| 356 | 356 | $user_quiz_grade = 0; | 
| 357 | -        if( isset( $user_lesson_status->comment_ID ) ) { | |
| 358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 357 | +        if (isset($user_lesson_status->comment_ID)) { | |
| 358 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); | |
| 359 | 359 | } | 
| 360 | 360 | |
| 361 | -        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } | |
| 361 | +        if ( ! is_array($user_quizzes)) { $user_quizzes = array(); } | |
| 362 | 362 | |
| 363 | 363 | // Check again that the lesson is complete | 
| 364 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); | |
| 364 | + $user_lesson_end = Sensei_Utils::user_completed_lesson($user_lesson_status); | |
| 365 | 365 | $user_lesson_complete = false; | 
| 366 | -        if ( $user_lesson_end ) { | |
| 366 | +        if ($user_lesson_end) { | |
| 367 | 367 | $user_lesson_complete = true; | 
| 368 | 368 | } // End If Statement | 
| 369 | 369 | |
| 370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); | |
| 370 | + $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); | |
| 371 | 371 | //backwards compatibility | 
| 372 | -        if( 'on' == $reset_allowed ) { | |
| 372 | +        if ('on' == $reset_allowed) { | |
| 373 | 373 | $reset_allowed = 1; | 
| 374 | 374 | } | 
| 375 | 375 | |
| 376 | 376 | // Build frontend data object for backwards compatibility | 
| 377 | 377 | // using this is no longer recommended | 
| 378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 378 | + $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 379 | 379 | $this->data->quiz_passmark = $quiz_passmark; | 
| 380 | 380 | $this->data->quiz_lesson = $quiz_lesson_id; | 
| 381 | 381 | $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); | 
| @@ -400,41 +400,41 @@ discard block | ||
| 400 | 400 | * @param $files | 
| 401 | 401 | * @return array | 
| 402 | 402 | */ | 
| 403 | -	public static function prepare_form_submitted_answers( $unprepared_answers,  $files ){ | |
| 403 | +	public static function prepare_form_submitted_answers($unprepared_answers, $files) { | |
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | $prepared_answers = array(); | 
| 407 | 407 | |
| 408 | 408 | // validate incoming answers | 
| 409 | -		if( empty( $unprepared_answers  ) || ! is_array( $unprepared_answers ) ){ | |
| 409 | +		if (empty($unprepared_answers) || ! is_array($unprepared_answers)) { | |
| 410 | 410 | return false; | 
| 411 | 411 | } | 
| 412 | 412 | |
| 413 | 413 | // Loop through submitted quiz answers and save them appropriately | 
| 414 | -		foreach( $unprepared_answers as $question_id => $answer ) { | |
| 414 | +		foreach ($unprepared_answers as $question_id => $answer) { | |
| 415 | 415 | |
| 416 | 416 | //get the current questions question type | 
| 417 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 417 | + $question_type = Sensei()->question->get_question_type($question_id); | |
| 418 | 418 | |
| 419 | 419 | // Sanitise answer | 
| 420 | -			if( 0 == get_magic_quotes_gpc() ) { | |
| 421 | - $answer = wp_unslash( $answer ); | |
| 420 | +			if (0 == get_magic_quotes_gpc()) { | |
| 421 | + $answer = wp_unslash($answer); | |
| 422 | 422 | } | 
| 423 | 423 | |
| 424 | 424 | // compress the answer for saving | 
| 425 | -			if( 'multi-line' == $question_type ) { | |
| 426 | - $answer = esc_html( $answer ); | |
| 427 | -            }elseif( 'file-upload' == $question_type  ){ | |
| 428 | - $file_key = 'file_upload_' . $question_id; | |
| 429 | -                if( isset( $files[ $file_key ] ) ) { | |
| 430 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); | |
| 431 | -                        if( $attachment_id ) { | |
| 425 | +			if ('multi-line' == $question_type) { | |
| 426 | + $answer = esc_html($answer); | |
| 427 | +            }elseif ('file-upload' == $question_type) { | |
| 428 | + $file_key = 'file_upload_'.$question_id; | |
| 429 | +                if (isset($files[$file_key])) { | |
| 430 | + $attachment_id = Sensei_Utils::upload_file($files[$file_key]); | |
| 431 | +                        if ($attachment_id) { | |
| 432 | 432 | $answer = $attachment_id; | 
| 433 | 433 | } | 
| 434 | 434 | } | 
| 435 | 435 | } // end if | 
| 436 | 436 | |
| 437 | - $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); | |
| 437 | + $prepared_answers[$question_id] = base64_encode(maybe_serialize($answer)); | |
| 438 | 438 | |
| 439 | 439 | }// end for each $quiz_answers | 
| 440 | 440 | |
| @@ -454,54 +454,54 @@ discard block | ||
| 454 | 454 | * @param int $user_id | 
| 455 | 455 | * @param int $lesson_id | 
| 456 | 456 | */ | 
| 457 | -    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ | |
| 457 | +    public function reset_user_lesson_data($lesson_id, $user_id = 0) { | |
| 458 | 458 | |
| 459 | 459 | //make sure the parameters are valid | 
| 460 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 461 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 462 | -            || ! get_userdata( $user_id ) ){ | |
| 460 | + if (empty($lesson_id) || empty($user_id) | |
| 461 | + || 'lesson' != get_post_type($lesson_id) | |
| 462 | +            || ! get_userdata($user_id)) { | |
| 463 | 463 | return false; | 
| 464 | 464 | } | 
| 465 | 465 | |
| 466 | 466 | |
| 467 | 467 | |
| 468 | 468 | //get the users lesson status to make | 
| 469 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 470 | -        if( ! isset( $user_lesson_status->comment_ID ) ) { | |
| 469 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); | |
| 470 | +        if ( ! isset($user_lesson_status->comment_ID)) { | |
| 471 | 471 | // this user is not taking this lesson so this process is not needed | 
| 472 | 472 | return false; | 
| 473 | 473 | } | 
| 474 | 474 | |
| 475 | 475 | //get the lesson quiz and course | 
| 476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); | |
| 476 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); | |
| 477 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); | |
| 478 | 478 | |
| 479 | 479 | // reset the transients | 
| 480 | 480 | $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | 
| 481 | 481 | $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | 
| 482 | 482 | $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | 
| 483 | - delete_transient( $answers_transient_key ); | |
| 484 | - delete_transient( $grades_transient_key ); | |
| 485 | - delete_transient( $answers_feedback_transient_key ); | |
| 483 | + delete_transient($answers_transient_key); | |
| 484 | + delete_transient($grades_transient_key); | |
| 485 | + delete_transient($answers_feedback_transient_key); | |
| 486 | 486 | |
| 487 | 487 | // reset the quiz answers and feedback notes | 
| 488 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); | |
| 489 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 490 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 488 | +        $deleted_answers = Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id); | |
| 489 | +        $deleted_grades = Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id); | |
| 490 | +        $deleted_user_feedback = Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id); | |
| 491 | 491 | |
| 492 | 492 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade | 
| 493 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); | |
| 493 | + Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id); | |
| 494 | 494 | |
| 495 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); | |
| 495 | +        Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => '')); | |
| 496 | 496 | |
| 497 | 497 | // Update course completion | 
| 498 | - Sensei_Utils::update_course_status( $user_id, $course_id ); | |
| 498 | + Sensei_Utils::update_course_status($user_id, $course_id); | |
| 499 | 499 | |
| 500 | 500 | // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() | 
| 501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); | |
| 502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 501 | +        do_action('sensei_user_lesson_reset', $user_id, $lesson_id); | |
| 502 | +        Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>'; | |
| 503 | 503 | |
| 504 | - return ( $deleted_answers && $deleted_grades ) ; | |
| 504 | + return ($deleted_answers && $deleted_grades); | |
| 505 | 505 | |
| 506 | 506 | } // end reset_user_lesson_data | 
| 507 | 507 | |
| @@ -521,20 +521,20 @@ discard block | ||
| 521 | 521 | * | 
| 522 | 522 | * @return bool $answers_submitted | 
| 523 | 523 | */ | 
| 524 | -     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ | |
| 524 | +     public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { | |
| 525 | 525 | |
| 526 | 526 | $answers_submitted = false; | 
| 527 | 527 | |
| 528 | 528 | // get the user_id if none was passed in use the current logged in user | 
| 529 | -         if( ! intval( $user_id ) > 0 ) { | |
| 529 | +         if ( ! intval($user_id) > 0) { | |
| 530 | 530 | $user_id = get_current_user_id(); | 
| 531 | 531 | } | 
| 532 | 532 | |
| 533 | 533 | // make sure the parameters are valid before continuing | 
| 534 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 535 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 536 | - ||!get_userdata( $user_id ) | |
| 537 | -             || !is_array( $quiz_answers ) ){ | |
| 534 | + if (empty($lesson_id) || empty($user_id) | |
| 535 | + || 'lesson' != get_post_type($lesson_id) | |
| 536 | + ||! get_userdata($user_id) | |
| 537 | +             || ! is_array($quiz_answers)) { | |
| 538 | 538 | |
| 539 | 539 | return false; | 
| 540 | 540 | |
| @@ -544,38 +544,38 @@ discard block | ||
| 544 | 544 | $grade = 0; | 
| 545 | 545 | |
| 546 | 546 | // Get Quiz ID | 
| 547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 547 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); | |
| 548 | 548 | |
| 549 | 549 | // Get quiz grade type | 
| 550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 550 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); | |
| 551 | 551 | |
| 552 | 552 | // Get quiz pass setting | 
| 553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 553 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); | |
| 554 | 554 | |
| 555 | 555 | // Get the minimum percentage need to pass this quiz | 
| 556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 556 | + $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); | |
| 557 | 557 | |
| 558 | 558 | // Handle Quiz Questions asked | 
| 559 | 559 | // This is to ensure we save the questions that we've asked this user and that this can't be change unless | 
| 560 | 560 | // the quiz is reset by admin or user( user: only if the setting is enabled ). | 
| 561 | 561 | // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions | 
| 562 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); | |
| 564 | -         if( empty( $questions_asked ) ){ | |
| 562 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); | |
| 563 | + $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); | |
| 564 | +         if (empty($questions_asked)) { | |
| 565 | 565 | |
| 566 | - $questions_asked = array_keys( $quiz_answers ); | |
| 567 | - $questions_asked_string = implode( ',', $questions_asked ); | |
| 566 | + $questions_asked = array_keys($quiz_answers); | |
| 567 | +             $questions_asked_string = implode(',', $questions_asked); | |
| 568 | 568 | |
| 569 | 569 | // Save questions that were asked in this quiz | 
| 570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); | |
| 570 | + update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string); | |
| 571 | 571 | |
| 572 | 572 | } | 
| 573 | 573 | |
| 574 | 574 | // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson | 
| 575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); | |
| 575 | + self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id); | |
| 576 | 576 | |
| 577 | 577 | // Grade quiz | 
| 578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); | |
| 578 | + $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type); | |
| 579 | 579 | |
| 580 | 580 | // Get Lesson Grading Setting | 
| 581 | 581 | $lesson_metadata = array(); | 
| @@ -585,13 +585,13 @@ discard block | ||
| 585 | 585 | $answers_submitted = true; | 
| 586 | 586 | |
| 587 | 587 | // if this condition is false the quiz should manually be graded by admin | 
| 588 | -         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) { | |
| 588 | +         if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) { | |
| 589 | 589 | |
| 590 | 590 | // Quiz has been automatically Graded | 
| 591 | -             if ( 'on' == $pass_required ) { | |
| 591 | +             if ('on' == $pass_required) { | |
| 592 | 592 | |
| 593 | 593 | // Student has reached the pass mark and lesson is complete | 
| 594 | -                 if ( $quiz_pass_percentage <= $grade ) { | |
| 594 | +                 if ($quiz_pass_percentage <= $grade) { | |
| 595 | 595 | |
| 596 | 596 | $lesson_status = 'passed'; | 
| 597 | 597 | |
| @@ -612,9 +612,9 @@ discard block | ||
| 612 | 612 | |
| 613 | 613 | } // end if ! is_wp_error( $grade ... | 
| 614 | 614 | |
| 615 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); | |
| 615 | + Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata); | |
| 616 | 616 | |
| 617 | -         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ | |
| 617 | +         if ('passed' == $lesson_status || 'graded' == $lesson_status) { | |
| 618 | 618 | |
| 619 | 619 | /** | 
| 620 | 620 | * Lesson end action hook | 
| @@ -624,7 +624,7 @@ discard block | ||
| 624 | 624 | * @param int $user_id | 
| 625 | 625 | * @param int $lesson_id | 
| 626 | 626 | */ | 
| 627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); | |
| 627 | +             do_action('sensei_user_lesson_end', $user_id, $lesson_id); | |
| 628 | 628 | |
| 629 | 629 | } | 
| 630 | 630 | |
| @@ -640,7 +640,7 @@ discard block | ||
| 640 | 640 | * @param string $quiz_pass_percentage | 
| 641 | 641 | * @param string $quiz_grade_type | 
| 642 | 642 | */ | 
| 643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); | |
| 643 | +         do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type); | |
| 644 | 644 | |
| 645 | 645 | return $answers_submitted; | 
| 646 | 646 | |
| @@ -660,38 +660,38 @@ discard block | ||
| 660 | 660 | * | 
| 661 | 661 | * @return bool $answers_submitted | 
| 662 | 662 | */ | 
| 663 | -     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ | |
| 663 | +     public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) { | |
| 664 | 664 | |
| 665 | 665 | // parameter validation | 
| 666 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 667 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 668 | - || ! ( intval( $question_id ) > 0 ) | |
| 669 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 670 | -             || 'question' != get_post_type( $question_id )) { | |
| 666 | + if (empty($lesson_id) || empty($question_id) | |
| 667 | + || ! (intval($lesson_id) > 0) | |
| 668 | + || ! (intval($question_id) > 0) | |
| 669 | + || 'lesson' != get_post_type($lesson_id) | |
| 670 | +             || 'question' != get_post_type($question_id)) { | |
| 671 | 671 | |
| 672 | 672 | return false; | 
| 673 | 673 | } | 
| 674 | 674 | |
| 675 | -         if( ! ( intval( $user_id ) > 0 )   ){ | |
| 675 | +         if ( ! (intval($user_id) > 0)) { | |
| 676 | 676 | $user_id = get_current_user_id(); | 
| 677 | 677 | } | 
| 678 | 678 | |
| 679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); | |
| 679 | + $users_answers = $this->get_user_answers($lesson_id, $user_id); | |
| 680 | 680 | |
| 681 | - if( !$users_answers || empty( $users_answers ) | |
| 682 | -         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ | |
| 681 | + if ( ! $users_answers || empty($users_answers) | |
| 682 | +         ||  ! is_array($users_answers) || ! isset($users_answers[$question_id])) { | |
| 683 | 683 | |
| 684 | 684 | //Fallback for pre 1.7.4 data | 
| 685 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); | |
| 685 | +             $comment = Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true); | |
| 686 | 686 | |
| 687 | -             if( ! isset( $comment->comment_content ) ){ | |
| 687 | +             if ( ! isset($comment->comment_content)) { | |
| 688 | 688 | return false; | 
| 689 | 689 | } | 
| 690 | 690 | |
| 691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); | |
| 691 | + return maybe_unserialize(base64_decode($comment->comment_content)); | |
| 692 | 692 | } | 
| 693 | 693 | |
| 694 | - return $users_answers[ $question_id ]; | |
| 694 | + return $users_answers[$question_id]; | |
| 695 | 695 | |
| 696 | 696 | }// end get_user_question_answer | 
| 697 | 697 | |
| @@ -712,18 +712,18 @@ discard block | ||
| 712 | 712 | * | 
| 713 | 713 | * @return bool | 
| 714 | 714 | */ | 
| 715 | -     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ | |
| 715 | +     public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) { | |
| 716 | 716 | |
| 717 | 717 | // get the user_id if none was passed in use the current logged in user | 
| 718 | -         if( ! intval( $user_id ) > 0 ) { | |
| 718 | +         if ( ! intval($user_id) > 0) { | |
| 719 | 719 | $user_id = get_current_user_id(); | 
| 720 | 720 | } | 
| 721 | 721 | |
| 722 | 722 | // make sure the parameters are valid before continuing | 
| 723 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 724 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 725 | - ||!get_userdata( $user_id ) | |
| 726 | -             || !is_array( $quiz_grades ) ){ | |
| 723 | + if (empty($lesson_id) || empty($user_id) | |
| 724 | + || 'lesson' != get_post_type($lesson_id) | |
| 725 | + ||! get_userdata($user_id) | |
| 726 | +             || ! is_array($quiz_grades)) { | |
| 727 | 727 | |
| 728 | 728 | return false; | 
| 729 | 729 | |
| @@ -732,15 +732,15 @@ discard block | ||
| 732 | 732 | $success = false; | 
| 733 | 733 | |
| 734 | 734 | // save that data for the user on the lesson comment meta | 
| 735 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); | |
| 735 | +         $comment_meta_id = Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id); | |
| 736 | 736 | |
| 737 | 737 | // were the grades save successfully ? | 
| 738 | -         if( intval( $comment_meta_id ) > 0 ) { | |
| 738 | +         if (intval($comment_meta_id) > 0) { | |
| 739 | 739 | |
| 740 | 740 | $success = true; | 
| 741 | 741 | // save transient | 
| 742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); | |
| 742 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 743 | + set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS); | |
| 744 | 744 | } | 
| 745 | 745 | |
| 746 | 746 | return $success; | 
| @@ -759,36 +759,36 @@ discard block | ||
| 759 | 759 | * | 
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users | 
| 761 | 761 | */ | 
| 762 | -     public function get_user_grades( $lesson_id, $user_id = 0 ){ | |
| 762 | +     public function get_user_grades($lesson_id, $user_id = 0) { | |
| 763 | 763 | |
| 764 | 764 | $user_grades = array(); | 
| 765 | 765 | |
| 766 | 766 | // get the user_id if none was passed in use the current logged in user | 
| 767 | -         if( ! intval( $user_id ) > 0 ) { | |
| 767 | +         if ( ! intval($user_id) > 0) { | |
| 768 | 768 | $user_id = get_current_user_id(); | 
| 769 | 769 | } | 
| 770 | 770 | |
| 771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 772 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 771 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) | |
| 772 | +             || ! intval($user_id) > 0 || ! get_userdata($user_id)) { | |
| 773 | 773 | return false; | 
| 774 | 774 | } | 
| 775 | 775 | |
| 776 | 776 | // save some time and get the transient cached data | 
| 777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 778 | - $user_grades = get_transient( $transient_key ); | |
| 777 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 778 | + $user_grades = get_transient($transient_key); | |
| 779 | 779 | |
| 780 | 780 | // get the data if nothing was stored in the transient | 
| 781 | -         if( empty( $user_grades  ) || false != $user_grades ){ | |
| 781 | +         if (empty($user_grades) || false != $user_grades) { | |
| 782 | 782 | |
| 783 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 783 | +             $user_grades = Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id); | |
| 784 | 784 | |
| 785 | 785 | //set the transient with the new valid data for faster retrieval in future | 
| 786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); | |
| 786 | + set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS); | |
| 787 | 787 | |
| 788 | 788 | } // end if transient check | 
| 789 | 789 | |
| 790 | 790 | // if there is no data for this user | 
| 791 | -         if( ! is_array( $user_grades ) ){ | |
| 791 | +         if ( ! is_array($user_grades)) { | |
| 792 | 792 | return false; | 
| 793 | 793 | } | 
| 794 | 794 | |
| @@ -811,21 +811,21 @@ discard block | ||
| 811 | 811 | * | 
| 812 | 812 | * @return bool $question_grade | 
| 813 | 813 | */ | 
| 814 | -     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ | |
| 814 | +     public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) { | |
| 815 | 815 | |
| 816 | 816 | // parameter validation | 
| 817 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 818 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 819 | - || ! ( intval( $question_id ) > 0 ) | |
| 820 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 821 | -             || 'question' != get_post_type( $question_id )) { | |
| 817 | + if (empty($lesson_id) || empty($question_id) | |
| 818 | + || ! (intval($lesson_id) > 0) | |
| 819 | + || ! (intval($question_id) > 0) | |
| 820 | + || 'lesson' != get_post_type($lesson_id) | |
| 821 | +             || 'question' != get_post_type($question_id)) { | |
| 822 | 822 | |
| 823 | 823 | return false; | 
| 824 | 824 | } | 
| 825 | 825 | |
| 826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); | |
| 826 | + $all_user_grades = self::get_user_grades($lesson_id, $user_id); | |
| 827 | 827 | |
| 828 | -         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){ | |
| 828 | +         if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) { | |
| 829 | 829 | |
| 830 | 830 | //fallback to data pre 1.7.4 | 
| 831 | 831 | $args = array( | 
| @@ -834,17 +834,17 @@ discard block | ||
| 834 | 834 | 'type' => 'sensei_user_answer' | 
| 835 | 835 | ); | 
| 836 | 836 | |
| 837 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 837 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); | |
| 838 | 838 | $fall_back_grade = false; | 
| 839 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); | |
| 839 | +             if (isset($question_activity->comment_ID)) { | |
| 840 | + $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true); | |
| 841 | 841 | } | 
| 842 | 842 | |
| 843 | 843 | return $fall_back_grade; | 
| 844 | 844 | |
| 845 | 845 | } // end if $all_user_grades... | 
| 846 | 846 | |
| 847 | - return $all_user_grades[ $question_id ]; | |
| 847 | + return $all_user_grades[$question_id]; | |
| 848 | 848 | |
| 849 | 849 | }// end get_user_question_grade | 
| 850 | 850 | |
| @@ -866,13 +866,13 @@ discard block | ||
| 866 | 866 | * | 
| 867 | 867 | * @return false or int $feedback_saved | 
| 868 | 868 | */ | 
| 869 | -    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ | |
| 869 | +    public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) { | |
| 870 | 870 | |
| 871 | 871 | // make sure the parameters are valid before continuing | 
| 872 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 873 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 874 | - ||!get_userdata( $user_id ) | |
| 875 | -            || !is_array( $answers_feedback ) ){ | |
| 872 | + if (empty($lesson_id) || empty($user_id) | |
| 873 | + || 'lesson' != get_post_type($lesson_id) | |
| 874 | + ||! get_userdata($user_id) | |
| 875 | +            || ! is_array($answers_feedback)) { | |
| 876 | 876 | |
| 877 | 877 | return false; | 
| 878 | 878 | |
| @@ -880,25 +880,25 @@ discard block | ||
| 880 | 880 | |
| 881 | 881 | |
| 882 | 882 | // check if the lesson is started before saving, if not start the lesson for the user | 
| 883 | -        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { | |
| 884 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 883 | +        if ( ! (0 < intval(Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) { | |
| 884 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); | |
| 885 | 885 | } | 
| 886 | 886 | |
| 887 | 887 | // encode the feedback | 
| 888 | - $encoded_answers_feedback = array(); | |
| 889 | -        foreach( $answers_feedback as $question_id => $feedback ){ | |
| 890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); | |
| 888 | + $encoded_answers_feedback = array(); | |
| 889 | +        foreach ($answers_feedback as $question_id => $feedback) { | |
| 890 | + $encoded_answers_feedback[$question_id] = base64_encode($feedback); | |
| 891 | 891 | } | 
| 892 | 892 | |
| 893 | 893 | // save the user data | 
| 894 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; | |
| 894 | +        $feedback_saved = Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id); | |
| 895 | 895 | |
| 896 | 896 | //Were the the question feedback save correctly? | 
| 897 | -        if( intval( $feedback_saved ) > 0){ | |
| 897 | +        if (intval($feedback_saved) > 0) { | |
| 898 | 898 | |
| 899 | 899 | // save transient to make retrieval faster in future | 
| 900 | 900 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | 
| 901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); | |
| 901 | + set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS); | |
| 902 | 902 | |
| 903 | 903 | } | 
| 904 | 904 | |
| @@ -923,42 +923,42 @@ discard block | ||
| 923 | 923 | * $type string $question_feedback | 
| 924 | 924 | * } | 
| 925 | 925 | */ | 
| 926 | -     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ | |
| 926 | +     public function get_user_answers_feedback($lesson_id, $user_id = 0) { | |
| 927 | 927 | |
| 928 | 928 | $answers_feedback = array(); | 
| 929 | 929 | |
| 930 | 930 | // get the user_id if none was passed in use the current logged in user | 
| 931 | -         if( ! intval( $user_id ) > 0 ) { | |
| 931 | +         if ( ! intval($user_id) > 0) { | |
| 932 | 932 | $user_id = get_current_user_id(); | 
| 933 | 933 | } | 
| 934 | 934 | |
| 935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 936 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 935 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) | |
| 936 | +             || ! intval($user_id) > 0 || ! get_userdata($user_id)) { | |
| 937 | 937 | return false; | 
| 938 | 938 | } | 
| 939 | 939 | |
| 940 | 940 | // first check the transient to save a few split seconds | 
| 941 | 941 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | 
| 942 | - $encoded_feedback = get_transient( $transient_key ); | |
| 942 | + $encoded_feedback = get_transient($transient_key); | |
| 943 | 943 | |
| 944 | 944 | // get the data if nothing was stored in the transient | 
| 945 | -         if( empty( $encoded_feedback  ) || !$encoded_feedback ){ | |
| 945 | +         if (empty($encoded_feedback) || ! $encoded_feedback) { | |
| 946 | 946 | |
| 947 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 947 | +             $encoded_feedback = Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id); | |
| 948 | 948 | |
| 949 | 949 | //set the transient with the new valid data for faster retrieval in future | 
| 950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 950 | + set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 951 | 951 | |
| 952 | 952 | } // end if transient check | 
| 953 | 953 | |
| 954 | 954 | // if there is no data for this user | 
| 955 | -         if( ! is_array( $encoded_feedback ) ){ | |
| 955 | +         if ( ! is_array($encoded_feedback)) { | |
| 956 | 956 | return false; | 
| 957 | 957 | } | 
| 958 | 958 | |
| 959 | -         foreach( $encoded_feedback as $question_id => $feedback ){ | |
| 959 | +         foreach ($encoded_feedback as $question_id => $feedback) { | |
| 960 | 960 | |
| 961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); | |
| 961 | + $answers_feedback[$question_id] = base64_decode($feedback); | |
| 962 | 962 | |
| 963 | 963 | } | 
| 964 | 964 | |
| @@ -981,25 +981,25 @@ discard block | ||
| 981 | 981 | * | 
| 982 | 982 | * @return string $feedback or bool if false | 
| 983 | 983 | */ | 
| 984 | -     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ | |
| 984 | +     public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) { | |
| 985 | 985 | |
| 986 | 986 | $feedback = false; | 
| 987 | 987 | |
| 988 | 988 | // parameter validation | 
| 989 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 990 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 991 | - || ! ( intval( $question_id ) > 0 ) | |
| 992 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 993 | -             || 'question' != get_post_type( $question_id )) { | |
| 989 | + if (empty($lesson_id) || empty($question_id) | |
| 990 | + || ! (intval($lesson_id) > 0) | |
| 991 | + || ! (intval($question_id) > 0) | |
| 992 | + || 'lesson' != get_post_type($lesson_id) | |
| 993 | +             || 'question' != get_post_type($question_id)) { | |
| 994 | 994 | |
| 995 | 995 | return false; | 
| 996 | 996 | } | 
| 997 | 997 | |
| 998 | 998 | // get all the feedback for the user on the given lesson | 
| 999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); | |
| 999 | + $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id); | |
| 1000 | 1000 | |
| 1001 | - if( !$all_feedback || empty( $all_feedback ) | |
| 1002 | -             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ | |
| 1001 | + if ( ! $all_feedback || empty($all_feedback) | |
| 1002 | +             || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) { | |
| 1003 | 1003 | |
| 1004 | 1004 | //fallback to data pre 1.7.4 | 
| 1005 | 1005 | |
| @@ -1009,23 +1009,23 @@ discard block | ||
| 1009 | 1009 | 'user_id' => $user_id, | 
| 1010 | 1010 | 'type' => 'sensei_user_answer' | 
| 1011 | 1011 | ); | 
| 1012 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 1012 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); | |
| 1013 | 1013 | |
| 1014 | 1014 | // set the default to false and return that if no old data is available. | 
| 1015 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); | |
| 1015 | +             if (isset($question_activity->comment_ID)) { | |
| 1016 | + $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true)); | |
| 1017 | 1017 | } | 
| 1018 | 1018 | |
| 1019 | 1019 | // finally use the default question feedback | 
| 1020 | -             if( empty( $feedback ) ){ | |
| 1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); | |
| 1020 | +             if (empty($feedback)) { | |
| 1021 | + $feedback = get_post_meta($question_id, '_answer_feedback', true); | |
| 1022 | 1022 | } | 
| 1023 | 1023 | |
| 1024 | 1024 | return $feedback; | 
| 1025 | 1025 | |
| 1026 | 1026 | } | 
| 1027 | 1027 | |
| 1028 | - return $all_feedback[ $question_id ]; | |
| 1028 | + return $all_feedback[$question_id]; | |
| 1029 | 1029 | |
| 1030 | 1030 | } // end get_user_question_feedback | 
| 1031 | 1031 | |
| @@ -1044,7 +1044,7 @@ discard block | ||
| 1044 | 1044 |       public function quiz_has_no_questions() { | 
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | -         if( ! is_singular( 'quiz' ) )  { | |
| 1047 | +         if ( ! is_singular('quiz')) { | |
| 1048 | 1048 | return; | 
| 1049 | 1049 | } | 
| 1050 | 1050 | |
| @@ -1052,11 +1052,11 @@ discard block | ||
| 1052 | 1052 | |
| 1053 | 1053 | $lesson_id = $this->get_lesson_id($post->ID); | 
| 1054 | 1054 | |
| 1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); | |
| 1055 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); | |
| 1056 | 1056 | |
| 1057 | 1057 | $lesson = get_post($lesson_id); | 
| 1058 | 1058 | |
| 1059 | -         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { | |
| 1059 | +         if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") { | |
| 1060 | 1060 | |
| 1061 | 1061 | wp_redirect(get_permalink($lesson->ID), 301); | 
| 1062 | 1062 | exit; | 
| @@ -1070,7 +1070,7 @@ discard block | ||
| 1070 | 1070 | * | 
| 1071 | 1071 | * @deprecated since 1.9.0 | 
| 1072 | 1072 | */ | 
| 1073 | - public static function deprecate_quiz_sensei_single_main_content_hook(){ | |
| 1073 | + public static function deprecate_quiz_sensei_single_main_content_hook() { | |
| 1074 | 1074 | |
| 1075 | 1075 |       sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); | 
| 1076 | 1076 | |
| @@ -1080,7 +1080,7 @@ discard block | ||
| 1080 | 1080 | * | 
| 1081 | 1081 | * @deprecated since 1.9.0 | 
| 1082 | 1082 | */ | 
| 1083 | -     public static function deprecate_quiz_sensei_quiz_single_title_hook(){ | |
| 1083 | +     public static function deprecate_quiz_sensei_quiz_single_title_hook() { | |
| 1084 | 1084 | |
| 1085 | 1085 |           sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); | 
| 1086 | 1086 | |
| @@ -1093,29 +1093,29 @@ discard block | ||
| 1093 | 1093 | * @param int $id title post id | 
| 1094 | 1094 | * @return string $quiz_title | 
| 1095 | 1095 | */ | 
| 1096 | -     public static function single_quiz_title( $title, $post_id ){ | |
| 1096 | +     public static function single_quiz_title($title, $post_id) { | |
| 1097 | 1097 | |
| 1098 | -         if( 'quiz' == get_post_type( $post_id ) ){ | |
| 1098 | +         if ('quiz' == get_post_type($post_id)) { | |
| 1099 | 1099 | |
| 1100 | 1100 | $title_with_no_quizzes = $title; | 
| 1101 | 1101 | |
| 1102 | 1102 | // if the title has quiz, remove it: legacy titles have the word quiz stored. | 
| 1103 | -             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ | |
| 1103 | +             if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) { | |
| 1104 | 1104 | |
| 1105 | 1105 | // remove all possible appearances of quiz | 
| 1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); | |
| 1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); | |
| 1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); | |
| 1106 | +                 $title_with_no_quizzes = str_replace('quiz', '', $title); | |
| 1107 | +                 $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes); | |
| 1108 | +                 $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes); | |
| 1109 | 1109 | |
| 1110 | 1110 | } | 
| 1111 | 1111 | |
| 1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); | |
| 1112 | +             $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei'); | |
| 1113 | 1113 | } | 
| 1114 | 1114 | |
| 1115 | 1115 | /** | 
| 1116 | 1116 | * hook document in class-woothemes-sensei-message.php | 
| 1117 | 1117 | */ | 
| 1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); | |
| 1118 | +         return apply_filters('sensei_single_title', $title, get_post_type( )); | |
| 1119 | 1119 | |
| 1120 | 1120 | } | 
| 1121 | 1121 | |
| @@ -1127,21 +1127,21 @@ discard block | ||
| 1127 | 1127 | * @since 1.9.0 | 
| 1128 | 1128 | * | 
| 1129 | 1129 | */ | 
| 1130 | -     public static function start_quiz_questions_loop(){ | |
| 1130 | +     public static function start_quiz_questions_loop() { | |
| 1131 | 1131 | |
| 1132 | 1132 | global $sensei_question_loop; | 
| 1133 | 1133 | |
| 1134 | 1134 | //intialize the questions loop object | 
| 1135 | 1135 | $sensei_question_loop['current'] = -1; | 
| 1136 | - $sensei_question_loop['total'] = 0; | |
| 1136 | + $sensei_question_loop['total'] = 0; | |
| 1137 | 1137 | $sensei_question_loop['questions'] = array(); | 
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| 1140 | + $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID()); | |
| 1141 | 1141 | |
| 1142 | -         if( count( $questions  ) > 0  ){ | |
| 1142 | +         if (count($questions) > 0) { | |
| 1143 | 1143 | |
| 1144 | - $sensei_question_loop['total'] = count( $questions ); | |
| 1144 | + $sensei_question_loop['total'] = count($questions); | |
| 1145 | 1145 | $sensei_question_loop['questions'] = $questions; | 
| 1146 | 1146 | $sensei_question_loop['quiz_id'] = get_the_ID(); | 
| 1147 | 1147 | |
| @@ -1157,9 +1157,9 @@ discard block | ||
| 1157 | 1157 | * @since 1.9.0 | 
| 1158 | 1158 | * | 
| 1159 | 1159 | */ | 
| 1160 | -     public static function stop_quiz_questions_loop(){ | |
| 1160 | +     public static function stop_quiz_questions_loop() { | |
| 1161 | 1161 | |
| 1162 | - $sensei_question_loop['total'] = 0; | |
| 1162 | + $sensei_question_loop['total'] = 0; | |
| 1163 | 1163 | $sensei_question_loop['questions'] = array(); | 
| 1164 | 1164 | $sensei_question_loop['quiz_id'] = ''; | 
| 1165 | 1165 | |
| @@ -1170,7 +1170,7 @@ discard block | ||
| 1170 | 1170 | * | 
| 1171 | 1171 | * @since 1.9.0 | 
| 1172 | 1172 | */ | 
| 1173 | -     public static function the_title(){ | |
| 1173 | +     public static function the_title() { | |
| 1174 | 1174 | ?> | 
| 1175 | 1175 | <header> | 
| 1176 | 1176 | |
| @@ -1180,7 +1180,7 @@ discard block | ||
| 1180 | 1180 | /** | 
| 1181 | 1181 | * Filter documented in class-sensei-messages.php the_title | 
| 1182 | 1182 | */ | 
| 1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); | |
| 1183 | +                 echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID())); | |
| 1184 | 1184 | ?> | 
| 1185 | 1185 | |
| 1186 | 1186 | </h1> | 
| @@ -1195,11 +1195,11 @@ discard block | ||
| 1195 | 1195 | * | 
| 1196 | 1196 | * @param $quiz_id | 
| 1197 | 1197 | */ | 
| 1198 | -    public static function  the_user_status_message( $quiz_id ){ | |
| 1198 | +    public static function  the_user_status_message($quiz_id) { | |
| 1199 | 1199 | |
| 1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 1201 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); | |
| 1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; | |
| 1200 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); | |
| 1201 | + $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id()); | |
| 1202 | + echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>'; | |
| 1203 | 1203 | |
| 1204 | 1204 | } | 
| 1205 | 1205 | |
| @@ -1210,9 +1210,9 @@ discard block | ||
| 1210 | 1210 | * @since 1.9.0 | 
| 1211 | 1211 | * @deprecated | 
| 1212 | 1212 | */ | 
| 1213 | -     public static function deprecate_sensei_quiz_action_buttons_hook(){ | |
| 1213 | +     public static function deprecate_sensei_quiz_action_buttons_hook() { | |
| 1214 | 1214 | |
| 1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1215 | +         sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1216 | 1216 | |
| 1217 | 1217 | } | 
| 1218 | 1218 | |
| @@ -1226,50 +1226,50 @@ discard block | ||
| 1226 | 1226 | |
| 1227 | 1227 | global $post, $current_user; | 
| 1228 | 1228 | |
| 1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); | |
| 1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); | |
| 1229 | + $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true); | |
| 1230 | + $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true); | |
| 1231 | + $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); | |
| 1232 | 1232 | $show_actions = true; | 
| 1233 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); | |
| 1233 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID); | |
| 1234 | 1234 | |
| 1235 | 1235 | //setup quiz grade | 
| 1236 | 1236 | $user_quiz_grade = ''; | 
| 1237 | -         if( ! empty( $user_lesson_status  ) ){ | |
| 1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1237 | +         if ( ! empty($user_lesson_status)) { | |
| 1238 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); | |
| 1239 | 1239 | } | 
| 1240 | 1240 | |
| 1241 | 1241 | |
| 1242 | -         if( intval( $lesson_prerequisite ) > 0 ) { | |
| 1242 | +         if (intval($lesson_prerequisite) > 0) { | |
| 1243 | 1243 | |
| 1244 | 1244 | // If the user hasn't completed the prereq then hide the current actions | 
| 1245 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); | |
| 1245 | + $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID); | |
| 1246 | 1246 | |
| 1247 | 1247 | } | 
| 1248 | -         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { | |
| 1248 | +         if ($show_actions && is_user_logged_in() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { | |
| 1249 | 1249 | |
| 1250 | 1250 | // Get Reset Settings | 
| 1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> | |
| 1251 | + $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?> | |
| 1252 | 1252 | |
| 1253 | 1253 | <!-- Action Nonce's --> | 
| 1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" | 
| 1255 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" /> | |
| 1255 | +                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" /> | |
| 1256 | 1256 | <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce" | 
| 1257 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" /> | |
| 1257 | +                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" /> | |
| 1258 | 1258 | <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce" | 
| 1259 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" /> | |
| 1259 | +                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" /> | |
| 1260 | 1260 | <!--#end Action Nonce's --> | 
| 1261 | 1261 | |
| 1262 | -             <?php if ( '' == $user_quiz_grade) { ?> | |
| 1262 | +             <?php if ('' == $user_quiz_grade) { ?> | |
| 1263 | 1263 | |
| 1264 | - <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span> | |
| 1264 | +                 <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php  _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span> | |
| 1265 | 1265 | |
| 1266 | - <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span> | |
| 1266 | +                 <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span> | |
| 1267 | 1267 | |
| 1268 | 1268 | <?php } // End If Statement ?> | 
| 1269 | 1269 | |
| 1270 | -             <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?> | |
| 1270 | +             <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?> | |
| 1271 | 1271 | |
| 1272 | - <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span> | |
| 1272 | +                 <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span> | |
| 1273 | 1273 | |
| 1274 | 1274 | <?php } ?> | 
| 1275 | 1275 | |
| @@ -1287,13 +1287,13 @@ discard block | ||
| 1287 | 1287 | * | 
| 1288 | 1288 | * @return double $user_quiz_grade | 
| 1289 | 1289 | */ | 
| 1290 | -     public static function get_user_quiz_grade( $lesson_id, $user_id ){ | |
| 1290 | +     public static function get_user_quiz_grade($lesson_id, $user_id) { | |
| 1291 | 1291 | |
| 1292 | 1292 | // get the quiz grade | 
| 1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); | |
| 1294 | 1294 | $user_quiz_grade = 0; | 
| 1295 | -         if( isset( $user_lesson_status->comment_ID ) ) { | |
| 1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1295 | +         if (isset($user_lesson_status->comment_ID)) { | |
| 1296 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); | |
| 1297 | 1297 | } | 
| 1298 | 1298 | |
| 1299 | 1299 | return (double) $user_quiz_grade; | 
| @@ -1311,13 +1311,13 @@ discard block | ||
| 1311 | 1311 | * @param int $lesson_id | 
| 1312 | 1312 | * @return bool | 
| 1313 | 1313 | */ | 
| 1314 | -     public static function is_reset_allowed( $lesson_id ){ | |
| 1314 | +     public static function is_reset_allowed($lesson_id) { | |
| 1315 | 1315 | |
| 1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); | |
| 1317 | 1317 | |
| 1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 1318 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); | |
| 1319 | 1319 | //backwards compatibility | 
| 1320 | -         if( 'on' == $reset_allowed ) { | |
| 1320 | +         if ('on' == $reset_allowed) { | |
| 1321 | 1321 | $reset_allowed = 1; | 
| 1322 | 1322 | } | 
| 1323 | 1323 | |
| @@ -1334,4 +1334,4 @@ discard block | ||
| 1334 | 1334 | * for backward compatibility | 
| 1335 | 1335 | * @since 1.9.0 | 
| 1336 | 1336 | */ | 
| 1337 | -class WooThemes_Sensei_Quiz extends Sensei_Quiz{} | |
| 1337 | +class WooThemes_Sensei_Quiz extends Sensei_Quiz {} | |
| @@ -24,69 +24,69 @@ discard block | ||
| 24 | 24 | */ | 
| 25 | 25 |  	public function __construct ( $file = __FILE__ ) { | 
| 26 | 26 | $this->file = $file; | 
| 27 | - $this->token = 'quiz'; | |
| 27 | + $this->token = 'quiz'; | |
| 28 | 28 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); | 
| 29 | 29 | add_action( 'save_post', array( $this, 'update_author' )); | 
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click | 
| 32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | 
| 33 | 33 | |
| 34 | - // fire the complete quiz button submit for grading action | |
| 35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); | |
| 34 | + // fire the complete quiz button submit for grading action | |
| 35 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); | |
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder | 
| 38 | 38 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); | 
| 39 | 39 | |
| 40 | - // fire the load global data function | |
| 41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); | |
| 40 | + // fire the load global data function | |
| 41 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); | |
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); | |
| 43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - } // End __construct() | |
| 46 | + } // End __construct() | |
| 47 | 47 | |
| 48 | 48 | /** | 
| 49 | - * Update the quiz author when the lesson post type is save | |
| 50 | - * | |
| 51 | - * @param int $post_id | |
| 52 | - * @return void | |
| 53 | - */ | |
| 49 | + * Update the quiz author when the lesson post type is save | |
| 50 | + * | |
| 51 | + * @param int $post_id | |
| 52 | + * @return void | |
| 53 | + */ | |
| 54 | 54 |  	public function update_author( $post_id ){ | 
| 55 | 55 | |
| 56 | 56 | // If this isn't a 'lesson' post, don't update it. | 
| 57 | - // if this is a revision don't save it | |
| 58 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] | |
| 59 | -            || wp_is_post_revision( $post_id ) ) { | |
| 57 | + // if this is a revision don't save it | |
| 58 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] | |
| 59 | +			|| wp_is_post_revision( $post_id ) ) { | |
| 60 | 60 | |
| 61 | - return; | |
| 61 | + return; | |
| 62 | 62 | |
| 63 | - } | |
| 64 | - // get the lesson author id to be use late | |
| 65 | - $saved_post = get_post( $post_id ); | |
| 66 | - $new_lesson_author_id = $saved_post->post_author; | |
| 63 | + } | |
| 64 | + // get the lesson author id to be use late | |
| 65 | + $saved_post = get_post( $post_id ); | |
| 66 | + $new_lesson_author_id = $saved_post->post_author; | |
| 67 | 67 | |
| 68 | - //get the lessons quiz | |
| 68 | + //get the lessons quiz | |
| 69 | 69 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); | 
| 70 | -	    foreach ( (array) $lesson_quizzes as $quiz_item ) { | |
| 70 | +		foreach ( (array) $lesson_quizzes as $quiz_item ) { | |
| 71 | 71 | |
| 72 | -	    	if( ! $quiz_item ) { | |
| 73 | - continue; | |
| 74 | - } | |
| 72 | +			if( ! $quiz_item ) { | |
| 73 | + continue; | |
| 74 | + } | |
| 75 | 75 | |
| 76 | - // setup the quiz items new author value | |
| 76 | + // setup the quiz items new author value | |
| 77 | 77 | $my_post = array( | 
| 78 | - 'ID' => $quiz_item, | |
| 79 | - 'post_author' => $new_lesson_author_id | |
| 78 | + 'ID' => $quiz_item, | |
| 79 | + 'post_author' => $new_lesson_author_id | |
| 80 | 80 | ); | 
| 81 | 81 | |
| 82 | - // remove the action so that it doesn't fire again | |
| 83 | - remove_action( 'save_post', array( $this, 'update_author' )); | |
| 82 | + // remove the action so that it doesn't fire again | |
| 83 | + remove_action( 'save_post', array( $this, 'update_author' )); | |
| 84 | 84 | |
| 85 | 85 | // Update the post into the database | 
| 86 | 86 | wp_update_post( $my_post ); | 
| 87 | - } | |
| 87 | + } | |
| 88 | 88 | |
| 89 | - return; | |
| 89 | + return; | |
| 90 | 90 | }// end update_author | 
| 91 | 91 | |
| 92 | 92 | |
| @@ -117,32 +117,32 @@ discard block | ||
| 117 | 117 | } // end lesson | 
| 118 | 118 | |
| 119 | 119 | |
| 120 | - /** | |
| 121 | - * user_save_quiz_answers_listener | |
| 122 | - * | |
| 123 | - * This function hooks into the quiz page and accepts the answer form save post. | |
| 124 | - * @since 1.7.3 | |
| 125 | - * @return bool $saved; | |
| 126 | - */ | |
| 127 | -    public function user_save_quiz_answers_listener(){ | |
| 120 | + /** | |
| 121 | + * user_save_quiz_answers_listener | |
| 122 | + * | |
| 123 | + * This function hooks into the quiz page and accepts the answer form save post. | |
| 124 | + * @since 1.7.3 | |
| 125 | + * @return bool $saved; | |
| 126 | + */ | |
| 127 | +	public function user_save_quiz_answers_listener(){ | |
| 128 | 128 | |
| 129 | - if( ! isset( $_POST[ 'quiz_save' ]) | |
| 130 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 131 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 132 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) { | |
| 133 | - return; | |
| 134 | - } | |
| 129 | + if( ! isset( $_POST[ 'quiz_save' ]) | |
| 130 | + || !isset( $_POST[ 'sensei_question' ] ) | |
| 131 | + || empty( $_POST[ 'sensei_question' ] ) | |
| 132 | +			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) { | |
| 133 | + return; | |
| 134 | + } | |
| 135 | 135 | |
| 136 | - global $post; | |
| 137 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 138 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 139 | - // call the save function | |
| 140 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); | |
| 136 | + global $post; | |
| 137 | + $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 138 | + $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 139 | + // call the save function | |
| 140 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); | |
| 141 | 141 | |
| 142 | - // remove the hook as it should only fire once per click | |
| 143 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); | |
| 142 | + // remove the hook as it should only fire once per click | |
| 143 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); | |
| 144 | 144 | |
| 145 | - } // end user_save_quiz_answers_listener | |
| 145 | + } // end user_save_quiz_answers_listener | |
| 146 | 146 | |
| 147 | 147 | /** | 
| 148 | 148 | * Save the user answers for the given lesson's quiz | 
| @@ -153,7 +153,7 @@ discard block | ||
| 153 | 153 | * @access public | 
| 154 | 154 | * | 
| 155 | 155 | * @param array $quiz_answers | 
| 156 | - * @param array $files from global $_FILES | |
| 156 | + * @param array $files from global $_FILES | |
| 157 | 157 | * @param int $lesson_id | 
| 158 | 158 | * @param int $user_id | 
| 159 | 159 | * | 
| @@ -161,11 +161,11 @@ discard block | ||
| 161 | 161 | */ | 
| 162 | 162 |  	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ | 
| 163 | 163 | |
| 164 | -        if( ! ( $user_id > 0 ) ){ | |
| 165 | - $user_id = get_current_user_id(); | |
| 166 | - } | |
| 164 | +		if( ! ( $user_id > 0 ) ){ | |
| 165 | + $user_id = get_current_user_id(); | |
| 166 | + } | |
| 167 | 167 | |
| 168 | - // make sure the parameters are valid before continuing | |
| 168 | + // make sure the parameters are valid before continuing | |
| 169 | 169 | if( empty( $lesson_id ) || empty( $user_id ) | 
| 170 | 170 | || 'lesson' != get_post_type( $lesson_id ) | 
| 171 | 171 | ||!get_userdata( $user_id ) | 
| @@ -176,25 +176,25 @@ discard block | ||
| 176 | 176 | } | 
| 177 | 177 | |
| 178 | 178 | |
| 179 | - // start the lesson before saving the data in case the user has not started the lesson | |
| 180 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 179 | + // start the lesson before saving the data in case the user has not started the lesson | |
| 180 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 181 | 181 | |
| 182 | 182 | //prepare the answers | 
| 183 | 183 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); | 
| 184 | 184 | |
| 185 | 185 | // save the user data | 
| 186 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; | |
| 186 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; | |
| 187 | 187 | |
| 188 | 188 | // were the answers saved correctly? | 
| 189 | 189 |  		if( intval( $answers_saved ) > 0){ | 
| 190 | 190 | |
| 191 | - // save transient to make retrieval faster | |
| 192 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 193 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); | |
| 191 | + // save transient to make retrieval faster | |
| 192 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 193 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); | |
| 194 | 194 | |
| 195 | - // update the message showed to user | |
| 196 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 197 | - } | |
| 195 | + // update the message showed to user | |
| 196 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 197 | + } | |
| 198 | 198 | |
| 199 | 199 | return $answers_saved; | 
| 200 | 200 | |
| @@ -202,9 +202,9 @@ discard block | ||
| 202 | 202 | |
| 203 | 203 | /** | 
| 204 | 204 | * Get the user answers for the given lesson's quiz. | 
| 205 | - * | |
| 206 | - * This function returns the data that is stored on the lesson as meta and is not compatible with | |
| 207 | - * retrieving data for quiz answer before sensei 1.7.4 | |
| 205 | + * | |
| 206 | + * This function returns the data that is stored on the lesson as meta and is not compatible with | |
| 207 | + * retrieving data for quiz answer before sensei 1.7.4 | |
| 208 | 208 | * | 
| 209 | 209 | * | 
| 210 | 210 | * @since 1.7.4 | 
| @@ -224,27 +224,27 @@ discard block | ||
| 224 | 224 | return false; | 
| 225 | 225 | } | 
| 226 | 226 | |
| 227 | - // save some time and get the transient cached data | |
| 228 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 229 | - $transient_cached_answers = get_transient( $transient_key ); | |
| 227 | + // save some time and get the transient cached data | |
| 228 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 229 | + $transient_cached_answers = get_transient( $transient_key ); | |
| 230 | 230 | |
| 231 | - // return the transient or get the values get the values from the comment meta | |
| 232 | -        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){ | |
| 231 | + // return the transient or get the values get the values from the comment meta | |
| 232 | +		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){ | |
| 233 | 233 | |
| 234 | - $encoded_user_answers = $transient_cached_answers; | |
| 234 | + $encoded_user_answers = $transient_cached_answers; | |
| 235 | 235 | |
| 236 | -        }else{ | |
| 236 | +		}else{ | |
| 237 | 237 | |
| 238 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | |
| 238 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | |
| 239 | 239 | |
| 240 | - } // end if transient check | |
| 240 | + } // end if transient check | |
| 241 | 241 | |
| 242 | 242 |  		if( ! is_array( $encoded_user_answers ) ){ | 
| 243 | 243 | return false; | 
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | - //set the transient with the new valid data for faster retrieval in future | |
| 247 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 246 | + //set the transient with the new valid data for faster retrieval in future | |
| 247 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 248 | 248 | |
| 249 | 249 | // decode an unserialize all answers | 
| 250 | 250 |  		foreach( $encoded_user_answers as $question_id => $encoded_answer ) { | 
| @@ -278,8 +278,8 @@ discard block | ||
| 278 | 278 | $current_quiz_id = $post->ID; | 
| 279 | 279 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); | 
| 280 | 280 | |
| 281 | - // reset all user data | |
| 282 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); | |
| 281 | + // reset all user data | |
| 282 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); | |
| 283 | 283 | |
| 284 | 284 | //this function should only run once | 
| 285 | 285 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | 
| @@ -290,7 +290,7 @@ discard block | ||
| 290 | 290 | * Complete/ submit quiz hooked function | 
| 291 | 291 | * | 
| 292 | 292 | * This function listens to the complete button submit action and processes the users submitted answers | 
| 293 | - * not that this function submits the given users quiz answers for grading. | |
| 293 | + * not that this function submits the given users quiz answers for grading. | |
| 294 | 294 | * | 
| 295 | 295 | * @since 1.7.4 | 
| 296 | 296 | * @access public | 
| @@ -300,90 +300,90 @@ discard block | ||
| 300 | 300 | */ | 
| 301 | 301 |  	public function user_quiz_submit_listener() { | 
| 302 | 302 | |
| 303 | - // only respond to valid quiz completion submissions | |
| 304 | - if( ! isset( $_POST[ 'quiz_complete' ]) | |
| 305 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 306 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 307 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) { | |
| 308 | - return; | |
| 309 | - } | |
| 303 | + // only respond to valid quiz completion submissions | |
| 304 | + if( ! isset( $_POST[ 'quiz_complete' ]) | |
| 305 | + || !isset( $_POST[ 'sensei_question' ] ) | |
| 306 | + || empty( $_POST[ 'sensei_question' ] ) | |
| 307 | +			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) { | |
| 308 | + return; | |
| 309 | + } | |
| 310 | 310 | |
| 311 | - global $post, $current_user; | |
| 312 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 313 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 311 | + global $post, $current_user; | |
| 312 | + $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 313 | + $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 314 | 314 | |
| 315 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); | |
| 315 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); | |
| 316 | 316 | |
| 317 | 317 | } // End sensei_complete_quiz() | 
| 318 | 318 | |
| 319 | - /** | |
| 320 | - * This function set's up the data need for the quiz page | |
| 321 | - * | |
| 322 | - * This function hooks into sensei_complete_quiz and load the global data for the | |
| 323 | - * current quiz. | |
| 324 | - * | |
| 325 | - * @since 1.7.4 | |
| 326 | - * @access public | |
| 327 | - * | |
| 328 | - */ | |
| 329 | -    public function load_global_quiz_data(){ | |
| 319 | + /** | |
| 320 | + * This function set's up the data need for the quiz page | |
| 321 | + * | |
| 322 | + * This function hooks into sensei_complete_quiz and load the global data for the | |
| 323 | + * current quiz. | |
| 324 | + * | |
| 325 | + * @since 1.7.4 | |
| 326 | + * @access public | |
| 327 | + * | |
| 328 | + */ | |
| 329 | +	public function load_global_quiz_data(){ | |
| 330 | 330 | |
| 331 | - global $post, $current_user; | |
| 332 | - $this->data = new stdClass(); | |
| 331 | + global $post, $current_user; | |
| 332 | + $this->data = new stdClass(); | |
| 333 | 333 | |
| 334 | - // Default grade | |
| 335 | - $grade = 0; | |
| 334 | + // Default grade | |
| 335 | + $grade = 0; | |
| 336 | 336 | |
| 337 | - // Get Quiz Questions | |
| 338 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); | |
| 337 | + // Get Quiz Questions | |
| 338 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); | |
| 339 | 339 | |
| 340 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); | |
| 340 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); | |
| 341 | 341 | |
| 342 | - // Get quiz grade type | |
| 343 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); | |
| 342 | + // Get quiz grade type | |
| 343 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); | |
| 344 | 344 | |
| 345 | - // Get quiz pass setting | |
| 346 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); | |
| 345 | + // Get quiz pass setting | |
| 346 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); | |
| 347 | 347 | |
| 348 | - // Get quiz pass mark | |
| 349 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); | |
| 348 | + // Get quiz pass mark | |
| 349 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); | |
| 350 | 350 | |
| 351 | - // Get latest quiz answers and grades | |
| 352 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); | |
| 353 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); | |
| 354 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); | |
| 355 | - $user_quiz_grade = 0; | |
| 356 | -        if( isset( $user_lesson_status->comment_ID ) ) { | |
| 357 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 358 | - } | |
| 351 | + // Get latest quiz answers and grades | |
| 352 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); | |
| 353 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); | |
| 354 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); | |
| 355 | + $user_quiz_grade = 0; | |
| 356 | +		if( isset( $user_lesson_status->comment_ID ) ) { | |
| 357 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 358 | + } | |
| 359 | 359 | |
| 360 | -        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } | |
| 360 | +		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } | |
| 361 | 361 | |
| 362 | - // Check again that the lesson is complete | |
| 363 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); | |
| 364 | - $user_lesson_complete = false; | |
| 365 | -        if ( $user_lesson_end ) { | |
| 366 | - $user_lesson_complete = true; | |
| 367 | - } // End If Statement | |
| 362 | + // Check again that the lesson is complete | |
| 363 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); | |
| 364 | + $user_lesson_complete = false; | |
| 365 | +		if ( $user_lesson_end ) { | |
| 366 | + $user_lesson_complete = true; | |
| 367 | + } // End If Statement | |
| 368 | 368 | |
| 369 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); | |
| 370 | - //backwards compatibility | |
| 371 | -        if( 'on' == $reset_allowed ) { | |
| 372 | - $reset_allowed = 1; | |
| 373 | - } | |
| 369 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); | |
| 370 | + //backwards compatibility | |
| 371 | +		if( 'on' == $reset_allowed ) { | |
| 372 | + $reset_allowed = 1; | |
| 373 | + } | |
| 374 | 374 | |
| 375 | - // Build frontend data object for backwards compatibility | |
| 376 | - // using this is no longer recommended | |
| 377 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 378 | - $this->data->quiz_passmark = $quiz_passmark; | |
| 379 | - $this->data->quiz_lesson = $quiz_lesson_id; | |
| 380 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 381 | - $this->data->user_lesson_end = $user_lesson_end; | |
| 382 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 383 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; | |
| 384 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 375 | + // Build frontend data object for backwards compatibility | |
| 376 | + // using this is no longer recommended | |
| 377 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 378 | + $this->data->quiz_passmark = $quiz_passmark; | |
| 379 | + $this->data->quiz_lesson = $quiz_lesson_id; | |
| 380 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 381 | + $this->data->user_lesson_end = $user_lesson_end; | |
| 382 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 383 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; | |
| 384 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 385 | 385 | |
| 386 | - } // end load_global_quiz_data | |
| 386 | + } // end load_global_quiz_data | |
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | /** | 
| @@ -413,25 +413,25 @@ discard block | ||
| 413 | 413 |  		foreach( $unprepared_answers as $question_id => $answer ) { | 
| 414 | 414 | |
| 415 | 415 | //get the current questions question type | 
| 416 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 416 | + $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 417 | 417 | |
| 418 | 418 | // Sanitise answer | 
| 419 | 419 |  			if( 0 == get_magic_quotes_gpc() ) { | 
| 420 | 420 | $answer = wp_unslash( $answer ); | 
| 421 | 421 | } | 
| 422 | 422 | |
| 423 | - // compress the answer for saving | |
| 423 | + // compress the answer for saving | |
| 424 | 424 |  			if( 'multi-line' == $question_type ) { | 
| 425 | - $answer = esc_html( $answer ); | |
| 426 | -            }elseif( 'file-upload' == $question_type  ){ | |
| 427 | - $file_key = 'file_upload_' . $question_id; | |
| 428 | -                if( isset( $files[ $file_key ] ) ) { | |
| 429 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); | |
| 430 | -                        if( $attachment_id ) { | |
| 431 | - $answer = $attachment_id; | |
| 432 | - } | |
| 433 | - } | |
| 434 | - } // end if | |
| 425 | + $answer = esc_html( $answer ); | |
| 426 | +			}elseif( 'file-upload' == $question_type  ){ | |
| 427 | + $file_key = 'file_upload_' . $question_id; | |
| 428 | +				if( isset( $files[ $file_key ] ) ) { | |
| 429 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); | |
| 430 | +						if( $attachment_id ) { | |
| 431 | + $answer = $attachment_id; | |
| 432 | + } | |
| 433 | + } | |
| 434 | + } // end if | |
| 435 | 435 | |
| 436 | 436 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); | 
| 437 | 437 | |
| @@ -440,813 +440,813 @@ discard block | ||
| 440 | 440 | return $prepared_answers; | 
| 441 | 441 | } // prepare_form_submitted_answers | 
| 442 | 442 | |
| 443 | - /** | |
| 444 | - * Reset user submitted questions | |
| 445 | - * | |
| 446 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to | |
| 447 | - * the save_user_answers as currently the saved and submitted answers are stored differently. | |
| 448 | - * | |
| 449 | - * @since 1.7.4 | |
| 450 | - * @access public | |
| 451 | - * | |
| 452 | - * @return bool $reset_success | |
| 453 | - * @param int $user_id | |
| 454 | - * @param int $lesson_id | |
| 455 | - */ | |
| 456 | -    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ | |
| 443 | + /** | |
| 444 | + * Reset user submitted questions | |
| 445 | + * | |
| 446 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to | |
| 447 | + * the save_user_answers as currently the saved and submitted answers are stored differently. | |
| 448 | + * | |
| 449 | + * @since 1.7.4 | |
| 450 | + * @access public | |
| 451 | + * | |
| 452 | + * @return bool $reset_success | |
| 453 | + * @param int $user_id | |
| 454 | + * @param int $lesson_id | |
| 455 | + */ | |
| 456 | +	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ | |
| 457 | + | |
| 458 | + //make sure the parameters are valid | |
| 459 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 460 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 461 | +			|| ! get_userdata( $user_id ) ){ | |
| 462 | + return false; | |
| 463 | + } | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + //get the users lesson status to make | |
| 468 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 469 | +		if( ! isset( $user_lesson_status->comment_ID ) ) { | |
| 470 | + // this user is not taking this lesson so this process is not needed | |
| 471 | + return false; | |
| 472 | + } | |
| 473 | + | |
| 474 | + //get the lesson quiz and course | |
| 475 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 476 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); | |
| 477 | + | |
| 478 | + // reset the transients | |
| 479 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 480 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 481 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 482 | + delete_transient( $answers_transient_key ); | |
| 483 | + delete_transient( $grades_transient_key ); | |
| 484 | + delete_transient( $answers_feedback_transient_key ); | |
| 485 | + | |
| 486 | + // reset the quiz answers and feedback notes | |
| 487 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); | |
| 488 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 489 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 490 | + | |
| 491 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade | |
| 492 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); | |
| 493 | + | |
| 494 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); | |
| 495 | + | |
| 496 | + // Update course completion | |
| 497 | + Sensei_Utils::update_course_status( $user_id, $course_id ); | |
| 457 | 498 | |
| 458 | - //make sure the parameters are valid | |
| 459 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 460 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 461 | -            || ! get_userdata( $user_id ) ){ | |
| 462 | - return false; | |
| 463 | - } | |
| 464 | - | |
| 465 | - | |
| 466 | - | |
| 467 | - //get the users lesson status to make | |
| 468 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 469 | -        if( ! isset( $user_lesson_status->comment_ID ) ) { | |
| 470 | - // this user is not taking this lesson so this process is not needed | |
| 471 | - return false; | |
| 472 | - } | |
| 499 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() | |
| 500 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); | |
| 501 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 473 | 502 | |
| 474 | - //get the lesson quiz and course | |
| 475 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 476 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); | |
| 503 | + return ( $deleted_answers && $deleted_grades ) ; | |
| 477 | 504 | |
| 478 | - // reset the transients | |
| 479 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 480 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 481 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 482 | - delete_transient( $answers_transient_key ); | |
| 483 | - delete_transient( $grades_transient_key ); | |
| 484 | - delete_transient( $answers_feedback_transient_key ); | |
| 505 | + } // end reset_user_lesson_data | |
| 485 | 506 | |
| 486 | - // reset the quiz answers and feedback notes | |
| 487 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); | |
| 488 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 489 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 507 | + /** | |
| 508 | + * Submit the users quiz answers for grading | |
| 509 | + * | |
| 510 | + * This function accepts users answers and stores it but also initiates the grading | |
| 511 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. | |
| 512 | + * | |
| 513 | + * @since 1.7.4 | |
| 514 | + * @access public | |
| 515 | + * | |
| 516 | + * @param array $quiz_answers | |
| 517 | + * @param array $files from $_FILES | |
| 518 | + * @param int $user_id | |
| 519 | + * @param int $lesson_id | |
| 520 | + * | |
| 521 | + * @return bool $answers_submitted | |
| 522 | + */ | |
| 523 | +	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ | |
| 490 | 524 | |
| 491 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade | |
| 492 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); | |
| 525 | + $answers_submitted = false; | |
| 493 | 526 | |
| 494 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); | |
| 527 | + // get the user_id if none was passed in use the current logged in user | |
| 528 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 529 | + $user_id = get_current_user_id(); | |
| 530 | + } | |
| 495 | 531 | |
| 496 | - // Update course completion | |
| 497 | - Sensei_Utils::update_course_status( $user_id, $course_id ); | |
| 532 | + // make sure the parameters are valid before continuing | |
| 533 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 534 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 535 | + ||!get_userdata( $user_id ) | |
| 536 | +			 || !is_array( $quiz_answers ) ){ | |
| 498 | 537 | |
| 499 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() | |
| 500 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); | |
| 501 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 538 | + return false; | |
| 502 | 539 | |
| 503 | - return ( $deleted_answers && $deleted_grades ) ; | |
| 540 | + } | |
| 504 | 541 | |
| 505 | - } // end reset_user_lesson_data | |
| 542 | + // Default grade | |
| 543 | + $grade = 0; | |
| 506 | 544 | |
| 507 | - /** | |
| 508 | - * Submit the users quiz answers for grading | |
| 509 | - * | |
| 510 | - * This function accepts users answers and stores it but also initiates the grading | |
| 511 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. | |
| 512 | - * | |
| 513 | - * @since 1.7.4 | |
| 514 | - * @access public | |
| 515 | - * | |
| 516 | - * @param array $quiz_answers | |
| 517 | - * @param array $files from $_FILES | |
| 518 | - * @param int $user_id | |
| 519 | - * @param int $lesson_id | |
| 520 | - * | |
| 521 | - * @return bool $answers_submitted | |
| 522 | - */ | |
| 523 | -     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ | |
| 545 | + // Get Quiz ID | |
| 546 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 524 | 547 | |
| 525 | - $answers_submitted = false; | |
| 548 | + // Get quiz grade type | |
| 549 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 526 | 550 | |
| 527 | - // get the user_id if none was passed in use the current logged in user | |
| 528 | -         if( ! intval( $user_id ) > 0 ) { | |
| 529 | - $user_id = get_current_user_id(); | |
| 530 | - } | |
| 551 | + // Get quiz pass setting | |
| 552 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 531 | 553 | |
| 532 | - // make sure the parameters are valid before continuing | |
| 533 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 534 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 535 | - ||!get_userdata( $user_id ) | |
| 536 | -             || !is_array( $quiz_answers ) ){ | |
| 554 | + // Get the minimum percentage need to pass this quiz | |
| 555 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 537 | 556 | |
| 538 | - return false; | |
| 557 | + // Handle Quiz Questions asked | |
| 558 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless | |
| 559 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). | |
| 560 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions | |
| 561 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 562 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); | |
| 563 | +		 if( empty( $questions_asked ) ){ | |
| 539 | 564 | |
| 540 | - } | |
| 565 | + $questions_asked = array_keys( $quiz_answers ); | |
| 566 | + $questions_asked_string = implode( ',', $questions_asked ); | |
| 541 | 567 | |
| 542 | - // Default grade | |
| 543 | - $grade = 0; | |
| 568 | + // Save questions that were asked in this quiz | |
| 569 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); | |
| 544 | 570 | |
| 545 | - // Get Quiz ID | |
| 546 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 571 | + } | |
| 547 | 572 | |
| 548 | - // Get quiz grade type | |
| 549 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 573 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson | |
| 574 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); | |
| 550 | 575 | |
| 551 | - // Get quiz pass setting | |
| 552 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 576 | + // Grade quiz | |
| 577 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); | |
| 553 | 578 | |
| 554 | - // Get the minimum percentage need to pass this quiz | |
| 555 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 579 | + // Get Lesson Grading Setting | |
| 580 | + $lesson_metadata = array(); | |
| 581 | + $lesson_status = 'ungraded'; // Default when completing a quiz | |
| 556 | 582 | |
| 557 | - // Handle Quiz Questions asked | |
| 558 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless | |
| 559 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). | |
| 560 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions | |
| 561 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 562 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); | |
| 563 | -         if( empty( $questions_asked ) ){ | |
| 583 | + // At this point the answers have been submitted | |
| 584 | + $answers_submitted = true; | |
| 564 | 585 | |
| 565 | - $questions_asked = array_keys( $quiz_answers ); | |
| 566 | - $questions_asked_string = implode( ',', $questions_asked ); | |
| 567 | - | |
| 568 | - // Save questions that were asked in this quiz | |
| 569 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); | |
| 586 | + // if this condition is false the quiz should manually be graded by admin | |
| 587 | +		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) { | |
| 570 | 588 | |
| 571 | - } | |
| 589 | + // Quiz has been automatically Graded | |
| 590 | +			 if ( 'on' == $pass_required ) { | |
| 572 | 591 | |
| 573 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson | |
| 574 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); | |
| 592 | + // Student has reached the pass mark and lesson is complete | |
| 593 | +				 if ( $quiz_pass_percentage <= $grade ) { | |
| 575 | 594 | |
| 576 | - // Grade quiz | |
| 577 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); | |
| 595 | + $lesson_status = 'passed'; | |
| 578 | 596 | |
| 579 | - // Get Lesson Grading Setting | |
| 580 | - $lesson_metadata = array(); | |
| 581 | - $lesson_status = 'ungraded'; // Default when completing a quiz | |
| 597 | +				 } else { | |
| 582 | 598 | |
| 583 | - // At this point the answers have been submitted | |
| 584 | - $answers_submitted = true; | |
| 599 | + $lesson_status = 'failed'; | |
| 585 | 600 | |
| 586 | - // if this condition is false the quiz should manually be graded by admin | |
| 587 | -         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) { | |
| 601 | + } // End If Statement | |
| 588 | 602 | |
| 589 | - // Quiz has been automatically Graded | |
| 590 | -             if ( 'on' == $pass_required ) { | |
| 603 | +			 } else { | |
| 591 | 604 | |
| 592 | - // Student has reached the pass mark and lesson is complete | |
| 593 | -                 if ( $quiz_pass_percentage <= $grade ) { | |
| 605 | + // Student only has to partake the quiz | |
| 606 | + $lesson_status = 'graded'; | |
| 607 | + | |
| 608 | + } | |
| 609 | + | |
| 610 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above | |
| 611 | + | |
| 612 | + } // end if ! is_wp_error( $grade ... | |
| 613 | + | |
| 614 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); | |
| 594 | 615 | |
| 595 | - $lesson_status = 'passed'; | |
| 616 | +		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ | |
| 596 | 617 | |
| 597 | -                 } else { | |
| 618 | + /** | |
| 619 | + * Lesson end action hook | |
| 620 | + * | |
| 621 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' | |
| 622 | + * | |
| 623 | + * @param int $user_id | |
| 624 | + * @param int $lesson_id | |
| 625 | + */ | |
| 626 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); | |
| 598 | 627 | |
| 599 | - $lesson_status = 'failed'; | |
| 628 | + } | |
| 600 | 629 | |
| 601 | - } // End If Statement | |
| 630 | + /** | |
| 631 | + * User quiz has been submitted | |
| 632 | + * | |
| 633 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission | |
| 634 | + * results. | |
| 635 | + * | |
| 636 | + * @param int $user_id | |
| 637 | + * @param int $quiz_id | |
| 638 | + * @param string $grade | |
| 639 | + * @param string $quiz_pass_percentage | |
| 640 | + * @param string $quiz_grade_type | |
| 641 | + */ | |
| 642 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); | |
| 602 | 643 | |
| 603 | -             } else { | |
| 644 | + return $answers_submitted; | |
| 604 | 645 | |
| 605 | - // Student only has to partake the quiz | |
| 606 | - $lesson_status = 'graded'; | |
| 607 | - | |
| 608 | - } | |
| 609 | - | |
| 610 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above | |
| 611 | - | |
| 612 | - } // end if ! is_wp_error( $grade ... | |
| 613 | - | |
| 614 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); | |
| 646 | + }// end submit_answers_for_grading | |
| 615 | 647 | |
| 616 | -         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ | |
| 648 | + /** | |
| 649 | + * Get the user question answer | |
| 650 | + * | |
| 651 | + * This function gets the the users saved answer on given quiz for the given question parameter | |
| 652 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 653 | + * | |
| 654 | + * @since 1.7.4 | |
| 655 | + * | |
| 656 | + * @param int $lesson_id | |
| 657 | + * @param int $question_id | |
| 658 | + * @param int $user_id ( optional ) | |
| 659 | + * | |
| 660 | + * @return bool $answers_submitted | |
| 661 | + */ | |
| 662 | +	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ | |
| 617 | 663 | |
| 618 | - /** | |
| 619 | - * Lesson end action hook | |
| 620 | - * | |
| 621 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' | |
| 622 | - * | |
| 623 | - * @param int $user_id | |
| 624 | - * @param int $lesson_id | |
| 625 | - */ | |
| 626 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); | |
| 664 | + // parameter validation | |
| 665 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 666 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 667 | + || ! ( intval( $question_id ) > 0 ) | |
| 668 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 669 | +			 || 'question' != get_post_type( $question_id )) { | |
| 627 | 670 | |
| 628 | - } | |
| 671 | + return false; | |
| 672 | + } | |
| 673 | + | |
| 674 | +		 if( ! ( intval( $user_id ) > 0 )   ){ | |
| 675 | + $user_id = get_current_user_id(); | |
| 676 | + } | |
| 677 | + | |
| 678 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); | |
| 679 | + | |
| 680 | + if( !$users_answers || empty( $users_answers ) | |
| 681 | +		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ | |
| 682 | + | |
| 683 | + //Fallback for pre 1.7.4 data | |
| 684 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); | |
| 685 | + | |
| 686 | +			 if( ! isset( $comment->comment_content ) ){ | |
| 687 | + return false; | |
| 688 | + } | |
| 689 | + | |
| 690 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); | |
| 691 | + } | |
| 692 | + | |
| 693 | + return $users_answers[ $question_id ]; | |
| 694 | + | |
| 695 | + }// end get_user_question_answer | |
| 696 | + | |
| 697 | + /** | |
| 698 | + * Saving the users quiz question grades | |
| 699 | + * | |
| 700 | + * This function save all the grades for all the question in a given quiz on the lesson | |
| 701 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage | |
| 702 | + * | |
| 703 | + * @since 1.7.4 | |
| 704 | + * | |
| 705 | +	  * @param array $quiz_grades{ | |
| 706 | + * @type int $question_id | |
| 707 | + * @type int $question_grade | |
| 708 | + * } | |
| 709 | + * @param $lesson_id | |
| 710 | + * @param $user_id (Optional) will use the current user if not supplied | |
| 711 | + * | |
| 712 | + * @return bool | |
| 713 | + */ | |
| 714 | +	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ | |
| 715 | + | |
| 716 | + // get the user_id if none was passed in use the current logged in user | |
| 717 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 718 | + $user_id = get_current_user_id(); | |
| 719 | + } | |
| 720 | + | |
| 721 | + // make sure the parameters are valid before continuing | |
| 722 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 723 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 724 | + ||!get_userdata( $user_id ) | |
| 725 | +			 || !is_array( $quiz_grades ) ){ | |
| 726 | + | |
| 727 | + return false; | |
| 728 | + | |
| 729 | + } | |
| 730 | + | |
| 731 | + $success = false; | |
| 732 | + | |
| 733 | + // save that data for the user on the lesson comment meta | |
| 734 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); | |
| 735 | + | |
| 736 | + // were the grades save successfully ? | |
| 737 | +		 if( intval( $comment_meta_id ) > 0 ) { | |
| 738 | + | |
| 739 | + $success = true; | |
| 740 | + // save transient | |
| 741 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 742 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); | |
| 743 | + } | |
| 744 | + | |
| 745 | + return $success; | |
| 746 | + | |
| 747 | + }// end set_user_grades | |
| 748 | + | |
| 749 | + /** | |
| 750 | + * Retrieve the users quiz question grades | |
| 751 | + * | |
| 752 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. | |
| 753 | + * | |
| 754 | + * @since 1.7.4 | |
| 755 | + * | |
| 756 | + * @param $lesson_id | |
| 757 | + * @param $user_id (Optional) will use the current user if not supplied | |
| 758 | + * | |
| 759 | + * @return array $user_quiz_grades or false if none exists for this users | |
| 760 | + */ | |
| 761 | +	 public function get_user_grades( $lesson_id, $user_id = 0 ){ | |
| 762 | + | |
| 763 | + $user_grades = array(); | |
| 764 | + | |
| 765 | + // get the user_id if none was passed in use the current logged in user | |
| 766 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 767 | + $user_id = get_current_user_id(); | |
| 768 | + } | |
| 769 | + | |
| 770 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 771 | +			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 772 | + return false; | |
| 773 | + } | |
| 774 | + | |
| 775 | + // save some time and get the transient cached data | |
| 776 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 777 | + $user_grades = get_transient( $transient_key ); | |
| 778 | + | |
| 779 | + // get the data if nothing was stored in the transient | |
| 780 | +		 if( empty( $user_grades  ) || false != $user_grades ){ | |
| 781 | + | |
| 782 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 783 | + | |
| 784 | + //set the transient with the new valid data for faster retrieval in future | |
| 785 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); | |
| 786 | + | |
| 787 | + } // end if transient check | |
| 788 | + | |
| 789 | + // if there is no data for this user | |
| 790 | +		 if( ! is_array( $user_grades ) ){ | |
| 791 | + return false; | |
| 792 | + } | |
| 793 | + | |
| 794 | + return $user_grades; | |
| 795 | + | |
| 796 | + }// end get_user_grades | |
| 797 | + | |
| 798 | + /** | |
| 799 | + * Get the user question grade | |
| 800 | + * | |
| 801 | + * This function gets the grade on a quiz for the given question parameter | |
| 802 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. | |
| 803 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 804 | + * | |
| 805 | + * @since 1.7.4 | |
| 806 | + * | |
| 807 | + * @param int $lesson_id | |
| 808 | + * @param int $question_id | |
| 809 | + * @param int $user_id ( optional ) | |
| 810 | + * | |
| 811 | + * @return bool $question_grade | |
| 812 | + */ | |
| 813 | +	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ | |
| 814 | + | |
| 815 | + // parameter validation | |
| 816 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 817 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 818 | + || ! ( intval( $question_id ) > 0 ) | |
| 819 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 820 | +			 || 'question' != get_post_type( $question_id )) { | |
| 821 | + | |
| 822 | + return false; | |
| 823 | + } | |
| 824 | + | |
| 825 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); | |
| 826 | + | |
| 827 | +		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){ | |
| 828 | + | |
| 829 | + //fallback to data pre 1.7.4 | |
| 830 | + $args = array( | |
| 831 | + 'post_id' => $question_id, | |
| 832 | + 'user_id' => $user_id, | |
| 833 | + 'type' => 'sensei_user_answer' | |
| 834 | + ); | |
| 835 | + | |
| 836 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 837 | + $fall_back_grade = false; | |
| 838 | +			 if( isset( $question_activity->comment_ID ) ){ | |
| 839 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); | |
| 840 | + } | |
| 841 | + | |
| 842 | + return $fall_back_grade; | |
| 843 | + | |
| 844 | + } // end if $all_user_grades... | |
| 845 | + | |
| 846 | + return $all_user_grades[ $question_id ]; | |
| 847 | + | |
| 848 | + }// end get_user_question_grade | |
| 849 | + | |
| 850 | + /** | |
| 851 | + * Save the user's answers feedback | |
| 852 | + * | |
| 853 | + * For this function you must supply all three parameters. If will return false one is left out. | |
| 854 | + * The data will be saved on the lesson ID supplied. | |
| 855 | + * | |
| 856 | + * @since 1.7.5 | |
| 857 | + * @access public | |
| 858 | + * | |
| 859 | +	  * @param array $answers_feedback{ | |
| 860 | + * $type int $question_id | |
| 861 | + * $type string $question_feedback | |
| 862 | + * } | |
| 863 | + * @param int $lesson_id | |
| 864 | + * @param int $user_id | |
| 865 | + * | |
| 866 | + * @return false or int $feedback_saved | |
| 867 | + */ | |
| 868 | +	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ | |
| 869 | + | |
| 870 | + // make sure the parameters are valid before continuing | |
| 871 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 872 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 873 | + ||!get_userdata( $user_id ) | |
| 874 | +			|| !is_array( $answers_feedback ) ){ | |
| 875 | + | |
| 876 | + return false; | |
| 877 | + | |
| 878 | + } | |
| 879 | + | |
| 880 | + | |
| 881 | + // check if the lesson is started before saving, if not start the lesson for the user | |
| 882 | +		if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { | |
| 883 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 884 | + } | |
| 629 | 885 | |
| 630 | - /** | |
| 631 | - * User quiz has been submitted | |
| 632 | - * | |
| 633 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission | |
| 634 | - * results. | |
| 635 | - * | |
| 636 | - * @param int $user_id | |
| 637 | - * @param int $quiz_id | |
| 638 | - * @param string $grade | |
| 639 | - * @param string $quiz_pass_percentage | |
| 640 | - * @param string $quiz_grade_type | |
| 641 | - */ | |
| 642 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); | |
| 886 | + // encode the feedback | |
| 887 | + $encoded_answers_feedback = array(); | |
| 888 | +		foreach( $answers_feedback as $question_id => $feedback ){ | |
| 889 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); | |
| 890 | + } | |
| 891 | + | |
| 892 | + // save the user data | |
| 893 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; | |
| 894 | + | |
| 895 | + //Were the the question feedback save correctly? | |
| 896 | +		if( intval( $feedback_saved ) > 0){ | |
| 897 | + | |
| 898 | + // save transient to make retrieval faster in future | |
| 899 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 900 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); | |
| 643 | 901 | |
| 644 | - return $answers_submitted; | |
| 902 | + } | |
| 903 | + | |
| 904 | + return $feedback_saved; | |
| 905 | + | |
| 906 | + } // end save_user_answers_feedback | |
| 907 | + | |
| 908 | + /** | |
| 909 | + * Get the user's answers feedback. | |
| 910 | + * | |
| 911 | + * This function returns the feedback submitted by the teacher/admin | |
| 912 | + * during grading. Grading occurs manually or automatically. | |
| 913 | + * | |
| 914 | + * @since 1.7.5 | |
| 915 | + * @access public | |
| 916 | + * | |
| 917 | + * @param int $lesson_id | |
| 918 | + * @param int $user_id | |
| 919 | + * | |
| 920 | +	  * @return false | array $answers_feedback{ | |
| 921 | + * $type int $question_id | |
| 922 | + * $type string $question_feedback | |
| 923 | + * } | |
| 924 | + */ | |
| 925 | +	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ | |
| 926 | + | |
| 927 | + $answers_feedback = array(); | |
| 645 | 928 | |
| 646 | - }// end submit_answers_for_grading | |
| 929 | + // get the user_id if none was passed in use the current logged in user | |
| 930 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 931 | + $user_id = get_current_user_id(); | |
| 932 | + } | |
| 647 | 933 | |
| 648 | - /** | |
| 649 | - * Get the user question answer | |
| 650 | - * | |
| 651 | - * This function gets the the users saved answer on given quiz for the given question parameter | |
| 652 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 653 | - * | |
| 654 | - * @since 1.7.4 | |
| 655 | - * | |
| 656 | - * @param int $lesson_id | |
| 657 | - * @param int $question_id | |
| 658 | - * @param int $user_id ( optional ) | |
| 659 | - * | |
| 660 | - * @return bool $answers_submitted | |
| 661 | - */ | |
| 662 | -     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ | |
| 934 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 935 | +			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 936 | + return false; | |
| 937 | + } | |
| 938 | + | |
| 939 | + // first check the transient to save a few split seconds | |
| 940 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 941 | + $encoded_feedback = get_transient( $transient_key ); | |
| 942 | + | |
| 943 | + // get the data if nothing was stored in the transient | |
| 944 | +		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){ | |
| 945 | + | |
| 946 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 947 | + | |
| 948 | + //set the transient with the new valid data for faster retrieval in future | |
| 949 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 950 | + | |
| 951 | + } // end if transient check | |
| 663 | 952 | |
| 664 | - // parameter validation | |
| 665 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 666 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 667 | - || ! ( intval( $question_id ) > 0 ) | |
| 668 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 669 | -             || 'question' != get_post_type( $question_id )) { | |
| 953 | + // if there is no data for this user | |
| 954 | +		 if( ! is_array( $encoded_feedback ) ){ | |
| 955 | + return false; | |
| 956 | + } | |
| 670 | 957 | |
| 671 | - return false; | |
| 672 | - } | |
| 673 | - | |
| 674 | -         if( ! ( intval( $user_id ) > 0 )   ){ | |
| 675 | - $user_id = get_current_user_id(); | |
| 676 | - } | |
| 677 | - | |
| 678 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); | |
| 679 | - | |
| 680 | - if( !$users_answers || empty( $users_answers ) | |
| 681 | -         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ | |
| 682 | - | |
| 683 | - //Fallback for pre 1.7.4 data | |
| 684 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); | |
| 685 | - | |
| 686 | -             if( ! isset( $comment->comment_content ) ){ | |
| 687 | - return false; | |
| 688 | - } | |
| 689 | - | |
| 690 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); | |
| 691 | - } | |
| 692 | - | |
| 693 | - return $users_answers[ $question_id ]; | |
| 694 | - | |
| 695 | - }// end get_user_question_answer | |
| 696 | - | |
| 697 | - /** | |
| 698 | - * Saving the users quiz question grades | |
| 699 | - * | |
| 700 | - * This function save all the grades for all the question in a given quiz on the lesson | |
| 701 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage | |
| 702 | - * | |
| 703 | - * @since 1.7.4 | |
| 704 | - * | |
| 705 | -      * @param array $quiz_grades{ | |
| 706 | - * @type int $question_id | |
| 707 | - * @type int $question_grade | |
| 708 | - * } | |
| 709 | - * @param $lesson_id | |
| 710 | - * @param $user_id (Optional) will use the current user if not supplied | |
| 711 | - * | |
| 712 | - * @return bool | |
| 713 | - */ | |
| 714 | -     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ | |
| 715 | - | |
| 716 | - // get the user_id if none was passed in use the current logged in user | |
| 717 | -         if( ! intval( $user_id ) > 0 ) { | |
| 718 | - $user_id = get_current_user_id(); | |
| 719 | - } | |
| 720 | - | |
| 721 | - // make sure the parameters are valid before continuing | |
| 722 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 723 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 724 | - ||!get_userdata( $user_id ) | |
| 725 | -             || !is_array( $quiz_grades ) ){ | |
| 726 | - | |
| 727 | - return false; | |
| 728 | - | |
| 729 | - } | |
| 730 | - | |
| 731 | - $success = false; | |
| 732 | - | |
| 733 | - // save that data for the user on the lesson comment meta | |
| 734 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); | |
| 735 | - | |
| 736 | - // were the grades save successfully ? | |
| 737 | -         if( intval( $comment_meta_id ) > 0 ) { | |
| 738 | - | |
| 739 | - $success = true; | |
| 740 | - // save transient | |
| 741 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 742 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); | |
| 743 | - } | |
| 744 | - | |
| 745 | - return $success; | |
| 746 | - | |
| 747 | - }// end set_user_grades | |
| 748 | - | |
| 749 | - /** | |
| 750 | - * Retrieve the users quiz question grades | |
| 751 | - * | |
| 752 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. | |
| 753 | - * | |
| 754 | - * @since 1.7.4 | |
| 755 | - * | |
| 756 | - * @param $lesson_id | |
| 757 | - * @param $user_id (Optional) will use the current user if not supplied | |
| 758 | - * | |
| 759 | - * @return array $user_quiz_grades or false if none exists for this users | |
| 760 | - */ | |
| 761 | -     public function get_user_grades( $lesson_id, $user_id = 0 ){ | |
| 762 | - | |
| 763 | - $user_grades = array(); | |
| 764 | - | |
| 765 | - // get the user_id if none was passed in use the current logged in user | |
| 766 | -         if( ! intval( $user_id ) > 0 ) { | |
| 767 | - $user_id = get_current_user_id(); | |
| 768 | - } | |
| 769 | - | |
| 770 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 771 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 772 | - return false; | |
| 773 | - } | |
| 774 | - | |
| 775 | - // save some time and get the transient cached data | |
| 776 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 777 | - $user_grades = get_transient( $transient_key ); | |
| 778 | - | |
| 779 | - // get the data if nothing was stored in the transient | |
| 780 | -         if( empty( $user_grades  ) || false != $user_grades ){ | |
| 781 | - | |
| 782 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 783 | - | |
| 784 | - //set the transient with the new valid data for faster retrieval in future | |
| 785 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); | |
| 786 | - | |
| 787 | - } // end if transient check | |
| 788 | - | |
| 789 | - // if there is no data for this user | |
| 790 | -         if( ! is_array( $user_grades ) ){ | |
| 791 | - return false; | |
| 792 | - } | |
| 793 | - | |
| 794 | - return $user_grades; | |
| 795 | - | |
| 796 | - }// end get_user_grades | |
| 797 | - | |
| 798 | - /** | |
| 799 | - * Get the user question grade | |
| 800 | - * | |
| 801 | - * This function gets the grade on a quiz for the given question parameter | |
| 802 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. | |
| 803 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 804 | - * | |
| 805 | - * @since 1.7.4 | |
| 806 | - * | |
| 807 | - * @param int $lesson_id | |
| 808 | - * @param int $question_id | |
| 809 | - * @param int $user_id ( optional ) | |
| 810 | - * | |
| 811 | - * @return bool $question_grade | |
| 812 | - */ | |
| 813 | -     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ | |
| 814 | - | |
| 815 | - // parameter validation | |
| 816 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 817 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 818 | - || ! ( intval( $question_id ) > 0 ) | |
| 819 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 820 | -             || 'question' != get_post_type( $question_id )) { | |
| 821 | - | |
| 822 | - return false; | |
| 823 | - } | |
| 824 | - | |
| 825 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); | |
| 826 | - | |
| 827 | -         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){ | |
| 828 | - | |
| 829 | - //fallback to data pre 1.7.4 | |
| 830 | - $args = array( | |
| 831 | - 'post_id' => $question_id, | |
| 832 | - 'user_id' => $user_id, | |
| 833 | - 'type' => 'sensei_user_answer' | |
| 834 | - ); | |
| 835 | - | |
| 836 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 837 | - $fall_back_grade = false; | |
| 838 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 839 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); | |
| 840 | - } | |
| 841 | - | |
| 842 | - return $fall_back_grade; | |
| 843 | - | |
| 844 | - } // end if $all_user_grades... | |
| 845 | - | |
| 846 | - return $all_user_grades[ $question_id ]; | |
| 847 | - | |
| 848 | - }// end get_user_question_grade | |
| 849 | - | |
| 850 | - /** | |
| 851 | - * Save the user's answers feedback | |
| 852 | - * | |
| 853 | - * For this function you must supply all three parameters. If will return false one is left out. | |
| 854 | - * The data will be saved on the lesson ID supplied. | |
| 855 | - * | |
| 856 | - * @since 1.7.5 | |
| 857 | - * @access public | |
| 858 | - * | |
| 859 | -      * @param array $answers_feedback{ | |
| 860 | - * $type int $question_id | |
| 861 | - * $type string $question_feedback | |
| 862 | - * } | |
| 863 | - * @param int $lesson_id | |
| 864 | - * @param int $user_id | |
| 865 | - * | |
| 866 | - * @return false or int $feedback_saved | |
| 867 | - */ | |
| 868 | -    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ | |
| 869 | - | |
| 870 | - // make sure the parameters are valid before continuing | |
| 871 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 872 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 873 | - ||!get_userdata( $user_id ) | |
| 874 | -            || !is_array( $answers_feedback ) ){ | |
| 875 | - | |
| 876 | - return false; | |
| 877 | - | |
| 878 | - } | |
| 879 | - | |
| 880 | - | |
| 881 | - // check if the lesson is started before saving, if not start the lesson for the user | |
| 882 | -        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { | |
| 883 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 884 | - } | |
| 885 | - | |
| 886 | - // encode the feedback | |
| 887 | - $encoded_answers_feedback = array(); | |
| 888 | -        foreach( $answers_feedback as $question_id => $feedback ){ | |
| 889 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); | |
| 890 | - } | |
| 891 | - | |
| 892 | - // save the user data | |
| 893 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; | |
| 894 | - | |
| 895 | - //Were the the question feedback save correctly? | |
| 896 | -        if( intval( $feedback_saved ) > 0){ | |
| 897 | - | |
| 898 | - // save transient to make retrieval faster in future | |
| 899 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 900 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); | |
| 901 | - | |
| 902 | - } | |
| 903 | - | |
| 904 | - return $feedback_saved; | |
| 905 | - | |
| 906 | - } // end save_user_answers_feedback | |
| 907 | - | |
| 908 | - /** | |
| 909 | - * Get the user's answers feedback. | |
| 910 | - * | |
| 911 | - * This function returns the feedback submitted by the teacher/admin | |
| 912 | - * during grading. Grading occurs manually or automatically. | |
| 913 | - * | |
| 914 | - * @since 1.7.5 | |
| 915 | - * @access public | |
| 916 | - * | |
| 917 | - * @param int $lesson_id | |
| 918 | - * @param int $user_id | |
| 919 | - * | |
| 920 | -      * @return false | array $answers_feedback{ | |
| 921 | - * $type int $question_id | |
| 922 | - * $type string $question_feedback | |
| 923 | - * } | |
| 924 | - */ | |
| 925 | -     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ | |
| 926 | - | |
| 927 | - $answers_feedback = array(); | |
| 928 | - | |
| 929 | - // get the user_id if none was passed in use the current logged in user | |
| 930 | -         if( ! intval( $user_id ) > 0 ) { | |
| 931 | - $user_id = get_current_user_id(); | |
| 932 | - } | |
| 933 | - | |
| 934 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 935 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 936 | - return false; | |
| 937 | - } | |
| 938 | - | |
| 939 | - // first check the transient to save a few split seconds | |
| 940 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 941 | - $encoded_feedback = get_transient( $transient_key ); | |
| 942 | - | |
| 943 | - // get the data if nothing was stored in the transient | |
| 944 | -         if( empty( $encoded_feedback  ) || !$encoded_feedback ){ | |
| 945 | - | |
| 946 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 947 | - | |
| 948 | - //set the transient with the new valid data for faster retrieval in future | |
| 949 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 950 | - | |
| 951 | - } // end if transient check | |
| 952 | - | |
| 953 | - // if there is no data for this user | |
| 954 | -         if( ! is_array( $encoded_feedback ) ){ | |
| 955 | - return false; | |
| 956 | - } | |
| 957 | - | |
| 958 | -         foreach( $encoded_feedback as $question_id => $feedback ){ | |
| 958 | +		 foreach( $encoded_feedback as $question_id => $feedback ){ | |
| 959 | 959 | |
| 960 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); | |
| 960 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); | |
| 961 | 961 | |
| 962 | - } | |
| 962 | + } | |
| 963 | 963 | |
| 964 | - return $answers_feedback; | |
| 964 | + return $answers_feedback; | |
| 965 | 965 | |
| 966 | - } // end get_user_answers_feedback | |
| 966 | + } // end get_user_answers_feedback | |
| 967 | 967 | |
| 968 | - /** | |
| 969 | - * Get the user's answer feedback for a specific question. | |
| 970 | - * | |
| 971 | - * This function gives you a single answer note/feedback string | |
| 972 | - * for the user on the given question. | |
| 973 | - * | |
| 974 | - * @since 1.7.5 | |
| 975 | - * @access public | |
| 976 | - * | |
| 977 | - * @param int $lesson_id | |
| 978 | - * @param int $question_id | |
| 979 | - * @param int $user_id | |
| 980 | - * | |
| 981 | - * @return string $feedback or bool if false | |
| 982 | - */ | |
| 983 | -     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ | |
| 968 | + /** | |
| 969 | + * Get the user's answer feedback for a specific question. | |
| 970 | + * | |
| 971 | + * This function gives you a single answer note/feedback string | |
| 972 | + * for the user on the given question. | |
| 973 | + * | |
| 974 | + * @since 1.7.5 | |
| 975 | + * @access public | |
| 976 | + * | |
| 977 | + * @param int $lesson_id | |
| 978 | + * @param int $question_id | |
| 979 | + * @param int $user_id | |
| 980 | + * | |
| 981 | + * @return string $feedback or bool if false | |
| 982 | + */ | |
| 983 | +	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ | |
| 984 | 984 | |
| 985 | - $feedback = false; | |
| 985 | + $feedback = false; | |
| 986 | 986 | |
| 987 | - // parameter validation | |
| 988 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 989 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 990 | - || ! ( intval( $question_id ) > 0 ) | |
| 991 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 992 | -             || 'question' != get_post_type( $question_id )) { | |
| 987 | + // parameter validation | |
| 988 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 989 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 990 | + || ! ( intval( $question_id ) > 0 ) | |
| 991 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 992 | +			 || 'question' != get_post_type( $question_id )) { | |
| 993 | 993 | |
| 994 | - return false; | |
| 995 | - } | |
| 994 | + return false; | |
| 995 | + } | |
| 996 | 996 | |
| 997 | - // get all the feedback for the user on the given lesson | |
| 998 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); | |
| 997 | + // get all the feedback for the user on the given lesson | |
| 998 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); | |
| 999 | 999 | |
| 1000 | - if( !$all_feedback || empty( $all_feedback ) | |
| 1001 | -             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ | |
| 1000 | + if( !$all_feedback || empty( $all_feedback ) | |
| 1001 | +			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ | |
| 1002 | 1002 | |
| 1003 | - //fallback to data pre 1.7.4 | |
| 1003 | + //fallback to data pre 1.7.4 | |
| 1004 | 1004 | |
| 1005 | - // setup the sensei data query | |
| 1006 | - $args = array( | |
| 1007 | - 'post_id' => $question_id, | |
| 1008 | - 'user_id' => $user_id, | |
| 1009 | - 'type' => 'sensei_user_answer' | |
| 1010 | - ); | |
| 1011 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 1005 | + // setup the sensei data query | |
| 1006 | + $args = array( | |
| 1007 | + 'post_id' => $question_id, | |
| 1008 | + 'user_id' => $user_id, | |
| 1009 | + 'type' => 'sensei_user_answer' | |
| 1010 | + ); | |
| 1011 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 1012 | 1012 | |
| 1013 | - // set the default to false and return that if no old data is available. | |
| 1014 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 1015 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); | |
| 1016 | - } | |
| 1013 | + // set the default to false and return that if no old data is available. | |
| 1014 | +			 if( isset( $question_activity->comment_ID ) ){ | |
| 1015 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); | |
| 1016 | + } | |
| 1017 | 1017 | |
| 1018 | - // finally use the default question feedback | |
| 1019 | -             if( empty( $feedback ) ){ | |
| 1020 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); | |
| 1021 | - } | |
| 1018 | + // finally use the default question feedback | |
| 1019 | +			 if( empty( $feedback ) ){ | |
| 1020 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); | |
| 1021 | + } | |
| 1022 | 1022 | |
| 1023 | - return $feedback; | |
| 1023 | + return $feedback; | |
| 1024 | 1024 | |
| 1025 | - } | |
| 1025 | + } | |
| 1026 | 1026 | |
| 1027 | - return $all_feedback[ $question_id ]; | |
| 1027 | + return $all_feedback[ $question_id ]; | |
| 1028 | 1028 | |
| 1029 | - } // end get_user_question_feedback | |
| 1029 | + } // end get_user_question_feedback | |
| 1030 | 1030 | |
| 1031 | - /** | |
| 1032 | - * Check if a quiz has no questions, and redirect back to lesson. | |
| 1033 | - * | |
| 1034 | - * Though a quiz is created for each lesson, it should not be visible | |
| 1035 | - * unless it has questions. | |
| 1036 | - * | |
| 1037 | - * @since 1.9.0 | |
| 1038 | - * @access public | |
| 1039 | - * @param none | |
| 1040 | - * @return void | |
| 1041 | - */ | |
| 1031 | + /** | |
| 1032 | + * Check if a quiz has no questions, and redirect back to lesson. | |
| 1033 | + * | |
| 1034 | + * Though a quiz is created for each lesson, it should not be visible | |
| 1035 | + * unless it has questions. | |
| 1036 | + * | |
| 1037 | + * @since 1.9.0 | |
| 1038 | + * @access public | |
| 1039 | + * @param none | |
| 1040 | + * @return void | |
| 1041 | + */ | |
| 1042 | 1042 | |
| 1043 | -     public function quiz_has_no_questions() { | |
| 1043 | +	 public function quiz_has_no_questions() { | |
| 1044 | 1044 | |
| 1045 | -         if( ! is_singular( 'quiz' ) )  { | |
| 1046 | - return; | |
| 1047 | - } | |
| 1045 | +		 if( ! is_singular( 'quiz' ) )  { | |
| 1046 | + return; | |
| 1047 | + } | |
| 1048 | 1048 | |
| 1049 | - global $post; | |
| 1049 | + global $post; | |
| 1050 | 1050 | |
| 1051 | - $lesson_id = $this->get_lesson_id($post->ID); | |
| 1051 | + $lesson_id = $this->get_lesson_id($post->ID); | |
| 1052 | 1052 | |
| 1053 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); | |
| 1053 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); | |
| 1054 | 1054 | |
| 1055 | - $lesson = get_post($lesson_id); | |
| 1055 | + $lesson = get_post($lesson_id); | |
| 1056 | 1056 | |
| 1057 | -         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { | |
| 1057 | +		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { | |
| 1058 | 1058 | |
| 1059 | - wp_redirect(get_permalink($lesson->ID), 301); | |
| 1060 | - exit; | |
| 1059 | + wp_redirect(get_permalink($lesson->ID), 301); | |
| 1060 | + exit; | |
| 1061 | 1061 | |
| 1062 | - } | |
| 1062 | + } | |
| 1063 | 1063 | |
| 1064 | - } // end quiz_has_no_questions | |
| 1064 | + } // end quiz_has_no_questions | |
| 1065 | 1065 | |
| 1066 | 1066 | /** | 
| 1067 | - * Deprecate the sensei_single_main_content on the single-quiz template. | |
| 1068 | - * | |
| 1069 | - * @deprecated since 1.9.0 | |
| 1070 | - */ | |
| 1067 | + * Deprecate the sensei_single_main_content on the single-quiz template. | |
| 1068 | + * | |
| 1069 | + * @deprecated since 1.9.0 | |
| 1070 | + */ | |
| 1071 | 1071 |   public static function deprecate_quiz_sensei_single_main_content_hook(){ | 
| 1072 | 1072 | |
| 1073 | -     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); | |
| 1073 | +	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); | |
| 1074 | 1074 | |
| 1075 | 1075 | } | 
| 1076 | - /* | |
| 1076 | + /* | |
| 1077 | 1077 | * Deprecate the sensei_quiz_single_title on the single-quiz template. | 
| 1078 | 1078 | * | 
| 1079 | 1079 | * @deprecated since 1.9.0 | 
| 1080 | 1080 | */ | 
| 1081 | -     public static function deprecate_quiz_sensei_quiz_single_title_hook(){ | |
| 1081 | +	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){ | |
| 1082 | 1082 | |
| 1083 | -         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); | |
| 1083 | +		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); | |
| 1084 | 1084 | |
| 1085 | - } | |
| 1085 | + } | |
| 1086 | 1086 | |
| 1087 | - /** | |
| 1088 | - * Filter the single title and add the Quiz to it. | |
| 1089 | - * | |
| 1090 | - * @param string $title | |
| 1091 | - * @param int $id title post id | |
| 1092 | - * @return string $quiz_title | |
| 1093 | - */ | |
| 1094 | -     public static function single_quiz_title( $title, $post_id ){ | |
| 1087 | + /** | |
| 1088 | + * Filter the single title and add the Quiz to it. | |
| 1089 | + * | |
| 1090 | + * @param string $title | |
| 1091 | + * @param int $id title post id | |
| 1092 | + * @return string $quiz_title | |
| 1093 | + */ | |
| 1094 | +	 public static function single_quiz_title( $title, $post_id ){ | |
| 1095 | 1095 | |
| 1096 | -         if( 'quiz' == get_post_type( $post_id ) ){ | |
| 1096 | +		 if( 'quiz' == get_post_type( $post_id ) ){ | |
| 1097 | 1097 | |
| 1098 | - $title_with_no_quizzes = $title; | |
| 1098 | + $title_with_no_quizzes = $title; | |
| 1099 | 1099 | |
| 1100 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. | |
| 1101 | -             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ | |
| 1100 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. | |
| 1101 | +			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ | |
| 1102 | 1102 | |
| 1103 | - // remove all possible appearances of quiz | |
| 1104 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); | |
| 1105 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); | |
| 1106 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); | |
| 1103 | + // remove all possible appearances of quiz | |
| 1104 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); | |
| 1105 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); | |
| 1106 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); | |
| 1107 | 1107 | |
| 1108 | - } | |
| 1108 | + } | |
| 1109 | 1109 | |
| 1110 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); | |
| 1111 | - } | |
| 1110 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); | |
| 1111 | + } | |
| 1112 | 1112 | |
| 1113 | - /** | |
| 1114 | - * hook document in class-woothemes-sensei-message.php | |
| 1115 | - */ | |
| 1116 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); | |
| 1113 | + /** | |
| 1114 | + * hook document in class-woothemes-sensei-message.php | |
| 1115 | + */ | |
| 1116 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); | |
| 1117 | 1117 | |
| 1118 | - } | |
| 1118 | + } | |
| 1119 | 1119 | |
| 1120 | - /** | |
| 1121 | - * Initialize the quiz question loop on the single quiz template | |
| 1122 | - * | |
| 1123 | - * The function will create a global quiz loop varialbe. | |
| 1124 | - * | |
| 1125 | - * @since 1.9.0 | |
| 1126 | - * | |
| 1127 | - */ | |
| 1128 | -     public static function start_quiz_questions_loop(){ | |
| 1120 | + /** | |
| 1121 | + * Initialize the quiz question loop on the single quiz template | |
| 1122 | + * | |
| 1123 | + * The function will create a global quiz loop varialbe. | |
| 1124 | + * | |
| 1125 | + * @since 1.9.0 | |
| 1126 | + * | |
| 1127 | + */ | |
| 1128 | +	 public static function start_quiz_questions_loop(){ | |
| 1129 | 1129 | |
| 1130 | - global $sensei_question_loop; | |
| 1130 | + global $sensei_question_loop; | |
| 1131 | 1131 | |
| 1132 | - //intialize the questions loop object | |
| 1133 | - $sensei_question_loop['current'] = -1; | |
| 1134 | - $sensei_question_loop['total'] = 0; | |
| 1135 | - $sensei_question_loop['questions'] = array(); | |
| 1132 | + //intialize the questions loop object | |
| 1133 | + $sensei_question_loop['current'] = -1; | |
| 1134 | + $sensei_question_loop['total'] = 0; | |
| 1135 | + $sensei_question_loop['questions'] = array(); | |
| 1136 | 1136 | |
| 1137 | 1137 | |
| 1138 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| 1138 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| 1139 | 1139 | |
| 1140 | -         if( count( $questions  ) > 0  ){ | |
| 1140 | +		 if( count( $questions  ) > 0  ){ | |
| 1141 | 1141 | |
| 1142 | - $sensei_question_loop['total'] = count( $questions ); | |
| 1143 | - $sensei_question_loop['questions'] = $questions; | |
| 1144 | - $sensei_question_loop['quiz_id'] = get_the_ID(); | |
| 1142 | + $sensei_question_loop['total'] = count( $questions ); | |
| 1143 | + $sensei_question_loop['questions'] = $questions; | |
| 1144 | + $sensei_question_loop['quiz_id'] = get_the_ID(); | |
| 1145 | 1145 | |
| 1146 | - } | |
| 1146 | + } | |
| 1147 | 1147 | |
| 1148 | - }// static function | |
| 1148 | + }// static function | |
| 1149 | 1149 | |
| 1150 | - /** | |
| 1151 | - * Initialize the quiz question loop on the single quiz template | |
| 1152 | - * | |
| 1153 | - * The function will create a global quiz loop varialbe. | |
| 1154 | - * | |
| 1155 | - * @since 1.9.0 | |
| 1156 | - * | |
| 1157 | - */ | |
| 1158 | -     public static function stop_quiz_questions_loop(){ | |
| 1150 | + /** | |
| 1151 | + * Initialize the quiz question loop on the single quiz template | |
| 1152 | + * | |
| 1153 | + * The function will create a global quiz loop varialbe. | |
| 1154 | + * | |
| 1155 | + * @since 1.9.0 | |
| 1156 | + * | |
| 1157 | + */ | |
| 1158 | +	 public static function stop_quiz_questions_loop(){ | |
| 1159 | 1159 | |
| 1160 | - $sensei_question_loop['total'] = 0; | |
| 1161 | - $sensei_question_loop['questions'] = array(); | |
| 1162 | - $sensei_question_loop['quiz_id'] = ''; | |
| 1160 | + $sensei_question_loop['total'] = 0; | |
| 1161 | + $sensei_question_loop['questions'] = array(); | |
| 1162 | + $sensei_question_loop['quiz_id'] = ''; | |
| 1163 | 1163 | |
| 1164 | - } | |
| 1164 | + } | |
| 1165 | 1165 | |
| 1166 | - /** | |
| 1167 | - * Output the title for the single quiz page | |
| 1168 | - * | |
| 1169 | - * @since 1.9.0 | |
| 1170 | - */ | |
| 1171 | -     public static function the_title(){ | |
| 1172 | - ?> | |
| 1166 | + /** | |
| 1167 | + * Output the title for the single quiz page | |
| 1168 | + * | |
| 1169 | + * @since 1.9.0 | |
| 1170 | + */ | |
| 1171 | +	 public static function the_title(){ | |
| 1172 | + ?> | |
| 1173 | 1173 | <header> | 
| 1174 | 1174 | |
| 1175 | 1175 | <h1> | 
| 1176 | 1176 | |
| 1177 | 1177 | <?php | 
| 1178 | - /** | |
| 1179 | - * Filter documented in class-sensei-messages.php the_title | |
| 1180 | - */ | |
| 1181 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); | |
| 1182 | - ?> | |
| 1178 | + /** | |
| 1179 | + * Filter documented in class-sensei-messages.php the_title | |
| 1180 | + */ | |
| 1181 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); | |
| 1182 | + ?> | |
| 1183 | 1183 | |
| 1184 | 1184 | </h1> | 
| 1185 | 1185 | |
| 1186 | 1186 | </header> | 
| 1187 | 1187 | |
| 1188 | 1188 | <?php | 
| 1189 | - }//the_title | |
| 1189 | + }//the_title | |
| 1190 | 1190 | |
| 1191 | - /** | |
| 1192 | - * Output the sensei quiz status message. | |
| 1193 | - * | |
| 1194 | - * @param $quiz_id | |
| 1195 | - */ | |
| 1196 | -    public static function  the_user_status_message( $quiz_id ){ | |
| 1191 | + /** | |
| 1192 | + * Output the sensei quiz status message. | |
| 1193 | + * | |
| 1194 | + * @param $quiz_id | |
| 1195 | + */ | |
| 1196 | +	public static function  the_user_status_message( $quiz_id ){ | |
| 1197 | 1197 | |
| 1198 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 1199 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); | |
| 1200 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; | |
| 1198 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 1199 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); | |
| 1200 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; | |
| 1201 | 1201 | |
| 1202 | - } | |
| 1202 | + } | |
| 1203 | 1203 | |
| 1204 | - /** | |
| 1205 | - * This functions runs the old sensei_quiz_action_buttons action | |
| 1206 | - * for backwards compatiblity sake. | |
| 1207 | - * | |
| 1208 | - * @since 1.9.0 | |
| 1209 | - * @deprecated | |
| 1210 | - */ | |
| 1211 | -     public static function deprecate_sensei_quiz_action_buttons_hook(){ | |
| 1204 | + /** | |
| 1205 | + * This functions runs the old sensei_quiz_action_buttons action | |
| 1206 | + * for backwards compatiblity sake. | |
| 1207 | + * | |
| 1208 | + * @since 1.9.0 | |
| 1209 | + * @deprecated | |
| 1210 | + */ | |
| 1211 | +	 public static function deprecate_sensei_quiz_action_buttons_hook(){ | |
| 1212 | 1212 | |
| 1213 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1213 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1214 | 1214 | |
| 1215 | - } | |
| 1215 | + } | |
| 1216 | 1216 | |
| 1217 | - /** | |
| 1218 | - * The quiz action buttons needed to ouput quiz | |
| 1219 | - * action such as reset complete and save. | |
| 1220 | - * | |
| 1221 | - * @since 1.3.0 | |
| 1222 | - */ | |
| 1223 | -     public static function action_buttons() { | |
| 1217 | + /** | |
| 1218 | + * The quiz action buttons needed to ouput quiz | |
| 1219 | + * action such as reset complete and save. | |
| 1220 | + * | |
| 1221 | + * @since 1.3.0 | |
| 1222 | + */ | |
| 1223 | +	 public static function action_buttons() { | |
| 1224 | 1224 | |
| 1225 | - global $post, $current_user; | |
| 1225 | + global $post, $current_user; | |
| 1226 | 1226 | |
| 1227 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); | |
| 1228 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 1229 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); | |
| 1230 | - $show_actions = true; | |
| 1231 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); | |
| 1227 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); | |
| 1228 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 1229 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); | |
| 1230 | + $show_actions = true; | |
| 1231 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); | |
| 1232 | 1232 | |
| 1233 | - //setup quiz grade | |
| 1234 | - $user_quiz_grade = ''; | |
| 1235 | -         if( ! empty( $user_lesson_status  ) ){ | |
| 1236 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1237 | - } | |
| 1233 | + //setup quiz grade | |
| 1234 | + $user_quiz_grade = ''; | |
| 1235 | +		 if( ! empty( $user_lesson_status  ) ){ | |
| 1236 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1237 | + } | |
| 1238 | 1238 | |
| 1239 | 1239 | |
| 1240 | -         if( intval( $lesson_prerequisite ) > 0 ) { | |
| 1240 | +		 if( intval( $lesson_prerequisite ) > 0 ) { | |
| 1241 | 1241 | |
| 1242 | - // If the user hasn't completed the prereq then hide the current actions | |
| 1243 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); | |
| 1242 | + // If the user hasn't completed the prereq then hide the current actions | |
| 1243 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); | |
| 1244 | 1244 | |
| 1245 | - } | |
| 1246 | -         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { | |
| 1245 | + } | |
| 1246 | +		 if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { | |
| 1247 | 1247 | |
| 1248 | - // Get Reset Settings | |
| 1249 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> | |
| 1248 | + // Get Reset Settings | |
| 1249 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> | |
| 1250 | 1250 | |
| 1251 | 1251 | <!-- Action Nonce's --> | 
| 1252 | 1252 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" | 
| @@ -1273,55 +1273,55 @@ discard block | ||
| 1273 | 1273 | |
| 1274 | 1274 | <?php } | 
| 1275 | 1275 | |
| 1276 | - } // End sensei_quiz_action_buttons() | |
| 1277 | - | |
| 1278 | - /** | |
| 1279 | - * Fetch the quiz grade | |
| 1280 | - * | |
| 1281 | - * @since 1.9.0 | |
| 1282 | - * | |
| 1283 | - * @param int $lesson_id | |
| 1284 | - * @param int $user_id | |
| 1285 | - * | |
| 1286 | - * @return double $user_quiz_grade | |
| 1287 | - */ | |
| 1288 | -     public static function get_user_quiz_grade( $lesson_id, $user_id ){ | |
| 1289 | - | |
| 1290 | - // get the quiz grade | |
| 1291 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 1292 | - $user_quiz_grade = 0; | |
| 1293 | -         if( isset( $user_lesson_status->comment_ID ) ) { | |
| 1294 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1295 | - } | |
| 1296 | - | |
| 1297 | - return (double) $user_quiz_grade; | |
| 1298 | - | |
| 1299 | - } | |
| 1300 | - | |
| 1301 | - /** | |
| 1302 | - * Check the quiz reset property for a given lesson's quiz. | |
| 1303 | - * | |
| 1304 | - * The data is stored on the quiz but going forward the quiz post | |
| 1305 | - * type will be retired, hence the lesson_id is a require parameter. | |
| 1306 | - * | |
| 1307 | - * @since 1.9.0 | |
| 1308 | - * | |
| 1309 | - * @param int $lesson_id | |
| 1310 | - * @return bool | |
| 1311 | - */ | |
| 1312 | -     public static function is_reset_allowed( $lesson_id ){ | |
| 1313 | - | |
| 1314 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 1315 | - | |
| 1316 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 1317 | - //backwards compatibility | |
| 1318 | -         if( 'on' == $reset_allowed ) { | |
| 1319 | - $reset_allowed = 1; | |
| 1320 | - } | |
| 1321 | - | |
| 1322 | - return (bool) $reset_allowed; | |
| 1323 | - | |
| 1324 | - } | |
| 1276 | + } // End sensei_quiz_action_buttons() | |
| 1277 | + | |
| 1278 | + /** | |
| 1279 | + * Fetch the quiz grade | |
| 1280 | + * | |
| 1281 | + * @since 1.9.0 | |
| 1282 | + * | |
| 1283 | + * @param int $lesson_id | |
| 1284 | + * @param int $user_id | |
| 1285 | + * | |
| 1286 | + * @return double $user_quiz_grade | |
| 1287 | + */ | |
| 1288 | +	 public static function get_user_quiz_grade( $lesson_id, $user_id ){ | |
| 1289 | + | |
| 1290 | + // get the quiz grade | |
| 1291 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 1292 | + $user_quiz_grade = 0; | |
| 1293 | +		 if( isset( $user_lesson_status->comment_ID ) ) { | |
| 1294 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1295 | + } | |
| 1296 | + | |
| 1297 | + return (double) $user_quiz_grade; | |
| 1298 | + | |
| 1299 | + } | |
| 1300 | + | |
| 1301 | + /** | |
| 1302 | + * Check the quiz reset property for a given lesson's quiz. | |
| 1303 | + * | |
| 1304 | + * The data is stored on the quiz but going forward the quiz post | |
| 1305 | + * type will be retired, hence the lesson_id is a require parameter. | |
| 1306 | + * | |
| 1307 | + * @since 1.9.0 | |
| 1308 | + * | |
| 1309 | + * @param int $lesson_id | |
| 1310 | + * @return bool | |
| 1311 | + */ | |
| 1312 | +	 public static function is_reset_allowed( $lesson_id ){ | |
| 1313 | + | |
| 1314 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 1315 | + | |
| 1316 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 1317 | + //backwards compatibility | |
| 1318 | +		 if( 'on' == $reset_allowed ) { | |
| 1319 | + $reset_allowed = 1; | |
| 1320 | + } | |
| 1321 | + | |
| 1322 | + return (bool) $reset_allowed; | |
| 1323 | + | |
| 1324 | + } | |
| 1325 | 1325 | |
| 1326 | 1326 | } // End Class WooThemes_Sensei_Quiz | 
| 1327 | 1327 | |
| @@ -178,8 +178,8 @@ | ||
| 178 | 178 | * | 
| 179 | 179 | * @since 1.9.0 | 
| 180 | 180 | * | 
| 181 | - * @param $hook_tag | |
| 182 | - * @param $version | |
| 181 | + * @param string $hook_tag | |
| 182 | + * @param string $version | |
| 183 | 183 | * @param $alternative | 
| 184 | 184 | * @param array $args | 
| 185 | 185 | */ | 
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Analysis User Profile List Table Class | 
| @@ -45,16 +45,16 @@ discard block | ||
| 45 | 45 | */ | 
| 46 | 46 |  function sensei_all_access() { | 
| 47 | 47 | |
| 48 | - $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Filter sensei_all_access function result | |
| 52 | - * which determinse if the current user | |
| 53 | - * can access all of Sensei without restrictions | |
| 54 | - * | |
| 55 | - * @since 1.4.0 | |
| 56 | - * @param bool $access | |
| 57 | - */ | |
| 48 | + $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Filter sensei_all_access function result | |
| 52 | + * which determinse if the current user | |
| 53 | + * can access all of Sensei without restrictions | |
| 54 | + * | |
| 55 | + * @since 1.4.0 | |
| 56 | + * @param bool $access | |
| 57 | + */ | |
| 58 | 58 | return apply_filters( 'sensei_all_access', $access ); | 
| 59 | 59 | |
| 60 | 60 | } // End sensei_all_access() | 
| @@ -72,7 +72,7 @@ discard block | ||
| 72 | 72 | */ | 
| 73 | 73 |  	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { | 
| 74 | 74 | |
| 75 | - $hex = str_replace( '#', '', $color ); | |
| 75 | + $hex = str_replace( '#', '', $color ); | |
| 76 | 76 | |
| 77 | 77 | $c_r = hexdec( substr( $hex, 0, 2 ) ); | 
| 78 | 78 | $c_g = hexdec( substr( $hex, 2, 2 ) ); | 
| @@ -119,15 +119,15 @@ discard block | ||
| 119 | 119 | $color = '#'; | 
| 120 | 120 | |
| 121 | 121 | foreach ($base as $k => $v) : | 
| 122 | - $amount = $v / 100; | |
| 123 | - $amount = round($amount * $factor); | |
| 124 | - $new_decimal = $v - $amount; | |
| 125 | - | |
| 126 | - $new_hex_component = dechex($new_decimal); | |
| 127 | - if(strlen($new_hex_component) < 2) : | |
| 128 | - $new_hex_component = "0".$new_hex_component; | |
| 129 | - endif; | |
| 130 | - $color .= $new_hex_component; | |
| 122 | + $amount = $v / 100; | |
| 123 | + $amount = round($amount * $factor); | |
| 124 | + $new_decimal = $v - $amount; | |
| 125 | + | |
| 126 | + $new_hex_component = dechex($new_decimal); | |
| 127 | + if(strlen($new_hex_component) < 2) : | |
| 128 | + $new_hex_component = "0".$new_hex_component; | |
| 129 | + endif; | |
| 130 | + $color .= $new_hex_component; | |
| 131 | 131 | endforeach; | 
| 132 | 132 | |
| 133 | 133 | return $color; | 
| @@ -148,17 +148,17 @@ discard block | ||
| 148 | 148 | $base = sensei_rgb_from_hex( $color ); | 
| 149 | 149 | $color = '#'; | 
| 150 | 150 | |
| 151 | - foreach ($base as $k => $v) : | |
| 152 | - $amount = 255 - $v; | |
| 153 | - $amount = $amount / 100; | |
| 154 | - $amount = round($amount * $factor); | |
| 155 | - $new_decimal = $v + $amount; | |
| 156 | - | |
| 157 | - $new_hex_component = dechex($new_decimal); | |
| 158 | - if(strlen($new_hex_component) < 2) : | |
| 159 | - $new_hex_component = "0".$new_hex_component; | |
| 160 | - endif; | |
| 161 | - $color .= $new_hex_component; | |
| 151 | + foreach ($base as $k => $v) : | |
| 152 | + $amount = 255 - $v; | |
| 153 | + $amount = $amount / 100; | |
| 154 | + $amount = round($amount * $factor); | |
| 155 | + $new_decimal = $v + $amount; | |
| 156 | + | |
| 157 | + $new_hex_component = dechex($new_decimal); | |
| 158 | + if(strlen($new_hex_component) < 2) : | |
| 159 | + $new_hex_component = "0".$new_hex_component; | |
| 160 | + endif; | |
| 161 | + $color .= $new_hex_component; | |
| 162 | 162 | endforeach; | 
| 163 | 163 | |
| 164 | 164 | return $color; | 
| @@ -172,14 +172,14 @@ discard block | ||
| 172 | 172 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() | 
| 173 | 173 | */ | 
| 174 | 174 |  if ( ! function_exists( 'is_woocommerce_active' ) ) { | 
| 175 | -    function is_woocommerce_active() { | |
| 176 | - // calling is present instead of is active here | |
| 177 | - // as this function can override other is_woocommerce_active | |
| 178 | - // function in other woo plugins and Sensei_WC::is_woocommerce_active | |
| 179 | - // also check the sensei settings for enable WooCommerce support, which | |
| 180 | - // other plugins should not check against. | |
| 181 | - return Sensei_WC::is_woocommerce_present(); | |
| 182 | - } | |
| 175 | +	function is_woocommerce_active() { | |
| 176 | + // calling is present instead of is active here | |
| 177 | + // as this function can override other is_woocommerce_active | |
| 178 | + // function in other woo plugins and Sensei_WC::is_woocommerce_active | |
| 179 | + // also check the sensei settings for enable WooCommerce support, which | |
| 180 | + // other plugins should not check against. | |
| 181 | + return Sensei_WC::is_woocommerce_present(); | |
| 182 | + } | |
| 183 | 183 | } | 
| 184 | 184 | |
| 185 | 185 | /** | 
| @@ -195,20 +195,20 @@ discard block | ||
| 195 | 195 | */ | 
| 196 | 196 |  function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){ | 
| 197 | 197 | |
| 198 | -    if( has_action( $hook_tag ) ){ | |
| 198 | +	if( has_action( $hook_tag ) ){ | |
| 199 | 199 | |
| 200 | - $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); | |
| 200 | + $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); | |
| 201 | 201 | |
| 202 | -        if( !empty( $alternative ) ){ | |
| 202 | +		if( !empty( $alternative ) ){ | |
| 203 | 203 | |
| 204 | -            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; | |
| 204 | +			$error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; | |
| 205 | 205 | |
| 206 | - } | |
| 206 | + } | |
| 207 | 207 | |
| 208 | - trigger_error( $error_message ); | |
| 209 | - do_action( $hook_tag , $args ); | |
| 208 | + trigger_error( $error_message ); | |
| 209 | + do_action( $hook_tag , $args ); | |
| 210 | 210 | |
| 211 | - } | |
| 211 | + } | |
| 212 | 212 | |
| 213 | 213 | }// end sensei_do_deprecated_action | 
| 214 | 214 | |
| @@ -238,18 +238,18 @@ discard block | ||
| 238 | 238 | */ | 
| 239 | 239 |  function sensei_user_login_url(){ | 
| 240 | 240 | |
| 241 | - $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); | |
| 242 | - $page = get_post( $my_courses_page_id ); | |
| 241 | + $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); | |
| 242 | + $page = get_post( $my_courses_page_id ); | |
| 243 | 243 | |
| 244 | -    if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID )  ){ | |
| 244 | +	if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID )  ){ | |
| 245 | 245 | |
| 246 | - return get_permalink( $page->ID ); | |
| 246 | + return get_permalink( $page->ID ); | |
| 247 | 247 | |
| 248 | -    } else { | |
| 248 | +	} else { | |
| 249 | 249 | |
| 250 | - return wp_login_url(); | |
| 250 | + return wp_login_url(); | |
| 251 | 251 | |
| 252 | - } | |
| 252 | + } | |
| 253 | 253 | |
| 254 | 254 | }// end sensei_user_login_link | 
| 255 | 255 | |
| @@ -262,8 +262,8 @@ discard block | ||
| 262 | 262 | */ | 
| 263 | 263 |  function sensei_is_login_required(){ | 
| 264 | 264 | |
| 265 | - $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); | |
| 265 | + $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); | |
| 266 | 266 | |
| 267 | - return $login_required; | |
| 267 | + return $login_required; | |
| 268 | 268 | |
| 269 | 269 | } | 
| 270 | 270 | \ No newline at end of file | 
| @@ -1,6 +1,6 @@ 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 | 5 | /** | 
| 6 | 6 | * Global Sensei functions | 
| @@ -11,21 +11,21 @@ discard block | ||
| 11 | 11 | |
| 12 | 12 | $is_sensei = false; | 
| 13 | 13 | |
| 14 | - $post_types = array( 'lesson', 'course', 'quiz', 'question' ); | |
| 15 | - $taxonomies = array( 'course-category', 'quiz-type', 'question-type', 'lesson-tag' ); | |
| 14 | +	$post_types = array('lesson', 'course', 'quiz', 'question'); | |
| 15 | +	$taxonomies = array('course-category', 'quiz-type', 'question-type', 'lesson-tag'); | |
| 16 | 16 | |
| 17 | -	if( is_post_type_archive( $post_types ) || is_singular( $post_types ) || is_tax( $taxonomies ) ) { | |
| 17 | +	if (is_post_type_archive($post_types) || is_singular($post_types) || is_tax($taxonomies)) { | |
| 18 | 18 | |
| 19 | 19 | $is_sensei = true; | 
| 20 | 20 | |
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | -	if( is_object( $post ) && ! is_wp_error( $post ) ) { | |
| 23 | +	if (is_object($post) && ! is_wp_error($post)) { | |
| 24 | 24 | |
| 25 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); | |
| 26 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); | |
| 25 | + $course_page_id = intval(Sensei()->settings->settings['course_page']); | |
| 26 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); | |
| 27 | 27 | |
| 28 | -		if( in_array( $post->ID, array( $course_page_id, $my_courses_page_id ) ) ) { | |
| 28 | +		if (in_array($post->ID, array($course_page_id, $my_courses_page_id))) { | |
| 29 | 29 | |
| 30 | 30 | $is_sensei = true; | 
| 31 | 31 | |
| @@ -33,7 +33,7 @@ discard block | ||
| 33 | 33 | |
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | - return apply_filters( 'is_sensei', $is_sensei, $post ); | |
| 36 | +	return apply_filters('is_sensei', $is_sensei, $post); | |
| 37 | 37 | } | 
| 38 | 38 | |
| 39 | 39 | /** | 
| @@ -45,7 +45,7 @@ discard block | ||
| 45 | 45 | */ | 
| 46 | 46 |  function sensei_all_access() { | 
| 47 | 47 | |
| 48 | - $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); | |
| 48 | +    $access = current_user_can('manage_sensei') || current_user_can('manage_sensei_grades'); | |
| 49 | 49 | |
| 50 | 50 | /** | 
| 51 | 51 | * Filter sensei_all_access function result | 
| @@ -55,11 +55,11 @@ discard block | ||
| 55 | 55 | * @since 1.4.0 | 
| 56 | 56 | * @param bool $access | 
| 57 | 57 | */ | 
| 58 | - return apply_filters( 'sensei_all_access', $access ); | |
| 58 | +	return apply_filters('sensei_all_access', $access); | |
| 59 | 59 | |
| 60 | 60 | } // End sensei_all_access() | 
| 61 | 61 | |
| 62 | -if ( ! function_exists( 'sensei_light_or_dark' ) ) { | |
| 62 | +if ( ! function_exists('sensei_light_or_dark')) { | |
| 63 | 63 | |
| 64 | 64 | /** | 
| 65 | 65 | * Detect if we should use a light or dark colour on a background colour | 
| @@ -70,20 +70,20 @@ discard block | ||
| 70 | 70 | * @param string $light (default: '#FFFFFF') | 
| 71 | 71 | * @return string | 
| 72 | 72 | */ | 
| 73 | -	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { | |
| 73 | +	function sensei_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { | |
| 74 | 74 | |
| 75 | - $hex = str_replace( '#', '', $color ); | |
| 75 | +	    $hex = str_replace('#', '', $color); | |
| 76 | 76 | |
| 77 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); | |
| 78 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); | |
| 79 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); | |
| 80 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; | |
| 77 | + $c_r = hexdec(substr($hex, 0, 2)); | |
| 78 | + $c_g = hexdec(substr($hex, 2, 2)); | |
| 79 | + $c_b = hexdec(substr($hex, 4, 2)); | |
| 80 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; | |
| 81 | 81 | |
| 82 | 82 | return $brightness > 155 ? $dark : $light; | 
| 83 | 83 | } | 
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | -if ( ! function_exists( 'sensei_rgb_from_hex' ) ) { | |
| 86 | +if ( ! function_exists('sensei_rgb_from_hex')) { | |
| 87 | 87 | |
| 88 | 88 | /** | 
| 89 | 89 | * Hex darker/lighter/contrast functions for colours | 
| @@ -92,19 +92,19 @@ discard block | ||
| 92 | 92 | * @param mixed $color | 
| 93 | 93 | * @return string | 
| 94 | 94 | */ | 
| 95 | -	function sensei_rgb_from_hex( $color ) { | |
| 96 | - $color = str_replace( '#', '', $color ); | |
| 95 | +	function sensei_rgb_from_hex($color) { | |
| 96 | +		$color = str_replace('#', '', $color); | |
| 97 | 97 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" | 
| 98 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); | |
| 98 | +		$color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); | |
| 99 | 99 | |
| 100 | -		$rgb['R'] = hexdec( $color{0}.$color{1} ); | |
| 101 | -		$rgb['G'] = hexdec( $color{2}.$color{3} ); | |
| 102 | -		$rgb['B'] = hexdec( $color{4}.$color{5} ); | |
| 100 | +		$rgb['R'] = hexdec($color{0}.$color{1} ); | |
| 101 | +		$rgb['G'] = hexdec($color{2}.$color{3} ); | |
| 102 | +		$rgb['B'] = hexdec($color{4}.$color{5} ); | |
| 103 | 103 | return $rgb; | 
| 104 | 104 | } | 
| 105 | 105 | } | 
| 106 | 106 | |
| 107 | -if ( ! function_exists( 'sensei_hex_darker' ) ) { | |
| 107 | +if ( ! function_exists('sensei_hex_darker')) { | |
| 108 | 108 | |
| 109 | 109 | /** | 
| 110 | 110 | * Hex darker/lighter/contrast functions for colours | 
| @@ -114,8 +114,8 @@ discard block | ||
| 114 | 114 | * @param int $factor (default: 30) | 
| 115 | 115 | * @return string | 
| 116 | 116 | */ | 
| 117 | -	function sensei_hex_darker( $color, $factor = 30 ) { | |
| 118 | - $base = sensei_rgb_from_hex( $color ); | |
| 117 | +	function sensei_hex_darker($color, $factor = 30) { | |
| 118 | + $base = sensei_rgb_from_hex($color); | |
| 119 | 119 | $color = '#'; | 
| 120 | 120 | |
| 121 | 121 | foreach ($base as $k => $v) : | 
| @@ -124,7 +124,7 @@ discard block | ||
| 124 | 124 | $new_decimal = $v - $amount; | 
| 125 | 125 | |
| 126 | 126 | $new_hex_component = dechex($new_decimal); | 
| 127 | - if(strlen($new_hex_component) < 2) : | |
| 127 | + if (strlen($new_hex_component) < 2) : | |
| 128 | 128 | $new_hex_component = "0".$new_hex_component; | 
| 129 | 129 | endif; | 
| 130 | 130 | $color .= $new_hex_component; | 
| @@ -134,7 +134,7 @@ discard block | ||
| 134 | 134 | } | 
| 135 | 135 | } | 
| 136 | 136 | |
| 137 | -if ( ! function_exists( 'sensei_hex_lighter' ) ) { | |
| 137 | +if ( ! function_exists('sensei_hex_lighter')) { | |
| 138 | 138 | |
| 139 | 139 | /** | 
| 140 | 140 | * Hex darker/lighter/contrast functions for colours | 
| @@ -144,8 +144,8 @@ discard block | ||
| 144 | 144 | * @param int $factor (default: 30) | 
| 145 | 145 | * @return string | 
| 146 | 146 | */ | 
| 147 | -	function sensei_hex_lighter( $color, $factor = 30 ) { | |
| 148 | - $base = sensei_rgb_from_hex( $color ); | |
| 147 | +	function sensei_hex_lighter($color, $factor = 30) { | |
| 148 | + $base = sensei_rgb_from_hex($color); | |
| 149 | 149 | $color = '#'; | 
| 150 | 150 | |
| 151 | 151 | foreach ($base as $k => $v) : | 
| @@ -155,7 +155,7 @@ discard block | ||
| 155 | 155 | $new_decimal = $v + $amount; | 
| 156 | 156 | |
| 157 | 157 | $new_hex_component = dechex($new_decimal); | 
| 158 | - if(strlen($new_hex_component) < 2) : | |
| 158 | + if (strlen($new_hex_component) < 2) : | |
| 159 | 159 | $new_hex_component = "0".$new_hex_component; | 
| 160 | 160 | endif; | 
| 161 | 161 | $color .= $new_hex_component; | 
| @@ -171,7 +171,7 @@ discard block | ||
| 171 | 171 | * @since 1.9.0 | 
| 172 | 172 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() | 
| 173 | 173 | */ | 
| 174 | -if ( ! function_exists( 'is_woocommerce_active' ) ) { | |
| 174 | +if ( ! function_exists('is_woocommerce_active')) { | |
| 175 | 175 |      function is_woocommerce_active() { | 
| 176 | 176 | // calling is present instead of is active here | 
| 177 | 177 | // as this function can override other is_woocommerce_active | 
| @@ -193,20 +193,20 @@ discard block | ||
| 193 | 193 | * @param $alternative | 
| 194 | 194 | * @param array $args | 
| 195 | 195 | */ | 
| 196 | -function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){ | |
| 196 | +function sensei_do_deprecated_action($hook_tag, $version, $alternative = "", $args = array()) { | |
| 197 | 197 | |
| 198 | -    if( has_action( $hook_tag ) ){ | |
| 198 | +    if (has_action($hook_tag)) { | |
| 199 | 199 | |
| 200 | - $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); | |
| 200 | +        $error_message = sprintf(__("SENSEI: The hook '%s', has been deprecated since '%s'.", 'woothemes-sensei'), $hook_tag, $version); | |
| 201 | 201 | |
| 202 | -        if( !empty( $alternative ) ){ | |
| 202 | +        if ( ! empty($alternative)) { | |
| 203 | 203 | |
| 204 | -            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; | |
| 204 | +            $error_message .= sprintf(__("Please use '%s' instead.", 'woothemes-sensei'), $alternative); | |
| 205 | 205 | |
| 206 | 206 | } | 
| 207 | 207 | |
| 208 | - trigger_error( $error_message ); | |
| 209 | - do_action( $hook_tag , $args ); | |
| 208 | + trigger_error($error_message); | |
| 209 | + do_action($hook_tag, $args); | |
| 210 | 210 | |
| 211 | 211 | } | 
| 212 | 212 | |
| @@ -221,9 +221,9 @@ discard block | ||
| 221 | 221 | * @param $post_id | 
| 222 | 222 | * @return bool | 
| 223 | 223 | */ | 
| 224 | -function sensei_is_a_course( $post ){ | |
| 224 | +function sensei_is_a_course($post) { | |
| 225 | 225 | |
| 226 | - return "course" == get_post_type( $post ); | |
| 226 | + return "course" == get_post_type($post); | |
| 227 | 227 | |
| 228 | 228 | } | 
| 229 | 229 | |
| @@ -236,14 +236,14 @@ discard block | ||
| 236 | 236 | * | 
| 237 | 237 | * @since 1.9.0 | 
| 238 | 238 | */ | 
| 239 | -function sensei_user_login_url(){ | |
| 239 | +function sensei_user_login_url() { | |
| 240 | 240 | |
| 241 | - $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); | |
| 242 | - $page = get_post( $my_courses_page_id ); | |
| 241 | +    $my_courses_page_id = intval(Sensei()->settings->get('my_course_page')); | |
| 242 | + $page = get_post($my_courses_page_id); | |
| 243 | 243 | |
| 244 | -    if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID )  ){ | |
| 244 | +    if ($my_courses_page_id && isset($page->ID) && 'page' == get_post_type($page->ID)) { | |
| 245 | 245 | |
| 246 | - return get_permalink( $page->ID ); | |
| 246 | + return get_permalink($page->ID); | |
| 247 | 247 | |
| 248 | 248 |      } else { | 
| 249 | 249 | |
| @@ -260,9 +260,9 @@ discard block | ||
| 260 | 260 | * @since 1.9.0 | 
| 261 | 261 | * @return bool | 
| 262 | 262 | */ | 
| 263 | -function sensei_is_login_required(){ | |
| 263 | +function sensei_is_login_required() { | |
| 264 | 264 | |
| 265 | - $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); | |
| 265 | + $login_required = isset(Sensei()->settings->settings['access_permission']) && (true == Sensei()->settings->settings['access_permission']); | |
| 266 | 266 | |
| 267 | 267 | return $login_required; | 
| 268 | 268 | |
| @@ -103,8 +103,8 @@ | ||
| 103 | 103 | * | 
| 104 | 104 | * @since 1.9.0 | 
| 105 | 105 | * | 
| 106 | - * @param $title | |
| 107 | - * @param $shortcode_specific_override | |
| 106 | + * @param string $title | |
| 107 | + * @param string $shortcode_specific_override | |
| 108 | 108 | * @return string | 
| 109 | 109 | */ | 
| 110 | 110 |      public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){ | 
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | |
| 167 | 167 | Sensei_Templates::get_template( 'user/my-courses.php' ); | 
| 168 | 168 | |
| 169 | -        }else{ | |
| 169 | +        } else{ | |
| 170 | 170 | |
| 171 | 171 | Sensei()->frontend->sensei_login_form(); | 
| 172 | 172 | |
| @@ -15,14 +15,14 @@ discard block | ||
| 15 | 15 | * | 
| 16 | 16 | * @since 1.9.0 | 
| 17 | 17 | */ | 
| 18 | -    public static function init(){ | |
| 18 | +    public static function init() { | |
| 19 | 19 | |
| 20 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); | |
| 21 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); | |
| 22 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); | |
| 23 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); | |
| 24 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); | |
| 25 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); | |
| 20 | +        add_shortcode('allcourses', array(__CLASS__, 'all_courses')); | |
| 21 | +        add_shortcode('newcourses', array(__CLASS__, 'new_courses')); | |
| 22 | +        add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses')); | |
| 23 | +        add_shortcode('freecourses', array(__CLASS__, 'free_courses')); | |
| 24 | +        add_shortcode('paidcourses', array(__CLASS__, 'paid_courses')); | |
| 25 | +        add_shortcode('usercourses', array(__CLASS__, 'user_courses')); | |
| 26 | 26 | |
| 27 | 27 | } | 
| 28 | 28 | /** | 
| @@ -35,9 +35,9 @@ discard block | ||
| 35 | 35 | * @param mixed $content (default: null) | 
| 36 | 36 | * @return string | 
| 37 | 37 | */ | 
| 38 | -    public static function all_courses( $atts, $content = null ) { | |
| 38 | +    public static function all_courses($atts, $content = null) { | |
| 39 | 39 | |
| 40 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title | |
| 40 | +        return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title | |
| 41 | 41 | |
| 42 | 42 | } // all_courses() | 
| 43 | 43 | |
| @@ -49,9 +49,9 @@ discard block | ||
| 49 | 49 | * @param mixed $content (default: null) | 
| 50 | 50 | * @return string | 
| 51 | 51 | */ | 
| 52 | -    public static function paid_courses( $atts, $content = null ) { | |
| 52 | +    public static function paid_courses($atts, $content = null) { | |
| 53 | 53 | |
| 54 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); | |
| 54 | +        return self::generate_shortcode_courses('Paid Courses', 'paidcourses'); | |
| 55 | 55 | |
| 56 | 56 | } // End paid_courses() | 
| 57 | 57 | |
| @@ -64,9 +64,9 @@ discard block | ||
| 64 | 64 | * @param mixed $content (default: null) | 
| 65 | 65 | * @return string | 
| 66 | 66 | */ | 
| 67 | -    public static function featured_courses( $atts, $content = null ) { | |
| 67 | +    public static function featured_courses($atts, $content = null) { | |
| 68 | 68 | |
| 69 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); | |
| 69 | +        return self::generate_shortcode_courses('Featured Courses', 'featuredcourses'); | |
| 70 | 70 | |
| 71 | 71 | } // End featured_courses() | 
| 72 | 72 | |
| @@ -78,9 +78,9 @@ discard block | ||
| 78 | 78 | * @param mixed $content (default: null) | 
| 79 | 79 | * @return string | 
| 80 | 80 | */ | 
| 81 | -    public static function free_courses( $atts, $content = null ) { | |
| 81 | +    public static function free_courses($atts, $content = null) { | |
| 82 | 82 | |
| 83 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); | |
| 83 | +        return self::generate_shortcode_courses('Free Courses', 'freecourses'); | |
| 84 | 84 | |
| 85 | 85 | } // End free_courses() | 
| 86 | 86 | |
| @@ -92,9 +92,9 @@ discard block | ||
| 92 | 92 | * @param mixed $content (default: null) | 
| 93 | 93 | * @return string | 
| 94 | 94 | */ | 
| 95 | -    public static function new_courses( $atts, $content = null ) { | |
| 95 | +    public static function new_courses($atts, $content = null) { | |
| 96 | 96 | |
| 97 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); | |
| 97 | +        return self::generate_shortcode_courses('New Courses', 'newcourses'); | |
| 98 | 98 | |
| 99 | 99 | } // End new_courses() | 
| 100 | 100 | |
| @@ -107,7 +107,7 @@ discard block | ||
| 107 | 107 | * @param $shortcode_specific_override | 
| 108 | 108 | * @return string | 
| 109 | 109 | */ | 
| 110 | -    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){ | |
| 110 | +    public static function generate_shortcode_courses($title, $shortcode_specific_override) { | |
| 111 | 111 | |
| 112 | 112 | global $shortcode_override, $posts_array; | 
| 113 | 113 | |
| @@ -115,9 +115,9 @@ discard block | ||
| 115 | 115 | |
| 116 | 116 | // do not show this short code if there is a shortcode int he url and | 
| 117 | 117 | // this specific shortcode is not the one requested in the ur. | 
| 118 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; | |
| 119 | - if( ! empty( $specific_shortcode_requested) && | |
| 120 | -            $specific_shortcode_requested != $shortcode_override ){ | |
| 118 | + $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; | |
| 119 | + if ( ! empty($specific_shortcode_requested) && | |
| 120 | +            $specific_shortcode_requested != $shortcode_override) { | |
| 121 | 121 | |
| 122 | 122 | return ''; | 
| 123 | 123 | |
| @@ -129,15 +129,15 @@ discard block | ||
| 129 | 129 | $courses = ob_get_clean(); | 
| 130 | 130 | |
| 131 | 131 | $content = ''; | 
| 132 | -        if( count( $posts_array ) > 0 ){ | |
| 132 | +        if (count($posts_array) > 0) { | |
| 133 | 133 | |
| 134 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; | |
| 134 | + $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>'; | |
| 135 | 135 | $before .= '<section id="main-course" class="course-container">'; | 
| 136 | 136 | |
| 137 | 137 | $after = '</section>'; | 
| 138 | 138 | |
| 139 | 139 | //assemble | 
| 140 | - $content = $before . $courses . $after; | |
| 140 | + $content = $before.$courses.$after; | |
| 141 | 141 | |
| 142 | 142 | } | 
| 143 | 143 | |
| @@ -154,19 +154,19 @@ discard block | ||
| 154 | 154 | * @param mixed $content (default: null) | 
| 155 | 155 | * @return string | 
| 156 | 156 | */ | 
| 157 | -    public static function user_courses( $atts, $content = null ) { | |
| 157 | +    public static function user_courses($atts, $content = null) { | |
| 158 | 158 | global $shortcode_override; | 
| 159 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); | |
| 159 | +        extract(shortcode_atts(array('amount' => 0), $atts)); | |
| 160 | 160 | |
| 161 | 161 | $shortcode_override = 'usercourses'; | 
| 162 | 162 | |
| 163 | 163 | ob_start(); | 
| 164 | 164 | |
| 165 | -        if( is_user_logged_in() ){ | |
| 165 | +        if (is_user_logged_in()) { | |
| 166 | 166 | |
| 167 | - Sensei_Templates::get_template( 'user/my-courses.php' ); | |
| 167 | +            Sensei_Templates::get_template('user/my-courses.php'); | |
| 168 | 168 | |
| 169 | -        }else{ | |
| 169 | +        } else { | |
| 170 | 170 | |
| 171 | 171 | Sensei()->frontend->sensei_login_form(); | 
| 172 | 172 | |
| @@ -182,54 +182,54 @@ discard block | ||
| 182 | 182 | * loop-course.php for the old shortcodes. | 
| 183 | 183 | * @since 1.9.0 | 
| 184 | 184 | */ | 
| 185 | -    public static function initialise_legacy_course_loop(){ | |
| 185 | +    public static function initialise_legacy_course_loop() { | |
| 186 | 186 | |
| 187 | 187 | global $post, $wp_query, $shortcode_override, $course_excludes; | 
| 188 | 188 | |
| 189 | 189 | // Handle Query Type | 
| 190 | 190 | $query_type = ''; | 
| 191 | 191 | |
| 192 | -        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { | |
| 193 | - $query_type = esc_html( $_GET[ 'action' ] ); | |
| 192 | +        if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) { | |
| 193 | + $query_type = esc_html($_GET['action']); | |
| 194 | 194 | } // End If Statement | 
| 195 | 195 | |
| 196 | -        if ( '' != $shortcode_override ) { | |
| 196 | +        if ('' != $shortcode_override) { | |
| 197 | 197 | $query_type = $shortcode_override; | 
| 198 | 198 | } // End If Statement | 
| 199 | 199 | |
| 200 | -        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } | |
| 200 | +        if ( ! is_array($course_excludes)) { $course_excludes = array(); } | |
| 201 | 201 | |
| 202 | 202 | // Check that query returns results | 
| 203 | 203 | // Handle Pagination | 
| 204 | - $paged = $wp_query->get( 'paged' ); | |
| 205 | - $paged = empty( $paged ) ? 1 : $paged; | |
| 204 | +        $paged = $wp_query->get('paged'); | |
| 205 | + $paged = empty($paged) ? 1 : $paged; | |
| 206 | 206 | |
| 207 | 207 | |
| 208 | 208 | // Check for pagination settings | 
| 209 | -        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { | |
| 209 | +        if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { | |
| 210 | 210 | |
| 211 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); | |
| 211 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); | |
| 212 | 212 | |
| 213 | 213 |          } else { | 
| 214 | 214 | |
| 215 | - $amount = $wp_query->get( 'posts_per_page' ); | |
| 215 | +            $amount = $wp_query->get('posts_per_page'); | |
| 216 | 216 | |
| 217 | 217 | } // End If Statement | 
| 218 | 218 | |
| 219 | 219 | // This is not a paginated page (or it's simply the first page of a paginated page/post) | 
| 220 | 220 | |
| 221 | 221 | global $posts_array; | 
| 222 | - $course_includes = array(); | |
| 222 | + $course_includes = array(); | |
| 223 | 223 | |
| 224 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); | |
| 225 | - $course_query = new WP_Query( $query_args ); | |
| 224 | + $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes); | |
| 225 | + $course_query = new WP_Query($query_args); | |
| 226 | 226 | $posts_array = $course_query->get_posts(); | 
| 227 | 227 | |
| 228 | 228 | // output the courses | 
| 229 | -        if( ! empty( $posts_array ) ) { | |
| 229 | +        if ( ! empty($posts_array)) { | |
| 230 | 230 | |
| 231 | 231 | //output all courses for current query | 
| 232 | - self::loop_courses( $course_query, $amount ); | |
| 232 | + self::loop_courses($course_query, $amount); | |
| 233 | 233 | |
| 234 | 234 | } | 
| 235 | 235 | |
| @@ -242,31 +242,31 @@ discard block | ||
| 242 | 242 | * | 
| 243 | 243 | * @param WP_Query $course_query | 
| 244 | 244 | */ | 
| 245 | -    public static function loop_courses( $course_query, $amount ){ | |
| 245 | +    public static function loop_courses($course_query, $amount) { | |
| 246 | 246 | |
| 247 | 247 | global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; | 
| 248 | 248 | |
| 249 | -        if ( count( $course_query->get_posts() ) > 0 ) { | |
| 249 | +        if (count($course_query->get_posts()) > 0) { | |
| 250 | 250 | |
| 251 | - do_action( 'sensei_course_archive_header', $shortcode_override ); | |
| 251 | +            do_action('sensei_course_archive_header', $shortcode_override); | |
| 252 | 252 | |
| 253 | -            foreach ( $course_query->get_posts() as $course){ | |
| 253 | +            foreach ($course_query->get_posts() as $course) { | |
| 254 | 254 | |
| 255 | 255 | // Make sure the other loops dont include the same post twice! | 
| 256 | - array_push( $course_excludes, $course->ID ); | |
| 256 | + array_push($course_excludes, $course->ID); | |
| 257 | 257 | |
| 258 | 258 | // output the course markup | 
| 259 | - self::the_course( $course->ID ); | |
| 259 | + self::the_course($course->ID); | |
| 260 | 260 | |
| 261 | 261 | } // End For Loop | 
| 262 | 262 | |
| 263 | 263 | // More and Prev links | 
| 264 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); | |
| 264 | + $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes)); | |
| 265 | 265 | $posts_array = $posts_array_query->get_posts(); | 
| 266 | 266 | $max_pages = $course_query->found_posts / $amount; | 
| 267 | -            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { | |
| 267 | +            if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) { | |
| 268 | 268 | |
| 269 | -                switch( $shortcode_override ){ | |
| 269 | +                switch ($shortcode_override) { | |
| 270 | 270 | case 'paidcourses': | 
| 271 | 271 | $filter = 'paid'; | 
| 272 | 272 | break; | 
| @@ -282,22 +282,22 @@ discard block | ||
| 282 | 282 | } | 
| 283 | 283 | |
| 284 | 284 | $quer_args = array(); | 
| 285 | - $quer_args[ 'paged' ] = '2'; | |
| 286 | -                if( !empty( $filter ) ){ | |
| 287 | - $quer_args[ 'course_filter' ] = $filter; | |
| 285 | + $quer_args['paged'] = '2'; | |
| 286 | +                if ( ! empty($filter)) { | |
| 287 | + $quer_args['course_filter'] = $filter; | |
| 288 | 288 | } | 
| 289 | 289 | |
| 290 | - $course_pagination_link = get_post_type_archive_link( 'course' ); | |
| 291 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); | |
| 292 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); | |
| 290 | +                $course_pagination_link = get_post_type_archive_link('course'); | |
| 291 | + $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']); | |
| 292 | + $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link)); | |
| 293 | 293 | |
| 294 | 294 | // next/more | 
| 295 | 295 | $html = '<div class="navigation"><div class="nav-next">'; | 
| 296 | - $html .= '<a href="' . $more_link_url . '">'; | |
| 296 | + $html .= '<a href="'.$more_link_url.'">'; | |
| 297 | 297 | $html .= $more_link_text; | 
| 298 | 298 | $html .= '<span class="meta-nav"></span></a></div>'; | 
| 299 | 299 | |
| 300 | - echo apply_filters( 'course_archive_next_link', $html ); | |
| 300 | +                echo apply_filters('course_archive_next_link', $html); | |
| 301 | 301 | |
| 302 | 302 | } // End If Statement | 
| 303 | 303 | |
| @@ -309,23 +309,23 @@ discard block | ||
| 309 | 309 | * | 
| 310 | 310 | * @param $course_id | 
| 311 | 311 | */ | 
| 312 | -    public static function the_course( $course_id ){ | |
| 312 | +    public static function the_course($course_id) { | |
| 313 | 313 | |
| 314 | 314 | // Get meta data | 
| 315 | - $course = get_post( $course_id ); | |
| 316 | - $user_info = get_userdata( absint( $course->post_author ) ); | |
| 317 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); | |
| 315 | + $course = get_post($course_id); | |
| 316 | + $user_info = get_userdata(absint($course->post_author)); | |
| 317 | + $author_link = get_author_posts_url(absint($course->post_author)); | |
| 318 | 318 | $author_display_name = $user_info->display_name; | 
| 319 | 319 | $author_id = $course->post_author; | 
| 320 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); | |
| 321 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); | |
| 322 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); | |
| 320 | + $category_output = get_the_term_list($course_id, 'course-category', '', ', ', ''); | |
| 321 | + $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id)); | |
| 322 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id()); | |
| 323 | 323 | ?> | 
| 324 | 324 | |
| 325 | - <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> | |
| 325 | +        <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>"> | |
| 326 | 326 | <?php | 
| 327 | 327 | // so that legacy shortcodes work with thir party plugins that wants to hook in | 
| 328 | -            do_action('sensei_course_content_before',$course ); | |
| 328 | +            do_action('sensei_course_content_before', $course); | |
| 329 | 329 | ?> | 
| 330 | 330 | <div class="course-content"> | 
| 331 | 331 | |
| @@ -341,19 +341,19 @@ discard block | ||
| 341 | 341 | |
| 342 | 342 | <p class="sensei-course-meta"> | 
| 343 | 343 | |
| 344 | -                        <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> | |
| 345 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span> | |
| 344 | +                        <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> | |
| 345 | +                            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span> | |
| 346 | 346 | <?php } // End If Statement ?> | 
| 347 | 347 | |
| 348 | 348 | <span class="course-lesson-count"> | 
| 349 | - <?php echo Sensei()->course->course_lesson_count( $course_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?> | |
| 349 | +                                    <?php echo Sensei()->course->course_lesson_count($course_id).' '.__('Lessons', 'woothemes-sensei'); ?> | |
| 350 | 350 | </span> | 
| 351 | 351 | |
| 352 | -                        <?php if ( '' != $category_output ) { ?> | |
| 353 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> | |
| 352 | +                        <?php if ('' != $category_output) { ?> | |
| 353 | +                            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> | |
| 354 | 354 | <?php } // End If Statement ?> | 
| 355 | 355 | |
| 356 | - <?php sensei_simple_course_price( $course_id ); ?> | |
| 356 | + <?php sensei_simple_course_price($course_id); ?> | |
| 357 | 357 | |
| 358 | 358 | </p> | 
| 359 | 359 | |
| @@ -361,10 +361,10 @@ discard block | ||
| 361 | 361 | |
| 362 | 362 | </p> | 
| 363 | 363 | |
| 364 | -                    <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { | |
| 365 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> | |
| 364 | +                    <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) { | |
| 365 | +                        $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> | |
| 366 | 366 | <p class="sensei-free-lessons"> | 
| 367 | - <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> | |
| 367 | +                            <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?> | |
| 368 | 368 | </a> - <?php echo $preview_lessons; ?> | 
| 369 | 369 | </p> | 
| 370 | 370 | <?php } ?> | 
| @@ -10,323 +10,323 @@ discard block | ||
| 10 | 10 | */ | 
| 11 | 11 |  class Sensei_Legacy_Shortcodes { | 
| 12 | 12 | |
| 13 | - /** | |
| 14 | - * Add the legacy shortcodes to WordPress | |
| 15 | - * | |
| 16 | - * @since 1.9.0 | |
| 17 | - */ | |
| 18 | -    public static function init(){ | |
| 19 | - | |
| 20 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); | |
| 21 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); | |
| 22 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); | |
| 23 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); | |
| 24 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); | |
| 25 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); | |
| 26 | - | |
| 27 | - } | |
| 28 | - /** | |
| 29 | - * all_courses shortcode output function. | |
| 30 | - * | |
| 31 | - * The function should only be called indirectly through do_shortcode() | |
| 32 | - * | |
| 33 | - * @access public | |
| 34 | - * @param mixed $atts | |
| 35 | - * @param mixed $content (default: null) | |
| 36 | - * @return string | |
| 37 | - */ | |
| 38 | -    public static function all_courses( $atts, $content = null ) { | |
| 39 | - | |
| 40 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title | |
| 41 | - | |
| 42 | - } // all_courses() | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * paid_courses function. | |
| 46 | - * | |
| 47 | - * @access public | |
| 48 | - * @param mixed $atts | |
| 49 | - * @param mixed $content (default: null) | |
| 50 | - * @return string | |
| 51 | - */ | |
| 52 | -    public static function paid_courses( $atts, $content = null ) { | |
| 53 | - | |
| 54 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); | |
| 55 | - | |
| 56 | - } // End paid_courses() | |
| 57 | - | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * featured_courses function. | |
| 61 | - * | |
| 62 | - * @access public | |
| 63 | - * @param mixed $atts | |
| 64 | - * @param mixed $content (default: null) | |
| 65 | - * @return string | |
| 66 | - */ | |
| 67 | -    public static function featured_courses( $atts, $content = null ) { | |
| 68 | - | |
| 69 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); | |
| 13 | + /** | |
| 14 | + * Add the legacy shortcodes to WordPress | |
| 15 | + * | |
| 16 | + * @since 1.9.0 | |
| 17 | + */ | |
| 18 | +	public static function init(){ | |
| 19 | + | |
| 20 | + add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); | |
| 21 | + add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); | |
| 22 | + add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); | |
| 23 | + add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); | |
| 24 | + add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); | |
| 25 | + add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); | |
| 26 | + | |
| 27 | + } | |
| 28 | + /** | |
| 29 | + * all_courses shortcode output function. | |
| 30 | + * | |
| 31 | + * The function should only be called indirectly through do_shortcode() | |
| 32 | + * | |
| 33 | + * @access public | |
| 34 | + * @param mixed $atts | |
| 35 | + * @param mixed $content (default: null) | |
| 36 | + * @return string | |
| 37 | + */ | |
| 38 | +	public static function all_courses( $atts, $content = null ) { | |
| 39 | + | |
| 40 | + return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title | |
| 41 | + | |
| 42 | + } // all_courses() | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * paid_courses function. | |
| 46 | + * | |
| 47 | + * @access public | |
| 48 | + * @param mixed $atts | |
| 49 | + * @param mixed $content (default: null) | |
| 50 | + * @return string | |
| 51 | + */ | |
| 52 | +	public static function paid_courses( $atts, $content = null ) { | |
| 53 | + | |
| 54 | + return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); | |
| 55 | + | |
| 56 | + } // End paid_courses() | |
| 57 | + | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * featured_courses function. | |
| 61 | + * | |
| 62 | + * @access public | |
| 63 | + * @param mixed $atts | |
| 64 | + * @param mixed $content (default: null) | |
| 65 | + * @return string | |
| 66 | + */ | |
| 67 | +	public static function featured_courses( $atts, $content = null ) { | |
| 68 | + | |
| 69 | + return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); | |
| 70 | 70 | |
| 71 | - } // End featured_courses() | |
| 71 | + } // End featured_courses() | |
| 72 | 72 | |
| 73 | - /** | |
| 74 | - * shortcode_free_courses function. | |
| 75 | - * | |
| 76 | - * @access public | |
| 77 | - * @param mixed $atts | |
| 78 | - * @param mixed $content (default: null) | |
| 79 | - * @return string | |
| 80 | - */ | |
| 81 | -    public static function free_courses( $atts, $content = null ) { | |
| 73 | + /** | |
| 74 | + * shortcode_free_courses function. | |
| 75 | + * | |
| 76 | + * @access public | |
| 77 | + * @param mixed $atts | |
| 78 | + * @param mixed $content (default: null) | |
| 79 | + * @return string | |
| 80 | + */ | |
| 81 | +	public static function free_courses( $atts, $content = null ) { | |
| 82 | 82 | |
| 83 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); | |
| 83 | + return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); | |
| 84 | 84 | |
| 85 | - } // End free_courses() | |
| 85 | + } // End free_courses() | |
| 86 | 86 | |
| 87 | - /** | |
| 88 | - * shortcode_new_courses function. | |
| 89 | - * | |
| 90 | - * @access public | |
| 91 | - * @param mixed $atts | |
| 92 | - * @param mixed $content (default: null) | |
| 93 | - * @return string | |
| 94 | - */ | |
| 95 | -    public static function new_courses( $atts, $content = null ) { | |
| 87 | + /** | |
| 88 | + * shortcode_new_courses function. | |
| 89 | + * | |
| 90 | + * @access public | |
| 91 | + * @param mixed $atts | |
| 92 | + * @param mixed $content (default: null) | |
| 93 | + * @return string | |
| 94 | + */ | |
| 95 | +	public static function new_courses( $atts, $content = null ) { | |
| 96 | 96 | |
| 97 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); | |
| 97 | + return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); | |
| 98 | 98 | |
| 99 | - } // End new_courses() | |
| 99 | + } // End new_courses() | |
| 100 | 100 | |
| 101 | - /** | |
| 102 | - * Generate courses adding a title. | |
| 103 | - * | |
| 104 | - * @since 1.9.0 | |
| 105 | - * | |
| 106 | - * @param $title | |
| 107 | - * @param $shortcode_specific_override | |
| 108 | - * @return string | |
| 109 | - */ | |
| 110 | -    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){ | |
| 101 | + /** | |
| 102 | + * Generate courses adding a title. | |
| 103 | + * | |
| 104 | + * @since 1.9.0 | |
| 105 | + * | |
| 106 | + * @param $title | |
| 107 | + * @param $shortcode_specific_override | |
| 108 | + * @return string | |
| 109 | + */ | |
| 110 | +	public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){ | |
| 111 | 111 | |
| 112 | - global $shortcode_override, $posts_array; | |
| 112 | + global $shortcode_override, $posts_array; | |
| 113 | 113 | |
| 114 | - $shortcode_override = $shortcode_specific_override; | |
| 114 | + $shortcode_override = $shortcode_specific_override; | |
| 115 | 115 | |
| 116 | - // do not show this short code if there is a shortcode int he url and | |
| 117 | - // this specific shortcode is not the one requested in the ur. | |
| 118 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; | |
| 119 | - if( ! empty( $specific_shortcode_requested) && | |
| 120 | -            $specific_shortcode_requested != $shortcode_override ){ | |
| 116 | + // do not show this short code if there is a shortcode int he url and | |
| 117 | + // this specific shortcode is not the one requested in the ur. | |
| 118 | + $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; | |
| 119 | + if( ! empty( $specific_shortcode_requested) && | |
| 120 | +			$specific_shortcode_requested != $shortcode_override ){ | |
| 121 | 121 | |
| 122 | - return ''; | |
| 122 | + return ''; | |
| 123 | 123 | |
| 124 | - } | |
| 124 | + } | |
| 125 | 125 | |
| 126 | - // loop and get all courses html | |
| 127 | - ob_start(); | |
| 128 | - self::initialise_legacy_course_loop(); | |
| 129 | - $courses = ob_get_clean(); | |
| 126 | + // loop and get all courses html | |
| 127 | + ob_start(); | |
| 128 | + self::initialise_legacy_course_loop(); | |
| 129 | + $courses = ob_get_clean(); | |
| 130 | 130 | |
| 131 | - $content = ''; | |
| 132 | -        if( count( $posts_array ) > 0 ){ | |
| 131 | + $content = ''; | |
| 132 | +		if( count( $posts_array ) > 0 ){ | |
| 133 | 133 | |
| 134 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; | |
| 135 | - $before .= '<section id="main-course" class="course-container">'; | |
| 134 | + $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; | |
| 135 | + $before .= '<section id="main-course" class="course-container">'; | |
| 136 | 136 | |
| 137 | - $after = '</section>'; | |
| 137 | + $after = '</section>'; | |
| 138 | 138 | |
| 139 | - //assemble | |
| 140 | - $content = $before . $courses . $after; | |
| 139 | + //assemble | |
| 140 | + $content = $before . $courses . $after; | |
| 141 | 141 | |
| 142 | - } | |
| 142 | + } | |
| 143 | 143 | |
| 144 | - return $content; | |
| 144 | + return $content; | |
| 145 | 145 | |
| 146 | - }// end generate_shortcode_courses | |
| 146 | + }// end generate_shortcode_courses | |
| 147 | 147 | |
| 148 | 148 | |
| 149 | - /** | |
| 150 | - * user_courses function. | |
| 151 | - * | |
| 152 | - * @access public | |
| 153 | - * @param mixed $atts | |
| 154 | - * @param mixed $content (default: null) | |
| 155 | - * @return string | |
| 156 | - */ | |
| 157 | -    public static function user_courses( $atts, $content = null ) { | |
| 158 | - global $shortcode_override; | |
| 159 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); | |
| 149 | + /** | |
| 150 | + * user_courses function. | |
| 151 | + * | |
| 152 | + * @access public | |
| 153 | + * @param mixed $atts | |
| 154 | + * @param mixed $content (default: null) | |
| 155 | + * @return string | |
| 156 | + */ | |
| 157 | +	public static function user_courses( $atts, $content = null ) { | |
| 158 | + global $shortcode_override; | |
| 159 | + extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); | |
| 160 | 160 | |
| 161 | - $shortcode_override = 'usercourses'; | |
| 161 | + $shortcode_override = 'usercourses'; | |
| 162 | 162 | |
| 163 | - ob_start(); | |
| 163 | + ob_start(); | |
| 164 | 164 | |
| 165 | -        if( is_user_logged_in() ){ | |
| 165 | +		if( is_user_logged_in() ){ | |
| 166 | 166 | |
| 167 | - Sensei_Templates::get_template( 'user/my-courses.php' ); | |
| 167 | + Sensei_Templates::get_template( 'user/my-courses.php' ); | |
| 168 | 168 | |
| 169 | -        }else{ | |
| 169 | +		}else{ | |
| 170 | 170 | |
| 171 | - Sensei()->frontend->sensei_login_form(); | |
| 171 | + Sensei()->frontend->sensei_login_form(); | |
| 172 | 172 | |
| 173 | - } | |
| 173 | + } | |
| 174 | 174 | |
| 175 | - $content = ob_get_clean(); | |
| 176 | - return $content; | |
| 175 | + $content = ob_get_clean(); | |
| 176 | + return $content; | |
| 177 | 177 | |
| 178 | - } // End user_courses() | |
| 178 | + } // End user_courses() | |
| 179 | 179 | |
| 180 | - /** | |
| 181 | - * This function is simply to honor the legacy | |
| 182 | - * loop-course.php for the old shortcodes. | |
| 183 | - * @since 1.9.0 | |
| 184 | - */ | |
| 185 | -    public static function initialise_legacy_course_loop(){ | |
| 180 | + /** | |
| 181 | + * This function is simply to honor the legacy | |
| 182 | + * loop-course.php for the old shortcodes. | |
| 183 | + * @since 1.9.0 | |
| 184 | + */ | |
| 185 | +	public static function initialise_legacy_course_loop(){ | |
| 186 | 186 | |
| 187 | - global $post, $wp_query, $shortcode_override, $course_excludes; | |
| 187 | + global $post, $wp_query, $shortcode_override, $course_excludes; | |
| 188 | 188 | |
| 189 | - // Handle Query Type | |
| 190 | - $query_type = ''; | |
| 189 | + // Handle Query Type | |
| 190 | + $query_type = ''; | |
| 191 | 191 | |
| 192 | -        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { | |
| 193 | - $query_type = esc_html( $_GET[ 'action' ] ); | |
| 194 | - } // End If Statement | |
| 192 | +		if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { | |
| 193 | + $query_type = esc_html( $_GET[ 'action' ] ); | |
| 194 | + } // End If Statement | |
| 195 | 195 | |
| 196 | -        if ( '' != $shortcode_override ) { | |
| 197 | - $query_type = $shortcode_override; | |
| 198 | - } // End If Statement | |
| 196 | +		if ( '' != $shortcode_override ) { | |
| 197 | + $query_type = $shortcode_override; | |
| 198 | + } // End If Statement | |
| 199 | 199 | |
| 200 | -        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } | |
| 200 | +		if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } | |
| 201 | 201 | |
| 202 | - // Check that query returns results | |
| 203 | - // Handle Pagination | |
| 204 | - $paged = $wp_query->get( 'paged' ); | |
| 205 | - $paged = empty( $paged ) ? 1 : $paged; | |
| 202 | + // Check that query returns results | |
| 203 | + // Handle Pagination | |
| 204 | + $paged = $wp_query->get( 'paged' ); | |
| 205 | + $paged = empty( $paged ) ? 1 : $paged; | |
| 206 | 206 | |
| 207 | 207 | |
| 208 | - // Check for pagination settings | |
| 209 | -        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { | |
| 208 | + // Check for pagination settings | |
| 209 | +		if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { | |
| 210 | 210 | |
| 211 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); | |
| 211 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); | |
| 212 | 212 | |
| 213 | -        } else { | |
| 213 | +		} else { | |
| 214 | 214 | |
| 215 | - $amount = $wp_query->get( 'posts_per_page' ); | |
| 215 | + $amount = $wp_query->get( 'posts_per_page' ); | |
| 216 | 216 | |
| 217 | - } // End If Statement | |
| 217 | + } // End If Statement | |
| 218 | 218 | |
| 219 | - // This is not a paginated page (or it's simply the first page of a paginated page/post) | |
| 219 | + // This is not a paginated page (or it's simply the first page of a paginated page/post) | |
| 220 | 220 | |
| 221 | - global $posts_array; | |
| 222 | - $course_includes = array(); | |
| 221 | + global $posts_array; | |
| 222 | + $course_includes = array(); | |
| 223 | 223 | |
| 224 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); | |
| 225 | - $course_query = new WP_Query( $query_args ); | |
| 226 | - $posts_array = $course_query->get_posts(); | |
| 224 | + $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); | |
| 225 | + $course_query = new WP_Query( $query_args ); | |
| 226 | + $posts_array = $course_query->get_posts(); | |
| 227 | 227 | |
| 228 | - // output the courses | |
| 229 | -        if( ! empty( $posts_array ) ) { | |
| 228 | + // output the courses | |
| 229 | +		if( ! empty( $posts_array ) ) { | |
| 230 | 230 | |
| 231 | - //output all courses for current query | |
| 232 | - self::loop_courses( $course_query, $amount ); | |
| 231 | + //output all courses for current query | |
| 232 | + self::loop_courses( $course_query, $amount ); | |
| 233 | 233 | |
| 234 | - } | |
| 234 | + } | |
| 235 | 235 | |
| 236 | - } | |
| 236 | + } | |
| 237 | 237 | |
| 238 | - /** | |
| 239 | - * Loop through courses in the query and output the infomration needed | |
| 240 | - * | |
| 241 | - * @since 1.9.0 | |
| 242 | - * | |
| 243 | - * @param WP_Query $course_query | |
| 244 | - */ | |
| 245 | -    public static function loop_courses( $course_query, $amount ){ | |
| 238 | + /** | |
| 239 | + * Loop through courses in the query and output the infomration needed | |
| 240 | + * | |
| 241 | + * @since 1.9.0 | |
| 242 | + * | |
| 243 | + * @param WP_Query $course_query | |
| 244 | + */ | |
| 245 | +	public static function loop_courses( $course_query, $amount ){ | |
| 246 | 246 | |
| 247 | - global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; | |
| 247 | + global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; | |
| 248 | 248 | |
| 249 | -        if ( count( $course_query->get_posts() ) > 0 ) { | |
| 249 | +		if ( count( $course_query->get_posts() ) > 0 ) { | |
| 250 | 250 | |
| 251 | - do_action( 'sensei_course_archive_header', $shortcode_override ); | |
| 251 | + do_action( 'sensei_course_archive_header', $shortcode_override ); | |
| 252 | 252 | |
| 253 | -            foreach ( $course_query->get_posts() as $course){ | |
| 253 | +			foreach ( $course_query->get_posts() as $course){ | |
| 254 | 254 | |
| 255 | - // Make sure the other loops dont include the same post twice! | |
| 256 | - array_push( $course_excludes, $course->ID ); | |
| 255 | + // Make sure the other loops dont include the same post twice! | |
| 256 | + array_push( $course_excludes, $course->ID ); | |
| 257 | 257 | |
| 258 | - // output the course markup | |
| 259 | - self::the_course( $course->ID ); | |
| 258 | + // output the course markup | |
| 259 | + self::the_course( $course->ID ); | |
| 260 | 260 | |
| 261 | - } // End For Loop | |
| 261 | + } // End For Loop | |
| 262 | 262 | |
| 263 | - // More and Prev links | |
| 264 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); | |
| 265 | - $posts_array = $posts_array_query->get_posts(); | |
| 266 | - $max_pages = $course_query->found_posts / $amount; | |
| 267 | -            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { | |
| 263 | + // More and Prev links | |
| 264 | + $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); | |
| 265 | + $posts_array = $posts_array_query->get_posts(); | |
| 266 | + $max_pages = $course_query->found_posts / $amount; | |
| 267 | +			if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { | |
| 268 | 268 | |
| 269 | -                switch( $shortcode_override ){ | |
| 270 | - case 'paidcourses': | |
| 271 | - $filter = 'paid'; | |
| 272 | - break; | |
| 273 | - case 'featuredcourses': | |
| 274 | - $filter = 'featured'; | |
| 275 | - break; | |
| 276 | - case 'freecourses': | |
| 277 | - $filter = 'free'; | |
| 278 | - break; | |
| 279 | - default: | |
| 280 | - $filter = ''; | |
| 281 | - break; | |
| 282 | - } | |
| 269 | +				switch( $shortcode_override ){ | |
| 270 | + case 'paidcourses': | |
| 271 | + $filter = 'paid'; | |
| 272 | + break; | |
| 273 | + case 'featuredcourses': | |
| 274 | + $filter = 'featured'; | |
| 275 | + break; | |
| 276 | + case 'freecourses': | |
| 277 | + $filter = 'free'; | |
| 278 | + break; | |
| 279 | + default: | |
| 280 | + $filter = ''; | |
| 281 | + break; | |
| 282 | + } | |
| 283 | 283 | |
| 284 | - $quer_args = array(); | |
| 285 | - $quer_args[ 'paged' ] = '2'; | |
| 286 | -                if( !empty( $filter ) ){ | |
| 287 | - $quer_args[ 'course_filter' ] = $filter; | |
| 288 | - } | |
| 284 | + $quer_args = array(); | |
| 285 | + $quer_args[ 'paged' ] = '2'; | |
| 286 | +				if( !empty( $filter ) ){ | |
| 287 | + $quer_args[ 'course_filter' ] = $filter; | |
| 288 | + } | |
| 289 | 289 | |
| 290 | - $course_pagination_link = get_post_type_archive_link( 'course' ); | |
| 291 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); | |
| 292 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); | |
| 290 | + $course_pagination_link = get_post_type_archive_link( 'course' ); | |
| 291 | + $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); | |
| 292 | + $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); | |
| 293 | 293 | |
| 294 | - // next/more | |
| 295 | - $html = '<div class="navigation"><div class="nav-next">'; | |
| 296 | - $html .= '<a href="' . $more_link_url . '">'; | |
| 297 | - $html .= $more_link_text; | |
| 298 | - $html .= '<span class="meta-nav"></span></a></div>'; | |
| 294 | + // next/more | |
| 295 | + $html = '<div class="navigation"><div class="nav-next">'; | |
| 296 | + $html .= '<a href="' . $more_link_url . '">'; | |
| 297 | + $html .= $more_link_text; | |
| 298 | + $html .= '<span class="meta-nav"></span></a></div>'; | |
| 299 | 299 | |
| 300 | - echo apply_filters( 'course_archive_next_link', $html ); | |
| 300 | + echo apply_filters( 'course_archive_next_link', $html ); | |
| 301 | 301 | |
| 302 | - } // End If Statement | |
| 302 | + } // End If Statement | |
| 303 | 303 | |
| 304 | - } // End If Statement | |
| 305 | - } | |
| 304 | + } // End If Statement | |
| 305 | + } | |
| 306 | 306 | |
| 307 | - /** | |
| 308 | - * Print a single course markup | |
| 309 | - * | |
| 310 | - * @param $course_id | |
| 311 | - */ | |
| 312 | -    public static function the_course( $course_id ){ | |
| 307 | + /** | |
| 308 | + * Print a single course markup | |
| 309 | + * | |
| 310 | + * @param $course_id | |
| 311 | + */ | |
| 312 | +	public static function the_course( $course_id ){ | |
| 313 | 313 | |
| 314 | - // Get meta data | |
| 315 | - $course = get_post( $course_id ); | |
| 316 | - $user_info = get_userdata( absint( $course->post_author ) ); | |
| 317 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); | |
| 318 | - $author_display_name = $user_info->display_name; | |
| 319 | - $author_id = $course->post_author; | |
| 320 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); | |
| 321 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); | |
| 322 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); | |
| 323 | - ?> | |
| 314 | + // Get meta data | |
| 315 | + $course = get_post( $course_id ); | |
| 316 | + $user_info = get_userdata( absint( $course->post_author ) ); | |
| 317 | + $author_link = get_author_posts_url( absint( $course->post_author ) ); | |
| 318 | + $author_display_name = $user_info->display_name; | |
| 319 | + $author_id = $course->post_author; | |
| 320 | + $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); | |
| 321 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); | |
| 322 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); | |
| 323 | + ?> | |
| 324 | 324 | |
| 325 | 325 | <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> | 
| 326 | 326 | <?php | 
| 327 | - // so that legacy shortcodes work with thir party plugins that wants to hook in | |
| 328 | -            do_action('sensei_course_content_before',$course ); | |
| 329 | - ?> | |
| 327 | + // so that legacy shortcodes work with thir party plugins that wants to hook in | |
| 328 | +			do_action('sensei_course_content_before',$course ); | |
| 329 | + ?> | |
| 330 | 330 | <div class="course-content"> | 
| 331 | 331 | |
| 332 | 332 | <?php Sensei()->course->course_image($course_id); ?> | 
| @@ -362,7 +362,7 @@ discard block | ||
| 362 | 362 | </p> | 
| 363 | 363 | |
| 364 | 364 |                      <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { | 
| 365 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> | |
| 365 | + $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> | |
| 366 | 366 | <p class="sensei-free-lessons"> | 
| 367 | 367 | <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> | 
| 368 | 368 | </a> - <?php echo $preview_lessons; ?> | 
| @@ -373,15 +373,15 @@ discard block | ||
| 373 | 373 | |
| 374 | 374 | </div> | 
| 375 | 375 | <?php | 
| 376 | - // so that legacy shortcodes work with thir party plugins that wants to hook in | |
| 377 | -            do_action('sensei_course_content_after', $course->ID); | |
| 378 | - ?> | |
| 376 | + // so that legacy shortcodes work with thir party plugins that wants to hook in | |
| 377 | +			do_action('sensei_course_content_after', $course->ID); | |
| 378 | + ?> | |
| 379 | 379 | |
| 380 | 380 | </article> | 
| 381 | 381 | |
| 382 | 382 | <?php | 
| 383 | 383 | |
| 384 | 384 | |
| 385 | - } // end the_course | |
| 385 | + } // end the_course | |
| 386 | 386 | |
| 387 | 387 | }// end class legacy shortcodes | 
| 388 | 388 | \ No newline at end of file | 
| @@ -114,7 +114,7 @@ | ||
| 114 | 114 | * | 
| 115 | 115 | * @since 1.9.0 | 
| 116 | 116 | * | 
| 117 | - * @param array $category_ids | |
| 117 | + * @param array $categories | |
| 118 | 118 | * @return array | 
| 119 | 119 | */ | 
| 120 | 120 |      public function generate_term_ids( $categories = array() ){ | 
| @@ -24,135 +24,135 @@ | ||
| 24 | 24 | */ | 
| 25 | 25 |  class Sensei_Shortcode_Course_Categories implements Sensei_Shortcode_Interface { | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @var array list of taxonomy terms. | |
| 29 | - */ | |
| 30 | - protected $sensei_course_taxonomy_terms; | |
| 27 | + /** | |
| 28 | + * @var array list of taxonomy terms. | |
| 29 | + */ | |
| 30 | + protected $sensei_course_taxonomy_terms; | |
| 31 | 31 | |
| 32 | - /** | |
| 33 | - * Setup the shortcode object | |
| 34 | - * | |
| 35 | - * @since 1.9.0 | |
| 36 | - * @param array $attributes | |
| 37 | - * @param string $content | |
| 38 | - * @param string $shortcode the shortcode that was called for this instance | |
| 39 | - */ | |
| 40 | -    public function __construct( $attributes, $content, $shortcode ){ | |
| 32 | + /** | |
| 33 | + * Setup the shortcode object | |
| 34 | + * | |
| 35 | + * @since 1.9.0 | |
| 36 | + * @param array $attributes | |
| 37 | + * @param string $content | |
| 38 | + * @param string $shortcode the shortcode that was called for this instance | |
| 39 | + */ | |
| 40 | +	public function __construct( $attributes, $content, $shortcode ){ | |
| 41 | 41 | |
| 42 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name'; | |
| 43 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; | |
| 44 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100'; | |
| 45 | - $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : ''; | |
| 42 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name'; | |
| 43 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; | |
| 44 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100'; | |
| 45 | + $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : ''; | |
| 46 | 46 | |
| 47 | - $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : ''; | |
| 48 | - $this->include = $this->generate_term_ids( $include ); | |
| 47 | + $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : ''; | |
| 48 | + $this->include = $this->generate_term_ids( $include ); | |
| 49 | 49 | |
| 50 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : ''; | |
| 51 | - $this->exclude = $this->generate_term_ids( $exclude ); | |
| 50 | + $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : ''; | |
| 51 | + $this->exclude = $this->generate_term_ids( $exclude ); | |
| 52 | 52 | |
| 53 | - // make sure we handle string true/false values correctly with respective defaults | |
| 54 | - $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false'; | |
| 55 | - $this->hide_empty = 'true' == $hide_empty ? true: false; | |
| 53 | + // make sure we handle string true/false values correctly with respective defaults | |
| 54 | + $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false'; | |
| 55 | + $this->hide_empty = 'true' == $hide_empty ? true: false; | |
| 56 | 56 | |
| 57 | - $this->setup_course_categories(); | |
| 57 | + $this->setup_course_categories(); | |
| 58 | 58 | |
| 59 | - } | |
| 59 | + } | |
| 60 | 60 | |
| 61 | - /** | |
| 62 | - * create the messages query . | |
| 63 | - * | |
| 64 | - * @return mixed | |
| 65 | - */ | |
| 66 | -    public function setup_course_categories(){ | |
| 61 | + /** | |
| 62 | + * create the messages query . | |
| 63 | + * | |
| 64 | + * @return mixed | |
| 65 | + */ | |
| 66 | +	public function setup_course_categories(){ | |
| 67 | 67 | |
| 68 | - $args = array( | |
| 69 | - 'orderby' => $this->orderby, | |
| 70 | - 'order' => $this->order, | |
| 71 | - 'exclude' => $this->exclude, | |
| 72 | - 'include' => $this->include, | |
| 73 | - 'number' => $this->number, | |
| 74 | - 'parent' => $this->parent, | |
| 75 | - 'hide_empty' => $this->hide_empty, | |
| 76 | - 'fields' => 'all', | |
| 77 | - ); | |
| 68 | + $args = array( | |
| 69 | + 'orderby' => $this->orderby, | |
| 70 | + 'order' => $this->order, | |
| 71 | + 'exclude' => $this->exclude, | |
| 72 | + 'include' => $this->include, | |
| 73 | + 'number' => $this->number, | |
| 74 | + 'parent' => $this->parent, | |
| 75 | + 'hide_empty' => $this->hide_empty, | |
| 76 | + 'fields' => 'all', | |
| 77 | + ); | |
| 78 | 78 | |
| 79 | -        $this->sensei_course_taxonomy_terms = get_terms('course-category', $args); | |
| 79 | +		$this->sensei_course_taxonomy_terms = get_terms('course-category', $args); | |
| 80 | 80 | |
| 81 | - } | |
| 81 | + } | |
| 82 | 82 | |
| 83 | - /** | |
| 84 | - * Rendering the shortcode this class is responsible for. | |
| 85 | - * | |
| 86 | - * @return string $content | |
| 87 | - */ | |
| 88 | -    public function render(){ | |
| 83 | + /** | |
| 84 | + * Rendering the shortcode this class is responsible for. | |
| 85 | + * | |
| 86 | + * @return string $content | |
| 87 | + */ | |
| 88 | +	public function render(){ | |
| 89 | 89 | |
| 90 | -        if( empty(  $this->sensei_course_taxonomy_terms  ) ){ | |
| 90 | +		if( empty(  $this->sensei_course_taxonomy_terms  ) ){ | |
| 91 | 91 | |
| 92 | - return __( 'No course categories found.', 'woothemes-sensei' ); | |
| 92 | + return __( 'No course categories found.', 'woothemes-sensei' ); | |
| 93 | 93 | |
| 94 | - } | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - $terms_html = ''; | |
| 96 | + $terms_html = ''; | |
| 97 | 97 | |
| 98 | - //set the wp_query to the current messages query | |
| 99 | - $terms_html .= '<ul class="sensei course-categories">'; | |
| 100 | -        foreach( $this->sensei_course_taxonomy_terms as $category ){ | |
| 98 | + //set the wp_query to the current messages query | |
| 99 | + $terms_html .= '<ul class="sensei course-categories">'; | |
| 100 | +		foreach( $this->sensei_course_taxonomy_terms as $category ){ | |
| 101 | 101 | |
| 102 | - $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name . '</a>'; | |
| 103 | - $terms_html .= '<li class="sensei course-category" >' . $category_link . '</li>'; | |
| 102 | + $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name . '</a>'; | |
| 103 | + $terms_html .= '<li class="sensei course-category" >' . $category_link . '</li>'; | |
| 104 | 104 | |
| 105 | - } | |
| 106 | - $terms_html .= '<ul>'; | |
| 105 | + } | |
| 106 | + $terms_html .= '<ul>'; | |
| 107 | 107 | |
| 108 | - return $terms_html; | |
| 108 | + return $terms_html; | |
| 109 | 109 | |
| 110 | - }// end render | |
| 110 | + }// end render | |
| 111 | 111 | |
| 112 | - /** | |
| 113 | - * Convert an array of mixed ids, slugs or names to only the id's of those terms | |
| 114 | - * | |
| 115 | - * @since 1.9.0 | |
| 116 | - * | |
| 117 | - * @param array $category_ids | |
| 118 | - * @return array | |
| 119 | - */ | |
| 120 | -    public function generate_term_ids( $categories = array() ){ | |
| 112 | + /** | |
| 113 | + * Convert an array of mixed ids, slugs or names to only the id's of those terms | |
| 114 | + * | |
| 115 | + * @since 1.9.0 | |
| 116 | + * | |
| 117 | + * @param array $category_ids | |
| 118 | + * @return array | |
| 119 | + */ | |
| 120 | +	public function generate_term_ids( $categories = array() ){ | |
| 121 | 121 | |
| 122 | - $cat_ids = array(); | |
| 122 | + $cat_ids = array(); | |
| 123 | 123 | |
| 124 | -        if ( is_array($categories) ) { | |
| 125 | -            foreach ($categories as $cat) { | |
| 124 | +		if ( is_array($categories) ) { | |
| 125 | +			foreach ($categories as $cat) { | |
| 126 | 126 | |
| 127 | -                if (!is_numeric($cat)) { | |
| 127 | +				if (!is_numeric($cat)) { | |
| 128 | 128 | |
| 129 | - // try the slug | |
| 130 | -                    $term = get_term_by('slug', $cat, 'course-category'); | |
| 129 | + // try the slug | |
| 130 | +					$term = get_term_by('slug', $cat, 'course-category'); | |
| 131 | 131 | |
| 132 | - // if the slug didn't work try the name | |
| 133 | -                    if (!$term) { | |
| 132 | + // if the slug didn't work try the name | |
| 133 | +					if (!$term) { | |
| 134 | 134 | |
| 135 | -                        $term = get_term_by('name', $cat, 'course-category'); | |
| 135 | +						$term = get_term_by('name', $cat, 'course-category'); | |
| 136 | 136 | |
| 137 | - } | |
| 137 | + } | |
| 138 | 138 | |
| 139 | -                    if ($term) { | |
| 140 | - $cat_ids[] = $term->term_id; | |
| 141 | - } | |
| 139 | +					if ($term) { | |
| 140 | + $cat_ids[] = $term->term_id; | |
| 141 | + } | |
| 142 | 142 | |
| 143 | -                } else { | |
| 143 | +				} else { | |
| 144 | 144 | |
| 145 | - $cat_ids[] = $cat; | |
| 145 | + $cat_ids[] = $cat; | |
| 146 | 146 | |
| 147 | - } | |
| 147 | + } | |
| 148 | 148 | |
| 149 | - } | |
| 149 | + } | |
| 150 | 150 | |
| 151 | - } | |
| 151 | + } | |
| 152 | 152 | |
| 153 | - return $cat_ids; | |
| 153 | + return $cat_ids; | |
| 154 | 154 | |
| 155 | - }// end generate_term_ids | |
| 155 | + }// end generate_term_ids | |
| 156 | 156 | |
| 157 | 157 | }// end class | 
| 158 | 158 | |
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly | |
| 3 | 3 | /** | 
| 4 | 4 | * | 
| 5 | 5 | * Renders the [sensei_course_categories] shortcode. Show the list or course categories as links to their archive | 
| @@ -37,22 +37,22 @@ discard block | ||
| 37 | 37 | * @param string $content | 
| 38 | 38 | * @param string $shortcode the shortcode that was called for this instance | 
| 39 | 39 | */ | 
| 40 | -    public function __construct( $attributes, $content, $shortcode ){ | |
| 40 | +    public function __construct($attributes, $content, $shortcode) { | |
| 41 | 41 | |
| 42 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name'; | |
| 43 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; | |
| 44 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100'; | |
| 45 | - $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : ''; | |
| 42 | + $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'name'; | |
| 43 | + $this->order = isset($attributes['order']) ? $attributes['order'] : 'ASC'; | |
| 44 | + $this->number = isset($attributes['number']) ? $attributes['number'] : '100'; | |
| 45 | + $this->parent = isset($attributes['parent']) ? $attributes['parent'] : ''; | |
| 46 | 46 | |
| 47 | - $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : ''; | |
| 48 | - $this->include = $this->generate_term_ids( $include ); | |
| 47 | +        $include = isset($attributes['include']) ? explode(',', $attributes['include']) : ''; | |
| 48 | + $this->include = $this->generate_term_ids($include); | |
| 49 | 49 | |
| 50 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : ''; | |
| 51 | - $this->exclude = $this->generate_term_ids( $exclude ); | |
| 50 | +        $exclude = isset($attributes['exclude']) ? explode(',', $attributes['exclude']) : ''; | |
| 51 | + $this->exclude = $this->generate_term_ids($exclude); | |
| 52 | 52 | |
| 53 | 53 | // make sure we handle string true/false values correctly with respective defaults | 
| 54 | - $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false'; | |
| 55 | - $this->hide_empty = 'true' == $hide_empty ? true: false; | |
| 54 | + $hide_empty = isset($attributes['hide_empty']) ? $attributes['hide_empty'] : 'false'; | |
| 55 | + $this->hide_empty = 'true' == $hide_empty ? true : false; | |
| 56 | 56 | |
| 57 | 57 | $this->setup_course_categories(); | 
| 58 | 58 | |
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | * | 
| 64 | 64 | * @return mixed | 
| 65 | 65 | */ | 
| 66 | -    public function setup_course_categories(){ | |
| 66 | +    public function setup_course_categories() { | |
| 67 | 67 | |
| 68 | 68 | $args = array( | 
| 69 | 69 | 'orderby' => $this->orderby, | 
| @@ -85,11 +85,11 @@ discard block | ||
| 85 | 85 | * | 
| 86 | 86 | * @return string $content | 
| 87 | 87 | */ | 
| 88 | -    public function render(){ | |
| 88 | +    public function render() { | |
| 89 | 89 | |
| 90 | -        if( empty(  $this->sensei_course_taxonomy_terms  ) ){ | |
| 90 | +        if (empty($this->sensei_course_taxonomy_terms)) { | |
| 91 | 91 | |
| 92 | - return __( 'No course categories found.', 'woothemes-sensei' ); | |
| 92 | +            return __('No course categories found.', 'woothemes-sensei'); | |
| 93 | 93 | |
| 94 | 94 | } | 
| 95 | 95 | |
| @@ -97,10 +97,10 @@ discard block | ||
| 97 | 97 | |
| 98 | 98 | //set the wp_query to the current messages query | 
| 99 | 99 | $terms_html .= '<ul class="sensei course-categories">'; | 
| 100 | -        foreach( $this->sensei_course_taxonomy_terms as $category ){ | |
| 100 | +        foreach ($this->sensei_course_taxonomy_terms as $category) { | |
| 101 | 101 | |
| 102 | - $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name . '</a>'; | |
| 103 | - $terms_html .= '<li class="sensei course-category" >' . $category_link . '</li>'; | |
| 102 | + $category_link = '<a href="'.get_term_link($category).'">'.$category->name.'</a>'; | |
| 103 | + $terms_html .= '<li class="sensei course-category" >'.$category_link.'</li>'; | |
| 104 | 104 | |
| 105 | 105 | } | 
| 106 | 106 | $terms_html .= '<ul>'; | 
| @@ -117,20 +117,20 @@ discard block | ||
| 117 | 117 | * @param array $category_ids | 
| 118 | 118 | * @return array | 
| 119 | 119 | */ | 
| 120 | -    public function generate_term_ids( $categories = array() ){ | |
| 120 | +    public function generate_term_ids($categories = array()) { | |
| 121 | 121 | |
| 122 | 122 | $cat_ids = array(); | 
| 123 | 123 | |
| 124 | -        if ( is_array($categories) ) { | |
| 124 | +        if (is_array($categories)) { | |
| 125 | 125 |              foreach ($categories as $cat) { | 
| 126 | 126 | |
| 127 | -                if (!is_numeric($cat)) { | |
| 127 | +                if ( ! is_numeric($cat)) { | |
| 128 | 128 | |
| 129 | 129 | // try the slug | 
| 130 | 130 |                      $term = get_term_by('slug', $cat, 'course-category'); | 
| 131 | 131 | |
| 132 | 132 | // if the slug didn't work try the name | 
| 133 | -                    if (!$term) { | |
| 133 | +                    if ( ! $term) { | |
| 134 | 134 | |
| 135 | 135 |                          $term = get_term_by('name', $cat, 'course-category'); | 
| 136 | 136 | |
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php | 
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; | |
| 4 | +} | |
| 5 | +// Exit if accessed directly | |
| 3 | 6 | |
| 4 | 7 | /** | 
| 5 | 8 | * Sensei Analysis User Profile List Table Class |