@@ -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 Utilities Class |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | * @since 1.0.0 |
| 19 | 19 | * @return string The URL to the placeholder thumbnail image. |
| 20 | 20 | */ |
| 21 | - public static function get_placeholder_image () { |
|
| 21 | + public static function get_placeholder_image() { |
|
| 22 | 22 | |
| 23 | - return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) ); |
|
| 23 | + return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png')); |
|
| 24 | 24 | } // End get_placeholder_image() |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @static |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public static function sensei_is_woocommerce_present () { |
|
| 35 | + public static function sensei_is_woocommerce_present() { |
|
| 36 | 36 | |
| 37 | 37 | return Sensei_WC::is_woocommerce_present(); |
| 38 | 38 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @static |
| 48 | 48 | * @return boolean |
| 49 | 49 | */ |
| 50 | - public static function sensei_is_woocommerce_activated () { |
|
| 50 | + public static function sensei_is_woocommerce_activated() { |
|
| 51 | 51 | |
| 52 | 52 | return Sensei_WC::is_woocommerce_active(); |
| 53 | 53 | |
@@ -60,70 +60,70 @@ discard block |
||
| 60 | 60 | * @param array $args (default: array()) |
| 61 | 61 | * @return bool | int |
| 62 | 62 | */ |
| 63 | - public static function sensei_log_activity ( $args = array() ) { |
|
| 63 | + public static function sensei_log_activity($args = array()) { |
|
| 64 | 64 | global $wpdb; |
| 65 | 65 | |
| 66 | 66 | // Args, minimum data required for WP |
| 67 | 67 | $data = array( |
| 68 | - 'comment_post_ID' => intval( $args['post_id'] ), |
|
| 68 | + 'comment_post_ID' => intval($args['post_id']), |
|
| 69 | 69 | 'comment_author' => '', // Not needed |
| 70 | 70 | 'comment_author_email' => '', // Not needed |
| 71 | 71 | 'comment_author_url' => '', // Not needed |
| 72 | - 'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '', |
|
| 73 | - 'comment_type' => esc_attr( $args['type'] ), |
|
| 74 | - 'user_id' => intval( $args['user_id'] ), |
|
| 75 | - 'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer' |
|
| 72 | + 'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '', |
|
| 73 | + 'comment_type' => esc_attr($args['type']), |
|
| 74 | + 'user_id' => intval($args['user_id']), |
|
| 75 | + 'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer' |
|
| 76 | 76 | ); |
| 77 | 77 | // Allow extra data |
| 78 | - if ( !empty($args['username']) ) { |
|
| 79 | - $data['comment_author'] = sanitize_user( $args['username'] ); |
|
| 78 | + if ( ! empty($args['username'])) { |
|
| 79 | + $data['comment_author'] = sanitize_user($args['username']); |
|
| 80 | 80 | } |
| 81 | - if ( !empty($args['user_email']) ) { |
|
| 82 | - $data['comment_author_email'] = sanitize_email( $args['user_email'] ); |
|
| 81 | + if ( ! empty($args['user_email'])) { |
|
| 82 | + $data['comment_author_email'] = sanitize_email($args['user_email']); |
|
| 83 | 83 | } |
| 84 | - if ( !empty($args['user_url']) ) { |
|
| 85 | - $data['comment_author_url'] = esc_url( $args['user_url'] ); |
|
| 84 | + if ( ! empty($args['user_url'])) { |
|
| 85 | + $data['comment_author_url'] = esc_url($args['user_url']); |
|
| 86 | 86 | } |
| 87 | - if ( !empty($args['parent']) ) { |
|
| 87 | + if ( ! empty($args['parent'])) { |
|
| 88 | 88 | $data['comment_parent'] = $args['parent']; |
| 89 | 89 | } |
| 90 | 90 | // Sanity check |
| 91 | - if ( empty($args['user_id']) ) { |
|
| 92 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 91 | + if (empty($args['user_id'])) { |
|
| 92 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - do_action( 'sensei_log_activity_before', $args, $data ); |
|
| 96 | + do_action('sensei_log_activity_before', $args, $data); |
|
| 97 | 97 | |
| 98 | 98 | $flush_cache = false; |
| 99 | 99 | |
| 100 | 100 | // Custom Logic |
| 101 | 101 | // Check if comment exists first |
| 102 | - $comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) ); |
|
| 103 | - if ( ! $comment_id ) { |
|
| 102 | + $comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'])); |
|
| 103 | + if ( ! $comment_id) { |
|
| 104 | 104 | // Add the comment |
| 105 | - $comment_id = wp_insert_comment( $data ); |
|
| 105 | + $comment_id = wp_insert_comment($data); |
|
| 106 | 106 | |
| 107 | 107 | $flush_cache = true; |
| 108 | - } elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) { |
|
| 108 | + } elseif (isset($args['action']) && 'update' == $args['action']) { |
|
| 109 | 109 | // Update the comment if an update was requested |
| 110 | 110 | $data['comment_ID'] = $comment_id; |
| 111 | 111 | // By default update the timestamp of the comment |
| 112 | - if ( empty($args['keep_time']) ) { |
|
| 112 | + if (empty($args['keep_time'])) { |
|
| 113 | 113 | $data['comment_date'] = current_time('mysql'); |
| 114 | 114 | } |
| 115 | - wp_update_comment( $data ); |
|
| 115 | + wp_update_comment($data); |
|
| 116 | 116 | $flush_cache = true; |
| 117 | 117 | } // End If Statement |
| 118 | 118 | |
| 119 | 119 | // Manually Flush the Cache |
| 120 | - if ( $flush_cache ) { |
|
| 120 | + if ($flush_cache) { |
|
| 121 | 121 | wp_cache_flush(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - do_action( 'sensei_log_activity_after', $args, $data, $comment_id ); |
|
| 124 | + do_action('sensei_log_activity_after', $args, $data, $comment_id); |
|
| 125 | 125 | |
| 126 | - if ( 0 < $comment_id ) { |
|
| 126 | + if (0 < $comment_id) { |
|
| 127 | 127 | // Return the ID so that it can be used for meta data storage |
| 128 | 128 | return $comment_id; |
| 129 | 129 | } else { |
@@ -140,41 +140,41 @@ discard block |
||
| 140 | 140 | * @param bool $return_comments (default: false) |
| 141 | 141 | * @return mixed | int |
| 142 | 142 | */ |
| 143 | - public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) { |
|
| 143 | + public static function sensei_check_for_activity($args = array(), $return_comments = false) { |
|
| 144 | 144 | |
| 145 | 145 | global $wp_version; |
| 146 | - if ( !$return_comments ) { |
|
| 146 | + if ( ! $return_comments) { |
|
| 147 | 147 | $args['count'] = true; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Are we only retrieving a single entry, or not care about the order... |
| 151 | - if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){ |
|
| 151 | + if (isset($args['count']) || isset($args['post_id'])) { |
|
| 152 | 152 | |
| 153 | 153 | // ...then we don't need to ask the db to order the results, this overrides WP default behaviour |
| 154 | - if ( version_compare( $wp_version, '4.1', '>=' ) ) { |
|
| 154 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 155 | 155 | $args['order'] = false; |
| 156 | 156 | $args['orderby'] = false; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // A user ID of 0 is in valid, so shortcut this |
| 161 | - if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) { |
|
| 162 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
| 161 | + if (isset($args['user_id']) && 0 == intval($args['user_id'])) { |
|
| 162 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | // Check for legacy code |
| 166 | - if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) { |
|
| 167 | - _deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) ); |
|
| 166 | + if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) { |
|
| 167 | + _deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'])); |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | // Are we checking for specific comment_approved statuses? |
| 171 | - if ( isset($args['status']) ) { |
|
| 171 | + if (isset($args['status'])) { |
|
| 172 | 172 | // Temporarily store as a custom status if requesting an array... |
| 173 | - if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 173 | + if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 174 | 174 | // Encode now, decode later |
| 175 | - $args['status'] = implode( ",", $args['status'] ); |
|
| 175 | + $args['status'] = implode(",", $args['status']); |
|
| 176 | 176 | // ...use a filter to switch the encoding back |
| 177 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 177 | + add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | else { |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 ' |
| 185 | - if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
| 186 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 185 | + if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
| 186 | + add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | //Get the comments |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param int|array $comments |
| 196 | 196 | */ |
| 197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 197 | + $comments = apply_filters('sensei_check_for_activity', get_comments($args)); |
|
| 198 | 198 | |
| 199 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
| 200 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
| 199 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
| 200 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
| 201 | 201 | // Return comments |
| 202 | - if ( $return_comments ) { |
|
| 202 | + if ($return_comments) { |
|
| 203 | 203 | // Could check for array of 1 and just return the 1 item? |
| 204 | - if ( is_array($comments) && 1 == count($comments) ) { |
|
| 204 | + if (is_array($comments) && 1 == count($comments)) { |
|
| 205 | 205 | $comments = array_shift($comments); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -219,31 +219,31 @@ discard block |
||
| 219 | 219 | * @param array $args (default: array()) |
| 220 | 220 | * @return array |
| 221 | 221 | */ |
| 222 | - public static function sensei_activity_ids ( $args = array() ) { |
|
| 222 | + public static function sensei_activity_ids($args = array()) { |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - $comments = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 225 | + $comments = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 226 | 226 | // Need to always use an array, even with only 1 item |
| 227 | - if ( !is_array($comments) ) { |
|
| 228 | - $comments = array( $comments ); |
|
| 227 | + if ( ! is_array($comments)) { |
|
| 228 | + $comments = array($comments); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $post_ids = array(); |
| 232 | 232 | // Count comments |
| 233 | - if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) { |
|
| 234 | - foreach ( $comments as $key => $value ) { |
|
| 233 | + if (is_array($comments) && (0 < intval(count($comments)))) { |
|
| 234 | + foreach ($comments as $key => $value) { |
|
| 235 | 235 | // Add matches to id array |
| 236 | - if ( isset( $args['field'] ) && 'comment' == $args['field'] ) { |
|
| 237 | - array_push( $post_ids, $value->comment_ID ); |
|
| 238 | - } elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) { |
|
| 239 | - array_push( $post_ids, $value->user_id ); |
|
| 236 | + if (isset($args['field']) && 'comment' == $args['field']) { |
|
| 237 | + array_push($post_ids, $value->comment_ID); |
|
| 238 | + } elseif (isset($args['field']) && 'user_id' == $args['field']) { |
|
| 239 | + array_push($post_ids, $value->user_id); |
|
| 240 | 240 | } else { |
| 241 | - array_push( $post_ids, $value->comment_post_ID ); |
|
| 241 | + array_push($post_ids, $value->comment_post_ID); |
|
| 242 | 242 | } // End If Statement |
| 243 | 243 | } // End For Loop |
| 244 | 244 | // Reset array indexes |
| 245 | - $post_ids = array_unique( $post_ids ); |
|
| 246 | - $post_ids = array_values( $post_ids ); |
|
| 245 | + $post_ids = array_unique($post_ids); |
|
| 246 | + $post_ids = array_values($post_ids); |
|
| 247 | 247 | } // End If Statement |
| 248 | 248 | |
| 249 | 249 | return $post_ids; |
@@ -257,20 +257,20 @@ discard block |
||
| 257 | 257 | * @param array $args (default: array()) |
| 258 | 258 | * @return boolean |
| 259 | 259 | */ |
| 260 | - public static function sensei_delete_activities ( $args = array() ) { |
|
| 260 | + public static function sensei_delete_activities($args = array()) { |
|
| 261 | 261 | |
| 262 | 262 | $dataset_changes = false; |
| 263 | 263 | |
| 264 | 264 | // If activity exists remove activity from log |
| 265 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true ); |
|
| 266 | - if( $comments ) { |
|
| 265 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true); |
|
| 266 | + if ($comments) { |
|
| 267 | 267 | // Need to always return an array, even with only 1 item |
| 268 | - if ( !is_array( $comments ) ) { |
|
| 269 | - $comments = array( $comments ); |
|
| 268 | + if ( ! is_array($comments)) { |
|
| 269 | + $comments = array($comments); |
|
| 270 | 270 | } |
| 271 | - foreach ( $comments as $key => $value ) { |
|
| 272 | - if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { |
|
| 273 | - $dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true ); |
|
| 271 | + foreach ($comments as $key => $value) { |
|
| 272 | + if (isset($value->comment_ID) && 0 < $value->comment_ID) { |
|
| 273 | + $dataset_changes = wp_delete_comment(intval($value->comment_ID), true); |
|
| 274 | 274 | } // End If Statement |
| 275 | 275 | } // End For Loop |
| 276 | 276 | // Manually flush the cache |
@@ -286,25 +286,25 @@ discard block |
||
| 286 | 286 | * @param integer $user_id User ID |
| 287 | 287 | * @return boolean |
| 288 | 288 | */ |
| 289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 289 | + public static function delete_all_user_activity($user_id = 0) { |
|
| 290 | 290 | |
| 291 | 291 | $dataset_changes = false; |
| 292 | 292 | |
| 293 | - if( $user_id ) { |
|
| 293 | + if ($user_id) { |
|
| 294 | 294 | |
| 295 | - $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
|
| 295 | + $activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true); |
|
| 296 | 296 | |
| 297 | - if( $activities ) { |
|
| 297 | + if ($activities) { |
|
| 298 | 298 | |
| 299 | 299 | // Need to always return an array, even with only 1 item |
| 300 | - if ( ! is_array( $activities ) ) { |
|
| 301 | - $activities = array( $activities ); |
|
| 300 | + if ( ! is_array($activities)) { |
|
| 301 | + $activities = array($activities); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - foreach( $activities as $activity ) { |
|
| 305 | - if( '' == $activity->comment_type ) continue; |
|
| 306 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 307 | - $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 304 | + foreach ($activities as $activity) { |
|
| 305 | + if ('' == $activity->comment_type) continue; |
|
| 306 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 307 | + $dataset_changes = wp_delete_comment(intval($activity->comment_ID), true); |
|
| 308 | 308 | wp_cache_flush(); |
| 309 | 309 | } |
| 310 | 310 | } |
@@ -321,13 +321,13 @@ discard block |
||
| 321 | 321 | * @param array $args (default: array()) |
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | - public static function sensei_get_activity_value ( $args = array() ) { |
|
| 324 | + public static function sensei_get_activity_value($args = array()) { |
|
| 325 | 325 | |
| 326 | 326 | $activity_value = false; |
| 327 | - if ( !empty($args['field']) ) { |
|
| 328 | - $comment = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
| 327 | + if ( ! empty($args['field'])) { |
|
| 328 | + $comment = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 329 | 329 | |
| 330 | - if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 330 | + if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
| 331 | 331 | $activity_value = $comment->{$args['field']}; |
| 332 | 332 | } // End If Statement |
| 333 | 333 | } |
@@ -345,22 +345,22 @@ discard block |
||
| 345 | 345 | * @param int $product_id |
| 346 | 346 | * @return bool |
| 347 | 347 | */ |
| 348 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 348 | + public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) { |
|
| 349 | 349 | |
| 350 | 350 | $emails = array(); |
| 351 | 351 | |
| 352 | - if ( $user_id ) { |
|
| 353 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 352 | + if ($user_id) { |
|
| 353 | + $user = get_user_by('id', intval($user_id)); |
|
| 354 | 354 | $emails[] = $user->user_email; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( is_email( $customer_email ) ) |
|
| 357 | + if (is_email($customer_email)) |
|
| 358 | 358 | $emails[] = $customer_email; |
| 359 | 359 | |
| 360 | - if ( sizeof( $emails ) == 0 ) |
|
| 360 | + if (sizeof($emails) == 0) |
|
| 361 | 361 | return false; |
| 362 | 362 | |
| 363 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 363 | + return Sensei_WC::has_customer_bought_product($user_id, $product_id); |
|
| 364 | 364 | |
| 365 | 365 | } // End sensei_customer_bought_product() |
| 366 | 366 | |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | * @param string $input_name Name for text area form element |
| 372 | 372 | * @return void |
| 373 | 373 | */ |
| 374 | - public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
|
| 374 | + public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') { |
|
| 375 | 375 | |
| 376 | - if( ! $input_name ) $input_name = $editor_id; |
|
| 376 | + if ( ! $input_name) $input_name = $editor_id; |
|
| 377 | 377 | |
| 378 | 378 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
| 379 | 379 | |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | 'quicktags' => false |
| 392 | 392 | ); |
| 393 | 393 | |
| 394 | - wp_editor( $content, $editor_id, $settings ); |
|
| 394 | + wp_editor($content, $editor_id, $settings); |
|
| 395 | 395 | |
| 396 | 396 | } // End sensei_text_editor() |
| 397 | 397 | |
@@ -401,57 +401,57 @@ discard block |
||
| 401 | 401 | * @param int $user_id |
| 402 | 402 | * @return boolean Whether the answers were saved or not |
| 403 | 403 | */ |
| 404 | - public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
|
| 404 | + public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) { |
|
| 405 | 405 | |
| 406 | - if( intval( $user_id ) == 0 ) { |
|
| 406 | + if (intval($user_id) == 0) { |
|
| 407 | 407 | $user_id = get_current_user_id(); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $answers_saved = false; |
| 411 | 411 | |
| 412 | - if( $submitted && intval( $user_id ) > 0 ) { |
|
| 412 | + if ($submitted && intval($user_id) > 0) { |
|
| 413 | 413 | |
| 414 | - foreach( $submitted as $question_id => $answer ) { |
|
| 414 | + foreach ($submitted as $question_id => $answer) { |
|
| 415 | 415 | |
| 416 | 416 | // Get 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 | - switch( $question_type ) { |
|
| 424 | - case 'multi-line': $answer = nl2br( $answer ); break; |
|
| 423 | + switch ($question_type) { |
|
| 424 | + case 'multi-line': $answer = nl2br($answer); break; |
|
| 425 | 425 | case 'single-line': break; |
| 426 | 426 | case 'gap-fill': break; |
| 427 | - default: $answer = maybe_serialize( $answer ); break; |
|
| 427 | + default: $answer = maybe_serialize($answer); break; |
|
| 428 | 428 | } |
| 429 | 429 | $args = array( |
| 430 | 430 | 'post_id' => $question_id, |
| 431 | - 'data' => base64_encode( $answer ), |
|
| 431 | + 'data' => base64_encode($answer), |
|
| 432 | 432 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 433 | 433 | 'user_id' => $user_id, |
| 434 | 434 | 'action' => 'update' |
| 435 | 435 | ); |
| 436 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
| 436 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Handle file upload questions |
| 440 | - if( isset( $_FILES ) ) { |
|
| 441 | - foreach( $_FILES as $field => $file ) { |
|
| 442 | - if( strpos( $field, 'file_upload_' ) !== false ) { |
|
| 443 | - $question_id = str_replace( 'file_upload_', '', $field ); |
|
| 444 | - if( $file && $question_id ) { |
|
| 445 | - $attachment_id = self::upload_file( $file ); |
|
| 446 | - if( $attachment_id ) { |
|
| 440 | + if (isset($_FILES)) { |
|
| 441 | + foreach ($_FILES as $field => $file) { |
|
| 442 | + if (strpos($field, 'file_upload_') !== false) { |
|
| 443 | + $question_id = str_replace('file_upload_', '', $field); |
|
| 444 | + if ($file && $question_id) { |
|
| 445 | + $attachment_id = self::upload_file($file); |
|
| 446 | + if ($attachment_id) { |
|
| 447 | 447 | $args = array( |
| 448 | 448 | 'post_id' => $question_id, |
| 449 | - 'data' => base64_encode( $attachment_id ), |
|
| 449 | + 'data' => base64_encode($attachment_id), |
|
| 450 | 450 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
| 451 | 451 | 'user_id' => $user_id, |
| 452 | 452 | 'action' => 'update' |
| 453 | 453 | ); |
| 454 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
| 454 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | } |
@@ -463,9 +463,9 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | } // End sensei_save_quiz_answers() |
| 465 | 465 | |
| 466 | - public static function upload_file( $file = array() ) { |
|
| 466 | + public static function upload_file($file = array()) { |
|
| 467 | 467 | |
| 468 | - require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
|
| 468 | + require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | 471 | * Filter the data array for the Sensei wp_handle_upload function call |
@@ -480,11 +480,11 @@ discard block |
||
| 480 | 480 | * @type string test_form set to false by default |
| 481 | 481 | * } |
| 482 | 482 | */ |
| 483 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 483 | + $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false)); |
|
| 484 | 484 | |
| 485 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 485 | + $file_return = wp_handle_upload($file, $file_upload_args); |
|
| 486 | 486 | |
| 487 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 487 | + if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { |
|
| 488 | 488 | return false; |
| 489 | 489 | } else { |
| 490 | 490 | |
@@ -492,19 +492,19 @@ discard block |
||
| 492 | 492 | |
| 493 | 493 | $attachment = array( |
| 494 | 494 | 'post_mime_type' => $file_return['type'], |
| 495 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 495 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
| 496 | 496 | 'post_content' => '', |
| 497 | 497 | 'post_status' => 'inherit', |
| 498 | 498 | 'guid' => $file_return['url'] |
| 499 | 499 | ); |
| 500 | 500 | |
| 501 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 501 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
| 502 | 502 | |
| 503 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 504 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 505 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 503 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 504 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
| 505 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
| 506 | 506 | |
| 507 | - if( 0 < intval( $attachment_id ) ) { |
|
| 507 | + if (0 < intval($attachment_id)) { |
|
| 508 | 508 | return $attachment_id; |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -530,9 +530,9 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * @return int $quiz_grade total sum of all question grades |
| 532 | 532 | */ |
| 533 | - public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 533 | + public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
| 534 | 534 | |
| 535 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 535 | + return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); |
|
| 536 | 536 | |
| 537 | 537 | } // End sensei_grade_quiz_auto() |
| 538 | 538 | |
@@ -544,20 +544,20 @@ discard block |
||
| 544 | 544 | * @param string $quiz_grade_type default 'auto' |
| 545 | 545 | * @return boolean |
| 546 | 546 | */ |
| 547 | - public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
|
| 548 | - if( intval( $user_id ) == 0 ) { |
|
| 547 | + public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') { |
|
| 548 | + if (intval($user_id) == 0) { |
|
| 549 | 549 | $user_id = get_current_user_id(); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $activity_logged = false; |
| 553 | - if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 554 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 555 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 556 | - $activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade ); |
|
| 553 | + if (intval($quiz_id) > 0 && intval($user_id) > 0) { |
|
| 554 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 555 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 556 | + $activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade); |
|
| 557 | 557 | |
| 558 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 558 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 559 | 559 | |
| 560 | - do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type ); |
|
| 560 | + do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | return $activity_logged; |
@@ -577,9 +577,9 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @return int $question_grade |
| 579 | 579 | */ |
| 580 | - public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 580 | + public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
| 581 | 581 | |
| 582 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 582 | + return WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
| 583 | 583 | |
| 584 | 584 | } // end sensei_grade_question_auto |
| 585 | 585 | |
@@ -590,20 +590,20 @@ discard block |
||
| 590 | 590 | * @param int $user_id |
| 591 | 591 | * @return boolean |
| 592 | 592 | */ |
| 593 | - public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
|
| 594 | - if( intval( $user_id ) == 0 ) { |
|
| 593 | + public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) { |
|
| 594 | + if (intval($user_id) == 0) { |
|
| 595 | 595 | $user_id = get_current_user_id(); |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | $activity_logged = false; |
| 599 | - if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) { |
|
| 599 | + if (intval($question_id) > 0 && intval($user_id) > 0) { |
|
| 600 | 600 | |
| 601 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 602 | - $activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade ); |
|
| 601 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 602 | + $activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade); |
|
| 603 | 603 | |
| 604 | - $answer_notes = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 605 | - if ( !empty($answer_notes) ) { |
|
| 606 | - update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) ); |
|
| 604 | + $answer_notes = get_post_meta($question_id, '_answer_feedback', true); |
|
| 605 | + if ( ! empty($answer_notes)) { |
|
| 606 | + update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes)); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | } |
@@ -611,15 +611,15 @@ discard block |
||
| 611 | 611 | return $activity_logged; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) { |
|
| 615 | - if( intval( $user_id ) == 0 ) { |
|
| 614 | + public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) { |
|
| 615 | + if (intval($user_id) == 0) { |
|
| 616 | 616 | $user_id = get_current_user_id(); |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | $activity_logged = false; |
| 620 | - if( intval( $question_id ) > 0 ) { |
|
| 621 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 622 | - $activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' ); |
|
| 620 | + if (intval($question_id) > 0) { |
|
| 621 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 622 | + $activity_logged = delete_comment_meta($user_answer_id, 'user_grade'); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | return $activity_logged; |
@@ -637,9 +637,9 @@ discard block |
||
| 637 | 637 | * |
| 638 | 638 | * @return mixed boolean or comment_ID |
| 639 | 639 | */ |
| 640 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 640 | + public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) { |
|
| 641 | 641 | |
| 642 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 642 | + return self::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
| 643 | 643 | |
| 644 | 644 | }// end user_start_lesson() |
| 645 | 645 | |
@@ -656,22 +656,22 @@ discard block |
||
| 656 | 656 | * |
| 657 | 657 | * @return mixed boolean or comment_ID |
| 658 | 658 | */ |
| 659 | - public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
|
| 659 | + public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) { |
|
| 660 | 660 | |
| 661 | 661 | |
| 662 | - if( intval( $user_id ) == 0 ) { |
|
| 662 | + if (intval($user_id) == 0) { |
|
| 663 | 663 | $user_id = get_current_user_id(); |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | $activity_logged = false; |
| 667 | 667 | |
| 668 | - if( intval( $lesson_id ) > 0 ) { |
|
| 668 | + if (intval($lesson_id) > 0) { |
|
| 669 | 669 | |
| 670 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 671 | - if( $course_id ) { |
|
| 672 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 673 | - if( ! $is_user_taking_course ) { |
|
| 674 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 670 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 671 | + if ($course_id) { |
|
| 672 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 673 | + if ( ! $is_user_taking_course) { |
|
| 674 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
@@ -679,12 +679,12 @@ discard block |
||
| 679 | 679 | $status = 'in-progress'; |
| 680 | 680 | |
| 681 | 681 | // Note: When this action runs the lesson status may not yet exist |
| 682 | - do_action( 'sensei_user_lesson_start', $user_id, $lesson_id ); |
|
| 682 | + do_action('sensei_user_lesson_start', $user_id, $lesson_id); |
|
| 683 | 683 | |
| 684 | - if( $complete ) { |
|
| 684 | + if ($complete) { |
|
| 685 | 685 | |
| 686 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 687 | - if ( $has_questions ) { |
|
| 686 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 687 | + if ($has_questions) { |
|
| 688 | 688 | $status = 'passed'; // Force a pass |
| 689 | 689 | $metadata['grade'] = 0; |
| 690 | 690 | } |
@@ -694,31 +694,31 @@ discard block |
||
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // Check if user is already taking the lesson |
| 697 | - $activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id ); |
|
| 698 | - if( ! $activity_logged ) { |
|
| 697 | + $activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id); |
|
| 698 | + if ( ! $activity_logged) { |
|
| 699 | 699 | |
| 700 | 700 | $metadata['start'] = current_time('mysql'); |
| 701 | - $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
|
| 701 | + $activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata); |
|
| 702 | 702 | |
| 703 | 703 | } else { |
| 704 | 704 | |
| 705 | 705 | // if users is already taking the lesson and the status changes to complete update it |
| 706 | 706 | $current_user_activity = get_comment($activity_logged); |
| 707 | - if( $status=='complete' && |
|
| 708 | - $status != $current_user_activity->comment_approved ){ |
|
| 707 | + if ($status == 'complete' && |
|
| 708 | + $status != $current_user_activity->comment_approved) { |
|
| 709 | 709 | |
| 710 | 710 | $comment = array(); |
| 711 | 711 | $comment['comment_ID'] = $activity_logged; |
| 712 | 712 | $comment['comment_approved'] = $status; |
| 713 | - wp_update_comment( $comment ); |
|
| 713 | + wp_update_comment($comment); |
|
| 714 | 714 | |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if ( $complete ) { |
|
| 719 | + if ($complete) { |
|
| 720 | 720 | // Run this *after* the lesson status has been created/updated |
| 721 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 721 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | } |
@@ -733,23 +733,23 @@ discard block |
||
| 733 | 733 | * @param int $user_id |
| 734 | 734 | * @return boolean |
| 735 | 735 | */ |
| 736 | - public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
|
| 736 | + public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) { |
|
| 737 | 737 | |
| 738 | - if( ! $lesson_id ) return false; |
|
| 738 | + if ( ! $lesson_id) return false; |
|
| 739 | 739 | |
| 740 | - if( intval( $user_id ) == 0 ) { |
|
| 740 | + if (intval($user_id) == 0) { |
|
| 741 | 741 | $user_id = get_current_user_id(); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // Process quiz |
| 745 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 745 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 746 | 746 | |
| 747 | 747 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
| 748 | - Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id ); |
|
| 748 | + Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id); |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | // Delete quiz saved answers |
| 752 | - Sensei()->quiz->reset_user_lesson_data( $lesson_id, $user_id ); |
|
| 752 | + Sensei()->quiz->reset_user_lesson_data($lesson_id, $user_id); |
|
| 753 | 753 | |
| 754 | 754 | // Delete lesson status |
| 755 | 755 | $args = array( |
@@ -758,10 +758,10 @@ discard block |
||
| 758 | 758 | 'user_id' => $user_id, |
| 759 | 759 | ); |
| 760 | 760 | // This auto deletes the corresponding meta data, such as the quiz grade, and questions asked |
| 761 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
| 761 | + Sensei_Utils::sensei_delete_activities($args); |
|
| 762 | 762 | |
| 763 | - if( ! $from_course ) { |
|
| 764 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 763 | + if ( ! $from_course) { |
|
| 764 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | return true; |
@@ -774,19 +774,19 @@ discard block |
||
| 774 | 774 | * @param int $user_id |
| 775 | 775 | * @return boolean |
| 776 | 776 | */ |
| 777 | - public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
|
| 777 | + public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) { |
|
| 778 | 778 | |
| 779 | 779 | |
| 780 | - if( ! $course_id ) return false; |
|
| 780 | + if ( ! $course_id) return false; |
|
| 781 | 781 | |
| 782 | - if( intval( $user_id ) == 0 ) { |
|
| 782 | + if (intval($user_id) == 0) { |
|
| 783 | 783 | $user_id = get_current_user_id(); |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 786 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 787 | 787 | |
| 788 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 789 | - Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true ); |
|
| 788 | + foreach ($lesson_ids as $lesson_id) { |
|
| 789 | + Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | // Delete course status |
@@ -796,36 +796,36 @@ discard block |
||
| 796 | 796 | 'user_id' => $user_id, |
| 797 | 797 | ); |
| 798 | 798 | |
| 799 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
| 799 | + Sensei_Utils::sensei_delete_activities($args); |
|
| 800 | 800 | |
| 801 | - do_action( 'sensei_user_course_reset', $user_id, $course_id ); |
|
| 801 | + do_action('sensei_user_course_reset', $user_id, $course_id); |
|
| 802 | 802 | |
| 803 | 803 | return true; |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - public static function sensei_get_quiz_questions( $quiz_id = 0 ) { |
|
| 806 | + public static function sensei_get_quiz_questions($quiz_id = 0) { |
|
| 807 | 807 | |
| 808 | 808 | |
| 809 | 809 | $questions = array(); |
| 810 | 810 | |
| 811 | - if( intval( $quiz_id ) > 0 ) { |
|
| 812 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 813 | - $questions = Sensei_Utils::array_sort_reorder( $questions ); |
|
| 811 | + if (intval($quiz_id) > 0) { |
|
| 812 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 813 | + $questions = Sensei_Utils::array_sort_reorder($questions); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | return $questions; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - public static function sensei_get_quiz_total( $quiz_id = 0 ) { |
|
| 819 | + public static function sensei_get_quiz_total($quiz_id = 0) { |
|
| 820 | 820 | |
| 821 | 821 | |
| 822 | 822 | $quiz_total = 0; |
| 823 | 823 | |
| 824 | - if( $quiz_id > 0 ) { |
|
| 825 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 824 | + if ($quiz_id > 0) { |
|
| 825 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 826 | 826 | $question_grade = 0; |
| 827 | - foreach( $questions as $question ) { |
|
| 828 | - $question_grade = Sensei()->question->get_question_grade( $question->ID ); |
|
| 827 | + foreach ($questions as $question) { |
|
| 828 | + $question_grade = Sensei()->question->get_question_grade($question->ID); |
|
| 829 | 829 | $quiz_total += $question_grade; |
| 830 | 830 | } |
| 831 | 831 | } |
@@ -840,20 +840,20 @@ discard block |
||
| 840 | 840 | * @param int $user_id |
| 841 | 841 | * @return string |
| 842 | 842 | */ |
| 843 | - public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) { |
|
| 843 | + public static function sensei_get_user_question_grade($question = 0, $user_id = 0) { |
|
| 844 | 844 | $question_grade = false; |
| 845 | - if( $question ) { |
|
| 846 | - if ( is_object( $question ) ) { |
|
| 845 | + if ($question) { |
|
| 846 | + if (is_object($question)) { |
|
| 847 | 847 | $user_answer_id = $question->comment_ID; |
| 848 | 848 | } |
| 849 | 849 | else { |
| 850 | - if( intval( $user_id ) == 0 ) { |
|
| 850 | + if (intval($user_id) == 0) { |
|
| 851 | 851 | $user_id = get_current_user_id(); |
| 852 | 852 | } |
| 853 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 853 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 854 | 854 | } |
| 855 | - if ( $user_answer_id ) { |
|
| 856 | - $question_grade = get_comment_meta( $user_answer_id, 'user_grade', true ); |
|
| 855 | + if ($user_answer_id) { |
|
| 856 | + $question_grade = get_comment_meta($user_answer_id, 'user_grade', true); |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
@@ -868,52 +868,52 @@ discard block |
||
| 868 | 868 | * @param int $user_id |
| 869 | 869 | * @return string |
| 870 | 870 | */ |
| 871 | - public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) { |
|
| 871 | + public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) { |
|
| 872 | 872 | $answer_notes = false; |
| 873 | - if( $question ) { |
|
| 874 | - if ( is_object( $question ) ) { |
|
| 873 | + if ($question) { |
|
| 874 | + if (is_object($question)) { |
|
| 875 | 875 | $user_answer_id = $question->comment_ID; |
| 876 | 876 | } |
| 877 | 877 | else { |
| 878 | - if( intval( $user_id ) == 0 ) { |
|
| 878 | + if (intval($user_id) == 0) { |
|
| 879 | 879 | $user_id = get_current_user_id(); |
| 880 | 880 | } |
| 881 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 881 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 882 | 882 | } |
| 883 | - if ( $user_answer_id ) { |
|
| 884 | - $answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) ); |
|
| 883 | + if ($user_answer_id) { |
|
| 884 | + $answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true)); |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | return $answer_notes; |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) { |
|
| 892 | - if( intval( $user_id ) == 0 ) { |
|
| 891 | + public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) { |
|
| 892 | + if (intval($user_id) == 0) { |
|
| 893 | 893 | $user_id = get_current_user_id(); |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | $delete_answers = false; |
| 897 | - if( intval( $quiz_id ) > 0 ) { |
|
| 898 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 899 | - foreach( $questions as $question ) { |
|
| 900 | - $delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) ); |
|
| 897 | + if (intval($quiz_id) > 0) { |
|
| 898 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 899 | + foreach ($questions as $question) { |
|
| 900 | + $delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer')); |
|
| 901 | 901 | } |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | return $delete_answers; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) { |
|
| 908 | - if( intval( $user_id ) == 0 ) { |
|
| 907 | + public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) { |
|
| 908 | + if (intval($user_id) == 0) { |
|
| 909 | 909 | $user_id = get_current_user_id(); |
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | $delete_grade = false; |
| 913 | - if( intval( $quiz_id ) > 0 ) { |
|
| 914 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 915 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 916 | - $delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' ); |
|
| 913 | + if (intval($quiz_id) > 0) { |
|
| 914 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 915 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 916 | + $delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade'); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | return $delete_grade; |
@@ -926,20 +926,20 @@ discard block |
||
| 926 | 926 | * @param string $notes |
| 927 | 927 | * @return boolean |
| 928 | 928 | */ |
| 929 | - public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
|
| 930 | - if( intval( $user_id ) == 0 ) { |
|
| 929 | + public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') { |
|
| 930 | + if (intval($user_id) == 0) { |
|
| 931 | 931 | $user_id = get_current_user_id(); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | $activity_logged = false; |
| 935 | 935 | |
| 936 | - if( intval( $question_id ) > 0 ) { |
|
| 937 | - $notes = base64_encode( $notes ); |
|
| 936 | + if (intval($question_id) > 0) { |
|
| 937 | + $notes = base64_encode($notes); |
|
| 938 | 938 | |
| 939 | 939 | // Don't store empty values, no point |
| 940 | - if ( !empty($notes) ) { |
|
| 941 | - $user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
| 942 | - $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
|
| 940 | + if ( ! empty($notes)) { |
|
| 941 | + $user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
| 942 | + $activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes); |
|
| 943 | 943 | } |
| 944 | 944 | else { |
| 945 | 945 | $activity_logged = true; |
@@ -955,16 +955,16 @@ discard block |
||
| 955 | 955 | * @param array $return_array data to be ordered |
| 956 | 956 | * @return array $return_array ordered data |
| 957 | 957 | */ |
| 958 | - public static function array_sort_reorder( $return_array ) { |
|
| 959 | - if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) { |
|
| 958 | + public static function array_sort_reorder($return_array) { |
|
| 959 | + if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) { |
|
| 960 | 960 | $sort_key = ''; |
| 961 | 961 | // if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) { |
| 962 | 962 | // $sort_key = esc_html( $_GET['orderby'] ); |
| 963 | 963 | // } // End If Statement |
| 964 | - if ( '' != $sort_key ) { |
|
| 965 | - Sensei_Utils::sort_array_by_key($return_array,$sort_key); |
|
| 966 | - if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) { |
|
| 967 | - $return_array = array_reverse( $return_array, true ); |
|
| 964 | + if ('' != $sort_key) { |
|
| 965 | + Sensei_Utils::sort_array_by_key($return_array, $sort_key); |
|
| 966 | + if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) { |
|
| 967 | + $return_array = array_reverse($return_array, true); |
|
| 968 | 968 | } // End If Statement |
| 969 | 969 | } // End If Statement |
| 970 | 970 | return $return_array; |
@@ -980,15 +980,15 @@ discard block |
||
| 980 | 980 | * @param $key string column name in array |
| 981 | 981 | * @return void |
| 982 | 982 | */ |
| 983 | - public static function sort_array_by_key( $array, $key ) { |
|
| 983 | + public static function sort_array_by_key($array, $key) { |
|
| 984 | 984 | $sorter = array(); |
| 985 | 985 | $ret = array(); |
| 986 | - reset( $array ); |
|
| 987 | - foreach ( $array as $ii => $va ) { |
|
| 986 | + reset($array); |
|
| 987 | + foreach ($array as $ii => $va) { |
|
| 988 | 988 | $sorter[$ii] = $va[$key]; |
| 989 | 989 | } // End For Loop |
| 990 | - asort( $sorter ); |
|
| 991 | - foreach ( $sorter as $ii => $va ) { |
|
| 990 | + asort($sorter); |
|
| 991 | + foreach ($sorter as $ii => $va) { |
|
| 992 | 992 | $ret[$ii] = $array[$ii]; |
| 993 | 993 | } // End For Loop |
| 994 | 994 | $array = $ret; |
@@ -1000,10 +1000,10 @@ discard block |
||
| 1000 | 1000 | * @param integer $quiz_id |
| 1001 | 1001 | * @return array of quiz questions |
| 1002 | 1002 | */ |
| 1003 | - public static function lesson_quiz_questions( $quiz_id = 0 ) { |
|
| 1003 | + public static function lesson_quiz_questions($quiz_id = 0) { |
|
| 1004 | 1004 | $questions_array = array(); |
| 1005 | - if ( 0 < $quiz_id ) { |
|
| 1006 | - $question_args = array( 'post_type' => 'question', |
|
| 1005 | + if (0 < $quiz_id) { |
|
| 1006 | + $question_args = array('post_type' => 'question', |
|
| 1007 | 1007 | 'posts_per_page' => -1, |
| 1008 | 1008 | 'orderby' => 'ID', |
| 1009 | 1009 | 'order' => 'ASC', |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | 'post_status' => 'any', |
| 1017 | 1017 | 'suppress_filters' => 0 |
| 1018 | 1018 | ); |
| 1019 | - $questions_array = get_posts( $question_args ); |
|
| 1019 | + $questions_array = get_posts($question_args); |
|
| 1020 | 1020 | } // End If Statement |
| 1021 | 1021 | return $questions_array; |
| 1022 | 1022 | } // End lesson_quiz_questions() |
@@ -1026,25 +1026,25 @@ discard block |
||
| 1026 | 1026 | * @param integer $course_id ID of course |
| 1027 | 1027 | * @return integer Pass mark for course |
| 1028 | 1028 | */ |
| 1029 | - public static function sensei_course_pass_grade( $course_id = 0 ) { |
|
| 1029 | + public static function sensei_course_pass_grade($course_id = 0) { |
|
| 1030 | 1030 | |
| 1031 | 1031 | |
| 1032 | 1032 | $course_passmark = 0; |
| 1033 | 1033 | |
| 1034 | - if( $course_id > 0 ) { |
|
| 1035 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1034 | + if ($course_id > 0) { |
|
| 1035 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1036 | 1036 | $lesson_count = 0; |
| 1037 | 1037 | $total_passmark = 0; |
| 1038 | - foreach( $lessons as $lesson ) { |
|
| 1038 | + foreach ($lessons as $lesson) { |
|
| 1039 | 1039 | |
| 1040 | 1040 | // Get Quiz ID |
| 1041 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 1041 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 1042 | 1042 | |
| 1043 | 1043 | // Check for a pass being required |
| 1044 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1045 | - if ( $pass_required ) { |
|
| 1044 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1045 | + if ($pass_required) { |
|
| 1046 | 1046 | // Get quiz passmark |
| 1047 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1047 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1048 | 1048 | |
| 1049 | 1049 | // Add up total passmark |
| 1050 | 1050 | $total_passmark += $quiz_passmark; |
@@ -1053,12 +1053,12 @@ discard block |
||
| 1053 | 1053 | } |
| 1054 | 1054 | } |
| 1055 | 1055 | // Might be a case of no required lessons |
| 1056 | - if ( $lesson_count ) { |
|
| 1057 | - $course_passmark = ( $total_passmark / $lesson_count ); |
|
| 1056 | + if ($lesson_count) { |
|
| 1057 | + $course_passmark = ($total_passmark / $lesson_count); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | - return Sensei_Utils::round( $course_passmark ); |
|
| 1061 | + return Sensei_Utils::round($course_passmark); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1067,31 +1067,31 @@ discard block |
||
| 1067 | 1067 | * @param integer $user_id ID of user |
| 1068 | 1068 | * @return integer User's total grade |
| 1069 | 1069 | */ |
| 1070 | - public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
|
| 1070 | + public static function sensei_course_user_grade($course_id = 0, $user_id = 0) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | |
| 1073 | - if( intval( $user_id ) == 0 ) { |
|
| 1073 | + if (intval($user_id) == 0) { |
|
| 1074 | 1074 | $user_id = get_current_user_id(); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | $total_grade = 0; |
| 1078 | 1078 | |
| 1079 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1080 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1079 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1080 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 1081 | 1081 | $lesson_count = 0; |
| 1082 | 1082 | $total_grade = 0; |
| 1083 | - foreach( $lessons as $lesson ) { |
|
| 1083 | + foreach ($lessons as $lesson) { |
|
| 1084 | 1084 | |
| 1085 | 1085 | // Check for lesson having questions, thus a quiz, thus having a grade |
| 1086 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
| 1087 | - if ( $has_questions ) { |
|
| 1088 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id ); |
|
| 1086 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
| 1087 | + if ($has_questions) { |
|
| 1088 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id); |
|
| 1089 | 1089 | |
| 1090 | - if( empty( $user_lesson_status ) ){ |
|
| 1090 | + if (empty($user_lesson_status)) { |
|
| 1091 | 1091 | continue; |
| 1092 | 1092 | } |
| 1093 | 1093 | // Get user quiz grade |
| 1094 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1094 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1095 | 1095 | |
| 1096 | 1096 | // Add up total grade |
| 1097 | 1097 | $total_grade += $quiz_grade; |
@@ -1101,13 +1101,13 @@ discard block |
||
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | // Might be a case of no lessons with quizzes |
| 1104 | - if ( $lesson_count ) { |
|
| 1105 | - $total_grade = ( $total_grade / $lesson_count ); |
|
| 1104 | + if ($lesson_count) { |
|
| 1105 | + $total_grade = ($total_grade / $lesson_count); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - return Sensei_Utils::round( $total_grade ); |
|
| 1110 | + return Sensei_Utils::round($total_grade); |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1116,18 +1116,18 @@ discard block |
||
| 1116 | 1116 | * @param integer $user_id ID of user |
| 1117 | 1117 | * @return boolean |
| 1118 | 1118 | */ |
| 1119 | - public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) { |
|
| 1120 | - if( intval( $user_id ) == 0 ) { |
|
| 1119 | + public static function sensei_user_passed_course($course_id = 0, $user_id = 0) { |
|
| 1120 | + if (intval($user_id) == 0) { |
|
| 1121 | 1121 | $user_id = get_current_user_id(); |
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | $pass = false; |
| 1125 | 1125 | |
| 1126 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1127 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); |
|
| 1128 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); |
|
| 1126 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1127 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); |
|
| 1128 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); |
|
| 1129 | 1129 | |
| 1130 | - if( $user_grade >= $passmark ) { |
|
| 1130 | + if ($user_grade >= $passmark) { |
|
| 1131 | 1131 | $pass = true; |
| 1132 | 1132 | } |
| 1133 | 1133 | } |
@@ -1141,37 +1141,37 @@ discard block |
||
| 1141 | 1141 | * @param integer $course_id ID of course |
| 1142 | 1142 | * @param integer $user_id ID of user |
| 1143 | 1143 | */ |
| 1144 | - public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) { |
|
| 1145 | - if( intval( $user_id ) == 0 ) { |
|
| 1144 | + public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) { |
|
| 1145 | + if (intval($user_id) == 0) { |
|
| 1146 | 1146 | $user_id = get_current_user_id(); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | $status = 'not_started'; |
| 1150 | 1150 | $box_class = 'info'; |
| 1151 | - $message = __( 'You have not started this course yet.', 'woothemes-sensei' ); |
|
| 1151 | + $message = __('You have not started this course yet.', 'woothemes-sensei'); |
|
| 1152 | 1152 | |
| 1153 | - if( $course_id > 0 && $user_id > 0 ) { |
|
| 1153 | + if ($course_id > 0 && $user_id > 0) { |
|
| 1154 | 1154 | |
| 1155 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1155 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1156 | 1156 | |
| 1157 | - if( $started_course ) { |
|
| 1158 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()! |
|
| 1159 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()! |
|
| 1160 | - if( $user_grade >= $passmark ) { |
|
| 1157 | + if ($started_course) { |
|
| 1158 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()! |
|
| 1159 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()! |
|
| 1160 | + if ($user_grade >= $passmark) { |
|
| 1161 | 1161 | $status = 'passed'; |
| 1162 | 1162 | $box_class = 'tick'; |
| 1163 | - $message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade ); |
|
| 1163 | + $message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade); |
|
| 1164 | 1164 | } else { |
| 1165 | 1165 | $status = 'failed'; |
| 1166 | 1166 | $box_class = 'alert'; |
| 1167 | - $message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade ); |
|
| 1167 | + $message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | - $message = apply_filters( 'sensei_user_course_status_' . $status, $message ); |
|
| 1174 | - Sensei()->notices->add_notice( $message, $box_class ); |
|
| 1173 | + $message = apply_filters('sensei_user_course_status_'.$status, $message); |
|
| 1174 | + Sensei()->notices->add_notice($message, $box_class); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | /** |
@@ -1181,94 +1181,94 @@ discard block |
||
| 1181 | 1181 | * @param bool $is_lesson |
| 1182 | 1182 | * @return array Status code and message |
| 1183 | 1183 | */ |
| 1184 | - public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
|
| 1184 | + public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) { |
|
| 1185 | 1185 | global $current_user; |
| 1186 | - if( intval( $user_id ) == 0 ) { |
|
| 1186 | + if (intval($user_id) == 0) { |
|
| 1187 | 1187 | $user_id = $current_user->ID; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | $status = 'not_started'; |
| 1191 | 1191 | $box_class = 'info'; |
| 1192 | - $message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' ); |
|
| 1192 | + $message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei'); |
|
| 1193 | 1193 | $extra = ''; |
| 1194 | 1194 | |
| 1195 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1195 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1196 | 1196 | |
| 1197 | 1197 | // Prerequisite lesson |
| 1198 | - $prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1198 | + $prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 1199 | 1199 | |
| 1200 | 1200 | // Course ID |
| 1201 | - $course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
| 1201 | + $course_id = absint(get_post_meta($lesson_id, '_lesson_course', true)); |
|
| 1202 | 1202 | |
| 1203 | 1203 | // Has user started course |
| 1204 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1204 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1205 | 1205 | |
| 1206 | 1206 | // Has user completed lesson |
| 1207 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1208 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 1207 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1208 | + $lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
| 1209 | 1209 | |
| 1210 | 1210 | // Quiz ID |
| 1211 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1211 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1212 | 1212 | |
| 1213 | 1213 | // Quiz grade |
| 1214 | 1214 | $quiz_grade = 0; |
| 1215 | - if ( $user_lesson_status ) { |
|
| 1216 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1215 | + if ($user_lesson_status) { |
|
| 1216 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | // Quiz passmark |
| 1220 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
| 1220 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
| 1221 | 1221 | $quiz_passmark_float = (float) $quiz_passmark; |
| 1222 | 1222 | |
| 1223 | 1223 | // Pass required |
| 1224 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 1224 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 1225 | 1225 | |
| 1226 | 1226 | // Quiz questions |
| 1227 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1227 | + $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1228 | 1228 | |
| 1229 | - if ( ! $started_course ) { |
|
| 1229 | + if ( ! $started_course) { |
|
| 1230 | 1230 | |
| 1231 | 1231 | $status = 'not_started_course'; |
| 1232 | 1232 | $box_class = 'info'; |
| 1233 | - $message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' ); |
|
| 1233 | + $message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>'); |
|
| 1234 | 1234 | |
| 1235 | - } elseif ( ! is_user_logged_in() ) { |
|
| 1235 | + } elseif ( ! is_user_logged_in()) { |
|
| 1236 | 1236 | |
| 1237 | 1237 | $status = 'login_required'; |
| 1238 | 1238 | $box_class = 'info'; |
| 1239 | - $message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' ); |
|
| 1239 | + $message = __('You must be logged in to take this quiz', 'woothemes-sensei'); |
|
| 1240 | 1240 | |
| 1241 | 1241 | } |
| 1242 | 1242 | // Lesson/Quiz is marked as complete thus passing any quiz restrictions |
| 1243 | - elseif ( $lesson_complete ) { |
|
| 1243 | + elseif ($lesson_complete) { |
|
| 1244 | 1244 | |
| 1245 | 1245 | $status = 'passed'; |
| 1246 | 1246 | $box_class = 'tick'; |
| 1247 | 1247 | // Lesson status will be "complete" (has no Quiz) |
| 1248 | - if ( ! $has_quiz_questions ) { |
|
| 1249 | - $message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) ); |
|
| 1248 | + if ( ! $has_quiz_questions) { |
|
| 1249 | + $message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei')); |
|
| 1250 | 1250 | } |
| 1251 | 1251 | // Lesson status will be "graded" (no passmark required so might have failed all the questions) |
| 1252 | - elseif ( empty( $quiz_grade ) ) { |
|
| 1253 | - $message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) ); |
|
| 1252 | + elseif (empty($quiz_grade)) { |
|
| 1253 | + $message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei')); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | // Lesson status will be "passed" (passmark reached) |
| 1256 | - elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) { |
|
| 1257 | - if( $is_lesson ) { |
|
| 1258 | - $message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1256 | + elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) { |
|
| 1257 | + if ($is_lesson) { |
|
| 1258 | + $message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
| 1259 | 1259 | } else { |
| 1260 | - $message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1260 | + $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | // add next lesson button |
| 1265 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1266 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1265 | + $nav_id_array = sensei_get_prev_next_lessons($lesson_id); |
|
| 1266 | + $next_lesson_id = absint($nav_id_array['next_lesson']); |
|
| 1267 | 1267 | |
| 1268 | 1268 | // Output HTML |
| 1269 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1270 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1271 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1269 | + if ((0 < $next_lesson_id)) { |
|
| 1270 | + $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id)) |
|
| 1271 | + . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei') |
|
| 1272 | 1272 | .'</a>'; |
| 1273 | 1273 | |
| 1274 | 1274 | } |
@@ -1277,51 +1277,51 @@ discard block |
||
| 1277 | 1277 | // Lesson/Quiz not complete |
| 1278 | 1278 | else { |
| 1279 | 1279 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1280 | - if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
|
| 1280 | + if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) { |
|
| 1281 | 1281 | $status = 'complete'; |
| 1282 | 1282 | $box_class = 'info'; |
| 1283 | - if( $is_lesson ) { |
|
| 1284 | - $message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' ); |
|
| 1283 | + if ($is_lesson) { |
|
| 1284 | + $message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>'); |
|
| 1285 | 1285 | } else { |
| 1286 | - $message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1286 | + $message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | } |
| 1289 | 1289 | // Lesson status must be "failed" |
| 1290 | - elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) { |
|
| 1290 | + elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) { |
|
| 1291 | 1291 | $status = 'failed'; |
| 1292 | 1292 | $box_class = 'alert'; |
| 1293 | - if( $is_lesson ) { |
|
| 1294 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1293 | + if ($is_lesson) { |
|
| 1294 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
| 1295 | 1295 | } else { |
| 1296 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
| 1296 | + $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | } |
| 1299 | 1299 | // Lesson/Quiz requires a pass |
| 1300 | - elseif( $pass_required ) { |
|
| 1300 | + elseif ($pass_required) { |
|
| 1301 | 1301 | $status = 'not_started'; |
| 1302 | 1302 | $box_class = 'info'; |
| 1303 | - if( $is_lesson ) { |
|
| 1304 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1303 | + if ($is_lesson) { |
|
| 1304 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1305 | 1305 | } else { |
| 1306 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
| 1306 | + $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | } |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - }else{ |
|
| 1311 | + } else { |
|
| 1312 | 1312 | |
| 1313 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1314 | - $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' ) . '">'; |
|
| 1315 | - $a_element .= __( 'course', 'woothemes-sensei' ); |
|
| 1313 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1314 | + $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">'; |
|
| 1315 | + $a_element .= __('course', 'woothemes-sensei'); |
|
| 1316 | 1316 | $a_element .= '</a>'; |
| 1317 | 1317 | |
| 1318 | - if ( Sensei_WC::is_course_purchasable( $course_id ) ){ |
|
| 1318 | + if (Sensei_WC::is_course_purchasable($course_id)) { |
|
| 1319 | 1319 | |
| 1320 | - $message = sprintf( __( 'Please purchase the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element ); |
|
| 1320 | + $message = sprintf(__('Please purchase the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element); |
|
| 1321 | 1321 | |
| 1322 | 1322 | } else { |
| 1323 | 1323 | |
| 1324 | - $message = sprintf( __( 'Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element ); |
|
| 1324 | + $message = sprintf(__('Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element); |
|
| 1325 | 1325 | |
| 1326 | 1326 | } |
| 1327 | 1327 | |
@@ -1329,15 +1329,15 @@ discard block |
||
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | // Legacy filter |
| 1332 | - $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
|
| 1332 | + $message = apply_filters('sensei_user_quiz_status_'.$status, $message); |
|
| 1333 | 1333 | |
| 1334 | - if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
|
| 1335 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1336 | - $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
|
| 1334 | + if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) { |
|
| 1335 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1336 | + $extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>'; |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | // Filter of all messages |
| 1340 | - return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson ); |
|
| 1340 | + return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson); |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | /** |
@@ -1347,14 +1347,14 @@ discard block |
||
| 1347 | 1347 | * @param integer $course_id Course ID |
| 1348 | 1348 | * @return mixed boolean or comment_ID |
| 1349 | 1349 | */ |
| 1350 | - public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
|
| 1350 | + public static function user_start_course($user_id = 0, $course_id = 0) { |
|
| 1351 | 1351 | |
| 1352 | 1352 | $activity_logged = false; |
| 1353 | 1353 | |
| 1354 | - if( $user_id && $course_id ) { |
|
| 1354 | + if ($user_id && $course_id) { |
|
| 1355 | 1355 | // Check if user is already on the Course |
| 1356 | - $activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
| 1357 | - if ( ! $activity_logged ) { |
|
| 1356 | + $activity_logged = Sensei_Utils::user_started_course($course_id, $user_id); |
|
| 1357 | + if ( ! $activity_logged) { |
|
| 1358 | 1358 | |
| 1359 | 1359 | // Add user to course |
| 1360 | 1360 | $course_metadata = array( |
@@ -1363,11 +1363,11 @@ discard block |
||
| 1363 | 1363 | 'complete' => 0, |
| 1364 | 1364 | ); |
| 1365 | 1365 | |
| 1366 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata ); |
|
| 1366 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata); |
|
| 1367 | 1367 | |
| 1368 | 1368 | // Allow further actions |
| 1369 | - if ( $activity_logged ) { |
|
| 1370 | - do_action( 'sensei_user_course_start', $user_id, $course_id ); |
|
| 1369 | + if ($activity_logged) { |
|
| 1370 | + do_action('sensei_user_course_start', $user_id, $course_id); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | } |
| 1373 | 1373 | } |
@@ -1383,19 +1383,19 @@ discard block |
||
| 1383 | 1383 | * @param int $user_id |
| 1384 | 1384 | * @return mixed false or comment_ID |
| 1385 | 1385 | */ |
| 1386 | - public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
|
| 1386 | + public static function user_started_course($course_id = 0, $user_id = 0) { |
|
| 1387 | 1387 | |
| 1388 | - if( $course_id ) { |
|
| 1389 | - if( ! $user_id ) { |
|
| 1388 | + if ($course_id) { |
|
| 1389 | + if ( ! $user_id) { |
|
| 1390 | 1390 | $user_id = get_current_user_id(); |
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | - if( ! $user_id > 0 ){ |
|
| 1393 | + if ( ! $user_id > 0) { |
|
| 1394 | 1394 | return false; |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | - $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
|
| 1398 | - if( $user_course_status_id ) { |
|
| 1397 | + $user_course_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID')); |
|
| 1398 | + if ($user_course_status_id) { |
|
| 1399 | 1399 | return $user_course_status_id; |
| 1400 | 1400 | } |
| 1401 | 1401 | } |
@@ -1410,17 +1410,17 @@ discard block |
||
| 1410 | 1410 | * @param integer $user_id User ID |
| 1411 | 1411 | * @return int |
| 1412 | 1412 | */ |
| 1413 | - public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
|
| 1413 | + public static function user_complete_course($course_id = 0, $user_id = 0) { |
|
| 1414 | 1414 | global $wp_version; |
| 1415 | 1415 | |
| 1416 | - if( $course_id ) { |
|
| 1417 | - if( ! $user_id ) { |
|
| 1416 | + if ($course_id) { |
|
| 1417 | + if ( ! $user_id) { |
|
| 1418 | 1418 | $user_id = get_current_user_id(); |
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | 1421 | $course_status = 'in-progress'; |
| 1422 | 1422 | $course_metadata = array(); |
| 1423 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1423 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1424 | 1424 | $lessons_completed = $total_lessons = 0; |
| 1425 | 1425 | $lesson_status_args = array( |
| 1426 | 1426 | 'user_id' => $user_id, |
@@ -1429,8 +1429,8 @@ discard block |
||
| 1429 | 1429 | ); |
| 1430 | 1430 | |
| 1431 | 1431 | // Grab all of this Courses' lessons, looping through each... |
| 1432 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
| 1433 | - $total_lessons = count( $lesson_ids ); |
|
| 1432 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
| 1433 | + $total_lessons = count($lesson_ids); |
|
| 1434 | 1434 | // ...if course completion not set to 'passed', and all lessons are complete or graded, |
| 1435 | 1435 | // ......then all lessons are 'passed' |
| 1436 | 1436 | // ...else if course completion is set to 'passed', check if each lesson has questions... |
@@ -1443,29 +1443,29 @@ discard block |
||
| 1443 | 1443 | // The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson() |
| 1444 | 1444 | $all_lesson_statuses = array(); |
| 1445 | 1445 | // In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs |
| 1446 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1446 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1447 | 1447 | $lesson_status_args['post__in'] = $lesson_ids; |
| 1448 | - $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1448 | + $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1449 | 1449 | // Need to always return an array, even with only 1 item |
| 1450 | - if ( !is_array($all_lesson_statuses) ) { |
|
| 1451 | - $all_lesson_statuses = array( $all_lesson_statuses ); |
|
| 1450 | + if ( ! is_array($all_lesson_statuses)) { |
|
| 1451 | + $all_lesson_statuses = array($all_lesson_statuses); |
|
| 1452 | 1452 | } |
| 1453 | 1453 | } |
| 1454 | 1454 | // ...otherwise check each one |
| 1455 | 1455 | else { |
| 1456 | - foreach( $lesson_ids as $lesson_id ) { |
|
| 1456 | + foreach ($lesson_ids as $lesson_id) { |
|
| 1457 | 1457 | $lesson_status_args['post_id'] = $lesson_id; |
| 1458 | - $each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
| 1458 | + $each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
| 1459 | 1459 | // Check for valid return before using |
| 1460 | - if ( !empty($each_lesson_status->comment_approved) ) { |
|
| 1460 | + if ( ! empty($each_lesson_status->comment_approved)) { |
|
| 1461 | 1461 | $all_lesson_statuses[] = $each_lesson_status; |
| 1462 | 1462 | } |
| 1463 | 1463 | } |
| 1464 | 1464 | } |
| 1465 | - foreach( $all_lesson_statuses as $lesson_status ) { |
|
| 1465 | + foreach ($all_lesson_statuses as $lesson_status) { |
|
| 1466 | 1466 | // If lessons are complete without needing quizzes to be passed |
| 1467 | - if ( 'passed' != $course_completion ) { |
|
| 1468 | - switch ( $lesson_status->comment_approved ) { |
|
| 1467 | + if ('passed' != $course_completion) { |
|
| 1468 | + switch ($lesson_status->comment_approved) { |
|
| 1469 | 1469 | // A user cannot 'complete' a course if a lesson... |
| 1470 | 1470 | case 'in-progress': // ...is still in progress |
| 1471 | 1471 | case 'ungraded': // ...hasn't yet been graded |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | } |
| 1478 | 1478 | } |
| 1479 | 1479 | else { |
| 1480 | - switch ( $lesson_status->comment_approved ) { |
|
| 1480 | + switch ($lesson_status->comment_approved) { |
|
| 1481 | 1481 | case 'complete': // Lesson has no quiz/questions |
| 1482 | 1482 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1483 | 1483 | case 'passed': // Lesson has quiz and the user passed |
@@ -1491,20 +1491,20 @@ discard block |
||
| 1491 | 1491 | } |
| 1492 | 1492 | } |
| 1493 | 1493 | } // Each lesson |
| 1494 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1494 | + if ($lessons_completed == $total_lessons) { |
|
| 1495 | 1495 | $course_status = 'complete'; |
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | // Update meta data on how many lessons have been completed |
| 1499 | 1499 | $course_metadata['complete'] = $lessons_completed; |
| 1500 | 1500 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1501 | - $course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1501 | + $course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1502 | 1502 | |
| 1503 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata ); |
|
| 1503 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata); |
|
| 1504 | 1504 | |
| 1505 | 1505 | // Allow further actions |
| 1506 | - if ( 'complete' == $course_status ) { |
|
| 1507 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
| 1506 | + if ('complete' == $course_status) { |
|
| 1507 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
| 1508 | 1508 | } |
| 1509 | 1509 | return $activity_logged; |
| 1510 | 1510 | } |
@@ -1520,40 +1520,40 @@ discard block |
||
| 1520 | 1520 | * @param int $user_id |
| 1521 | 1521 | * @return boolean |
| 1522 | 1522 | */ |
| 1523 | - public static function user_completed_course( $course , $user_id = 0 ) { |
|
| 1523 | + public static function user_completed_course($course, $user_id = 0) { |
|
| 1524 | 1524 | |
| 1525 | - if( $course ) { |
|
| 1526 | - if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
|
| 1525 | + if ($course) { |
|
| 1526 | + if (is_object($course) && is_a($course, 'WP_Comment')) { |
|
| 1527 | 1527 | $user_course_status = $course->comment_approved; |
| 1528 | 1528 | } |
| 1529 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
| 1529 | + elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) { |
|
| 1530 | 1530 | $user_course_status = $course; |
| 1531 | 1531 | } |
| 1532 | 1532 | else { |
| 1533 | 1533 | |
| 1534 | 1534 | // check the user_id |
| 1535 | - if( ! $user_id ) { |
|
| 1535 | + if ( ! $user_id) { |
|
| 1536 | 1536 | |
| 1537 | 1537 | $user_id = get_current_user_id(); |
| 1538 | 1538 | |
| 1539 | - if( empty( $user_id ) ){ |
|
| 1539 | + if (empty($user_id)) { |
|
| 1540 | 1540 | |
| 1541 | 1541 | return false; |
| 1542 | 1542 | |
| 1543 | 1543 | } |
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1547 | - $course = $course->ID; |
|
| 1546 | + if (is_a($course, 'WP_Post')) { |
|
| 1547 | + $course = $course->ID; |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | - $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
|
| 1551 | - if( isset( $user_course_status->comment_approved ) ){ |
|
| 1550 | + $user_course_status = Sensei_Utils::user_course_status($course, $user_id); |
|
| 1551 | + if (isset($user_course_status->comment_approved)) { |
|
| 1552 | 1552 | $user_course_status = $user_course_status->comment_approved; |
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | } |
| 1556 | - if( $user_course_status && 'complete' == $user_course_status ) { |
|
| 1556 | + if ($user_course_status && 'complete' == $user_course_status) { |
|
| 1557 | 1557 | return true; |
| 1558 | 1558 | } |
| 1559 | 1559 | } |
@@ -1568,10 +1568,10 @@ discard block |
||
| 1568 | 1568 | * @param int $user_id |
| 1569 | 1569 | * @return mixed false or comment_ID |
| 1570 | 1570 | */ |
| 1571 | - public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
|
| 1571 | + public static function user_started_lesson($lesson_id = 0, $user_id = 0) { |
|
| 1572 | 1572 | |
| 1573 | - if( $lesson_id ) { |
|
| 1574 | - if( ! $user_id ) { |
|
| 1573 | + if ($lesson_id) { |
|
| 1574 | + if ( ! $user_id) { |
|
| 1575 | 1575 | $user_id = get_current_user_id(); |
| 1576 | 1576 | } |
| 1577 | 1577 | |
@@ -1581,8 +1581,8 @@ discard block |
||
| 1581 | 1581 | 'type' => 'sensei_lesson_status', |
| 1582 | 1582 | 'field' => 'comment_ID' ); |
| 1583 | 1583 | |
| 1584 | - $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
|
| 1585 | - if( $user_lesson_status_id ) { |
|
| 1584 | + $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args); |
|
| 1585 | + if ($user_lesson_status_id) { |
|
| 1586 | 1586 | return $user_lesson_status_id; |
| 1587 | 1587 | } |
| 1588 | 1588 | } |
@@ -1597,29 +1597,29 @@ discard block |
||
| 1597 | 1597 | * @param int $user_id |
| 1598 | 1598 | * @return boolean |
| 1599 | 1599 | */ |
| 1600 | - public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) { |
|
| 1600 | + public static function user_completed_lesson($lesson = 0, $user_id = 0) { |
|
| 1601 | 1601 | |
| 1602 | - if( $lesson ) { |
|
| 1602 | + if ($lesson) { |
|
| 1603 | 1603 | $lesson_id = 0; |
| 1604 | - if ( is_object( $lesson ) ) { |
|
| 1604 | + if (is_object($lesson)) { |
|
| 1605 | 1605 | $user_lesson_status = $lesson->comment_approved; |
| 1606 | 1606 | $lesson_id = $lesson->comment_post_ID; |
| 1607 | 1607 | } |
| 1608 | - elseif ( ! is_numeric( $lesson ) ) { |
|
| 1608 | + elseif ( ! is_numeric($lesson)) { |
|
| 1609 | 1609 | $user_lesson_status = $lesson; |
| 1610 | 1610 | } |
| 1611 | 1611 | else { |
| 1612 | - if( ! $user_id ) { |
|
| 1612 | + if ( ! $user_id) { |
|
| 1613 | 1613 | $user_id = get_current_user_id(); |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | 1616 | // the user is not logged in |
| 1617 | - if( ! $user_id > 0 ){ |
|
| 1617 | + if ( ! $user_id > 0) { |
|
| 1618 | 1618 | return false; |
| 1619 | 1619 | } |
| 1620 | - $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
|
| 1620 | + $_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id); |
|
| 1621 | 1621 | |
| 1622 | - if ( $_user_lesson_status ) { |
|
| 1622 | + if ($_user_lesson_status) { |
|
| 1623 | 1623 | $user_lesson_status = $_user_lesson_status->comment_approved; |
| 1624 | 1624 | } |
| 1625 | 1625 | else { |
@@ -1627,12 +1627,12 @@ discard block |
||
| 1627 | 1627 | } |
| 1628 | 1628 | $lesson_id = $lesson; |
| 1629 | 1629 | } |
| 1630 | - if ( 'in-progress' != $user_lesson_status ) { |
|
| 1630 | + if ('in-progress' != $user_lesson_status) { |
|
| 1631 | 1631 | // Check for Passed or Completed Setting |
| 1632 | 1632 | // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting |
| 1633 | 1633 | // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
| 1634 | 1634 | // if ( 'passed' == $course_completion ) { |
| 1635 | - switch( $user_lesson_status ) { |
|
| 1635 | + switch ($user_lesson_status) { |
|
| 1636 | 1636 | case 'complete': |
| 1637 | 1637 | case 'graded': |
| 1638 | 1638 | case 'passed': |
@@ -1641,13 +1641,13 @@ discard block |
||
| 1641 | 1641 | |
| 1642 | 1642 | case 'failed': |
| 1643 | 1643 | // This may be 'completed' depending on... |
| 1644 | - if ( $lesson_id ) { |
|
| 1644 | + if ($lesson_id) { |
|
| 1645 | 1645 | // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson |
| 1646 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1647 | - if ( $lesson_quiz_id ) { |
|
| 1646 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1647 | + if ($lesson_quiz_id) { |
|
| 1648 | 1648 | // ...the quiz pass setting |
| 1649 | - $pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true ); |
|
| 1650 | - if ( empty($pass_required) ) { |
|
| 1649 | + $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); |
|
| 1650 | + if (empty($pass_required)) { |
|
| 1651 | 1651 | // We just require the user to have done the quiz, not to have passed |
| 1652 | 1652 | return true; |
| 1653 | 1653 | } |
@@ -1670,15 +1670,15 @@ discard block |
||
| 1670 | 1670 | * @param int $user_id |
| 1671 | 1671 | * @return object |
| 1672 | 1672 | */ |
| 1673 | - public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
|
| 1673 | + public static function user_course_status($course_id = 0, $user_id = 0) { |
|
| 1674 | 1674 | |
| 1675 | 1675 | |
| 1676 | - if( $course_id ) { |
|
| 1677 | - if( ! $user_id ) { |
|
| 1676 | + if ($course_id) { |
|
| 1677 | + if ( ! $user_id) { |
|
| 1678 | 1678 | $user_id = get_current_user_id(); |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | - $user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true ); |
|
| 1681 | + $user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true); |
|
| 1682 | 1682 | return $user_course_status; |
| 1683 | 1683 | } |
| 1684 | 1684 | |
@@ -1693,27 +1693,27 @@ discard block |
||
| 1693 | 1693 | * @param int $user_id |
| 1694 | 1694 | * @return object | bool |
| 1695 | 1695 | */ |
| 1696 | - public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
|
| 1696 | + public static function user_lesson_status($lesson_id = 0, $user_id = 0) { |
|
| 1697 | 1697 | |
| 1698 | - if( ! $user_id ) { |
|
| 1698 | + if ( ! $user_id) { |
|
| 1699 | 1699 | $user_id = get_current_user_id(); |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
| 1702 | + if ($lesson_id > 0 && $user_id > 0) { |
|
| 1703 | 1703 | |
| 1704 | - $user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true ); |
|
| 1704 | + $user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true); |
|
| 1705 | 1705 | return $user_lesson_status; |
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | return false; |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | - public static function is_preview_lesson( $lesson_id ) { |
|
| 1711 | + public static function is_preview_lesson($lesson_id) { |
|
| 1712 | 1712 | $is_preview = false; |
| 1713 | 1713 | |
| 1714 | - if( 'lesson' == get_post_type( $lesson_id ) ) { |
|
| 1715 | - $lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true ); |
|
| 1716 | - if ( isset( $lesson_preview ) && '' != $lesson_preview ) { |
|
| 1714 | + if ('lesson' == get_post_type($lesson_id)) { |
|
| 1715 | + $lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true); |
|
| 1716 | + if (isset($lesson_preview) && '' != $lesson_preview) { |
|
| 1717 | 1717 | $is_preview = true; |
| 1718 | 1718 | } |
| 1719 | 1719 | } |
@@ -1721,22 +1721,22 @@ discard block |
||
| 1721 | 1721 | return $is_preview; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | - public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
|
| 1724 | + public static function user_passed_quiz($quiz_id = 0, $user_id = 0) { |
|
| 1725 | 1725 | |
| 1726 | - if( ! $quiz_id ) return false; |
|
| 1726 | + if ( ! $quiz_id) return false; |
|
| 1727 | 1727 | |
| 1728 | - if( ! $user_id ) { |
|
| 1728 | + if ( ! $user_id) { |
|
| 1729 | 1729 | $user_id = get_current_user_id(); |
| 1730 | 1730 | } |
| 1731 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 1731 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 1732 | 1732 | |
| 1733 | 1733 | // Quiz Grade |
| 1734 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1735 | - $quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
| 1734 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1735 | + $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
| 1736 | 1736 | |
| 1737 | 1737 | // Check if Grade is greater than or equal to pass percentage |
| 1738 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 1739 | - if ( $quiz_passmark <= intval( $quiz_grade ) ) { |
|
| 1738 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 1739 | + if ($quiz_passmark <= intval($quiz_grade)) { |
|
| 1740 | 1740 | return true; |
| 1741 | 1741 | } |
| 1742 | 1742 | |
@@ -1756,9 +1756,9 @@ discard block |
||
| 1756 | 1756 | * |
| 1757 | 1757 | * @return mixed false or comment_ID |
| 1758 | 1758 | */ |
| 1759 | - public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1759 | + public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) { |
|
| 1760 | 1760 | $comment_id = false; |
| 1761 | - if ( !empty($status) ) { |
|
| 1761 | + if ( ! empty($status)) { |
|
| 1762 | 1762 | $args = array( |
| 1763 | 1763 | 'user_id' => $user_id, |
| 1764 | 1764 | 'post_id' => $lesson_id, |
@@ -1767,18 +1767,18 @@ discard block |
||
| 1767 | 1767 | 'action' => 'update', // Update the existing status... |
| 1768 | 1768 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1769 | 1769 | ); |
| 1770 | - if( 'in-progress' == $status ) { |
|
| 1771 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1770 | + if ('in-progress' == $status) { |
|
| 1771 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1772 | 1772 | } |
| 1773 | 1773 | |
| 1774 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
| 1775 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1776 | - foreach( $metadata as $key => $value ) { |
|
| 1777 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1774 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
| 1775 | + if ($comment_id && ! empty($metadata)) { |
|
| 1776 | + foreach ($metadata as $key => $value) { |
|
| 1777 | + update_comment_meta($comment_id, $key, $value); |
|
| 1778 | 1778 | } |
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | - do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id ); |
|
| 1781 | + do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | return $comment_id; |
| 1784 | 1784 | } |
@@ -1794,9 +1794,9 @@ discard block |
||
| 1794 | 1794 | * @param array $metadata |
| 1795 | 1795 | * @return mixed false or comment_ID |
| 1796 | 1796 | */ |
| 1797 | - public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
|
| 1797 | + public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) { |
|
| 1798 | 1798 | $comment_id = false; |
| 1799 | - if ( !empty($status) ) { |
|
| 1799 | + if ( ! empty($status)) { |
|
| 1800 | 1800 | $args = array( |
| 1801 | 1801 | 'user_id' => $user_id, |
| 1802 | 1802 | 'post_id' => $course_id, |
@@ -1805,17 +1805,17 @@ discard block |
||
| 1805 | 1805 | 'action' => 'update', // Update the existing status... |
| 1806 | 1806 | 'keep_time' => true, // ...but don't change the existing timestamp |
| 1807 | 1807 | ); |
| 1808 | - if( 'in-progress' == $status ) { |
|
| 1809 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
| 1808 | + if ('in-progress' == $status) { |
|
| 1809 | + unset($args['keep_time']); // Keep updating what's happened |
|
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
| 1813 | - if ( $comment_id && !empty($metadata) ) { |
|
| 1814 | - foreach( $metadata as $key => $value ) { |
|
| 1815 | - update_comment_meta( $comment_id, $key, $value ); |
|
| 1812 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
| 1813 | + if ($comment_id && ! empty($metadata)) { |
|
| 1814 | + foreach ($metadata as $key => $value) { |
|
| 1815 | + update_comment_meta($comment_id, $key, $value); |
|
| 1816 | 1816 | } |
| 1817 | 1817 | } |
| 1818 | - do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id ); |
|
| 1818 | + do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id); |
|
| 1819 | 1819 | } |
| 1820 | 1820 | return $comment_id; |
| 1821 | 1821 | } |
@@ -1827,9 +1827,9 @@ discard block |
||
| 1827 | 1827 | * @param array $pieces (default: array()) |
| 1828 | 1828 | * @return array |
| 1829 | 1829 | */ |
| 1830 | - public static function single_comment_filter( $pieces ) { |
|
| 1831 | - unset( $pieces['orderby'] ); |
|
| 1832 | - unset( $pieces['order'] ); |
|
| 1830 | + public static function single_comment_filter($pieces) { |
|
| 1831 | + unset($pieces['orderby']); |
|
| 1832 | + unset($pieces['order']); |
|
| 1833 | 1833 | |
| 1834 | 1834 | return $pieces; |
| 1835 | 1835 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
| 1841 | 1841 | * @param array $pieces (default: array()) |
| 1842 | 1842 | * @return array |
| 1843 | 1843 | */ |
| 1844 | - public static function comment_any_status_filter( $pieces ) { |
|
| 1844 | + public static function comment_any_status_filter($pieces) { |
|
| 1845 | 1845 | |
| 1846 | - $pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] ); |
|
| 1846 | + $pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']); |
|
| 1847 | 1847 | |
| 1848 | 1848 | return $pieces; |
| 1849 | 1849 | } |
@@ -1855,12 +1855,12 @@ discard block |
||
| 1855 | 1855 | * @param array $pieces (default: array()) |
| 1856 | 1856 | * @return array |
| 1857 | 1857 | */ |
| 1858 | - public static function comment_multiple_status_filter( $pieces ) { |
|
| 1858 | + public static function comment_multiple_status_filter($pieces) { |
|
| 1859 | 1859 | |
| 1860 | - preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder ); |
|
| 1861 | - if ( !empty($placeholder[1]) ) { |
|
| 1862 | - $statuses = explode( ',', $placeholder[1] ); |
|
| 1863 | - $pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] ); |
|
| 1860 | + preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder); |
|
| 1861 | + if ( ! empty($placeholder[1])) { |
|
| 1862 | + $statuses = explode(',', $placeholder[1]); |
|
| 1863 | + $pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']); |
|
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | return $pieces; |
@@ -1872,12 +1872,12 @@ discard block |
||
| 1872 | 1872 | * @param array $pieces |
| 1873 | 1873 | * @return array $pieces |
| 1874 | 1874 | */ |
| 1875 | - public static function comment_total_sum_meta_value_filter( $pieces ) { |
|
| 1875 | + public static function comment_total_sum_meta_value_filter($pieces) { |
|
| 1876 | 1876 | global $wpdb, $wp_version; |
| 1877 | 1877 | |
| 1878 | 1878 | $pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum "; |
| 1879 | - unset( $pieces['groupby'] ); |
|
| 1880 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1879 | + unset($pieces['groupby']); |
|
| 1880 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1881 | 1881 | $args['order'] = false; |
| 1882 | 1882 | $args['orderby'] = false; |
| 1883 | 1883 | } |
@@ -1892,12 +1892,12 @@ discard block |
||
| 1892 | 1892 | * @param array $pieces (default: array()) |
| 1893 | 1893 | * @return array |
| 1894 | 1894 | */ |
| 1895 | - public static function get_posts_count_only_filter( $pieces ) { |
|
| 1895 | + public static function get_posts_count_only_filter($pieces) { |
|
| 1896 | 1896 | global $wp_version; |
| 1897 | 1897 | |
| 1898 | 1898 | $pieces['fields'] = " COUNT(*) AS total "; |
| 1899 | - unset( $pieces['groupby'] ); |
|
| 1900 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 1899 | + unset($pieces['groupby']); |
|
| 1900 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 1901 | 1901 | $args['order'] = false; |
| 1902 | 1902 | $args['orderby'] = false; |
| 1903 | 1903 | } |
@@ -1916,9 +1916,9 @@ discard block |
||
| 1916 | 1916 | * |
| 1917 | 1917 | * @return bool $success |
| 1918 | 1918 | */ |
| 1919 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1919 | + public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1920 | 1920 | |
| 1921 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1921 | + return self::update_user_data($data_key, $post_id, $value, $user_id); |
|
| 1922 | 1922 | |
| 1923 | 1923 | }// end add_user_data |
| 1924 | 1924 | |
@@ -1937,18 +1937,18 @@ discard block |
||
| 1937 | 1937 | * |
| 1938 | 1938 | * @return bool $success |
| 1939 | 1939 | */ |
| 1940 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1940 | + public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
| 1941 | 1941 | |
| 1942 | - if( ! ( $user_id > 0 ) ){ |
|
| 1942 | + if ( ! ($user_id > 0)) { |
|
| 1943 | 1943 | $user_id = get_current_user_id(); |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1947 | - $post_type = get_post_type( $post_id ); |
|
| 1948 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1949 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1950 | - || !get_userdata( $user_id ) |
|
| 1951 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1946 | + $supported_post_types = array('course', 'lesson'); |
|
| 1947 | + $post_type = get_post_type($post_id); |
|
| 1948 | + if (empty($post_id) || empty($data_key) |
|
| 1949 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 1950 | + || ! get_userdata($user_id) |
|
| 1951 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 1952 | 1952 | |
| 1953 | 1953 | return false; |
| 1954 | 1954 | } |
@@ -1956,20 +1956,20 @@ discard block |
||
| 1956 | 1956 | // check if there and existing Sensei status on this post type if not create it |
| 1957 | 1957 | // and get the activity ID |
| 1958 | 1958 | $status_function = 'user_'.$post_type.'_status'; |
| 1959 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1960 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1959 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 1960 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 1961 | 1961 | |
| 1962 | 1962 | $start_function = 'user_start_'.$post_type; |
| 1963 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1963 | + $sensei_user_activity_id = self::$start_function($user_id, $post_id); |
|
| 1964 | 1964 | |
| 1965 | - }else{ |
|
| 1965 | + } else { |
|
| 1966 | 1966 | |
| 1967 | 1967 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 1968 | 1968 | |
| 1969 | 1969 | } |
| 1970 | 1970 | |
| 1971 | 1971 | // store the data |
| 1972 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1972 | + $success = update_comment_meta($sensei_user_activity_id, $data_key, $value); |
|
| 1973 | 1973 | |
| 1974 | 1974 | return $success; |
| 1975 | 1975 | |
@@ -1988,20 +1988,20 @@ discard block |
||
| 1988 | 1988 | * |
| 1989 | 1989 | * @return mixed $user_data_value |
| 1990 | 1990 | */ |
| 1991 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1991 | + public static function get_user_data($data_key, $post_id, $user_id = 0) { |
|
| 1992 | 1992 | |
| 1993 | 1993 | $user_data_value = true; |
| 1994 | 1994 | |
| 1995 | - if( ! ( $user_id > 0 ) ){ |
|
| 1995 | + if ( ! ($user_id > 0)) { |
|
| 1996 | 1996 | $user_id = get_current_user_id(); |
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2000 | - $post_type = get_post_type( $post_id ); |
|
| 2001 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2002 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2003 | - || ! get_userdata( $user_id ) |
|
| 2004 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1999 | + $supported_post_types = array('course', 'lesson'); |
|
| 2000 | + $post_type = get_post_type($post_id); |
|
| 2001 | + if (empty($post_id) || empty($data_key) |
|
| 2002 | + || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2003 | + || ! get_userdata($user_id) |
|
| 2004 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2005 | 2005 | |
| 2006 | 2006 | return false; |
| 2007 | 2007 | } |
@@ -2009,13 +2009,13 @@ discard block |
||
| 2009 | 2009 | // check if there and existing Sensei status on this post type if not create it |
| 2010 | 2010 | // and get the activity ID |
| 2011 | 2011 | $status_function = 'user_'.$post_type.'_status'; |
| 2012 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2013 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2012 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2013 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2014 | 2014 | return false; |
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | 2017 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2018 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 2018 | + $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true); |
|
| 2019 | 2019 | |
| 2020 | 2020 | return $user_data_value; |
| 2021 | 2021 | |
@@ -2030,19 +2030,19 @@ discard block |
||
| 2030 | 2030 | * |
| 2031 | 2031 | * @return bool $deleted |
| 2032 | 2032 | */ |
| 2033 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2033 | + public static function delete_user_data($data_key, $post_id, $user_id) { |
|
| 2034 | 2034 | $deleted = true; |
| 2035 | 2035 | |
| 2036 | - if( ! ( $user_id > 0 ) ){ |
|
| 2036 | + if ( ! ($user_id > 0)) { |
|
| 2037 | 2037 | $user_id = get_current_user_id(); |
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2041 | - $post_type = get_post_type( $post_id ); |
|
| 2042 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2043 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2044 | - || ! get_userdata( $user_id ) |
|
| 2045 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2040 | + $supported_post_types = array('course', 'lesson'); |
|
| 2041 | + $post_type = get_post_type($post_id); |
|
| 2042 | + if (empty($post_id) || empty($data_key) |
|
| 2043 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
| 2044 | + || ! get_userdata($user_id) |
|
| 2045 | + || ! in_array($post_type, $supported_post_types)) { |
|
| 2046 | 2046 | |
| 2047 | 2047 | return false; |
| 2048 | 2048 | } |
@@ -2050,13 +2050,13 @@ discard block |
||
| 2050 | 2050 | // check if there and existing Sensei status on this post type if not create it |
| 2051 | 2051 | // and get the activity ID |
| 2052 | 2052 | $status_function = 'user_'.$post_type.'_status'; |
| 2053 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2054 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2053 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
| 2054 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
| 2055 | 2055 | return false; |
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | 2058 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
| 2059 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2059 | + $deleted = delete_comment_meta($sensei_user_activity_id, $data_key); |
|
| 2060 | 2060 | |
| 2061 | 2061 | return $deleted; |
| 2062 | 2062 | |
@@ -2081,62 +2081,62 @@ discard block |
||
| 2081 | 2081 | * |
| 2082 | 2082 | * @return string $drop_down_element |
| 2083 | 2083 | */ |
| 2084 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2084 | + public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) { |
|
| 2085 | 2085 | |
| 2086 | 2086 | $drop_down_element = ''; |
| 2087 | 2087 | |
| 2088 | 2088 | // setup the basic attributes |
| 2089 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2089 | + if ( ! isset($attributes['name']) || empty($attributes['name'])) { |
|
| 2090 | 2090 | |
| 2091 | 2091 | $attributes['name'] = 'sensei-options'; |
| 2092 | 2092 | |
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2095 | + if ( ! isset($attributes['id']) || empty($attributes['id'])) { |
|
| 2096 | 2096 | |
| 2097 | 2097 | $attributes['id'] = 'sensei-options'; |
| 2098 | 2098 | |
| 2099 | 2099 | } |
| 2100 | 2100 | |
| 2101 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2101 | + if ( ! isset($attributes['class']) || empty($attributes['class'])) { |
|
| 2102 | 2102 | |
| 2103 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2103 | + $attributes['class'] = 'chosen_select widefat'; |
|
| 2104 | 2104 | |
| 2105 | 2105 | } |
| 2106 | 2106 | |
| 2107 | 2107 | // create element attributes |
| 2108 | 2108 | $combined_attributes = ''; |
| 2109 | - foreach( $attributes as $attribute => $value ){ |
|
| 2109 | + foreach ($attributes as $attribute => $value) { |
|
| 2110 | 2110 | |
| 2111 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2111 | + $combined_attributes .= $attribute.'="'.$value.'"'.' '; |
|
| 2112 | 2112 | |
| 2113 | 2113 | }// end for each |
| 2114 | 2114 | |
| 2115 | 2115 | |
| 2116 | 2116 | // create the select element |
| 2117 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2117 | + $drop_down_element .= '<select '.$combined_attributes.' >'."\n"; |
|
| 2118 | 2118 | |
| 2119 | 2119 | // show the none option if the client requested |
| 2120 | - if( $enable_none_option ) { |
|
| 2121 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2120 | + if ($enable_none_option) { |
|
| 2121 | + $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | - if ( count( $options ) > 0 ) { |
|
| 2124 | + if (count($options) > 0) { |
|
| 2125 | 2125 | |
| 2126 | - foreach ($options as $value => $option ){ |
|
| 2126 | + foreach ($options as $value => $option) { |
|
| 2127 | 2127 | |
| 2128 | 2128 | $element = ''; |
| 2129 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2130 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2131 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2129 | + $element .= '<option value="'.esc_attr($value).'"'; |
|
| 2130 | + $element .= selected($value, $selected_value, false).'>'; |
|
| 2131 | + $element .= esc_html($option).'</option>'."\n"; |
|
| 2132 | 2132 | |
| 2133 | 2133 | // add the element to the select html |
| 2134 | - $drop_down_element.= $element; |
|
| 2134 | + $drop_down_element .= $element; |
|
| 2135 | 2135 | } // End For Loop |
| 2136 | 2136 | |
| 2137 | 2137 | } // End If Statement |
| 2138 | 2138 | |
| 2139 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2139 | + $drop_down_element .= '</select>'."\n"; |
|
| 2140 | 2140 | |
| 2141 | 2141 | return $drop_down_element; |
| 2142 | 2142 | |
@@ -2156,14 +2156,14 @@ discard block |
||
| 2156 | 2156 | * |
| 2157 | 2157 | * @return double $val |
| 2158 | 2158 | */ |
| 2159 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2159 | + public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') { |
|
| 2160 | 2160 | |
| 2161 | 2161 | /**å |
| 2162 | 2162 | * Change the precision for the Sensei_Utils::round function. |
| 2163 | 2163 | * the precision given will be passed into the php round function |
| 2164 | 2164 | * @since 1.8.5 |
| 2165 | 2165 | */ |
| 2166 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2166 | + $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode); |
|
| 2167 | 2167 | |
| 2168 | 2168 | /** |
| 2169 | 2169 | * Change the mode for the Sensei_Utils::round function. |
@@ -2173,15 +2173,15 @@ discard block |
||
| 2173 | 2173 | * |
| 2174 | 2174 | * @since 1.8.5 |
| 2175 | 2175 | */ |
| 2176 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2176 | + $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision); |
|
| 2177 | 2177 | |
| 2178 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2178 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
| 2179 | 2179 | |
| 2180 | - return round( $val, $precision, $mode ); |
|
| 2180 | + return round($val, $precision, $mode); |
|
| 2181 | 2181 | |
| 2182 | - }else{ |
|
| 2182 | + } else { |
|
| 2183 | 2183 | |
| 2184 | - return round( $val, $precision ); |
|
| 2184 | + return round($val, $precision); |
|
| 2185 | 2185 | |
| 2186 | 2186 | } |
| 2187 | 2187 | |
@@ -2193,15 +2193,15 @@ discard block |
||
| 2193 | 2193 | * @since 1.9.0 |
| 2194 | 2194 | * @return string $url |
| 2195 | 2195 | */ |
| 2196 | - public static function get_current_url(){ |
|
| 2196 | + public static function get_current_url() { |
|
| 2197 | 2197 | |
| 2198 | 2198 | global $wp; |
| 2199 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2200 | - if ( isset( $_GET ) ) { |
|
| 2199 | + $current_url = trailingslashit(home_url($wp->request)); |
|
| 2200 | + if (isset($_GET)) { |
|
| 2201 | 2201 | |
| 2202 | - foreach ($_GET as $param => $val ) { |
|
| 2202 | + foreach ($_GET as $param => $val) { |
|
| 2203 | 2203 | |
| 2204 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2204 | + $current_url = add_query_arg($param, $val, $current_url); |
|
| 2205 | 2205 | |
| 2206 | 2206 | } |
| 2207 | 2207 | } |
@@ -2231,27 +2231,27 @@ discard block |
||
| 2231 | 2231 | * @param array $array_b |
| 2232 | 2232 | * @return array $merged_array |
| 2233 | 2233 | */ |
| 2234 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2234 | + public static function array_zip_merge($array_a, $array_b) { |
|
| 2235 | 2235 | |
| 2236 | - if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2236 | + if ( ! is_array($array_a) || ! is_array($array_b)) { |
|
| 2237 | 2237 | trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | $merged_array = array(); |
| 2241 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2241 | + $total_elements = count($array_a) + count($array_b); |
|
| 2242 | 2242 | |
| 2243 | 2243 | // Zip arrays |
| 2244 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2244 | + for ($i = 0; $i < $total_elements; $i++) { |
|
| 2245 | 2245 | |
| 2246 | 2246 | // if has an element at current index push a on top |
| 2247 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2248 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2247 | + if (isset($array_a[$i])) { |
|
| 2248 | + $merged_array[] = $array_a[$i]; |
|
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | 2251 | // next if $array_b has an element at current index push a on top of the element |
| 2252 | 2252 | // from a if there was one, if not the element before that. |
| 2253 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2254 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2253 | + if (isset($array_b[$i])) { |
|
| 2254 | + $merged_array[] = $array_b[$i]; |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | } |
@@ -2266,4 +2266,4 @@ discard block |
||
| 2266 | 2266 | * @ignore only for backward compatibility |
| 2267 | 2267 | * @since 1.9.0 |
| 2268 | 2268 | */ |
| 2269 | -class WooThemes_Sensei_Utils extends Sensei_Utils{} |
|
| 2270 | 2269 | \ No newline at end of file |
| 2270 | +class WooThemes_Sensei_Utils extends Sensei_Utils {} |
|
| 2271 | 2271 | \ No newline at end of file |